Debian Codegraph @

lib/proc/proc_json.c

raw symbols SCIP
1 /*
2 Copyright (C) 2026 Sutou Kouhei <[email protected]>
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 #include "../grn_proc.h"cxx . . $ `<file>/lib/grn_proc.h`/
20 #include "../grn_db.h"cxx . . $ `<file>/lib/grn_db.h`/
21 #include "../grn_expr.h"cxx . . $ `<file>/lib/grn_expr.h`/
22 #include "../grn_store.h"cxx . . $ `<file>/lib/grn_store.h`/
23
24 #include <groonga/plugin.h>cxx . . $ `<file>/include/groonga/plugin.h`/
25
26 typedef structcxx . . $ $anonymous_type_cbf6691f0a79e06e_0# {
27 grn_objcxx . . $ grn_obj# *jsoncxx . . $ $anonymous_type_cbf6691f0a79e06e_0#json.;
28 grn_objcxx . . $ grn_obj# json_buffercxx . . $ $anonymous_type_cbf6691f0a79e06e_0#json_buffer.;
29 grn_json_pathcxx . . $ grn_json_path# *json_pathcxx . . $ $anonymous_type_cbf6691f0a79e06e_0#json_path.;
30 } grn_json_extract_datacxx . . $ grn_json_extract_data#;
31
32 static void
33 grn_json_extract_data_freecxx . . $ grn_json_extract_data_free(4c2740a9465cd124).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_json_extract_datacxx . . $ grn_json_extract_data# *data)
34 {
35 if (!data) {
36 return;
37 }
38
39 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &(data->json_buffer));
40 if (data->json_pathcxx . . $ $anonymous_type_cbf6691f0a79e06e_0#json_path.) {
41 grn_json_path_closecxx . . $ grn_json_path_close(21c1c787af2cfc3).(ctx, data->json_pathcxx . . $ $anonymous_type_cbf6691f0a79e06e_0#json_path.);
42 }
43
44 GRN_PLUGIN_FREEcxx . . $ `include/groonga/plugin.h:100:9`!(ctx, data);
45 }
46
47 static grn_objcxx . . $ grn_obj# *
48 func_json_extract_initcxx . . $ func_json_extract_init(fd082858389c8bb0).(grn_ctxcxx . . $ grn_ctx# *ctx,
49 int n_args,
50 grn_objcxx . . $ grn_obj# **args,
51 grn_user_datacxx . . $ grn_user_data# *user_data)
52 {
53 if (n_args != 2) {
54 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
55 GRN_INVALID_ARGUMENT,
56 "json_extract(): wrong number of arguments (%d for 2)",
57 n_args);
58 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
59 }
60
61 grn_json_extract_datacxx . . $ grn_json_extract_data# *data =
62 GRN_PLUGIN_CALLOCcxx . . $ `include/groonga/plugin.h:96:9`!(ctx, sizeof(grn_json_extract_data));
63 if (!data) {
64 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
65 GRN_INVALID_ARGUMENT,
66 "json_extract(): failed to allocate internal data");
67 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
68 }
69 user_data->ptrcxx . . $ $anonymous_type_1555d7cc1d218aa4_5#ptr. = data;
70
71 GRN_JSON_INITcxx . . $ `include/groonga/groonga.h:2820:9`!(&(data->json_buffer), 0);
72 grn_objcxx . . $ grn_obj# *json = args[0];
73 if (json->headercxx . . $ _grn_obj#header..domaincxx . . $ _grn_obj_header#domain. == GRN_DB_JSONcxx . . $ GRN_DB_JSON.) {
74 data->jsoncxx . . $ $anonymous_type_cbf6691f0a79e06e_0#json. = json;
75 } else if (grn_obj_is_text_family_bulkcxx . . $ grn_obj_is_text_family_bulk(a5760e5c319a06ee).(ctx, json)) {
76 grn_rccxx . . $ grn_rc# rc = grn_obj_castcxx . . $ grn_obj_cast(a6fd93da1614eccd).(ctx, json, &(data->json_buffercxx . . $ $anonymous_type_cbf6691f0a79e06e_0#json_buffer.), falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!);
77 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
78 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
79 GRN_INVALID_ARGUMENT,
80 "json_extract(): failed to parse JSON: <%.*s>",
81 (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(json),
82 GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(json));
83 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
84 }
85 data->jsoncxx . . $ $anonymous_type_cbf6691f0a79e06e_0#json. = &(data->json_buffercxx . . $ $anonymous_type_cbf6691f0a79e06e_0#json_buffer.);
86 } else {
87 grn_objcxx . . $ grn_obj# inspected;
88 GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&inspected, 0);
89 grn_inspectcxx . . $ grn_inspect(88456f97fe0d41a).(ctx, &inspected, json);
90 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
91 GRN_INVALID_ARGUMENT,
92 "json_extract(): the first argument must be "
93 "a parsed JSON or JSON string: <%.*s>",
94 (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&inspected),
95 GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(&inspected));
96 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &inspected);
97 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
98 }
99
100 grn_objcxx . . $ grn_obj# *json_path = args[1];
101 if (!grn_obj_is_text_family_bulkcxx . . $ grn_obj_is_text_family_bulk(a5760e5c319a06ee).(ctx, json_path)) {
102 grn_objcxx . . $ grn_obj# inspected;
103 GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&inspected, 0);
104 grn_inspectcxx . . $ grn_inspect(88456f97fe0d41a).(ctx, &inspected, json_path);
105 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
106 GRN_INVALID_ARGUMENT,
107 "json_extract(): the second argument must be "
108 "a JSONPath string: <%.*s>",
109 (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&inspected),
110 GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(&inspected));
111 GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &inspected);
112 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
113 }
114 data->json_pathcxx . . $ $anonymous_type_cbf6691f0a79e06e_0#json_path. =
115 grn_json_path_opencxx . . $ grn_json_path_open(5293b6d555fcc0ac).(ctx, GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(json_path), GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(json_path));
116 if (!data->json_pathcxx . . $ $anonymous_type_cbf6691f0a79e06e_0#json_path.) {
117 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
118 GRN_INVALID_ARGUMENT,
119 "json_extract(): failed to parse JSONPath: <%.*s>",
120 (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(json_path),
121 GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(json_path));
122 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
123 }
124
125 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
126 }
127
128 static grn_objcxx . . $ grn_obj# *
129 func_json_extract_nextcxx . . $ func_json_extract_next(fd082858389c8bb0).(grn_ctxcxx . . $ grn_ctx# *ctx,
130 int n_args,
131 grn_objcxx . . $ grn_obj# **args,
132 grn_user_datacxx . . $ grn_user_data# *user_data)
133 {
134 grn_json_extract_datacxx . . $ grn_json_extract_data# *data = user_data->ptrcxx . . $ $anonymous_type_1555d7cc1d218aa4_5#ptr.;
135
136 if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
137 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
138 }
139
140 grn_objcxx . . $ grn_obj# *values =
141 grn_plugin_proc_alloccxx . . $ grn_plugin_proc_alloc(acb267eca6702fc).(ctx, user_data, GRN_DB_VOIDcxx . . $ GRN_DB_VOID., GRN_OBJ_VECTORcxx . . $ `include/groonga/groonga.h:2734:9`!);
142 if (!values) {
143 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
144 }
145 grn_rccxx . . $ grn_rc# rc = grn_json_extractcxx . . $ grn_json_extract(7d006019447c46b0).(ctx, data->jsoncxx . . $ $anonymous_type_cbf6691f0a79e06e_0#json., data->json_pathcxx . . $ $anonymous_type_cbf6691f0a79e06e_0#json_path., values);
146 if (rc != GRN_SUCCESScxx . . $ GRN_SUCCESS.) {
147 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx,
148 rc,
149 "json_extract(): "
150 "failed to extract values: %s",
151 ctx->errbuf);
152 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
153 }
154
155 return values;
156 }
157
158 static grn_objcxx . . $ grn_obj# *
159 func_json_extract_fincxx . . $ func_json_extract_fin(fd082858389c8bb0).(grn_ctxcxx . . $ grn_ctx# *ctx,
160 int n_args,
161 grn_objcxx . . $ grn_obj# **args,
162 grn_user_datacxx . . $ grn_user_data# *user_data)
163 {
164 grn_json_extract_datacxx . . $ grn_json_extract_data# *data = user_data->ptrcxx . . $ $anonymous_type_1555d7cc1d218aa4_5#ptr.;
165
166 grn_json_extract_data_freecxx . . $ grn_json_extract_data_free(4c2740a9465cd124).(ctx, data);
167
168 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
169 }
170
171 void
172 grn_proc_init_json_extractcxx . . $ grn_proc_init_json_extract(b578cd6e53d5fe91).(grn_ctxcxx . . $ grn_ctx# *ctx)
173 {
174 grn_proc_createcxx . . $ grn_proc_create(195df001e5324f57).(ctx,
175 "json_extract",
176 -1,
177 GRN_PROC_FUNCTIONcxx . . $ GRN_PROC_FUNCTION.,
178 func_json_extract_initcxx . . $ func_json_extract_init(fd082858389c8bb0).,
179 func_json_extract_nextcxx . . $ func_json_extract_next(fd082858389c8bb0).,
180 func_json_extract_fincxx . . $ func_json_extract_fin(fd082858389c8bb0).,
181 0,
182 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
183 }