summaryrefslogtreecommitdiff
path: root/noncore/todayplugins/stockticker/libstocks/http.c
Unidiff
Diffstat (limited to 'noncore/todayplugins/stockticker/libstocks/http.c') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/todayplugins/stockticker/libstocks/http.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/todayplugins/stockticker/libstocks/http.c b/noncore/todayplugins/stockticker/libstocks/http.c
index 2f38f8a..cc78ab7 100644
--- a/noncore/todayplugins/stockticker/libstocks/http.c
+++ b/noncore/todayplugins/stockticker/libstocks/http.c
@@ -117,187 +117,187 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata)
117#elif __WINDOWS__ 117#elif __WINDOWS__
118 closesocket(s); 118 closesocket(s);
119#endif 119#endif
120 return ERRCONN; 120 return ERRCONN;
121 } 121 }
122 122
123 /* create header */ 123 /* create header */
124 if (http_proxy_server) 124 if (http_proxy_server)
125 { 125 {
126 sprintf(header,"GET http://%.128s:80%.256s HTTP/1.0\015\012\015\012", 126 sprintf(header,"GET http://%.128s:80%.256s HTTP/1.0\015\012\015\012",
127 http_server, http_file); 127 http_server, http_file);
128 } 128 }
129 else 129 else
130 { 130 {
131 sprintf(header,"GET %s HTTP/1.0\015\012\015\012",http_file); 131 sprintf(header,"GET %s HTTP/1.0\015\012\015\012",http_file);
132 } 132 }
133 133
134 hlg=strlen(header); 134 hlg=strlen(header);
135 135
136 /* send header */ 136 /* send header */
137#ifdef __UNIX__ 137#ifdef __UNIX__
138 if (write(s,header,hlg)!=hlg) 138 if (write(s,header,hlg)!=hlg)
139#elif __WINDOWS__ 139#elif __WINDOWS__
140 if (send(s,header,hlg, 0)!=hlg) 140 if (send(s,header,hlg, 0)!=hlg)
141#endif 141#endif
142 { 142 {
143#ifdef DEBUG 143#ifdef DEBUG
144 printf(" send header : NOK\n"); 144 printf(" send header : NOK\n");
145#endif 145#endif
146 return ERRWHEA; 146 return ERRWHEA;
147 } 147 }
148 148
149 data_lgr = 0; 149 data_lgr = 0;
150 r=1; 150 r=1;
151 while(r) 151 while(r)
152 { 152 {
153 /* Clear Buffer */ 153 /* Clear Buffer */
154 memset(buf,0,BUF_SIZE+1); 154 memset(buf,0,BUF_SIZE+1);
155 155
156#ifdef __UNIX__ 156#ifdef __UNIX__
157 r=read(s,buf,BUF_SIZE); 157 r=read(s,buf,BUF_SIZE);
158#elif __WINDOWS__ 158#elif __WINDOWS__
159 r=recv(s,buf,BUF_SIZE,0); 159 r=recv(s,buf,BUF_SIZE,0);
160#endif 160#endif
161 161
162 if (r) 162 if (r)
163 { 163 {
164 if(!data_lgr) 164 if(!data_lgr)
165 { 165 {
166 if((data = malloc(r+1))==NULL) 166 if((data = malloc(r+1))==NULL)
167 { 167 {
168 fprintf(stderr,"Memory allocating error (%s line %d)\n" 168 fprintf(stderr,"Memory allocating error (%s line %d)\n"
169 ,__FILE__, __LINE__); 169 ,__FILE__, __LINE__);
170 exit(1); 170 exit(1);
171 } 171 }
172 172
173 memcpy(data,buf,r); 173 memcpy(data,buf,r);
174 data_lgr = r; 174 data_lgr = r;
175 data[r]=0; 175 data[r]=0;
176 } 176 }
177 else 177 else
178 { 178 {
179 if((temp = malloc(r+data_lgr+1))==NULL) 179 if((temp = malloc(r+data_lgr+1))==NULL)
180 { 180 {
181 fprintf(stderr,"Memory allocating error (%s line %d)\n" 181 fprintf(stderr,"Memory allocating error (%s line %d)\n"
182 ,__FILE__, __LINE__); 182 ,__FILE__, __LINE__);
183 exit(1); 183 exit(1);
184 } 184 }
185 memcpy(temp, data, data_lgr); 185 memcpy(temp, data, data_lgr);
186 memcpy(temp+data_lgr, buf, r); 186 memcpy(temp+data_lgr, buf, r);
187 temp[r+data_lgr]=0; 187 temp[r+data_lgr]=0;
188 data_lgr += r; 188 data_lgr += r;
189 free(data); 189 free(data);
190 data = temp; 190 data = temp;
191 } 191 }
192 } 192 }
193 } 193 }
194 194
195 /* close socket */ 195 /* close socket */
196#ifdef __UNIX__ 196#ifdef __UNIX__
197 close(s); 197 close(s);
198#elif __WINDOWS__ 198#elif __WINDOWS__
199 closesocket(s); 199 closesocket(s);
200#endif 200#endif
201 201
202#ifdef DEBUG 202#ifdef DEBUG
203 printf("%s\n", data); 203 printf("%s\n", data);
204#endif 204#endif
205 205
206 /* get headers to test status line */ 206 /* get headers to test status line */
207 /* and to split headers and content */ 207 /* and to split headers and content */
208 208
209 temp = data; 209 temp = data;
210 header_founded = 0; 210 header_founded = 0;
211 while( !header_founded ) 211 while( !header_founded )
212 { 212 {
213 if (*temp==0) return ERRRHEA; 213 if (!temp || *temp==0) return ERRRHEA;
214 214
215 if( *temp==0x0A ) 215 if( *temp==0x0A )
216 { 216 {
217 /* test if it is the header end */ 217 /* test if it is the header end */
218 temp ++; 218 temp ++;
219 if (*temp == 0x0D) temp++; 219 if (*temp == 0x0D) temp++;
220 if (*temp == 0x0A) header_founded = 1; 220 if (*temp == 0x0A) header_founded = 1;
221 } 221 }
222 else 222 else
223 temp++; 223 temp++;
224 } 224 }
225 225
226 *temp = 0; 226 *temp = 0;
227 temp++; 227 temp++;
228 228
229 sscanf(data,"HTTP/1.%*d %03d",&error_code); 229 sscanf(data,"HTTP/1.%*d %03d",&error_code);
230 230
231 if (error_code != 200) 231 if (error_code != 200)
232 { 232 {
233#ifdef DEBUG 233#ifdef DEBUG
234 printf(" HTTP error code : %d\n", error_code); 234 printf(" HTTP error code : %d\n", error_code);
235#endif 235#endif
236 free(data); 236 free(data);
237 return ERRPAHD; 237 return ERRPAHD;
238 } 238 }
239 239
240 if ((csv_ptr = malloc(strlen(temp)+1))==NULL) 240 if ((csv_ptr = malloc(strlen(temp)+1))==NULL)
241 { 241 {
242 free(data); 242 free(data);
243 fprintf(stderr,"Memory allocating error (%s line %d)\n" 243 fprintf(stderr,"Memory allocating error (%s line %d)\n"
244 ,__FILE__, __LINE__); 244 ,__FILE__, __LINE__);
245 exit(1); 245 exit(1);
246 } 246 }
247 247
248 memcpy(csv_ptr, temp, strlen(temp)+1); 248 memcpy(csv_ptr, temp, strlen(temp)+1);
249 free(data); 249 free(data);
250 250
251#ifdef DEBUG 251#ifdef DEBUG
252 printf(" CSV\n"); 252 printf(" CSV\n");
253 printf("%s,\n", csv_ptr); 253 printf("%s,\n", csv_ptr);
254#endif 254#endif
255 255
256 *pdata = csv_ptr; 256 *pdata = csv_ptr;
257 257
258 return 0; 258 return 0;
259} 259}
260 260
261/******************************************************************************/ 261/******************************************************************************/
262/* Set the proxy server to use */ 262/* Set the proxy server to use */
263/******************************************************************************/ 263/******************************************************************************/
264libstocks_return_code set_proxy(char *proxy) 264libstocks_return_code set_proxy(char *proxy)
265{ 265{
266 char *ptr; 266 char *ptr;
267 char c; 267 char c;
268 268
269#ifdef DEBUG 269#ifdef DEBUG
270 printf("*set_proxy\n"); 270 printf("*set_proxy\n");
271#endif 271#endif
272 272
273 /* Parse the proxy URL - It must start with http:// */ 273 /* Parse the proxy URL - It must start with http:// */
274#ifdef __UNIX__ 274#ifdef __UNIX__
275 if (strncasecmp("http://",proxy,7)) return ERRPROX; 275 if (strncasecmp("http://",proxy,7)) return ERRPROX;
276#elif __WINDOWS__ 276#elif __WINDOWS__
277 if (_mbsnbicmp("http://",proxy,7)) return ERRPROX; 277 if (_mbsnbicmp("http://",proxy,7)) return ERRPROX;
278#endif 278#endif
279 279
280 proxy+=7; 280 proxy+=7;
281 281
282 /* find ":" in the proxy url */ 282 /* find ":" in the proxy url */
283 ptr = proxy; 283 ptr = proxy;
284 for (c=*ptr; (c && c!=':');) c=*ptr++; 284 for (c=*ptr; (c && c!=':');) c=*ptr++;
285 285
286 /* ptr points just after the ":" or at the end of proxy if : not founded */ 286 /* ptr points just after the ":" or at the end of proxy if : not founded */
287 *(ptr-1)=0; /* clear the ":" */ 287 *(ptr-1)=0; /* clear the ":" */
288 288
289 http_proxy_server=strdup(proxy); 289 http_proxy_server=strdup(proxy);
290 290
291#ifdef DEBUG 291#ifdef DEBUG
292 printf("http_proxy_server : %s\n", http_proxy_server); 292 printf("http_proxy_server : %s\n", http_proxy_server);
293#endif 293#endif
294 294
295 /* get the port number of the url */ 295 /* get the port number of the url */
296 if (sscanf(ptr,"%d",&http_proxy_port)!=1) return ERRPROX; 296 if (sscanf(ptr,"%d",&http_proxy_port)!=1) return ERRPROX;
297 297
298#ifdef DEBUG 298#ifdef DEBUG
299 printf("http_proxy_port : %d\n", http_proxy_port); 299 printf("http_proxy_port : %d\n", http_proxy_port);
300#endif 300#endif
301 301
302 return 0; 302 return 0;
303} 303}