| 851 | |
| 852 | |
| 853 | static int |
| 854 | json_norm_parse(struct json_norm_value *root, json_engine_t *je, MEM_ROOT *current_mem_root, MEM_ROOT_DYNAMIC_ARRAY *stack) |
| 855 | { |
| 856 | size_t current = 0; |
| 857 | int err = 0; |
| 858 | DYNAMIC_STRING key; |
| 859 | struct json_norm_value* root_ptr = root; |
| 860 | |
| 861 | // Set the root pointer in the stack |
| 862 | mem_root_dynamic_array_set_val(stack, &root_ptr, current); |
| 863 | |
| 864 | err = init_dynamic_string(&key, NULL, 0, 0); |
| 865 | if (err) |
| 866 | { |
| 867 | goto json_norm_parse_end; |
| 868 | } |
| 869 | |
| 870 | do { |
| 871 | switch (je->state) |
| 872 | { |
| 873 | case JST_KEY: |
| 874 | { |
| 875 | const uchar *key_start = je->s.c_str; |
| 876 | const uchar *key_end; |
| 877 | struct json_norm_value* new_val_ptr= NULL; |
| 878 | struct json_norm_value** curr_val_ptr = |
| 879 | (struct json_norm_value**)(stack->buffer) + current; |
| 880 | struct json_norm_value* curr_val = *curr_val_ptr; |
| 881 | DBUG_ASSERT(curr_val->type == JSON_VALUE_OBJECT); |
| 882 | |
| 883 | do |
| 884 | { |
| 885 | key_end = je->s.c_str; |
| 886 | } while (json_read_keyname_chr(je) == 0); |
| 887 | |
| 888 | /* we have the key name */ |
| 889 | /* reset the dynstr: */ |
| 890 | dynstr_trunc(&key, key.length); |
| 891 | dynstr_append_mem(&key, (char*)key_start, (key_end - key_start)); |
| 892 | |
| 893 | /* After reading the key, we have a follow-up value. */ |
| 894 | err = json_read_value(je); |
| 895 | if (err) |
| 896 | goto json_norm_parse_end; |
| 897 | |
| 898 | err = json_norm_append_to_object(curr_val, &key, je); |
| 899 | if (err) |
| 900 | goto json_norm_parse_end; |
| 901 | |
| 902 | if (je->value_type == JSON_VALUE_ARRAY || |
| 903 | je->value_type == JSON_VALUE_OBJECT) |
| 904 | { |
| 905 | struct json_norm_kv* kv; |
| 906 | kv = json_norm_object_get_last_element(&curr_val->value.object); |
| 907 | new_val_ptr = &kv->value; |
| 908 | mem_root_dynamic_array_resize_and_set_val(stack, &new_val_ptr, ++current); |
| 909 | } |
| 910 | break; |
no test coverage detected