aboutsummaryrefslogtreecommitdiff
path: root/src/ping903.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ping903.c')
-rw-r--r--src/ping903.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/ping903.c b/src/ping903.c
index 1b8a668..3de8e97 100644
--- a/src/ping903.c
+++ b/src/ping903.c
@@ -294,6 +294,67 @@ httpd_json_response(struct MHD_Connection *conn,
return ret;
}
+static struct json_value *
+ident_to_json(void)
+{
+ struct json_value *obj, *jv;
+
+ obj = json_new_object();
+ if (!obj)
+ return NULL;
+ if (!(jv = json_new_string(PACKAGE))
+ || json_object_set(obj, "package", jv))
+ goto err;
+ if (!(jv = json_new_string(PACKAGE_VERSION))
+ || json_object_set(obj, "version", jv))
+ goto err;
+ if (!(jv = json_new_number(getpid()))
+ || json_object_set(obj, "pid", jv))
+ goto err;
+ return obj;
+err:
+ json_value_free(jv);
+ json_value_free(obj);
+ return NULL;
+}
+
+static int
+ept_ident(struct MHD_Connection *conn,
+ const char *url, const char *method, const char *suffix,
+ struct json_value *unused)
+{
+ int ret;
+ struct json_value *obj;
+
+ while (*suffix == '/')
+ suffix++;
+ obj = ident_to_json();
+ if (!obj)
+ return http_response(conn, method, url,
+ MHD_HTTP_INTERNAL_SERVER_ERROR);
+ if (*suffix) {
+ struct json_value *jv, *cp;
+ if (json_object_get(obj, suffix, &jv)) {
+ ret = http_response(conn, method, url,
+ (errno == ENOENT)
+ ? MHD_HTTP_NOT_FOUND
+ : MHD_HTTP_INTERNAL_SERVER_ERROR);
+ json_value_free(obj);
+ return ret;
+ }
+
+ if (json_value_copy(jv, &cp)) {
+ ret = http_response(conn, method, url,
+ MHD_HTTP_INTERNAL_SERVER_ERROR);
+ json_value_free(obj);
+ return ret;
+ }
+ json_value_free(obj);
+ obj = cp;
+ }
+ return httpd_json_response(conn, url, method, MHD_HTTP_OK, obj);
+}
+
static int
ept_config(struct MHD_Connection *conn,
const char *url, const char *method, const char *suffix,
@@ -774,6 +835,7 @@ struct endpoint {
};
static struct endpoint endpoint[] = {
+ { "/id", EPT_PREFIX, MHD_HTTP_METHOD_GET, ept_ident },
{ "/config/ip-list", EPT_PREFIX, MHD_HTTP_METHOD_PUT, ept_ip_put },
{ "/config/ip-list", EPT_PREFIX, MHD_HTTP_METHOD_POST, ept_ip_post },
{ "/config/ip-list", EPT_PREFIX, MHD_HTTP_METHOD_DELETE, ept_ip_delete },

Return to:

Send suggestions and report system problems to the System administrator.