summaryrefslogtreecommitdiff
path: root/src/webserver.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/webserver.c')
-rw-r--r--src/webserver.c22
1 files changed, 17 insertions, 5 deletions
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, "<html><body><p>This is biruda, the REST api. You can access the web interface <a href=\"/web\">here</a>.</p></body></html>" );
}
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 );