Issue #9, a little bit of refactoring

This commit is contained in:
Andrew Bettison 2012-10-04 14:35:09 +09:30
parent 3040d2b665
commit 9614d4f89c

View File

@ -574,7 +574,7 @@ int rhizome_direct_process_post_multipart_bytes(rhizome_http_request *r,const ch
int rhizome_direct_parse_http_request(rhizome_http_request *r)
{
const char *submitBareFileURI=confValueGet("rhizome.api.addfile.uri", NULL);
DEBUGF("uri='%s'",submitBareFileURI?submitBareFileURI:"(null)");
DEBUGF("uri=%s", submitBareFileURI ? alloca_str_toprint(submitBareFileURI) : "NULL");
/* Switching to writing, so update the call-back */
r->alarm.poll.events=POLLOUT;
@ -621,17 +621,15 @@ int rhizome_direct_parse_http_request(rhizome_http_request *r)
INFOF("RHIZOME HTTP SERVER, %s %s %s", verb, alloca_toprint(-1, path, pathlen), proto);
if (debug & DEBUG_RHIZOME_TX)
DEBUGF("headers %s", alloca_toprint(-1, headers, headerlen));
if (strcmp(verb, "GET") == 0) {
if (strcmp(path, "/favicon.ico") == 0) {
if (strcmp(verb, "GET") == 0 && strcmp(path, "/favicon.ico") == 0) {
r->request_type = RHIZOME_HTTP_REQUEST_FAVICON;
rhizome_server_http_response_header(r, 200, "image/vnd.microsoft.icon", favicon_len);
} else {
rhizome_server_simple_http_response(r, 404, "<html><h1>Not found (GET)</h1></html>\r\n");
}
} else if (strcmp(verb, "POST") == 0) {
if (strcmp(path, "/rhizome/import") == 0
} else if (strcmp(verb, "POST") == 0
&& ( strcmp(path, "/rhizome/import") == 0
|| strcmp(path, "/rhizome/enquiry") == 0
|| (submitBareFileURI&&(strcmp(path, submitBareFileURI)==0))) {
|| (submitBareFileURI && strcmp(path, submitBareFileURI) == 0)
)
) {
const char *cl_str=str_str(headers,"Content-Length: ",headerlen);
const char *ct_str=str_str(headers,"Content-Type: multipart/form-data; boundary=",headerlen);
if (!cl_str)
@ -665,11 +663,11 @@ int rhizome_direct_parse_http_request(rhizome_http_request *r)
strbuf_puts(bs, "--");
strbuf_puts(bs, boundary_string);
if (strbuf_overrun(bs))
return rhizome_server_simple_http_response(r,500,"<html><h1>Server error: Multipart boundary string too long</h1></html>\r\n");
return rhizome_server_simple_http_response(r,500,"<html><h1>Internal server error: Multipart boundary string too long</h1></html>\r\n");
strbuf ps = strbuf_local(r->path, sizeof r->path);
strbuf_puts(ps, path);
if (strbuf_overrun(ps))
return rhizome_server_simple_http_response(r,500,"<html><h1>Server error: Path too long</h1></html>\r\n");
return rhizome_server_simple_http_response(r,500,"<html><h1>Internal server error: Path too long</h1></html>\r\n");
r->boundary_string_length = strbuf_len(bs);
r->source_index = 0;
r->source_count = content_length;
@ -689,9 +687,6 @@ int rhizome_direct_parse_http_request(rhizome_http_request *r)
/* Handle the rest of the transfer asynchronously. */
return 0;
} else {
rhizome_server_simple_http_response(r, 404, "<html><h1>Not found (POST)</h1></html>\r\n");
}
} else {
rhizome_server_simple_http_response(r, 404, "<html><h1>Not found (OTHER)</h1></html>\r\n");
}