diff --git a/src/core/store.c b/src/core/store.c
index a0bbf55ce39173c536c4758fce4efefcfeca81cf..6deb699024d9b1f90052834efb55d4bcb3abd83a 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
#include "sysdb.h"
#include "core/store.h"
#include "sysdb.h"
#include "core/store.h"
-#include "utils/error.h"
+#include "core/error.h"
+#include "core/plugin.h"
#include "utils/llist.h"
#include "utils/llist.h"
-#include "utils/string.h"
#include <assert.h>
#include <assert.h>
#include <pthread.h>
#include <pthread.h>
-/*
- * private data types
- */
-
-/* type used for looking up named objects */
-typedef struct {
- sdb_object_t parent;
- const char *obj_name;
-} sdb_store_lookup_obj_t;
-#define SDB_STORE_LOOKUP_OBJ_INIT { SDB_OBJECT_INIT, NULL }
-
/*
* private variables
*/
/*
* private variables
*/
static pthread_rwlock_t host_lock = PTHREAD_RWLOCK_INITIALIZER;
/*
static pthread_rwlock_t host_lock = PTHREAD_RWLOCK_INITIALIZER;
/*
- * private helper functions
+ * private types
*/
*/
-static int
-sdb_store_obj_cmp_by_name(const sdb_object_t *a, const sdb_object_t *b)
-{
- const sdb_store_obj_t *h1 = (const sdb_store_obj_t *)a;
- const sdb_store_obj_t *h2 = (const sdb_store_obj_t *)b;
+static sdb_type_t sdb_host_type;
+static sdb_type_t sdb_attribute_type;
+static sdb_type_t sdb_service_type;
- assert(h1 && h2);
- return strcasecmp(h1->name, h2->name);
-} /* sdb_store_obj_cmp_by_name */
+typedef struct {
+ sdb_object_t super;
+ sdb_time_t last_update;
+} sdb_store_obj_t;
+#define SDB_STORE_OBJ(obj) ((sdb_store_obj_t *)(obj))
+#define SDB_CONST_STORE_OBJ(obj) ((const sdb_store_obj_t *)(obj))
-static int
-sdb_cmp_store_obj_with_name(const sdb_object_t *a, const sdb_object_t *b)
-{
- const sdb_store_obj_t *obj = (const sdb_store_obj_t *)a;
- const sdb_store_lookup_obj_t *lookup = (const sdb_store_lookup_obj_t *)b;
+typedef struct {
+ sdb_store_obj_t super;
- assert(obj && lookup);
- return strcasecmp(obj->name, lookup->obj_name);
-} /* sdb_cmp_store_obj_with_name */
+ char *hostname;
+} sdb_service_t;
+#define SDB_SVC(obj) ((sdb_service_t *)(obj))
+#define SDB_CONST_SVC(obj) ((const sdb_service_t *)(obj))
-static int
-sdb_host_init(sdb_object_t *obj, va_list ap)
-{
- const char *name = va_arg(ap, const char *);
+typedef struct {
+ sdb_store_obj_t super;
- SDB_HOST(obj)->host_name = strdup(name);
- if (! SDB_HOST(obj)->host_name)
- return -1;
+ char *attr_value;
+ char *hostname;
+} sdb_attribute_t;
+#define SDB_ATTR(obj) ((sdb_attribute_t *)(obj))
+#define SDB_CONST_ATTR(obj) ((const sdb_attribute_t *)(obj))
+
+typedef struct {
+ sdb_store_obj_t super;
+
+ sdb_llist_t *attributes;
+ sdb_llist_t *services;
+} sdb_host_t;
+#define SDB_HOST(obj) ((sdb_host_t *)(obj))
+#define SDB_CONST_HOST(obj) ((const sdb_host_t *)(obj))
- SDB_HOST(obj)->host_last_update = sdb_gettime();
+/* shortcuts for accessing the sdb_store_obj_t attributes of inheriting
+ * objects */
+#define _last_update super.last_update
+
+static int
+sdb_host_init(sdb_object_t *obj, va_list __attribute__((unused)) ap)
+{
+ SDB_HOST(obj)->_last_update = sdb_gettime();
/* ignore errors -> last_update will be updated later */
SDB_HOST(obj)->attributes = sdb_llist_create();
/* ignore errors -> last_update will be updated later */
SDB_HOST(obj)->attributes = sdb_llist_create();
{
assert(obj);
{
assert(obj);
- if (SDB_HOST(obj)->host_name)
- free(SDB_HOST(obj)->host_name);
-
if (SDB_HOST(obj)->attributes)
sdb_llist_destroy(SDB_HOST(obj)->attributes);
if (SDB_HOST(obj)->services)
sdb_llist_destroy(SDB_HOST(obj)->services);
} /* sdb_host_destroy */
if (SDB_HOST(obj)->attributes)
sdb_llist_destroy(SDB_HOST(obj)->attributes);
if (SDB_HOST(obj)->services)
sdb_llist_destroy(SDB_HOST(obj)->services);
} /* sdb_host_destroy */
+static sdb_object_t *
+sdb_host_clone(const sdb_object_t *obj)
+{
+ const sdb_host_t *host = (const sdb_host_t *)obj;
+ sdb_host_t *new;
+
+ new = SDB_HOST(sdb_object_create(obj->name, sdb_host_type));
+ if (! new)
+ return NULL;
+
+ /* make sure these are initialized; else sdb_object_deref() might access
+ * arbitrary memory in case of an error */
+ new->services = new->attributes = NULL;
+
+ if (host->attributes) {
+ new->attributes = sdb_llist_clone(host->attributes);
+ if (! new->attributes) {
+ sdb_object_deref(SDB_OBJ(new));
+ return NULL;
+ }
+ }
+
+ new->_last_update = host->_last_update;
+ if (host->services) {
+ new->services = sdb_llist_clone(host->services);
+ if (! new->services) {
+ sdb_object_deref(SDB_OBJ(new));
+ return NULL;
+ }
+ }
+ return SDB_OBJ(new);
+} /* sdb_host_clone */
+
static int
sdb_attr_init(sdb_object_t *obj, va_list ap)
{
const char *hostname = va_arg(ap, const char *);
static int
sdb_attr_init(sdb_object_t *obj, va_list ap)
{
const char *hostname = va_arg(ap, const char *);
- const char *name = va_arg(ap, const char *);
const char *value = va_arg(ap, const char *);
SDB_ATTR(obj)->hostname = strdup(hostname);
const char *value = va_arg(ap, const char *);
SDB_ATTR(obj)->hostname = strdup(hostname);
- SDB_ATTR(obj)->attr_name = strdup(name);
SDB_ATTR(obj)->attr_value = strdup(value);
SDB_ATTR(obj)->attr_value = strdup(value);
- if ((! SDB_ATTR(obj)->hostname)
- || (! SDB_ATTR(obj)->attr_name) || (! SDB_ATTR(obj)->attr_value))
+ if ((! SDB_ATTR(obj)->hostname) || (! SDB_ATTR(obj)->attr_value))
return -1;
return -1;
- SDB_ATTR(obj)->attr_last_update = sdb_gettime();
+ SDB_ATTR(obj)->_last_update = sdb_gettime();
return 0;
} /* sdb_attr_init */
return 0;
} /* sdb_attr_init */
if (SDB_ATTR(obj)->hostname)
free(SDB_ATTR(obj)->hostname);
if (SDB_ATTR(obj)->hostname)
free(SDB_ATTR(obj)->hostname);
- if (SDB_ATTR(obj)->attr_name)
- free(SDB_ATTR(obj)->attr_name);
if (SDB_ATTR(obj)->attr_value)
free(SDB_ATTR(obj)->attr_value);
} /* sdb_attr_destroy */
if (SDB_ATTR(obj)->attr_value)
free(SDB_ATTR(obj)->attr_value);
} /* sdb_attr_destroy */
+static sdb_object_t *
+sdb_attr_clone(const sdb_object_t *obj)
+{
+ const sdb_attribute_t *attr = (const sdb_attribute_t *)obj;
+ sdb_attribute_t *new;
+
+ new = SDB_ATTR(sdb_object_create(obj->name, sdb_attribute_type,
+ attr->hostname, attr->attr_value));
+ if (! new)
+ return NULL;
+
+ new->_last_update = attr->_last_update;
+ return SDB_OBJ(new);
+} /* sdb_attr_clone */
+
static int
sdb_svc_init(sdb_object_t *obj, va_list ap)
{
const char *hostname = va_arg(ap, const char *);
static int
sdb_svc_init(sdb_object_t *obj, va_list ap)
{
const char *hostname = va_arg(ap, const char *);
- const char *name = va_arg(ap, const char *);
SDB_SVC(obj)->hostname = strdup(hostname);
SDB_SVC(obj)->hostname = strdup(hostname);
- SDB_SVC(obj)->svc_name = strdup(name);
- if ((! SDB_SVC(obj)->hostname) || (! SDB_SVC(obj)->svc_name))
+ if (! SDB_SVC(obj)->hostname)
return -1;
return -1;
- SDB_SVC(obj)->svc_last_update = sdb_gettime();
+ SDB_SVC(obj)->_last_update = sdb_gettime();
/* ignore errors -> last_update will be updated later */
return 0;
} /* sdb_svc_init */
/* ignore errors -> last_update will be updated later */
return 0;
} /* sdb_svc_init */
if (SDB_SVC(obj)->hostname)
free(SDB_SVC(obj)->hostname);
if (SDB_SVC(obj)->hostname)
free(SDB_SVC(obj)->hostname);
- if (SDB_SVC(obj)->svc_name)
- free(SDB_SVC(obj)->svc_name);
} /* sdb_svc_destroy */
} /* sdb_svc_destroy */
-/*
- * public API
- */
-
-sdb_host_t *
-sdb_host_create(const char *name)
+static sdb_object_t *
+sdb_svc_clone(const sdb_object_t *obj)
{
{
- sdb_object_t *obj;
+ const sdb_service_t *svc = (const sdb_service_t *)obj;
+ sdb_service_t *new;
- if (! name)
+ new = SDB_SVC(sdb_object_create(obj->name, sdb_service_type,
+ svc->hostname));
+ if (! new)
return NULL;
return NULL;
- obj = sdb_object_create(sizeof(sdb_host_t), sdb_host_init,
- sdb_host_destroy, name);
- if (! obj)
- return NULL;
- return SDB_HOST(obj);
-} /* sdb_host_create */
+ new->_last_update = svc->_last_update;
+ return SDB_OBJ(new);
+} /* sdb_svc_clone */
-sdb_host_t *
-sdb_host_clone(const sdb_host_t *host)
-{
- sdb_host_t *new;
+static sdb_type_t sdb_host_type = {
+ sizeof(sdb_host_t),
- new = sdb_host_create(host->host_name);
- if (! new)
- return NULL;
+ sdb_host_init,
+ sdb_host_destroy,
+ sdb_host_clone
+};
- /* make sure these are initialized; else sdb_object_deref() might access
- * arbitrary memory in case of an error */
- new->services = new->attributes = NULL;
+static sdb_type_t sdb_attribute_type = {
+ sizeof(sdb_attribute_t),
- if (host->attributes) {
- new->attributes = sdb_llist_clone(host->attributes);
- if (! new->attributes) {
- sdb_object_deref(SDB_OBJ(new));
- return NULL;
- }
- }
+ sdb_attr_init,
+ sdb_attr_destroy,
+ sdb_attr_clone
+};
- new->host_last_update = host->host_last_update;
- if (host->services) {
- new->services = sdb_llist_clone(host->services);
- if (! new->services) {
- sdb_object_deref(SDB_OBJ(new));
- return NULL;
- }
- }
- return new;
-} /* sdb_host_clone */
+static sdb_type_t sdb_service_type = {
+ sizeof(sdb_service_t),
+
+ sdb_svc_init,
+ sdb_svc_destroy,
+ sdb_svc_clone
+};
+
+/*
+ * public API
+ */
int
int
-sdb_store_host(const sdb_host_t *host)
+sdb_store_host(const char *name, sdb_time_t last_update)
{
{
- sdb_store_lookup_obj_t lookup = SDB_STORE_LOOKUP_OBJ_INIT;
- sdb_time_t last_update;
-
sdb_host_t *old;
sdb_host_t *old;
+
+ char *cname;
int status = 0;
int status = 0;
- if ((! host) || (! host->host_name))
+ if (! name)
return -1;
return -1;
- last_update = host->host_last_update;
+ cname = sdb_plugin_cname(strdup(name));
+ if (! cname) {
+ sdb_log(SDB_LOG_ERR, "store: strdup failed");
+ return -1;
+ }
+
if (last_update <= 0)
last_update = sdb_gettime();
if (last_update <= 0)
last_update = sdb_gettime();
}
}
}
}
- lookup.obj_name = host->host_name;
- old = SDB_HOST(sdb_llist_search(host_list, (const sdb_object_t *)&lookup,
- sdb_cmp_store_obj_with_name));
+ old = SDB_HOST(sdb_llist_search_by_name(host_list, cname));
if (old) {
if (old) {
- if (old->host_last_update > last_update) {
- sdb_error_set(SDB_LOG_DEBUG, "store: Cannot update host '%s' - "
- "value too old (%"PRIscTIME" < %"PRIscTIME")\n",
- host->host_name, last_update, old->host_last_update);
+ if (old->_last_update > last_update) {
+ sdb_log(SDB_LOG_DEBUG, "store: Cannot update host '%s' - "
+ "value too old (%"PRIscTIME" < %"PRIscTIME")",
+ cname, last_update, old->_last_update);
/* don't report an error; the host may be updated by multiple
* backends */
status = 1;
}
else {
/* don't report an error; the host may be updated by multiple
* backends */
status = 1;
}
else {
- old->host_last_update = last_update;
+ old->_last_update = last_update;
}
}
else {
}
}
else {
- sdb_host_t *new = sdb_host_clone(host);
+ sdb_host_t *new = SDB_HOST(sdb_object_create(name, sdb_host_type));
if (! new) {
char errbuf[1024];
if (! new) {
char errbuf[1024];
- sdb_error_set(SDB_LOG_ERR, "store: Failed to clone host object: "
- "%s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
+ sdb_log(SDB_LOG_ERR, "store: Failed to clone host object: %s",
+ sdb_strerror(errno, errbuf, sizeof(errbuf)));
pthread_rwlock_unlock(&host_lock);
return -1;
}
pthread_rwlock_unlock(&host_lock);
return -1;
}
- if (! new->attributes) {
- if (! (new->attributes = sdb_llist_create())) {
- char errbuf[1024];
- sdb_error_set(SDB_LOG_ERR, "store: Failed to initialize "
- "host object '%s': %s\n", host->host_name,
- sdb_strerror(errno, errbuf, sizeof(errbuf)));
- sdb_object_deref(SDB_OBJ(new));
- pthread_rwlock_unlock(&host_lock);
- return -1;
- }
- }
-
- if (! new->services) {
- if (! (new->services = sdb_llist_create())) {
- char errbuf[1024];
- sdb_error_set(SDB_LOG_ERR, "store: Failed to initialize "
- "host object '%s': %s\n", host->host_name,
- sdb_strerror(errno, errbuf, sizeof(errbuf)));
- sdb_object_deref(SDB_OBJ(new));
- pthread_rwlock_unlock(&host_lock);
- return -1;
- }
- }
+ free(SDB_OBJ(new)->name);
+ SDB_OBJ(new)->name = cname;
status = sdb_llist_insert_sorted(host_list, SDB_OBJ(new),
status = sdb_llist_insert_sorted(host_list, SDB_OBJ(new),
- sdb_store_obj_cmp_by_name);
+ sdb_object_cmp_by_name);
/* pass control to the list or destroy in case of an error */
sdb_object_deref(SDB_OBJ(new));
/* pass control to the list or destroy in case of an error */
sdb_object_deref(SDB_OBJ(new));
return status;
} /* sdb_store_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_store_lookup_obj_t lookup = SDB_STORE_LOOKUP_OBJ_INIT;
sdb_host_t *host;
if (! name)
return NULL;
sdb_host_t *host;
if (! name)
return NULL;
- lookup.obj_name = name;
- host = SDB_HOST(sdb_llist_search(host_list, (const sdb_object_t *)&lookup,
- sdb_cmp_store_obj_with_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(sizeof(sdb_attribute_t), sdb_attr_init,
- sdb_attr_destroy, hostname, name, value);
- if (! obj)
- return NULL;
- return SDB_ATTR(obj);
-} /* sdb_attribute_create */
-
-sdb_attribute_t *
-sdb_attribute_clone(const sdb_attribute_t *attr)
-{
- sdb_attribute_t *new;
-
- new = sdb_attribute_create(attr->hostname,
- attr->attr_name, attr->attr_value);
- if (! new)
- return NULL;
-
- new->attr_last_update = attr->attr_last_update;
- return new;
-} /* sdb_attribute_clone */
+ host = SDB_HOST(sdb_llist_search_by_name(host_list, name));
+ return host != NULL;
+} /* sdb_store_has_host */
int
int
-sdb_store_attribute(const sdb_attribute_t *attr)
+sdb_store_attribute(const char *hostname, const char *key, const char *value,
+ sdb_time_t last_update)
{
{
- sdb_store_lookup_obj_t lookup = SDB_STORE_LOOKUP_OBJ_INIT;
sdb_host_t *host;
sdb_host_t *host;
-
sdb_attribute_t *old;
sdb_attribute_t *old;
- sdb_time_t last_update;
-
int status = 0;
int status = 0;
- if (! attr)
+ if ((! hostname) || (! key))
return -1;
return -1;
- last_update = attr->attr_last_update;
if (last_update <= 0)
last_update = sdb_gettime();
if (last_update <= 0)
last_update = sdb_gettime();
pthread_rwlock_wrlock(&host_lock);
pthread_rwlock_wrlock(&host_lock);
- lookup.obj_name = attr->hostname;
- host = SDB_HOST(sdb_llist_search(host_list, (const sdb_object_t *)&lookup,
- sdb_cmp_store_obj_with_name));
-
+ host = SDB_HOST(sdb_llist_search_by_name(host_list, hostname));
if (! host) {
pthread_rwlock_unlock(&host_lock);
return -1;
}
if (! host) {
pthread_rwlock_unlock(&host_lock);
return -1;
}
- lookup.obj_name = attr->attr_name;
- old = SDB_ATTR(sdb_llist_search(host->attributes,
- (const sdb_object_t *)&lookup,
- sdb_cmp_store_obj_with_name));
-
+ old = SDB_ATTR(sdb_llist_search_by_name(host->attributes, key));
if (old) {
if (old) {
- if (old->host_last_update > last_update) {
- sdb_error_set(SDB_LOG_DEBUG, "store: Cannot update attribute "
- "'%s/%s' - value too old (%"PRIscTIME" < %"PRIscTIME")\n",
- attr->hostname, attr->attr_name, last_update,
- old->host_last_update);
+ if (old->_last_update > last_update) {
+ sdb_log(SDB_LOG_DEBUG, "store: Cannot update attribute "
+ "'%s/%s' - value too old (%"PRIscTIME" < %"PRIscTIME")",
+ hostname, key, last_update, old->_last_update);
status = 1;
}
else {
status = 1;
}
else {
- old->attr_last_update = last_update;
+ old->_last_update = last_update;
}
}
else {
}
}
else {
- sdb_attribute_t *new = sdb_attribute_clone(attr);
+ sdb_attribute_t *new = SDB_ATTR(sdb_object_create(key,
+ sdb_attribute_type, hostname, value));
if (! new) {
char errbuf[1024];
if (! new) {
char errbuf[1024];
- sdb_error_set(SDB_LOG_ERR, "store: Failed to clone attribute "
- "object: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
+ sdb_log(SDB_LOG_ERR, "store: Failed to clone attribute "
+ "object: %s", sdb_strerror(errno, errbuf, sizeof(errbuf)));
pthread_rwlock_unlock(&host_lock);
return -1;
}
status = sdb_llist_insert_sorted(host->attributes, SDB_OBJ(new),
pthread_rwlock_unlock(&host_lock);
return -1;
}
status = sdb_llist_insert_sorted(host->attributes, SDB_OBJ(new),
- sdb_store_obj_cmp_by_name);
+ sdb_object_cmp_by_name);
/* pass control to the list or destroy in case of an error */
sdb_object_deref(SDB_OBJ(new));
/* pass control to the list or destroy in case of an error */
sdb_object_deref(SDB_OBJ(new));
return status;
} /* sdb_store_attribute */
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(sizeof(sdb_service_t), sdb_svc_init,
- sdb_svc_destroy, hostname, name);
- if (! obj)
- return NULL;
- return SDB_SVC(obj);
-} /* sdb_service_create */
-
-sdb_service_t *
-sdb_service_clone(const sdb_service_t *svc)
-{
- sdb_service_t *new;
-
- new = sdb_service_create(svc->hostname, svc->svc_name);
- if (! new)
- return NULL;
-
- new->svc_last_update = svc->svc_last_update;
- return new;
-} /* sdb_service_clone */
-
int
int
-sdb_store_service(const sdb_service_t *svc)
+sdb_store_service(const char *hostname, const char *name,
+ sdb_time_t last_update)
{
{
- sdb_store_lookup_obj_t lookup = SDB_STORE_LOOKUP_OBJ_INIT;
sdb_host_t *host;
sdb_host_t *host;
-
sdb_service_t *old;
sdb_service_t *old;
- sdb_time_t last_update;
-
int status = 0;
int status = 0;
- if (! svc)
+ if ((! hostname) || (! name))
return -1;
return -1;
- last_update = svc->svc_last_update;
if (last_update <= 0)
last_update = sdb_gettime();
if (last_update <= 0)
last_update = sdb_gettime();
pthread_rwlock_wrlock(&host_lock);
pthread_rwlock_wrlock(&host_lock);
- lookup.obj_name = svc->hostname;
- host = SDB_HOST(sdb_llist_search(host_list, (const sdb_object_t *)&lookup,
- sdb_cmp_store_obj_with_name));
-
+ host = SDB_HOST(sdb_llist_search_by_name(host_list, hostname));
if (! host) {
pthread_rwlock_unlock(&host_lock);
return -1;
}
if (! host) {
pthread_rwlock_unlock(&host_lock);
return -1;
}
- lookup.obj_name = svc->svc_name;
- old = SDB_SVC(sdb_llist_search(host->services, (const sdb_object_t *)&lookup,
- sdb_cmp_store_obj_with_name));
-
+ old = SDB_SVC(sdb_llist_search_by_name(host->services, name));
if (old) {
if (old) {
- if (old->host_last_update > last_update) {
- sdb_error_set(SDB_LOG_DEBUG, "store: Cannot update service "
- "'%s/%s' - value too old (%"PRIscTIME" < %"PRIscTIME")\n",
- svc->hostname, svc->svc_name, last_update,
- old->host_last_update);
+ if (old->_last_update > last_update) {
+ sdb_log(SDB_LOG_DEBUG, "store: Cannot update service "
+ "'%s/%s' - value too old (%"PRIscTIME" < %"PRIscTIME")",
+ hostname, name, last_update, old->_last_update);
status = 1;
}
else {
status = 1;
}
else {
- old->svc_last_update = last_update;
+ old->_last_update = last_update;
}
}
else {
}
}
else {
- sdb_service_t *new = sdb_service_clone(svc);
+ sdb_service_t *new = SDB_SVC(sdb_object_create(name, sdb_service_type,
+ hostname));
if (! new) {
char errbuf[1024];
if (! new) {
char errbuf[1024];
- sdb_error_set(SDB_LOG_ERR, "store: Failed to clone service "
- "object: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
+ sdb_log(SDB_LOG_ERR, "store: Failed to clone service "
+ "object: %s", sdb_strerror(errno, errbuf, sizeof(errbuf)));
pthread_rwlock_unlock(&host_lock);
return -1;
}
status = sdb_llist_insert_sorted(host->services, SDB_OBJ(new),
pthread_rwlock_unlock(&host_lock);
return -1;
}
status = sdb_llist_insert_sorted(host->services, SDB_OBJ(new),
- sdb_store_obj_cmp_by_name);
+ sdb_object_cmp_by_name);
/* pass control to the list or destroy in case of an error */
sdb_object_deref(SDB_OBJ(new));
/* pass control to the list or destroy in case of an error */
sdb_object_deref(SDB_OBJ(new));
return status;
} /* sdb_store_service */
return status;
} /* sdb_store_service */
-const sdb_service_t *
-sdb_store_get_service(const sdb_host_t *host, const char *name)
-{
- sdb_store_lookup_obj_t lookup = SDB_STORE_LOOKUP_OBJ_INIT;
- sdb_service_t *svc;
-
- if ((! host) || (! name))
- return NULL;
-
- lookup.obj_name = name;
- svc = SDB_SVC(sdb_llist_search(host->services,
- (const sdb_object_t *)&lookup,
- sdb_cmp_store_obj_with_name));
-
- if (! svc)
- return NULL;
- return svc;
-} /* sdb_store_get_service */
-
int
sdb_store_dump(FILE *fh)
{
int
sdb_store_dump(FILE *fh)
{
assert(host);
if (! sdb_strftime(time_str, sizeof(time_str),
assert(host);
if (! sdb_strftime(time_str, sizeof(time_str),
- "%F %T %z", host->host_last_update))
+ "%F %T %z", host->_last_update))
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
fprintf(fh, "Host '%s' (last updated: %s):\n",
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
fprintf(fh, "Host '%s' (last updated: %s):\n",
- host->host_name, time_str);
+ SDB_OBJ(host)->name, time_str);
attr_iter = sdb_llist_get_iter(host->attributes);
if (! attr_iter) {
attr_iter = sdb_llist_get_iter(host->attributes);
if (! attr_iter) {
assert(attr);
if (! sdb_strftime(time_str, sizeof(time_str),
assert(attr);
if (! sdb_strftime(time_str, sizeof(time_str),
- "%F %T %z", attr->attr_last_update))
+ "%F %T %z", attr->_last_update))
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
fprintf(fh, "\tAttribute '%s' -> '%s' (last updated: %s)\n",
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
fprintf(fh, "\tAttribute '%s' -> '%s' (last updated: %s)\n",
- attr->attr_name, attr->attr_value, time_str);
+ SDB_OBJ(attr)->name, attr->attr_value, time_str);
}
sdb_llist_iter_destroy(attr_iter);
}
sdb_llist_iter_destroy(attr_iter);
assert(svc);
if (! sdb_strftime(time_str, sizeof(time_str),
assert(svc);
if (! sdb_strftime(time_str, sizeof(time_str),
- "%F %T %z", svc->svc_last_update))
+ "%F %T %z", svc->_last_update))
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
fprintf(fh, "\tService '%s' (last updated: %s)\n",
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
fprintf(fh, "\tService '%s' (last updated: %s)\n",
- svc->svc_name, time_str);
+ SDB_OBJ(svc)->name, time_str);
}
sdb_llist_iter_destroy(svc_iter);
}
sdb_llist_iter_destroy(svc_iter);