summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/todayplugins/stockticker/libstocks/csv.c2
-rw-r--r--noncore/todayplugins/stockticker/libstocks/http.c2
2 files changed, 4 insertions, 0 deletions
diff --git a/noncore/todayplugins/stockticker/libstocks/csv.c b/noncore/todayplugins/stockticker/libstocks/csv.c
index f45af52..6170bed 100644
--- a/noncore/todayplugins/stockticker/libstocks/csv.c
+++ b/noncore/todayplugins/stockticker/libstocks/csv.c
@@ -1,118 +1,120 @@
1/* libstocks - Library to get current stock quotes from Yahoo Finance 1/* libstocks - Library to get current stock quotes from Yahoo Finance
2 * 2 *
3 * Copyright (C) 2000 Eric Laeuffer 3 * Copyright (C) 2000 Eric Laeuffer
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public 15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the 16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA. 18 * Boston, MA 02111-1307, USA.
19 */ 19 */
20 20
21#define __CSV_C__ 21#define __CSV_C__
22#ifndef __UNIX__
22#define __UNIX__ 23#define __UNIX__
24#endif
23 25
24#include <string.h> 26#include <string.h>
25#include <stdlib.h> 27#include <stdlib.h>
26#include <stdio.h> 28#include <stdio.h>
27 29
28#ifdef __WINDOWS__ 30#ifdef __WINDOWS__
29#include <mbstring.h> 31#include <mbstring.h>
30#endif 32#endif
31 33
32#include "csv.h" 34#include "csv.h"
33#include "stocks.h" 35#include "stocks.h"
34#include "lists.h" 36#include "lists.h"
35 37
36#define DATE_LENGTH 7 /*YYMMDD*/ 38#define DATE_LENGTH 7 /*YYMMDD*/
37 39
38const char *months[12]= 40const char *months[12]=
39{ 41{
40 "Jan", 42 "Jan",
41 "Feb", 43 "Feb",
42 "Mar", 44 "Mar",
43 "Apr", 45 "Apr",
44 "May", 46 "May",
45 "Jun", 47 "Jun",
46 "Jul", 48 "Jul",
47 "Aug", 49 "Aug",
48 "Sep", 50 "Sep",
49 "Oct", 51 "Oct",
50 "Nov", 52 "Nov",
51 "Dec" 53 "Dec"
52}; 54};
53 55
54/*****************************************************************************/ 56/*****************************************************************************/
55/* Replacement of the strtok function. This one forgets "delim" when it is */ 57/* Replacement of the strtok function. This one forgets "delim" when it is */
56/* between two commas. */ 58/* between two commas. */
57/* Thanks to Julio Lucas who has told me the bug and has proposed me a patch */ 59/* Thanks to Julio Lucas who has told me the bug and has proposed me a patch */
58/*****************************************************************************/ 60/*****************************************************************************/
59char *csv_strtok(char *s, char *delim) 61char *csv_strtok(char *s, char *delim)
60{ 62{
61 static char *next=NULL; 63 static char *next=NULL;
62 char *temp, *first; 64 char *temp, *first;
63 int comma=0; 65 int comma=0;
64 66
65 if (s!=NULL) first=s; 67 if (s!=NULL) first=s;
66 else first=next; 68 else first=next;
67 69
68 temp=first; 70 temp=first;
69 if (*temp=='\0') return NULL; 71 if (*temp=='\0') return NULL;
70 72
71 while (*temp!='\0' && ((*temp!=*delim) || comma)) 73 while (*temp!='\0' && ((*temp!=*delim) || comma))
72 { 74 {
73 if (*temp=='"') comma ^= 1; 75 if (*temp=='"') comma ^= 1;
74 temp++; 76 temp++;
75 } 77 }
76 78
77 if (*temp=='\0') next=temp; 79 if (*temp=='\0') next=temp;
78 else 80 else
79 { 81 {
80 *temp='\0'; 82 *temp='\0';
81 next=temp+1; 83 next=temp+1;
82 } 84 }
83 85
84 return first; 86 return first;
85} 87}
86 88
87/*****************************************************************************/ 89/*****************************************************************************/
88/* Parses the csv file and return a list of stocks structure. */ 90/* Parses the csv file and return a list of stocks structure. */
89/* *csv points on the csv file in memory */ 91/* *csv points on the csv file in memory */
90/* count defines the country, because csv depends on the country */ 92/* count defines the country, because csv depends on the country */
91/*****************************************************************************/ 93/*****************************************************************************/
92stock *parse_csv_file(char *csv) 94stock *parse_csv_file(char *csv)
93{ 95{
94 char *line; 96 char *line;
95 char *end_line; 97 char *end_line;
96 98
97 char *ptr; 99 char *ptr;
98 100
99 char *date; 101 char *date;
100 char *time; 102 char *time;
101 char *name; 103 char *name;
102 char *symbol; 104 char *symbol;
103 105
104 stock *StockPtr=NULL; 106 stock *StockPtr=NULL;
105 stock *LastStockPtr=NULL; 107 stock *LastStockPtr=NULL;
106 108
107 /* Used to return the pointer to the list */ 109 /* Used to return the pointer to the list */
108 stock *FirstStockPtr=NULL; 110 stock *FirstStockPtr=NULL;
109 111
110 /* used to see if symbol is valid */ 112 /* used to see if symbol is valid */
111 int valid; 113 int valid;
112 char *test; 114 char *test;
113 115
114 line = csv; 116 line = csv;
115 end_line = csv; 117 end_line = csv;
116 118
117 while ((end_line = strstr(line, "\n"))) 119 while ((end_line = strstr(line, "\n")))
118 { 120 {
diff --git a/noncore/todayplugins/stockticker/libstocks/http.c b/noncore/todayplugins/stockticker/libstocks/http.c
index 3078746..2f38f8a 100644
--- a/noncore/todayplugins/stockticker/libstocks/http.c
+++ b/noncore/todayplugins/stockticker/libstocks/http.c
@@ -1,118 +1,120 @@
1/* libstocks - Library to get current stock quotes from Yahoo Finance 1/* libstocks - Library to get current stock quotes from Yahoo Finance
2 * 2 *
3 * Copyright (C) 2000 Eric Laeuffer 3 * Copyright (C) 2000 Eric Laeuffer
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public 15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the 16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA. 18 * Boston, MA 02111-1307, USA.
19 */ 19 */
20 20
21#define __HTTP_C__ 21#define __HTTP_C__
22#ifndef __UNIX__
22#define __UNIX__ 23#define __UNIX__
24#endif
23 25
24#ifdef __UNIX__ 26#ifdef __UNIX__
25#include <sys/socket.h> 27#include <sys/socket.h>
26#include <netinet/in.h> 28#include <netinet/in.h>
27#include <arpa/inet.h> 29#include <arpa/inet.h>
28#include <netdb.h> 30#include <netdb.h>
29#include <unistd.h> 31#include <unistd.h>
30#elif __WINDOWS__ 32#elif __WINDOWS__
31#include <winsock.h> 33#include <winsock.h>
32#include <mbstring.h> 34#include <mbstring.h>
33#endif 35#endif
34 36
35#include <sys/types.h> 37#include <sys/types.h>
36#include <ctype.h> 38#include <ctype.h>
37#include <string.h> 39#include <string.h>
38#include <stdlib.h> 40#include <stdlib.h>
39#include <stdio.h> 41#include <stdio.h>
40 42
41#include "http.h" 43#include "http.h"
42#include "stocks.h" 44#include "stocks.h"
43 45
44#define BUF_SIZE 1024 46#define BUF_SIZE 1024
45#define HEADER_MAXBUF 512 47#define HEADER_MAXBUF 512
46 48
47/* pointer to proxy server name or NULL */ 49/* pointer to proxy server name or NULL */
48char *http_proxy_server=NULL; 50char *http_proxy_server=NULL;
49/* proxy server port number or 0 */ 51/* proxy server port number or 0 */
50int http_proxy_port=0; 52int http_proxy_port=0;
51 53
52/*****************************************************************************/ 54/*****************************************************************************/
53/* Gets the file from http://http_server/http_file */ 55/* Gets the file from http://http_server/http_file */
54/* This function is used to get quotes csv file from yahoo. */ 56/* This function is used to get quotes csv file from yahoo. */
55/* It allocates memory for the file and defines *pdata (the pointer of datas)*/ 57/* It allocates memory for the file and defines *pdata (the pointer of datas)*/
56/*****************************************************************************/ 58/*****************************************************************************/
57libstocks_return_code http_get(char *http_file, char *http_server, char **pdata) 59libstocks_return_code http_get(char *http_file, char *http_server, char **pdata)
58{ 60{
59 struct hostent *host; /* structs needed by socket */ 61 struct hostent *host; /* structs needed by socket */
60 struct sockaddr_in server; 62 struct sockaddr_in server;
61 int s; /* socket descriptor */ 63 int s; /* socket descriptor */
62 char header[HEADER_MAXBUF]; /* request header */ 64 char header[HEADER_MAXBUF]; /* request header */
63 int hlg; /* header length */ 65 int hlg; /* header length */
64 char buf[BUF_SIZE+1]; /* tempory buffer from socket read */ 66 char buf[BUF_SIZE+1]; /* tempory buffer from socket read */
65 int r; /* number of bytes read by read function */ 67 int r; /* number of bytes read by read function */
66 char *data=NULL; /* http server response */ 68 char *data=NULL; /* http server response */
67 int data_lgr; /* http server response length */ 69 int data_lgr; /* http server response length */
68 char *temp; /* pointer used to split header and csv */ 70 char *temp; /* pointer used to split header and csv */
69 int error_code; /* error code returned by http server */ 71 int error_code; /* error code returned by http server */
70 char *csv_ptr; /* pointer to the csv content */ 72 char *csv_ptr; /* pointer to the csv content */
71 int header_founded; /* test if header is founded */ 73 int header_founded; /* test if header is founded */
72 74
73#ifdef DEBUG 75#ifdef DEBUG
74 printf("*http_get\n"); 76 printf("*http_get\n");
75#endif 77#endif
76 78
77 /* get host info by name :*/ 79 /* get host info by name :*/
78 if ((host = gethostbyname( http_proxy_server ? http_proxy_server : http_server))) 80 if ((host = gethostbyname( http_proxy_server ? http_proxy_server : http_server)))
79 { 81 {
80 memset((char *) &server,0, sizeof(server)); 82 memset((char *) &server,0, sizeof(server));
81 memmove((char *) &server.sin_addr, host->h_addr, host->h_length); 83 memmove((char *) &server.sin_addr, host->h_addr, host->h_length);
82 server.sin_family = host->h_addrtype; 84 server.sin_family = host->h_addrtype;
83 server.sin_port = (unsigned short) htons( http_proxy_server ? http_proxy_port : 80 ); 85 server.sin_port = (unsigned short) htons( http_proxy_server ? http_proxy_port : 80 );
84 86
85 } else 87 } else
86 { 88 {
87 89
88#ifdef DEBUG 90#ifdef DEBUG
89 printf(" gethostbyname : NOK\n"); 91 printf(" gethostbyname : NOK\n");
90#endif 92#endif
91 return ERRHOST; 93 return ERRHOST;
92 } 94 }
93 95
94 /* create socket */ 96 /* create socket */
95 if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) 97 if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0)
96 { 98 {
97 99
98#ifdef DEBUG 100#ifdef DEBUG
99 printf(" create socket : NOK\n"); 101 printf(" create socket : NOK\n");
100#endif 102#endif
101 return ERRSOCK; 103 return ERRSOCK;
102 } 104 }
103 105
104 setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, 0, 0); 106 setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
105 107
106 /* connect to server */ 108 /* connect to server */
107 if (connect(s, &server, sizeof(server)) < 0) 109 if (connect(s, &server, sizeof(server)) < 0)
108 { 110 {
109#ifdef DEBUG 111#ifdef DEBUG
110 printf(" connect to server : NOK\n"); 112 printf(" connect to server : NOK\n");
111#endif 113#endif
112 114
113#ifdef __UNIX__ 115#ifdef __UNIX__
114 close(s); 116 close(s);
115#elif __WINDOWS__ 117#elif __WINDOWS__
116 closesocket(s); 118 closesocket(s);
117#endif 119#endif
118 return ERRCONN; 120 return ERRCONN;