summaryrefslogtreecommitdiff
path: root/noncore/todayplugins/stockticker/libstocks/http.c
authorllornkcor <llornkcor>2002-10-31 20:32:13 (UTC)
committer llornkcor <llornkcor>2002-10-31 20:32:13 (UTC)
commit73b03f932dd43d684e67db1837bf506ee015f2eb (patch) (side-by-side diff)
tree87be47c236586177c65b38216818951337c0b59a /noncore/todayplugins/stockticker/libstocks/http.c
parent50f1091ee877020c9864ce24202951f49bec8cd7 (diff)
downloadopie-73b03f932dd43d684e67db1837bf506ee015f2eb.zip
opie-73b03f932dd43d684e67db1837bf506ee015f2eb.tar.gz
opie-73b03f932dd43d684e67db1837bf506ee015f2eb.tar.bz2
make define __UNIX__ inherent
Diffstat (limited to 'noncore/todayplugins/stockticker/libstocks/http.c') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/todayplugins/stockticker/libstocks/http.c87
1 files changed, 44 insertions, 43 deletions
diff --git a/noncore/todayplugins/stockticker/libstocks/http.c b/noncore/todayplugins/stockticker/libstocks/http.c
index 462080d..3078746 100644
--- a/noncore/todayplugins/stockticker/libstocks/http.c
+++ b/noncore/todayplugins/stockticker/libstocks/http.c
@@ -4,26 +4,27 @@
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#define __HTTP_C__
+#define __UNIX__
#ifdef __UNIX__
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#elif __WINDOWS__
@@ -80,19 +81,19 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata)
memmove((char *) &server.sin_addr, host->h_addr, host->h_length);
server.sin_family = host->h_addrtype;
server.sin_port = (unsigned short) htons( http_proxy_server ? http_proxy_port : 80 );
} else
{
#ifdef DEBUG
- printf(" gethostbyname : NOK\n");
+ printf(" gethostbyname : NOK\n");
#endif
- return ERRHOST;
+ return ERRHOST;
}
/* create socket */
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
#ifdef DEBUG
printf(" create socket : NOK\n");
@@ -116,34 +117,34 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata)
#endif
return ERRCONN;
}
/* create header */
if (http_proxy_server)
{
sprintf(header,"GET http://%.128s:80%.256s HTTP/1.0\015\012\015\012",
- http_server, http_file);
+ http_server, http_file);
}
else
{
sprintf(header,"GET %s HTTP/1.0\015\012\015\012",http_file);
}
hlg=strlen(header);
/* send header */
#ifdef __UNIX__
if (write(s,header,hlg)!=hlg)
#elif __WINDOWS__
if (send(s,header,hlg, 0)!=hlg)
#endif
{
#ifdef DEBUG
- printf(" send header : NOK\n");
+ printf(" send header : NOK\n");
#endif
return ERRWHEA;
}
data_lgr = 0;
r=1;
while(r)
{
@@ -152,46 +153,46 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata)
#ifdef __UNIX__
r=read(s,buf,BUF_SIZE);
#elif __WINDOWS__
r=recv(s,buf,BUF_SIZE,0);
#endif
if (r)
- {
- if(!data_lgr)
- {
- if((data = malloc(r+1))==NULL)
- {
- fprintf(stderr,"Memory allocating error (%s line %d)\n"
- ,__FILE__, __LINE__);
- exit(1);
- }
-
- memcpy(data,buf,r);
- data_lgr = r;
- data[r]=0;
- }
- else
- {
- if((temp = malloc(r+data_lgr+1))==NULL)
- {
- fprintf(stderr,"Memory allocating error (%s line %d)\n"
- ,__FILE__, __LINE__);
- exit(1);
- }
- memcpy(temp, data, data_lgr);
- memcpy(temp+data_lgr, buf, r);
- temp[r+data_lgr]=0;
- data_lgr += r;
- free(data);
- data = temp;
- }
- }
+ {
+ if(!data_lgr)
+ {
+ if((data = malloc(r+1))==NULL)
+ {
+ fprintf(stderr,"Memory allocating error (%s line %d)\n"
+ ,__FILE__, __LINE__);
+ exit(1);
+ }
+
+ memcpy(data,buf,r);
+ data_lgr = r;
+ data[r]=0;
+ }
+ else
+ {
+ if((temp = malloc(r+data_lgr+1))==NULL)
+ {
+ fprintf(stderr,"Memory allocating error (%s line %d)\n"
+ ,__FILE__, __LINE__);
+ exit(1);
+ }
+ memcpy(temp, data, data_lgr);
+ memcpy(temp+data_lgr, buf, r);
+ temp[r+data_lgr]=0;
+ data_lgr += r;
+ free(data);
+ data = temp;
+ }
+ }
}
/* close socket */
#ifdef __UNIX__
close(s);
#elif __WINDOWS__
closesocket(s);
#endif
@@ -205,24 +206,24 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata)
temp = data;
header_founded = 0;
while( !header_founded )
{
if (*temp==0) return ERRRHEA;
if( *temp==0x0A )
- {
- /* test if it is the header end */
- temp ++;
- if (*temp == 0x0D) temp++;
- if (*temp == 0x0A) header_founded = 1;
- }
+ {
+ /* test if it is the header end */
+ temp ++;
+ if (*temp == 0x0D) temp++;
+ if (*temp == 0x0A) header_founded = 1;
+ }
else
- temp++;
+ temp++;
}
*temp = 0;
temp++;
sscanf(data,"HTTP/1.%*d %03d",&error_code);
if (error_code != 200)
@@ -233,17 +234,17 @@ libstocks_return_code http_get(char *http_file, char *http_server, char **pdata)
free(data);
return ERRPAHD;
}
if ((csv_ptr = malloc(strlen(temp)+1))==NULL)
{
free(data);
fprintf(stderr,"Memory allocating error (%s line %d)\n"
- ,__FILE__, __LINE__);
+ ,__FILE__, __LINE__);
exit(1);
}
memcpy(csv_ptr, temp, strlen(temp)+1);
free(data);
#ifdef DEBUG
printf(" CSV\n");