| 1 | /* |
| 2 | Copyright (C) 2009-2016 Brazil |
| 3 | Copyright (C) 2019-2024 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_proc.h"cxx . . $ `<file>/lib/grn_proc.h`/ |
| 21 | #include "../grn_io.h"cxx . . $ `<file>/lib/grn_io.h`/ |
| 22 | |
| 23 | #include <groonga/plugin.h>cxx . . $ `<file>/include/groonga/plugin.h`/ |
| 24 | |
| 25 | #include <sys/types.h> |
| 26 | #include <sys/stat.h> |
| 27 | |
| 28 | static grn_objcxx . . $ grn_obj# * |
| 29 | command_object_existcxx . . $ command_object_exist(fd082858389c8bb0).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 30 | int nargs, |
| 31 | grn_objcxx . . $ grn_obj# **args, |
| 32 | grn_user_datacxx . . $ grn_user_data# *user_data) |
| 33 | { |
| 34 | grn_objcxx . . $ grn_obj# *db; |
| 35 | grn_objcxx . . $ grn_obj# *name; |
| 36 | grn_idcxx . . $ grn_id# id; |
| 37 | |
| 38 | db = grn_ctx_dbcxx . . $ grn_ctx_db(ddec8e3b1327ceae).(ctx); |
| 39 | name = grn_plugin_proc_get_varcxx . . $ grn_plugin_proc_get_var(3074f8d72b0d40ab).(ctx, user_data, "name", -1); |
| 40 | if (GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(name) == 0) { |
| 41 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 42 | GRN_INVALID_ARGUMENT, |
| 43 | "[object][exist] name is missing"); |
| 44 | grn_ctx_output_boolcxx . . $ grn_ctx_output_bool(1112b62984b2cd7f).(ctx, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!); |
| 45 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 46 | } |
| 47 | |
| 48 | id = grn_table_getcxx . . $ grn_table_get(5676c91e20172100).(ctx, |
| 49 | db, |
| 50 | GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(name), |
| 51 | (unsigned int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(name)); |
| 52 | grn_ctx_output_boolcxx . . $ grn_ctx_output_bool(1112b62984b2cd7f).(ctx, id != GRN_ID_NILcxx . . $ `include/groonga/groonga.h:55:9`!); |
| 53 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 54 | } |
| 55 | |
| 56 | void |
| 57 | grn_proc_init_object_existcxx . . $ grn_proc_init_object_exist(b578cd6e53d5fe91).(grn_ctxcxx . . $ grn_ctx# *ctx) |
| 58 | { |
| 59 | grn_expr_varcxx . . $ grn_expr_var# vars[1]; |
| 60 | |
| 61 | grn_plugin_expr_var_initcxx . . $ grn_plugin_expr_var_init(680ef4125f11597f).(ctx, &(vars[0]), "name", -1); |
| 62 | grn_plugin_command_createcxx . . $ grn_plugin_command_create(2dfd920bb40f3149).(ctx, |
| 63 | "object_exist", |
| 64 | -1, |
| 65 | command_object_existcxx . . $ command_object_exist(fd082858389c8bb0)., |
| 66 | 1, |
| 67 | vars); |
| 68 | } |
| 69 | |
| 70 | static grn_objcxx . . $ grn_obj# * |
| 71 | command_object_removecxx . . $ command_object_remove(fd082858389c8bb0).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 72 | int nargs, |
| 73 | grn_objcxx . . $ grn_obj# **args, |
| 74 | grn_user_datacxx . . $ grn_user_data# *user_data) |
| 75 | { |
| 76 | grn_objcxx . . $ grn_obj# *db; |
| 77 | grn_objcxx . . $ grn_obj# *name; |
| 78 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! force; |
| 79 | grn_objcxx . . $ grn_obj# *target; |
| 80 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! failed_to_open; |
| 81 | |
| 82 | db = grn_ctx_dbcxx . . $ grn_ctx_db(ddec8e3b1327ceae).(ctx); |
| 83 | name = grn_plugin_proc_get_varcxx . . $ grn_plugin_proc_get_var(3074f8d72b0d40ab).(ctx, user_data, "name", -1); |
| 84 | force = grn_plugin_proc_get_var_boolcxx . . $ grn_plugin_proc_get_var_bool(544c966dc918f81a).(ctx, user_data, "force", -1, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!); |
| 85 | |
| 86 | if (GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(name) == 0) { |
| 87 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 88 | GRN_INVALID_ARGUMENT, |
| 89 | "[object][remove] name is missing"); |
| 90 | grn_ctx_output_boolcxx . . $ grn_ctx_output_bool(1112b62984b2cd7f).(ctx, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!); |
| 91 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 92 | } |
| 93 | |
| 94 | target = grn_ctx_getcxx . . $ grn_ctx_get(70fde0087014f9ea).(ctx, GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(name), (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(name)); |
| 95 | if (target) { |
| 96 | grn_obj_removecxx . . $ grn_obj_remove(4865d068a46d0f83).(ctx, target); |
| 97 | if (!force || ctx->rccxx . . $ _grn_ctx#rc. == GRN_SUCCESScxx . . $ GRN_SUCCESS.) { |
| 98 | grn_ctx_output_boolcxx . . $ grn_ctx_output_bool(1112b62984b2cd7f).(ctx, ctx->rccxx . . $ _grn_ctx#rc. == GRN_SUCCESScxx . . $ GRN_SUCCESS.); |
| 99 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 100 | } |
| 101 | grn_obj_closecxx . . $ grn_obj_close(4865d068a46d0f83).(ctx, target); |
| 102 | failed_to_open = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 103 | } else { |
| 104 | failed_to_open = (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.); |
| 105 | } |
| 106 | |
| 107 | if (force) { |
| 108 | grn_ctx_removecxx . . $ grn_ctx_remove(acd5f39bcd03cbc).(ctx, |
| 109 | GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(name), |
| 110 | (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(name), |
| 111 | GRN_OBJ_REMOVE_DEPENDENTcxx . . $ `include/groonga/groonga.h:1516:9`! | GRN_OBJ_REMOVE_ENSUREcxx . . $ `include/groonga/groonga.h:1517:9`!); |
| 112 | grn_ctx_output_boolcxx . . $ grn_ctx_output_bool(1112b62984b2cd7f).(ctx, ctx->rccxx . . $ _grn_ctx#rc. == GRN_SUCCESScxx . . $ GRN_SUCCESS.); |
| 113 | } else { |
| 114 | if (failed_to_open) { |
| 115 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 116 | GRN_INVALID_ARGUMENT, |
| 117 | "[object][remove] " |
| 118 | "failed to open the target object: <%.*s>", |
| 119 | (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(name), |
| 120 | GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(name)); |
| 121 | } else { |
| 122 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 123 | GRN_INVALID_ARGUMENT, |
| 124 | "[object][remove] target object doesn't exist: <%.*s>", |
| 125 | (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(name), |
| 126 | GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(name)); |
| 127 | } |
| 128 | grn_ctx_output_boolcxx . . $ grn_ctx_output_bool(1112b62984b2cd7f).(ctx, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!); |
| 129 | } |
| 130 | |
| 131 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 132 | } |
| 133 | |
| 134 | void |
| 135 | grn_proc_init_object_removecxx . . $ grn_proc_init_object_remove(b578cd6e53d5fe91).(grn_ctxcxx . . $ grn_ctx# *ctx) |
| 136 | { |
| 137 | grn_expr_varcxx . . $ grn_expr_var# vars[2]; |
| 138 | |
| 139 | grn_plugin_expr_var_initcxx . . $ grn_plugin_expr_var_init(680ef4125f11597f).(ctx, &(vars[0]), "name", -1); |
| 140 | grn_plugin_expr_var_initcxx . . $ grn_plugin_expr_var_init(680ef4125f11597f).(ctx, &(vars[1]), "force", -1); |
| 141 | grn_plugin_command_createcxx . . $ grn_plugin_command_create(2dfd920bb40f3149).(ctx, |
| 142 | "object_remove", |
| 143 | -1, |
| 144 | command_object_removecxx . . $ command_object_remove(fd082858389c8bb0)., |
| 145 | 2, |
| 146 | vars); |
| 147 | } |
| 148 | |
| 149 | static grn_objcxx . . $ grn_obj# * |
| 150 | command_object_set_visibilitycxx . . $ command_object_set_visibility(fd082858389c8bb0).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 151 | int n_args, |
| 152 | grn_objcxx . . $ grn_obj# **args, |
| 153 | grn_user_datacxx . . $ grn_user_data# *user_data) |
| 154 | { |
| 155 | grn_raw_stringcxx . . $ grn_raw_string# name; |
| 156 | grn_objcxx . . $ grn_obj# *object; |
| 157 | |
| 158 | name.valuecxx . . $ $anonymous_type_7f733dd816802915_0#value. = |
| 159 | grn_plugin_proc_get_var_stringcxx . . $ grn_plugin_proc_get_var_string(b6763965d55cfbc).(ctx, user_data, "name", -1, &(name.lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length.)); |
| 160 | if (name.lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length. == 0) { |
| 161 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 162 | GRN_INVALID_ARGUMENT, |
| 163 | "[object][set-visibility] name is missing"); |
| 164 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 165 | } |
| 166 | |
| 167 | object = grn_ctx_getcxx . . $ grn_ctx_get(70fde0087014f9ea).(ctx, name.valuecxx . . $ $anonymous_type_7f733dd816802915_0#value., (int)(name.lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length.)); |
| 168 | if (!object) { |
| 169 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 170 | GRN_INVALID_ARGUMENT, |
| 171 | "[object][set-visibility] object doesn't exist: <%.*s>", |
| 172 | (int)(name.length), |
| 173 | name.value); |
| 174 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 175 | } |
| 176 | |
| 177 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! old_visibility = grn_obj_is_visiblecxx . . $ grn_obj_is_visible(a5760e5c319a06ee).(ctx, object); |
| 178 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! new_visibility = |
| 179 | grn_plugin_proc_get_var_boolcxx . . $ grn_plugin_proc_get_var_bool(544c966dc918f81a).(ctx, user_data, "visible", -1, old_visibility); |
| 180 | if (grn_obj_set_visibilitycxx . . $ grn_obj_set_visibility(7f588588f63dc99e).(ctx, object, new_visibility) != GRN_SUCCESScxx . . $ GRN_SUCCESS.) { |
| 181 | goto exit; |
| 182 | } |
| 183 | |
| 184 | grn_ctx_output_map_opencxx . . $ grn_ctx_output_map_open(f0f392d632556531).(ctx, "visibility", 2); |
| 185 | { |
| 186 | grn_ctx_output_cstrcxx . . $ grn_ctx_output_cstr(777524e3d10dd7b4).(ctx, "old"); |
| 187 | grn_ctx_output_boolcxx . . $ grn_ctx_output_bool(1112b62984b2cd7f).(ctx, old_visibility); |
| 188 | grn_ctx_output_cstrcxx . . $ grn_ctx_output_cstr(777524e3d10dd7b4).(ctx, "new"); |
| 189 | grn_ctx_output_boolcxx . . $ grn_ctx_output_bool(1112b62984b2cd7f).(ctx, grn_obj_is_visiblecxx . . $ grn_obj_is_visible(a5760e5c319a06ee).(ctx, object)); |
| 190 | } |
| 191 | grn_ctx_output_map_closecxx . . $ grn_ctx_output_map_close(b578cd6e53d5fe91).(ctx); |
| 192 | |
| 193 | exit: |
| 194 | if (grn_obj_is_accessorcxx . . $ grn_obj_is_accessor(a5760e5c319a06ee).(ctx, object)) { |
| 195 | grn_obj_unlinkcxx . . $ grn_obj_unlink(4865d068a46d0f83).(ctx, object); |
| 196 | } |
| 197 | |
| 198 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 199 | } |
| 200 | |
| 201 | void |
| 202 | grn_proc_init_object_set_visibilitycxx . . $ grn_proc_init_object_set_visibility(b578cd6e53d5fe91).(grn_ctxcxx . . $ grn_ctx# *ctx) |
| 203 | { |
| 204 | grn_expr_varcxx . . $ grn_expr_var# vars[2]; |
| 205 | unsigned int n_vars = 0; |
| 206 | |
| 207 | grn_plugin_expr_var_initcxx . . $ grn_plugin_expr_var_init(680ef4125f11597f).(ctx, &(vars[n_vars++]), "name", -1); |
| 208 | grn_plugin_expr_var_initcxx . . $ grn_plugin_expr_var_init(680ef4125f11597f).(ctx, &(vars[n_vars++]), "visible", -1); |
| 209 | grn_plugin_command_createcxx . . $ grn_plugin_command_create(2dfd920bb40f3149).(ctx, |
| 210 | "object_set_visibility", |
| 211 | -1, |
| 212 | command_object_set_visibilitycxx . . $ command_object_set_visibility(fd082858389c8bb0)., |
| 213 | n_vars, |
| 214 | vars); |
| 215 | } |
| 216 | |
| 217 | static grn_objcxx . . $ grn_obj# * |
| 218 | command_object_warmcxx . . $ command_object_warm(fd082858389c8bb0).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 219 | int n_args, |
| 220 | grn_objcxx . . $ grn_obj# **args, |
| 221 | grn_user_datacxx . . $ grn_user_data# *user_data) |
| 222 | { |
| 223 | grn_objcxx . . $ grn_obj# *name = grn_plugin_proc_get_varcxx . . $ grn_plugin_proc_get_var(3074f8d72b0d40ab).(ctx, user_data, "name", -1); |
| 224 | |
| 225 | grn_objcxx . . $ grn_obj# *target; |
| 226 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! need_unref = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 227 | if (GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(name) == 0) { |
| 228 | target = grn_ctx_dbcxx . . $ grn_ctx_db(ddec8e3b1327ceae).(ctx); |
| 229 | } else { |
| 230 | target = grn_ctx_getcxx . . $ grn_ctx_get(70fde0087014f9ea).(ctx, GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(name), (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(name)); |
| 231 | if (!target) { |
| 232 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 233 | GRN_INVALID_ARGUMENT, |
| 234 | "[object][warm] nonexistent target: <%.*s>", |
| 235 | (int)GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(name), |
| 236 | GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(name)); |
| 237 | grn_ctx_output_boolcxx . . $ grn_ctx_output_bool(1112b62984b2cd7f).(ctx, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!); |
| 238 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 239 | } |
| 240 | need_unref = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 241 | } |
| 242 | |
| 243 | grn_rccxx . . $ grn_rc# rc = grn_obj_warmcxx . . $ grn_obj_warm(4865d068a46d0f83).(ctx, target); |
| 244 | grn_ctx_output_boolcxx . . $ grn_ctx_output_bool(1112b62984b2cd7f).(ctx, rc == GRN_SUCCESScxx . . $ GRN_SUCCESS.); |
| 245 | |
| 246 | if (need_unref) { |
| 247 | grn_obj_unrefcxx . . $ grn_obj_unref(cda3a5f3c2e53c6b).(ctx, target); |
| 248 | } |
| 249 | |
| 250 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 251 | } |
| 252 | |
| 253 | void |
| 254 | grn_proc_init_object_warmcxx . . $ grn_proc_init_object_warm(b578cd6e53d5fe91).(grn_ctxcxx . . $ grn_ctx# *ctx) |
| 255 | { |
| 256 | grn_expr_varcxx . . $ grn_expr_var# vars[1]; |
| 257 | |
| 258 | grn_plugin_expr_var_initcxx . . $ grn_plugin_expr_var_init(680ef4125f11597f).(ctx, &(vars[0]), "name", -1); |
| 259 | grn_plugin_command_createcxx . . $ grn_plugin_command_create(2dfd920bb40f3149).(ctx, |
| 260 | "object_warm", |
| 261 | -1, |
| 262 | command_object_warmcxx . . $ command_object_warm(fd082858389c8bb0)., |
| 263 | 1, |
| 264 | vars); |
| 265 | } |