Code

store: Removed now unused tojson functions.
[sysdb.git] / src / include / core / store.h
index 2720db472f30abd4c853b7c1c805979749407f25..9bb75948d76e76c759568dda46860b67f179ade7 100644 (file)
@@ -88,6 +88,13 @@ struct sdb_store_matcher;
 typedef struct sdb_store_matcher sdb_store_matcher_t;
 #define SDB_STORE_MATCHER(obj) ((sdb_store_matcher_t *)(obj))
 
+/*
+ * A JSON formatter converts stored objects into the JSON format.
+ * See http://www.ietf.org/rfc/rfc4627.txt
+ */
+struct sdb_store_json_formatter;
+typedef struct sdb_store_json_formatter sdb_store_json_formatter_t;
+
 /*
  * Queryable fields of a stored object.
  */
@@ -563,54 +570,64 @@ sdb_store_scan(int type, sdb_store_matcher_t *m, sdb_store_matcher_t *filter,
                sdb_store_lookup_cb cb, void *user_data);
 
 /*
- * Flags for serialization functions.
- *
- * By default, the full host object will be included in the serialized output.
- * When specifying any of the flags, the respective information will be left
- * out. The SKIP_EMPTY flags may be used to skip host objects entirely.
+ * Flags for JSON formatting.
  */
 enum {
-       SDB_SKIP_ATTRIBUTES         = 1 << 0,
-       SDB_SKIP_SERVICES           = 1 << 1,
-       SDB_SKIP_METRICS            = 1 << 2,
-       SDB_SKIP_SERVICE_ATTRIBUTES = 1 << 3,
-
-       SDB_SKIP_ALL                = (1 << 8) - 1,
-
-       /* skip hosts if they do not reference any services/metrics */
-       SDB_SKIP_EMPTY_SERVICES     = 1 << 8,
-       SDB_SKIP_EMPTY_METRICS      = 1 << 9,
+       SDB_WANT_ARRAY = 1 << 0,
 };
 
 /*
- * sdb_store_tojson:
- * Serialize the entire store to JSON and append the result to the specified
- * buffer. If specified, only objects matching the filter will be included in
- * the result (see sdb_store_host_tojson for details).
+ * sdb_store_json_formatter:
+ * Create a JSON formatter for the specified object types writing to the
+ * specified buffer.
+ */
+sdb_store_json_formatter_t *
+sdb_store_json_formatter(sdb_strbuf_t *buf, int type, int flags);
+
+/*
+ * sdb_store_json_emit:
+ * Serialize a single object to JSON adding it to the string buffer associated
+ * with the formatter object. The serialized object will not include
+ * attributes or any child objects. Instead, call the function again for each
+ * of those objects. All attributes have to be emitted before any other
+ * children types. Use sdb_store_json_emit_full() to emit a full (filtered)
+ * object.
+ *
+ * Note that the output might not be valid JSON before calling
+ * sdb_store_json_finish().
  *
  * Returns:
  *  - 0 on success
- *  - a negative value on error
+ *  - a negative value else
  */
 int
-sdb_store_tojson(sdb_strbuf_t *buf, sdb_store_matcher_t *filter, int flags);
+sdb_store_json_emit(sdb_store_json_formatter_t *f, sdb_store_obj_t *obj);
 
 /*
- * sdb_store_host_tojson:
- * Serialize a host object to JSON and append the result to the specified
- * buffer. If specified, only objects matching the filter will be included in
- * the result. The filter is applied to each object individually and, thus,
- * should not be of any object-type specific kind. The filter is never applied
- * to the specified host object; the caller is responsible for this and for
- * correctly handling skipped hosts.
+ * sdb_store_json_emit_full:
+ * Serialize a single object including it's attributes and all children to
+ * JSON, adding it to the string buffer associated with the formatter object.
+ * The filter, if specified, is applied to each attribute and child object.
+ * Only matching objects will be included in the output.
+ *
+ * Note that the output might not be valid JSON before calling
+ * sdb_store_json_finish().
  *
  * Returns:
  *  - 0 on success
- *  - a negative value on error
+ *  - a negative value else
+ */
+int
+sdb_store_json_emit_full(sdb_store_json_formatter_t *f, sdb_store_obj_t *obj,
+               sdb_store_matcher_t *filter);
+
+/*
+ * sdb_store_json_finish:
+ * Finish the JSON output. This function has to be called once after emiting
+ * all objects.
  */
 int
-sdb_store_host_tojson(sdb_store_obj_t *host, sdb_strbuf_t *buf,
-               sdb_store_matcher_t *filter, int flags);
+sdb_store_json_finish(sdb_store_json_formatter_t *f);
 
 #ifdef __cplusplus
 } /* extern "C" */