Code

store: Canonicalize hostname before storing a service.
authorSebastian Harl <sh@tokkee.org>
Sat, 17 Aug 2013 18:10:45 +0000 (20:10 +0200)
committerSebastian Harl <sh@tokkee.org>
Sat, 17 Aug 2013 18:10:45 +0000 (20:10 +0200)
Else, host to service mapping is not correct.

src/core/store.c

index b013dcdd1683cae08f1a4993121605e0674b5712..1eb22d6c5e2c9be5e1942a711abc3126ce55fdfe 100644 (file)
@@ -492,10 +492,22 @@ int
 sdb_store_service(const char *hostname, const char *name,
                sdb_time_t last_update)
 {
+       char *cname;
+       int status = 0;
+
        if ((! hostname) || (! name))
                return -1;
-       return store_obj(/* parent = */ SDB_HOST, hostname,
+
+       cname = sdb_plugin_cname(strdup(hostname));
+       if (! cname) {
+               sdb_log(SDB_LOG_ERR, "store: strdup failed");
+               return -1;
+       }
+
+       status = store_obj(/* parent = */ SDB_HOST, cname,
                        /* stored object = */ SDB_SERVICE, name, last_update);
+       free(cname);
+       return status;
 } /* sdb_store_service */
 
 /* TODO: actually support hierarchical data */