(http_lib.c) Cleanups

This commit is contained in:
twinaphex 2015-01-21 00:39:10 +01:00
parent 9e64ff2a86
commit 300e5ebd0d
2 changed files with 24 additions and 26 deletions

View File

@ -211,7 +211,10 @@ static http_retcode http_query(const char *command, const char *url,
ret=ERRCONN;
else
{
if (pfd) *pfd=s;
int n;
if (pfd)
*pfd=s;
/* create header */
if (proxy)
@ -251,12 +254,12 @@ static http_retcode http_query(const char *command, const char *url,
else
{
/* read result & check */
int linelen=http_read_line(s,header,MAXBUF-1);
n = http_read_line(s,header,MAXBUF-1);
#ifdef VERBOSE
fputs(header,stderr);
putc('\n',stderr);
#endif
if (linelen<=0)
if (n <= 0)
ret = ERRRDHD;
else if (sscanf(header, "HTTP/1.%*d %03d", (int*)&ret) != 1)
ret = ERRPAHD;
@ -331,11 +334,8 @@ http_retcode http_get(const char *filename,
char **pdata, int *plength, char *typebuf)
{
http_retcode ret;
char header[MAXBUF];
char *pc;
int fd;
int n,length=-1;
char header[MAXBUF], *pc;
int fd, n, length = -1;
if (!pdata)
return ERRNULL;
@ -387,7 +387,9 @@ http_retcode http_get(const char *filename,
close(fd);
return ERRMEM;
}
n = http_read_buffer(fd, *pdata, length);
close(fd);
if (n != length)
ret = ERRRDDT;
@ -422,13 +424,9 @@ http_retcode http_get(const char *filename,
**/
http_retcode http_head(const char *filename, int *plength, char *typebuf)
{
/* mostly copied from http_get : */
http_retcode ret;
char header[MAXBUF];
char *pc;
int fd;
int n,length=-1;
char header[MAXBUF], *pc;
int fd, n, length = -1;
if (plength)
*plength=0;
@ -436,6 +434,7 @@ http_retcode http_head(const char *filename, int *plength, char *typebuf)
*typebuf='\0';
ret=http_query("HEAD", filename, "", KEEP_OPEN, NULL, 0, &fd);
if (ret == 200)
{
while (1)
@ -559,5 +558,5 @@ http_retcode http_parse_url(char *url, char **pfilename)
fprintf(stderr,"host=(%s), port=%d, filename=(%s)\n",
http_server, http_port, *pfilename);
#endif
return OK0;
return 0;
}

View File

@ -48,7 +48,6 @@ typedef enum
ERR503 = 503, /* Service overloaded */
/* Succesful results */
OK0 = 0, /* successfully parsed */
OK201 = 201, /* Resource succesfully created */
OK200 = 200 /* Resource succesfully read */