summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Fietkau2023-10-19 09:26:22 +0000
committerFelix Fietkau2023-10-19 09:26:22 +0000
commitd45c443aa1e6514aab58bbbf9311913e484d31a6 (patch)
tree0604a8347a01fefad029d6ed1288493382d503c5
parentb42b22152d73c0b5825bd20742d501d47adabed1 (diff)
downloadmdnsd-d45c443aa1e6514aab58bbbf9311913e484d31a6.tar.gz
ubus: add array flag support for the hosts method
Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--ubus.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/ubus.c b/ubus.c
index e0a40aa..9982f86 100644
--- a/ubus.c
+++ b/ubus.c
@@ -119,15 +119,29 @@ umdns_browse(struct ubus_context *ctx, struct ubus_object *obj,
return UBUS_STATUS_OK;
}
+enum {
+ HOSTS_ARRAY,
+ __HOSTS_MAX
+};
+static const struct blobmsg_policy hosts_policy[] = {
+ [HOSTS_ARRAY] = { "array", BLOBMSG_TYPE_BOOL }
+};
+
static int
umdns_hosts(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
struct cache_record *prev = NULL;
+ struct blob_attr *tb[__HOSTS_MAX];
struct cache_record *r;
+ bool array = false;
void *c;
+ blobmsg_parse(hosts_policy, __HOSTS_MAX, tb, blobmsg_data(msg), blobmsg_len(msg));
+ if (tb[HOSTS_ARRAY])
+ array = blobmsg_get_bool(tb[HOSTS_ARRAY]);
+
blob_buf_init(&b, 0);
avl_for_each_element(&records, r, avl) {
if (r->type != TYPE_A && r->type != TYPE_AAAA)
@@ -135,7 +149,7 @@ umdns_hosts(struct ubus_context *ctx, struct ubus_object *obj,
/* Query each domain just once */
if (!prev || strcmp(r->record, prev->record)) {
c = blobmsg_open_table(&b, r->record);
- cache_dump_records(&b, r->record, false, NULL);
+ cache_dump_records(&b, r->record, array, NULL);
blobmsg_close_table(&b, c);
}
prev = r;
@@ -255,7 +269,7 @@ static const struct ubus_method umdns_methods[] = {
UBUS_METHOD("fetch", umdns_query, query_policy),
UBUS_METHOD("browse", umdns_browse, browse_policy),
UBUS_METHOD_NOARG("update", umdns_update),
- UBUS_METHOD_NOARG("hosts", umdns_hosts),
+ UBUS_METHOD("hosts", umdns_hosts, hosts_policy),
UBUS_METHOD_NOARG("reload", umdns_reload),
};