diff options
Diffstat (limited to 'src/ping903.c')
-rw-r--r-- | src/ping903.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/ping903.c b/src/ping903.c index 99e3a80..4e5310f 100644 --- a/src/ping903.c +++ b/src/ping903.c @@ -263,10 +263,37 @@ ept_config(struct MHD_Connection *conn, { struct json_value *val; + while (*suffix == '/') + suffix++; + val = config_to_json(); if (!val) return http_error(conn, method, url, MHD_HTTP_INTERNAL_SERVER_ERROR); + + if (*suffix) { + struct json_value *jv, *cp; + int ret; + + if (json_object_get(val, suffix, &jv)) { + ret = http_error(conn, method, url, + (errno == ENOENT) + ? MHD_HTTP_NOT_FOUND + : MHD_HTTP_INTERNAL_SERVER_ERROR); + json_value_free(val); + return ret; + } + + if (json_value_copy(jv, &cp)) { + ret = http_error(conn, method, url, + MHD_HTTP_INTERNAL_SERVER_ERROR); + json_value_free(val); + return ret; + } + json_value_free(val); + val = cp; + } + return httpd_json_response(conn, url, method, val); } @@ -375,7 +402,7 @@ struct endpoint { }; static struct endpoint endpoint[] = { - { "/config", EPT_EXACT, MHD_HTTP_METHOD_GET, ept_config }, + { "/config", EPT_PREFIX, MHD_HTTP_METHOD_GET, ept_config }, { "/host", EPT_PREFIX, MHD_HTTP_METHOD_GET, ept_host_stat }, { "/ip", EPT_PREFIX, MHD_HTTP_METHOD_GET, ept_ip_stat }, { "/match", EPT_PREFIX, MHD_HTTP_METHOD_GET, ept_ip_match }, |