diff --git a/src/core/store.c b/src/core/store.c
index c66b5236a95b82869d19b532237a0ed0e4832aef..92f3e510b9bccd6c57076bfbbf920c09c9754fbf 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
#include "sysdb.h"
#include "core/store.h"
#include "core/error.h"
#include "sysdb.h"
#include "core/store.h"
#include "core/error.h"
+#include "core/plugin.h"
#include "utils/llist.h"
#include <assert.h>
#include "utils/llist.h"
#include <assert.h>
const sdb_host_t *host = (const sdb_host_t *)obj;
sdb_host_t *new;
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;
if (! new)
return NULL;
* public API
*/
* 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)
{
int
sdb_store_host(const sdb_host_t *host)
{
+ char *cname;
+
sdb_time_t last_update;
sdb_host_t *old;
sdb_time_t last_update;
sdb_host_t *old;
+
int status = 0;
if ((! host) || (! SDB_CONST_OBJ(host)->name))
return -1;
int status = 0;
if ((! host) || (! SDB_CONST_OBJ(host)->name))
return -1;
+ cname = sdb_plugin_cname(strdup(SDB_CONST_OBJ(host)->name));
+ if (! cname) {
+ sdb_log(SDB_LOG_ERR, "store: strdup failed");
+ return -1;
+ }
+
last_update = host->_last_update;
if (last_update <= 0)
last_update = sdb_gettime();
last_update = host->_last_update;
if (last_update <= 0)
last_update = sdb_gettime();
}
}
}
}
- 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")",
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;
/* don't report an error; the host may be updated by multiple
* backends */
status = 1;
return -1;
}
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 "
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);
sdb_strerror(errno, errbuf, sizeof(errbuf)));
sdb_object_deref(SDB_OBJ(new));
pthread_rwlock_unlock(&host_lock);
if (! (new->services = sdb_llist_create())) {
char errbuf[1024];
sdb_log(SDB_LOG_ERR, "store: Failed to initialize "
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);
sdb_strerror(errno, errbuf, sizeof(errbuf)));
sdb_object_deref(SDB_OBJ(new));
pthread_rwlock_unlock(&host_lock);