From d3f5c6e5983f6ae5777342b293e978c22f161211 Mon Sep 17 00:00:00 2001 From: gardners Date: Thu, 6 Sep 2012 13:21:13 +0930 Subject: [PATCH] Merged rhizome direct httpd back into main rhizome httpd server. bundles can be imported via HTTP POST multi-part form. #9 --- commandline.c | 2 -- rhizome.h | 2 -- rhizome_direct.c | 33 --------------------------------- rhizome_http.c | 5 ++++- serval.h | 2 -- 5 files changed, 4 insertions(+), 40 deletions(-) diff --git a/commandline.c b/commandline.c index bb455cf1..7caefbee 100644 --- a/commandline.c +++ b/commandline.c @@ -1783,8 +1783,6 @@ command_line_option command_line_options[]={ "Extract a manifest from Rhizome and write it to the given path"}, {app_rhizome_extract_file,{"rhizome","extract","file","","[]","[]",NULL},CLIFLAG_STANDALONE, "Extract a file from Rhizome and write it to the given path"}, - {app_rhizome_direct_server,{"rhizome","direct","server",NULL},CLIFLAG_STANDALONE, - "Listen for Rhizome Direct requests"}, {app_rhizome_direct_sync,{"rhizome","direct","sync","",NULL}, CLIFLAG_STANDALONE, "Synchronise with the specified Rhizome Direct server. Return when done."}, diff --git a/rhizome.h b/rhizome.h index 94588cee..850b3383 100644 --- a/rhizome.h +++ b/rhizome.h @@ -43,8 +43,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #define RHIZOME_HTTP_PORT 4110 #define RHIZOME_HTTP_PORT_MAX 4150 -#define RHIZOME_DIRECT_PORT 4100 -#define RHIZOME_DIRECT_PORT_MAX 4109 extern time_ms_t rhizome_voice_timeout; diff --git a/rhizome_direct.c b/rhizome_direct.c index f20183e7..982a5dac 100644 --- a/rhizome_direct.c +++ b/rhizome_direct.c @@ -564,39 +564,6 @@ int rhizome_direct_parse_http_request(rhizome_http_request *r) return 0; } -int app_rhizome_direct_server(int argc, const char *const *argv, - struct command_line_option *o) -{ - /* Start Rhizome Direct server on configured port. - We re-use the Rhizome HTTP server code as much as possible here, - just replacing the server and client poll functions with our own. - */ - - int port_low=confValueGetInt64Range("rhizome.direct.port",RHIZOME_DIRECT_PORT, - 0,65535); - int port_high=confValueGetInt64Range("rhizome.direct.port_max",RHIZOME_DIRECT_PORT_MAX, - port_low,65535); - - /* Rhizome direct mode doesn't need all of the normal servald preparation, because - rhizome direct just needs to listen on its port, talk to other rhizome direct - daemons, and query the rhizome database directly. So we probably just need to - read configuration settings so that we can access the rhizome sqlite database. - */ - - /* Start rhizome direct http server */ - rhizome_http_server_start(rhizome_direct_parse_http_request, - "rhizome_direct_parse_http_request", - port_low,port_high); - - /* Respond to events */ - while(1) { - /* Check for activitiy and respond to it */ - fd_poll(); - } - - return 0; -} - int app_rhizome_direct_sync(int argc, const char *const *argv, struct command_line_option *o) { diff --git a/rhizome_http.c b/rhizome_http.c index 03338f7b..b3bed7ed 100644 --- a/rhizome_http.c +++ b/rhizome_http.c @@ -473,6 +473,7 @@ int http_header_complete(const char *buf, size_t len, size_t tail) return count == 2; } +int rhizome_direct_parse_http_request(rhizome_http_request *r); int rhizome_server_parse_http_request(rhizome_http_request *r) { /* Switching to writing, so update the call-back */ @@ -483,7 +484,9 @@ int rhizome_server_parse_http_request(rhizome_http_request *r) // Parse the HTTP "GET" line. char *path = NULL; size_t pathlen = 0; - if (str_startswith(r->request, "GET ", &path)) { + if (str_startswith(r->request, "POST ", &path)) { + return rhizome_direct_parse_http_request(r); + } else if (str_startswith(r->request, "GET ", &path)) { char *p; // This loop is guaranteed to terminate before the end of the buffer, because we know that the // buffer contains at least "\n\n" and maybe "\r\n\r\n" at the end of the header block. diff --git a/serval.h b/serval.h index 878cd6bc..27fe5c8e 100644 --- a/serval.h +++ b/serval.h @@ -1057,8 +1057,6 @@ int overlay_broadcast_ensemble(int interface_number, int app_rhizome_direct_sync(int argc, const char *const *argv, struct command_line_option *o); -int app_rhizome_direct_server(int argc, const char *const *argv, - struct command_line_option *o); #ifdef HAVE_VOIPTEST int app_pa_phone(int argc, const char *const *argv, struct command_line_option *o);