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
* 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.
*
* This program is distributed in the hope that it will be useful,
@ -15,8 +15,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -407,162 +406,162 @@ int http_async_req_status(void *ctx)
switch (cx->state)
{
case HTS_STRT:
dns = getserv(cx->host);
srv = getport(cx->host);
if (resolve(dns, srv, &cx->addr))
{
free(dns);
free(srv);
cx->state = HTS_DONE;
cx->ret = 602;
return 1;
}
free(dns);
free(srv);
cx->state = HTS_RSLV;
return 0;
case HTS_RSLV:
cx->state = HTS_CONN;
cx->last = now;
return 0;
case HTS_CONN:
if (cx->fd == PERROR)
{
cx->fd = socket(AF_INET, SOCK_STREAM, 0);
if (cx->fd == PERROR)
goto fail;
cx->fdhost = mystrdup(cx->host);
case HTS_STRT:
dns = getserv(cx->host);
srv = getport(cx->host);
if (resolve(dns, srv, &cx->addr))
{
free(dns);
free(srv);
cx->state = HTS_DONE;
cx->ret = 602;
return 1;
}
free(dns);
free(srv);
cx->state = HTS_RSLV;
return 0;
case HTS_RSLV:
cx->state = HTS_CONN;
cx->last = now;
return 0;
case HTS_CONN:
if (cx->fd == PERROR)
{
cx->fd = socket(AF_INET, SOCK_STREAM, 0);
if (cx->fd == PERROR)
goto fail;
cx->fdhost = mystrdup(cx->host);
#ifdef WIN32
tmp2 = 1;
if (ioctlsocket(cx->fd, FIONBIO, &tmp2) == SOCKET_ERROR)
goto fail;
tmp2 = 1;
if (ioctlsocket(cx->fd, FIONBIO, &tmp2) == SOCKET_ERROR)
goto fail;
#else
tmp = fcntl(cx->fd, F_GETFL);
if (tmp < 0)
goto fail;
if (fcntl(cx->fd, F_SETFL, tmp|O_NONBLOCK) < 0)
goto fail;
tmp = fcntl(cx->fd, F_GETFL);
if (tmp < 0)
goto fail;
if (fcntl(cx->fd, F_SETFL, tmp|O_NONBLOCK) < 0)
goto fail;
#endif
}
if (!connect(cx->fd, (struct sockaddr *)&cx->addr, sizeof(cx->addr)))
cx->state = HTS_IDLE;
}
if (!connect(cx->fd, (struct sockaddr *)&cx->addr, sizeof(cx->addr)))
cx->state = HTS_IDLE;
#ifdef WIN32
else if (PERRNO==WSAEISCONN)
cx->state = HTS_IDLE;
else if (PERRNO==WSAEISCONN)
cx->state = HTS_IDLE;
#endif
#if defined(MACOSX) || defined(BSD)
else if (PERRNO==EISCONN)
cx->state = HTS_IDLE;
else if (PERRNO==EISCONN)
cx->state = HTS_IDLE;
#endif
else if (PERRNO!=PEINPROGRESS && PERRNO!=PEALREADY
else if (PERRNO!=PEINPROGRESS && PERRNO!=PEALREADY
#ifdef WIN32
&& PERRNO!=PEAGAIN && PERRNO!=WSAEINVAL
&& PERRNO!=PEAGAIN && PERRNO!=WSAEINVAL
#endif
)
goto fail;
if (now-cx->last>http_timeout)
goto timeout;
return 0;
case HTS_IDLE:
if (cx->txdl)
{
// generate POST
cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) + 127 + cx->txdl + cx->thlen);
cx->tptr = 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, "Host: %s\r\n", cx->host);
if (!cx->keep)
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\r\n");
if (cx->thdr)
{
memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen);
cx->tlen += cx->thlen;
free(cx->thdr);
cx->thdr = NULL;
cx->thlen = 0;
}
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Content-Length: %d\r\n", cx->txdl);
)
goto fail;
if (now-cx->last>http_timeout)
goto timeout;
return 0;
case HTS_IDLE:
if (cx->txdl)
{
// generate POST
cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) + 126 + cx->txdl + cx->thlen);
cx->tptr = 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, "Host: %s\r\n", cx->host);
if (!cx->keep)
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\r\n");
if (cx->thdr)
{
memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen);
cx->tlen += cx->thlen;
free(cx->thdr);
cx->thdr = NULL;
cx->thlen = 0;
}
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Content-Length: %d\r\n", cx->txdl);
#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
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
cx->tlen += sprintf(cx->tbuf+cx->tlen, "\r\n");
memcpy(cx->tbuf+cx->tlen, cx->txd, cx->txdl);
cx->tlen += cx->txdl;
free(cx->txd);
cx->txd = NULL;
cx->txdl = 0;
}
else
{
// generate GET
cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) + 95 + cx->thlen);
cx->tptr = 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, "Host: %s\r\n", cx->host);
if (cx->thdr)
{
memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen);
cx->tlen += cx->thlen;
free(cx->thdr);
cx->thdr = NULL;
cx->thlen = 0;
}
if (!cx->keep)
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\r\n");
cx->tlen += sprintf(cx->tbuf+cx->tlen, "\r\n");
memcpy(cx->tbuf+cx->tlen, cx->txd, cx->txdl);
cx->tlen += cx->txdl;
free(cx->txd);
cx->txd = NULL;
cx->txdl = 0;
}
else
{
// generate GET
cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) +93 + cx->thlen);
cx->tptr = 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, "Host: %s\r\n", cx->host);
if (cx->thdr)
{
memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen);
cx->tlen += cx->thlen;
free(cx->thdr);
cx->thdr = NULL;
cx->thlen = 0;
}
if (!cx->keep)
cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\r\n");
#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
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
cx->tlen += sprintf(cx->tbuf+cx->tlen, "\r\n");
}
cx->state = HTS_XMIT;
cx->last = now;
return 0;
case HTS_XMIT:
tmp = send(cx->fd, cx->tbuf+cx->tptr, cx->tlen-cx->tptr, 0);
if (tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR)
goto fail;
if (tmp!=PERROR)
{
cx->tptr += tmp;
if (cx->tptr == cx->tlen)
{
cx->tptr = 0;
cx->tlen = 0;
if (cx->tbuf)
free(cx->tbuf);
cx->state = HTS_RECV;
}
cx->last = now;
}
if (now-cx->last>http_timeout)
goto timeout;
return 0;
case HTS_RECV:
tmp = recv(cx->fd, buf, CHUNK, 0);
if (tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR)
goto fail;
if (tmp!=PERROR)
{
for (i=0; i<tmp; i++)
{
process_byte(cx, buf[i]);
if (cx->state == HTS_DONE)
return 1;
}
cx->last = now;
}
if (now-cx->last>http_timeout)
goto timeout;
return 0;
case HTS_DONE:
return 1;
cx->tlen += sprintf(cx->tbuf+cx->tlen, "\r\n");
}
cx->state = HTS_XMIT;
cx->last = now;
return 0;
case HTS_XMIT:
tmp = send(cx->fd, cx->tbuf+cx->tptr, cx->tlen-cx->tptr, 0);
if (tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR)
goto fail;
if (tmp!=PERROR)
{
cx->tptr += tmp;
if (cx->tptr == cx->tlen)
{
cx->tptr = 0;
cx->tlen = 0;
if (cx->tbuf)
free(cx->tbuf);
cx->state = HTS_RECV;
}
cx->last = now;
}
if (now-cx->last>http_timeout)
goto timeout;
return 0;
case HTS_RECV:
tmp = recv(cx->fd, buf, CHUNK, 0);
if (tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR)
goto fail;
if (tmp!=PERROR)
{
for (i=0; i<tmp; i++)
{
process_byte(cx, buf[i]);
if (cx->state == HTS_DONE)
return 1;
}
cx->last = now;
}
if (now-cx->last>http_timeout)
goto timeout;
return 0;
case HTS_DONE:
return 1;
}
return 0;
@ -757,137 +756,137 @@ char *http_ret_text(int ret)
{
switch (ret)
{
case 100:
return "Continue";
case 101:
return "Switching Protocols";
case 102:
return "Processing";
case 100:
return "Continue";
case 101:
return "Switching Protocols";
case 102:
return "Processing";
case 200:
return "OK";
case 201:
return "Created";
case 202:
return "Accepted";
case 203:
return "Non-Authoritative Information";
case 204:
return "No Content";
case 205:
return "Reset Content";
case 206:
return "Partial Content";
case 207:
return "Multi-Status";
case 200:
return "OK";
case 201:
return "Created";
case 202:
return "Accepted";
case 203:
return "Non-Authoritative Information";
case 204:
return "No Content";
case 205:
return "Reset Content";
case 206:
return "Partial Content";
case 207:
return "Multi-Status";
case 300:
return "Multiple Choices";
case 301:
return "Moved Permanently";
case 302:
return "Found";
case 303:
return "See Other";
case 304:
return "Not Modified";
case 305:
return "Use Proxy";
case 306:
return "Switch Proxy";
case 307:
return "Temporary Redirect";
case 300:
return "Multiple Choices";
case 301:
return "Moved Permanently";
case 302:
return "Found";
case 303:
return "See Other";
case 304:
return "Not Modified";
case 305:
return "Use Proxy";
case 306:
return "Switch Proxy";
case 307:
return "Temporary Redirect";
case 400:
return "Bad Request";
case 401:
return "Unauthorized";
case 402:
return "Payment Required";
case 403:
return "Forbidden";
case 404:
return "Not Found";
case 405:
return "Method Not Allowed";
case 406:
return "Not Acceptable";
case 407:
return "Proxy Authentication Required";
case 408:
return "Request Timeout";
case 409:
return "Conflict";
case 410:
return "Gone";
case 411:
return "Length Required";
case 412:
return "Precondition Failed";
case 413:
return "Request Entity Too Large";
case 414:
return "Request URI Too Long";
case 415:
return "Unsupported Media Type";
case 416:
return "Requested Range Not Satisfiable";
case 417:
return "Expectation Failed";
case 418:
return "I'm a teapot";
case 422:
return "Unprocessable Entity";
case 423:
return "Locked";
case 424:
return "Failed Dependency";
case 425:
return "Unordered Collection";
case 426:
return "Upgrade Required";
case 444:
return "No Response";
case 450:
return "Blocked by Windows Parental Controls";
case 499:
return "Client Closed Request";
case 400:
return "Bad Request";
case 401:
return "Unauthorized";
case 402:
return "Payment Required";
case 403:
return "Forbidden";
case 404:
return "Not Found";
case 405:
return "Method Not Allowed";
case 406:
return "Not Acceptable";
case 407:
return "Proxy Authentication Required";
case 408:
return "Request Timeout";
case 409:
return "Conflict";
case 410:
return "Gone";
case 411:
return "Length Required";
case 412:
return "Precondition Failed";
case 413:
return "Request Entity Too Large";
case 414:
return "Request URI Too Long";
case 415:
return "Unsupported Media Type";
case 416:
return "Requested Range Not Satisfiable";
case 417:
return "Expectation Failed";
case 418:
return "I'm a teapot";
case 422:
return "Unprocessable Entity";
case 423:
return "Locked";
case 424:
return "Failed Dependency";
case 425:
return "Unordered Collection";
case 426:
return "Upgrade Required";
case 444:
return "No Response";
case 450:
return "Blocked by Windows Parental Controls";
case 499:
return "Client Closed Request";
case 500:
return "Internal Server Error";
case 501:
return "Not Implemented";
case 502:
return "Bad Gateway";
case 503:
return "Service Unavailable";
case 504:
return "Gateway Timeout";
case 505:
return "HTTP Version Not Supported";
case 506:
return "Variant Also Negotiates";
case 507:
return "Insufficient Storage";
case 509:
return "Bandwidth Limit Exceeded";
case 510:
return "Not Extended";
case 500:
return "Internal Server Error";
case 501:
return "Not Implemented";
case 502:
return "Bad Gateway";
case 503:
return "Service Unavailable";
case 504:
return "Gateway Timeout";
case 505:
return "HTTP Version Not Supported";
case 506:
return "Variant Also Negotiates";
case 507:
return "Insufficient Storage";
case 509:
return "Bandwidth Limit Exceeded";
case 510:
return "Not Extended";
case 600:
return "Internal Client Error";
case 601:
return "Unsupported Protocol";
case 602:
return "Server Not Found";
case 603:
return "Malformed Response";
case 604:
return "Network Not Available";
case 605:
return "Request Timed Out";
default:
return "Unknown Status Code";
case 600:
return "Internal Client Error";
case 601:
return "Unsupported Protocol";
case 602:
return "Server Not Found";
case 603:
return "Malformed Response";
case 604:
return "Network Not Available";
case 605:
return "Request Timed Out";
default:
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)
@ -914,7 +913,7 @@ char *http_multipart_post(char *uri, char **names, char **parts, int *plens, cha
plens[i] = strlen(parts[i]);
}
retry:
retry:
if (blen >= 31)
goto fail;
memset(map, 0, 62*sizeof(int));