diff --git a/src/core/store.c b/src/core/store.c
index 8dc256ea5645563cc59b4e687eb498ade64e6533..cbd5f0c05595ccdca54ce2dba48b02d386fed972 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
/*
/*
- * syscollector - src/core/store.c
+ * SysDB - src/core/store.c
* Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
* All rights reserved.
*
* Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
* All rights reserved.
*
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "syscollector.h"
+#include "sysdb.h"
#include "core/store.h"
#include "utils/llist.h"
#include "utils/string.h"
#include "core/store.h"
#include "utils/llist.h"
#include "utils/string.h"
/* type used for looking up named objects */
typedef struct {
/* type used for looking up named objects */
typedef struct {
- sc_object_t parent;
+ sdb_object_t parent;
const char *obj_name;
const char *obj_name;
-} sc_store_lookup_obj_t;
-#define SC_STORE_LOOKUP_OBJ_INIT { SC_OBJECT_INIT, NULL }
+} sdb_store_lookup_obj_t;
+#define SDB_STORE_LOOKUP_OBJ_INIT { SDB_OBJECT_INIT, NULL }
/*
* private variables
*/
/*
* private variables
*/
-static sc_llist_t *host_list = NULL;
+static sdb_llist_t *host_list = NULL;
static pthread_rwlock_t host_lock = PTHREAD_RWLOCK_INITIALIZER;
/*
static pthread_rwlock_t host_lock = PTHREAD_RWLOCK_INITIALIZER;
/*
*/
static int
*/
static int
-sc_store_obj_cmp_by_name(const sc_object_t *a, const sc_object_t *b)
+sdb_store_obj_cmp_by_name(const sdb_object_t *a, const sdb_object_t *b)
{
{
- const sc_store_obj_t *h1 = (const sc_store_obj_t *)a;
- const sc_store_obj_t *h2 = (const sc_store_obj_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;
assert(h1 && h2);
return strcasecmp(h1->name, h2->name);
assert(h1 && h2);
return strcasecmp(h1->name, h2->name);
-} /* sc_store_obj_cmp_by_name */
+} /* sdb_store_obj_cmp_by_name */
static int
static int
-sc_cmp_store_obj_with_name(const sc_object_t *a, const sc_object_t *b)
+sdb_cmp_store_obj_with_name(const sdb_object_t *a, const sdb_object_t *b)
{
{
- const sc_store_obj_t *obj = (const sc_store_obj_t *)a;
- const sc_store_lookup_obj_t *lookup = (const sc_store_lookup_obj_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;
assert(obj && lookup);
return strcasecmp(obj->name, lookup->obj_name);
assert(obj && lookup);
return strcasecmp(obj->name, lookup->obj_name);
-} /* sc_cmp_store_obj_with_name */
+} /* sdb_cmp_store_obj_with_name */
static int
static int
-sc_host_init(sc_object_t *obj, va_list ap)
+sdb_host_init(sdb_object_t *obj, va_list ap)
{
const char *name = va_arg(ap, const char *);
{
const char *name = va_arg(ap, const char *);
- SC_HOST(obj)->host_name = strdup(name);
- if (! SC_HOST(obj)->host_name)
+ SDB_HOST(obj)->host_name = strdup(name);
+ if (! SDB_HOST(obj)->host_name)
return -1;
return -1;
- SC_HOST(obj)->host_last_update = sc_gettime();
+ SDB_HOST(obj)->host_last_update = sdb_gettime();
/* ignore errors -> last_update will be updated later */
/* ignore errors -> last_update will be updated later */
- SC_HOST(obj)->attributes = sc_llist_create();
- if (! SC_HOST(obj)->attributes)
+ SDB_HOST(obj)->attributes = sdb_llist_create();
+ if (! SDB_HOST(obj)->attributes)
return -1;
return -1;
- SC_HOST(obj)->services = sc_llist_create();
- if (! SC_HOST(obj)->services)
+ SDB_HOST(obj)->services = sdb_llist_create();
+ if (! SDB_HOST(obj)->services)
return -1;
return 0;
return -1;
return 0;
-} /* sc_host_init */
+} /* sdb_host_init */
static void
static void
-sc_host_destroy(sc_object_t *obj)
+sdb_host_destroy(sdb_object_t *obj)
{
assert(obj);
{
assert(obj);
- if (SC_HOST(obj)->host_name)
- free(SC_HOST(obj)->host_name);
+ if (SDB_HOST(obj)->host_name)
+ free(SDB_HOST(obj)->host_name);
- if (SC_HOST(obj)->attributes)
- sc_llist_destroy(SC_HOST(obj)->attributes);
- if (SC_HOST(obj)->services)
- sc_llist_destroy(SC_HOST(obj)->services);
-} /* sc_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 int
static int
-sc_attr_init(sc_object_t *obj, va_list ap)
+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 *);
{
const char *hostname = va_arg(ap, const char *);
const char *name = va_arg(ap, const char *);
const char *value = va_arg(ap, const char *);
- SC_ATTR(obj)->hostname = strdup(hostname);
- SC_ATTR(obj)->attr_name = strdup(name);
- SC_ATTR(obj)->attr_value = strdup(value);
- if ((! SC_ATTR(obj)->hostname)
- || (! SC_ATTR(obj)->attr_name) || (! SC_ATTR(obj)->attr_value))
+ SDB_ATTR(obj)->hostname = strdup(hostname);
+ SDB_ATTR(obj)->attr_name = strdup(name);
+ SDB_ATTR(obj)->attr_value = strdup(value);
+ if ((! SDB_ATTR(obj)->hostname)
+ || (! SDB_ATTR(obj)->attr_name) || (! SDB_ATTR(obj)->attr_value))
return -1;
return -1;
- SC_ATTR(obj)->attr_last_update = sc_gettime();
+ SDB_ATTR(obj)->attr_last_update = sdb_gettime();
return 0;
return 0;
-} /* sc_attr_init */
+} /* sdb_attr_init */
static void
static void
-sc_attr_destroy(sc_object_t *obj)
+sdb_attr_destroy(sdb_object_t *obj)
{
assert(obj);
{
assert(obj);
- if (SC_ATTR(obj)->hostname)
- free(SC_ATTR(obj)->hostname);
- if (SC_ATTR(obj)->attr_name)
- free(SC_ATTR(obj)->attr_name);
- if (SC_ATTR(obj)->attr_value)
- free(SC_ATTR(obj)->attr_value);
-} /* sc_attr_destroy */
+ 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 */
static int
static int
-sc_svc_init(sc_object_t *obj, va_list ap)
+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 *);
{
const char *hostname = va_arg(ap, const char *);
const char *name = va_arg(ap, const char *);
- SC_SVC(obj)->hostname = strdup(hostname);
- SC_SVC(obj)->svc_name = strdup(name);
- if ((! SC_SVC(obj)->hostname) || (! SC_SVC(obj)->svc_name))
+ SDB_SVC(obj)->hostname = strdup(hostname);
+ SDB_SVC(obj)->svc_name = strdup(name);
+ if ((! SDB_SVC(obj)->hostname) || (! SDB_SVC(obj)->svc_name))
return -1;
return -1;
- SC_SVC(obj)->svc_last_update = sc_gettime();
+ SDB_SVC(obj)->svc_last_update = sdb_gettime();
/* ignore errors -> last_update will be updated later */
return 0;
/* ignore errors -> last_update will be updated later */
return 0;
-} /* sc_svc_init */
+} /* sdb_svc_init */
static void
static void
-sc_svc_destroy(sc_object_t *obj)
+sdb_svc_destroy(sdb_object_t *obj)
{
assert(obj);
{
assert(obj);
- if (SC_SVC(obj)->hostname)
- free(SC_SVC(obj)->hostname);
- if (SC_SVC(obj)->svc_name)
- free(SC_SVC(obj)->svc_name);
-} /* sc_svc_destroy */
+ 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 */
/*
* public API
*/
/*
* public API
*/
-sc_host_t *
-sc_host_create(const char *name)
+sdb_host_t *
+sdb_host_create(const char *name)
{
{
- sc_object_t *obj;
+ sdb_object_t *obj;
if (! name)
return NULL;
if (! name)
return NULL;
- obj = sc_object_create(sizeof(sc_host_t), sc_host_init,
- sc_host_destroy, name);
+ obj = sdb_object_create(sizeof(sdb_host_t), sdb_host_init,
+ sdb_host_destroy, name);
if (! obj)
return NULL;
if (! obj)
return NULL;
- return SC_HOST(obj);
-} /* sc_host_create */
+ return SDB_HOST(obj);
+} /* sdb_host_create */
-sc_host_t *
-sc_host_clone(const sc_host_t *host)
+sdb_host_t *
+sdb_host_clone(const sdb_host_t *host)
{
{
- sc_host_t *clone;
+ sdb_host_t *new;
- clone = sc_host_create(host->host_name);
- if (! clone)
+ new = sdb_host_create(host->host_name);
+ if (! new)
return NULL;
return NULL;
- /* make sure these are initialized; else sc_object_deref() might access
+ /* make sure these are initialized; else sdb_object_deref() might access
* arbitrary memory in case of an error */
* arbitrary memory in case of an error */
- clone->services = clone->attributes = NULL;
+ new->services = new->attributes = NULL;
if (host->attributes) {
if (host->attributes) {
- clone->attributes = sc_llist_clone(host->attributes);
- if (! clone->attributes) {
- sc_object_deref(SC_OBJ(clone));
+ new->attributes = sdb_llist_clone(host->attributes);
+ if (! new->attributes) {
+ sdb_object_deref(SDB_OBJ(new));
return NULL;
}
}
return NULL;
}
}
- clone->host_last_update = host->host_last_update;
+ new->host_last_update = host->host_last_update;
if (host->services) {
if (host->services) {
- clone->services = sc_llist_clone(host->services);
- if (! clone->services) {
- sc_object_deref(SC_OBJ(clone));
+ new->services = sdb_llist_clone(host->services);
+ if (! new->services) {
+ sdb_object_deref(SDB_OBJ(new));
return NULL;
}
}
return NULL;
}
}
- return clone;
-} /* sc_host_clone */
+ return new;
+} /* sdb_host_clone */
int
int
-sc_store_host(const sc_host_t *host)
+sdb_store_host(const sdb_host_t *host)
{
{
- sc_store_lookup_obj_t lookup = SC_STORE_LOOKUP_OBJ_INIT;
- sc_time_t last_update;
+ sdb_store_lookup_obj_t lookup = SDB_STORE_LOOKUP_OBJ_INIT;
+ sdb_time_t last_update;
- sc_host_t *old;
+ sdb_host_t *old;
int status = 0;
if ((! host) || (! host->host_name))
int status = 0;
if ((! host) || (! host->host_name))
last_update = host->host_last_update;
if (last_update <= 0)
last_update = host->host_last_update;
if (last_update <= 0)
- last_update = sc_gettime();
+ last_update = sdb_gettime();
pthread_rwlock_wrlock(&host_lock);
if (! host_list) {
pthread_rwlock_wrlock(&host_lock);
if (! host_list) {
- if (! (host_list = sc_llist_create())) {
+ if (! (host_list = sdb_llist_create())) {
pthread_rwlock_unlock(&host_lock);
return -1;
}
}
lookup.obj_name = host->host_name;
pthread_rwlock_unlock(&host_lock);
return -1;
}
}
lookup.obj_name = host->host_name;
- old = SC_HOST(sc_llist_search(host_list, (const sc_object_t *)&lookup,
- sc_cmp_store_obj_with_name));
+ old = SDB_HOST(sdb_llist_search(host_list, (const sdb_object_t *)&lookup,
+ sdb_cmp_store_obj_with_name));
if (old) {
if (old->host_last_update > last_update) {
if (old) {
if (old->host_last_update > last_update) {
}
}
else {
}
}
else {
- sc_host_t *new = sc_host_clone(host);
+ sdb_host_t *new = sdb_host_clone(host);
if (! new) {
char errbuf[1024];
fprintf(stderr, "store: Failed to clone host object: %s\n",
if (! new) {
char errbuf[1024];
fprintf(stderr, "store: Failed to clone host object: %s\n",
- sc_strerror(errno, errbuf, sizeof(errbuf)));
+ sdb_strerror(errno, errbuf, sizeof(errbuf)));
pthread_rwlock_unlock(&host_lock);
return -1;
}
if (! new->attributes) {
pthread_rwlock_unlock(&host_lock);
return -1;
}
if (! new->attributes) {
- if (! (new->attributes = sc_llist_create())) {
+ if (! (new->attributes = sdb_llist_create())) {
char errbuf[1024];
fprintf(stderr, "store: Failed to initialize "
"host object '%s': %s\n", host->host_name,
char errbuf[1024];
fprintf(stderr, "store: Failed to initialize "
"host object '%s': %s\n", host->host_name,
- sc_strerror(errno, errbuf, sizeof(errbuf)));
- sc_object_deref(SC_OBJ(new));
+ sdb_strerror(errno, errbuf, sizeof(errbuf)));
+ sdb_object_deref(SDB_OBJ(new));
pthread_rwlock_unlock(&host_lock);
return -1;
}
}
if (! new->services) {
pthread_rwlock_unlock(&host_lock);
return -1;
}
}
if (! new->services) {
- if (! (new->services = sc_llist_create())) {
+ if (! (new->services = sdb_llist_create())) {
char errbuf[1024];
fprintf(stderr, "store: Failed to initialize "
"host object '%s': %s\n", host->host_name,
char errbuf[1024];
fprintf(stderr, "store: Failed to initialize "
"host object '%s': %s\n", host->host_name,
- sc_strerror(errno, errbuf, sizeof(errbuf)));
- sc_object_deref(SC_OBJ(new));
+ sdb_strerror(errno, errbuf, sizeof(errbuf)));
+ sdb_object_deref(SDB_OBJ(new));
pthread_rwlock_unlock(&host_lock);
return -1;
}
}
pthread_rwlock_unlock(&host_lock);
return -1;
}
}
- status = sc_llist_insert_sorted(host_list, SC_OBJ(new),
- sc_store_obj_cmp_by_name);
+ status = sdb_llist_insert_sorted(host_list, SDB_OBJ(new),
+ sdb_store_obj_cmp_by_name);
/* pass control to the list or destroy in case of an error */
/* pass control to the list or destroy in case of an error */
- sc_object_deref(SC_OBJ(new));
+ sdb_object_deref(SDB_OBJ(new));
}
pthread_rwlock_unlock(&host_lock);
return status;
}
pthread_rwlock_unlock(&host_lock);
return status;
-} /* sc_store_host */
+} /* sdb_store_host */
-const sc_host_t *
-sc_store_get_host(const char *name)
+const sdb_host_t *
+sdb_store_get_host(const char *name)
{
{
- sc_store_lookup_obj_t lookup = SC_STORE_LOOKUP_OBJ_INIT;
- sc_host_t *host;
+ sdb_store_lookup_obj_t lookup = SDB_STORE_LOOKUP_OBJ_INIT;
+ sdb_host_t *host;
if (! name)
return NULL;
lookup.obj_name = name;
if (! name)
return NULL;
lookup.obj_name = name;
- host = SC_HOST(sc_llist_search(host_list, (const sc_object_t *)&lookup,
- sc_cmp_store_obj_with_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;
if (! host)
return NULL;
return host;
-} /* sc_store_get_host */
+} /* sdb_store_get_host */
-sc_attribute_t *
-sc_attribute_create(const char *hostname,
+sdb_attribute_t *
+sdb_attribute_create(const char *hostname,
const char *name, const char *value)
{
const char *name, const char *value)
{
- sc_object_t *obj;
+ sdb_object_t *obj;
if ((! hostname) || (! name) || (! value))
return NULL;
if ((! hostname) || (! name) || (! value))
return NULL;
- obj = sc_object_create(sizeof(sc_attribute_t), sc_attr_init,
- sc_attr_destroy, hostname, name, value);
+ obj = sdb_object_create(sizeof(sdb_attribute_t), sdb_attr_init,
+ sdb_attr_destroy, hostname, name, value);
if (! obj)
return NULL;
if (! obj)
return NULL;
- return SC_ATTR(obj);
-} /* sc_attribute_create */
+ return SDB_ATTR(obj);
+} /* sdb_attribute_create */
-sc_attribute_t *
-sc_attribute_clone(const sc_attribute_t *attr)
+sdb_attribute_t *
+sdb_attribute_clone(const sdb_attribute_t *attr)
{
{
- sc_attribute_t *clone;
+ sdb_attribute_t *new;
- clone = sc_attribute_create(attr->hostname,
+ new = sdb_attribute_create(attr->hostname,
attr->attr_name, attr->attr_value);
attr->attr_name, attr->attr_value);
- if (! clone)
+ if (! new)
return NULL;
return NULL;
- clone->attr_last_update = attr->attr_last_update;
- return clone;
-} /* sc_attribute_clone */
+ new->attr_last_update = attr->attr_last_update;
+ return new;
+} /* sdb_attribute_clone */
int
int
-sc_store_attribute(const sc_attribute_t *attr)
+sdb_store_attribute(const sdb_attribute_t *attr)
{
{
- sc_store_lookup_obj_t lookup = SC_STORE_LOOKUP_OBJ_INIT;
- sc_host_t *host;
+ sdb_store_lookup_obj_t lookup = SDB_STORE_LOOKUP_OBJ_INIT;
+ sdb_host_t *host;
- sc_attribute_t *old;
+ sdb_attribute_t *old;
- sc_time_t last_update;
+ sdb_time_t last_update;
int status = 0;
int status = 0;
last_update = attr->attr_last_update;
if (last_update <= 0)
last_update = attr->attr_last_update;
if (last_update <= 0)
- last_update = sc_gettime();
+ last_update = sdb_gettime();
if (! host_list)
return -1;
if (! host_list)
return -1;
pthread_rwlock_wrlock(&host_lock);
lookup.obj_name = attr->hostname;
pthread_rwlock_wrlock(&host_lock);
lookup.obj_name = attr->hostname;
- host = SC_HOST(sc_llist_search(host_list, (const sc_object_t *)&lookup,
- sc_cmp_store_obj_with_name));
+ host = SDB_HOST(sdb_llist_search(host_list, (const sdb_object_t *)&lookup,
+ sdb_cmp_store_obj_with_name));
if (! host) {
pthread_rwlock_unlock(&host_lock);
if (! host) {
pthread_rwlock_unlock(&host_lock);
}
lookup.obj_name = attr->attr_name;
}
lookup.obj_name = attr->attr_name;
- old = SC_ATTR(sc_llist_search(host->attributes,
- (const sc_object_t *)&lookup,
- sc_cmp_store_obj_with_name));
+ old = SDB_ATTR(sdb_llist_search(host->attributes,
+ (const sdb_object_t *)&lookup,
+ sdb_cmp_store_obj_with_name));
if (old) {
if (old->host_last_update > last_update) {
if (old) {
if (old->host_last_update > last_update) {
}
}
else {
}
}
else {
- sc_attribute_t *new = sc_attribute_clone(attr);
+ sdb_attribute_t *new = sdb_attribute_clone(attr);
if (! new) {
char errbuf[1024];
fprintf(stderr, "store: Failed to clone attribute object: %s\n",
if (! new) {
char errbuf[1024];
fprintf(stderr, "store: Failed to clone attribute object: %s\n",
- sc_strerror(errno, errbuf, sizeof(errbuf)));
+ sdb_strerror(errno, errbuf, sizeof(errbuf)));
pthread_rwlock_unlock(&host_lock);
return -1;
}
pthread_rwlock_unlock(&host_lock);
return -1;
}
- status = sc_llist_insert_sorted(host->attributes, SC_OBJ(new),
- sc_store_obj_cmp_by_name);
+ status = sdb_llist_insert_sorted(host->attributes, SDB_OBJ(new),
+ sdb_store_obj_cmp_by_name);
/* pass control to the list or destroy in case of an error */
/* pass control to the list or destroy in case of an error */
- sc_object_deref(SC_OBJ(new));
+ sdb_object_deref(SDB_OBJ(new));
}
pthread_rwlock_unlock(&host_lock);
return status;
}
pthread_rwlock_unlock(&host_lock);
return status;
-} /* sc_store_attribute */
+} /* sdb_store_attribute */
-sc_service_t *
-sc_service_create(const char *hostname, const char *name)
+sdb_service_t *
+sdb_service_create(const char *hostname, const char *name)
{
{
- sc_object_t *obj;
+ sdb_object_t *obj;
if ((! hostname) || (! name))
return NULL;
if ((! hostname) || (! name))
return NULL;
- obj = sc_object_create(sizeof(sc_service_t), sc_svc_init,
- sc_svc_destroy, hostname, name);
+ obj = sdb_object_create(sizeof(sdb_service_t), sdb_svc_init,
+ sdb_svc_destroy, hostname, name);
if (! obj)
return NULL;
if (! obj)
return NULL;
- return SC_SVC(obj);
-} /* sc_service_create */
+ return SDB_SVC(obj);
+} /* sdb_service_create */
-sc_service_t *
-sc_service_clone(const sc_service_t *svc)
+sdb_service_t *
+sdb_service_clone(const sdb_service_t *svc)
{
{
- sc_service_t *clone;
+ sdb_service_t *new;
- clone = sc_service_create(svc->hostname, svc->svc_name);
- if (! clone)
+ new = sdb_service_create(svc->hostname, svc->svc_name);
+ if (! new)
return NULL;
return NULL;
- clone->svc_last_update = svc->svc_last_update;
- return clone;
-} /* sc_service_clone */
+ new->svc_last_update = svc->svc_last_update;
+ return new;
+} /* sdb_service_clone */
int
int
-sc_store_service(const sc_service_t *svc)
+sdb_store_service(const sdb_service_t *svc)
{
{
- sc_store_lookup_obj_t lookup = SC_STORE_LOOKUP_OBJ_INIT;
- sc_host_t *host;
+ sdb_store_lookup_obj_t lookup = SDB_STORE_LOOKUP_OBJ_INIT;
+ sdb_host_t *host;
- sc_service_t *old;
+ sdb_service_t *old;
- sc_time_t last_update;
+ sdb_time_t last_update;
int status = 0;
int status = 0;
last_update = svc->svc_last_update;
if (last_update <= 0)
last_update = svc->svc_last_update;
if (last_update <= 0)
- last_update = sc_gettime();
+ last_update = sdb_gettime();
if (! host_list)
return -1;
if (! host_list)
return -1;
pthread_rwlock_wrlock(&host_lock);
lookup.obj_name = svc->hostname;
pthread_rwlock_wrlock(&host_lock);
lookup.obj_name = svc->hostname;
- host = SC_HOST(sc_llist_search(host_list, (const sc_object_t *)&lookup,
- sc_cmp_store_obj_with_name));
+ host = SDB_HOST(sdb_llist_search(host_list, (const sdb_object_t *)&lookup,
+ sdb_cmp_store_obj_with_name));
if (! host) {
pthread_rwlock_unlock(&host_lock);
if (! host) {
pthread_rwlock_unlock(&host_lock);
}
lookup.obj_name = svc->svc_name;
}
lookup.obj_name = svc->svc_name;
- old = SC_SVC(sc_llist_search(host->services, (const sc_object_t *)&lookup,
- sc_cmp_store_obj_with_name));
+ old = SDB_SVC(sdb_llist_search(host->services, (const sdb_object_t *)&lookup,
+ sdb_cmp_store_obj_with_name));
if (old) {
if (old->host_last_update > last_update) {
if (old) {
if (old->host_last_update > last_update) {
}
}
else {
}
}
else {
- sc_service_t *new = sc_service_clone(svc);
+ sdb_service_t *new = sdb_service_clone(svc);
if (! new) {
char errbuf[1024];
fprintf(stderr, "store: Failed to clone service object: %s\n",
if (! new) {
char errbuf[1024];
fprintf(stderr, "store: Failed to clone service object: %s\n",
- sc_strerror(errno, errbuf, sizeof(errbuf)));
+ sdb_strerror(errno, errbuf, sizeof(errbuf)));
pthread_rwlock_unlock(&host_lock);
return -1;
}
pthread_rwlock_unlock(&host_lock);
return -1;
}
- status = sc_llist_insert_sorted(host->services, SC_OBJ(new),
- sc_store_obj_cmp_by_name);
+ status = sdb_llist_insert_sorted(host->services, SDB_OBJ(new),
+ sdb_store_obj_cmp_by_name);
/* pass control to the list or destroy in case of an error */
/* pass control to the list or destroy in case of an error */
- sc_object_deref(SC_OBJ(new));
+ sdb_object_deref(SDB_OBJ(new));
}
pthread_rwlock_unlock(&host_lock);
return status;
}
pthread_rwlock_unlock(&host_lock);
return status;
-} /* sc_store_service */
+} /* sdb_store_service */
-const sc_service_t *
-sc_store_get_service(const sc_host_t *host, const char *name)
+const sdb_service_t *
+sdb_store_get_service(const sdb_host_t *host, const char *name)
{
{
- sc_store_lookup_obj_t lookup = SC_STORE_LOOKUP_OBJ_INIT;
- sc_service_t *svc;
+ sdb_store_lookup_obj_t lookup = SDB_STORE_LOOKUP_OBJ_INIT;
+ sdb_service_t *svc;
if ((! host) || (! name))
return NULL;
lookup.obj_name = name;
if ((! host) || (! name))
return NULL;
lookup.obj_name = name;
- svc = SC_SVC(sc_llist_search(host->services, (const sc_object_t *)&lookup,
- sc_cmp_store_obj_with_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;
if (! svc)
return NULL;
return svc;
-} /* sc_store_get_service */
+} /* sdb_store_get_service */
int
int
-sc_store_dump(FILE *fh)
+sdb_store_dump(FILE *fh)
{
{
- sc_llist_iter_t *host_iter;
+ sdb_llist_iter_t *host_iter;
if (! fh)
return -1;
pthread_rwlock_rdlock(&host_lock);
if (! fh)
return -1;
pthread_rwlock_rdlock(&host_lock);
- host_iter = sc_llist_get_iter(host_list);
+ host_iter = sdb_llist_get_iter(host_list);
if (! host_iter) {
pthread_rwlock_unlock(&host_lock);
return -1;
}
if (! host_iter) {
pthread_rwlock_unlock(&host_lock);
return -1;
}
- while (sc_llist_iter_has_next(host_iter)) {
- sc_host_t *host = SC_HOST(sc_llist_iter_get_next(host_iter));
- sc_llist_iter_t *svc_iter;
- sc_llist_iter_t *attr_iter;
+ while (sdb_llist_iter_has_next(host_iter)) {
+ sdb_host_t *host = SDB_HOST(sdb_llist_iter_get_next(host_iter));
+ sdb_llist_iter_t *svc_iter;
+ sdb_llist_iter_t *attr_iter;
char time_str[64];
assert(host);
char time_str[64];
assert(host);
- if (! sc_strftime(time_str, sizeof(time_str),
+ if (! sdb_strftime(time_str, sizeof(time_str),
"%F %T %z", host->host_last_update))
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
"%F %T %z", host->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",
host->host_name, time_str);
fprintf(fh, "Host '%s' (last updated: %s):\n",
host->host_name, time_str);
- attr_iter = sc_llist_get_iter(host->attributes);
+ attr_iter = sdb_llist_get_iter(host->attributes);
if (! attr_iter) {
char errbuf[1024];
fprintf(fh, "Failed to retrieve attributes: %s\n",
if (! attr_iter) {
char errbuf[1024];
fprintf(fh, "Failed to retrieve attributes: %s\n",
- sc_strerror(errno, errbuf, sizeof(errbuf)));
+ sdb_strerror(errno, errbuf, sizeof(errbuf)));
continue;
}
continue;
}
- while (sc_llist_iter_has_next(attr_iter)) {
- sc_attribute_t *attr = SC_ATTR(sc_llist_iter_get_next(attr_iter));
+ while (sdb_llist_iter_has_next(attr_iter)) {
+ sdb_attribute_t *attr = SDB_ATTR(sdb_llist_iter_get_next(attr_iter));
assert(attr);
assert(attr);
- if (! sc_strftime(time_str, sizeof(time_str),
+ if (! sdb_strftime(time_str, sizeof(time_str),
"%F %T %z", attr->attr_last_update))
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
"%F %T %z", attr->attr_last_update))
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
attr->attr_name, attr->attr_value, time_str);
}
attr->attr_name, attr->attr_value, time_str);
}
- sc_llist_iter_destroy(attr_iter);
+ sdb_llist_iter_destroy(attr_iter);
- svc_iter = sc_llist_get_iter(host->services);
+ svc_iter = sdb_llist_get_iter(host->services);
if (! svc_iter) {
char errbuf[1024];
fprintf(fh, "Failed to retrieve services: %s\n",
if (! svc_iter) {
char errbuf[1024];
fprintf(fh, "Failed to retrieve services: %s\n",
- sc_strerror(errno, errbuf, sizeof(errbuf)));
+ sdb_strerror(errno, errbuf, sizeof(errbuf)));
continue;
}
continue;
}
- while (sc_llist_iter_has_next(svc_iter)) {
- sc_service_t *svc = SC_SVC(sc_llist_iter_get_next(svc_iter));
+ while (sdb_llist_iter_has_next(svc_iter)) {
+ sdb_service_t *svc = SDB_SVC(sdb_llist_iter_get_next(svc_iter));
assert(svc);
assert(svc);
- if (! sc_strftime(time_str, sizeof(time_str),
+ if (! sdb_strftime(time_str, sizeof(time_str),
"%F %T %z", svc->svc_last_update))
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
"%F %T %z", svc->svc_last_update))
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
svc->svc_name, time_str);
}
svc->svc_name, time_str);
}
- sc_llist_iter_destroy(svc_iter);
+ sdb_llist_iter_destroy(svc_iter);
}
}
- sc_llist_iter_destroy(host_iter);
+ sdb_llist_iter_destroy(host_iter);
pthread_rwlock_unlock(&host_lock);
return 0;
pthread_rwlock_unlock(&host_lock);
return 0;
-} /* sc_store_dump */
+} /* sdb_store_dump */
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */