Code

store: Use store super-class when storing objects.
[sysdb.git] / src / core / store.c
index b013dcdd1683cae08f1a4993121605e0674b5712..2088e73547c48e436d2de216003ca8bab9748430 100644 (file)
@@ -313,7 +313,7 @@ store_obj(int parent_type, const char *parent_name,
                int type, const char *name, sdb_time_t last_update)
 {
        sdb_llist_t *parent_list;
-       sdb_store_obj_t *old;
+       store_obj_t *old;
        int status = 0;
 
        if (! name)
@@ -353,23 +353,23 @@ store_obj(int parent_type, const char *parent_name,
        }
 
        /* TODO: only look into direct children? */
-       old = sdb_store_lookup_in_list(parent_list, type, name);
+       old = STORE_OBJ(sdb_store_lookup_in_list(parent_list, type, name));
 
        if (old) {
-               if (old->_last_update > last_update) {
+               if (old->last_update > last_update) {
                        sdb_log(SDB_LOG_DEBUG, "store: Cannot update %s '%s' - "
                                        "value too old (%"PRIscTIME" < %"PRIscTIME")",
-                                       TYPE_TO_NAME(type), name, last_update, old->_last_update);
+                                       TYPE_TO_NAME(type), name, last_update, old->last_update);
                        /* don't report an error; the object may be updated by multiple
                         * backends */
                        status = 1;
                }
                else {
-                       old->_last_update = last_update;
+                       old->last_update = last_update;
                }
        }
        else {
-               sdb_store_obj_t *new = SDB_STORE_OBJ(sdb_object_create(name,
+               store_obj_t *new = STORE_OBJ(sdb_object_create(name,
                                        sdb_store_obj_type, type));
                if (! new) {
                        char errbuf[1024];
@@ -380,6 +380,7 @@ store_obj(int parent_type, const char *parent_name,
                        return -1;
                }
 
+               /* TODO: insert type-aware */
                status = sdb_llist_insert_sorted(parent_list, SDB_OBJ(new),
                                sdb_object_cmp_by_name);
 
@@ -492,10 +493,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 */