Fix bugs in new HTTP server MIME body parsing code

Fixes 'rhizomeprotocol' test 24 HttpAddLocal.  Four tests still fail.
This commit is contained in:
Andrew Bettison 2013-10-28 12:08:57 +10:30
parent 2a9329c0c8
commit 8f60a4ceb5
5 changed files with 28 additions and 15 deletions

View File

@ -123,7 +123,7 @@ struct http_request {
bool_t *disable_tx_flag;
time_ms_t initiate_time; // time connection was initiated
time_ms_t idle_timeout; // disconnect if no bytes received for this long
struct sockaddr_in client_in_addr;
struct sockaddr_in client_sockaddr_in;
HTTP_REQUEST_PARSER parser; // current parser function
HTTP_REQUEST_PARSER handle_first_line; // called after first line is parsed
HTTP_REQUEST_PARSER handle_headers; // called after all headers are parsed

View File

@ -381,13 +381,12 @@ int rhizome_direct_addfile(rhizome_http_request *r, const char *remainder)
http_request_simple_response(&r->http, 405, NULL);
return 0;
}
if (cmp_sockaddr((struct sockaddr *)&r->http.client_in_addr, sizeof r->http.client_in_addr,
(struct sockaddr *)&config.rhizome.api.addfile.allow_host, sizeof config.rhizome.api.addfile.allow_host
) != 0
if ( r->http.client_sockaddr_in.sin_family != AF_INET
|| r->http.client_sockaddr_in.sin_addr.s_addr != config.rhizome.api.addfile.allow_host.s_addr
) {
INFOF("rhizome.api.addfile request received from %s, but is only allowed from %s",
alloca_sockaddr(&r->http.client_in_addr, sizeof r->http.client_in_addr),
alloca_sockaddr(&config.rhizome.api.addfile.allow_host, sizeof config.rhizome.api.addfile.allow_host)
INFOF("rhizome.api.addfile request received from %s, but is only allowed from AF_INET %s",
alloca_sockaddr(&r->http.client_sockaddr_in, sizeof r->http.client_sockaddr_in),
alloca_in_addr(&config.rhizome.api.addfile.allow_host)
);
rhizome_direct_clear_temporary_files(r);
http_request_simple_response(&r->http, 404, "<html><h1>Not available from here</h1></html>");

View File

@ -270,7 +270,7 @@ void rhizome_server_poll(struct sched_ent *alarm)
request->read_state.blob_fd = -1;
request->read_state.blob_rowid = -1;
if (peerip)
request->http.client_in_addr = *peerip;
request->http.client_sockaddr_in = *peerip;
request->http.handle_headers = rhizome_dispatch;
request->http.debug_flag = &config.debug.rhizome_httpd;
request->http.disable_tx_flag = &config.debug.rhizome_nohttptx;

View File

@ -313,6 +313,16 @@ strbuf strbuf_append_socket_type(strbuf sb, int type)
return sb;
}
strbuf strbuf_append_in_addr(strbuf sb, const struct in_addr *addr)
{
strbuf_sprintf(sb, " %u.%u.%u.%u",
((unsigned char *) &addr->s_addr)[0],
((unsigned char *) &addr->s_addr)[1],
((unsigned char *) &addr->s_addr)[2],
((unsigned char *) &addr->s_addr)[3]);
return sb;
}
strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *addr, socklen_t addrlen)
{
strbuf_append_socket_domain(sb, addr->sa_family);
@ -336,13 +346,9 @@ strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *addr, socklen_t
break;
case AF_INET: {
const struct sockaddr_in *addr_in = (const struct sockaddr_in *) addr;
strbuf_sprintf(sb, " %u.%u.%u.%u:%u",
((unsigned char *) &addr_in->sin_addr.s_addr)[0],
((unsigned char *) &addr_in->sin_addr.s_addr)[1],
((unsigned char *) &addr_in->sin_addr.s_addr)[2],
((unsigned char *) &addr_in->sin_addr.s_addr)[3],
ntohs(addr_in->sin_port)
);
strbuf_putc(sb, ' ');
strbuf_append_in_addr(sb, &addr_in->sin_addr);
strbuf_sprintf(sb, ":%u", ntohs(addr_in->sin_port));
if (addrlen != sizeof(struct sockaddr_in))
strbuf_sprintf(sb, " (addrlen=%d should be %zd)", (int)addrlen, sizeof(struct sockaddr_in));
}

View File

@ -117,6 +117,14 @@ strbuf strbuf_append_socket_domain(strbuf sb, int domain);
strbuf strbuf_append_socket_type(strbuf sb, int type);
#define alloca_socket_type(type) strbuf_str(strbuf_append_socket_type(strbuf_alloca(15), type))
/* Append a textual description of a struct in_addr (in network order) as IPv4
* quartet "N.N.N.N".
* @author Andrew Bettison <andrew@servalproject.com>
*/
struct in_addr;
strbuf strbuf_append_in_addr(strbuf sb, const struct in_addr *addr);
#define alloca_in_addr(addr) strbuf_str(strbuf_append_in_addr(strbuf_alloca(16), (const struct in_addr *)(addr)))
/* Append a textual description of a struct sockaddr_in.
* @author Andrew Bettison <andrew@servalproject.com>
*/