Code

store: Let tojson() embed errors into JSON rather than aborting.
[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/time.h"
34 #include "utils/llist.h"
35 #include "utils/strbuf.h"
37 #include <stdio.h>
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
43 /*
44  * sdb_store_host:
45  * Add/update a host in the store. If the host, identified by its
46  * canonicalized name, already exists, it will be updated according to the
47  * specified name and timestamp. Else, a new entry will be created in the
48  * store. Any memory required for storing the entry will be allocated an
49  * managed by the store itself.
50  *
51  * Returns:
52  *  - 0 on success
53  *  - a positive value if the new entry is older than the currently stored
54  *    entry (in this case, no update will happen)
55  *  - a negative value on error
56  */
57 int
58 sdb_store_host(const char *name, sdb_time_t last_update);
60 _Bool
61 sdb_store_has_host(const char *name);
63 /*
64  * sdb_store_attribute:
65  * Add/update a host's attribute in the store. If the attribute, identified by
66  * its key, already exists for the specified host, it will be updated to the
67  * specified values. If the referenced host does not exist, an error will be
68  * reported. Else, a new entry will be created in the store. Any memory
69  * required for storing the entry will be allocated and managed by the store
70  * itself.
71  *
72  * Returns:
73  *  - 0 on success
74  *  - a positive value if the new entry is older than the currently stored
75  *    entry (in this case, no update will happen)
76  *  - a negative value on error
77  */
78 int
79 sdb_store_attribute(const char *hostname, const char *key, const char *value,
80                 sdb_time_t last_update);
82 /*
83  * sdb_store_service:
84  * Add/update a store in the store. If the service, identified by its name,
85  * already exists for the specified host, it will be updated according to the
86  * specified 'service' object. If the referenced host does not exist, an error
87  * will be reported. Else, a new entry will be created in the store. Any
88  * memory required for storing the entry will be allocated an managed by the
89  * store itself. The specified service-object will not be referenced or
90  * further accessed.
91  *
92  * Returns:
93  *  - 0 on success
94  *  - a positive value if the new entry is older than the currently stored
95  *    entry (in this case, no update will happen)
96  *  - a negative value on error
97  */
98 int
99 sdb_store_service(const char *hostname, const char *name,
100                 sdb_time_t last_update);
102 /*
103  * sdb_store_tojson:
104  * Serialize the entire store to JSON and append the result to the specified
105  * buffer.
106  *
107  * Returns:
108  *  - 0 on success
109  *  - a negative value on error
110  */
111 int
112 sdb_store_tojson(sdb_strbuf_t *buf);
114 #ifdef __cplusplus
115 } /* extern "C" */
116 #endif
118 #endif /* ! SDB_CORE_STORE_H */
120 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */