| 2224 | |
| 2225 | |
| 2226 | enum json_types json_get_object_nkey(const char *js __attribute__((unused)), |
| 2227 | const char *js_end __attribute__((unused)), |
| 2228 | int nkey __attribute__((unused)), |
| 2229 | const char **keyname __attribute__((unused)), |
| 2230 | const char **keyname_end __attribute__((unused)), |
| 2231 | const char **value __attribute__((unused)), |
| 2232 | int *value_len __attribute__((unused))) |
| 2233 | { |
| 2234 | json_engine_t je; |
| 2235 | int keys_found= 0; |
| 2236 | MEM_ROOT current_mem_root; |
| 2237 | enum json_types return_value; |
| 2238 | |
| 2239 | init_alloc_root(PSI_INSTRUMENT_MEM, ¤t_mem_root, |
| 2240 | BLOCK_SIZE_JSON_DYN_ARRAY, 0, MYF(0)); |
| 2241 | |
| 2242 | mem_root_dynamic_array_init(¤t_mem_root, PSI_INSTRUMENT_MEM, |
| 2243 | &je.stack, sizeof(int), NULL, |
| 2244 | JSON_DEPTH_DEFAULT, JSON_DEPTH_INC, MYF(0)); |
| 2245 | |
| 2246 | json_scan_start(&je, &my_charset_utf8mb4_bin,(const uchar *) js, |
| 2247 | (const uchar *) js_end); |
| 2248 | |
| 2249 | if (json_read_value(&je) || |
| 2250 | je.value_type != JSON_VALUE_OBJECT) |
| 2251 | goto err_return; |
| 2252 | |
| 2253 | while (!json_scan_next(&je)) |
| 2254 | { |
| 2255 | switch (je.state) |
| 2256 | { |
| 2257 | case JST_KEY: |
| 2258 | if (nkey == keys_found) |
| 2259 | { |
| 2260 | *keyname= (char *) je.s.c_str; |
| 2261 | while (json_read_keyname_chr(&je) == 0) |
| 2262 | *keyname_end= (char *) je.s.c_str; |
| 2263 | |
| 2264 | return_value= smart_read_value(&je, value, value_len); |
| 2265 | free_root(¤t_mem_root, MYF(0)); |
| 2266 | return return_value; |
| 2267 | } |
| 2268 | |
| 2269 | keys_found++; |
| 2270 | if (json_skip_key(&je)) |
| 2271 | goto err_return; |
| 2272 | |
| 2273 | break; |
| 2274 | |
| 2275 | case JST_OBJ_END: |
| 2276 | free_root(¤t_mem_root, MYF(0)); |
| 2277 | return JSV_NOTHING; |
| 2278 | } |
| 2279 | } |
| 2280 | |
| 2281 | err_return: |
| 2282 | free_root(¤t_mem_root, MYF(0)); |
| 2283 | return JSV_BAD_JSON; |
no test coverage detected