Debian Codegraph @

lib/config.c

raw symbols SCIP
1 /*
2 Copyright (C) 2015-2016 Brazil
3 Copyright (C) 2021-2022 Sutou Kouhei <[email protected]>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "grn_ctx_impl.h"cxx . . $ `<file>/lib/grn_ctx_impl.h`/
21 #include "grn_config.h"cxx . . $ `<file>/lib/grn_config.h`/
22
23 #include <string.h>
24
25 grn_rccxx . . $ grn_rc#
26 grn_config_setcxx . . $ grn_config_set(2afa6b044548fd83).(grn_ctxcxx . . $ grn_ctx# *ctx,
27 const char *key, int32_tcxx . . $ int32_t# key_size,
28 const char *value, int32_tcxx . . $ int32_t# value_size)
29 {
30 grn_objcxx . . $ grn_obj# *db;
31 grn_hashcxx . . $ grn_hash# *config;
32 grn_idcxx . . $ grn_id# id;
33
34 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
35
36 if (!ctx || !ctx->implcxx . . $ _grn_ctx#impl. || !(db = ctx->implcxx . . $ _grn_ctx#impl.->dbcxx . . $ _grn_ctx_impl#db.)) {
37 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[config][set] DB isn't initialized");
38 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
39 }
40
41 uint32_tcxx . . $ uint32_t# real_key_size;
42 if (key_size < 0) {
43 real_key_size = (uint32_tcxx . . $ uint32_t#)strlencxx . . $ strlen(751346f8406fd082).(key);
44 } else {
45 real_key_size = (uint32_tcxx . . $ uint32_t#)key_size;
46 }
47 if (real_key_size > GRN_CONFIG_MAX_KEY_SIZEcxx . . $ `include/groonga/config.h:25:9`!) {
48 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
49 "[config][set] too large key: max=<%u>: <%u>",
50 GRN_CONFIG_MAX_KEY_SIZEcxx . . $ `include/groonga/config.h:25:9`!, real_key_size);
51 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
52 }
53
54 uint32_tcxx . . $ uint32_t# real_value_size;
55 if (value_size < 0) {
56 real_value_size = (uint32_tcxx . . $ uint32_t#)strlencxx . . $ strlen(751346f8406fd082).(value);
57 } else {
58 real_value_size = (uint32_tcxx . . $ uint32_t#)value_size;
59 }
60 if (real_value_size > GRN_CONFIG_MAX_VALUE_SIZEcxx . . $ `include/groonga/config.h:26:9`!) {
61 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
62 "[config][set] too large value: max=<%" GRN_FMT_SIZEcxx . . $ `lib/grn.h:408:11`! ">: <%u>",
63 GRN_CONFIG_MAX_VALUE_SIZEcxx . . $ `include/groonga/config.h:26:9`!, real_value_size);
64 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
65 }
66
67 config = ((grn_dbcxx . . $ grn_db# *)db)->configcxx . . $ _grn_db#config.;
68 {
69 grn_rccxx . . $ grn_rc# rc;
70 rc = grn_io_lockcxx . . $ grn_io_lock(2c16bfdb6acf067b).(ctx, config->iocxx . . $ _grn_hash#io., grn_lock_timeoutcxx . . $ grn_lock_timeout.);
71 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
72 if (ctx->rccxx . . $ _grn_ctx#rc. == GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
73 ERRcxx . . $ `lib/grn_error.h:156:9`!(rc, "[config][set] failed to lock");
74 }
75 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(rc);
76 }
77 id = grn_hash_addcxx . . $ grn_hash_add(251a256fc515235e).(ctx, config, key, real_key_size, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
78 if (id != GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!) {
79 grn_objcxx . . $ grn_obj# packed_value;
80 GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&packed_value, 0);
81 grn_bulk_reservecxx . . $ grn_bulk_reserve(f9a66385f261f61d).(ctx, &packed_value, GRN_CONFIG_MAX_VALUE_SIZEcxx . . $ `include/groonga/config.h:26:9`!);
82 GRN_UINT32_PUTcxx . . $ `include/groonga/groonga.h:3182:9`!(ctx, &packed_value, real_value_size);
83 GRN_TEXT_PUTcxx . . $ `include/groonga/groonga.h:2773:9`!(ctx, &packed_value, value, real_value_size);
84 GRN_TEXT_PUTCcxx . . $ `include/groonga/groonga.h:2775:9`!(ctx, &packed_value, '\0');
85 grn_hash_set_valuecxx . . $ grn_hash_set_value(1fef6aa35b4cc9a).(ctx,
86 config,
87 id,
88 GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(&packed_value),
89 GRN_OBJ_SETcxx . . $ `include/groonga/groonga.h:1466:9`!);
90 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &packed_value);
91 }
92 grn_io_unlockcxx . . $ grn_io_unlock(341fd28fcb683921).(ctx, config->iocxx . . $ _grn_hash#io.);
93 }
94 if (id == GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`! || ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
95 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
96 "[config][set] failed to set: name=<%.*s>: <%u>",
97 (int)real_key_size, key, real_value_size);
98 }
99
100 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
101 }
102
103 grn_rccxx . . $ grn_rc#
104 grn_config_getcxx . . $ grn_config_get(55f0c7275dd3feda).(grn_ctxcxx . . $ grn_ctx# *ctx,
105 const char *key, int32_tcxx . . $ int32_t# key_size,
106 const char **value, uint32_tcxx . . $ uint32_t# *value_size)
107 {
108 grn_objcxx . . $ grn_obj# *db;
109 grn_hashcxx . . $ grn_hash# *config;
110 grn_idcxx . . $ grn_id# id;
111 void *packed_value;
112
113 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
114
115 if (!ctx || !ctx->implcxx . . $ _grn_ctx#impl. || !(db = ctx->implcxx . . $ _grn_ctx#impl.->dbcxx . . $ _grn_ctx_impl#db.)) {
116 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[config][get] DB isn't initialized");
117 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
118 }
119
120 uint32_tcxx . . $ uint32_t# real_key_size;
121 if (key_size < 0) {
122 real_key_size = (uint32_tcxx . . $ uint32_t#)strlencxx . . $ strlen(751346f8406fd082).(key);
123 } else {
124 real_key_size = (uint32_tcxx . . $ uint32_t#)key_size;
125 }
126 if (real_key_size > GRN_CONFIG_MAX_KEY_SIZEcxx . . $ `include/groonga/config.h:25:9`!) {
127 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
128 "[config][get] too large key: max=<%u>: <%u>",
129 GRN_CONFIG_MAX_KEY_SIZEcxx . . $ `include/groonga/config.h:25:9`!, real_key_size);
130 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
131 }
132
133 config = ((grn_dbcxx . . $ grn_db# *)db)->configcxx . . $ _grn_db#config.;
134 id = grn_hash_getcxx . . $ grn_hash_get(4e868e5367e71b67).(ctx, config, key, real_key_size, &packed_value);
135 if (id == GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!) {
136 *value = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
137 *value_size = 0;
138 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(GRN_SUCCESS);
139 }
140
141 *value = (char *)packed_value + sizeof(uint32_tcxx . . $ uint32_t#);
142 *value_size = *((uint32_tcxx . . $ uint32_t# *)packed_value);
143 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(GRN_SUCCESS);
144 }
145
146 grn_rccxx . . $ grn_rc#
147 grn_config_deletecxx . . $ grn_config_delete(7bd03b5ef0400a0e).(grn_ctxcxx . . $ grn_ctx# *ctx,
148 const char *key, int key_size)
149 {
150 grn_objcxx . . $ grn_obj# *db;
151 grn_hashcxx . . $ grn_hash# *config;
152
153 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
154
155 if (!ctx || !ctx->implcxx . . $ _grn_ctx#impl. || !(db = ctx->implcxx . . $ _grn_ctx#impl.->dbcxx . . $ _grn_ctx_impl#db.)) {
156 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[config][delete] DB isn't initialized");
157 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
158 }
159
160 uint32_tcxx . . $ uint32_t# real_key_size;
161 if (key_size < 0) {
162 real_key_size = (uint32_tcxx . . $ uint32_t#)strlencxx . . $ strlen(751346f8406fd082).(key);
163 } else {
164 real_key_size = (uint32_tcxx . . $ uint32_t#)key_size;
165 }
166 if (real_key_size > GRN_CONFIG_MAX_KEY_SIZEcxx . . $ `include/groonga/config.h:25:9`!) {
167 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT,
168 "[config][delete] too large key: max=<%u>: <%u>",
169 GRN_CONFIG_MAX_KEY_SIZEcxx . . $ `include/groonga/config.h:25:9`!, real_key_size);
170 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
171 }
172
173 config = ((grn_dbcxx . . $ grn_db# *)db)->configcxx . . $ _grn_db#config.;
174 {
175 grn_rccxx . . $ grn_rc# rc;
176 rc = grn_io_lockcxx . . $ grn_io_lock(2c16bfdb6acf067b).(ctx, config->iocxx . . $ _grn_hash#io., grn_lock_timeoutcxx . . $ grn_lock_timeout.);
177 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
178 if (ctx->rccxx . . $ _grn_ctx#rc. == GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
179 ERRcxx . . $ `lib/grn_error.h:156:9`!(rc,
180 "[config][delete] failed to lock: <%.*s>",
181 (int)real_key_size, key);
182 }
183 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(rc);
184 }
185 rc = grn_hash_deletecxx . . $ grn_hash_delete(c1719313595c9549).(ctx, config, key, real_key_size, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
186 grn_io_unlockcxx . . $ grn_io_unlock(341fd28fcb683921).(ctx, config->iocxx . . $ _grn_hash#io.);
187 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
188 if (ctx->rccxx . . $ _grn_ctx#rc. == GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
189 ERRcxx . . $ `lib/grn_error.h:156:9`!(rc,
190 "[config][delete] failed to delete: <%.*s>",
191 (int)real_key_size, key);
192 }
193 }
194 }
195
196 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
197 }
198
199 grn_objcxx . . $ grn_obj# *
200 grn_config_cursor_opencxx . . $ grn_config_cursor_open(ddec8e3b1327ceae).(grn_ctxcxx . . $ grn_ctx# *ctx)
201 {
202 grn_objcxx . . $ grn_obj# *db;
203 grn_hashcxx . . $ grn_hash# *config;
204 grn_config_cursorcxx . . $ grn_config_cursor# *cursor;
205 grn_idcxx . . $ grn_id# id;
206
207 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
208
209 if (!ctx || !ctx->implcxx . . $ _grn_ctx#impl. || !(db = ctx->implcxx . . $ _grn_ctx#impl.->dbcxx . . $ _grn_ctx_impl#db.)) {
210 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_INVALID_ARGUMENT, "[config][cursor][open] DB isn't initialized");
211 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
212 }
213 config = ((grn_dbcxx . . $ grn_db# *)db)->configcxx . . $ _grn_db#config.;
214
215 cursor = GRN_CALLOCcxx . . $ `lib/grn_alloc.h:42:9`!(sizeof(grn_config_cursor));
216 if (!cursor) {
217 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_NO_MEMORY_AVAILABLE,
218 "[config][cursor][open] failed to allocate memory for config cursor");
219 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
220 }
221
222 GRN_DB_OBJ_SET_TYPEcxx . . $ `lib/grn_ctx.h:195:9`!(cursor, GRN_CURSOR_CONFIGcxx . . $ `include/groonga/groonga.h:891:9`!);
223 cursor->hash_cursorcxx . . $ $anonymous_type_672589bbda10e2e5_0#hash_cursor. = grn_hash_cursor_opencxx . . $ grn_hash_cursor_open(d9a98562cd457d90).(ctx, config,
224 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0,
225 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0,
226 0, -1, 0);
227 if (!cursor->hash_cursorcxx . . $ $anonymous_type_672589bbda10e2e5_0#hash_cursor.) {
228 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(cursor);
229 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_NO_MEMORY_AVAILABLE,
230 "[config][cursor][open] failed to allocate memory for hash cursor");
231 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
232 }
233
234 id = grn_obj_registercxx . . $ grn_obj_register(5739ee2245199e94).(ctx, ctx->implcxx . . $ _grn_ctx#impl.->dbcxx . . $ _grn_ctx_impl#db., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0);
235 DB_OBJcxx . . $ `lib/grn_db.h:62:9`!(cursor)->headercxx . . $ $anonymous_type_4a7c1014017e4c5d_0#header..domaincxx . . $ _grn_obj_header#domain. = GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!;
236 DB_OBJcxx . . $ `lib/grn_db.h:62:9`!(cursor)->rangecxx . . $ $anonymous_type_4a7c1014017e4c5d_0#range. = GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!;
237 grn_db_obj_initcxx . . $ grn_db_obj_init(e57fea19a9dd2af9).(ctx, ctx->implcxx . . $ _grn_ctx#impl.->dbcxx . . $ _grn_ctx_impl#db., id, DB_OBJcxx . . $ `lib/grn_db.h:62:9`!(cursor));
238
239 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!((grn_obj *)cursor);
240 }
241
242 grn_rccxx . . $ grn_rc#
243 grn_config_cursor_closecxx . . $ grn_config_cursor_close(dcf8b8063f66b4ff).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_config_cursorcxx . . $ grn_config_cursor# *cursor)
244 {
245 grn_hash_cursor_closecxx . . $ grn_hash_cursor_close(7eec73c6b4523bff).(ctx, cursor->hash_cursorcxx . . $ $anonymous_type_672589bbda10e2e5_0#hash_cursor.);
246 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(cursor);
247
248 return GRN_SUCCESScxx . . $ GRN_SUCCESS.;
249 }
250
251 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`!
252 grn_config_cursor_nextcxx . . $ grn_config_cursor_next(a5760e5c319a06ee).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *cursor)
253 {
254 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! have_next;
255 grn_config_cursorcxx . . $ grn_config_cursor# *config_cursor = (grn_config_cursorcxx . . $ grn_config_cursor# *)cursor;
256
257 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
258
259 have_next = grn_hash_cursor_nextcxx . . $ grn_hash_cursor_next(6f2ad840d1580522).(ctx, config_cursor->hash_cursorcxx . . $ $anonymous_type_672589bbda10e2e5_0#hash_cursor.) != GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!;
260
261 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(have_next);
262 }
263
264 uint32_tcxx . . $ uint32_t#
265 grn_config_cursor_get_keycxx . . $ grn_config_cursor_get_key(4d6594c229367d9b).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *cursor, const char **key)
266 {
267 void *key_raw;
268 uint32_tcxx . . $ uint32_t# key_size;
269 int key_size_raw;
270 grn_config_cursorcxx . . $ grn_config_cursor# *config_cursor = (grn_config_cursorcxx . . $ grn_config_cursor# *)cursor;
271
272 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
273
274 key_size_raw = grn_hash_cursor_get_keycxx . . $ grn_hash_cursor_get_key(248c0d78df691c42).(ctx,
275 config_cursor->hash_cursorcxx . . $ $anonymous_type_672589bbda10e2e5_0#hash_cursor.,
276 &key_raw);
277 key_size = (uint32_tcxx . . $ uint32_t#)key_size_raw;
278 *key = key_raw;
279
280 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(key_size);
281 }
282
283 uint32_tcxx . . $ uint32_t#
284 grn_config_cursor_get_valuecxx . . $ grn_config_cursor_get_value(4d6594c229367d9b).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *cursor, const char **value)
285 {
286 void *value_raw;
287 uint32_tcxx . . $ uint32_t# value_size;
288 int value_size_raw;
289 grn_config_cursorcxx . . $ grn_config_cursor# *config_cursor = (grn_config_cursorcxx . . $ grn_config_cursor# *)cursor;
290
291 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
292
293 value_size_raw = grn_hash_cursor_get_valuecxx . . $ grn_hash_cursor_get_value(248c0d78df691c42).(ctx,
294 config_cursor->hash_cursorcxx . . $ $anonymous_type_672589bbda10e2e5_0#hash_cursor.,
295 &value_raw);
296 *value = (char *)value_raw + sizeof(uint32_tcxx . . $ uint32_t#);
297 value_size = *((uint32_tcxx . . $ uint32_t# *)value_raw);
298
299 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(value_size);
300 }
301
302 /* Deprecated since 5.1.2. Use grn_config_* instead. */
303 grn_rccxx . . $ grn_rc#
304 grn_conf_setcxx . . $ grn_conf_set(2afa6b044548fd83).(grn_ctxcxx . . $ grn_ctx# *ctx,
305 const char *key, int32_tcxx . . $ int32_t# key_size,
306 const char *value, int32_tcxx . . $ int32_t# value_size)
307 {
308 return grn_config_setcxx . . $ grn_config_set(2afa6b044548fd83).(ctx, key, key_size, value, value_size);
309 }
310
311 grn_rccxx . . $ grn_rc#
312 grn_conf_getcxx . . $ grn_conf_get(55f0c7275dd3feda).(grn_ctxcxx . . $ grn_ctx# *ctx,
313 const char *key, int32_tcxx . . $ int32_t# key_size,
314 const char **value, uint32_tcxx . . $ uint32_t# *value_size)
315 {
316 return grn_config_getcxx . . $ grn_config_get(55f0c7275dd3feda).(ctx, key, key_size, value, value_size);
317 }