X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Finclude%2Fcore%2Fstore.h;h=9bb75948d76e76c759568dda46860b67f179ade7;hb=f20bc8d5ec8abe86914eeedc741ca00109fb6ece;hp=97bb6e65cd56be1afff6a6da035a6ab0ae18803b;hpb=9d15e8a6bb4b1d5219f65b859a0744e9d91c8384;p=sysdb.git diff --git a/src/include/core/store.h b/src/include/core/store.h index 97bb6e6..9bb7594 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -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. */ @@ -381,12 +388,20 @@ sdb_store_matcher_t * sdb_store_isnnull_matcher(sdb_store_expr_t *expr); /* - * sdb_store_child_matcher: - * Creates a matcher matching an object's children of the specified type. It - * matches if *any* of those children match 'm'. + * sdb_store_any_matcher: + * Creates a matcher iterating over objects of the specified type. It matches + * if *any* of those objects match 'm'. + */ +sdb_store_matcher_t * +sdb_store_any_matcher(int type, sdb_store_matcher_t *m); + +/* + * sdb_store_all_matcher: + * Creates a matcher iterating over objects of the specified type. It matches + * if *all* of those objects match 'm'. */ sdb_store_matcher_t * -sdb_store_child_matcher(int type, sdb_store_matcher_t *m); +sdb_store_all_matcher(int type, sdb_store_matcher_t *m); /* * sdb_store_lt_matcher, sdb_store_le_matcher, sdb_store_eq_matcher, @@ -532,93 +547,87 @@ sdb_store_matcher_matches(sdb_store_matcher_t *m, sdb_store_obj_t *obj, /* * sdb_store_lookup_cb: * Lookup callback. It is called for each matching object when looking up data - * in the store. The lookup aborts if the callback returns non-zero. + * in the store passing on the lookup filter and the specified user-data. The + * lookup aborts early if the callback returns non-zero. */ -typedef int (*sdb_store_lookup_cb)(sdb_store_obj_t *obj, void *user_data); +typedef int (*sdb_store_lookup_cb)(sdb_store_obj_t *obj, + sdb_store_matcher_t *filter, void *user_data); /* * sdb_store_scan: - * Look up objects in the store. The specified callback function is called for - * each object in the store matching 'm'. The function performs a full scan of - * all hosts stored in the database. If specified, the filter will be used to - * preselect objects for further evaluation. See the description of - * 'sdb_store_matcher_matches' for details. + * Look up objects of the specified type in the store. The specified callback + * function is called for each object in the store matching 'm'. The function + * performs a full scan of all objects stored in the database. If specified, + * the filter will be used to preselect objects for further evaluation. See + * the description of 'sdb_store_matcher_matches' for details. * * Returns: * - 0 on success * - a negative value else */ int -sdb_store_scan(sdb_store_matcher_t *m, sdb_store_matcher_t *filter, +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). - * - * Returns: - * - 0 on success - * - a negative value on error + * sdb_store_json_formatter: + * Create a JSON formatter for the specified object types writing to the + * specified buffer. */ -int -sdb_store_tojson(sdb_strbuf_t *buf, sdb_store_matcher_t *filter, int flags); +sdb_store_json_formatter_t * +sdb_store_json_formatter(sdb_strbuf_t *buf, int type, int flags); /* - * 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: + * 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_host_tojson(sdb_store_obj_t *host, sdb_strbuf_t *buf, - sdb_store_matcher_t *filter, int flags); - -/* - * sdb_store_iter_cb: - * Store iterator callback. Iteration stops if the callback returns non-zero. - */ -typedef int (*sdb_store_iter_cb)(sdb_store_obj_t *obj, void *user_data); +sdb_store_json_emit(sdb_store_json_formatter_t *f, sdb_store_obj_t *obj); /* - * sdb_store_iterate: - * Iterate the entire store, calling the specified callback for each object. - * The user_data pointer is passed on to each call of the callback. + * 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 else */ int -sdb_store_iterate(sdb_store_iter_cb cb, void *user_data); +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_json_finish(sdb_store_json_formatter_t *f); #ifdef __cplusplus } /* extern "C" */