Code

store: Introduced sdb_store_host_tojson() to serialize a single host.
[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_base_t represents the super-class of any object stored in the
45  * database. It inherits from sdb_object_t and may safely be cast to a generic
46  * object to access its name.
47  */
48 struct sdb_store_base;
49 typedef struct sdb_store_base sdb_store_base_t;
51 /*
52  * sdb_store_host:
53  * Add/update a host in the store. If the host, identified by its
54  * canonicalized name, already exists, it will be updated according to the
55  * specified name and timestamp. Else, a new entry will be created in the
56  * store. Any memory required for storing the entry will be allocated an
57  * managed by the store itself.
58  *
59  * Returns:
60  *  - 0 on success
61  *  - a positive value if the new entry is older than the currently stored
62  *    entry (in this case, no update will happen)
63  *  - a negative value on error
64  */
65 int
66 sdb_store_host(const char *name, sdb_time_t last_update);
68 _Bool
69 sdb_store_has_host(const char *name);
71 /*
72  * sdb_store_attribute:
73  * Add/update a host's attribute in the store. If the attribute, identified by
74  * its key, already exists for the specified host, it will be updated to the
75  * specified values. If the referenced host does not exist, an error will be
76  * reported. Else, a new entry will be created in the store. Any memory
77  * required for storing the entry will be allocated and managed by the store
78  * itself.
79  *
80  * Returns:
81  *  - 0 on success
82  *  - a positive value if the new entry is older than the currently stored
83  *    entry (in this case, no update will happen)
84  *  - a negative value on error
85  */
86 int
87 sdb_store_attribute(const char *hostname, const char *key, const char *value,
88                 sdb_time_t last_update);
90 /*
91  * sdb_store_service:
92  * Add/update a store in the store. If the service, identified by its name,
93  * already exists for the specified host, it will be updated according to the
94  * specified 'service' object. If the referenced host does not exist, an error
95  * will be reported. Else, a new entry will be created in the store. Any
96  * memory required for storing the entry will be allocated an managed by the
97  * store itself. The specified service-object will not be referenced or
98  * further accessed.
99  *
100  * Returns:
101  *  - 0 on success
102  *  - a positive value if the new entry is older than the currently stored
103  *    entry (in this case, no update will happen)
104  *  - a negative value on error
105  */
106 int
107 sdb_store_service(const char *hostname, const char *name,
108                 sdb_time_t last_update);
110 /*
111  * sdb_store_tojson:
112  * Serialize the entire store to JSON and append the result to the specified
113  * buffer.
114  *
115  * Returns:
116  *  - 0 on success
117  *  - a negative value on error
118  */
119 int
120 sdb_store_tojson(sdb_strbuf_t *buf);
122 /*
123  * sdb_store_host_tojson:
124  * Serialize a host object to JSON and append the result to the specified
125  * buffer.
126  *
127  * Returns:
128  *  - 0 on success
129  *  - a negative value on error
130  */
131 int
132 sdb_store_host_tojson(sdb_store_base_t *host, sdb_strbuf_t *buf);
134 #ifdef __cplusplus
135 } /* extern "C" */
136 #endif
138 #endif /* ! SDB_CORE_STORE_H */
140 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */