1 | /* |
2 | Copyright(C) 2009-2017 Brazil |
3 | |
4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Lesser General Public |
6 | License as published by the Free Software Foundation; either |
7 | version 2.1 of the License, or (at your option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Lesser General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Lesser General Public |
15 | License along with this library; if not, write to the Free Software |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
17 | */ |
18 | |
19 | #pragma once |
20 | |
21 | #include <stdarg.h> |
22 | #include <sys/types.h> |
23 | #include <stdint.h> |
24 | #include <string.h> |
25 | |
26 | #ifdef __cplusplus |
27 | extern "C" { |
28 | #endif |
29 | |
30 | #ifndef GRN_API |
31 | # if defined(_WIN32) || defined(_WIN64) |
32 | # define GRN_API __declspec(dllimport) |
33 | # else |
34 | # define GRN_API |
35 | # endif /* defined(_WIN32) || defined(_WIN64) */ |
36 | #endif /* GRN_API */ |
37 | |
38 | typedef unsigned int grn_id; |
39 | typedef uint8_t grn_bool; |
40 | |
41 | #define GRN_ID_NIL (0x00) |
42 | #define GRN_ID_MAX (0x3fffffff) |
43 | |
44 | #define GRN_TRUE (1) |
45 | #define GRN_FALSE (0) |
46 | |
47 | typedef enum { |
48 | GRN_SUCCESS = 0, |
49 | GRN_END_OF_DATA = 1, |
50 | GRN_UNKNOWN_ERROR = -1, |
51 | GRN_OPERATION_NOT_PERMITTED = -2, |
52 | GRN_NO_SUCH_FILE_OR_DIRECTORY = -3, |
53 | GRN_NO_SUCH_PROCESS = -4, |
54 | GRN_INTERRUPTED_FUNCTION_CALL = -5, |
55 | GRN_INPUT_OUTPUT_ERROR = -6, |
56 | GRN_NO_SUCH_DEVICE_OR_ADDRESS = -7, |
57 | GRN_ARG_LIST_TOO_LONG = -8, |
58 | GRN_EXEC_FORMAT_ERROR = -9, |
59 | GRN_BAD_FILE_DESCRIPTOR = -10, |
60 | GRN_NO_CHILD_PROCESSES = -11, |
61 | GRN_RESOURCE_TEMPORARILY_UNAVAILABLE = -12, |
62 | GRN_NOT_ENOUGH_SPACE = -13, |
63 | GRN_PERMISSION_DENIED = -14, |
64 | GRN_BAD_ADDRESS = -15, |
65 | GRN_RESOURCE_BUSY = -16, |
66 | GRN_FILE_EXISTS = -17, |
67 | GRN_IMPROPER_LINK = -18, |
68 | GRN_NO_SUCH_DEVICE = -19, |
69 | GRN_NOT_A_DIRECTORY = -20, |
70 | GRN_IS_A_DIRECTORY = -21, |
71 | GRN_INVALID_ARGUMENT = -22, |
72 | GRN_TOO_MANY_OPEN_FILES_IN_SYSTEM = -23, |
73 | GRN_TOO_MANY_OPEN_FILES = -24, |
74 | GRN_INAPPROPRIATE_I_O_CONTROL_OPERATION = -25, |
75 | GRN_FILE_TOO_LARGE = -26, |
76 | GRN_NO_SPACE_LEFT_ON_DEVICE = -27, |
77 | GRN_INVALID_SEEK = -28, |
78 | GRN_READ_ONLY_FILE_SYSTEM = -29, |
79 | GRN_TOO_MANY_LINKS = -30, |
80 | GRN_BROKEN_PIPE = -31, |
81 | GRN_DOMAIN_ERROR = -32, |
82 | GRN_RESULT_TOO_LARGE = -33, |
83 | GRN_RESOURCE_DEADLOCK_AVOIDED = -34, |
84 | GRN_NO_MEMORY_AVAILABLE = -35, |
85 | GRN_FILENAME_TOO_LONG = -36, |
86 | GRN_NO_LOCKS_AVAILABLE = -37, |
87 | GRN_FUNCTION_NOT_IMPLEMENTED = -38, |
88 | GRN_DIRECTORY_NOT_EMPTY = -39, |
89 | GRN_ILLEGAL_BYTE_SEQUENCE = -40, |
90 | GRN_SOCKET_NOT_INITIALIZED = -41, |
91 | GRN_OPERATION_WOULD_BLOCK = -42, |
92 | GRN_ADDRESS_IS_NOT_AVAILABLE = -43, |
93 | GRN_NETWORK_IS_DOWN = -44, |
94 | GRN_NO_BUFFER = -45, |
95 | GRN_SOCKET_IS_ALREADY_CONNECTED = -46, |
96 | GRN_SOCKET_IS_NOT_CONNECTED = -47, |
97 | GRN_SOCKET_IS_ALREADY_SHUTDOWNED = -48, |
98 | GRN_OPERATION_TIMEOUT = -49, |
99 | GRN_CONNECTION_REFUSED = -50, |
100 | GRN_RANGE_ERROR = -51, |
101 | GRN_TOKENIZER_ERROR = -52, |
102 | GRN_FILE_CORRUPT = -53, |
103 | GRN_INVALID_FORMAT = -54, |
104 | GRN_OBJECT_CORRUPT = -55, |
105 | GRN_TOO_MANY_SYMBOLIC_LINKS = -56, |
106 | GRN_NOT_SOCKET = -57, |
107 | GRN_OPERATION_NOT_SUPPORTED = -58, |
108 | GRN_ADDRESS_IS_IN_USE = -59, |
109 | GRN_ZLIB_ERROR = -60, |
110 | GRN_LZ4_ERROR = -61, |
111 | /* Just for backward compatibility. We'll remove it at 5.0.0. */ |
112 | #define GRN_LZO_ERROR GRN_LZ4_ERROR |
113 | GRN_STACK_OVER_FLOW = -62, |
114 | GRN_SYNTAX_ERROR = -63, |
115 | GRN_RETRY_MAX = -64, |
116 | GRN_INCOMPATIBLE_FILE_FORMAT = -65, |
117 | GRN_UPDATE_NOT_ALLOWED = -66, |
118 | GRN_TOO_SMALL_OFFSET = -67, |
119 | GRN_TOO_LARGE_OFFSET = -68, |
120 | GRN_TOO_SMALL_LIMIT = -69, |
121 | GRN_CAS_ERROR = -70, |
122 | GRN_UNSUPPORTED_COMMAND_VERSION = -71, |
123 | GRN_NORMALIZER_ERROR = -72, |
124 | GRN_TOKEN_FILTER_ERROR = -73, |
125 | GRN_COMMAND_ERROR = -74, |
126 | GRN_PLUGIN_ERROR = -75, |
127 | GRN_SCORER_ERROR = -76, |
128 | GRN_CANCEL = -77, |
129 | GRN_WINDOW_FUNCTION_ERROR = -78, |
130 | GRN_ZSTD_ERROR = -79 |
131 | } grn_rc; |
132 | |
133 | GRN_API grn_rc grn_init(void); |
134 | GRN_API grn_rc grn_fin(void); |
135 | |
136 | GRN_API const char *grn_get_global_error_message(void); |
137 | |
138 | typedef enum { |
139 | GRN_ENC_DEFAULT = 0, |
140 | GRN_ENC_NONE, |
141 | GRN_ENC_EUC_JP, |
142 | GRN_ENC_UTF8, |
143 | GRN_ENC_SJIS, |
144 | GRN_ENC_LATIN1, |
145 | GRN_ENC_KOI8R |
146 | } grn_encoding; |
147 | |
148 | typedef enum { |
149 | GRN_COMMAND_VERSION_DEFAULT = 0, |
150 | GRN_COMMAND_VERSION_1, |
151 | GRN_COMMAND_VERSION_2, |
152 | GRN_COMMAND_VERSION_3 |
153 | } grn_command_version; |
154 | |
155 | #define GRN_COMMAND_VERSION_MIN GRN_COMMAND_VERSION_1 |
156 | #define GRN_COMMAND_VERSION_STABLE GRN_COMMAND_VERSION_1 |
157 | #define GRN_COMMAND_VERSION_MAX GRN_COMMAND_VERSION_3 |
158 | |
159 | typedef enum { |
160 | GRN_LOG_NONE = 0, |
161 | GRN_LOG_EMERG, |
162 | GRN_LOG_ALERT, |
163 | GRN_LOG_CRIT, |
164 | GRN_LOG_ERROR, |
165 | GRN_LOG_WARNING, |
166 | GRN_LOG_NOTICE, |
167 | GRN_LOG_INFO, |
168 | GRN_LOG_DEBUG, |
169 | GRN_LOG_DUMP |
170 | } grn_log_level; |
171 | |
172 | GRN_API const char *grn_log_level_to_string(grn_log_level level); |
173 | GRN_API grn_bool grn_log_level_parse(const char *string, grn_log_level *level); |
174 | |
175 | /* query log flags */ |
176 | #define GRN_QUERY_LOG_NONE (0x00) |
177 | #define GRN_QUERY_LOG_COMMAND (0x01<<0) |
178 | #define GRN_QUERY_LOG_RESULT_CODE (0x01<<1) |
179 | #define GRN_QUERY_LOG_DESTINATION (0x01<<2) |
180 | #define GRN_QUERY_LOG_CACHE (0x01<<3) |
181 | #define GRN_QUERY_LOG_SIZE (0x01<<4) |
182 | #define GRN_QUERY_LOG_SCORE (0x01<<5) |
183 | #define GRN_QUERY_LOG_ALL\ |
184 | (GRN_QUERY_LOG_COMMAND |\ |
185 | GRN_QUERY_LOG_RESULT_CODE |\ |
186 | GRN_QUERY_LOG_DESTINATION |\ |
187 | GRN_QUERY_LOG_CACHE |\ |
188 | GRN_QUERY_LOG_SIZE |\ |
189 | GRN_QUERY_LOG_SCORE) |
190 | #define GRN_QUERY_LOG_DEFAULT GRN_QUERY_LOG_ALL |
191 | |
192 | typedef enum { |
193 | GRN_CONTENT_NONE = 0, |
194 | GRN_CONTENT_TSV, |
195 | GRN_CONTENT_JSON, |
196 | GRN_CONTENT_XML, |
197 | GRN_CONTENT_MSGPACK, |
198 | GRN_CONTENT_GROONGA_COMMAND_LIST |
199 | } grn_content_type; |
200 | |
201 | typedef struct _grn_obj grn_obj; |
202 | typedef struct _grn_ctx grn_ctx; |
203 | |
204 | #define GRN_CTX_MSGSIZE (0x80) |
205 | #define GRN_CTX_FIN (0xff) |
206 | |
207 | typedef union { |
208 | int int_value; |
209 | grn_id id; |
210 | void *ptr; |
211 | } grn_user_data; |
212 | |
213 | typedef grn_obj *grn_proc_func(grn_ctx *ctx, int nargs, grn_obj **args, |
214 | grn_user_data *user_data); |
215 | |
216 | struct _grn_ctx { |
217 | grn_rc rc; |
218 | int flags; |
219 | grn_encoding encoding; |
220 | unsigned char ntrace; |
221 | unsigned char errlvl; |
222 | unsigned char stat; |
223 | unsigned int seqno; |
224 | unsigned int subno; |
225 | unsigned int seqno2; |
226 | unsigned int errline; |
227 | grn_user_data user_data; |
228 | grn_ctx *prev; |
229 | grn_ctx *next; |
230 | const char *errfile; |
231 | const char *errfunc; |
232 | struct _grn_ctx_impl *impl; |
233 | void *trace[16]; |
234 | char errbuf[GRN_CTX_MSGSIZE]; |
235 | }; |
236 | |
237 | #define GRN_CTX_USER_DATA(ctx) (&((ctx)->user_data)) |
238 | |
239 | /* Deprecated since 4.0.3. Don't use it. */ |
240 | #define GRN_CTX_USE_QL (0x03) |
241 | /* Deprecated since 4.0.3. Don't use it. */ |
242 | #define GRN_CTX_BATCH_MODE (0x04) |
243 | #define GRN_CTX_PER_DB (0x08) |
244 | |
245 | GRN_API grn_rc grn_ctx_init(grn_ctx *ctx, int flags); |
246 | GRN_API grn_rc grn_ctx_fin(grn_ctx *ctx); |
247 | GRN_API grn_ctx *grn_ctx_open(int flags); |
248 | GRN_API grn_rc grn_ctx_close(grn_ctx *ctx); |
249 | GRN_API grn_rc grn_ctx_set_finalizer(grn_ctx *ctx, grn_proc_func *func); |
250 | |
251 | GRN_API grn_rc grn_ctx_push_temporary_open_space(grn_ctx *ctx); |
252 | GRN_API grn_rc grn_ctx_pop_temporary_open_space(grn_ctx *ctx); |
253 | GRN_API grn_rc grn_ctx_merge_temporary_open_space(grn_ctx *ctx); |
254 | |
255 | GRN_API grn_encoding grn_get_default_encoding(void); |
256 | GRN_API grn_rc grn_set_default_encoding(grn_encoding encoding); |
257 | |
258 | #define GRN_CTX_GET_ENCODING(ctx) ((ctx)->encoding) |
259 | #define GRN_CTX_SET_ENCODING(ctx,enc) \ |
260 | ((ctx)->encoding = (enc == GRN_ENC_DEFAULT) ? grn_get_default_encoding() : enc) |
261 | |
262 | GRN_API const char *grn_get_version(void); |
263 | GRN_API const char *grn_get_package(void); |
264 | GRN_API const char *grn_get_package_label(void); |
265 | |
266 | GRN_API grn_command_version grn_get_default_command_version(void); |
267 | GRN_API grn_rc grn_set_default_command_version(grn_command_version version); |
268 | GRN_API grn_command_version grn_ctx_get_command_version(grn_ctx *ctx); |
269 | GRN_API grn_rc grn_ctx_set_command_version(grn_ctx *ctx, grn_command_version version); |
270 | GRN_API long long int grn_ctx_get_match_escalation_threshold(grn_ctx *ctx); |
271 | GRN_API grn_rc grn_ctx_set_match_escalation_threshold(grn_ctx *ctx, long long int threshold); |
272 | GRN_API long long int grn_get_default_match_escalation_threshold(void); |
273 | GRN_API grn_rc grn_set_default_match_escalation_threshold(long long int threshold); |
274 | |
275 | GRN_API int grn_get_lock_timeout(void); |
276 | GRN_API grn_rc grn_set_lock_timeout(int timeout); |
277 | |
278 | /* grn_encoding */ |
279 | |
280 | GRN_API const char *grn_encoding_to_string(grn_encoding encoding); |
281 | GRN_API grn_encoding grn_encoding_parse(const char *name); |
282 | |
283 | /* obj */ |
284 | |
285 | typedef uint16_t grn_obj_flags; |
286 | typedef uint32_t grn_table_flags; |
287 | typedef uint32_t grn_column_flags; |
288 | |
289 | /* flags for grn_obj_flags and grn_table_flags */ |
290 | |
291 | #define GRN_OBJ_FLAGS_MASK (0xffff) |
292 | |
293 | #define GRN_OBJ_TABLE_TYPE_MASK (0x07) |
294 | #define GRN_OBJ_TABLE_HASH_KEY (0x00) |
295 | #define GRN_OBJ_TABLE_PAT_KEY (0x01) |
296 | #define GRN_OBJ_TABLE_DAT_KEY (0x02) |
297 | #define GRN_OBJ_TABLE_NO_KEY (0x03) |
298 | |
299 | #define GRN_OBJ_KEY_MASK (0x07<<3) |
300 | #define GRN_OBJ_KEY_UINT (0x00<<3) |
301 | #define GRN_OBJ_KEY_INT (0x01<<3) |
302 | #define GRN_OBJ_KEY_FLOAT (0x02<<3) |
303 | #define GRN_OBJ_KEY_GEO_POINT (0x03<<3) |
304 | |
305 | #define GRN_OBJ_KEY_WITH_SIS (0x01<<6) |
306 | #define GRN_OBJ_KEY_NORMALIZE (0x01<<7) |
307 | |
308 | #define GRN_OBJ_COLUMN_TYPE_MASK (0x07) |
309 | #define GRN_OBJ_COLUMN_SCALAR (0x00) |
310 | #define GRN_OBJ_COLUMN_VECTOR (0x01) |
311 | #define GRN_OBJ_COLUMN_INDEX (0x02) |
312 | |
313 | #define GRN_OBJ_COMPRESS_MASK (0x07<<4) |
314 | #define GRN_OBJ_COMPRESS_NONE (0x00<<4) |
315 | #define GRN_OBJ_COMPRESS_ZLIB (0x01<<4) |
316 | #define GRN_OBJ_COMPRESS_LZ4 (0x02<<4) |
317 | /* Just for backward compatibility. We'll remove it at 5.0.0. */ |
318 | #define GRN_OBJ_COMPRESS_LZO GRN_OBJ_COMPRESS_LZ4 |
319 | #define GRN_OBJ_COMPRESS_ZSTD (0x03<<4) |
320 | |
321 | #define GRN_OBJ_WITH_SECTION (0x01<<7) |
322 | #define GRN_OBJ_WITH_WEIGHT (0x01<<8) |
323 | #define GRN_OBJ_WITH_POSITION (0x01<<9) |
324 | #define GRN_OBJ_RING_BUFFER (0x01<<10) |
325 | |
326 | #define GRN_OBJ_UNIT_MASK (0x0f<<8) |
327 | #define GRN_OBJ_UNIT_DOCUMENT_NONE (0x00<<8) |
328 | #define GRN_OBJ_UNIT_DOCUMENT_SECTION (0x01<<8) |
329 | #define GRN_OBJ_UNIT_DOCUMENT_POSITION (0x02<<8) |
330 | #define GRN_OBJ_UNIT_SECTION_NONE (0x03<<8) |
331 | #define GRN_OBJ_UNIT_SECTION_POSITION (0x04<<8) |
332 | #define GRN_OBJ_UNIT_POSITION_NONE (0x05<<8) |
333 | #define GRN_OBJ_UNIT_USERDEF_DOCUMENT (0x06<<8) |
334 | #define GRN_OBJ_UNIT_USERDEF_SECTION (0x07<<8) |
335 | #define GRN_OBJ_UNIT_USERDEF_POSITION (0x08<<8) |
336 | |
337 | /* Don't use (0x01<<12) because it's used internally. */ |
338 | |
339 | #define GRN_OBJ_NO_SUBREC (0x00<<13) |
340 | #define GRN_OBJ_WITH_SUBREC (0x01<<13) |
341 | |
342 | #define GRN_OBJ_KEY_VAR_SIZE (0x01<<14) |
343 | |
344 | #define GRN_OBJ_TEMPORARY (0x00<<15) |
345 | #define GRN_OBJ_PERSISTENT (0x01<<15) |
346 | |
347 | /* flags only for grn_table_flags */ |
348 | |
349 | #define GRN_OBJ_KEY_LARGE (0x01<<16) |
350 | |
351 | /* flags only for grn_column_flags */ |
352 | |
353 | #define GRN_OBJ_INDEX_SMALL (0x01<<16) |
354 | #define GRN_OBJ_INDEX_MEDIUM (0x01<<17) |
355 | |
356 | /* obj types */ |
357 | |
358 | #define GRN_VOID (0x00) |
359 | #define GRN_BULK (0x02) |
360 | #define GRN_PTR (0x03) |
361 | #define GRN_UVECTOR (0x04) /* vector of fixed size data especially grn_id */ |
362 | #define GRN_PVECTOR (0x05) /* vector of grn_obj* */ |
363 | #define GRN_VECTOR (0x06) /* vector of arbitrary data */ |
364 | #define GRN_MSG (0x07) |
365 | #define GRN_QUERY (0x08) |
366 | #define GRN_ACCESSOR (0x09) |
367 | #define GRN_SNIP (0x0b) |
368 | #define GRN_PATSNIP (0x0c) |
369 | #define GRN_STRING (0x0d) |
370 | #define GRN_CURSOR_TABLE_HASH_KEY (0x10) |
371 | #define GRN_CURSOR_TABLE_PAT_KEY (0x11) |
372 | #define GRN_CURSOR_TABLE_DAT_KEY (0x12) |
373 | #define GRN_CURSOR_TABLE_NO_KEY (0x13) |
374 | #define GRN_CURSOR_COLUMN_INDEX (0x18) |
375 | #define GRN_CURSOR_COLUMN_GEO_INDEX (0x1a) |
376 | #define GRN_CURSOR_CONFIG (0x1f) |
377 | #define GRN_TYPE (0x20) |
378 | #define GRN_PROC (0x21) |
379 | #define GRN_EXPR (0x22) |
380 | #define GRN_TABLE_HASH_KEY (0x30) |
381 | #define GRN_TABLE_PAT_KEY (0x31) |
382 | #define GRN_TABLE_DAT_KEY (0x32) |
383 | #define GRN_TABLE_NO_KEY (0x33) |
384 | #define GRN_DB (0x37) |
385 | #define GRN_COLUMN_FIX_SIZE (0x40) |
386 | #define GRN_COLUMN_VAR_SIZE (0x41) |
387 | #define GRN_COLUMN_INDEX (0x48) |
388 | |
389 | typedef struct _grn_section grn_section; |
390 | typedef struct _grn_obj_header ; |
391 | |
392 | struct _grn_section { |
393 | unsigned int offset; |
394 | unsigned int length; |
395 | unsigned int weight; |
396 | grn_id domain; |
397 | }; |
398 | |
399 | struct { |
400 | unsigned char ; |
401 | unsigned char ; |
402 | grn_obj_flags ; |
403 | grn_id domain; |
404 | }; |
405 | |
406 | struct _grn_obj { |
407 | grn_obj_header ; |
408 | union { |
409 | struct { |
410 | char *head; |
411 | char *curr; |
412 | char *tail; |
413 | } b; |
414 | struct { |
415 | grn_obj *body; |
416 | grn_section *sections; |
417 | int n_sections; |
418 | } v; |
419 | } u; |
420 | }; |
421 | |
422 | #define GRN_OBJ_REFER (0x01<<0) |
423 | #define GRN_OBJ_OUTPLACE (0x01<<1) |
424 | #define GRN_OBJ_OWN (0x01<<5) |
425 | |
426 | #define GRN_OBJ_INIT(obj,obj_type,obj_flags,obj_domain) do { \ |
427 | (obj)->header.type = (obj_type);\ |
428 | (obj)->header.impl_flags = (obj_flags);\ |
429 | (obj)->header.flags = 0;\ |
430 | (obj)->header.domain = (obj_domain);\ |
431 | (obj)->u.b.head = NULL;\ |
432 | (obj)->u.b.curr = NULL;\ |
433 | (obj)->u.b.tail = NULL;\ |
434 | } while (0) |
435 | |
436 | #define GRN_OBJ_FIN(ctx,obj) (grn_obj_close((ctx), (obj))) |
437 | |
438 | GRN_API grn_rc grn_ctx_use(grn_ctx *ctx, grn_obj *db); |
439 | GRN_API grn_obj *grn_ctx_db(grn_ctx *ctx); |
440 | GRN_API grn_obj *grn_ctx_get(grn_ctx *ctx, const char *name, int name_size); |
441 | GRN_API grn_rc grn_ctx_get_all_tables(grn_ctx *ctx, grn_obj *tables_buffer); |
442 | GRN_API grn_rc grn_ctx_get_all_types(grn_ctx *ctx, grn_obj *types_buffer); |
443 | GRN_API grn_rc grn_ctx_get_all_tokenizers(grn_ctx *ctx, |
444 | grn_obj *tokenizers_buffer); |
445 | GRN_API grn_rc grn_ctx_get_all_normalizers(grn_ctx *ctx, |
446 | grn_obj *normalizers_buffer); |
447 | GRN_API grn_rc grn_ctx_get_all_token_filters(grn_ctx *ctx, |
448 | grn_obj *token_filters_buffer); |
449 | |
450 | typedef enum { |
451 | GRN_DB_VOID = 0, |
452 | GRN_DB_DB, |
453 | GRN_DB_OBJECT, |
454 | GRN_DB_BOOL, |
455 | GRN_DB_INT8, |
456 | GRN_DB_UINT8, |
457 | GRN_DB_INT16, |
458 | GRN_DB_UINT16, |
459 | GRN_DB_INT32, |
460 | GRN_DB_UINT32, |
461 | GRN_DB_INT64, |
462 | GRN_DB_UINT64, |
463 | GRN_DB_FLOAT, |
464 | GRN_DB_TIME, |
465 | GRN_DB_SHORT_TEXT, |
466 | GRN_DB_TEXT, |
467 | GRN_DB_LONG_TEXT, |
468 | GRN_DB_TOKYO_GEO_POINT, |
469 | GRN_DB_WGS84_GEO_POINT |
470 | } grn_builtin_type; |
471 | |
472 | typedef enum { |
473 | GRN_DB_MECAB = 64, |
474 | GRN_DB_DELIMIT, |
475 | GRN_DB_UNIGRAM, |
476 | GRN_DB_BIGRAM, |
477 | GRN_DB_TRIGRAM |
478 | } grn_builtin_tokenizer; |
479 | |
480 | GRN_API grn_obj *grn_ctx_at(grn_ctx *ctx, grn_id id); |
481 | GRN_API grn_bool grn_ctx_is_opened(grn_ctx *ctx, grn_id id); |
482 | |
483 | GRN_API grn_rc grn_plugin_register(grn_ctx *ctx, const char *name); |
484 | GRN_API grn_rc grn_plugin_unregister(grn_ctx *ctx, const char *name); |
485 | GRN_API grn_rc grn_plugin_register_by_path(grn_ctx *ctx, const char *path); |
486 | GRN_API grn_rc grn_plugin_unregister_by_path(grn_ctx *ctx, const char *path); |
487 | GRN_API const char *grn_plugin_get_system_plugins_dir(void); |
488 | GRN_API const char *grn_plugin_get_suffix(void); |
489 | GRN_API const char *grn_plugin_get_ruby_suffix(void); |
490 | GRN_API grn_rc grn_plugin_get_names(grn_ctx *ctx, grn_obj *names); |
491 | |
492 | typedef struct { |
493 | const char *name; |
494 | unsigned int name_size; |
495 | grn_obj value; |
496 | } grn_expr_var; |
497 | |
498 | typedef grn_rc (*grn_plugin_func)(grn_ctx *ctx); |
499 | |
500 | typedef enum { |
501 | GRN_PROC_INVALID = 0, |
502 | GRN_PROC_TOKENIZER, |
503 | GRN_PROC_COMMAND, |
504 | GRN_PROC_FUNCTION, |
505 | GRN_PROC_HOOK, |
506 | GRN_PROC_NORMALIZER, |
507 | GRN_PROC_TOKEN_FILTER, |
508 | GRN_PROC_SCORER, |
509 | GRN_PROC_WINDOW_FUNCTION |
510 | } grn_proc_type; |
511 | |
512 | GRN_API grn_obj *grn_proc_create(grn_ctx *ctx, |
513 | const char *name, int name_size, grn_proc_type type, |
514 | grn_proc_func *init, grn_proc_func *next, grn_proc_func *fin, |
515 | unsigned int nvars, grn_expr_var *vars); |
516 | GRN_API grn_obj *grn_proc_get_info(grn_ctx *ctx, grn_user_data *user_data, |
517 | grn_expr_var **vars, unsigned int *nvars, grn_obj **caller); |
518 | GRN_API grn_proc_type grn_proc_get_type(grn_ctx *ctx, grn_obj *proc); |
519 | |
520 | typedef grn_obj grn_table_cursor; |
521 | |
522 | typedef struct { |
523 | grn_id rid; |
524 | uint32_t sid; |
525 | uint32_t pos; |
526 | uint32_t tf; |
527 | uint32_t weight; |
528 | uint32_t rest; |
529 | } grn_posting; |
530 | |
531 | typedef enum { |
532 | GRN_OP_PUSH = 0, |
533 | GRN_OP_POP, |
534 | GRN_OP_NOP, |
535 | GRN_OP_CALL, |
536 | GRN_OP_INTERN, |
537 | GRN_OP_GET_REF, |
538 | GRN_OP_GET_VALUE, |
539 | GRN_OP_AND, |
540 | GRN_OP_AND_NOT, |
541 | /* Deprecated. Just for backward compatibility. */ |
542 | #define GRN_OP_BUT GRN_OP_AND_NOT |
543 | GRN_OP_OR, |
544 | GRN_OP_ASSIGN, |
545 | GRN_OP_STAR_ASSIGN, |
546 | GRN_OP_SLASH_ASSIGN, |
547 | GRN_OP_MOD_ASSIGN, |
548 | GRN_OP_PLUS_ASSIGN, |
549 | GRN_OP_MINUS_ASSIGN, |
550 | GRN_OP_SHIFTL_ASSIGN, |
551 | GRN_OP_SHIFTR_ASSIGN, |
552 | GRN_OP_SHIFTRR_ASSIGN, |
553 | GRN_OP_AND_ASSIGN, |
554 | GRN_OP_XOR_ASSIGN, |
555 | GRN_OP_OR_ASSIGN, |
556 | GRN_OP_JUMP, |
557 | GRN_OP_CJUMP, |
558 | GRN_OP_COMMA, |
559 | GRN_OP_BITWISE_OR, |
560 | GRN_OP_BITWISE_XOR, |
561 | GRN_OP_BITWISE_AND, |
562 | GRN_OP_BITWISE_NOT, |
563 | GRN_OP_EQUAL, |
564 | GRN_OP_NOT_EQUAL, |
565 | GRN_OP_LESS, |
566 | GRN_OP_GREATER, |
567 | GRN_OP_LESS_EQUAL, |
568 | GRN_OP_GREATER_EQUAL, |
569 | GRN_OP_IN, |
570 | GRN_OP_MATCH, |
571 | GRN_OP_NEAR, |
572 | GRN_OP_NEAR2, |
573 | GRN_OP_SIMILAR, |
574 | , |
575 | GRN_OP_SHIFTL, |
576 | GRN_OP_SHIFTR, |
577 | GRN_OP_SHIFTRR, |
578 | GRN_OP_PLUS, |
579 | GRN_OP_MINUS, |
580 | GRN_OP_STAR, |
581 | GRN_OP_SLASH, |
582 | GRN_OP_MOD, |
583 | GRN_OP_DELETE, |
584 | GRN_OP_INCR, |
585 | GRN_OP_DECR, |
586 | GRN_OP_INCR_POST, |
587 | GRN_OP_DECR_POST, |
588 | GRN_OP_NOT, |
589 | GRN_OP_ADJUST, |
590 | GRN_OP_EXACT, |
591 | GRN_OP_LCP, |
592 | GRN_OP_PARTIAL, |
593 | GRN_OP_UNSPLIT, |
594 | GRN_OP_PREFIX, |
595 | GRN_OP_SUFFIX, |
596 | GRN_OP_GEO_DISTANCE1, |
597 | GRN_OP_GEO_DISTANCE2, |
598 | GRN_OP_GEO_DISTANCE3, |
599 | GRN_OP_GEO_DISTANCE4, |
600 | GRN_OP_GEO_WITHINP5, |
601 | GRN_OP_GEO_WITHINP6, |
602 | GRN_OP_GEO_WITHINP8, |
603 | GRN_OP_OBJ_SEARCH, |
604 | GRN_OP_EXPR_GET_VAR, |
605 | GRN_OP_TABLE_CREATE, |
606 | GRN_OP_TABLE_SELECT, |
607 | GRN_OP_TABLE_SORT, |
608 | GRN_OP_TABLE_GROUP, |
609 | GRN_OP_JSON_PUT, |
610 | GRN_OP_GET_MEMBER, |
611 | GRN_OP_REGEXP, |
612 | GRN_OP_FUZZY |
613 | } grn_operator; |
614 | |
615 | GRN_API grn_obj *grn_obj_column(grn_ctx *ctx, grn_obj *table, |
616 | const char *name, unsigned int name_size); |
617 | |
618 | /*------------------------------------------------------------- |
619 | * API for column |
620 | */ |
621 | |
622 | #define GRN_COLUMN_NAME_ID "_id" |
623 | #define GRN_COLUMN_NAME_ID_LEN (sizeof(GRN_COLUMN_NAME_ID) - 1) |
624 | #define GRN_COLUMN_NAME_KEY "_key" |
625 | #define GRN_COLUMN_NAME_KEY_LEN (sizeof(GRN_COLUMN_NAME_KEY) - 1) |
626 | #define GRN_COLUMN_NAME_VALUE "_value" |
627 | #define GRN_COLUMN_NAME_VALUE_LEN (sizeof(GRN_COLUMN_NAME_VALUE) - 1) |
628 | #define GRN_COLUMN_NAME_SCORE "_score" |
629 | #define GRN_COLUMN_NAME_SCORE_LEN (sizeof(GRN_COLUMN_NAME_SCORE) - 1) |
630 | #define GRN_COLUMN_NAME_NSUBRECS "_nsubrecs" |
631 | #define GRN_COLUMN_NAME_NSUBRECS_LEN (sizeof(GRN_COLUMN_NAME_NSUBRECS) - 1) |
632 | #define GRN_COLUMN_NAME_MAX "_max" |
633 | #define GRN_COLUMN_NAME_MAX_LEN (sizeof(GRN_COLUMN_NAME_MAX) - 1) |
634 | #define GRN_COLUMN_NAME_MIN "_min" |
635 | #define GRN_COLUMN_NAME_MIN_LEN (sizeof(GRN_COLUMN_NAME_MIN) - 1) |
636 | #define GRN_COLUMN_NAME_SUM "_sum" |
637 | #define GRN_COLUMN_NAME_SUM_LEN (sizeof(GRN_COLUMN_NAME_SUM) - 1) |
638 | #define GRN_COLUMN_NAME_AVG "_avg" |
639 | #define GRN_COLUMN_NAME_AVG_LEN (sizeof(GRN_COLUMN_NAME_AVG) - 1) |
640 | |
641 | GRN_API grn_obj *grn_column_create(grn_ctx *ctx, grn_obj *table, |
642 | const char *name, unsigned int name_size, |
643 | const char *path, grn_column_flags flags, grn_obj *type); |
644 | |
645 | #define GRN_COLUMN_OPEN_OR_CREATE(ctx,table,name,name_size,path,flags,type,column) \ |
646 | (((column) = grn_obj_column((ctx), (table), (name), (name_size))) ||\ |
647 | ((column) = grn_column_create((ctx), (table), (name), (name_size), (path), (flags), (type)))) |
648 | |
649 | GRN_API grn_rc grn_column_index_update(grn_ctx *ctx, grn_obj *column, |
650 | grn_id id, unsigned int section, |
651 | grn_obj *oldvalue, grn_obj *newvalue); |
652 | GRN_API grn_obj *grn_column_table(grn_ctx *ctx, grn_obj *column); |
653 | GRN_API grn_rc grn_column_truncate(grn_ctx *ctx, grn_obj *column); |
654 | |
655 | /*------------------------------------------------------------- |
656 | * API for db, table and/or column |
657 | */ |
658 | |
659 | typedef enum { |
660 | GRN_INFO_ENCODING = 0, |
661 | GRN_INFO_SOURCE, |
662 | GRN_INFO_DEFAULT_TOKENIZER, |
663 | GRN_INFO_ELEMENT_SIZE, |
664 | GRN_INFO_CURR_MAX, |
665 | GRN_INFO_MAX_ELEMENT_SIZE, |
666 | GRN_INFO_SEG_SIZE, |
667 | GRN_INFO_CHUNK_SIZE, |
668 | GRN_INFO_MAX_SECTION, |
669 | GRN_INFO_HOOK_LOCAL_DATA, |
670 | GRN_INFO_ELEMENT_A, |
671 | GRN_INFO_ELEMENT_CHUNK, |
672 | GRN_INFO_ELEMENT_CHUNK_SIZE, |
673 | GRN_INFO_ELEMENT_BUFFER_FREE, |
674 | GRN_INFO_ELEMENT_NTERMS, |
675 | GRN_INFO_ELEMENT_NTERMS_VOID, |
676 | GRN_INFO_ELEMENT_SIZE_IN_CHUNK, |
677 | GRN_INFO_ELEMENT_POS_IN_CHUNK, |
678 | GRN_INFO_ELEMENT_SIZE_IN_BUFFER, |
679 | GRN_INFO_ELEMENT_POS_IN_BUFFER, |
680 | GRN_INFO_ELEMENT_ESTIMATE_SIZE, |
681 | GRN_INFO_NGRAM_UNIT_SIZE, |
682 | /* |
683 | GRN_INFO_VERSION, |
684 | GRN_INFO_CONFIGURE_OPTIONS, |
685 | GRN_INFO_CONFIG_PATH, |
686 | */ |
687 | GRN_INFO_PARTIAL_MATCH_THRESHOLD, |
688 | GRN_INFO_II_SPLIT_THRESHOLD, |
689 | GRN_INFO_SUPPORT_ZLIB, |
690 | GRN_INFO_SUPPORT_LZ4, |
691 | /* Just for backward compatibility. We'll remove it at 5.0.0. */ |
692 | #define GRN_INFO_SUPPORT_LZO GRN_INFO_SUPPORT_LZ4 |
693 | GRN_INFO_NORMALIZER, |
694 | GRN_INFO_TOKEN_FILTERS, |
695 | GRN_INFO_SUPPORT_ZSTD, |
696 | GRN_INFO_SUPPORT_ARROW |
697 | } grn_info_type; |
698 | |
699 | GRN_API grn_obj *grn_obj_get_info(grn_ctx *ctx, grn_obj *obj, grn_info_type type, grn_obj *valuebuf); |
700 | GRN_API grn_rc grn_obj_set_info(grn_ctx *ctx, grn_obj *obj, grn_info_type type, grn_obj *value); |
701 | GRN_API grn_obj *grn_obj_get_element_info(grn_ctx *ctx, grn_obj *obj, grn_id id, |
702 | grn_info_type type, grn_obj *value); |
703 | GRN_API grn_rc grn_obj_set_element_info(grn_ctx *ctx, grn_obj *obj, grn_id id, |
704 | grn_info_type type, grn_obj *value); |
705 | |
706 | GRN_API grn_obj *grn_obj_get_value(grn_ctx *ctx, grn_obj *obj, grn_id id, grn_obj *value); |
707 | GRN_API int grn_obj_get_values(grn_ctx *ctx, grn_obj *obj, grn_id offset, void **values); |
708 | |
709 | #define GRN_COLUMN_EACH(ctx,column,id,value,block) do {\ |
710 | int _n;\ |
711 | grn_id id = 1;\ |
712 | while ((_n = grn_obj_get_values(ctx, column, id, (void **)&value)) > 0) {\ |
713 | for (; _n; _n--, id++, value++) {\ |
714 | block\ |
715 | }\ |
716 | }\ |
717 | } while (0) |
718 | |
719 | #define GRN_OBJ_SET_MASK (0x07) |
720 | #define GRN_OBJ_SET (0x01) |
721 | #define GRN_OBJ_INCR (0x02) |
722 | #define GRN_OBJ_DECR (0x03) |
723 | #define GRN_OBJ_APPEND (0x04) |
724 | #define GRN_OBJ_PREPEND (0x05) |
725 | #define GRN_OBJ_GET (0x01<<4) |
726 | #define GRN_OBJ_COMPARE (0x01<<5) |
727 | #define GRN_OBJ_LOCK (0x01<<6) |
728 | #define GRN_OBJ_UNLOCK (0x01<<7) |
729 | |
730 | GRN_API grn_rc grn_obj_set_value(grn_ctx *ctx, grn_obj *obj, grn_id id, grn_obj *value, int flags); |
731 | GRN_API grn_rc grn_obj_remove(grn_ctx *ctx, grn_obj *obj); |
732 | GRN_API grn_rc grn_obj_remove_dependent(grn_ctx *ctx, grn_obj *obj); |
733 | GRN_API grn_rc grn_obj_remove_force(grn_ctx *ctx, |
734 | const char *name, |
735 | int name_size); |
736 | GRN_API grn_rc grn_obj_rename(grn_ctx *ctx, grn_obj *obj, |
737 | const char *name, unsigned int name_size); |
738 | GRN_API grn_rc grn_table_rename(grn_ctx *ctx, grn_obj *table, |
739 | const char *name, unsigned int name_size); |
740 | |
741 | GRN_API grn_rc grn_column_rename(grn_ctx *ctx, grn_obj *column, |
742 | const char *name, unsigned int name_size); |
743 | |
744 | GRN_API grn_rc grn_obj_close(grn_ctx *ctx, grn_obj *obj); |
745 | GRN_API grn_rc grn_obj_reinit(grn_ctx *ctx, grn_obj *obj, grn_id domain, unsigned char flags); |
746 | GRN_API void grn_obj_unlink(grn_ctx *ctx, grn_obj *obj); |
747 | |
748 | GRN_API grn_user_data *grn_obj_user_data(grn_ctx *ctx, grn_obj *obj); |
749 | |
750 | GRN_API grn_rc grn_obj_set_finalizer(grn_ctx *ctx, grn_obj *obj, grn_proc_func *func); |
751 | |
752 | GRN_API const char *grn_obj_path(grn_ctx *ctx, grn_obj *obj); |
753 | GRN_API int grn_obj_name(grn_ctx *ctx, grn_obj *obj, char *namebuf, int buf_size); |
754 | |
755 | GRN_API int grn_column_name(grn_ctx *ctx, grn_obj *obj, char *namebuf, int buf_size); |
756 | |
757 | GRN_API grn_id grn_obj_get_range(grn_ctx *ctx, grn_obj *obj); |
758 | |
759 | #define GRN_OBJ_GET_DOMAIN(obj) \ |
760 | ((obj)->header.type == GRN_TABLE_NO_KEY ? GRN_ID_NIL : (obj)->header.domain) |
761 | |
762 | GRN_API int grn_obj_expire(grn_ctx *ctx, grn_obj *obj, int threshold); |
763 | GRN_API int grn_obj_check(grn_ctx *ctx, grn_obj *obj); |
764 | GRN_API grn_rc grn_obj_lock(grn_ctx *ctx, grn_obj *obj, grn_id id, int timeout); |
765 | GRN_API grn_rc grn_obj_unlock(grn_ctx *ctx, grn_obj *obj, grn_id id); |
766 | GRN_API grn_rc grn_obj_clear_lock(grn_ctx *ctx, grn_obj *obj); |
767 | GRN_API unsigned int grn_obj_is_locked(grn_ctx *ctx, grn_obj *obj); |
768 | GRN_API grn_rc grn_obj_flush(grn_ctx *ctx, grn_obj *obj); |
769 | GRN_API grn_rc grn_obj_flush_recursive(grn_ctx *ctx, grn_obj *obj); |
770 | GRN_API int grn_obj_defrag(grn_ctx *ctx, grn_obj *obj, int threshold); |
771 | |
772 | GRN_API grn_obj *grn_obj_db(grn_ctx *ctx, grn_obj *obj); |
773 | |
774 | GRN_API grn_id grn_obj_id(grn_ctx *ctx, grn_obj *obj); |
775 | |
776 | /* Flags for grn_fuzzy_search_optarg::flags. */ |
777 | #define GRN_TABLE_FUZZY_SEARCH_WITH_TRANSPOSITION (0x01) |
778 | |
779 | typedef struct _grn_fuzzy_search_optarg grn_fuzzy_search_optarg; |
780 | |
781 | struct _grn_fuzzy_search_optarg { |
782 | unsigned int max_distance; |
783 | unsigned int max_expansion; |
784 | unsigned int prefix_match_size; |
785 | int flags; |
786 | }; |
787 | |
788 | #define GRN_MATCH_INFO_GET_MIN_RECORD_ID (0x01) |
789 | |
790 | typedef struct _grn_match_info grn_match_info; |
791 | |
792 | struct _grn_match_info { |
793 | int flags; |
794 | grn_id min; |
795 | }; |
796 | |
797 | typedef struct _grn_search_optarg grn_search_optarg; |
798 | |
799 | struct _grn_search_optarg { |
800 | grn_operator mode; |
801 | int similarity_threshold; |
802 | int max_interval; |
803 | int *weight_vector; |
804 | int vector_size; |
805 | grn_obj *proc; |
806 | int max_size; |
807 | grn_obj *scorer; |
808 | grn_obj *scorer_args_expr; |
809 | unsigned int scorer_args_expr_offset; |
810 | grn_fuzzy_search_optarg fuzzy; |
811 | grn_match_info match_info; |
812 | }; |
813 | |
814 | GRN_API grn_rc grn_obj_search(grn_ctx *ctx, grn_obj *obj, grn_obj *query, |
815 | grn_obj *res, grn_operator op, grn_search_optarg *optarg); |
816 | |
817 | typedef grn_rc grn_selector_func(grn_ctx *ctx, grn_obj *table, grn_obj *index, |
818 | int nargs, grn_obj **args, |
819 | grn_obj *res, grn_operator op); |
820 | |
821 | GRN_API grn_rc grn_proc_set_selector(grn_ctx *ctx, grn_obj *proc, |
822 | grn_selector_func selector); |
823 | GRN_API grn_rc grn_proc_set_selector_operator(grn_ctx *ctx, |
824 | grn_obj *proc, |
825 | grn_operator selector_op); |
826 | GRN_API grn_operator grn_proc_get_selector_operator(grn_ctx *ctx, |
827 | grn_obj *proc); |
828 | |
829 | GRN_API grn_rc grn_proc_set_is_stable(grn_ctx *ctx, |
830 | grn_obj *proc, |
831 | grn_bool is_stable); |
832 | GRN_API grn_bool grn_proc_is_stable(grn_ctx *ctx, grn_obj *proc); |
833 | |
834 | /*------------------------------------------------------------- |
835 | * grn_vector |
836 | */ |
837 | |
838 | GRN_API unsigned int grn_vector_size(grn_ctx *ctx, grn_obj *vector); |
839 | |
840 | GRN_API grn_rc grn_vector_add_element(grn_ctx *ctx, grn_obj *vector, |
841 | const char *str, unsigned int str_len, |
842 | unsigned int weight, grn_id domain); |
843 | |
844 | GRN_API unsigned int grn_vector_get_element(grn_ctx *ctx, grn_obj *vector, |
845 | unsigned int offset, const char **str, |
846 | unsigned int *weight, grn_id *domain); |
847 | GRN_API unsigned int grn_vector_pop_element(grn_ctx *ctx, grn_obj *vector, |
848 | const char **str, |
849 | unsigned int *weight, |
850 | grn_id *domain); |
851 | |
852 | /*------------------------------------------------------------- |
853 | * grn_uvector |
854 | */ |
855 | |
856 | GRN_API unsigned int grn_uvector_size(grn_ctx *ctx, grn_obj *uvector); |
857 | GRN_API unsigned int grn_uvector_element_size(grn_ctx *ctx, grn_obj *uvector); |
858 | |
859 | GRN_API grn_rc grn_uvector_add_element(grn_ctx *ctx, grn_obj *vector, |
860 | grn_id id, unsigned int weight); |
861 | |
862 | GRN_API grn_id grn_uvector_get_element(grn_ctx *ctx, grn_obj *uvector, |
863 | unsigned int offset, |
864 | unsigned int *weight); |
865 | |
866 | /*------------------------------------------------------------- |
867 | * API for hook |
868 | */ |
869 | |
870 | GRN_API int grn_proc_call_next(grn_ctx *ctx, grn_obj *exec_info, grn_obj *in, grn_obj *out); |
871 | GRN_API void *grn_proc_get_ctx_local_data(grn_ctx *ctx, grn_obj *exec_info); |
872 | GRN_API void *grn_proc_get_hook_local_data(grn_ctx *ctx, grn_obj *exec_info); |
873 | |
874 | typedef enum { |
875 | GRN_HOOK_SET = 0, |
876 | GRN_HOOK_GET, |
877 | GRN_HOOK_INSERT, |
878 | GRN_HOOK_DELETE, |
879 | GRN_HOOK_SELECT |
880 | } grn_hook_entry; |
881 | |
882 | GRN_API grn_rc grn_obj_add_hook(grn_ctx *ctx, grn_obj *obj, grn_hook_entry entry, |
883 | int offset, grn_obj *proc, grn_obj *data); |
884 | GRN_API int grn_obj_get_nhooks(grn_ctx *ctx, grn_obj *obj, grn_hook_entry entry); |
885 | GRN_API grn_obj *grn_obj_get_hook(grn_ctx *ctx, grn_obj *obj, grn_hook_entry entry, |
886 | int offset, grn_obj *data); |
887 | GRN_API grn_rc grn_obj_delete_hook(grn_ctx *ctx, grn_obj *obj, grn_hook_entry entry, int offset); |
888 | |
889 | GRN_API grn_obj *grn_obj_open(grn_ctx *ctx, unsigned char type, grn_obj_flags flags, grn_id domain); |
890 | |
891 | /* Deprecated since 5.0.1. Use grn_column_find_index_data() instead. */ |
892 | GRN_API int grn_column_index(grn_ctx *ctx, grn_obj *column, grn_operator op, |
893 | grn_obj **indexbuf, int buf_size, int *section); |
894 | |
895 | /* @since 5.0.1. */ |
896 | typedef struct _grn_index_datum { |
897 | grn_obj *index; |
898 | unsigned int section; |
899 | } grn_index_datum; |
900 | |
901 | /* @since 5.0.1. */ |
902 | GRN_API unsigned int grn_column_find_index_data(grn_ctx *ctx, grn_obj *column, |
903 | grn_operator op, |
904 | grn_index_datum *index_data, |
905 | unsigned int n_index_data); |
906 | /* @since 5.1.2. */ |
907 | GRN_API uint32_t grn_column_get_all_index_data(grn_ctx *ctx, |
908 | grn_obj *column, |
909 | grn_index_datum *index_data, |
910 | uint32_t n_index_data); |
911 | |
912 | GRN_API grn_rc grn_obj_delete_by_id(grn_ctx *ctx, grn_obj *db, grn_id id, grn_bool removep); |
913 | GRN_API grn_rc grn_obj_path_by_id(grn_ctx *ctx, grn_obj *db, grn_id id, char *buffer); |
914 | |
915 | /* geo */ |
916 | |
917 | typedef struct { |
918 | int latitude; |
919 | int longitude; |
920 | } grn_geo_point; |
921 | |
922 | GRN_API grn_rc grn_geo_select_in_rectangle(grn_ctx *ctx, |
923 | grn_obj *index, |
924 | grn_obj *top_left_point, |
925 | grn_obj *bottom_right_point, |
926 | grn_obj *res, |
927 | grn_operator op); |
928 | GRN_API unsigned int grn_geo_estimate_size_in_rectangle(grn_ctx *ctx, |
929 | grn_obj *index, |
930 | grn_obj *top_left_point, |
931 | grn_obj *bottom_right_point); |
932 | /* Deprecated since 4.0.8. Use grn_geo_estimate_size_in_rectangle() instead. */ |
933 | GRN_API int grn_geo_estimate_in_rectangle(grn_ctx *ctx, |
934 | grn_obj *index, |
935 | grn_obj *top_left_point, |
936 | grn_obj *bottom_right_point); |
937 | GRN_API grn_obj *grn_geo_cursor_open_in_rectangle(grn_ctx *ctx, |
938 | grn_obj *index, |
939 | grn_obj *top_left_point, |
940 | grn_obj *bottom_right_point, |
941 | int offset, |
942 | int limit); |
943 | GRN_API grn_posting *grn_geo_cursor_next(grn_ctx *ctx, grn_obj *cursor); |
944 | |
945 | |
946 | /* query & snippet */ |
947 | |
948 | #ifndef GRN_QUERY_AND |
949 | #define GRN_QUERY_AND '+' |
950 | #endif /* GRN_QUERY_AND */ |
951 | #ifndef GRN_QUERY_AND_NOT |
952 | # ifdef GRN_QUERY_BUT |
953 | /* Deprecated. Just for backward compatibility. */ |
954 | # define GRN_QUERY_AND_NOT GRN_QUERY_BUT |
955 | # else |
956 | # define GRN_QUERY_AND_NOT '-' |
957 | # endif /* GRN_QUERY_BUT */ |
958 | #endif /* GRN_QUERY_AND_NOT */ |
959 | #ifndef GRN_QUERY_ADJ_INC |
960 | #define GRN_QUERY_ADJ_INC '>' |
961 | #endif /* GRN_QUERY_ADJ_POS2 */ |
962 | #ifndef GRN_QUERY_ADJ_DEC |
963 | #define GRN_QUERY_ADJ_DEC '<' |
964 | #endif /* GRN_QUERY_ADJ_POS1 */ |
965 | #ifndef GRN_QUERY_ADJ_NEG |
966 | #define GRN_QUERY_ADJ_NEG '~' |
967 | #endif /* GRN_QUERY_ADJ_NEG */ |
968 | #ifndef GRN_QUERY_PREFIX |
969 | #define GRN_QUERY_PREFIX '*' |
970 | #endif /* GRN_QUERY_PREFIX */ |
971 | #ifndef GRN_QUERY_PARENL |
972 | #define GRN_QUERY_PARENL '(' |
973 | #endif /* GRN_QUERY_PARENL */ |
974 | #ifndef GRN_QUERY_PARENR |
975 | #define GRN_QUERY_PARENR ')' |
976 | #endif /* GRN_QUERY_PARENR */ |
977 | #ifndef GRN_QUERY_QUOTEL |
978 | #define GRN_QUERY_QUOTEL '"' |
979 | #endif /* GRN_QUERY_QUOTEL */ |
980 | #ifndef GRN_QUERY_QUOTER |
981 | #define GRN_QUERY_QUOTER '"' |
982 | #endif /* GRN_QUERY_QUOTER */ |
983 | #ifndef GRN_QUERY_ESCAPE |
984 | #define GRN_QUERY_ESCAPE '\\' |
985 | #endif /* GRN_QUERY_ESCAPE */ |
986 | #ifndef GRN_QUERY_COLUMN |
987 | #define GRN_QUERY_COLUMN ':' |
988 | #endif /* GRN_QUERY_COLUMN */ |
989 | |
990 | typedef struct _grn_snip_mapping grn_snip_mapping; |
991 | |
992 | struct _grn_snip_mapping { |
993 | void *dummy; |
994 | }; |
995 | |
996 | #define GRN_SNIP_NORMALIZE (0x01<<0) |
997 | #define GRN_SNIP_COPY_TAG (0x01<<1) |
998 | #define GRN_SNIP_SKIP_LEADING_SPACES (0x01<<2) |
999 | |
1000 | #define GRN_SNIP_MAPPING_HTML_ESCAPE ((grn_snip_mapping *)-1) |
1001 | |
1002 | GRN_API grn_obj *grn_snip_open(grn_ctx *ctx, int flags, unsigned int width, |
1003 | unsigned int max_results, |
1004 | const char *defaultopentag, unsigned int defaultopentag_len, |
1005 | const char *defaultclosetag, unsigned int defaultclosetag_len, |
1006 | grn_snip_mapping *mapping); |
1007 | GRN_API grn_rc grn_snip_add_cond(grn_ctx *ctx, grn_obj *snip, |
1008 | const char *keyword, unsigned int keyword_len, |
1009 | const char *opentag, unsigned int opentag_len, |
1010 | const char *closetag, unsigned int closetag_len); |
1011 | GRN_API grn_rc grn_snip_set_normalizer(grn_ctx *ctx, grn_obj *snip, |
1012 | grn_obj *normalizer); |
1013 | GRN_API grn_obj *grn_snip_get_normalizer(grn_ctx *ctx, grn_obj *snip); |
1014 | GRN_API grn_rc grn_snip_exec(grn_ctx *ctx, grn_obj *snip, |
1015 | const char *string, unsigned int string_len, |
1016 | unsigned int *nresults, unsigned int *max_tagged_len); |
1017 | GRN_API grn_rc grn_snip_get_result(grn_ctx *ctx, grn_obj *snip, const unsigned int index, |
1018 | char *result, unsigned int *result_len); |
1019 | |
1020 | /* log */ |
1021 | |
1022 | #define GRN_LOG_TIME (0x01<<0) |
1023 | #define GRN_LOG_TITLE (0x01<<1) |
1024 | #define GRN_LOG_MESSAGE (0x01<<2) |
1025 | #define GRN_LOG_LOCATION (0x01<<3) |
1026 | #define GRN_LOG_PID (0x01<<4) |
1027 | |
1028 | /* Deprecated since 2.1.2. Use grn_logger instead. */ |
1029 | typedef struct _grn_logger_info grn_logger_info; |
1030 | |
1031 | /* Deprecated since 2.1.2. Use grn_logger instead. */ |
1032 | struct _grn_logger_info { |
1033 | grn_log_level max_level; |
1034 | int flags; |
1035 | void (*func)(int, const char *, const char *, const char *, const char *, void *); |
1036 | void *func_arg; |
1037 | }; |
1038 | |
1039 | /* Deprecated since 2.1.2. Use grn_logger_set() instead. */ |
1040 | GRN_API grn_rc grn_logger_info_set(grn_ctx *ctx, const grn_logger_info *info); |
1041 | |
1042 | typedef struct _grn_logger grn_logger; |
1043 | |
1044 | struct _grn_logger { |
1045 | grn_log_level max_level; |
1046 | int flags; |
1047 | void *user_data; |
1048 | void (*log)(grn_ctx *ctx, grn_log_level level, |
1049 | const char *timestamp, const char *title, const char *message, |
1050 | const char *location, void *user_data); |
1051 | void (*reopen)(grn_ctx *ctx, void *user_data); |
1052 | void (*fin)(grn_ctx *ctx, void *user_data); |
1053 | }; |
1054 | |
1055 | GRN_API grn_rc grn_logger_set(grn_ctx *ctx, const grn_logger *logger); |
1056 | |
1057 | GRN_API void grn_logger_set_max_level(grn_ctx *ctx, grn_log_level max_level); |
1058 | GRN_API grn_log_level grn_logger_get_max_level(grn_ctx *ctx); |
1059 | |
1060 | #ifdef __GNUC__ |
1061 | # define GRN_ATTRIBUTE_PRINTF(fmt_pos) \ |
1062 | __attribute__ ((format(printf, fmt_pos, fmt_pos + 1))) |
1063 | #else |
1064 | # define GRN_ATTRIBUTE_PRINTF(fmt_pos) |
1065 | #endif /* __GNUC__ */ |
1066 | |
1067 | #if defined(__clang__) |
1068 | # if __has_attribute(__alloc_size__) |
1069 | # define HAVE_ALLOC_SIZE_ATTRIBUTE |
1070 | # endif /* __has_attribute(__alloc_size__) */ |
1071 | #elif defined(__GNUC__) && \ |
1072 | ((__GNUC__ >= 5) || (__GNUC__ > 4 && __GNUC_MINOR__ >= 3)) |
1073 | # define HAVE_ALLOC_SIZE_ATTRIBUTE |
1074 | #endif /* __clang__ */ |
1075 | |
1076 | #ifdef HAVE_ALLOC_SIZE_ATTRIBUTE |
1077 | # define GRN_ATTRIBUTE_ALLOC_SIZE(size) \ |
1078 | __attribute__ ((alloc_size(size))) |
1079 | # define GRN_ATTRIBUTE_ALLOC_SIZE_N(n, size) \ |
1080 | __attribute__ ((alloc_size(n, size))) |
1081 | #else |
1082 | # define GRN_ATTRIBUTE_ALLOC_SIZE(size) |
1083 | # define GRN_ATTRIBUTE_ALLOC_SIZE_N(n, size) |
1084 | #endif /* HAVE_ALLOC_SIZE_ATTRIBUTE */ |
1085 | |
1086 | GRN_API void grn_logger_put(grn_ctx *ctx, grn_log_level level, |
1087 | const char *file, int line, const char *func, const char *fmt, ...) GRN_ATTRIBUTE_PRINTF(6); |
1088 | GRN_API void grn_logger_putv(grn_ctx *ctx, |
1089 | grn_log_level level, |
1090 | const char *file, |
1091 | int line, |
1092 | const char *func, |
1093 | const char *fmt, |
1094 | va_list ap); |
1095 | GRN_API void grn_logger_reopen(grn_ctx *ctx); |
1096 | |
1097 | GRN_API grn_bool grn_logger_pass(grn_ctx *ctx, grn_log_level level); |
1098 | |
1099 | #ifndef GRN_LOG_DEFAULT_LEVEL |
1100 | # define GRN_LOG_DEFAULT_LEVEL GRN_LOG_NOTICE |
1101 | #endif /* GRN_LOG_DEFAULT_LEVEL */ |
1102 | |
1103 | GRN_API void grn_default_logger_set_max_level(grn_log_level level); |
1104 | GRN_API grn_log_level grn_default_logger_get_max_level(void); |
1105 | GRN_API void grn_default_logger_set_flags(int flags); |
1106 | GRN_API int grn_default_logger_get_flags(void); |
1107 | GRN_API void grn_default_logger_set_path(const char *path); |
1108 | GRN_API const char *grn_default_logger_get_path(void); |
1109 | GRN_API void grn_default_logger_set_rotate_threshold_size(off_t threshold); |
1110 | GRN_API off_t grn_default_logger_get_rotate_threshold_size(void); |
1111 | |
1112 | #define GRN_LOG(ctx,level,...) do {\ |
1113 | if (grn_logger_pass(ctx, level)) {\ |
1114 | grn_logger_put(ctx, (level), __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__); \ |
1115 | }\ |
1116 | } while (0) |
1117 | |
1118 | typedef struct _grn_query_logger grn_query_logger; |
1119 | |
1120 | struct _grn_query_logger { |
1121 | unsigned int flags; |
1122 | void *user_data; |
1123 | void (*log)(grn_ctx *ctx, unsigned int flag, |
1124 | const char *timestamp, const char *info, const char *message, |
1125 | void *user_data); |
1126 | void (*reopen)(grn_ctx *ctx, void *user_data); |
1127 | void (*fin)(grn_ctx *ctx, void *user_data); |
1128 | }; |
1129 | |
1130 | GRN_API grn_bool grn_query_log_flags_parse(const char *string, |
1131 | int string_size, |
1132 | unsigned int *flags); |
1133 | |
1134 | GRN_API grn_rc grn_query_logger_set(grn_ctx *ctx, const grn_query_logger *logger); |
1135 | GRN_API void grn_query_logger_set_flags(grn_ctx *ctx, unsigned int flags); |
1136 | GRN_API void grn_query_logger_add_flags(grn_ctx *ctx, unsigned int flags); |
1137 | GRN_API void grn_query_logger_remove_flags(grn_ctx *ctx, unsigned int flags); |
1138 | GRN_API unsigned int grn_query_logger_get_flags(grn_ctx *ctx); |
1139 | |
1140 | GRN_API void grn_query_logger_put(grn_ctx *ctx, unsigned int flag, |
1141 | const char *mark, |
1142 | const char *format, ...) GRN_ATTRIBUTE_PRINTF(4); |
1143 | GRN_API void grn_query_logger_reopen(grn_ctx *ctx); |
1144 | |
1145 | GRN_API grn_bool grn_query_logger_pass(grn_ctx *ctx, unsigned int flag); |
1146 | |
1147 | GRN_API void grn_default_query_logger_set_flags(unsigned int flags); |
1148 | GRN_API unsigned int grn_default_query_logger_get_flags(void); |
1149 | GRN_API void grn_default_query_logger_set_path(const char *path); |
1150 | GRN_API const char *grn_default_query_logger_get_path(void); |
1151 | GRN_API void grn_default_query_logger_set_rotate_threshold_size(off_t threshold); |
1152 | GRN_API off_t grn_default_query_logger_get_rotate_threshold_size(void); |
1153 | |
1154 | #define GRN_QUERY_LOG(ctx, flag, mark, format, ...) do {\ |
1155 | if (grn_query_logger_pass(ctx, flag)) {\ |
1156 | grn_query_logger_put(ctx, (flag), (mark), format, __VA_ARGS__);\ |
1157 | }\ |
1158 | } while (0) |
1159 | |
1160 | /* grn_bulk */ |
1161 | |
1162 | #define GRN_BULK_BUFSIZE (sizeof(grn_obj) - sizeof(grn_obj_header)) |
1163 | /* This assumes that GRN_BULK_BUFSIZE is less than 32 (= 0x20). */ |
1164 | #define GRN_BULK_BUFSIZE_MAX 0x1f |
1165 | #define GRN_BULK_SIZE_IN_FLAGS(flags) ((flags) & GRN_BULK_BUFSIZE_MAX) |
1166 | #define GRN_BULK_OUTP(bulk) ((bulk)->header.impl_flags & GRN_OBJ_OUTPLACE) |
1167 | #define GRN_BULK_REWIND(bulk) do {\ |
1168 | if ((bulk)->header.type == GRN_VECTOR) {\ |
1169 | grn_obj *_body = (bulk)->u.v.body;\ |
1170 | if (_body) {\ |
1171 | if (GRN_BULK_OUTP(_body)) {\ |
1172 | (_body)->u.b.curr = (_body)->u.b.head;\ |
1173 | } else {\ |
1174 | (_body)->header.flags &= ~GRN_BULK_BUFSIZE_MAX;\ |
1175 | }\ |
1176 | }\ |
1177 | (bulk)->u.v.n_sections = 0;\ |
1178 | } else {\ |
1179 | if (GRN_BULK_OUTP(bulk)) {\ |
1180 | (bulk)->u.b.curr = (bulk)->u.b.head;\ |
1181 | } else {\ |
1182 | (bulk)->header.flags &= ~GRN_BULK_BUFSIZE_MAX;\ |
1183 | }\ |
1184 | }\ |
1185 | } while (0) |
1186 | #define GRN_BULK_INCR_LEN(bulk,len) do {\ |
1187 | if (GRN_BULK_OUTP(bulk)) {\ |
1188 | (bulk)->u.b.curr += (len);\ |
1189 | } else {\ |
1190 | (bulk)->header.flags += (grn_obj_flags)(len);\ |
1191 | }\ |
1192 | } while (0) |
1193 | #define GRN_BULK_WSIZE(bulk) \ |
1194 | (GRN_BULK_OUTP(bulk)\ |
1195 | ? ((bulk)->u.b.tail - (bulk)->u.b.head)\ |
1196 | : GRN_BULK_BUFSIZE) |
1197 | #define GRN_BULK_REST(bulk) \ |
1198 | (GRN_BULK_OUTP(bulk)\ |
1199 | ? ((bulk)->u.b.tail - (bulk)->u.b.curr)\ |
1200 | : GRN_BULK_BUFSIZE - GRN_BULK_SIZE_IN_FLAGS((bulk)->header.flags)) |
1201 | #define GRN_BULK_VSIZE(bulk) \ |
1202 | (GRN_BULK_OUTP(bulk)\ |
1203 | ? ((bulk)->u.b.curr - (bulk)->u.b.head)\ |
1204 | : GRN_BULK_SIZE_IN_FLAGS((bulk)->header.flags)) |
1205 | #define GRN_BULK_EMPTYP(bulk) \ |
1206 | (GRN_BULK_OUTP(bulk)\ |
1207 | ? ((bulk)->u.b.curr == (bulk)->u.b.head)\ |
1208 | : !(GRN_BULK_SIZE_IN_FLAGS((bulk)->header.flags))) |
1209 | #define GRN_BULK_HEAD(bulk) \ |
1210 | (GRN_BULK_OUTP(bulk)\ |
1211 | ? ((bulk)->u.b.head)\ |
1212 | : (char *)&((bulk)->u.b.head)) |
1213 | #define GRN_BULK_CURR(bulk) \ |
1214 | (GRN_BULK_OUTP(bulk)\ |
1215 | ? ((bulk)->u.b.curr)\ |
1216 | : (char *)&((bulk)->u.b.head) + GRN_BULK_SIZE_IN_FLAGS((bulk)->header.flags)) |
1217 | #define GRN_BULK_TAIL(bulk) \ |
1218 | (GRN_BULK_OUTP(bulk)\ |
1219 | ? ((bulk)->u.b.tail)\ |
1220 | : (char *)&((bulk)[1])) |
1221 | |
1222 | GRN_API grn_rc grn_bulk_reinit(grn_ctx *ctx, grn_obj *bulk, unsigned int size); |
1223 | GRN_API grn_rc grn_bulk_resize(grn_ctx *ctx, grn_obj *bulk, unsigned int newsize); |
1224 | GRN_API grn_rc grn_bulk_write(grn_ctx *ctx, grn_obj *bulk, |
1225 | const char *str, unsigned int len); |
1226 | GRN_API grn_rc grn_bulk_write_from(grn_ctx *ctx, grn_obj *bulk, |
1227 | const char *str, unsigned int from, unsigned int len); |
1228 | GRN_API grn_rc grn_bulk_reserve(grn_ctx *ctx, grn_obj *bulk, unsigned int len); |
1229 | GRN_API grn_rc grn_bulk_space(grn_ctx *ctx, grn_obj *bulk, unsigned int len); |
1230 | GRN_API grn_rc grn_bulk_truncate(grn_ctx *ctx, grn_obj *bulk, unsigned int len); |
1231 | GRN_API grn_rc grn_bulk_fin(grn_ctx *ctx, grn_obj *bulk); |
1232 | |
1233 | /* grn_text */ |
1234 | |
1235 | GRN_API grn_rc grn_text_itoa(grn_ctx *ctx, grn_obj *bulk, int i); |
1236 | GRN_API grn_rc grn_text_itoa_padded(grn_ctx *ctx, grn_obj *bulk, int i, char ch, unsigned int len); |
1237 | GRN_API grn_rc grn_text_lltoa(grn_ctx *ctx, grn_obj *bulk, long long int i); |
1238 | GRN_API grn_rc grn_text_ftoa(grn_ctx *ctx, grn_obj *bulk, double d); |
1239 | GRN_API grn_rc grn_text_itoh(grn_ctx *ctx, grn_obj *bulk, int i, unsigned int len); |
1240 | GRN_API grn_rc grn_text_itob(grn_ctx *ctx, grn_obj *bulk, grn_id id); |
1241 | GRN_API grn_rc grn_text_lltob32h(grn_ctx *ctx, grn_obj *bulk, long long int i); |
1242 | GRN_API grn_rc grn_text_benc(grn_ctx *ctx, grn_obj *bulk, unsigned int v); |
1243 | GRN_API grn_rc grn_text_esc(grn_ctx *ctx, grn_obj *bulk, const char *s, unsigned int len); |
1244 | GRN_API grn_rc grn_text_urlenc(grn_ctx *ctx, grn_obj *buf, |
1245 | const char *str, unsigned int len); |
1246 | GRN_API const char *grn_text_urldec(grn_ctx *ctx, grn_obj *buf, |
1247 | const char *s, const char *e, char d); |
1248 | GRN_API grn_rc grn_text_escape_xml(grn_ctx *ctx, grn_obj *buf, |
1249 | const char *s, unsigned int len); |
1250 | GRN_API grn_rc grn_text_time2rfc1123(grn_ctx *ctx, grn_obj *bulk, int sec); |
1251 | GRN_API grn_rc grn_text_printf(grn_ctx *ctx, grn_obj *bulk, |
1252 | const char *format, ...) GRN_ATTRIBUTE_PRINTF(3); |
1253 | GRN_API grn_rc grn_text_vprintf(grn_ctx *ctx, grn_obj *bulk, |
1254 | const char *format, va_list args); |
1255 | |
1256 | GRN_API void grn_ctx_recv_handler_set(grn_ctx *, |
1257 | void (*func)(grn_ctx *, int, void *), |
1258 | void *func_arg); |
1259 | |
1260 | /* various values exchanged via grn_obj */ |
1261 | |
1262 | #define GRN_OBJ_DO_SHALLOW_COPY (GRN_OBJ_REFER|GRN_OBJ_OUTPLACE) |
1263 | #define GRN_OBJ_VECTOR (0x01<<7) |
1264 | |
1265 | #define GRN_OBJ_MUTABLE(obj) ((obj) && (obj)->header.type <= GRN_VECTOR) |
1266 | |
1267 | #define GRN_VALUE_FIX_SIZE_INIT(obj,flags,domain)\ |
1268 | GRN_OBJ_INIT((obj), ((flags) & GRN_OBJ_VECTOR) ? GRN_UVECTOR : GRN_BULK,\ |
1269 | ((flags) & GRN_OBJ_DO_SHALLOW_COPY), (domain)) |
1270 | #define GRN_VALUE_VAR_SIZE_INIT(obj,flags,domain)\ |
1271 | GRN_OBJ_INIT((obj), ((flags) & GRN_OBJ_VECTOR) ? GRN_VECTOR : GRN_BULK,\ |
1272 | ((flags) & GRN_OBJ_DO_SHALLOW_COPY), (domain)) |
1273 | |
1274 | #define GRN_VOID_INIT(obj) GRN_OBJ_INIT((obj), GRN_VOID, 0, GRN_DB_VOID) |
1275 | #define GRN_TEXT_INIT(obj,flags) \ |
1276 | GRN_VALUE_VAR_SIZE_INIT(obj, flags, GRN_DB_TEXT) |
1277 | #define GRN_SHORT_TEXT_INIT(obj,flags) \ |
1278 | GRN_VALUE_VAR_SIZE_INIT(obj, flags, GRN_DB_SHORT_TEXT) |
1279 | #define GRN_LONG_TEXT_INIT(obj,flags) \ |
1280 | GRN_VALUE_VAR_SIZE_INIT(obj, flags, GRN_DB_LONG_TEXT) |
1281 | #define GRN_TEXT_SET_REF(obj,str,len) do {\ |
1282 | (obj)->u.b.head = (char *)(str);\ |
1283 | (obj)->u.b.curr = (char *)(str) + (len);\ |
1284 | } while (0) |
1285 | #define GRN_TEXT_SET(ctx,obj,str,len) do {\ |
1286 | if ((obj)->header.impl_flags & GRN_OBJ_REFER) {\ |
1287 | GRN_TEXT_SET_REF((obj), (str), (len));\ |
1288 | } else {\ |
1289 | grn_bulk_write_from((ctx), (obj), (const char *)(str), 0, (unsigned int)(len));\ |
1290 | }\ |
1291 | } while (0) |
1292 | #define GRN_TEXT_PUT(ctx,obj,str,len) \ |
1293 | grn_bulk_write((ctx), (obj), (const char *)(str), (unsigned int)(len)) |
1294 | #define GRN_TEXT_PUTC(ctx,obj,c) do {\ |
1295 | char _c = (c); grn_bulk_write((ctx), (obj), &_c, 1);\ |
1296 | } while (0) |
1297 | |
1298 | #define GRN_TEXT_PUTS(ctx,obj,str) GRN_TEXT_PUT((ctx), (obj), (str), strlen(str)) |
1299 | #define GRN_TEXT_SETS(ctx,obj,str) GRN_TEXT_SET((ctx), (obj), (str), strlen(str)) |
1300 | #define GRN_TEXT_VALUE(obj) GRN_BULK_HEAD(obj) |
1301 | #define GRN_TEXT_LEN(obj) GRN_BULK_VSIZE(obj) |
1302 | |
1303 | #define GRN_TEXT_EQUAL_CSTRING(bulk, string)\ |
1304 | (GRN_TEXT_LEN(bulk) == strlen(string) &&\ |
1305 | memcmp(GRN_TEXT_VALUE(bulk), string, GRN_TEXT_LEN(bulk)) == 0) |
1306 | |
1307 | #define GRN_BOOL_INIT(obj,flags) \ |
1308 | GRN_VALUE_FIX_SIZE_INIT(obj, flags, GRN_DB_BOOL) |
1309 | #define GRN_INT8_INIT(obj,flags) \ |
1310 | GRN_VALUE_FIX_SIZE_INIT(obj, flags, GRN_DB_INT8) |
1311 | #define GRN_UINT8_INIT(obj,flags) \ |
1312 | GRN_VALUE_FIX_SIZE_INIT(obj, flags, GRN_DB_UINT8) |
1313 | #define GRN_INT16_INIT(obj,flags) \ |
1314 | GRN_VALUE_FIX_SIZE_INIT(obj, flags, GRN_DB_INT16) |
1315 | #define GRN_UINT16_INIT(obj,flags) \ |
1316 | GRN_VALUE_FIX_SIZE_INIT(obj, flags, GRN_DB_UINT16) |
1317 | #define GRN_INT32_INIT(obj,flags) \ |
1318 | GRN_VALUE_FIX_SIZE_INIT(obj, flags, GRN_DB_INT32) |
1319 | #define GRN_UINT32_INIT(obj,flags) \ |
1320 | GRN_VALUE_FIX_SIZE_INIT(obj, flags, GRN_DB_UINT32) |
1321 | #define GRN_INT64_INIT(obj,flags) \ |
1322 | GRN_VALUE_FIX_SIZE_INIT(obj, flags, GRN_DB_INT64) |
1323 | #define GRN_UINT64_INIT(obj,flags) \ |
1324 | GRN_VALUE_FIX_SIZE_INIT(obj, flags, GRN_DB_UINT64) |
1325 | #define GRN_FLOAT_INIT(obj,flags) \ |
1326 | GRN_VALUE_FIX_SIZE_INIT(obj, flags, GRN_DB_FLOAT) |
1327 | #define GRN_TIME_INIT(obj,flags) \ |
1328 | GRN_VALUE_FIX_SIZE_INIT(obj, flags, GRN_DB_TIME) |
1329 | #define GRN_RECORD_INIT GRN_VALUE_FIX_SIZE_INIT |
1330 | #define GRN_PTR_INIT(obj,flags,domain)\ |
1331 | GRN_OBJ_INIT((obj), ((flags) & GRN_OBJ_VECTOR) ? GRN_PVECTOR : GRN_PTR,\ |
1332 | ((flags) & (GRN_OBJ_DO_SHALLOW_COPY | GRN_OBJ_OWN)),\ |
1333 | (domain)) |
1334 | #define GRN_TOKYO_GEO_POINT_INIT(obj,flags) \ |
1335 | GRN_VALUE_FIX_SIZE_INIT(obj, flags, GRN_DB_TOKYO_GEO_POINT) |
1336 | #define GRN_WGS84_GEO_POINT_INIT(obj,flags) \ |
1337 | GRN_VALUE_FIX_SIZE_INIT(obj, flags, GRN_DB_WGS84_GEO_POINT) |
1338 | |
1339 | #define GRN_BOOL_SET(ctx,obj,val) do {\ |
1340 | unsigned char _val = (unsigned char)(val);\ |
1341 | grn_bulk_write_from((ctx), (obj), (char *)&_val, 0, sizeof(unsigned char));\ |
1342 | } while (0) |
1343 | #define GRN_INT8_SET(ctx,obj,val) do {\ |
1344 | signed char _val = (signed char)(val);\ |
1345 | grn_bulk_write_from((ctx), (obj), (char *)&_val, 0, sizeof(signed char));\ |
1346 | } while (0) |
1347 | #define GRN_UINT8_SET(ctx,obj,val) do {\ |
1348 | unsigned char _val = (unsigned char)(val);\ |
1349 | grn_bulk_write_from((ctx), (obj), (char *)&_val, 0, sizeof(unsigned char));\ |
1350 | } while (0) |
1351 | #define GRN_INT16_SET(ctx,obj,val) do {\ |
1352 | signed short _val = (signed short)(val);\ |
1353 | grn_bulk_write_from((ctx), (obj), (char *)&_val, 0, sizeof(signed short));\ |
1354 | } while (0) |
1355 | #define GRN_UINT16_SET(ctx,obj,val) do {\ |
1356 | unsigned short _val = (unsigned short)(val);\ |
1357 | grn_bulk_write_from((ctx), (obj), (char *)&_val, 0, sizeof(unsigned short));\ |
1358 | } while (0) |
1359 | #define GRN_INT32_SET(ctx,obj,val) do {\ |
1360 | int _val = (int)(val);\ |
1361 | grn_bulk_write_from((ctx), (obj), (char *)&_val, 0, sizeof(int));\ |
1362 | } while (0) |
1363 | #define GRN_UINT32_SET(ctx,obj,val) do {\ |
1364 | unsigned int _val = (unsigned int)(val);\ |
1365 | grn_bulk_write_from((ctx), (obj), (char *)&_val, 0, sizeof(unsigned int));\ |
1366 | } while (0) |
1367 | #define GRN_INT64_SET(ctx,obj,val) do {\ |
1368 | long long int _val = (long long int)(val);\ |
1369 | grn_bulk_write_from((ctx), (obj), (char *)&_val, 0, sizeof(long long int));\ |
1370 | } while (0) |
1371 | #define GRN_UINT64_SET(ctx,obj,val) do {\ |
1372 | long long unsigned int _val = (long long unsigned int)(val);\ |
1373 | grn_bulk_write_from((ctx), (obj), (char *)&_val, 0, sizeof(long long unsigned int));\ |
1374 | } while (0) |
1375 | #define GRN_FLOAT_SET(ctx,obj,val) do {\ |
1376 | double _val = (double)(val);\ |
1377 | grn_bulk_write_from((ctx), (obj), (char *)&_val, 0, sizeof(double));\ |
1378 | } while (0) |
1379 | #define GRN_TIME_SET GRN_INT64_SET |
1380 | #define GRN_RECORD_SET(ctx,obj,val) do {\ |
1381 | grn_id _val = (grn_id)(val);\ |
1382 | grn_bulk_write_from((ctx), (obj), (char *)&_val, 0, sizeof(grn_id));\ |
1383 | } while (0) |
1384 | #define GRN_PTR_SET(ctx,obj,val) do {\ |
1385 | grn_obj *_val = (grn_obj *)(val);\ |
1386 | grn_bulk_write_from((ctx), (obj), (char *)&_val, 0, sizeof(grn_obj *));\ |
1387 | } while (0) |
1388 | |
1389 | #define GRN_GEO_DEGREE2MSEC(degree)\ |
1390 | ((int)((degree) * 3600 * 1000 + ((degree) > 0 ? 0.5 : -0.5))) |
1391 | #define GRN_GEO_MSEC2DEGREE(msec)\ |
1392 | ((((int)(msec)) / 3600.0) * 0.001) |
1393 | |
1394 | #define GRN_GEO_POINT_SET(ctx,obj,_latitude,_longitude) do {\ |
1395 | grn_geo_point _val;\ |
1396 | _val.latitude = (int)(_latitude);\ |
1397 | _val.longitude = (int)(_longitude);\ |
1398 | grn_bulk_write_from((ctx), (obj), (char *)&_val, 0, sizeof(grn_geo_point));\ |
1399 | } while (0) |
1400 | |
1401 | #define GRN_BOOL_SET_AT(ctx,obj,offset,val) do {\ |
1402 | unsigned char _val = (unsigned char)(val);\ |
1403 | grn_bulk_write_from((ctx), (obj), (char *)&_val,\ |
1404 | (offset), sizeof(unsigned char));\ |
1405 | } while (0) |
1406 | #define GRN_INT8_SET_AT(ctx,obj,offset,val) do {\ |
1407 | signed char _val = (signed char)(val);\ |
1408 | grn_bulk_write_from((ctx), (obj), (char *)&_val,\ |
1409 | (offset) * sizeof(signed char), sizeof(signed char));\ |
1410 | } while (0) |
1411 | #define GRN_UINT8_SET_AT(ctx,obj,offset,val) do { \ |
1412 | unsigned char _val = (unsigned char)(val);\ |
1413 | grn_bulk_write_from((ctx), (obj), (char *)&_val,\ |
1414 | (offset) * sizeof(unsigned char), sizeof(unsigned char));\ |
1415 | } while (0) |
1416 | #define GRN_INT16_SET_AT(ctx,obj,offset,val) do {\ |
1417 | signed short _val = (signed short)(val);\ |
1418 | grn_bulk_write_from((ctx), (obj), (char *)&_val,\ |
1419 | (offset) * sizeof(signed short), sizeof(signed short));\ |
1420 | } while (0) |
1421 | #define GRN_UINT16_SET_AT(ctx,obj,offset,val) do { \ |
1422 | unsigned short _val = (unsigned short)(val);\ |
1423 | grn_bulk_write_from((ctx), (obj), (char *)&_val,\ |
1424 | (offset) * sizeof(unsigned short), sizeof(unsigned short));\ |
1425 | } while (0) |
1426 | #define GRN_INT32_SET_AT(ctx,obj,offset,val) do {\ |
1427 | int _val = (int)(val);\ |
1428 | grn_bulk_write_from((ctx), (obj), (char *)&_val,\ |
1429 | (offset) * sizeof(int), sizeof(int));\ |
1430 | } while (0) |
1431 | #define GRN_UINT32_SET_AT(ctx,obj,offset,val) do { \ |
1432 | unsigned int _val = (unsigned int)(val);\ |
1433 | grn_bulk_write_from((ctx), (obj), (char *)&_val,\ |
1434 | (offset) * sizeof(unsigned int), sizeof(unsigned int));\ |
1435 | } while (0) |
1436 | #define GRN_INT64_SET_AT(ctx,obj,offset,val) do {\ |
1437 | long long int _val = (long long int)(val);\ |
1438 | grn_bulk_write_from((ctx), (obj), (char *)&_val,\ |
1439 | (offset) * sizeof(long long int), sizeof(long long int));\ |
1440 | } while (0) |
1441 | #define GRN_UINT64_SET_AT(ctx,obj,offset,val) do {\ |
1442 | long long unsigned int _val = (long long unsigned int)(val);\ |
1443 | grn_bulk_write_from((ctx), (obj), (char *)&_val,\ |
1444 | (offset) * sizeof(long long unsigned int),\ |
1445 | sizeof(long long unsigned int));\ |
1446 | } while (0) |
1447 | #define GRN_FLOAT_SET_AT(ctx,obj,offset,val) do {\ |
1448 | double _val = (double)(val);\ |
1449 | grn_bulk_write_from((ctx), (obj), (char *)&_val,\ |
1450 | (offset) * sizeof(double), sizeof(double));\ |
1451 | } while (0) |
1452 | #define GRN_TIME_SET_AT GRN_INT64_SET_AT |
1453 | #define GRN_RECORD_SET_AT(ctx,obj,offset,val) do {\ |
1454 | grn_id _val = (grn_id)(val);\ |
1455 | grn_bulk_write_from((ctx), (obj), (char *)&_val,\ |
1456 | (offset) * sizeof(grn_id), sizeof(grn_id));\ |
1457 | } while (0) |
1458 | #define GRN_PTR_SET_AT(ctx,obj,offset,val) do {\ |
1459 | grn_obj *_val = (grn_obj *)(val);\ |
1460 | grn_bulk_write_from((ctx), (obj), (char *)&_val,\ |
1461 | (offset) * sizeof(grn_obj *), sizeof(grn_obj *));\ |
1462 | } while (0) |
1463 | |
1464 | #define GRN_BOOL_VALUE(obj) (*((unsigned char *)GRN_BULK_HEAD(obj))) |
1465 | #define GRN_INT8_VALUE(obj) (*((signed char *)GRN_BULK_HEAD(obj))) |
1466 | #define GRN_UINT8_VALUE(obj) (*((unsigned char *)GRN_BULK_HEAD(obj))) |
1467 | #define GRN_INT16_VALUE(obj) (*((signed short *)GRN_BULK_HEAD(obj))) |
1468 | #define GRN_UINT16_VALUE(obj) (*((unsigned short *)GRN_BULK_HEAD(obj))) |
1469 | #define GRN_INT32_VALUE(obj) (*((int *)GRN_BULK_HEAD(obj))) |
1470 | #define GRN_UINT32_VALUE(obj) (*((unsigned int *)GRN_BULK_HEAD(obj))) |
1471 | #define GRN_INT64_VALUE(obj) (*((long long int *)GRN_BULK_HEAD(obj))) |
1472 | #define GRN_UINT64_VALUE(obj) (*((long long unsigned int *)GRN_BULK_HEAD(obj))) |
1473 | #define GRN_FLOAT_VALUE(obj) (*((double *)GRN_BULK_HEAD(obj))) |
1474 | #define GRN_TIME_VALUE GRN_INT64_VALUE |
1475 | #define GRN_RECORD_VALUE(obj) (*((grn_id *)GRN_BULK_HEAD(obj))) |
1476 | #define GRN_PTR_VALUE(obj) (*((grn_obj **)GRN_BULK_HEAD(obj))) |
1477 | #define GRN_GEO_POINT_VALUE(obj,_latitude,_longitude) do {\ |
1478 | grn_geo_point *_val = (grn_geo_point *)GRN_BULK_HEAD(obj);\ |
1479 | _latitude = _val->latitude;\ |
1480 | _longitude = _val->longitude;\ |
1481 | } while (0) |
1482 | |
1483 | #define GRN_BOOL_VALUE_AT(obj,offset) (((unsigned char *)GRN_BULK_HEAD(obj))[offset]) |
1484 | #define GRN_INT8_VALUE_AT(obj,offset) (((signed char *)GRN_BULK_HEAD(obj))[offset]) |
1485 | #define GRN_UINT8_VALUE_AT(obj,offset) (((unsigned char *)GRN_BULK_HEAD(obj))[offset]) |
1486 | #define GRN_INT16_VALUE_AT(obj,offset) (((signed short *)GRN_BULK_HEAD(obj))[offset]) |
1487 | #define GRN_UINT16_VALUE_AT(obj,offset) (((unsigned short *)GRN_BULK_HEAD(obj))[offset]) |
1488 | #define GRN_INT32_VALUE_AT(obj,offset) (((int *)GRN_BULK_HEAD(obj))[offset]) |
1489 | #define GRN_UINT32_VALUE_AT(obj,offset) (((unsigned int *)GRN_BULK_HEAD(obj))[offset]) |
1490 | #define GRN_INT64_VALUE_AT(obj,offset) (((long long int *)GRN_BULK_HEAD(obj))[offset]) |
1491 | #define GRN_UINT64_VALUE_AT(obj,offset) (((long long unsigned int *)GRN_BULK_HEAD(obj))[offset]) |
1492 | #define GRN_FLOAT_VALUE_AT(obj,offset) (((double *)GRN_BULK_HEAD(obj))[offset]) |
1493 | #define GRN_TIME_VALUE_AT GRN_INT64_VALUE_AT |
1494 | #define GRN_RECORD_VALUE_AT(obj,offset) (((grn_id *)GRN_BULK_HEAD(obj))[offset]) |
1495 | #define GRN_PTR_VALUE_AT(obj,offset) (((grn_obj **)GRN_BULK_HEAD(obj))[offset]) |
1496 | |
1497 | #define GRN_BOOL_PUT(ctx,obj,val) do {\ |
1498 | unsigned char _val = (unsigned char)(val);\ |
1499 | grn_bulk_write((ctx), (obj), (char *)&_val, sizeof(unsigned char));\ |
1500 | } while (0) |
1501 | #define GRN_INT8_PUT(ctx,obj,val) do {\ |
1502 | signed char _val = (signed char)(val); grn_bulk_write((ctx), (obj), (char *)&_val, sizeof(signed char));\ |
1503 | } while (0) |
1504 | #define GRN_UINT8_PUT(ctx,obj,val) do {\ |
1505 | unsigned char _val = (unsigned char)(val);\ |
1506 | grn_bulk_write((ctx), (obj), (char *)&_val, sizeof(unsigned char));\ |
1507 | } while (0) |
1508 | #define GRN_INT16_PUT(ctx,obj,val) do {\ |
1509 | signed short _val = (signed short)(val); grn_bulk_write((ctx), (obj), (char *)&_val, sizeof(signed short));\ |
1510 | } while (0) |
1511 | #define GRN_UINT16_PUT(ctx,obj,val) do {\ |
1512 | unsigned short _val = (unsigned short)(val);\ |
1513 | grn_bulk_write((ctx), (obj), (char *)&_val, sizeof(unsigned short));\ |
1514 | } while (0) |
1515 | #define GRN_INT32_PUT(ctx,obj,val) do {\ |
1516 | int _val = (int)(val); grn_bulk_write((ctx), (obj), (char *)&_val, sizeof(int));\ |
1517 | } while (0) |
1518 | #define GRN_UINT32_PUT(ctx,obj,val) do {\ |
1519 | unsigned int _val = (unsigned int)(val);\ |
1520 | grn_bulk_write((ctx), (obj), (char *)&_val, sizeof(unsigned int));\ |
1521 | } while (0) |
1522 | #define GRN_INT64_PUT(ctx,obj,val) do {\ |
1523 | long long int _val = (long long int)(val);\ |
1524 | grn_bulk_write((ctx), (obj), (char *)&_val, sizeof(long long int));\ |
1525 | } while (0) |
1526 | #define GRN_UINT64_PUT(ctx,obj,val) do {\ |
1527 | long long unsigned int _val = (long long unsigned int)(val);\ |
1528 | grn_bulk_write((ctx), (obj), (char *)&_val, sizeof(long long unsigned int));\ |
1529 | } while (0) |
1530 | #define GRN_FLOAT_PUT(ctx,obj,val) do {\ |
1531 | double _val = (double)(val); grn_bulk_write((ctx), (obj), (char *)&_val, sizeof(double));\ |
1532 | } while (0) |
1533 | #define GRN_TIME_PUT GRN_INT64_PUT |
1534 | #define GRN_RECORD_PUT(ctx,obj,val) do {\ |
1535 | grn_id _val = (grn_id)(val); grn_bulk_write((ctx), (obj), (char *)&_val, sizeof(grn_id));\ |
1536 | } while (0) |
1537 | #define GRN_PTR_PUT(ctx,obj,val) do {\ |
1538 | grn_obj *_val = (grn_obj *)(val);\ |
1539 | grn_bulk_write((ctx), (obj), (char *)&_val, sizeof(grn_obj *));\ |
1540 | } while (0) |
1541 | |
1542 | #define GRN_BULK_POP(obj, value, type, default) do {\ |
1543 | if (GRN_BULK_VSIZE(obj) >= sizeof(type)) {\ |
1544 | GRN_BULK_INCR_LEN((obj), -(sizeof(type)));\ |
1545 | value = *(type *)(GRN_BULK_CURR(obj));\ |
1546 | } else {\ |
1547 | value = default;\ |
1548 | }\ |
1549 | } while (0) |
1550 | #define GRN_BOOL_POP(obj, value) GRN_BULK_POP(obj, value, unsigned char, 0) |
1551 | #define GRN_INT8_POP(obj, value) GRN_BULK_POP(obj, value, int8_t, 0) |
1552 | #define GRN_UINT8_POP(obj, value) GRN_BULK_POP(obj, value, uint8_t, 0) |
1553 | #define GRN_INT16_POP(obj, value) GRN_BULK_POP(obj, value, int16_t, 0) |
1554 | #define GRN_UINT16_POP(obj, value) GRN_BULK_POP(obj, value, uint16_t, 0) |
1555 | #define GRN_INT32_POP(obj, value) GRN_BULK_POP(obj, value, int32_t, 0) |
1556 | #define GRN_UINT32_POP(obj, value) GRN_BULK_POP(obj, value, uint32_t, 0) |
1557 | #define GRN_INT64_POP(obj, value) GRN_BULK_POP(obj, value, int64_t, 0) |
1558 | #define GRN_UINT64_POP(obj, value) GRN_BULK_POP(obj, value, uint64_t, 0) |
1559 | #define GRN_FLOAT_POP(obj, value) GRN_BULK_POP(obj, value, double, 0.0) |
1560 | #define GRN_TIME_POP GRN_INT64_POP |
1561 | #define GRN_RECORD_POP(obj, value) GRN_BULK_POP(obj, value, grn_id, GRN_ID_NIL) |
1562 | #define GRN_PTR_POP(obj, value) GRN_BULK_POP(obj, value, grn_obj *, NULL) |
1563 | |
1564 | /* grn_str: deprecated. use grn_string instead. */ |
1565 | |
1566 | typedef struct { |
1567 | const char *orig; |
1568 | char *norm; |
1569 | short *checks; |
1570 | unsigned char *ctypes; |
1571 | int flags; |
1572 | unsigned int orig_blen; |
1573 | unsigned int norm_blen; |
1574 | unsigned int length; |
1575 | grn_encoding encoding; |
1576 | } grn_str; |
1577 | |
1578 | #define GRN_STR_REMOVEBLANK (0x01<<0) |
1579 | #define GRN_STR_WITH_CTYPES (0x01<<1) |
1580 | #define GRN_STR_WITH_CHECKS (0x01<<2) |
1581 | #define GRN_STR_NORMALIZE GRN_OBJ_KEY_NORMALIZE |
1582 | |
1583 | GRN_API grn_str *grn_str_open(grn_ctx *ctx, const char *str, unsigned int str_len, |
1584 | int flags); |
1585 | GRN_API grn_rc grn_str_close(grn_ctx *ctx, grn_str *nstr); |
1586 | |
1587 | /* grn_string */ |
1588 | |
1589 | #define GRN_STRING_REMOVE_BLANK (0x01<<0) |
1590 | #define GRN_STRING_WITH_TYPES (0x01<<1) |
1591 | #define GRN_STRING_WITH_CHECKS (0x01<<2) |
1592 | #define GRN_STRING_REMOVE_TOKENIZED_DELIMITER (0x01<<3) |
1593 | |
1594 | #define GRN_NORMALIZER_AUTO ((grn_obj *)1) |
1595 | |
1596 | #define GRN_CHAR_BLANK 0x80 |
1597 | #define GRN_CHAR_IS_BLANK(c) ((c) & (GRN_CHAR_BLANK)) |
1598 | #define GRN_CHAR_TYPE(c) ((c) & 0x7f) |
1599 | |
1600 | typedef enum { |
1601 | GRN_CHAR_NULL = 0, |
1602 | GRN_CHAR_ALPHA, |
1603 | GRN_CHAR_DIGIT, |
1604 | GRN_CHAR_SYMBOL, |
1605 | GRN_CHAR_HIRAGANA, |
1606 | GRN_CHAR_KATAKANA, |
1607 | GRN_CHAR_KANJI, |
1608 | GRN_CHAR_OTHERS |
1609 | } grn_char_type; |
1610 | |
1611 | GRN_API grn_obj *grn_string_open(grn_ctx *ctx, |
1612 | const char *string, |
1613 | unsigned int length_in_bytes, |
1614 | grn_obj *normalizer, int flags); |
1615 | GRN_API grn_rc grn_string_get_original(grn_ctx *ctx, grn_obj *string, |
1616 | const char **original, |
1617 | unsigned int *length_in_bytes); |
1618 | GRN_API int grn_string_get_flags(grn_ctx *ctx, grn_obj *string); |
1619 | GRN_API grn_rc grn_string_get_normalized(grn_ctx *ctx, grn_obj *string, |
1620 | const char **normalized, |
1621 | unsigned int *length_in_bytes, |
1622 | unsigned int *n_characters); |
1623 | GRN_API grn_rc grn_string_set_normalized(grn_ctx *ctx, grn_obj *string, |
1624 | char *normalized, |
1625 | unsigned int length_in_bytes, |
1626 | unsigned int n_characters); |
1627 | GRN_API const short *grn_string_get_checks(grn_ctx *ctx, grn_obj *string); |
1628 | GRN_API grn_rc grn_string_set_checks(grn_ctx *ctx, |
1629 | grn_obj *string, |
1630 | short *checks); |
1631 | GRN_API const unsigned char *grn_string_get_types(grn_ctx *ctx, grn_obj *string); |
1632 | GRN_API grn_rc grn_string_set_types(grn_ctx *ctx, |
1633 | grn_obj *string, |
1634 | unsigned char *types); |
1635 | GRN_API grn_encoding grn_string_get_encoding(grn_ctx *ctx, grn_obj *string); |
1636 | |
1637 | |
1638 | GRN_API int grn_charlen(grn_ctx *ctx, const char *str, const char *end); |
1639 | |
1640 | GRN_API grn_rc grn_ctx_push(grn_ctx *ctx, grn_obj *obj); |
1641 | GRN_API grn_obj *grn_ctx_pop(grn_ctx *ctx); |
1642 | |
1643 | GRN_API int grn_obj_columns(grn_ctx *ctx, grn_obj *table, |
1644 | const char *str, unsigned int str_size, grn_obj *res); |
1645 | |
1646 | GRN_API grn_rc grn_load(grn_ctx *ctx, grn_content_type input_type, |
1647 | const char *table, unsigned int table_len, |
1648 | const char *columns, unsigned int columns_len, |
1649 | const char *values, unsigned int values_len, |
1650 | const char *ifexists, unsigned int ifexists_len, |
1651 | const char *each, unsigned int each_len); |
1652 | |
1653 | #define GRN_CTX_MORE (0x01<<0) |
1654 | #define GRN_CTX_TAIL (0x01<<1) |
1655 | #define GRN_CTX_HEAD (0x01<<2) |
1656 | #define GRN_CTX_QUIET (0x01<<3) |
1657 | #define GRN_CTX_QUIT (0x01<<4) |
1658 | |
1659 | GRN_API grn_rc grn_ctx_connect(grn_ctx *ctx, const char *host, int port, int flags); |
1660 | GRN_API unsigned int grn_ctx_send(grn_ctx *ctx, const char *str, unsigned int str_len, int flags); |
1661 | GRN_API unsigned int grn_ctx_recv(grn_ctx *ctx, char **str, unsigned int *str_len, int *flags); |
1662 | |
1663 | typedef struct _grn_ctx_info grn_ctx_info; |
1664 | |
1665 | struct _grn_ctx_info { |
1666 | int fd; |
1667 | unsigned int com_status; |
1668 | grn_obj *outbuf; |
1669 | unsigned char stat; |
1670 | }; |
1671 | |
1672 | GRN_API grn_rc grn_ctx_info_get(grn_ctx *ctx, grn_ctx_info *info); |
1673 | |
1674 | GRN_API grn_rc grn_set_segv_handler(void); |
1675 | GRN_API grn_rc grn_set_int_handler(void); |
1676 | GRN_API grn_rc grn_set_term_handler(void); |
1677 | |
1678 | |
1679 | typedef struct _grn_table_delete_optarg grn_table_delete_optarg; |
1680 | |
1681 | struct _grn_table_delete_optarg { |
1682 | int flags; |
1683 | int (*func)(grn_ctx *ctx, grn_obj *, grn_id, void *); |
1684 | void *func_arg; |
1685 | }; |
1686 | |
1687 | struct _grn_table_scan_hit { |
1688 | grn_id id; |
1689 | unsigned int offset; |
1690 | unsigned int length; |
1691 | }; |
1692 | |
1693 | typedef struct { |
1694 | int64_t tv_sec; |
1695 | int32_t tv_nsec; |
1696 | } grn_timeval; |
1697 | |
1698 | #ifdef __cplusplus |
1699 | } |
1700 | #endif |
1701 | |