diff --git a/src/core/store.c b/src/core/store.c
index ccb5f0a954d97e0f867bc2bb2067573245e30133..9fb05dfdf72c8ff20a8a783ad9069746b7651878 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
static sdb_type_t sdb_attribute_type;
static int
-store_base_init(sdb_object_t *obj, va_list ap)
+store_obj_init(sdb_object_t *obj, va_list ap)
{
- sdb_store_base_t *sobj = STORE_BASE(obj);
+ sdb_store_obj_t *sobj = STORE_OBJ(obj);
sobj->type = va_arg(ap, int);
sobj->interval = 0;
sobj->parent = NULL;
return 0;
-} /* store_base_init */
+} /* store_obj_init */
static void
-store_base_destroy(sdb_object_t *obj)
+store_obj_destroy(sdb_object_t *obj)
{
- const sdb_store_base_t *sobj = STORE_CONST_BASE(obj);
+ const sdb_store_obj_t *sobj = STORE_CONST_OBJ(obj);
if (sobj->parent)
sdb_object_deref(SDB_OBJ(sobj->parent));
-} /* store_base_destroy */
+} /* store_obj_destroy */
static int
sdb_host_init(sdb_object_t *obj, va_list ap)
int ret;
/* this will consume the first argument (type) of ap */
- ret = store_base_init(obj, ap);
+ ret = store_obj_init(obj, ap);
if (ret)
return ret;
sdb_host_t *sobj = HOST(obj);
assert(obj);
- store_base_destroy(obj);
+ store_obj_destroy(obj);
if (sobj->services)
sdb_llist_destroy(sobj->services);
int ret;
/* this will consume the first argument (type) of ap */
- ret = store_base_init(obj, ap);
+ ret = store_obj_init(obj, ap);
if (ret)
return ret;
sdb_service_t *sobj = SVC(obj);
assert(obj);
- store_base_destroy(obj);
+ store_obj_destroy(obj);
if (sobj->attributes)
sdb_llist_destroy(sobj->attributes);
/* this will consume the first two arguments
* (type and last_update) of ap */
- ret = store_base_init(obj, ap);
+ ret = store_obj_init(obj, ap);
if (ret)
return ret;
value = va_arg(ap, const sdb_data_t *);
{
assert(obj);
- store_base_destroy(obj);
+ store_obj_destroy(obj);
sdb_data_free_datum(&ATTR(obj)->value);
} /* sdb_attr_destroy */
/* The obj_lock has to be acquired before calling this function. */
static int
store_obj(const char *hostname, int type, const char *name,
- sdb_time_t last_update, sdb_store_base_t **updated_obj)
+ sdb_time_t last_update, sdb_store_obj_t **updated_obj)
{
char *host_cname = NULL, *cname = NULL;
sdb_llist_t *parent_list;
- sdb_store_base_t *old;
+ sdb_store_obj_t *old;
int status = 0;
if (last_update <= 0)
}
if (type == SDB_HOST)
- old = STORE_BASE(sdb_llist_search_by_name(host_list, name));
+ old = STORE_OBJ(sdb_llist_search_by_name(host_list, name));
else
- old = STORE_BASE(sdb_llist_search_by_name(parent_list, name));
+ old = STORE_OBJ(sdb_llist_search_by_name(parent_list, name));
if (old) {
if (old->last_update > last_update) {
*updated_obj = old;
}
else {
- sdb_store_base_t *new;
+ sdb_store_obj_t *new;
if (type == SDB_ATTRIBUTE) {
/* the value will be updated by the caller */
- new = STORE_BASE(sdb_object_create(name, sdb_attribute_type,
+ new = STORE_OBJ(sdb_object_create(name, sdb_attribute_type,
type, last_update, NULL));
}
else {
sdb_type_t t;
t = type == SDB_HOST ? sdb_host_type : sdb_service_type;
- new = STORE_BASE(sdb_object_create(name, t, type, last_update));
+ new = STORE_OBJ(sdb_object_create(name, t, type, last_update));
}
if (! new) {
/* has_next returns false if the iterator is NULL */
while (sdb_llist_iter_has_next(iter)) {
- sdb_store_base_t *sobj = STORE_BASE(sdb_llist_iter_get_next(iter));
+ sdb_store_obj_t *sobj = STORE_OBJ(sdb_llist_iter_get_next(iter));
assert(sobj);
+ assert(sobj->type == type);
if (! sdb_strftime(time_str, sizeof(time_str),
"%F %T %z", sobj->last_update))
interval_str[sizeof(interval_str) - 1] = '\0';
sdb_strbuf_append(buf, "{\"name\": \"%s\", ", SDB_OBJ(sobj)->name);
- if (type == SDB_ATTRIBUTE) {
+ if (sobj->type == SDB_ATTRIBUTE) {
char tmp[sdb_data_strlen(&ATTR(sobj)->value) + 1];
sdb_data_format(&ATTR(sobj)->value, tmp, sizeof(tmp),
SDB_DOUBLE_QUOTED);
return host != NULL;
} /* sdb_store_has_host */
-sdb_store_base_t *
+sdb_store_obj_t *
sdb_store_get_host(const char *name)
{
sdb_host_t *host;
return NULL;
sdb_object_ref(SDB_OBJ(host));
- return STORE_BASE(host);
+ return STORE_OBJ(host);
} /* sdb_store_get_host */
int
{
int status;
- sdb_store_base_t *updated_attr = NULL;
+ sdb_store_obj_t *updated_attr = NULL;
if ((! hostname) || (! key))
return -1;
} /* sdb_store_service */
int
-sdb_store_host_tojson(sdb_store_base_t *h, sdb_strbuf_t *buf, int flags)
+sdb_store_host_tojson(sdb_store_obj_t *h, sdb_strbuf_t *buf, int flags)
{
sdb_host_t *host;
char time_str[64];
sdb_strbuf_append(buf, "{\"hosts\":[");
while (sdb_llist_iter_has_next(host_iter)) {
- sdb_store_base_t *host = STORE_BASE(sdb_llist_iter_get_next(host_iter));
+ sdb_store_obj_t *host = STORE_OBJ(sdb_llist_iter_get_next(host_iter));
assert(host);
if (sdb_store_host_tojson(host, buf, flags))
/* has_next returns false if the iterator is NULL */
while (sdb_llist_iter_has_next(host_iter)) {
- sdb_store_base_t *host = STORE_BASE(sdb_llist_iter_get_next(host_iter));
+ sdb_store_obj_t *host = STORE_OBJ(sdb_llist_iter_get_next(host_iter));
assert(host);
if (cb(host, user_data)) {