Code

Merged branch 'master' of git://git.tokkee.org/sysdb.
[sysdb.git] / src / include / core / store.h
index bc4de1090f6d4a95e980835cf7c4033002776e79..100aadf260700bdbb0c77f59c16cfedd0ca50048 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "sysdb.h"
 #include "core/object.h"
+#include "core/data.h"
 #include "core/time.h"
 #include "utils/llist.h"
 #include "utils/strbuf.h"
 extern "C" {
 #endif
 
+/*
+ * sdb_store_base_t represents the super-class of any object stored in the
+ * database. It inherits from sdb_object_t and may safely be cast to a generic
+ * object to access its name.
+ */
+struct sdb_store_base;
+typedef struct sdb_store_base sdb_store_base_t;
+
 /*
  * sdb_store_host:
  * Add/update a host in the store. If the host, identified by its
@@ -57,9 +66,20 @@ extern "C" {
 int
 sdb_store_host(const char *name, sdb_time_t last_update);
 
+/*
+ * sdb_store_has_host:
+ * sdb_store_get_host:
+ * Query the store for a host by its (canonicalized) name.
+ *
+ * sdb_store_get_host increments the ref count of the host object. The caller
+ * needs to deref it when no longer using it.
+ */
 _Bool
 sdb_store_has_host(const char *name);
 
+sdb_store_base_t *
+sdb_store_get_host(const char *name);
+
 /*
  * sdb_store_attribute:
  * Add/update a host's attribute in the store. If the attribute, identified by
@@ -76,7 +96,8 @@ sdb_store_has_host(const char *name);
  *  - a negative value on error
  */
 int
-sdb_store_attribute(const char *hostname, const char *key, const char *value,
+sdb_store_attribute(const char *hostname,
+               const char *key, const sdb_data_t *value,
                sdb_time_t last_update);
 
 /*
@@ -99,6 +120,18 @@ int
 sdb_store_service(const char *hostname, const char *name,
                sdb_time_t last_update);
 
+/*
+ * Flags for serialization functions.
+ *
+ * By default, the full object will be included in the serialized output. When
+ * specifying any of the flags, the respective information will be left out.
+ */
+enum {
+       SDB_SKIP_ATTRIBUTES         = 1 << 0,
+       SDB_SKIP_SERVICES           = 1 << 1,
+       SDB_SKIP_SERVICE_ATTRIBUTES = 1 << 2,
+};
+
 /*
  * sdb_store_tojson:
  * Serialize the entire store to JSON and append the result to the specified
@@ -109,7 +142,19 @@ sdb_store_service(const char *hostname, const char *name,
  *  - a negative value on error
  */
 int
-sdb_store_tojson(sdb_strbuf_t *buf);
+sdb_store_tojson(sdb_strbuf_t *buf, int flags);
+
+/*
+ * sdb_store_host_tojson:
+ * Serialize a host object to JSON and append the result to the specified
+ * buffer.
+ *
+ * Returns:
+ *  - 0 on success
+ *  - a negative value on error
+ */
+int
+sdb_store_host_tojson(sdb_store_base_t *host, sdb_strbuf_t *buf, int flags);
 
 #ifdef __cplusplus
 } /* extern "C" */