diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2014-11-29 17:05:31 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2014-11-29 17:05:31 +0100 |
commit | f2eb844d53f16586b67e4d753b705838808567d9 (patch) | |
tree | 520236dc25ec6648f332a51e50ab820e37bf1f56 /src/webserver.c | |
parent | 1135bfb7aa76ea4ec5cff756cc6f0f98332e9828 (diff) | |
download | biruda-f2eb844d53f16586b67e4d753b705838808567d9.tar.gz biruda-f2eb844d53f16586b67e4d753b705838808567d9.tar.bz2 |
fixed POST in http_lib
changed POST request for starting workers and added proper error handling
whole chain is working now
Diffstat (limited to 'src/webserver.c')
-rw-r--r-- | src/webserver.c | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/src/webserver.c b/src/webserver.c index 8093ec8..0b299ed 100644 --- a/src/webserver.c +++ b/src/webserver.c @@ -53,30 +53,47 @@ static int handle_request( void *cls, struct MHD_Connection *connection, MHD_destroy_response( response ); } else if( strcmp( method, "POST" ) == 0 ) { - - const char *op = MHD_lookup_connection_value( connection, MHD_GET_ARGUMENT_KIND, "op" ); - printf( "Got POST operation '%s'\n", op ); - - if( strcmp( op, "start" ) == 0 ) { - - const char *type = MHD_lookup_connection_value( connection, MHD_GET_ARGUMENT_KIND, "type" ); + if( strcmp( url, "/worker" ) == 0 ) { + + char biruda_msg[2048]; + biruda_msg[0] = '\0'; - printf( "Got POST parameter for type of process '%s'\n", type ); + const char *op = MHD_lookup_connection_value( connection, MHD_GET_ARGUMENT_KIND, "op" ); + + printf( "Got POST operation '%s'\n", op ); - if( strcmp( type, "worker" ) == 0 ) { + if( op != NULL && strcmp( op, "start" ) == 0 ) { const char *name = MHD_lookup_connection_value( connection, MHD_GET_ARGUMENT_KIND, "name" ); - printf( "Got POST parameter for starting a worker with name '%s'\n", name ); + if( name != NULL ) { - master_start_worker( name ); + printf( "Got POST parameter for starting a worker with name '%s'\n", name ); + + int res = master_start_worker( name ); + + if( res < 0 ) { + snprintf( biruda_msg, sizeof( biruda_msg ), "Queueing start request message failed\n" ); + } else { + snprintf( biruda_msg, sizeof( biruda_msg ), "Queued start worker request\n" ); + } + + response = MHD_create_response_from_buffer( strlen( biruda_msg ), + (void *)biruda_msg, MHD_RESPMEM_MUST_COPY ); + ret = MHD_queue_response( connection, ( res == 0 ) ? MHD_HTTP_OK : MHD_HTTP_INTERNAL_SERVER_ERROR, response ); + MHD_destroy_response( response ); + } + } else { + return MHD_NO; } + } else { + return MHD_NO; } - + } else { return MHD_NO; } - + return ret; } |