summaryrefslogtreecommitdiff
path: root/src/webserver.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-11-23 19:49:11 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2014-11-23 19:49:11 +0100
commita784c8f795f60604a2cd6f9633a213e891e4d7df (patch)
tree2e115572d1bc28243237c5a525548b6a7206d7cd /src/webserver.c
parent7b6d970a87fbfc2079ba98a26c0b457cc8cd05ee (diff)
downloadbiruda-a784c8f795f60604a2cd6f9633a213e891e4d7df.tar.gz
biruda-a784c8f795f60604a2cd6f9633a213e891e4d7df.tar.bz2
got to POSTing the start command to the master, now we have to design the messaging below
Diffstat (limited to 'src/webserver.c')
-rw-r--r--src/webserver.c90
1 files changed, 56 insertions, 34 deletions
diff --git a/src/webserver.c b/src/webserver.c
index a824506..8093ec8 100644
--- a/src/webserver.c
+++ b/src/webserver.c
@@ -14,47 +14,69 @@ static int handle_request( void *cls, struct MHD_Connection *connection,
{
struct MHD_Response *response;
int ret;
-
- if( strcmp( method, "GET" ) != 0 ) {
- return MHD_NO;
- }
-
- fprintf( stderr, "http request: %s\n", url );
+
+ fprintf( stderr, "%s http request: %s\n", method, url );
- char biruda_msg[2048];
- biruda_msg[0] = '\0';
- if( strcmp( url, "/status" ) == 0 ) {
- for( int pos = 0; pos < MAX_COORDINATORS; pos++ ) {
- coordinator_t *c = &coordinator[pos];
- if( c->used ) {
- char part[256];
- snprintf( part, sizeof( part ),
- "coordinator %s %s %s %d %s %lld (%d)\n",
- c->host, c->os, c->arch, c->cpus,
- ( c->alive ? "alive" : "dead" ),
- (long long)c->lastAlive, pos );
- strncat( biruda_msg, part, sizeof( biruda_msg ) );
-
- for( int i = 0; i < c->nof_workers; i++ ) {
- worker_t *w = &c->worker[i];
+ if( strcmp( method, "GET" ) == 0 ) {
+ char biruda_msg[2048];
+ biruda_msg[0] = '\0';
+ if( strcmp( url, "/status" ) == 0 ) {
+ for( int pos = 0; pos < MAX_COORDINATORS; pos++ ) {
+ coordinator_t *c = &coordinator[pos];
+ if( c->used ) {
+ char part[256];
snprintf( part, sizeof( part ),
- "worker %s %s %s (%d)\n",
- w->name, worker_exection_mode_str( w->mode ),
- ( w->command == NULL ? "" : w->command ),
- i );
+ "coordinator %s %s %s %d %s %lld (%d)\n",
+ c->host, c->os, c->arch, c->cpus,
+ ( c->alive ? "alive" : "dead" ),
+ (long long)c->lastAlive, pos );
strncat( biruda_msg, part, sizeof( biruda_msg ) );
+
+ for( int i = 0; i < c->nof_workers; i++ ) {
+ worker_t *w = &c->worker[i];
+ snprintf( part, sizeof( part ),
+ "worker %s %s %s (%d)\n",
+ w->name, worker_exection_mode_str( w->mode ),
+ ( w->command == NULL ? "" : w->command ),
+ i );
+ strncat( biruda_msg, part, sizeof( biruda_msg ) );
+ }
}
}
+ } else {
+ snprintf( biruda_msg, sizeof( biruda_msg ), "Welcome to biruda! Please state your wish..\n" );
}
- } else {
- snprintf( biruda_msg, sizeof( biruda_msg ), "Welcome to biruda! Please state your wish..\n" );
- }
- response = MHD_create_response_from_buffer( strlen( biruda_msg ),
- (void *)biruda_msg, MHD_RESPMEM_MUST_COPY );
- ret = MHD_queue_response( connection, MHD_HTTP_OK, response );
- MHD_destroy_response( response );
-
+ response = MHD_create_response_from_buffer( strlen( biruda_msg ),
+ (void *)biruda_msg, MHD_RESPMEM_MUST_COPY );
+ ret = MHD_queue_response( connection, MHD_HTTP_OK, response );
+ 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" );
+
+ printf( "Got POST parameter for type of process '%s'\n", type );
+
+ if( strcmp( type, "worker" ) == 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 );
+
+ master_start_worker( name );
+ }
+ }
+
+ return MHD_NO;
+ }
+
return ret;
}