Base changes to HTTP.c on correct file version

This commit is contained in:
Simon Robertshaw 2012-05-09 21:12:10 +01:00
parent aeb383742f
commit 0c8fae82c7

View File

@ -6,7 +6,7 @@
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
@ -15,8 +15,7 @@
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program. If not, see <http://www.gnu.org/licenses/>.
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/ */
@ -230,26 +229,26 @@ void *http_async_req_start(void *ctx, char *uri, char *data, int dlen, int keep)
cx = ctx; cx = ctx;
cx->fd = PERROR; cx->fd = PERROR;
} }
if (!cx->hbuf) if (!cx->hbuf)
{ {
cx->hbuf = malloc(256); cx->hbuf = malloc(256);
cx->hlen = 256; cx->hlen = 256;
} }
if (!http_up) if (!http_up)
{ {
cx->ret = 604; cx->ret = 604;
cx->state = HTS_DONE; cx->state = HTS_DONE;
return ctx; return ctx;
} }
if (cx->state!=HTS_STRT && cx->state!=HTS_IDLE) if (cx->state!=HTS_STRT && cx->state!=HTS_IDLE)
{ {
fprintf(stderr, "HTTP: unclean request restart state.\n"); fprintf(stderr, "HTTP: unclean request restart state.\n");
exit(1); exit(1);
} }
cx->keep = keep; cx->keep = keep;
cx->ret = 600; cx->ret = 600;
if (splituri(uri, &cx->host, &cx->path)) if (splituri(uri, &cx->host, &cx->path))
@ -281,18 +280,18 @@ void *http_async_req_start(void *ctx, char *uri, char *data, int dlen, int keep)
} }
else else
cx->txdl = 0; cx->txdl = 0;
cx->contlen = 0; cx->contlen = 0;
cx->chunked = 0; cx->chunked = 0;
cx->chunkhdr = 0; cx->chunkhdr = 0;
cx->rxtogo = 0; cx->rxtogo = 0;
cx->cclose = 0; cx->cclose = 0;
cx->tptr = 0; cx->tptr = 0;
cx->tlen = 0; cx->tlen = 0;
cx->last = time(NULL); cx->last = time(NULL);
return ctx; return ctx;
} }
@ -359,7 +358,7 @@ static void process_byte(struct http_ctx *cx, char ch)
if (cx->rxtogo) if (cx->rxtogo)
{ {
cx->rxtogo--; cx->rxtogo--;
if (!cx->rbuf) if (!cx->rbuf)
{ {
cx->rbuf = malloc(256); cx->rbuf = malloc(256);
@ -371,7 +370,7 @@ static void process_byte(struct http_ctx *cx, char ch)
cx->rbuf = realloc(cx->rbuf, cx->rlen); cx->rbuf = realloc(cx->rbuf, cx->rlen);
} }
cx->rbuf[cx->rptr++] = ch; cx->rbuf[cx->rptr++] = ch;
if (!cx->rxtogo && !cx->chunked) if (!cx->rxtogo && !cx->chunked)
cx->state = HTS_DONE; cx->state = HTS_DONE;
} }
@ -404,173 +403,173 @@ int http_async_req_status(void *ctx)
#ifdef WIN32 #ifdef WIN32
unsigned long tmp2; unsigned long tmp2;
#endif #endif
switch (cx->state) switch (cx->state)
{ {
case HTS_STRT: case HTS_STRT:
dns = getserv(cx->host); dns = getserv(cx->host);
srv = getport(cx->host); srv = getport(cx->host);
if (resolve(dns, srv, &cx->addr)) if (resolve(dns, srv, &cx->addr))
{ {
free(dns); free(dns);
free(srv); free(srv);
cx->state = HTS_DONE; cx->state = HTS_DONE;
cx->ret = 602; cx->ret = 602;
return 1; return 1;
} }
free(dns); free(dns);
free(srv); free(srv);
cx->state = HTS_RSLV; cx->state = HTS_RSLV;
return 0; return 0;
case HTS_RSLV: case HTS_RSLV:
cx->state = HTS_CONN; cx->state = HTS_CONN;
cx->last = now; cx->last = now;
return 0; return 0;
case HTS_CONN: case HTS_CONN:
if (cx->fd == PERROR) if (cx->fd == PERROR)
{ {
cx->fd = socket(AF_INET, SOCK_STREAM, 0); cx->fd = socket(AF_INET, SOCK_STREAM, 0);
if (cx->fd == PERROR) if (cx->fd == PERROR)
goto fail; goto fail;
cx->fdhost = mystrdup(cx->host); cx->fdhost = mystrdup(cx->host);
#ifdef WIN32 #ifdef WIN32
tmp2 = 1; tmp2 = 1;
if (ioctlsocket(cx->fd, FIONBIO, &tmp2) == SOCKET_ERROR) if (ioctlsocket(cx->fd, FIONBIO, &tmp2) == SOCKET_ERROR)
goto fail; goto fail;
#else #else
tmp = fcntl(cx->fd, F_GETFL); tmp = fcntl(cx->fd, F_GETFL);
if (tmp < 0) if (tmp < 0)
goto fail; goto fail;
if (fcntl(cx->fd, F_SETFL, tmp|O_NONBLOCK) < 0) if (fcntl(cx->fd, F_SETFL, tmp|O_NONBLOCK) < 0)
goto fail; goto fail;
#endif #endif
} }
if (!connect(cx->fd, (struct sockaddr *)&cx->addr, sizeof(cx->addr))) if (!connect(cx->fd, (struct sockaddr *)&cx->addr, sizeof(cx->addr)))
cx->state = HTS_IDLE; cx->state = HTS_IDLE;
#ifdef WIN32 #ifdef WIN32
else if (PERRNO==WSAEISCONN) else if (PERRNO==WSAEISCONN)
cx->state = HTS_IDLE; cx->state = HTS_IDLE;
#endif #endif
#if defined(MACOSX) || defined(BSD) #if defined(MACOSX) || defined(BSD)
else if (PERRNO==EISCONN) else if (PERRNO==EISCONN)
cx->state = HTS_IDLE; cx->state = HTS_IDLE;
#endif #endif
else if (PERRNO!=PEINPROGRESS && PERRNO!=PEALREADY else if (PERRNO!=PEINPROGRESS && PERRNO!=PEALREADY
#ifdef WIN32 #ifdef WIN32
&& PERRNO!=PEAGAIN && PERRNO!=WSAEINVAL && PERRNO!=PEAGAIN && PERRNO!=WSAEINVAL
#endif #endif
) )
goto fail; goto fail;
if (now-cx->last>http_timeout) if (now-cx->last>http_timeout)
goto timeout; goto timeout;
return 0; return 0;
case HTS_IDLE: case HTS_IDLE:
if (cx->txdl) if (cx->txdl)
{ {
// generate POST // generate POST
cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) + 127 + cx->txdl + cx->thlen); cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) + 126 + cx->txdl + cx->thlen);
cx->tptr = 0; cx->tptr = 0;
cx->tlen = 0; cx->tlen = 0;
cx->tlen += sprintf(cx->tbuf+cx->tlen, "POST %s HTTP/1.1\r\n", cx->path); cx->tlen += sprintf(cx->tbuf+cx->tlen, "POST %s HTTP/1.1\r\n", cx->path);
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\r\n", cx->host); cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\r\n", cx->host);
if (!cx->keep) if (!cx->keep)
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\r\n"); cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\r\n");
if (cx->thdr) if (cx->thdr)
{ {
memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen); memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen);
cx->tlen += cx->thlen; cx->tlen += cx->thlen;
free(cx->thdr); free(cx->thdr);
cx->thdr = NULL; cx->thdr = NULL;
cx->thlen = 0; cx->thlen = 0;
} }
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Content-Length: %d\r\n", cx->txdl); cx->tlen += sprintf(cx->tbuf+cx->tlen, "Content-Length: %d\r\n", cx->txdl);
#ifdef BETA #ifdef BETA
cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\r\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION); cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\r\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
#else #else
cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\r\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION); cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\r\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
#endif #endif
cx->tlen += sprintf(cx->tbuf+cx->tlen, "\r\n"); cx->tlen += sprintf(cx->tbuf+cx->tlen, "\r\n");
memcpy(cx->tbuf+cx->tlen, cx->txd, cx->txdl); memcpy(cx->tbuf+cx->tlen, cx->txd, cx->txdl);
cx->tlen += cx->txdl; cx->tlen += cx->txdl;
free(cx->txd); free(cx->txd);
cx->txd = NULL; cx->txd = NULL;
cx->txdl = 0; cx->txdl = 0;
} }
else else
{ {
// generate GET // generate GET
cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) + 95 + cx->thlen); cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) +93 + cx->thlen);
cx->tptr = 0; cx->tptr = 0;
cx->tlen = 0; cx->tlen = 0;
cx->tlen += sprintf(cx->tbuf+cx->tlen, "GET %s HTTP/1.1\r\n", cx->path); cx->tlen += sprintf(cx->tbuf+cx->tlen, "GET %s HTTP/1.1\r\n", cx->path);
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\r\n", cx->host); cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\r\n", cx->host);
if (cx->thdr) if (cx->thdr)
{ {
memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen); memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen);
cx->tlen += cx->thlen; cx->tlen += cx->thlen;
free(cx->thdr); free(cx->thdr);
cx->thdr = NULL; cx->thdr = NULL;
cx->thlen = 0; cx->thlen = 0;
} }
if (!cx->keep) if (!cx->keep)
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\r\n"); cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\r\n");
#ifdef BETA #ifdef BETA
cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\r\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION); cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\r\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
#else #else
cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\r\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION); cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\r\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
#endif #endif
cx->tlen += sprintf(cx->tbuf+cx->tlen, "\r\n"); cx->tlen += sprintf(cx->tbuf+cx->tlen, "\r\n");
} }
cx->state = HTS_XMIT; cx->state = HTS_XMIT;
cx->last = now; cx->last = now;
return 0; return 0;
case HTS_XMIT: case HTS_XMIT:
tmp = send(cx->fd, cx->tbuf+cx->tptr, cx->tlen-cx->tptr, 0); tmp = send(cx->fd, cx->tbuf+cx->tptr, cx->tlen-cx->tptr, 0);
if (tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR) if (tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR)
goto fail; goto fail;
if (tmp!=PERROR) if (tmp!=PERROR)
{ {
cx->tptr += tmp; cx->tptr += tmp;
if (cx->tptr == cx->tlen) if (cx->tptr == cx->tlen)
{ {
cx->tptr = 0; cx->tptr = 0;
cx->tlen = 0; cx->tlen = 0;
if (cx->tbuf) if (cx->tbuf)
free(cx->tbuf); free(cx->tbuf);
cx->state = HTS_RECV; cx->state = HTS_RECV;
} }
cx->last = now; cx->last = now;
} }
if (now-cx->last>http_timeout) if (now-cx->last>http_timeout)
goto timeout; goto timeout;
return 0; return 0;
case HTS_RECV: case HTS_RECV:
tmp = recv(cx->fd, buf, CHUNK, 0); tmp = recv(cx->fd, buf, CHUNK, 0);
if (tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR) if (tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR)
goto fail; goto fail;
if (tmp!=PERROR) if (tmp!=PERROR)
{ {
for (i=0; i<tmp; i++) for (i=0; i<tmp; i++)
{ {
process_byte(cx, buf[i]); process_byte(cx, buf[i]);
if (cx->state == HTS_DONE) if (cx->state == HTS_DONE)
return 1; return 1;
} }
cx->last = now; cx->last = now;
} }
if (now-cx->last>http_timeout) if (now-cx->last>http_timeout)
goto timeout; goto timeout;
return 0; return 0;
case HTS_DONE: case HTS_DONE:
return 1; return 1;
} }
return 0; return 0;
fail: fail:
cx->ret = 600; cx->ret = 600;
cx->state = HTS_DONE; cx->state = HTS_DONE;
return 1; return 1;
timeout: timeout:
cx->ret = 605; cx->ret = 605;
cx->state = HTS_DONE; cx->state = HTS_DONE;
@ -581,10 +580,10 @@ char *http_async_req_stop(void *ctx, int *ret, int *len)
{ {
struct http_ctx *cx = ctx; struct http_ctx *cx = ctx;
char *rxd; char *rxd;
if (cx->state != HTS_DONE) if (cx->state != HTS_DONE)
while (!http_async_req_status(ctx)) ; while (!http_async_req_status(ctx)) ;
if (cx->host) if (cx->host)
{ {
free(cx->host); free(cx->host);
@ -612,7 +611,7 @@ char *http_async_req_stop(void *ctx, int *ret, int *len)
cx->thdr = NULL; cx->thdr = NULL;
cx->thlen = 0; cx->thlen = 0;
} }
if (ret) if (ret)
*ret = cx->ret; *ret = cx->ret;
if (len) if (len)
@ -624,7 +623,7 @@ char *http_async_req_stop(void *ctx, int *ret, int *len)
cx->rlen = 0; cx->rlen = 0;
cx->rptr = 0; cx->rptr = 0;
cx->contlen = 0; cx->contlen = 0;
if (!cx->keep) if (!cx->keep)
http_async_req_close(ctx); http_async_req_close(ctx);
else if (cx->cclose) else if (cx->cclose)
@ -640,7 +639,7 @@ char *http_async_req_stop(void *ctx, int *ret, int *len)
} }
else else
cx->state = HTS_IDLE; cx->state = HTS_IDLE;
return rxd; return rxd;
} }
@ -691,7 +690,7 @@ void http_auth_headers(void *ctx, char *user, char *pass, char *session_id)
unsigned char hash[16]; unsigned char hash[16];
unsigned int m; unsigned int m;
struct md5_context md5; struct md5_context md5;
if (user) if (user)
{ {
if (pass) if (pass)
@ -700,7 +699,7 @@ void http_auth_headers(void *ctx, char *user, char *pass, char *session_id)
md5_update(&md5, (unsigned char *)user, strlen(user)); md5_update(&md5, (unsigned char *)user, strlen(user));
md5_update(&md5, (unsigned char *)"-", 1); md5_update(&md5, (unsigned char *)"-", 1);
m = 0; m = 0;
md5_update(&md5, (unsigned char *)pass, strlen(pass)); md5_update(&md5, (unsigned char *)pass, strlen(pass));
md5_final(hash, &md5); md5_final(hash, &md5);
tmp = malloc(33); tmp = malloc(33);
@ -727,7 +726,7 @@ void http_auth_headers(void *ctx, char *user, char *pass, char *session_id)
char *http_auth_get(char *uri, char *user, char *pass, char *session_id, int *ret, int *len) char *http_auth_get(char *uri, char *user, char *pass, char *session_id, int *ret, int *len)
{ {
void *ctx = http_async_req_start(NULL, uri, NULL, 0, 0); void *ctx = http_async_req_start(NULL, uri, NULL, 0, 0);
if (!ctx) if (!ctx)
{ {
if (ret) if (ret)
@ -757,137 +756,137 @@ char *http_ret_text(int ret)
{ {
switch (ret) switch (ret)
{ {
case 100: case 100:
return "Continue"; return "Continue";
case 101: case 101:
return "Switching Protocols"; return "Switching Protocols";
case 102: case 102:
return "Processing"; return "Processing";
case 200: case 200:
return "OK"; return "OK";
case 201: case 201:
return "Created"; return "Created";
case 202: case 202:
return "Accepted"; return "Accepted";
case 203: case 203:
return "Non-Authoritative Information"; return "Non-Authoritative Information";
case 204: case 204:
return "No Content"; return "No Content";
case 205: case 205:
return "Reset Content"; return "Reset Content";
case 206: case 206:
return "Partial Content"; return "Partial Content";
case 207: case 207:
return "Multi-Status"; return "Multi-Status";
case 300: case 300:
return "Multiple Choices"; return "Multiple Choices";
case 301: case 301:
return "Moved Permanently"; return "Moved Permanently";
case 302: case 302:
return "Found"; return "Found";
case 303: case 303:
return "See Other"; return "See Other";
case 304: case 304:
return "Not Modified"; return "Not Modified";
case 305: case 305:
return "Use Proxy"; return "Use Proxy";
case 306: case 306:
return "Switch Proxy"; return "Switch Proxy";
case 307: case 307:
return "Temporary Redirect"; return "Temporary Redirect";
case 400: case 400:
return "Bad Request"; return "Bad Request";
case 401: case 401:
return "Unauthorized"; return "Unauthorized";
case 402: case 402:
return "Payment Required"; return "Payment Required";
case 403: case 403:
return "Forbidden"; return "Forbidden";
case 404: case 404:
return "Not Found"; return "Not Found";
case 405: case 405:
return "Method Not Allowed"; return "Method Not Allowed";
case 406: case 406:
return "Not Acceptable"; return "Not Acceptable";
case 407: case 407:
return "Proxy Authentication Required"; return "Proxy Authentication Required";
case 408: case 408:
return "Request Timeout"; return "Request Timeout";
case 409: case 409:
return "Conflict"; return "Conflict";
case 410: case 410:
return "Gone"; return "Gone";
case 411: case 411:
return "Length Required"; return "Length Required";
case 412: case 412:
return "Precondition Failed"; return "Precondition Failed";
case 413: case 413:
return "Request Entity Too Large"; return "Request Entity Too Large";
case 414: case 414:
return "Request URI Too Long"; return "Request URI Too Long";
case 415: case 415:
return "Unsupported Media Type"; return "Unsupported Media Type";
case 416: case 416:
return "Requested Range Not Satisfiable"; return "Requested Range Not Satisfiable";
case 417: case 417:
return "Expectation Failed"; return "Expectation Failed";
case 418: case 418:
return "I'm a teapot"; return "I'm a teapot";
case 422: case 422:
return "Unprocessable Entity"; return "Unprocessable Entity";
case 423: case 423:
return "Locked"; return "Locked";
case 424: case 424:
return "Failed Dependency"; return "Failed Dependency";
case 425: case 425:
return "Unordered Collection"; return "Unordered Collection";
case 426: case 426:
return "Upgrade Required"; return "Upgrade Required";
case 444: case 444:
return "No Response"; return "No Response";
case 450: case 450:
return "Blocked by Windows Parental Controls"; return "Blocked by Windows Parental Controls";
case 499: case 499:
return "Client Closed Request"; return "Client Closed Request";
case 500: case 500:
return "Internal Server Error"; return "Internal Server Error";
case 501: case 501:
return "Not Implemented"; return "Not Implemented";
case 502: case 502:
return "Bad Gateway"; return "Bad Gateway";
case 503: case 503:
return "Service Unavailable"; return "Service Unavailable";
case 504: case 504:
return "Gateway Timeout"; return "Gateway Timeout";
case 505: case 505:
return "HTTP Version Not Supported"; return "HTTP Version Not Supported";
case 506: case 506:
return "Variant Also Negotiates"; return "Variant Also Negotiates";
case 507: case 507:
return "Insufficient Storage"; return "Insufficient Storage";
case 509: case 509:
return "Bandwidth Limit Exceeded"; return "Bandwidth Limit Exceeded";
case 510: case 510:
return "Not Extended"; return "Not Extended";
case 600: case 600:
return "Internal Client Error"; return "Internal Client Error";
case 601: case 601:
return "Unsupported Protocol"; return "Unsupported Protocol";
case 602: case 602:
return "Server Not Found"; return "Server Not Found";
case 603: case 603:
return "Malformed Response"; return "Malformed Response";
case 604: case 604:
return "Network Not Available"; return "Network Not Available";
case 605: case 605:
return "Request Timed Out"; return "Request Timed Out";
default: default:
return "Unknown Status Code"; return "Unknown Status Code";
} }
} }
char *http_multipart_post(char *uri, char **names, char **parts, int *plens, char *user, char *pass, char *session_id, int *ret, int *len) char *http_multipart_post(char *uri, char **names, char **parts, int *plens, char *user, char *pass, char *session_id, int *ret, int *len)
@ -902,7 +901,7 @@ char *http_multipart_post(char *uri, char **names, char **parts, int *plens, cha
struct md5_context md5; struct md5_context md5;
//struct md5_context md52; //struct md5_context md52;
int own_plen = 0; int own_plen = 0;
if (names) if (names)
{ {
if (!plens) if (!plens)
@ -913,8 +912,8 @@ char *http_multipart_post(char *uri, char **names, char **parts, int *plens, cha
for (i=0; names[i]; i++) for (i=0; names[i]; i++)
plens[i] = strlen(parts[i]); plens[i] = strlen(parts[i]);
} }
retry: retry:
if (blen >= 31) if (blen >= 31)
goto fail; goto fail;
memset(map, 0, 62*sizeof(int)); memset(map, 0, 62*sizeof(int));
@ -950,7 +949,7 @@ char *http_multipart_post(char *uri, char **names, char **parts, int *plens, cha
if (map[j]) if (map[j])
goto retry; goto retry;
boundary[blen] = 0; boundary[blen] = 0;
for (i=0; names[i]; i++) for (i=0; names[i]; i++)
dlen += blen+strlen(names[i])+plens[i]+128; dlen += blen+strlen(names[i])+plens[i]+128;
dlen += blen+8; dlen += blen+8;
@ -978,11 +977,11 @@ char *http_multipart_post(char *uri, char **names, char **parts, int *plens, cha
} }
dlen += sprintf(data+dlen, "--%s--\r\n", boundary); dlen += sprintf(data+dlen, "--%s--\r\n", boundary);
} }
ctx = http_async_req_start(NULL, uri, data, dlen, 0); ctx = http_async_req_start(NULL, uri, data, dlen, 0);
if (!ctx) if (!ctx)
goto fail; goto fail;
if (user) if (user)
{ {
//http_async_add_header(ctx, "X-Auth-User", user); //http_async_add_header(ctx, "X-Auth-User", user);
@ -1004,7 +1003,7 @@ char *http_multipart_post(char *uri, char **names, char **parts, int *plens, cha
else else
m += strlen(names[i])+1; m += strlen(names[i])+1;
} }
tmp = malloc(m); tmp = malloc(m);
m = 0; m = 0;
for (i=0; names[i]; i++) for (i=0; names[i]; i++)
@ -1030,7 +1029,7 @@ char *http_multipart_post(char *uri, char **names, char **parts, int *plens, cha
http_async_add_header(ctx, "X-Auth-Objects", tmp); http_async_add_header(ctx, "X-Auth-Objects", tmp);
free(tmp); free(tmp);
} }
md5_update(&md5, (unsigned char *)pass, strlen(pass)); md5_update(&md5, (unsigned char *)pass, strlen(pass));
md5_final(hash, &md5); md5_final(hash, &md5);
tmp = malloc(33); tmp = malloc(33);
@ -1053,7 +1052,7 @@ char *http_multipart_post(char *uri, char **names, char **parts, int *plens, cha
http_async_add_header(ctx, "X-Auth-User", user); http_async_add_header(ctx, "X-Auth-User", user);
} }
} }
if (data) if (data)
{ {
tmp = malloc(32+strlen((char *)boundary)); tmp = malloc(32+strlen((char *)boundary));
@ -1062,11 +1061,11 @@ char *http_multipart_post(char *uri, char **names, char **parts, int *plens, cha
free(tmp); free(tmp);
free(data); free(data);
} }
if (own_plen) if (own_plen)
free(plens); free(plens);
return http_async_req_stop(ctx, ret, len); return http_async_req_stop(ctx, ret, len);
fail: fail:
if (data) if (data)
free(data); free(data);