diff --git a/src/connection.c b/src/connection.c index a4d79cae..6fe1c564 100644 --- a/src/connection.c +++ b/src/connection.c @@ -419,6 +419,42 @@ static int _check_source_pass(http_parser_t *parser) return ret; } +static void handle_fallback_request(client_t *client) +{ + source_t *source; + char *mount, *value, *old; + int bytes; + + if(!_check_source_pass(client->parser)) { + INFO0("Bad or missing password on fallback configuration request"); + client_send_401(client); + return; + } + + mount = httpp_get_query_param(client->parser, "mount"); + value = httpp_get_query_param(client->parser, "fallback"); + + if(value == NULL || mount == NULL) { + client_send_400(client, "Missing parameter"); + return; + } + + avl_tree_rlock(global.source_tree); + source = source_find_mount(mount); + avl_tree_unlock(global.source_tree); + + old = source->fallback_mount; + source->fallback_mount = strdup(value); + free(old); + + client->respcode = 200; + bytes = sock_write(client->con->sock, + "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n" + "Fallback configured"); + if(bytes > 0) client->con->sent_bytes = bytes; + client_destroy(client); +} + static void handle_metadata_request(client_t *client) { source_t *source; @@ -578,6 +614,12 @@ static void _handle_get_request(connection_t *con, return; } + if(strcmp(uri, "/admin/fallbacks") == 0) { + DEBUG0("Got fallback request"); + handle_fallback_request(client); + return; + } + /* Here we are parsing the URI request to see ** if the extension is .xsl, if so, then process ** this request as an XSLT request diff --git a/src/source.c b/src/source.c index 7c80f6f2..a319bc78 100644 --- a/src/source.c +++ b/src/source.c @@ -45,6 +45,7 @@ source_t *source_create(client_t *client, connection_t *con, http_parser_t *pars src = (source_t *)malloc(sizeof(source_t)); src->client = client; src->mount = (char *)strdup(mount); + src->fallback_mount = NULL; src->format = format_get_plugin(type, src->mount); src->con = con; src->parser = parser;