Code

15f435fefdc6136a83fdb2e53a004a5cac82e8a9
[sysdb.git] / src / include / core / store.h
1 /*
2  * SysDB - src/include/core/store.h
3  * Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
28 #ifndef SDB_CORE_STORE_H
29 #define SDB_CORE_STORE_H 1
31 #include "sysdb.h"
32 #include "core/object.h"
33 #include "core/data.h"
34 #include "core/time.h"
35 #include "core/timeseries.h"
36 #include "parser/ast.h"
37 #include "utils/strbuf.h"
39 #include <stdbool.h>
40 #include <stdio.h>
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
46 /*
47  * Store object types.
48  */
49 enum {
50         SDB_HOST = 1,
51         SDB_SERVICE,
52         SDB_METRIC,
54         SDB_ATTRIBUTE = 1 << 4,
56         /*
57          * Queryable fields of a stored object.
58          */
59         SDB_FIELD_NAME = 1 << 8, /* type: string */
60         SDB_FIELD_LAST_UPDATE,   /* type: datetime */
61         SDB_FIELD_AGE,           /* type: datetime */
62         SDB_FIELD_INTERVAL,      /* type: datetime */
63         SDB_FIELD_BACKEND,       /* type: array of strings */
64         SDB_FIELD_VALUE,         /* attributes only;  type: type of the value */
65         SDB_FIELD_TIMESERIES,    /* metrics only;  type: boolean */
66 };
67 #define SDB_STORE_TYPE_TO_NAME(t) \
68         (((t) == SDB_HOST) ? "host" \
69                 : ((t) == SDB_SERVICE) ? "service" \
70                 : ((t) == SDB_METRIC) ? "metric" \
71                 : ((t) == SDB_ATTRIBUTE) ? "attribute" \
72                 : ((t) == (SDB_ATTRIBUTE | SDB_HOST)) ? "host attribute" \
73                 : ((t) == (SDB_ATTRIBUTE | SDB_SERVICE)) ? "service attribute" \
74                 : ((t) == (SDB_ATTRIBUTE | SDB_METRIC)) ? "metric attribute" \
75                 : "unknown")
77 #define SDB_FIELD_TO_NAME(f) \
78         (((f) == SDB_FIELD_NAME) ? "name" \
79                 : ((f) == SDB_FIELD_LAST_UPDATE) ? "last-update" \
80                 : ((f) == SDB_FIELD_AGE) ? "age" \
81                 : ((f) == SDB_FIELD_INTERVAL) ? "interval" \
82                 : ((f) == SDB_FIELD_BACKEND) ? "backend" \
83                 : ((f) == SDB_FIELD_VALUE) ? "value" \
84                 : ((f) == SDB_FIELD_TIMESERIES) ? "timeseries" \
85                 : "unknown")
87 #define SDB_FIELD_TYPE(f) \
88         (((f) == SDB_FIELD_NAME) ? SDB_TYPE_STRING \
89                 : ((f) == SDB_FIELD_LAST_UPDATE) ? SDB_TYPE_DATETIME \
90                 : ((f) == SDB_FIELD_AGE) ? SDB_TYPE_DATETIME \
91                 : ((f) == SDB_FIELD_INTERVAL) ? SDB_TYPE_DATETIME \
92                 : ((f) == SDB_FIELD_BACKEND) ? (SDB_TYPE_ARRAY | SDB_TYPE_STRING) \
93                 : ((f) == SDB_FIELD_VALUE) ? -1 /* unknown */ \
94                 : ((f) == SDB_FIELD_TIMESERIES) ? SDB_TYPE_BOOLEAN \
95                 : -1)
97 /*
98  * sdb_store_obj_t represents the super-class of any object stored in the
99  * database. It inherits from sdb_object_t and may safely be cast to a generic
100  * object to access its name.
101  */
102 struct sdb_store_obj;
103 typedef struct sdb_store_obj sdb_store_obj_t;
105 /*
106  * A metric store describes how to access a metric's data.
107  */
108 typedef struct {
109         const char *type;
110         const char *id;
111 } sdb_metric_store_t;
113 /*
114  * Expressions represent arithmetic expressions based on stored objects and
115  * their various attributes.
116  *
117  * An expression object inherits from sdb_object_t and, thus, may safely be
118  * cast to a generic object.
119  */
120 struct sdb_store_expr;
121 typedef struct sdb_store_expr sdb_store_expr_t;
122 #define SDB_STORE_EXPR(obj) ((sdb_store_expr_t *)(obj))
124 /*
125  * An expression iterator iterates over the values of an iterable expression
126  * (see sdb_store_expr_iterable).
127  */
128 struct sdb_store_expr_iter;
129 typedef struct sdb_store_expr_iter sdb_store_expr_iter_t;
131 /*
132  * Store matchers may be used to lookup hosts from the store based on their
133  * various attributes. Service and attribute matchers are applied to a host's
134  * services and attributes and evaluate to true if *any* service or attribute
135  * matches.
136  *
137  * A store matcher object inherits from sdb_object_t and, thus, may safely be
138  * cast to a generic object.
139  */
140 struct sdb_store_matcher;
141 typedef struct sdb_store_matcher sdb_store_matcher_t;
142 #define SDB_STORE_MATCHER(obj) ((sdb_store_matcher_t *)(obj))
144 /*
145  * A JSON formatter converts stored objects into the JSON format.
146  * See http://www.ietf.org/rfc/rfc4627.txt
147  */
148 struct sdb_store_json_formatter;
149 typedef struct sdb_store_json_formatter sdb_store_json_formatter_t;
151 /*
152  * A store writer describes the interface for plugins implementing a store.
153  *
154  * Any of the call-back functions shall return:
155  *  - 0 on success
156  *  - a positive value if the new entry is older than the currently stored
157  *    entry (in this case, no update will happen)
158  *  - a negative value on error
159  */
160 typedef struct {
161         /*
162          * store_host:
163          * Add/update a host in the store. If the host, identified by its
164          * canonicalized name, already exists, it will be updated according to the
165          * specified name and timestamp. Else, a new entry will be created in the
166          * store.
167          */
168         int (*store_host)(const char *name, sdb_time_t last_update,
169                         sdb_object_t *user_data);
171         /*
172          * store_service:
173          * Add/update a service in the store. If the service, identified by its
174          * name, already exists for the specified host, it will be updated
175          * according to the specified name and timestamp. If the referenced host
176          * does not exist, an error will be reported. Else, a new entry will be
177          * created in the store.
178          */
179         int (*store_service)(const char *hostname, const char *name,
180                         sdb_time_t last_update, sdb_object_t *user_data);
182         /*
183          * store_metric:
184          * Add/update a metric in the store. If the metric, identified by its
185          * name, already exists for the specified host, it will be updated
186          * according to the specified attributes. If the referenced host does not
187          * exist, an error will be reported. Else, a new entry will be created in
188          * the store.
189          */
190         int (*store_metric)(const char *hostname, const char *name,
191                         sdb_metric_store_t *store, sdb_time_t last_update,
192                         sdb_object_t *user_data);
194         /*
195          * store_attribute:
196          * Add/update a host's attribute in the store. If the attribute,
197          * identified by its key, already exists for the specified host, it will
198          * be updated to the specified values. If the referenced host does not
199          * exist, an error will be reported. Else, a new entry will be created in
200          * the store.
201          */
202         int (*store_attribute)(const char *hostname,
203                         const char *key, const sdb_data_t *value, sdb_time_t last_update,
204                         sdb_object_t *user_data);
206         /*
207          * store_service_attr:
208          * Add/update a service's attribute in the store. If the attribute,
209          * identified by its key, already exists for the specified service, it
210          * will be updated to the specified value. If the references service (for
211          * the specified host) does not exist, an error will be reported.
212          */
213         int (*store_service_attr)(const char *hostname, const char *service,
214                         const char *key, const sdb_data_t *value, sdb_time_t last_update,
215                         sdb_object_t *user_data);
217         /*
218          * store_metric_attr:
219          * Add/update a metric's attribute in the store. If the attribute,
220          * identified by its key, already exists for the specified metric, it will
221          * be updated to the specified value. If the references metric (for the
222          * specified host) does not exist, an error will be reported.
223          */
224         int (*store_metric_attr)(const char *hostname, const char *metric,
225                         const char *key, const sdb_data_t *value, sdb_time_t last_update,
226                         sdb_object_t *user_data);
227 } sdb_store_writer_t;
229 /*
230  * sdb_store_init:
231  * Initialize the store sub-system. This function has to be called before
232  * doing any other store operations.
233  *
234  * Returns:
235  *  - 0 on success
236  *  - a negative value else
237  */
238 int
239 sdb_store_init(void);
241 /*
242  * sdb_store_clear:
243  * Clear the entire store and remove all stored objects.
244  */
245 void
246 sdb_store_clear(void);
248 /*
249  * sdb_store_has_host:
250  * sdb_store_get_host:
251  * Query the store for a host by its (canonicalized) name.
252  *
253  * sdb_store_get_host increments the ref count of the host object. The caller
254  * needs to deref it when no longer using it.
255  */
256 bool
257 sdb_store_has_host(const char *name);
259 sdb_store_obj_t *
260 sdb_store_get_host(const char *name);
262 /*
263  * sdb_store_fetch_timeseries:
264  * Fetch the time-series described by the specified host's metric and
265  * serialize it as JSON into the provided string buffer.
266  *
267  * Returns:
268  *  - 0 on success
269  *  - a negative value else
270  */
271 int
272 sdb_store_fetch_timeseries(const char *hostname, const char *metric,
273                 sdb_timeseries_opts_t *opts, sdb_strbuf_t *buf);
275 /*
276  * sdb_store_get_child:
277  * Retrieve a host's child object of the specified type and name. The
278  * reference count of the child object will be incremented before returning
279  * it. The caller is responsible for releasing the object once it's no longer
280  * used.
281  *
282  * Returns:
283  *  - the child object on success
284  *  - NULL else
285  */
286 sdb_store_obj_t *
287 sdb_store_get_child(sdb_store_obj_t *host, int type, const char *name);
289 /*
290  * sdb_store_get_field:
291  * Get the value of a stored object's queryable field. The caller is
292  * responsible for freeing any dynamically allocated memory possibly stored in
293  * the returned value. If 'res' is NULL, the function will return whether the
294  * field exists.
295  *
296  * Returns:
297  *  - 0 on success
298  *  - a negative value else
299  */
300 int
301 sdb_store_get_field(sdb_store_obj_t *obj, int field, sdb_data_t *res);
303 /*
304  * sdb_store_get_attr:
305  * Get the value of a stored object's attribute. The caller is responsible for
306  * freeing any dynamically allocated memory possibly stored in the returned
307  * value. If 'res' is NULL, the function will return whether the attribute
308  * exists. If specified, only attributes matching the filter will be
309  * considered.
310  *
311  * Returns:
312  *  - 0 if the attribute exists
313  *  - a negative value else
314  */
315 int
316 sdb_store_get_attr(sdb_store_obj_t *obj, const char *name, sdb_data_t *res,
317                 sdb_store_matcher_t *filter);
319 /*
320  * Querying a store:
321  *
322  *  - Query interface: A query is a formal description of an interaction with
323  *    the store. It can be used, both, for read and write access. The query is
324  *    described by its abstract syntax tree (AST). The parser package provides
325  *    means to parse a string (SysQL) representation of the query into an AST.
326  *
327  *  - Matcher / expression interface: This low-level interface provides direct
328  *    control over how to access the store. It is used by the query
329  *    implementation internally and can only be used for read access.
330  */
332 /*
333  * sdb_store_query_t:
334  * A parsed query readily prepared for execution.
335  */
336 struct sdb_store_query;
337 typedef struct sdb_store_query sdb_store_query_t;
339 /*
340  * sdb_store_query_prepare:
341  * Prepare the query described by 'ast' for execution in a store.
342  *
343  * Returns:
344  *  - a store query on success
345  *  - NULL else
346  */
347 sdb_store_query_t *
348 sdb_store_query_prepare(sdb_ast_node_t *ast);
350 /*
351  * sdb_store_query_prepare_matcher:
352  * Prepare the logical expression described by 'ast' for execution as a store
353  * matcher.
354  *
355  * Returns:
356  *  - a matcher on success
357  *  - NULL else
358  */
359 sdb_store_matcher_t *
360 sdb_store_query_prepare_matcher(sdb_ast_node_t *ast);
362 /*
363  * sdb_store_query_execute:
364  * Execute a previously prepared query. The query result will be written to
365  * 'buf' and any errors to 'errbuf'.
366  *
367  * Returns:
368  *  - the result type (to be used by the server reply)
369  *  - a negative value on error
370  */
371 int
372 sdb_store_query_execute(sdb_store_query_t *m,
373                 sdb_strbuf_t *buf, sdb_strbuf_t *errbuf);
375 /*
376  * sdb_store_expr_create:
377  * Creates an arithmetic expression implementing the specified operator on the
378  * specified left and right operand.
379  *
380  * Returns:
381  *  - an expression object on success
382  *  - NULL else
383  */
384 sdb_store_expr_t *
385 sdb_store_expr_create(int op, sdb_store_expr_t *left, sdb_store_expr_t *right);
387 /*
388  * sdb_store_expr_typed:
389  * Creates an expression which evaluates in the context of an object's sibling
390  * as specified by the given type.
391  *
392  * Returns:
393  *  - an expression object on success
394  *  - NULL else
395  */
396 sdb_store_expr_t *
397 sdb_store_expr_typed(int typ, sdb_store_expr_t *expr);
399 /*
400  * sdb_store_expr_fieldvalue:
401  * Creates an expression which evaluates to the value of the specified
402  * queryable field of a stored object.
403  *
404  * Returns:
405  *  - an expression object on success
406  *  - NULL else
407  */
408 sdb_store_expr_t *
409 sdb_store_expr_fieldvalue(int field);
411 /*
412  * sdb_store_expr_attrvalue:
413  * Creates an expression which evaluates to the value of the specified
414  * attribute of a stored object. Evaluates to a NULL value if the attribute
415  * does not exist.
416  *
417  * Returns:
418  *  - an expression object on success
419  *  - NULL else
420  */
421 sdb_store_expr_t *
422 sdb_store_expr_attrvalue(const char *name);
424 /*
425  * sdb_store_expr_constvalue:
426  * Creates an expression which evaluates to the specified constant value.
427  *
428  * Returns:
429  *  - an expression object on success
430  *  - NULL else
431  */
432 sdb_store_expr_t *
433 sdb_store_expr_constvalue(const sdb_data_t *value);
435 /*
436  * sdb_store_expr_eval:
437  * Evaluate an expression for the specified stored object and stores the
438  * result in 'res'. The result's value will be allocated dynamically if
439  * necessary and, thus, should be free'd by the caller (e.g. using
440  * sdb_data_free_datum). The object may be NULL, in which case the expression
441  * needs to evaluate to a constant value. If specified, only objects matching
442  * the filter will be used during the evaluation.
443  *
444  * Returns:
445  *  - 0 on success
446  *  - a negative value else
447  */
448 int
449 sdb_store_expr_eval(sdb_store_expr_t *expr, sdb_store_obj_t *obj,
450                 sdb_data_t *res, sdb_store_matcher_t *filter);
452 /*
453  * sdb_store_expr_iterable:
454  * Check whether an expression, evaluated in the specified context (HOST,
455  * SERVICE, METRIC) is iterable, that is, if it may evaluate to multiple
456  * values.
457  */
458 bool
459 sdb_store_expr_iterable(sdb_store_expr_t *expr, int context);
461 /*
462  * sdb_store_expr_iter:
463  * Iterate over the elements of an iterable expression. sdb_store_expr_iter
464  * returns NULL if the expression is not iterable (for the specified object).
465  * See also sdb_store_expr_iterable.
466  *
467  * sdb_store_expr_iter_get_next returns NULL if there is no next element.
468  */
469 sdb_store_expr_iter_t *
470 sdb_store_expr_iter(sdb_store_expr_t *expr, sdb_store_obj_t *obj,
471                 sdb_store_matcher_t *filter);
472 void
473 sdb_store_expr_iter_destroy(sdb_store_expr_iter_t *iter);
475 bool
476 sdb_store_expr_iter_has_next(sdb_store_expr_iter_t *iter);
477 sdb_data_t
478 sdb_store_expr_iter_get_next(sdb_store_expr_iter_t *iter);
480 /*
481  * sdb_store_dis_matcher:
482  * Creates a matcher matching the disjunction (logical OR) of two matchers.
483  */
484 sdb_store_matcher_t *
485 sdb_store_dis_matcher(sdb_store_matcher_t *left, sdb_store_matcher_t *right);
487 /*
488  * sdb_store_con_matcher:
489  * Creates a matcher matching the conjunction (logical AND) of two matchers.
490  */
491 sdb_store_matcher_t *
492 sdb_store_con_matcher(sdb_store_matcher_t *left, sdb_store_matcher_t *right);
494 /*
495  * sdb_store_inv_matcher::
496  * Creates a matcher matching the inverse (logical NOT) of a matcher.
497  */
498 sdb_store_matcher_t *
499 sdb_store_inv_matcher(sdb_store_matcher_t *m);
501 /*
502  * sdb_store_any_matcher:
503  * Creates a matcher iterating over values of the first expression (which has
504  * to be iterable). It matches if *any* of those elements match 'm'. 'm' has
505  * to be an ary operation with the left operand unset.
506  */
507 sdb_store_matcher_t *
508 sdb_store_any_matcher(sdb_store_expr_t *iter, sdb_store_matcher_t *m);
510 /*
511  * sdb_store_all_matcher:
512  * Creates a matcher iterating over values of the first expression (which has
513  * to be iterable). It matches if *all* of those elements match 'm'. 'm' has
514  * to be an ary operation with the left operand unset.
515  */
516 sdb_store_matcher_t *
517 sdb_store_all_matcher(sdb_store_expr_t *iter, sdb_store_matcher_t *m);
519 /*
520  * sdb_store_in_matcher:
521  * Creates a matcher which matches if the right value evaluates to an array
522  * value and the left value is included in that array. See sdb_data_inarray
523  * for more details.
524  */
525 sdb_store_matcher_t *
526 sdb_store_in_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
528 /*
529  * sdb_store_lt_matcher, sdb_store_le_matcher, sdb_store_eq_matcher,
530  * sdb_store_ge_matcher, sdb_store_gt_matcher:
531  * Create conditional matchers comparing the values of two expressions. The
532  * matcher matches if the left expression compres less than, less or equal
533  * than, equal to, not equal to, greater or equal than, or greater than the
534  * right expression.
535  */
536 sdb_store_matcher_t *
537 sdb_store_lt_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
538 sdb_store_matcher_t *
539 sdb_store_le_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
540 sdb_store_matcher_t *
541 sdb_store_eq_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
542 sdb_store_matcher_t *
543 sdb_store_ne_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
544 sdb_store_matcher_t *
545 sdb_store_ge_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
546 sdb_store_matcher_t *
547 sdb_store_gt_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
549 /*
550  * sdb_store_regex_matcher:
551  * Creates a matcher which matches the string value the left expression
552  * evaluates to against the regular expression the right expression evaluates
553  * to. The right expression may either be a constant value regular expression
554  * or string or a dynamic value evaluating to a string. In the latter case,
555  * the string is compiled to a regex every time the matcher is executed.
556  */
557 sdb_store_matcher_t *
558 sdb_store_regex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
560 /*
561  * sdb_store_nregex_matcher:
562  * Creates a regex matcher just like sdb_store_regex_matcher except that it
563  * matches in case the regular expression does not match.
564  */
565 sdb_store_matcher_t *
566 sdb_store_nregex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
568 /*
569  * sdb_store_isnull_matcher:
570  * Creates a matcher matching NULL values.
571  */
572 sdb_store_matcher_t *
573 sdb_store_isnull_matcher(sdb_store_expr_t *expr);
575 /*
576  * sdb_store_istrue_matcher, sdb_store_isfalse_matcher:
577  * Creates a matcher matching boolean values.
578  */
579 sdb_store_matcher_t *
580 sdb_store_istrue_matcher(sdb_store_expr_t *expr);
581 sdb_store_matcher_t *
582 sdb_store_isfalse_matcher(sdb_store_expr_t *expr);
584 /*
585  * sdb_store_matcher_matches:
586  * Check whether the specified matcher matches the specified store object. If
587  * specified, the filter will be used to preselect objects for further
588  * evaluation. It is applied to any object that's used during the evaluation
589  * of the matcher. Only those objects matching the filter will be considered.
590  *
591  * Note that the filter is applied to all object types (hosts, service,
592  * metric, attribute). Thus, any object-specific matchers are mostly unsuited
593  * for this purpose and, if used, may result in unexpected behavior.
594  *
595  * Returns:
596  *  - 1 if the object matches
597  *  - 0 else
598  */
599 int
600 sdb_store_matcher_matches(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
601                 sdb_store_matcher_t *filter);
603 /*
604  * sdb_store_matcher_op_cb:
605  * Callback constructing a matcher operator.
606  */
607 typedef sdb_store_matcher_t *(*sdb_store_matcher_op_cb)
608         (sdb_store_expr_t *, sdb_store_expr_t *);
610 /*
611  * sdb_store_lookup_cb:
612  * Lookup callback. It is called for each matching object when looking up data
613  * in the store passing on the lookup filter and the specified user-data. The
614  * lookup aborts early if the callback returns non-zero.
615  */
616 typedef int (*sdb_store_lookup_cb)(sdb_store_obj_t *obj,
617                 sdb_store_matcher_t *filter, void *user_data);
619 /*
620  * sdb_store_scan:
621  * Look up objects of the specified type in the store. The specified callback
622  * function is called for each object in the store matching 'm'. The function
623  * performs a full scan of all objects stored in the database. If specified,
624  * the filter will be used to preselect objects for further evaluation. See
625  * the description of 'sdb_store_matcher_matches' for details.
626  *
627  * Returns:
628  *  - 0 on success
629  *  - a negative value else
630  */
631 int
632 sdb_store_scan(int type, sdb_store_matcher_t *m, sdb_store_matcher_t *filter,
633                 sdb_store_lookup_cb cb, void *user_data);
635 /*
636  * Flags for JSON formatting.
637  */
638 enum {
639         SDB_WANT_ARRAY = 1 << 0,
640 };
642 /*
643  * sdb_store_json_formatter:
644  * Create a JSON formatter for the specified object types writing to the
645  * specified buffer.
646  */
647 sdb_store_json_formatter_t *
648 sdb_store_json_formatter(sdb_strbuf_t *buf, int type, int flags);
650 /*
651  * sdb_store_json_emit:
652  * Serialize a single object to JSON adding it to the string buffer associated
653  * with the formatter object. The serialized object will not include
654  * attributes or any child objects. Instead, call the function again for each
655  * of those objects. All attributes have to be emitted before any other
656  * children types. Use sdb_store_json_emit_full() to emit a full (filtered)
657  * object.
658  *
659  * Note that the output might not be valid JSON before calling
660  * sdb_store_json_finish().
661  *
662  * Returns:
663  *  - 0 on success
664  *  - a negative value else
665  */
666 int
667 sdb_store_json_emit(sdb_store_json_formatter_t *f, sdb_store_obj_t *obj);
669 /*
670  * sdb_store_json_emit_full:
671  * Serialize a single object including it's attributes and all children to
672  * JSON, adding it to the string buffer associated with the formatter object.
673  * The filter, if specified, is applied to each attribute and child object.
674  * Only matching objects will be included in the output.
675  *
676  * Note that the output might not be valid JSON before calling
677  * sdb_store_json_finish().
678  *
679  * Returns:
680  *  - 0 on success
681  *  - a negative value else
682  */
683 int
684 sdb_store_json_emit_full(sdb_store_json_formatter_t *f, sdb_store_obj_t *obj,
685                 sdb_store_matcher_t *filter);
687 /*
688  * sdb_store_json_finish:
689  * Finish the JSON output. This function has to be called once after emiting
690  * all objects.
691  */
692 int
693 sdb_store_json_finish(sdb_store_json_formatter_t *f);
695 #ifdef __cplusplus
696 } /* extern "C" */
697 #endif
699 #endif /* ! SDB_CORE_STORE_H */
701 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */