Drop unneeded code to simplify getting hosts over ubus
authorRafał Miłecki <rafal@milecki.pl>
Thu, 9 Mar 2017 21:17:32 +0000 (22:17 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Fri, 10 Mar 2017 10:53:25 +0000 (11:53 +0100)
This code in umdns_hosts was there since ever but it seems like an
unneeded copy & paste part of umdns_browse. In this function we iterate
over *host* entries of cached services list. It means the entry field
conains values like "example.local".

In such case looking for "._" is pointless and appending ".local"
results in looking for entries like "example.local.local".

This code make sense for browsing *services* only where for entries like
"ex._ssh._tcp.local" we try dumping "ex.local" & "ex._ssh._tcp.local".

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
ubus.c

diff --git a/ubus.c b/ubus.c
index 9ceeab10bdeda184c1dbcfb6366b6b7a4d3cbcb7..4120fd509cd3585fbb8a5e5fdfbdf055ae5adea8 100644 (file)
--- a/ubus.c
+++ b/ubus.c
@@ -97,21 +97,13 @@ umdns_hosts(struct ubus_context *ctx, struct ubus_object *obj,
                struct blob_attr *msg)
 {
        struct cache_service *s;
-       char *buffer = (char *) mdns_buf;
        void *c;
 
        blob_buf_init(&b, 0);
        avl_for_each_element(&services, s, avl) {
-               char *local;
                if (!cache_service_is_host(s))
                        continue;
-               snprintf(buffer, MAX_NAME_LEN, "%s", s->entry);
-               local = strstr(buffer, "._");
-               if (local)
-                       *local = '\0';
-               c = blobmsg_open_table(&b, buffer);
-               strncat(buffer, ".local", MAX_NAME_LEN);
-               cache_dump_records(&b, buffer);
+               c = blobmsg_open_table(&b, s->entry);
                cache_dump_records(&b, s->entry);
                blobmsg_close_table(&b, c);
        }