mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 15:43:56 +00:00
Fix bugs in new HTTP server MIME body parsing code
Fixes 'rhizomeprotocol' test 24 HttpAddLocal. Four tests still fail.
This commit is contained in:
parent
2a9329c0c8
commit
8f60a4ceb5
@ -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
|
||||
|
@ -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>");
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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>
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user