summaryrefslogtreecommitdiff
path: root/noncore/todayplugins/stockticker/libstocks/stocks.c
Unidiff
Diffstat (limited to 'noncore/todayplugins/stockticker/libstocks/stocks.c') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/todayplugins/stockticker/libstocks/stocks.c189
1 files changed, 95 insertions, 94 deletions
diff --git a/noncore/todayplugins/stockticker/libstocks/stocks.c b/noncore/todayplugins/stockticker/libstocks/stocks.c
index eb04ba9..3a26a47 100644
--- a/noncore/todayplugins/stockticker/libstocks/stocks.c
+++ b/noncore/todayplugins/stockticker/libstocks/stocks.c
@@ -105,7 +105,7 @@ yahoo_source find_yahoo_source(char *symbol)
105 105
106 if (!test) return YAHOO_US; 106 if (!test) return YAHOO_US;
107 } 107 }
108 108
109 /* We suppose now it is a European stock */ 109 /* We suppose now it is a European stock */
110 return YAHOO_EUROPE; 110 return YAHOO_EUROPE;
111} 111}
@@ -116,8 +116,8 @@ yahoo_source find_yahoo_source(char *symbol)
116/* *stock_datas points to the beginning of the list */ 116/* *stock_datas points to the beginning of the list */
117/* count allows to connect to all country servers */ 117/* count allows to connect to all country servers */
118/*****************************************************************************/ 118/*****************************************************************************/
119libstocks_return_code download_stocks(char *stocks, 119libstocks_return_code download_stocks(char *stocks,
120 stock **stock_datas, 120 stock **stock_datas,
121 yahoo_source source) 121 yahoo_source source)
122{ 122{
123 char *stocks_server=NULL; 123 char *stocks_server=NULL;
@@ -138,14 +138,14 @@ libstocks_return_code download_stocks(char *stocks,
138 case YAHOO_US: 138 case YAHOO_US:
139 stocks_server = (char *)yahoo_us_stocks_server; 139 stocks_server = (char *)yahoo_us_stocks_server;
140 break; 140 break;
141 141
142 case YAHOO_EUROPE: 142 case YAHOO_EUROPE:
143 stocks_server = (char *)yahoo_eu_stocks_server; 143 stocks_server = (char *)yahoo_eu_stocks_server;
144 break; 144 break;
145 default: 145 default:
146 stocks_server = (char *)yahoo_us_stocks_server; 146 stocks_server = (char *)yahoo_us_stocks_server;
147 break; 147 break;
148 148
149 } 149 }
150 150
151 url_beg = (char *)yahoo_url_beg; 151 url_beg = (char *)yahoo_url_beg;
@@ -164,13 +164,13 @@ libstocks_return_code download_stocks(char *stocks,
164 strcpy(url, url_beg); 164 strcpy(url, url_beg);
165 strcat(url, stocks); 165 strcat(url, stocks);
166 strcat(url, url_end); 166 strcat(url, url_end);
167 167
168 error=http_get(url, stocks_server, &data); 168 error=http_get(url, stocks_server, &data);
169 169
170 free(url); 170 free(url);
171 171
172 if (error) return error; 172 if (error) return error;
173 173
174 *stock_datas = parse_csv_file(data); 174 *stock_datas = parse_csv_file(data);
175 175
176 free(data); 176 free(data);
@@ -222,7 +222,7 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas)
222 { 222 {
223 fprintf(stderr,"Memory allocating error (%s line %d)\n" 223 fprintf(stderr,"Memory allocating error (%s line %d)\n"
224 ,__FILE__, __LINE__); 224 ,__FILE__, __LINE__);
225 exit(1); 225 exit(1);
226 } 226 }
227 strcpy(tok_ptr, stocks); 227 strcpy(tok_ptr, stocks);
228 228
@@ -235,77 +235,75 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas)
235 source = find_yahoo_source(symbol); 235 source = find_yahoo_source(symbol);
236 236
237 switch (source) 237 switch (source)
238 { 238 {
239 case YAHOO_US: 239 case YAHOO_US:
240 240 if (us_quotes)
241 if (us_quotes) 241 {
242 { 242 lgr_us_quotes = strlen(us_quotes);
243 lgr_us_quotes = strlen(us_quotes); 243 lgr_symbol = strlen(symbol);
244 lgr_symbol = strlen(symbol); 244
245 245 us_quotes_temp = malloc(lgr_us_quotes + lgr_symbol +2);
246 us_quotes_temp = malloc(lgr_us_quotes + lgr_symbol +2); 246 if(us_quotes_temp==NULL)
247 if(us_quotes_temp==NULL) 247 {
248 { 248 fprintf(stderr,"Memory allocating error (%s line %d)\n",
249 fprintf(stderr,"Memory allocating error (%s line %d)\n" 249 __FILE__, __LINE__);
250 ,__FILE__, __LINE__); 250 exit(1);
251 exit(1); 251 }
252 } 252 strcpy(us_quotes_temp, us_quotes);
253 strcpy(us_quotes_temp, us_quotes); 253 strcat(us_quotes_temp,"+");
254 strcat(us_quotes_temp,"+"); 254 strcat(us_quotes_temp,symbol);
255 strcat(us_quotes_temp,symbol); 255
256 256 free(us_quotes);
257 free(us_quotes); 257 us_quotes = us_quotes_temp;
258 us_quotes = us_quotes_temp; 258 }
259 } 259 else
260 else 260 {
261 { 261 us_quotes = malloc(strlen(symbol)+1);
262 us_quotes = malloc(strlen(symbol)+1); 262
263 263 if(us_quotes==NULL)
264 if(us_quotes==NULL) 264 {
265 { 265 fprintf(stderr,"Memory allocating error (%s line %d)\n",
266 fprintf(stderr,"Memory allocating error (%s line %d)\n" 266 __FILE__, __LINE__);
267 ,__FILE__, __LINE__); 267 exit(1);
268 exit(1); 268 }
269 } 269 strcpy(us_quotes, symbol);
270 strcpy(us_quotes, symbol); 270 }
271 } 271
272 272 break;
273 break; 273
274 274 case YAHOO_EUROPE:
275 case YAHOO_EUROPE: 275 if (eu_quotes)
276 276 {
277 if (eu_quotes) 277 lgr_eu_quotes = strlen(eu_quotes);
278 { 278 lgr_symbol = strlen(symbol);
279 lgr_eu_quotes = strlen(eu_quotes); 279
280 lgr_symbol = strlen(symbol); 280 eu_quotes_temp = malloc(lgr_eu_quotes + lgr_symbol +2);
281 281 if(eu_quotes_temp==NULL)
282 eu_quotes_temp = malloc(lgr_eu_quotes + lgr_symbol +2); 282 {
283 if(eu_quotes_temp==NULL) 283 fprintf(stderr,"Memory allocating error (%s line %d)\n",
284 { 284 __FILE__, __LINE__);
285 fprintf(stderr,"Memory allocating error (%s line %d)\n" 285 exit(1);
286 ,__FILE__, __LINE__); 286 }
287 exit(1); 287 strcpy(eu_quotes_temp, eu_quotes);
288 } 288 strcat(eu_quotes_temp, "+");
289 strcpy(eu_quotes_temp, eu_quotes); 289 strcat(eu_quotes_temp, symbol);
290 strcat(eu_quotes_temp, "+"); 290
291 strcat(eu_quotes_temp, symbol); 291 free(eu_quotes);
292 292 eu_quotes = eu_quotes_temp;
293 free(eu_quotes); 293 }
294 eu_quotes = eu_quotes_temp; 294 else
295 } 295 {
296 else 296 eu_quotes = malloc(strlen(symbol)+1);
297 { 297 if(eu_quotes==NULL)
298 eu_quotes = malloc(strlen(symbol)+1); 298 {
299 if(eu_quotes==NULL) 299 fprintf(stderr,"Memory allocating error (%s line %d)\n",
300 { 300 __FILE__, __LINE__);
301 fprintf(stderr,"Memory allocating error (%s line %d)\n" 301 exit(1);
302 ,__FILE__, __LINE__); 302 }
303 exit(1); 303 strcpy(eu_quotes, symbol);
304 } 304 }
305 strcpy(eu_quotes, symbol); 305 break;
306 } 306 }
307 break;
308 }
309 } 307 }
310 308
311 free(tok_ptr); 309 free(tok_ptr);
@@ -314,34 +312,37 @@ libstocks_return_code get_stocks(const char *stocks, stock **stock_datas)
314 { 312 {
315 /* Gets us quotes */ 313 /* Gets us quotes */
316 error = download_stocks(us_quotes, &stocks_tmp, YAHOO_US); 314 error = download_stocks(us_quotes, &stocks_tmp, YAHOO_US);
315 free(us_quotes);
317 if (error) return error; 316 if (error) return error;
318 } 317 }
319 318
320 if (eu_quotes) 319 if (eu_quotes)
321 { 320 {
322 /* Gets european quotes */ 321 /* Gets european quotes */
323 error = download_stocks(eu_quotes, &stocks_getted, YAHOO_EUROPE); 322 error = download_stocks(eu_quotes, &stocks_getted, YAHOO_EUROPE);
323 free(eu_quotes);
324 if (error) return error; 324 if (error) return error;
325 325
326 /* concats lists if needed */ 326 /* concats lists if needed */
327 if (stocks_tmp) 327 if (stocks_tmp)
328 { 328 {
329 stocks_tmp2 = stocks_tmp; 329 stocks_tmp2 = stocks_tmp;
330 330
331 while(stocks_tmp2 != NULL) 331 while(stocks_tmp2 != NULL)
332 { 332 {
333 last_stock = stocks_tmp2; 333 last_stock = stocks_tmp2;
334 stocks_tmp2 = next_stock(stocks_tmp2); 334 stocks_tmp2 = next_stock(stocks_tmp2);
335 } 335 }
336 336
337 last_stock->NextStock = stocks_getted; 337 last_stock->NextStock = stocks_getted;
338 stocks_getted->PreviousStock = last_stock; 338 stocks_getted->PreviousStock = last_stock;
339 339
340 } 340 }
341 else (stocks_tmp = stocks_getted); 341 else
342 (stocks_tmp = stocks_getted);
342 } 343 }
343 344
344 *stock_datas = stocks_tmp; 345 *stock_datas = stocks_tmp;
345 346
346 return(0); 347 return(0);
347} 348}