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"
36 #include <stdio.h>
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
42 /*
43 * sdb_store_host:
44 * Add/update a host in the store. If the host, identified by its
45 * canonicalized name, already exists, it will be updated according to the
46 * specified name and timestamp. Else, a new entry will be created in the
47 * store. Any memory required for storing the entry will be allocated an
48 * managed by the store itself.
49 *
50 * Returns:
51 * - 0 on success
52 * - a positive value if the new entry is older than the currently stored
53 * entry (in this case, no update will happen)
54 * - a negative value on error
55 */
56 int
57 sdb_store_host(const char *name, sdb_time_t last_update);
59 _Bool
60 sdb_store_has_host(const char *name);
62 /*
63 * sdb_store_attribute:
64 * Add/update a host's attribute in the store. If the attribute, identified by
65 * its key, already exists for the specified host, it will be updated to the
66 * specified values. If the referenced host does not exist, an error will be
67 * reported. Else, a new entry will be created in the store. Any memory
68 * required for storing the entry will be allocated and managed by the store
69 * itself.
70 *
71 * Returns:
72 * - 0 on success
73 * - a positive value if the new entry is older than the currently stored
74 * entry (in this case, no update will happen)
75 * - a negative value on error
76 */
77 int
78 sdb_store_attribute(const char *hostname, const char *key, const char *value,
79 sdb_time_t last_update);
81 /*
82 * sdb_store_service:
83 * Add/update a store in the store. If the service, identified by its name,
84 * already exists for the specified host, it will be updated according to the
85 * specified 'service' object. If the referenced host does not exist, an error
86 * will be reported. Else, a new entry will be created in the store. Any
87 * memory required for storing the entry will be allocated an managed by the
88 * store itself. The specified service-object will not be referenced or
89 * further accessed.
90 *
91 * Returns:
92 * - 0 on success
93 * - a positive value if the new entry is older than the currently stored
94 * entry (in this case, no update will happen)
95 * - a negative value on error
96 */
97 int
98 sdb_store_service(const char *hostname, const char *name,
99 sdb_time_t last_update);
101 int
102 sdb_store_dump(FILE *fh);
104 #ifdef __cplusplus
105 } /* extern "C" */
106 #endif
108 #endif /* ! SDB_CORE_STORE_H */
110 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */