void t12_dict_in_dict(){ INIT_LOCAL(); onion_dict *A=onion_dict_new(); onion_dict *B=onion_dict_new(); onion_dict *C=onion_dict_new(); onion_dict *D=onion_dict_new(); int i; for (i=0;i<16;i++){ char tmp[9]; sprintf(tmp,"%08X",rand()); onion_dict_add(A, tmp, tmp, OD_DUP_ALL); sprintf(tmp,"%08X",rand()); onion_dict_add(B, tmp, tmp, OD_DUP_ALL); sprintf(tmp,"%08X",rand()); onion_dict_add(C, tmp, tmp, OD_DUP_ALL); sprintf(tmp,"%08X",rand()); onion_dict_add(D, tmp, tmp, OD_DUP_ALL); } onion_dict_add(A, "B", B, OD_DICT|OD_FREE_VALUE); onion_dict_add(A, "C", C, OD_DICT|OD_FREE_VALUE); onion_dict_add(A, "D", D, OD_DICT|OD_FREE_VALUE); FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get(A, "B"), NULL); FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get(A, "C"), NULL); FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get(A, "D"), NULL); FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get_dict(A, "B"), B); FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get_dict(A, "C"), C); FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get_dict(A, "D"), D); { onion_block *tmpA=onion_dict_to_json(A); onion_block *tmpB=onion_dict_to_json(B); onion_block *tmpC=onion_dict_to_json(C); onion_block *tmpD=onion_dict_to_json(D); /* ONION_DEBUG("Json is: %s",tmpA); ONION_DEBUG("Json is: %s",tmpB); ONION_DEBUG("Json is: %s",tmpC); ONION_DEBUG("Json is: %s",tmpD); */ FAIL_IF_EQUAL( strstr(onion_block_data(tmpA), onion_block_data(tmpB)), NULL); FAIL_IF_EQUAL( strstr(onion_block_data(tmpA), onion_block_data(tmpC)), NULL); FAIL_IF_EQUAL( strstr(onion_block_data(tmpA), onion_block_data(tmpD)), NULL); onion_block_free(tmpA); onion_block_free(tmpB); onion_block_free(tmpC); onion_block_free(tmpD); } B=onion_dict_hard_dup(A); onion_dict_free(A); onion_dict_free(B); END_LOCAL(); }
void cmpdict(onion_dict *d, const char *key, const char *value, int flags){ if (flags&OD_DICT){ onion_dict_preorder((onion_dict*)value, cmpdict, onion_dict_get_dict(d, key)); onion_dict_preorder(onion_dict_get_dict(d, key), cmpdict, (onion_dict*)value); } else FAIL_IF_NOT_EQUAL_STR(value, onion_dict_get(d, key)); }
static onion_dict *onion_sessions_mem_get(onion_sessions *sessions, const char *session_id){ ONION_DEBUG0("Accessing session '%s'",session_id); onion_dict *sess=onion_dict_get_dict(sessions->data, session_id); if (!sess){ ONION_DEBUG0("Unknown session '%s'.", session_id); return NULL; } return onion_dict_dup(sess); }
static void onion_sessions_mem_save(onion_sessions *sessions, const char *session_id, onion_dict *data){ if (data==NULL){ data=onion_dict_get_dict(sessions->data, session_id); if (data){ onion_dict_remove(sessions->data, session_id); } return; } onion_dict_add(sessions->data, session_id, onion_dict_dup(data), OD_DUP_KEY|OD_FREE_VALUE|OD_DICT|OD_REPLACE); }
/** * @short Gets a dictionary dict value, recursively * @memberof onion_dict_t * * Loops inside given dictionaries to get the given value * * @param dict The dictionary * @param key The key list, one per arg, end with NULL * @returns The const string if valid, or NULL */ onion_dict *onion_dict_rget_dict(const onion_dict *dict, const char *key, ...){ onion_dict *d=(onion_dict*)dict; const char *k=key; va_list va; va_start(va, key); while (d){ d=onion_dict_get_dict(d, k); k=va_arg(va, const char *); if (!k){ va_end(va); return d; } } va_end(va); return NULL; }
/** * @short Gets a dictionary string value, recursively * @memberof onion_dict_t * * Loops inside given dictionaries to get the given value * * @param dict The dictionary * @param key The key list, one per arg, end with NULL * @returns The const string if valid, or NULL */ const char *onion_dict_rget(const onion_dict *dict, const char *key, ...){ const onion_dict *d=dict; const char *k=key; const char *nextk; va_list va; va_start(va, key); while (d){ nextk=va_arg(va, const char *); if (!nextk){ va_end(va); return onion_dict_get(d, k); } d=onion_dict_get_dict(d, k); k=nextk; } va_end(va); return NULL; }
/** * @short Returns a subdictionary. * * For a given key, returns the subdictionary. */ Dict getDict(const std::string &k) const{ return Dict(onion_dict_get_dict(ptr, k.c_str())); }