Skip to content
Snippets Groups Projects
Commit 76c34567 authored by Jan-Philipp Litza's avatar Jan-Philipp Litza
Browse files

gluon-node-info: simplify respondd module code a bit

parent f7eda938
No related branches found
No related tags found
No related merge requests found
......@@ -69,6 +69,12 @@ static struct json_object * get_number(struct uci_context *ctx, struct uci_secti
return jso;
}
static void maybe_add_number(struct uci_context *ctx, struct uci_section *s, const char *name, struct json_object *parent) {
struct json_object *jso = get_number(ctx, s, name);
if (jso)
json_object_object_add(parent, name, jso);
}
static struct json_object * get_location(struct uci_context *ctx, struct uci_package *p) {
struct uci_section *s = get_first_section(p, "location");
if (!s)
......@@ -80,17 +86,9 @@ static struct json_object * get_location(struct uci_context *ctx, struct uci_pac
struct json_object *ret = json_object_new_object();
struct json_object *latitude = get_number(ctx, s, "latitude");
if (latitude)
json_object_object_add(ret, "latitude", latitude);
struct json_object *longitude = get_number(ctx, s, "longitude");
if (longitude)
json_object_object_add(ret, "longitude", longitude);
struct json_object *altitude = get_number(ctx, s, "altitude");
if (altitude)
json_object_object_add(ret, "altitude", altitude);
maybe_add_number(ctx, s, "latitude", ret);
maybe_add_number(ctx, s, "longitude", ret);
maybe_add_number(ctx, s, "altitude", ret);
return ret;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment