service: constify function arguments
[project/mdnsd.git] / service.c
index 486a1fbcae7606c7237e60a984acee06e56c6e18..049de52b511b10c71b77cbf7f7669024c2bcfd66 100644 (file)
--- a/service.c
+++ b/service.c
@@ -42,13 +42,13 @@ enum {
 };
 
 struct service {
-        struct avl_node avl;
+       struct avl_node avl;
 
        time_t t;
 
        char *service;
        char *daemon;
-       char *txt;
+       const uint8_t *txt;
        int txt_len;
        int port;
        int active;
@@ -70,8 +70,8 @@ char *hostname = NULL;
 static char *sdudp =  "_services._dns-sd._udp.local";
 static char *sdtcp =  "_services._dns-sd._tcp.local";
 
-char*
-service_name(char *domain)
+char *
+service_name(const char *domain)
 {
        static char buffer[256];
 
@@ -84,7 +84,7 @@ static void
 service_send_ptr(struct uloop_fd *u, struct service *s)
 {
        unsigned char buffer[MAX_NAME_LEN];
-       char *host = service_name(s->service);
+       const char *host = service_name(s->service);
        int len = dn_comp(host, buffer, MAX_NAME_LEN, NULL, NULL);
 
        if (len < 1)
@@ -173,7 +173,7 @@ service_reply_a(struct uloop_fd *u, int type)
 }
 
 void
-service_reply(struct uloop_fd *u, char *match)
+service_reply(struct uloop_fd *u, const char *match)
 {
        struct service *s;
 
@@ -209,7 +209,7 @@ service_reply(struct uloop_fd *u, char *match)
 }
 
 void
-service_announce_services(struct uloop_fd *u, char *service)
+service_announce_services(struct uloop_fd *u, const char *service)
 {
        struct service *s;
        int tcp = 1;
@@ -259,18 +259,23 @@ service_load(char *path)
                        continue;
                blob_for_each_attr(cur, b.head, rem) {
                        struct service *s;
-                       char *d_service, *d_txt, *d_daemon;
+                       char *d_service, *d_daemon;
+                       uint8_t *d_txt;
                        int rem2;
+                       int txt_len = 0;
 
                        blobmsg_parse(service_policy, ARRAY_SIZE(service_policy),
                                _tb, blobmsg_data(cur), blobmsg_data_len(cur));
                        if (!_tb[SERVICE_PORT] || !_tb[SERVICE_TXT])
                                continue;
 
+                       blobmsg_for_each_attr(txt, _tb[SERVICE_TXT], rem2)
+                               txt_len += 1 + strlen(blobmsg_get_string(txt));
+
                        s = calloc_a(sizeof(*s),
                                &d_daemon, strlen(gl.gl_pathv[i]) + 1,
                                &d_service, strlen(blobmsg_name(cur)) + 1,
-                               &d_txt, blobmsg_data_len(_tb[SERVICE_TXT]));
+                               &d_txt, txt_len);
                        if (!s)
                                continue;
 
@@ -282,18 +287,13 @@ service_load(char *path)
                        s->avl.key = s->service;
                        s->active = 1;
                        s->t = 0;
+                       s->txt_len = txt_len;
+                       s->txt = d_txt;
                        avl_insert(&services, &s->avl);
 
-                       blobmsg_for_each_attr(txt, _tb[SERVICE_TXT], rem2)
-                               s->txt_len += 1 + strlen(blobmsg_get_string(txt));
-
                        if (!s->txt_len)
                                continue;
 
-                       d_txt = s->txt = malloc(s->txt_len);
-                       if (!s->txt)
-                               continue;
-
                        blobmsg_for_each_attr(txt, _tb[SERVICE_TXT], rem2) {
                                int len = strlen(blobmsg_get_string(txt));
                                if (!len)