Code

store: Removed unused function sdb_store_get_service().
[sysdb.git] / src / core / store.c
index c66b5236a95b82869d19b532237a0ed0e4832aef..b96ff4e9054e46b76c45cc14be00d71e3966e62c 100644 (file)
@@ -28,6 +28,7 @@
 #include "sysdb.h"
 #include "core/store.h"
 #include "core/error.h"
+#include "core/plugin.h"
 #include "utils/llist.h"
 
 #include <assert.h>
@@ -83,7 +84,7 @@ sdb_host_do_clone(const sdb_object_t *obj)
        const sdb_host_t *host = (const sdb_host_t *)obj;
        sdb_host_t *new;
 
-       new = sdb_host_create(obj->name);
+       new = SDB_HOST(sdb_object_create(obj->name, sdb_host_type));
        if (! new)
                return NULL;
 
@@ -142,8 +143,8 @@ sdb_attr_clone(const sdb_object_t *obj)
        const sdb_attribute_t *attr = (const sdb_attribute_t *)obj;
        sdb_attribute_t *new;
 
-       new = sdb_attribute_create(attr->hostname,
-                       obj->name, attr->attr_value);
+       new = SDB_ATTR(sdb_object_create(obj->name, sdb_attribute_type,
+                               attr->hostname, attr->attr_value));
        if (! new)
                return NULL;
 
@@ -180,7 +181,8 @@ sdb_svc_clone(const sdb_object_t *obj)
        const sdb_service_t *svc = (const sdb_service_t *)obj;
        sdb_service_t *new;
 
-       new = sdb_service_create(svc->hostname, obj->name);
+       new = SDB_SVC(sdb_object_create(obj->name, sdb_service_type,
+                               svc->hostname));
        if (! new)
                return NULL;
 
@@ -216,31 +218,24 @@ const sdb_type_t sdb_service_type = {
  * public API
  */
 
-sdb_host_t *
-sdb_host_create(const char *name)
-{
-       sdb_object_t *obj;
-
-       if (! name)
-               return NULL;
-
-       obj = sdb_object_create(name, sdb_host_type);
-       if (! obj)
-               return NULL;
-       return SDB_HOST(obj);
-} /* sdb_host_create */
-
 int
-sdb_store_host(const sdb_host_t *host)
+sdb_store_host(const char *name, sdb_time_t last_update)
 {
-       sdb_time_t last_update;
        sdb_host_t *old;
+
+       char *cname;
        int status = 0;
 
-       if ((! host) || (! SDB_CONST_OBJ(host)->name))
+       if (! name)
+               return -1;
+
+       cname = sdb_plugin_cname(strdup(name));
+       if (! cname) {
+               sdb_log(SDB_LOG_ERR, "store: strdup failed");
                return -1;
+       }
 
-       last_update = host->_last_update;
+       last_update = last_update;
        if (last_update <= 0)
                last_update = sdb_gettime();
 
@@ -253,14 +248,13 @@ sdb_store_host(const sdb_host_t *host)
                }
        }
 
