From 783a4e1a5908c407f88c2a41f526d33f71a06b31 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Wed, 17 Jun 2015 19:41:26 +0200 Subject: some first jquery ui steps --- src/webserver.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/webserver.c') diff --git a/src/webserver.c b/src/webserver.c index 947f90f..b552ccb 100644 --- a/src/webserver.c +++ b/src/webserver.c @@ -14,7 +14,10 @@ /* embedded web pages and JS code */ #include "index.h" - +#include "jquery-ui-css.h" +#include "jquery-js.h" +#include "jquery-ui-js.h" + static struct MHD_Daemon *d; #if MHD_VERSION < 0x00090500 @@ -45,7 +48,7 @@ static int handle_request( void *cls, struct MHD_Connection *connection, fprintf( stderr, "%s http request: %s\n", method, url ); if( strcmp( method, "GET" ) == 0 ) { - char biruda_msg[8192]; + char *biruda_msg = malloc( 512 * 1024 ); biruda_msg[0] = '\0'; if( strcmp( url, "/status" ) == 0 ) { for( int pos = 0; pos < MAX_COORDINATORS; pos++ ) { @@ -57,7 +60,7 @@ static int handle_request( void *cls, struct MHD_Connection *connection, c->host, c->os, c->arch, c->cpus, ( c->alive ? "alive" : "dead" ), (long long)c->lastAlive, pos ); - strncat( biruda_msg, part, sizeof( biruda_msg ) ); + strncat( biruda_msg, part, strlen( part ) ); for( int i = 0; i < c->nof_workers; i++ ) { worker_t *w = &c->worker[i]; @@ -68,7 +71,7 @@ static int handle_request( void *cls, struct MHD_Connection *connection, worker_exection_mode_str( w->mode ), ( w->command == NULL ? "" : w->command ), i ); - strncat( biruda_msg, part, sizeof( biruda_msg ) ); + strncat( biruda_msg, part, strlen( part ) ); } } } @@ -102,12 +105,21 @@ static int handle_request( void *cls, struct MHD_Connection *connection, } } + } else if( strcmp( url, "/web" ) == 0 ) { + strncpy( biruda_msg, (char *)index_html, index_html_len ); + } else if( strcmp( url, "/web/jquery-ui.css" ) == 0 ) { + strncpy( biruda_msg, (char *)jquery_ui_css, jquery_ui_css_len ); + } else if( strcmp( url, "/web/jquery.js" ) == 0 ) { + strncpy( biruda_msg, (char *)jquery_js, jquery_js_len ); + } else if( strcmp( url, "/web/jquery-ui.js" ) == 0 ) { + strncpy( biruda_msg, (char *)jquery_ui_js, jquery_ui_js_len ); } else { - snprintf( biruda_msg, index_html_len, (char *)index_html ); + strcat( biruda_msg, "

This is biruda, the REST api. You can access the web interface here.

" ); } response = MHD_create_response_from_buffer( strlen( biruda_msg ), (void *)biruda_msg, MHD_RESPMEM_MUST_COPY ); + free( biruda_msg ); ret = MHD_queue_response( connection, MHD_HTTP_OK, response ); MHD_destroy_response( response ); -- cgit v1.2.3-54-g00ecf