Lines Matching refs:jso
52 static void json_object_generic_delete(struct json_object* jso);
152 extern struct json_object* json_object_get(struct json_object *jso) in json_object_get() argument
154 if (jso) in json_object_get()
155 jso->_ref_count++; in json_object_get()
156 return jso; in json_object_get()
159 int json_object_put(struct json_object *jso) in json_object_put() argument
161 if(jso) in json_object_put()
163 jso->_ref_count--; in json_object_put()
164 if(!jso->_ref_count) in json_object_put()
166 if (jso->_user_delete) in json_object_put()
167 jso->_user_delete(jso, jso->_userdata); in json_object_put()
168 jso->_delete(jso); in json_object_put()
178 static void json_object_generic_delete(struct json_object* jso) in json_object_generic_delete() argument
182 json_type_to_name(jso->o_type), jso); in json_object_generic_delete()
183 lh_table_delete(json_object_table, jso); in json_object_generic_delete()
185 printbuf_free(jso->_pb); in json_object_generic_delete()
186 free(jso); in json_object_generic_delete()
191 struct json_object *jso; in json_object_new() local
193 jso = (struct json_object*)calloc(sizeof(struct json_object), 1); in json_object_new()
194 if (!jso) in json_object_new()
196 jso->o_type = o_type; in json_object_new()
197 jso->_ref_count = 1; in json_object_new()
198 jso->_delete = &json_object_generic_delete; in json_object_new()
200 lh_table_insert(json_object_table, jso, jso); in json_object_new()
201 MC_DEBUG("json_object_new_%s: %p\n", json_type_to_name(jso->o_type), jso); in json_object_new()
203 return jso; in json_object_new()
209 int json_object_is_type(struct json_object *jso, enum json_type type) in json_object_is_type() argument
211 if (!jso) in json_object_is_type()
213 return (jso->o_type == type); in json_object_is_type()
216 enum json_type json_object_get_type(struct json_object *jso) in json_object_get_type() argument
218 if (!jso) in json_object_get_type()
220 return jso->o_type; in json_object_get_type()
225 void json_object_set_serializer(json_object *jso, in json_object_set_serializer() argument
231 if (jso->_user_delete) in json_object_set_serializer()
233 jso->_user_delete(jso, jso->_userdata); in json_object_set_serializer()
235 jso->_userdata = NULL; in json_object_set_serializer()
236 jso->_user_delete = NULL; in json_object_set_serializer()
241 switch(jso->o_type) in json_object_set_serializer()
244 jso->_to_json_string = NULL; in json_object_set_serializer()
247 jso->_to_json_string = &json_object_boolean_to_json_string; in json_object_set_serializer()
250 jso->_to_json_string = &json_object_double_to_json_string; in json_object_set_serializer()
253 jso->_to_json_string = &json_object_int_to_json_string; in json_object_set_serializer()
256 jso->_to_json_string = &json_object_object_to_json_string; in json_object_set_serializer()
259 jso->_to_json_string = &json_object_array_to_json_string; in json_object_set_serializer()
262 jso->_to_json_string = &json_object_string_to_json_string; in json_object_set_serializer()
268 jso->_to_json_string = to_string_func; in json_object_set_serializer()
269 jso->_userdata = userdata; in json_object_set_serializer()
270 jso->_user_delete = user_delete; in json_object_set_serializer()
276 const char* json_object_to_json_string_ext(struct json_object *jso, int flags) in json_object_to_json_string_ext() argument
278 if (!jso) in json_object_to_json_string_ext()
281 if ((!jso->_pb) && !(jso->_pb = printbuf_new())) in json_object_to_json_string_ext()
284 printbuf_reset(jso->_pb); in json_object_to_json_string_ext()
286 if(jso->_to_json_string(jso, jso->_pb, 0, flags) < 0) in json_object_to_json_string_ext()
289 return jso->_pb->buf; in json_object_to_json_string_ext()
294 const char* json_object_to_json_string(struct json_object *jso) in json_object_to_json_string() argument
296 return json_object_to_json_string_ext(jso, JSON_C_TO_STRING_SPACED); in json_object_to_json_string()
309 static int json_object_object_to_json_string(struct json_object* jso, in json_object_object_to_json_string() argument
320 json_object_object_foreachC(jso, iter) in json_object_object_to_json_string()
362 static void json_object_object_delete(struct json_object* jso) in json_object_object_delete() argument
364 lh_table_free(jso->o.c_object); in json_object_object_delete()
365 json_object_generic_delete(jso); in json_object_object_delete()
370 struct json_object *jso = json_object_new(json_type_object); in json_object_new_object() local
371 if (!jso) in json_object_new_object()
373 jso->_delete = &json_object_object_delete; in json_object_new_object()
374 jso->_to_json_string = &json_object_object_to_json_string; in json_object_new_object()
375 jso->o.c_object = lh_kchar_table_new(JSON_OBJECT_DEF_HASH_ENTRIES, in json_object_new_object()
377 if (!jso->o.c_object) in json_object_new_object()
379 json_object_generic_delete(jso); in json_object_new_object()
383 return jso; in json_object_new_object()
386 struct lh_table* json_object_get_object(struct json_object *jso) in json_object_get_object() argument
388 if (!jso) in json_object_get_object()
390 switch(jso->o_type) in json_object_get_object()
393 return jso->o.c_object; in json_object_get_object()
399 void json_object_object_add(struct json_object* jso, const char *key, in json_object_object_add() argument
406 existing_entry = lh_table_lookup_entry(jso->o.c_object, (void*)key); in json_object_object_add()
409 lh_table_insert(jso->o.c_object, strdup(key), val); in json_object_object_add()
418 int json_object_object_length(struct json_object *jso) in json_object_object_length() argument
420 return lh_table_length(jso->o.c_object); in json_object_object_length()
423 struct json_object* json_object_object_get(struct json_object* jso, const char *key) in json_object_object_get() argument
426 json_object_object_get_ex(jso, key, &result); in json_object_object_get()
430 json_bool json_object_object_get_ex(struct json_object* jso, const char *key, struct json_object **… in json_object_object_get_ex() argument
435 if (NULL == jso) in json_object_object_get_ex()
438 switch(jso->o_type) in json_object_object_get_ex()
441 return lh_table_lookup_ex(jso->o.c_object, (void*)key, (void**)value); in json_object_object_get_ex()
449 void json_object_object_del(struct json_object* jso, const char *key) in json_object_object_del() argument
451 lh_table_delete(jso->o.c_object, key); in json_object_object_del()
457 static int json_object_boolean_to_json_string(struct json_object* jso, in json_object_boolean_to_json_string() argument
462 if (jso->o.c_boolean) in json_object_boolean_to_json_string()
470 struct json_object *jso = json_object_new(json_type_boolean); in json_object_new_boolean() local
471 if (!jso) in json_object_new_boolean()
473 jso->_to_json_string = &json_object_boolean_to_json_string; in json_object_new_boolean()
474 jso->o.c_boolean = b; in json_object_new_boolean()
475 return jso; in json_object_new_boolean()
478 json_bool json_object_get_boolean(struct json_object *jso) in json_object_get_boolean() argument
480 if (!jso) in json_object_get_boolean()
482 switch(jso->o_type) in json_object_get_boolean()
485 return jso->o.c_boolean; in json_object_get_boolean()
487 return (jso->o.c_int64 != 0); in json_object_get_boolean()
489 return (jso->o.c_double != 0); in json_object_get_boolean()
491 return (jso->o.c_string.len != 0); in json_object_get_boolean()
500 static int json_object_int_to_json_string(struct json_object* jso, in json_object_int_to_json_string() argument
505 return sprintbuf(pb, "%"PRId64, jso->o.c_int64); in json_object_int_to_json_string()
510 struct json_object *jso = json_object_new(json_type_int); in json_object_new_int() local
511 if (!jso) in json_object_new_int()
513 jso->_to_json_string = &json_object_int_to_json_string; in json_object_new_int()
514 jso->o.c_int64 = i; in json_object_new_int()
515 return jso; in json_object_new_int()
518 int32_t json_object_get_int(struct json_object *jso) in json_object_get_int() argument
523 if(!jso) return 0; in json_object_get_int()
525 o_type = jso->o_type; in json_object_get_int()
526 cint64 = jso->o.c_int64; in json_object_get_int()
534 if (json_parse_int64(jso->o.c_string.str, &cint64) != 0) in json_object_get_int()
549 return (int32_t)jso->o.c_double; in json_object_get_int()
551 return jso->o.c_boolean; in json_object_get_int()
559 struct json_object *jso = json_object_new(json_type_int); in json_object_new_int64() local
560 if (!jso) in json_object_new_int64()
562 jso->_to_json_string = &json_object_int_to_json_string; in json_object_new_int64()
563 jso->o.c_int64 = i; in json_object_new_int64()
564 return jso; in json_object_new_int64()
567 int64_t json_object_get_int64(struct json_object *jso) in json_object_get_int64() argument
571 if (!jso) in json_object_get_int64()
573 switch(jso->o_type) in json_object_get_int64()
576 return jso->o.c_int64; in json_object_get_int64()
578 return (int64_t)jso->o.c_double; in json_object_get_int64()
580 return jso->o.c_boolean; in json_object_get_int64()
582 if (json_parse_int64(jso->o.c_string.str, &cint) == 0) in json_object_get_int64()
592 static int json_object_double_to_json_string(struct json_object* jso, in json_object_double_to_json_string() argument
603 if(isnan(jso->o.c_double)) in json_object_double_to_json_string()
605 else if(isinf(jso->o.c_double)) in json_object_double_to_json_string()
606 if(jso->o.c_double > 0) in json_object_double_to_json_string()
611 size = snprintf(buf, sizeof(buf), "%.17g", jso->o.c_double); in json_object_double_to_json_string()
635 struct json_object *jso = json_object_new(json_type_double); in json_object_new_double() local
636 if (!jso) in json_object_new_double()
638 jso->_to_json_string = &json_object_double_to_json_string; in json_object_new_double()
639 jso->o.c_double = d; in json_object_new_double()
640 return jso; in json_object_new_double()
645 struct json_object *jso = json_object_new_double(d); in json_object_new_double_s() local
646 if (!jso) in json_object_new_double_s()
652 json_object_generic_delete(jso); in json_object_new_double_s()
656 json_object_set_serializer(jso, json_object_userdata_to_json_string, in json_object_new_double_s()
658 return jso; in json_object_new_double_s()
661 int json_object_userdata_to_json_string(struct json_object *jso, in json_object_userdata_to_json_string() argument
664 int userdata_len = strlen(jso->_userdata); in json_object_userdata_to_json_string()
665 printbuf_memappend(pb, jso->_userdata, userdata_len); in json_object_userdata_to_json_string()
669 void json_object_free_userdata(struct json_object *jso, void *userdata) in json_object_free_userdata() argument
674 double json_object_get_double(struct json_object *jso) in json_object_get_double() argument
679 if(!jso) return 0.0; in json_object_get_double()
680 switch(jso->o_type) { in json_object_get_double()
682 return jso->o.c_double; in json_object_get_double()
684 return jso->o.c_int64; in json_object_get_double()
686 return jso->o.c_boolean; in json_object_get_double()
689 cdouble = strtod(jso->o.c_string.str,&errPtr); in json_object_get_double()
692 if (errPtr == jso->o.c_string.str) in json_object_get_double()
726 static int json_object_string_to_json_string(struct json_object* jso, in json_object_string_to_json_string() argument
732 json_escape_str(pb, jso->o.c_string.str, jso->o.c_string.len); in json_object_string_to_json_string()
737 static void json_object_string_delete(struct json_object* jso) in json_object_string_delete() argument
739 free(jso->o.c_string.str); in json_object_string_delete()
740 json_object_generic_delete(jso); in json_object_string_delete()
745 struct json_object *jso = json_object_new(json_type_string); in json_object_new_string() local
746 if (!jso) in json_object_new_string()
748 jso->_delete = &json_object_string_delete; in json_object_new_string()
749 jso->_to_json_string = &json_object_string_to_json_string; in json_object_new_string()
750 jso->o.c_string.str = strdup(s); in json_object_new_string()
751 if (!jso->o.c_string.str) in json_object_new_string()
753 json_object_generic_delete(jso); in json_object_new_string()
757 jso->o.c_string.len = strlen(s); in json_object_new_string()
758 return jso; in json_object_new_string()
763 struct json_object *jso = json_object_new(json_type_string); in json_object_new_string_len() local
764 if (!jso) in json_object_new_string_len()
766 jso->_delete = &json_object_string_delete; in json_object_new_string_len()
767 jso->_to_json_string = &json_object_string_to_json_string; in json_object_new_string_len()
768 jso->o.c_string.str = (char*)malloc(len + 1); in json_object_new_string_len()
769 if (!jso->o.c_string.str) in json_object_new_string_len()
771 json_object_generic_delete(jso); in json_object_new_string_len()
775 memcpy(jso->o.c_string.str, (void *)s, len); in json_object_new_string_len()
776 jso->o.c_string.str[len] = '\0'; in json_object_new_string_len()
777 jso->o.c_string.len = len; in json_object_new_string_len()
778 return jso; in json_object_new_string_len()
781 const char* json_object_get_string(struct json_object *jso) in json_object_get_string() argument
783 if (!jso) in json_object_get_string()
785 switch(jso->o_type) in json_object_get_string()
788 return jso->o.c_string.str; in json_object_get_string()
790 return json_object_to_json_string(jso); in json_object_get_string()
794 int json_object_get_string_len(struct json_object *jso) in json_object_get_string_len() argument
796 if (!jso) in json_object_get_string_len()
798 switch(jso->o_type) in json_object_get_string_len()
801 return jso->o.c_string.len; in json_object_get_string_len()
810 static int json_object_array_to_json_string(struct json_object* jso, in json_object_array_to_json_string() argument
820 for(ii=0; ii < json_object_array_length(jso); ii++) in json_object_array_to_json_string()
833 val = json_object_array_get_idx(jso, ii); in json_object_array_to_json_string()
857 static void json_object_array_delete(struct json_object* jso) in json_object_array_delete() argument
859 array_list_free(jso->o.c_array); in json_object_array_delete()
860 json_object_generic_delete(jso); in json_object_array_delete()
865 struct json_object *jso = json_object_new(json_type_array); in json_object_new_array() local
866 if (!jso) in json_object_new_array()
868 jso->_delete = &json_object_array_delete; in json_object_new_array()
869 jso->_to_json_string = &json_object_array_to_json_string; in json_object_new_array()
870 jso->o.c_array = array_list_new(&json_object_array_entry_free); in json_object_new_array()
871 return jso; in json_object_new_array()
874 struct array_list* json_object_get_array(struct json_object *jso) in json_object_get_array() argument
876 if (!jso) in json_object_get_array()
878 switch(jso->o_type) in json_object_get_array()
881 return jso->o.c_array; in json_object_get_array()
887 void json_object_array_sort(struct json_object *jso, int(*sort_fn)(const void *, const void *)) in json_object_array_sort() argument
889 array_list_sort(jso->o.c_array, sort_fn); in json_object_array_sort()
892 int json_object_array_length(struct json_object *jso) in json_object_array_length() argument
894 return array_list_length(jso->o.c_array); in json_object_array_length()
897 int json_object_array_add(struct json_object *jso,struct json_object *val) in json_object_array_add() argument
899 return array_list_add(jso->o.c_array, val); in json_object_array_add()
902 int json_object_array_put_idx(struct json_object *jso, int idx, in json_object_array_put_idx() argument
905 return array_list_put_idx(jso->o.c_array, idx, val); in json_object_array_put_idx()
908 struct json_object* json_object_array_get_idx(struct json_object *jso, in json_object_array_get_idx() argument
911 return (struct json_object*)array_list_get_idx(jso->o.c_array, idx); in json_object_array_get_idx()