-       old = SDB_HOST(sdb_llist_search_by_name(host_list,
-                               SDB_CONST_OBJ(host)->name));
+       old = SDB_HOST(sdb_llist_search_by_name(host_list, cname));
 
        if (old) {
                if (old->_last_update > last_update) {
                        sdb_log(SDB_LOG_DEBUG, "store: Cannot update host '%s' - "
                                        "value too old (%"PRIscTIME" < %"PRIscTIME")",
-                                       SDB_CONST_OBJ(host)->name, last_update, old->_last_update);
+                                       cname, last_update, old->_last_update);
                        /* don't report an error; the host may be updated by multiple
                         * backends */
                        status = 1;
@@ -270,7 +264,7 @@ sdb_store_host(const sdb_host_t *host)
                }
        }
        else {
-               sdb_host_t *new = SDB_HOST(sdb_object_clone(SDB_CONST_OBJ(host)));
+               sdb_host_t *new = SDB_HOST(sdb_object_create(name, sdb_host_type));
                if (! new) {
                        char errbuf[1024];
                        sdb_log(SDB_LOG_ERR, "store: Failed to clone host object: %s",
@@ -279,11 +273,14 @@ sdb_store_host(const sdb_host_t *host)
                        return -1;
                }
 
+               free(SDB_OBJ(new)->name);
+               SDB_OBJ(new)->name = cname;
+
                if (! new->attributes) {
                        if (! (new->attributes = sdb_llist_create())) {
                                char errbuf[1024];
                                sdb_log(SDB_LOG_ERR, "store: Failed to initialize "
-                                               "host object '%s': %s", SDB_CONST_OBJ(host)->name,
+                                               "host object '%s': %s", SDB_OBJ(new)->name,
                                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                                sdb_object_deref(SDB_OBJ(new));
                                pthread_rwlock_unlock(&host_lock);
@@ -295,7 +292,7 @@ sdb_store_host(const sdb_host_t *host)
                        if (! (new->services = sdb_llist_create())) {
                                char errbuf[1024];
                                sdb_log(SDB_LOG_ERR, "store: Failed to initialize "
-                                               "host object '%s': %s", SDB_CONST_OBJ(host)->name,
+                                               "host object '%s': %s", SDB_OBJ(new)->name,
                                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                                sdb_object_deref(SDB_OBJ(new));
                                pthread_rwlock_unlock(&host_lock);
@@ -314,8 +311,8 @@ sdb_store_host(const sdb_host_t *host)
        return status;
 } /* sdb_store_host */
 
-const sdb_host_t *
-sdb_store_get_host(const char *name)
+_Bool
+sdb_store_has_host(const char *name)
 {
        sdb_host_t *host;
 
@@ -323,25 +320,8 @@ sdb_store_get_host(const char *name)
                return NULL;
 
        host = SDB_HOST(sdb_llist_search_by_name(host_list, name));
-       if (! host)
-               return NULL;
-       return host;
-} /* sdb_store_get_host */
-
-sdb_attribute_t *
-sdb_attribute_create(const char *hostname,
-               const char *name, const char *value)
-{
-       sdb_object_t *obj;
-
-       if ((! hostname) || (! name) || (! value))
-               return NULL;
-
-       obj = sdb_object_create(name, sdb_attribute_type, hostname, value);
-       if (! obj)
-               return NULL;
-       return SDB_ATTR(obj);
-} /* sdb_attribute_create */
+       return host != NULL;
+} /* sdb_store_has_host */
 
 int
 sdb_store_attribute(const sdb_attribute_t *attr)
@@ -405,20 +385,6 @@ sdb_store_attribute(const sdb_attribute_t *attr)
        return status;
 } /* sdb_store_attribute */
 
-sdb_service_t *
-sdb_service_create(const char *hostname, const char *name)
-{
-       sdb_object_t *obj;
-
-       if ((! hostname) || (! name))
-               return NULL;
-
-       obj = sdb_object_create(name, sdb_service_type, hostname);
-       if (! obj)
-               return NULL;
-       return SDB_SVC(obj);
-} /* sdb_service_create */
-
 int
 sdb_store_service(const sdb_service_t *svc)
 {
@@ -481,20 +447,6 @@ sdb_store_service(const sdb_service_t *svc)
        return status;
 } /* sdb_store_service */
 
-const sdb_service_t *
-sdb_store_get_service(const sdb_host_t *host, const char *name)
-{
-       sdb_service_t *svc;
-
-       if ((! host) || (! name))
-               return NULL;
-
-       svc = SDB_SVC(sdb_llist_search_by_name(host->services, name));
-       if (! svc)
-               return NULL;
-       return svc;
-} /* sdb_store_get_service */
-
 int
 sdb_store_dump(FILE *fh)
 {