Code

289bc2f88684ef6a82be2d63935d1b5bcb85d22a
[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  * A JSON formatter object inherits from sdb_object_t and, thus, may safely be
149  * cast to a generic object.
150  */
151 struct sdb_store_json_formatter;
152 typedef struct sdb_store_json_formatter sdb_store_json_formatter_t;
154 /*
155  * A store writer describes the interface for plugins implementing a store.
156  *
157  * Any of the call-back functions shall return:
158  *  - 0 on success
159  *  - a positive value if the new entry is older than the currently stored
160  *    entry (in this case, no update will happen)
161  *  - a negative value on error
162  */
163 typedef struct {
164         /*
165          * store_host:
166          * Add/update a host in the store. If the host, identified by its
167          * canonicalized name, already exists, it will be updated according to the
168          * specified name and timestamp. Else, a new entry will be created in the
169          * store.
170          */
171         int (*store_host)(const char *name, sdb_time_t last_update,
172                         sdb_object_t *user_data);
174         /*
175          * store_service:
176          * Add/update a service in the store. If the service, identified by its
177          * name, already exists for the specified host, it will be updated
178          * according to the specified name and timestamp. If the referenced host
179          * does not exist, an error will be reported. Else, a new entry will be
180          * created in the store.
181          */
182         int (*store_service)(const char *hostname, const char *name,
183                         sdb_time_t last_update, sdb_object_t *user_data);
185         /*
186          * store_metric:
187          * Add/update a metric in the store. If the metric, identified by its
188          * name, already exists for the specified host, it will be updated
189          * according to the specified attributes. If the referenced host does not
190          * exist, an error will be reported. Else, a new entry will be created in
191          * the store.
192          */
193         int (*store_metric)(const char *hostname, const char *name,
194                         sdb_metric_store_t *store, sdb_time_t last_update,
195                         sdb_object_t *user_data);
197         /*
198          * store_attribute:
199          * Add/update a host's attribute in the store. If the attribute,
200          * identified by its key, already exists for the specified host, it will
201          * be updated to the specified values. If the referenced host does not
202          * exist, an error will be reported. Else, a new entry will be created in
203          * the store.
204          */
205         int (*store_attribute)(const char *hostname,
206                         const char *key, const sdb_data_t *value, sdb_time_t last_update,
207                         sdb_object_t *user_data);
209         /*
210          * store_service_attr:
211          * Add/update a service's attribute in the store. If the attribute,
212          * identified by its key, already exists for the specified service, it
213          * will be updated to the specified value. If the references service (for
214          * the specified host) does not exist, an error will be reported.
215          */
216         int (*store_service_attr)(const char *hostname, const char *service,
217                         const char *key, const sdb_data_t *value, sdb_time_t last_update,
218                         sdb_object_t *user_data);
220         /*
221          * store_metric_attr:
222          * Add/update a metric's attribute in the store. If the attribute,
223          * identified by its key, already exists for the specified metric, it will
224          * be updated to the specified value. If the references metric (for the
225          * specified host) does not exist, an error will be reported.
226          */
227         int (*store_metric_attr)(const char *hostname, const char *metric,
228                         const char *key, const sdb_data_t *value, sdb_time_t last_update,
229                         sdb_object_t *user_data);
230 } sdb_store_writer_t;
232 /*
233  * sdb_store_init:
234  * Initialize the store sub-system. This function has to be called before
235  * doing any other store operations.
236  *
237  * Returns:
238  *  - 0 on success
239  *  - a negative value else
240  */
241 int
242 sdb_store_init(void);
244 /*
245  * sdb_store_clear:
246  * Clear the entire store and remove all stored objects.
247  */
248 void
249 sdb_store_clear(void);
251 /*
252  * sdb_store_get_host:
253  * Query the store for a host by its (canonicalized) name.
254  *
255  * The function increments the ref count of the host object. The caller needs
256  * to deref it when no longer using it.
257  */
258 sdb_store_obj_t *
259 sdb_store_get_host(const char *name);
261 /*
262  * sdb_store_fetch_timeseries:
263  * Fetch the time-series described by the specified host's metric and
264  * serialize it as JSON into the provided string buffer.
265  *
266  * Returns:
267  *  - 0 on success
268  *  - a negative value else
269  */
270 int
271 sdb_store_fetch_timeseries(const char *hostname, const char *metric,
272                 sdb_timeseries_opts_t *opts, sdb_strbuf_t *buf);
274 /*
275  * sdb_store_get_child:
276  * Retrieve a host's child object of the specified type and name. The
277  * reference count of the child object will be incremented before returning
278  * it. The caller is responsible for releasing the object once it's no longer
279  * used.
280  *
281  * Returns:
282  *  - the child object on success
283  *  - NULL else
284  */
285 sdb_store_obj_t *
286 sdb_store_get_child(sdb_store_obj_t *host, int type, const char *name);
288 /*
289  * sdb_store_get_field:
290  * Get the value of a stored object's queryable field. The caller is
291  * responsible for freeing any dynamically allocated memory possibly stored in
292  * the returned value. If 'res' is NULL, the function will return whether the
293  * field exists.
294  *
295  * Returns:
296  *  - 0 on success
297  *  - a negative value else
298  */
299 int
300 sdb_store_get_field(sdb_store_obj_t *obj, int field, sdb_data_t *res);
302 /*
303  * sdb_store_get_attr:
304  * Get the value of a stored object's attribute. The caller is responsible for
305  * freeing any dynamically allocated memory possibly stored in the returned
306  * value. If 'res' is NULL, the function will return whether the attribute
307  * exists. If specified, only attributes matching the filter will be
308  * considered.
309  *
310  * Returns:
311  *  - 0 if the attribute exists
312  *  - a negative value else
313  */
314 int
315 sdb_store_get_attr(sdb_store_obj_t *obj, const char *name, sdb_data_t *res,
316                 sdb_store_matcher_t *filter);
318 /*
319  * Querying a store:
320  *
321  *  - Query interface: A query is a formal description of an interaction with
322  *    the store. It can be used, both, for read and write access. The query is
323  *    described by its abstract syntax tree (AST). The parser package provides
324  *    means to parse a string (SysQL) representation of the query into an AST.
325  *
326  *  - Matcher / expression interface: This low-level interface provides direct
327  *    control over how to access the store. It is used by the query
328  *    implementation internally and can only be used for read access.
329  */
331 /*
332  * sdb_store_query_t:
333  * A parsed query readily prepared for execution.
334  */
335 struct sdb_store_query;
336 typedef struct sdb_store_query sdb_store_query_t;
338 /*
339  * sdb_store_query_prepare:
340  * Prepare the query described by 'ast' for execution in a store.
341  *
342  * Returns:
343  *  - a store query on success
344  *  - NULL else
345  */
346 sdb_store_query_t *
347 sdb_store_query_prepare(sdb_ast_node_t *ast);
349 /*
350  * sdb_store_query_prepare_matcher:
351  * Prepare the logical expression described by 'ast' for execution as a store
352  * matcher.
353  *
354  * Returns:
355  *  - a matcher on success
356  *  - NULL else
357  */
358 sdb_store_matcher_t *
359 sdb_store_query_prepare_matcher(sdb_ast_node_t *ast);
361 /*
362  * sdb_store_query_execute:
363  * Execute a previously prepared query. The query result will be written to
364  * 'buf' and any errors to 'errbuf'.
365  *
366  * Returns:
367  *  - the result type (to be used by the server reply)
368  *  - a negative value on error
369  */
370 int
371 sdb_store_query_execute(sdb_store_query_t *m,
372                 sdb_strbuf_t *buf, sdb_strbuf_t *errbuf);
374 /*
375  * sdb_store_expr_create:
376  * Creates an arithmetic expression implementing the specified operator on the
377  * specified left and right operand.
378  *
379  * Returns:
380  *  - an expression object on success
381  *  - NULL else
382  */
383 sdb_store_expr_t *
384 sdb_store_expr_create(int op, sdb_store_expr_t *left, sdb_store_expr_t *right);
386 /*
387  * sdb_store_expr_typed:
388  * Creates an expression which evaluates in the context of an object's sibling
389  * as specified by the given type.
390  *
391  * Returns:
392  *  - an expression object on success
393  *  - NULL else
394  */
395 sdb_store_expr_t *
396 sdb_store_expr_typed(int typ, sdb_store_expr_t *expr);
398 /*
399  * sdb_store_expr_fieldvalue:
400  * Creates an expression which evaluates to the value of the specified
401  * queryable field of a stored object.
402  *
403  * Returns:
404  *  - an expression object on success
405  *  - NULL else
406  */
407 sdb_store_expr_t *
408 sdb_store_expr_fieldvalue(int field);
410 /*
411  * sdb_store_expr_attrvalue:
412  * Creates an expression which evaluates to the value of the specified
413  * attribute of a stored object. Evaluates to a NULL value if the attribute
414  * does not exist.
415  *
416  * Returns:
417  *  - an expression object on success
418  *  - NULL else
419  */
420 sdb_store_expr_t *
421 sdb_store_expr_attrvalue(const char *name);
423 /*
424  * sdb_store_expr_constvalue:
425  * Creates an expression which evaluates to the specified constant value.
426  *
427  * Returns:
428  *  - an expression object on success
429  *  - NULL else
430  */
431 sdb_store_expr_t *
432 sdb_store_expr_constvalue(const sdb_data_t *value);
434 /*
435  * sdb_store_expr_eval:
436  * Evaluate an expression for the specified stored object and stores the
437  * result in 'res'. The result's value will be allocated dynamically if
438  * necessary and, thus, should be free'd by the caller (e.g. using
439  * sdb_data_free_datum). The object may be NULL, in which case the expression
440  * needs to evaluate to a constant value. If specified, only objects matching
441  * the filter will be used during the evaluation.
442  *
443  * Returns:
444  *  - 0 on success
445  *  - a negative value else
446  */
447 int
448 sdb_store_expr_eval(sdb_store_expr_t *expr, sdb_store_obj_t *obj,
449                 sdb_data_t *res, sdb_store_matcher_t *filter);
451 /*
452  * sdb_store_expr_iterable:
453  * Check whether an expression, evaluated in the specified context (HOST,
454  * SERVICE, METRIC) is iterable, that is, if it may evaluate to multiple
455  * values.
456  */
457 bool
458 sdb_store_expr_iterable(sdb_store_expr_t *expr, int context);
460 /*
461  * sdb_store_expr_iter:
462  * Iterate over the elements of an iterable expression. sdb_store_expr_iter
463  * returns NULL if the expression is not iterable (for the specified object).
464  * See also sdb_store_expr_iterable.
465  *
466  * sdb_store_expr_iter_get_next returns NULL if there is no next element.
467  */
468 sdb_store_expr_iter_t *
469 sdb_store_expr_iter(sdb_store_expr_t *expr, sdb_store_obj_t *obj,
470                 sdb_store_matcher_t *filter);
471 void
472 sdb_store_expr_iter_destroy(sdb_store_expr_iter_t *iter);
474 bool
475 sdb_store_expr_iter_has_next(sdb_store_expr_iter_t *iter);
476 sdb_data_t
477 sdb_store_expr_iter_get_next(sdb_store_expr_iter_t *iter);
479 /*
480  * sdb_store_dis_matcher:
481  * Creates a matcher matching the disjunction (logical OR) of two matchers.
482  */
483 sdb_store_matcher_t *
484 sdb_store_dis_matcher(sdb_store_matcher_t *left, sdb_store_matcher_t *right);
486 /*
487  * sdb_store_con_matcher:
488  * Creates a matcher matching the conjunction (logical AND) of two matchers.
489  */
490 sdb_store_matcher_t *
491 sdb_store_con_matcher(sdb_store_matcher_t *left, sdb_store_matcher_t *right);
493 /*
494  * sdb_store_inv_matcher::
495  * Creates a matcher matching the inverse (logical NOT) of a matcher.
496  */
497 sdb_store_matcher_t *
498 sdb_store_inv_matcher(sdb_store_matcher_t *m);
500 /*
501  * sdb_store_any_matcher:
502  * Creates a matcher iterating over values of the first expression (which has
503  * to be iterable). It matches if *any* of those elements match 'm'. 'm' has
504  * to be an ary operation with the left operand unset.
505  */
506 sdb_store_matcher_t *
507 sdb_store_any_matcher(sdb_store_expr_t *iter, sdb_store_matcher_t *m);
509 /*
510  * sdb_store_all_matcher:
511  * Creates a matcher iterating over values of the first expression (which has
512  * to be iterable). It matches if *all* of those elements match 'm'. 'm' has
513  * to be an ary operation with the left operand unset.
514  */
515 sdb_store_matcher_t *
516 sdb_store_all_matcher(sdb_store_expr_t *iter, sdb_store_matcher_t *m);
518 /*
519  * sdb_store_in_matcher:
520  * Creates a matcher which matches if the right value evaluates to an array
521  * value and the left value is included in that array. See sdb_data_inarray
522  * for more details.
523  */
524 sdb_store_matcher_t *
525 sdb_store_in_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
527 /*
528  * sdb_store_lt_matcher, sdb_store_le_matcher, sdb_store_eq_matcher,
529  * sdb_store_ge_matcher, sdb_store_gt_matcher:
530  * Create conditional matchers comparing the values of two expressions. The
531  * matcher matches if the left expression compres less than, less or equal
532  * than, equal to, not equal to, greater or equal than, or greater than the
533  * right expression.
534  */
535 sdb_store_matcher_t *
536 sdb_store_lt_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
537 sdb_store_matcher_t *
538 sdb_store_le_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
539 sdb_store_matcher_t *
540 sdb_store_eq_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
541 sdb_store_matcher_t *
542 sdb_store_ne_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
543 sdb_store_matcher_t *
544 sdb_store_ge_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
545 sdb_store_matcher_t *
546 sdb_store_gt_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
548 /*
549  * sdb_store_regex_matcher:
550  * Creates a matcher which matches the string value the left expression
551  * evaluates to against the regular expression the right expression evaluates
552  * to. The right expression may either be a constant value regular expression
553  * or string or a dynamic value evaluating to a string. In the latter case,
554  * the string is compiled to a regex every time the matcher is executed.
555  */
556 sdb_store_matcher_t *
557 sdb_store_regex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
559 /*
560  * sdb_store_nregex_matcher:
561  * Creates a regex matcher just like sdb_store_regex_matcher except that it
562  * matches in case the regular expression does not match.
563  */
564 sdb_store_matcher_t *
565 sdb_store_nregex_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right);
567 /*
568  * sdb_store_isnull_matcher:
569  * Creates a matcher matching NULL values.
570  */
571 sdb_store_matcher_t *
572 sdb_store_isnull_matcher(sdb_store_expr_t *expr);
574 /*
575  * sdb_store_istrue_matcher, sdb_store_isfalse_matcher:
576  * Creates a matcher matching boolean values.
577  */
578 sdb_store_matcher_t *
579 sdb_store_istrue_matcher(sdb_store_expr_t *expr);
580 sdb_store_matcher_t *
581 sdb_store_isfalse_matcher(sdb_store_expr_t *expr);
583 /*
584  * sdb_store_matcher_matches:
585  * Check whether the specified matcher matches the specified store object. If
586  * specified, the filter will be used to preselect objects for further
587  * evaluation. It is applied to any object that's used during the evaluation
588  * of the matcher. Only those objects matching the filter will be considered.
589  *
590  * Note that the filter is applied to all object types (hosts, service,
591  * metric, attribute). Thus, any object-specific matchers are mostly unsuited
592  * for this purpose and, if used, may result in unexpected behavior.
593  *
594  * Returns:
595  *  - 1 if the object matches
596  *  - 0 else
597  */
598 int
599 sdb_store_matcher_matches(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
600                 sdb_store_matcher_t *filter);
602 /*
603  * sdb_store_matcher_op_cb:
604  * Callback constructing a matcher operator.
605  */
606 typedef sdb_store_matcher_t *(*sdb_store_matcher_op_cb)
607         (sdb_store_expr_t *, sdb_store_expr_t *);
609 /*
610  * sdb_store_lookup_cb:
611  * Lookup callback. It is called for each matching object when looking up data
612  * in the store passing on the lookup filter and the specified user-data. The
613  * lookup aborts early if the callback returns non-zero.
614  */
615 typedef int (*sdb_store_lookup_cb)(sdb_store_obj_t *obj,
616                 sdb_store_matcher_t *filter, void *user_data);
618 /*
619  * sdb_store_scan:
620  * Look up objects of the specified type in the store. The specified callback
621  * function is called for each object in the store matching 'm'. The function
622  * performs a full scan of all objects stored in the database. If specified,
623  * the filter will be used to preselect objects for further evaluation. See
624  * the description of 'sdb_store_matcher_matches' for details.
625  *
626  * Returns:
627  *  - 0 on success
628  *  - a negative value else
629  */
630 int
631 sdb_store_scan(int type, sdb_store_matcher_t *m, sdb_store_matcher_t *filter,
632                 sdb_store_lookup_cb cb, void *user_data);
634 /*
635  * Flags for JSON formatting.
636  */
637 enum {
638         SDB_WANT_ARRAY = 1 << 0,
639 };
641 /*
642  * sdb_store_json_formatter:
643  * Create a JSON formatter for the specified object types writing to the
644  * specified buffer.
645  */
646 sdb_store_json_formatter_t *
647 sdb_store_json_formatter(sdb_strbuf_t *buf, int type, int flags);
649 /*
650  * sdb_store_json_emit:
651  * Serialize a single object to JSON adding it to the string buffer associated
652  * with the formatter object. The serialized object will not include
653  * attributes or any child objects. Instead, call the function again for each
654  * of those objects. All attributes have to be emitted before any other
655  * children types. Use sdb_store_json_emit_full() to emit a full (filtered)
656  * object.
657  *
658  * Note that the output might not be valid JSON before calling
659  * sdb_store_json_finish().
660  *
661  * Returns:
662  *  - 0 on success
663  *  - a negative value else
664  */
665 int
666 sdb_store_json_emit(sdb_store_json_formatter_t *f, sdb_store_obj_t *obj);
668 /*
669  * sdb_store_json_emit_full:
670  * Serialize a single object including it's attributes and all children to
671  * JSON, adding it to the string buffer associated with the formatter object.
672  * The filter, if specified, is applied to each attribute and child object.
673  * Only matching objects will be included in the output.
674  *
675  * Note that the output might not be valid JSON before calling
676  * sdb_store_json_finish().
677  *
678  * Returns:
679  *  - 0 on success
680  *  - a negative value else
681  */
682 int
683 sdb_store_json_emit_full(sdb_store_json_formatter_t *f, sdb_store_obj_t *obj,
684                 sdb_store_matcher_t *filter);
686 /*
687  * sdb_store_json_finish:
688  * Finish the JSON output. This function has to be called once after emiting
689  * all objects.
690  */
691 int
692 sdb_store_json_finish(sdb_store_json_formatter_t *f);
694 #ifdef __cplusplus
695 } /* extern "C" */
696 #endif
698 #endif /* ! SDB_CORE_STORE_H */
700 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */