static void JsonAddPacketvars(const Packet *p, json_t *js_vars) { if (p == NULL || p->pktvar == NULL) { return; } json_t *js_pktvars = NULL; PktVar *pv = p->pktvar; while (pv != NULL) { if (pv->key || pv->id > 0) { if (js_pktvars == NULL) { js_pktvars = json_array(); if (js_pktvars == NULL) break; } json_t *js_pair = json_object(); if (js_pair == NULL) { break; } if (pv->key != NULL) { uint32_t offset = 0; uint8_t keybuf[pv->key_len + 1]; PrintStringsToBuffer(keybuf, &offset, sizeof(keybuf), pv->key, pv->key_len); uint32_t len = pv->value_len; uint8_t printable_buf[len + 1]; offset = 0; PrintStringsToBuffer(printable_buf, &offset, sizeof(printable_buf), pv->value, pv->value_len); json_object_set_new(js_pair, (char *)keybuf, json_string((char *)printable_buf)); } else { const char *varname = VarNameStoreLookupById(pv->id, VAR_TYPE_PKT_VAR); uint32_t len = pv->value_len; uint8_t printable_buf[len + 1]; uint32_t offset = 0; PrintStringsToBuffer(printable_buf, &offset, sizeof(printable_buf), pv->value, pv->value_len); json_object_set_new(js_pair, varname, json_string((char *)printable_buf)); } json_array_append_new(js_pktvars, js_pair); } pv = pv->next; } if (js_pktvars) { json_object_set_new(js_vars, "pktvars", js_pktvars); } }
void graph_response_newLinkDataResponse(req_t * req, json_t * request, json_t * response, int32_t requestId, void *sweb, req_store_t * req_store) { if (strcmp (json_string_value(json_object_get(response, "ack")), "ok") == 0) { json_t *link = json_object_get(request, "link"); json_t *web_resp = json_object(); json_object_set_new(web_resp, "type", json_string("newLinkData")); //TODO at the moment only the original node gets the update, which is good enough for me json_t *sessionIds = json_array(); json_array_append (sessionIds, json_object_get(req->request, "sessionId")); json_object_set_new(web_resp, "sessionIds", sessionIds); json_t *newData = json_object(); json_t *newLinkData = json_array(); json_array_append(newLinkData, link); json_object_set_new(newData, "newLinkData", newLinkData); json_object_set_new(web_resp, "newData", newData); zmsg_t *res = zmsg_new(); char *web_res_str = json_dumps(web_resp, JSON_COMPACT); printf("\nbroker:sweb sent: %s\n", web_res_str); zmsg_addstr(res, web_res_str); free(web_res_str); zmsg_wrap(res, req->address); zmsg_send(&res, sweb); json_decref(web_resp); } else { } request_store_delete(req_store, requestId); }
int tid_req_add_path(TID_REQ *req, const char *this_system, unsigned port) { char *path_element = talloc_asprintf(req, "%s:%u", this_system, port); if (!req->path) { req->path = json_array(); if (!req->path) return -1; tid_req_cleanup_json(req, req->path); } return json_array_append( req->path, json_string(path_element)); }
TID_REQ *tid_req_new() { TID_REQ *req = talloc_zero(NULL, TID_REQ); if(!req) return NULL; talloc_set_destructor(req, destroy_tid_req); req->json_references = json_array(); assert(req->json_references); req->conn = -1; req->free_conn = 1; req->request_id = NULL; return req; }
static json_t * json_string_or_array(int nr, char **items) { if (nr == 1) { return json_string(items[0]); } json_t *result = json_array(); int i; for (i = 0; i < nr; ++i) { json_array_append_new(result, json_string(items[i])); } return result; }
/** * @param search The search result */ static void get_search(sp_search *search) { int i; json_t *json = json_object(); json_t *tracks = json_array(); json_object_set_new(json, "tracks", tracks); for (i = 0; i < sp_search_num_tracks(search); ++i){ json_array_append_new(tracks, get_track(sp_search_track(search, i))); } json_object_set_new_nocheck(json, "query", json_string_nocheck(sp_search_query(search))); cmd_sendresponse(json, 200); }
json_t * bck_host_file_read(json_t * obj) { char * interface = (char *)json_string_value(json_object_get(obj,"int")); char * date = (char *)json_string_value(json_object_get(obj,"hostfile")); char * filename; filename = (char *)calloc(SIZE,sizeof(char)); sprintf(filename,"/etc/statistics/darkstat/%s_hosts_%s.txt",date,interface); //printf("This is the file name to read: %s\n",filename); json_t * ret = json_array(); ret = get_top_hosts(filename); free(filename); return(ret); }
char * MessageBuilder::buildRegister( int port, char const** hears, int hearsSize, char const** plays, int playsSize ) const { json_t *array = json_array(); json_array_append_new(array, json_string("register")); json_array_append_new(array, json_string(lemmaId)); json_array_append_new(array, json_integer(port)); string_array_append_new(array, hears, hearsSize); string_array_append_new(array, plays, playsSize); char * string = json_dumps(array, 0); json_decref(array); return string; }
char * MessageBuilder::buildMarco(const char* roomName) { json_t *array = json_array(); json_array_append_new(array, json_string("marco")); json_array_append_new(array, json_string(lemmaId)); json_array_append_new(array, json_string(roomName)); json_array_append_new(array, json_string("cpp")); json_array_append_new(array, json_string("1.1")); char * string = json_dumps(array, 0); json_decref(array); return string; }
/** * Initializes the device type by getting its uid, name and description */ json_t * b_device_type_init () { json_t * options = json_array(); json_array_append_new(options, json_pack("{ssssssso}", "name", "uri", "type", "string", "description", "uri to connect to the device", "optional", json_false())); json_array_append_new(options, json_pack("{ssssssso}", "name", "baud", "type", "numeric", "description", "speed of the device communication", "optional", json_false())); json_array_append_new(options, json_pack("{ssssssso}", "name", "do_not_check_certificate", "type", "boolean", "description", "check the certificate of the device if needed", "optional", json_true())); json_array_append_new(options, json_pack("{ssssssso}", "name", "device_specified", "type", "string", "description", "specified by the device when connected for the first time, then must be sent back at every other connection", "optional", json_true())); return json_pack("{sissssssso}", "result", WEBSERVICE_RESULT_OK, "uid", "00-00-00", "name", "Another Mock Device", "description", "This is another mock device, for development and debug purposes", "options", options); }
static void test_chaos() { json_malloc_t orig_malloc; json_free_t orig_free; json_t *json = NULL; json_t *obj = json_object(); json_t *arr1 = json_array(); json_t *arr2 = json_array(); json_t *txt = json_string("test"); json_t *intnum = json_integer(1); json_t *dblnum = json_real(0.5); char *dumptxt = NULL; json_t *dumpobj = json_pack("{s:[iiis], s:s}", "key1", 1, 2, 3, "txt", "key2", "v2"); int keyno; if (!obj || !arr1 || !arr2 || !txt || !intnum || !dblnum || !dumpobj) fail("failed to allocate basic objects"); json_get_alloc_funcs(&orig_malloc, &orig_free); json_set_alloc_funcs(chaos_malloc, chaos_free); chaos_loop_new_value(json, json_pack("{s:s}", "key", "value")); chaos_loop_new_value(json, json_pack("{s:[]}", "key")); chaos_loop_new_value(json, json_pack("[biIf]", 1, 1, (json_int_t)1, 1.0)); chaos_loop_new_value(json, json_pack("[s*,s*]", "v1", "v2")); chaos_loop_new_value(json, json_pack("o", json_incref(txt))); chaos_loop_new_value(json, json_pack("O", txt)); chaos_loop_new_value(json, json_pack("s++", "a", "long string to force realloc", "another long string to force yet another reallocation of the string because " "that's what we are testing.")); chaos_loop(test_unpack(),,); chaos_loop(json_dump_callback(dumpobj, dump_chaos_callback, NULL, JSON_INDENT(1)),,); chaos_loop(json_dump_callback(dumpobj, dump_chaos_callback, NULL, JSON_INDENT(1) | JSON_SORT_KEYS),,); chaos_loop(!dumptxt, dumptxt = json_dumps(dumpobj, JSON_COMPACT);, free(dumptxt); dumptxt = NULL;);
json_t* dump_headers(const nghttp2_nv *nva, size_t nvlen) { json_t *headers; size_t i; headers = json_array(); for(i = 0; i < nvlen; ++i) { json_array_append_new(headers, dump_header(nva[i].name, nva[i].namelen, nva[i].value, nva[i].valuelen)); } return headers; }
int32 rf_evt_pack_json(json_t *result, const int32 *evt_types, rf_evt_svc_t *service) { int32 i = 0; json_t *types_array = NULL; json_t *listener = NULL; json_t *status = NULL; json_object_add(result, RMM_JSON_ODATA_CONTEXT, json_string(service->links.odata_context)); json_object_add(result, RMM_JSON_ODATA_ID, json_string(service->links.odata_id)); add_json_string(result, RMM_JSON_ODATA_TYPE, service->fixed.odata_type); add_json_string(result, RMM_JSON_RF_ID, service->fixed.id); add_json_string(result, RMM_JSON_RF_NAME, service->fixed.name); status = json_object(); if (status != NULL) { add_json_string(status, RMM_JSON_RF_STATUS_STATE, service->fixed.status.state); add_json_string(status, RMM_JSON_RF_STATUS_HEALTH, service->fixed.status.health); } json_object_add(result, RMM_JSON_RF_STATUS, status); if (service->fixed.service_enabled) json_object_add(result, RMM_JSON_RF_SERVICE_ENABLED, json_true()); else json_object_add(result, RMM_JSON_RF_SERVICE_ENABLED, json_false()); add_json_integer(result, RMM_JSON_RF_DELIVERY_RETRY, service->fixed.retry); add_json_integer(result, RMM_JSON_RF_DELIVERY_RETRY_INTERVAL, service->fixed.retry_interval); types_array = json_array(); if (types_array == NULL) return -1; for (i = 0; i < MAX_EVT_ACTION_NUM; i++) { if (evt_types[i] == 0) continue; json_array_add(types_array, json_string((int8 *)rf_evt_msg[i].type_name)); } json_object_add(result, RMM_JSON_RF_SUPPORTED_EVT_TYPES, types_array); listener = json_object(); if (listener == NULL) return -1; add_json_string(listener, RMM_JSON_ODATA_ID, service->links.subscriptions); json_object_add(result, RMM_JSON_RF_SUBSCRIPTION, listener); return 0; }
json_t *json_pack_updates (unsigned flags) { json_t *a = json_array (); if (flags & TGL_UPDATE_CREATED) { assert (json_array_append (a, json_string ("created")) >= 0); } if (flags & TGL_UPDATE_DELETED) { assert (json_array_append (a, json_string ("deleted")) >= 0); } if (flags & TGL_UPDATE_PHONE) { assert (json_array_append (a, json_string ("phone")) >= 0); } if (flags & TGL_UPDATE_CONTACT) { assert (json_array_append (a, json_string ("contact")) >= 0); } if (flags & TGL_UPDATE_PHOTO) { assert (json_array_append (a, json_string ("photo")) >= 0); } if (flags & TGL_UPDATE_BLOCKED) { assert (json_array_append (a, json_string ("blocked")) >= 0); } if (flags & TGL_UPDATE_REAL_NAME) { assert (json_array_append (a, json_string ("real_name")) >= 0); } if (flags & TGL_UPDATE_NAME) { assert (json_array_append (a, json_string ("name")) >= 0); } if (flags & TGL_UPDATE_REQUESTED) { assert (json_array_append (a, json_string ("requested")) >= 0); } if (flags & TGL_UPDATE_WORKING) { assert (json_array_append (a, json_string ("working")) >= 0); } if (flags & TGL_UPDATE_FLAGS) { assert (json_array_append (a, json_string ("flags")) >= 0); } if (flags & TGL_UPDATE_TITLE) { assert (json_array_append (a, json_string ("title")) >= 0); } if (flags & TGL_UPDATE_ADMIN) { assert (json_array_append (a, json_string ("admin")) >= 0); } if (flags & TGL_UPDATE_MEMBERS) { assert (json_array_append (a, json_string ("members")) >= 0); } if (flags & TGL_UPDATE_USERNAME) { assert (json_array_append (a, json_string ("username")) >= 0); } return a; }
void Patch::writeChannels(json_t *jContainer, vector<channel_t> *channels) { json_t *jChannels = json_array(); for (unsigned i=0; i<channels->size(); i++) { json_t *jChannel = json_object(); channel_t channel = channels->at(i); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_TYPE, json_integer(channel.type)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_INDEX, json_integer(channel.index)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_COLUMN, json_integer(channel.column)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MUTE, json_integer(channel.mute)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MUTE_S, json_integer(channel.mute_s)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_SOLO, json_integer(channel.solo)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_VOLUME, json_real(channel.volume)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_PAN_LEFT, json_real(channel.panLeft)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_PAN_RIGHT, json_real(channel.panRight)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN, json_boolean(channel.midiIn)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_KEYPRESS, json_integer(channel.midiInKeyPress)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_KEYREL, json_integer(channel.midiInKeyRel)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_KILL, json_integer(channel.midiInKill)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_ARM, json_integer(channel.midiInArm)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_VOLUME, json_integer(channel.midiInVolume)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_MUTE, json_integer(channel.midiInMute)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_SOLO, json_integer(channel.midiInSolo)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_OUT_L, json_boolean(channel.midiOutL)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_OUT_L_PLAYING, json_integer(channel.midiOutLplaying)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_OUT_L_MUTE, json_integer(channel.midiOutLmute)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_OUT_L_SOLO, json_integer(channel.midiOutLsolo)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_SAMPLE_PATH, json_string(channel.samplePath.c_str())); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_KEY, json_integer(channel.key)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MODE, json_integer(channel.mode)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_BEGIN, json_integer(channel.begin)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_END, json_integer(channel.end)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_BOOST, json_real(channel.boost)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_REC_ACTIVE, json_integer(channel.recActive)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_PITCH, json_real(channel.pitch)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_READ_ACTIONS, json_integer(channel.midiInReadActions)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_IN_PITCH, json_integer(channel.midiInPitch)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_OUT, json_integer(channel.midiOut)); json_object_set_new(jChannel, PATCH_KEY_CHANNEL_MIDI_OUT_CHAN, json_integer(channel.midiOutChan)); json_array_append_new(jChannels, jChannel); writeActions(jChannel, &channel.actions); #ifdef WITH_VST writePlugins(jChannel, &channel.plugins, PATCH_KEY_CHANNEL_PLUGINS); #endif } json_object_set_new(jContainer, PATCH_KEY_CHANNELS, jChannels); }
static json_t * json_symarray(struct nh_symdef *array, int len) { int i; json_t *jarr, *jobj; jarr = json_array(); for (i = 0; i < len; i++) { jobj = json_pack("[s,i,i]", array[i].symname, array[i].ch, array[i].color); json_array_append_new(jarr, jobj); } return jarr; }
static void fsmonitor_callback(fsdiff_t *diff, void *data) { item_t *item = (item_t *)data; json_t *json = json_array(); int count = fsdiff_count(diff); for (int i = 0; i < count; ++i) json_array_append(json, json_string(fsdiff_get(diff, i))); fsdiff_free(diff); change_t *change = (change_t *)malloc(sizeof(change_t)); change->id = json_incref(item->id); change->diff = json; invoke_on_main_thread(fsmonitor_callback_main_thread, change); }
json_t* bser2json(bser_t* bser) { if (bser_is_integer(bser)) { json_int_t v = bser_integer_value(bser); return json_integer(v); } else if (bser_is_real(bser)) { double v = bser_real_value(bser); return json_real(v); } else if (bser_is_true(bser)) { return json_true(); } else if (bser_is_false(bser)) { return json_false(); } else if (bser_is_null(bser)) { return json_null(); } else if (bser_is_string(bser)) { size_t length; const char* str = bser_string_value(bser, &length); char* dup = strndup(str, length); json_t* string = json_string(dup); free(dup); return string; } else if (bser_is_array(bser)) { size_t length = bser_array_size(bser); json_t* array = json_array(); for (int i = 0; i < length; ++i) { json_array_append_new(array, bser2json(bser_array_get(bser, i))); } return array; } else if (bser_is_object(bser)) { size_t length = bser_object_size(bser); json_t* object = json_object(); for (int i = 0; i < length; ++i) { size_t key_length; bser_t* key = bser_object_key_at(bser, i); assert(bser_is_string(key)); bser_t* value = bser_object_value_at(bser, i); if (!bser_is_no_field(value)) { const char* key_chars = bser_string_value(key, &key_length); assert(key_chars != NULL && *key_chars != '\0'); char* key_dup = strndup(key_chars, key_length); json_object_set_new(object, key_dup, bser2json(value)); free(key_dup); } } return object; } else { return NULL; } }
static void get_playlist_subscribers(sp_playlist *playlist, struct evhttp_request *request, void *userdata) { assert(sp_playlist_is_loaded(playlist)); sp_subscribers *subscribers = sp_playlist_subscribers(playlist); json_t *array = json_array(); for (int i = 0; i < subscribers->count; i++) { char *subscriber = subscribers->subscribers[i]; json_array_append_new(array, json_string(subscriber)); } send_reply_json(request, HTTP_OK, "OK", array); }
void Patch::writeActions(json_t *jContainer, vector<action_t> *actions) { json_t *jActions = json_array(); for (unsigned k=0; k<actions->size(); k++) { json_t *jAction = json_object(); action_t action = actions->at(k); json_object_set_new(jAction, PATCH_KEY_ACTION_TYPE, json_integer(action.type)); json_object_set_new(jAction, PATCH_KEY_ACTION_FRAME, json_integer(action.frame)); json_object_set_new(jAction, PATCH_KEY_ACTION_F_VALUE, json_real(action.fValue)); json_object_set_new(jAction, PATCH_KEY_ACTION_I_VALUE, json_integer(action.iValue)); json_array_append_new(jActions, jAction); } json_object_set_new(jContainer, PATCH_KEY_CHANNEL_ACTIONS, jActions); }
static json_t *json_array_deep_copy(json_t *array) { json_t *result; unsigned int i; result = json_array(); if(!result) return NULL; for(i = 0; i < json_array_size(array); i++) json_array_append_new(result, json_deep_copy(json_array_get(array, i))); return result; }
Json::Json( json_type v ): data(NULL) { switch ( v ) { case JSON_ARRAY: data = json_array(); break; case JSON_OBJECT: data = json_object(); break; case JSON_FALSE: data = json_boolean(false); break; case JSON_TRUE: data = json_boolean(true); break; case JSON_INTEGER: data = json_integer(0); break; case JSON_REAL: data = json_real(0); break; case JSON_STRING: data = json_string(""); break; default: data = json_null(); break; } }
static json_t *create_array() { json_t *array; array = json_array(); if(!array) fail("unable to create an array"); if(json_array_append_new(array, json_integer(1)) || json_array_append_new(array, json_integer(2))) fail("unable to append array values"); return array; }
json_t *pug_module_dump(pug_module_t *module) { json_t *jmodule = json_object(); json_object_set(jmodule, "name", json_bstring(module->name)); json_t *jfunctions = json_array(); for (int i = 0; i < vector_pug_function_size(&module->functions); i++) { pug_function_t *function = vector_pug_function_get(&module->functions, i); json_t *jfunction = pug_function_dump(function); json_array_append(jfunctions, jfunction); } json_object_set(jmodule, "functions", jfunctions); return jmodule; }
static void _json_write(FILE * file, json_t json, unsigned int depth) { switch (json_type(json)) { case ARRAY: _json_write_array(file, json_array(json), depth); break; case OBJECT: _json_write_object(file, json_object(json), depth); break; case STRING: _json_write_string(file, json_string(json)); break; }; }
void pilot::JSONFileHandler::startArrayWrite(const char* name, size_t, bool) { auto array = json_array(); if (json_is_array(_currentEl)) { // We are in an array, section must be unnamed Assertion(name == nullptr, "Inside an array there can be no named section!"); json_array_append_new(_currentEl, array); } else { Assertion(name != nullptr, "Section outside of arrays must be named!"); json_object_set_new(_currentEl, name, array); } _currentEl = array; _elementStack.push_back(_currentEl); }
static json_t *json_array_copy(json_t *array) { json_t *result; size_t i; result = json_array(); if(!result) return NULL; for(i = 0; i < json_array_size(array); i++) json_array_append(result, json_array_get(array, i)); return result; }
json_t * fields_to_json(int fields) { json_t *result = json_array(); int i = 0; int mask; for (mask = 1; mask < WATCHMAN_FIELD_END; mask *= 2) { if (fields & mask) { json_array_append_new(result, json_string(fields_str[i])); } ++i; } return result; }
json_t *pug_function_dump(pug_function_t *function) { json_t *jfunction = json_object(); json_object_set(jfunction, "name", json_bstring(function->name)); json_t *jarguments = json_array(); for (int i = 0; i < vector_pug_argument_size(&function->arguments); i++) { pug_argument_t *argument = vector_pug_argument_get(&function->arguments, i); json_t *jargument = json_object(); json_object_set(jargument, "name", json_bstring(argument->name)); json_array_append(jarguments, jargument); } json_object_set(jfunction, "arguments", jarguments); return jfunction; }
void LoopCacheSave(JSON Root) { EXCLUSIVE_ACQUIRE(LockLoops); // Create the root JSON objects const JSON jsonLoops = json_array(); const JSON jsonAutoLoops = json_array(); // Write all entries for(auto & itr : loops) { const LOOPSINFO & currentLoop = itr.second; JSON currentJson = json_object(); json_object_set_new(currentJson, "module", json_string(currentLoop.mod)); json_object_set_new(currentJson, "start", json_hex(currentLoop.start)); json_object_set_new(currentJson, "end", json_hex(currentLoop.end)); json_object_set_new(currentJson, "depth", json_integer(currentLoop.depth)); json_object_set_new(currentJson, "parent", json_hex(currentLoop.parent)); if(currentLoop.manual) json_array_append_new(jsonLoops, currentJson); else json_array_append_new(jsonAutoLoops, currentJson); } // Append a link to the global root if(json_array_size(jsonLoops)) json_object_set(Root, "loops", jsonLoops); if(json_array_size(jsonAutoLoops)) json_object_set(Root, "autoloops", jsonAutoLoops); // Release memory/references json_decref(jsonLoops); json_decref(jsonAutoLoops); }