void LabelCacheSave(JSON Root) { EXCLUSIVE_ACQUIRE(LockLabels); // Create the sub-root structures in memory const JSON jsonLabels = json_array(); const JSON jsonAutoLabels = json_array(); // Iterator each label for(auto & itr : labels) { JSON jsonLabel = json_object(); json_object_set_new(jsonLabel, "module", json_string(itr.second.mod)); json_object_set_new(jsonLabel, "address", json_hex(itr.second.addr)); json_object_set_new(jsonLabel, "text", json_string(itr.second.text)); // Was the label manually added? if(itr.second.manual) json_array_append_new(jsonLabels, jsonLabel); else json_array_append_new(jsonAutoLabels, jsonLabel); } // Apply the object to the global root if(json_array_size(jsonLabels)) json_object_set(Root, "labels", jsonLabels); if(json_array_size(jsonAutoLabels)) json_object_set(Root, "autolabels", jsonAutoLabels); json_decref(jsonLabels); json_decref(jsonAutoLabels); }
char *serialize_result(const struct data_t *result, const char *error) { char *data = NULL; json_t *root = json_object(); if(!root) { return NULL; } json_t *json_result_type; json_t *json_result; if(error) { json_result_type = json_string("ERROR"); json_result = json_string(error); if(!json_result_type || json_object_set(root, RESULT_TYPE_JSON_KEY, json_result_type) || !json_result || json_object_set(root, RESULT_JSON_KEY, json_result)) { goto error; } } else { json_result_type = json_string("SUCCESS"); json_result = jsonize_param(result); if(!json_result_type || json_object_set(root, RESULT_TYPE_JSON_KEY, json_result_type) || !json_result || json_object_set(root, RESULT_JSON_KEY, json_result)) { goto error; } } data = json_dumps(root, JSON_COMPACT | JSON_PRESERVE_ORDER); error: if(json_result) json_decref(json_result); if(json_result_type) json_decref(json_result_type); if(root) json_decref(root); return data; }
static int get_port_obj(json_t **pport_obj, json_t *config_json, const char *port_name) { int err; json_t *ports_obj; json_t *port_obj; err = json_unpack(config_json, "{s:o}", "ports", &ports_obj); if (err) { ports_obj = json_object(); if (!ports_obj) return -ENOMEM; err = json_object_set(config_json, "ports", ports_obj); if (err) { json_decref(ports_obj); return -ENOMEM; } } err = json_unpack(ports_obj, "{s:o}", port_name, &port_obj); if (err) { port_obj = json_object(); if (!port_obj) return -ENOMEM; err = json_object_set(ports_obj, port_name, port_obj); if (err) { json_decref(port_obj); return -ENOMEM; } } if (pport_obj) *pport_obj = port_obj; return 0; }
static void test_circular() { json_t *object1, *object2; object1 = json_object(); object2 = json_object(); if(!object1 || !object2) fail("unable to create object"); /* the simple case is checked */ if(json_object_set(object1, "a", object1) == 0) fail("able to set self"); /* create circular references */ if(json_object_set(object1, "a", object2) || json_object_set(object2, "a", object1)) fail("unable to set value"); /* circularity is detected when dumping */ if(json_dumps(object1, 0) != NULL) fail("able to dump circulars"); /* decref twice to deal with the circular references */ json_decref(object1); json_decref(object2); json_decref(object1); }
int cometd_dump_message(void * output, cometd_message * message, json_dump_callback_t callback) { json_t * root = json_object(); json_object_set_new(root, CHANNEL_FIELD, json_string_nocheck(message->channel)); if (message->id) json_object_set_new(root, ID_FIELD, json_string_nocheck(message->id)); if (message->clientId) json_object_set_new(root, CLIENT_ID_FIELD, json_string_nocheck(message->clientId)); json_object_set_new(root, SUCCESSFUL_FIELD, message->successful ? json_true() : json_false()); json_object_set_new(root, VERSION_FIELD, json_string_nocheck(message->version)); if (message->supportedConnectionTypes) json_object_set(root, SUPPORTED_CONNECTION_TYPES_FIELD, message->supportedConnectionTypes); if (message->connectionType) json_object_set_new(root, CONNECTION_TYPE_FIELD, json_string_nocheck(message->connectionType)); if (message->data) json_object_set(root, DATA_FIELD, message->data); if (message->ext) json_object_set(root, EXT_FIELD, message->ext); if (message->advice.present) { if (message->advice.sourceAdvice) json_object_set_new(root, ADVICE_FIELD, message->advice.sourceAdvice); else { json_t * advice = json_object(); if (message->advice.reconnect) json_object_set_new(advice, RECONNECT_FIELD, json_string_nocheck(message->advice.reconnect)); json_object_set_new(advice, INTERVAL_FIELD, json_integer(message->advice.interval)); json_object_set(root, DATA_FIELD, message->data); json_object_set_new(root, ADVICE_FIELD, advice); } } int result = json_dump_callback(root, callback, output, 0); json_decref(root); return result; }
bool print_config_schema_json(POOL_MEM &buffer) { RES_TABLE *resources = my_config->m_resources; initialize_json(); json_t *json = json_object(); json_object_set_new(json, "format-version", json_integer(2)); json_object_set_new(json, "component", json_string("bareos-tray-monitor")); json_object_set_new(json, "version", json_string(VERSION)); /* * Resources */ json_t *resource = json_object(); json_object_set(json, "resource", resource); json_t *bareos_tray_monitor = json_object(); json_object_set(resource, "bareos-tray-monitor", bareos_tray_monitor); for (int r = 0; resources[r].name; r++) { RES_TABLE resource = my_config->m_resources[r]; json_object_set(bareos_tray_monitor, resource.name, json_items(resource.items)); } pm_strcat(buffer, json_dumps(json, JSON_INDENT(2))); json_decref(json); return true; }
void saveRevenueMovements(char * save_path) { json_t * json_revenue = json_object(); json_t * array = json_array(); json_t * json_total = json_real(total); for (struct revenue * revenue = firstRevenueMovement; revenue!=0; revenue=revenue->next) { json_array_append(array, createRevenueArray(revenue)); } int i = json_object_set(json_revenue, "total", json_total); int j = json_object_set(json_revenue, "revenue", array); if (i == -1 || j == -1) { printf("errore non è possibile scrivere il file"); } json_dump_file(json_revenue, strcat(save_path, "/revenue.json"), JSON_INDENT(3)); }
/** Sending data to server Parameters: char *type: type of data json_t *data: data object int sockfd: connection void (*callback)(char*): callback function */ char* get_data(char *type, json_t *data, int sockfd) { pid_t child_pid; json_t *root = json_object(); json_t *j_type = json_string(type); json_object_set(root, "type", j_type); json_object_set(root, "data", data); // Convert JSON data to string char *decode = json_dumps(root, 1); write(sockfd, decode, 500); printf("Send data:\n%s\n", decode); char *result_string = (char *) malloc(500*sizeof(char)); read(sockfd, result_string, 500); json_decref(root); json_decref(j_type); return result_string; }
void ZnpActorPublishDeviceErrorEvent(IEEEADDRESS macId, WORD error) { if (pZnpActor == NULL) return; json_t* eventJson = json_object(); json_t* paramsJson = json_object(); char* macIdString = IeeeToString(macId); json_t* macIdJson = json_string(macIdString); free(macIdString); json_t* protocolJson = json_string("zigbee"); char* errorMessage = malloc(50); sprintf(errorMessage, "%s%d","error.actor.", error); json_t* errorJson = json_string(errorMessage); free(errorMessage); json_object_set(paramsJson, "macId", macIdJson); json_object_set(paramsJson, "protocol", protocolJson); json_object_set(paramsJson, "error", errorJson); json_object_set(eventJson, "params", paramsJson); char* eventMessage = json_dumps(eventJson, JSON_INDENT(4) | JSON_REAL_PRECISION(4)); //char* topicName = ActorMakeTopicName(pZnpActor->guid, "/:event/device_error"); char* topicName = ActorMakeTopicName("event/", pZnpActor->guid, "/device_error"); ActorSend(pZnpActor, topicName, eventMessage, NULL, FALSE, topicName); json_decref(errorJson); json_decref(protocolJson); json_decref(macIdJson); json_decref(paramsJson); json_decref(eventJson); free(topicName); free(eventMessage); }
void ZnpActorPublishDeviceLqi(WORD nAddress, BYTE nLqi) { PDEVICEINFO pDevice; if (pZnpActor == NULL) return; pDevice = DeviceFind(nAddress); if (pDevice == NULL) return; json_t* eventJson = json_object(); json_t* paramsJson = json_object(); char* macIdString = IeeeToString(pDevice->IeeeAddr); json_t* macIdJson = json_string(macIdString); json_t* lqiJson = NULL; free(macIdString); json_t* protocolJson = json_string("zigbee"); if (nLqi > LQI_LIMIT) lqiJson = json_integer(1); else lqiJson = json_integer(0); json_object_set(paramsJson, "macId", macIdJson); json_object_set(paramsJson, "protocol", protocolJson); json_object_set(paramsJson, "signal_strength", lqiJson); json_object_set(eventJson, "params", paramsJson); char* eventMessage = json_dumps(eventJson, JSON_INDENT(4) | JSON_REAL_PRECISION(4)); //char* topicName = ActorMakeTopicName(pZnpActor->guid, "/:event/device_signal"); char* topicName = ActorMakeTopicName("event/", pZnpActor->guid, "/device_signal"); ActorSend(pZnpActor, topicName, eventMessage, NULL, FALSE, topicName); json_decref(lqiJson); json_decref(protocolJson); json_decref(macIdJson); json_decref(paramsJson); json_decref(eventJson); free(topicName); free(eventMessage); }
int main(void) { json_t *json = json_object(); int zbxVersion = json_object_set(json, "jsonrpc", json_string("2.0")); if (zbxVersion != 0) return -1; int zbxMethod = json_object_set(json, "method", json_string("user.login")); if (zbxMethod != 0) return -1; json_t *uidParams = json_pack("{s:s, s:s}", "user", "jreed", "password", "Flight8152LA"); int zbxParams = json_object_set(json, "params", uidParams); if (zbxParams != 0) return -1; int zbxId = json_object_set(json, "id", json_integer((json_int_t)1)); if (zbxId != 0) return -1; size_t jsonFLAGS = JSON_INDENT(4) | JSON_PRESERVE_ORDER ; puts(json_dumps(json,jsonFLAGS)); return 0; }
void ZnpActorPublishEndpointAddedEvent(IEEEADDRESS macId, BYTE endpoint, WORD deviceId, WORD deviceType) { if (pZnpActor == NULL) return; json_t* eventJson = json_object(); json_t* paramsJson = json_object(); char* eventMessage; char* topicName; char* macIdString = IeeeToString(macId); json_t* macJson = json_string(macIdString); free(macIdString); json_object_set(paramsJson, "macId", macJson); json_decref(macJson); char* endpointString = malloc(20); sprintf(endpointString, "%d", endpoint); json_t* endpointJson = json_string(endpointString); free(endpointString); json_object_set(paramsJson, "endpoint", endpointJson); json_decref(endpointJson); json_t* deviceClassJson; deviceClassJson = DevDesMakeDeviceClassJson(deviceId, deviceType); json_object_set(paramsJson, "class", deviceClassJson); json_decref(deviceClassJson); json_t* protocolJson = json_string("zigbee"); json_object_set(paramsJson, "protocol", protocolJson); json_decref(protocolJson); json_object_set(eventJson, "params", paramsJson); json_decref(paramsJson); eventMessage = json_dumps(eventJson, JSON_INDENT(4) | JSON_REAL_PRECISION(4)); json_decref(eventJson); //topicName = ActorMakeTopicName(pZnpActor->guid, "/:event/endpoint_added"); topicName = ActorMakeTopicName("event/", pZnpActor->guid, "/endpoint_added"); ActorSend(pZnpActor, topicName, eventMessage, NULL, FALSE, topicName); free(eventMessage); free(topicName); }
void CommentCacheSave(JSON Root) { EXCLUSIVE_ACQUIRE(LockComments); const JSON jsonComments = json_array(); const JSON jsonAutoComments = json_array(); // Build the JSON array for(auto & itr : comments) { JSON currentComment = json_object(); json_object_set_new(currentComment, "module", json_string(itr.second.mod)); json_object_set_new(currentComment, "address", json_hex(itr.second.addr)); json_object_set_new(currentComment, "text", json_string(itr.second.text)); if(itr.second.manual) json_array_append_new(jsonComments, currentComment); else json_array_append_new(jsonAutoComments, currentComment); } // Save to the JSON root if(json_array_size(jsonComments)) json_object_set(Root, "comments", jsonComments); if(json_array_size(jsonAutoComments)) json_object_set(Root, "autocomments", jsonAutoComments); json_decref(jsonComments); json_decref(jsonAutoComments); }
void OUTPUT_FORMATTER::json_finalize_result(bool result) { POOL_MEM string; json_t *msg_obj = json_object(); json_t *error_obj; /* * We mimic json-rpc result and error messages, * To make it easier to implement real json-rpc later on. */ json_object_set(msg_obj, "jsonrpc", json_string("2.0")); json_object_set(msg_obj, "id", json_null()); if (result) { json_object_set(msg_obj, "result", result_array_json); } else { error_obj = json_object(); json_object_set_new(error_obj, "code", json_integer(1)); json_object_set_new(error_obj, "message", json_string("failed")); json_object_set(error_obj, "data", result_array_json); json_object_set_new(msg_obj, "error", error_obj); } string.bsprintf("%s\n", json_dumps(msg_obj, UA_JSON_FLAGS)); send_func(send_ctx, string.c_str()); json_array_clear(result_array_json); json_object_clear(msg_obj); }
void TeamCard::initAoYi() { int num=0; for(int i=1;i<json_array_size(this->cards);i++){ json_t* card=json_array_get(cards, i); json_t* jxid=json_object_get(card, "xid"); if(jxid!=NULL){ int xid=json_integer_value(jxid); int type=XCard::record(Value(xid))->getCardType(); log("xid:%d,%d",xid,type); num += pow(10, i-1)*type; } } std::vector<int> items=this->getAoYiData(num); this->aoYiList->removeAllItems(); for(int i=0;i<items.size();i++){ AoyiItem* aoyi=AoyiItem::create(items.at(i)); this->aoYiList->pushBackCustomItem(aoyi); } if(items.size()==1 || ((items.size()==2 && json_array_size(cards)==3))){ json_t* aoyi=json_object(); int aoyiID=items.at(0); //XGroup* xgroup=XGroup::record(Value(aoyiID)); //XSkill* xskill=XSkill::record(Value(xgroup->getSkillId())); json_object_set(aoyi, "xid", json_integer(aoyiID)); json_object_set(aoyi, "atk", json_integer(30)); json_array_set(cards, 0, aoyi); } }
static void test_clear() { json_t *object, *ten; object = json_object(); ten = json_integer(10); if(!object) fail("unable to create object"); if(!ten) fail("unable to create integer"); if(json_object_set(object, "a", ten) || json_object_set(object, "b", ten) || json_object_set(object, "c", ten) || json_object_set(object, "d", ten) || json_object_set(object, "e", ten)) fail("unable to set value"); if(json_object_size(object) != 5) fail("invalid size"); json_object_clear(object); if(json_object_size(object) != 0) fail("invalid size after clear"); json_decref(ten); json_decref(object); }
// Create a payload with new values json_t* makeJansson(Status *stat) { json_t *newval, *values; values = json_array(); int j; for (j = 0; j < stat->num; j++) { if (stat->type == 0) { newval = json_pack("{sssf}", "title", zeit, "value", stat->result[j]); } else { json_real_set(newval, stat->result[j]); } if (!newval) { syslog(LOG_ERR, "error in creating new entry for %s.json\n", stat->name); return NULL; } json_array_append_new(values, newval); } if (stat->type != 2) { free(stat->result); } json_t *payload = json_object(); json_object_set(payload, "name", json_string(stat->name)); json_object_set(payload, "type", json_integer(stat->type)); json_object_set(payload, "payload", values); return payload; }
int _rsIESClientHints( rsComm_t* _comm, bytesBuf_t** _bbuf ) { if( ! _comm ) { return SYS_INVALID_INPUT_PARAM; } json_t* ies_hints = json_object(); if ( !ies_hints ) { rodsLog( LOG_ERROR, "failed to allocate json_object" ); return SYS_MALLOC_ERR; } std::string acls; irods::error ret = get_strict_acls( _comm, acls ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); } json_object_set( ies_hints, "strict_acls", json_string( acls.c_str() ) ); json_t* query_arr = 0; ret = get_query_array( _comm, query_arr ); if ( !ret.ok() ) { irods::log( PASS( ret ) ); } json_object_set( ies_hints, "specific_queries", query_arr ); char* tmp_buf = json_dumps( ies_hints, JSON_INDENT( 4 ) ); // *SHOULD* free All The Things... json_decref( ies_hints ); ( *_bbuf ) = ( bytesBuf_t* ) malloc( sizeof( bytesBuf_t ) ); if ( !( *_bbuf ) ) { rodsLog( LOG_ERROR, "_rsIESClientHints: failed to allocate _bbuf" ); return SYS_MALLOC_ERR; } ( *_bbuf )->buf = tmp_buf; ( *_bbuf )->len = strlen( tmp_buf ); return 0; } // _rsIESClientHints
json_t* process_vertex_weight(const struct aiVertexWeight* w) { json_t* json = json_object(); json_object_set(json, "vertex_id", json_integer(w->mVertexId)); json_object_set(json, "weight", json_real(w->mWeight)); return json; }
wbBool wbSolution(wbArg_t arg, void * data, int rows, int columns) { int ii; char * type; wbBool res; json_t * msg; char * expectedOutputFile; char * outputFile; json_t * inputFileArray; expectedOutputFile = wbArg_getExpectedOutputFile(arg); outputFile = wbArg_getOutputFile(arg); type = wbArg_getType(arg); wbAssert(type != NULL); wbAssert(expectedOutputFile != NULL); wbAssert(outputFile != NULL); res = wbSolution(expectedOutputFile, outputFile, type, data, rows, columns); #if 1 if (res) { _solution_correctQ = json_object(); msg = json_string("Solution is correct."); json_object_set(_solution_correctQ, "CorrectQ", json_true()); json_object_set(_solution_correctQ, "Message", msg); } else { msg = _solution_correctQ; _solution_correctQ = json_object(); json_object_set(_solution_correctQ, "CorrectQ", json_false()); json_object_set(_solution_correctQ, "Message", msg); } #else if (res) { _solution_correctQ = json_true(); } else { _solution_correctQ = json_false(); } #endif inputFileArray = json_array(); for (ii = 0; ii < wbArg_getInputCount(arg); ii++) { char * file = wbArg_getInputFile(arg, ii); if (file != NULL) { json_array_append(inputFileArray, json_string(file)); } } /* json_object_set(_solution_correctQ, "InputFiles", inputFileArray); json_object_set(_solution_correctQ, "ExpectedOutput", json_string(expectedOutputFile)); json_object_set(_solution_correctQ, "OutputFile", json_string(outputFile)); */ return res; }
json_t * ins_edge_serialize (struct _ins_edge * ins_edge) { json_t * json = json_object(); json_object_set(json, "ot", json_integer(SERIALIZE_INSTRUCTION_EDGE)); json_object_set(json, "type", json_integer(ins_edge->type)); return json; }
int jt_stats_packer(void *data, char **out) { struct timespec mts; /* message timestamp */ struct jt_msg_stats *stats_msg = data; json_t *t = json_object(); json_t *samples_arr = json_array(); json_t *params = json_object(); json_t *jmts = json_object(); json_object_set_new(params, "iface", json_string(stats_msg->iface)); json_object_set_new(params, "whoosh_err_mean", json_integer(stats_msg->err.mean)); json_object_set_new(params, "whoosh_err_max", json_integer(stats_msg->err.max)); json_object_set_new(params, "whoosh_err_sd", json_integer(stats_msg->err.sd)); json_t *sample[stats_msg->sample_count]; // order matters! for (int i = 0; i < stats_msg->sample_count; i++) { sample[i] = json_object(); json_object_set_new(sample[i], "rx", json_integer(stats_msg->samples[i].rx)); json_object_set_new(sample[i], "tx", json_integer(stats_msg->samples[i].tx)); json_object_set_new(sample[i], "rxP", json_integer(stats_msg->samples[i].rxPkt)); json_object_set_new(sample[i], "txP", json_integer(stats_msg->samples[i].txPkt)); json_array_append(samples_arr, sample[i]); } json_object_set_new( t, "msg", json_string(jt_messages[JT_MSG_STATS_V1].key)); json_object_set(params, "s", samples_arr); json_object_set(t, "p", params); /* timestamp the new message */ clock_gettime(CLOCK_MONOTONIC, &mts); json_object_set_new(jmts, "tv_sec", json_integer(mts.tv_sec)); json_object_set_new(jmts, "tv_nsec", json_integer(mts.tv_nsec)); json_object_set_new(params, "t", jmts); *out = json_dumps(t, 0); for (int i = 0; i < stats_msg->sample_count; i++) { json_decref(sample[i]); } json_array_clear(samples_arr); json_decref(samples_arr); json_object_clear(params); json_decref(params); json_object_clear(t); json_decref(t); return 0; }
void task_populate_titledb_cache_set(u32 id, bool cia, titledb_cache_entry* entry) { json_t* obj = task_populate_titledb_cache_get_base(id, cia, true); if(json_is_object(obj)) { json_object_set(obj, "id", json_integer(entry->id)); json_object_set(obj, "mtime", json_string(entry->mtime)); json_object_set(obj, "version", json_string(entry->version)); task_populate_titledb_cache_save(); } }
json_object_t new_osd_group(const char* name, const char* description) { json_object_t object = json_object_create(); json_object_setstr(object, "name", name); json_object_setstr(object, "description", description); json_object_set(object, "datastreams", json_array_create()); json_object_set(object, "photostreams", json_array_create()); return object; }
/* encode_json : encode the exnode in the JSON format n dump it in string * dir : directory name * parent_id : parent directory id * return : JSON dump of exnode * */ char *encode_json(const char *dir, const char *parent_id){ if(dir == NULL){ fprintf(stderr, "Invalid directory name \n"); return NULL; } // create json object json_t *json_exnode = json_object(); json_object_set(json_exnode, "name", json_string(dir)); json_object_set(json_exnode, "created", json_integer(time(NULL))); json_object_set(json_exnode, "modified", json_integer(time(NULL))); json_object_set(json_exnode, "mode", json_string("directory")); json_object_set(json_exnode, "size", json_integer(0)); if (parent_id == NULL) { json_object_set(json_exnode, "parent", json_null()); } else { json_t *pobj = json_object(); json_object_set(pobj, "href", json_string(parent_id)); json_object_set(pobj, "rel", json_string("full")); json_object_set(json_exnode, "parent", pobj); } return json_dumps(json_exnode, JSON_INDENT(1)); }
static json_t* net_write_json_params(void) { json_t *params = json_object(); json_t *l = json_array(); json_t* o; int i; json_object_set(params, "count", json_integer(net->numParams)); for(i=0; i<net->numParams; i++) { o = json_object(); json_object_set(o, "idx", json_integer(i)); json_object_set(o, "label", json_string(net->params[i].desc.label)); json_object_set(o, "type", json_integer(net->params[i].desc.type)); json_object_set(o, "min", json_integer(net->params[i].desc.min)); json_object_set(o, "max", json_integer(net->params[i].desc.max)); json_object_set(o, "value", json_integer(net->params[i].data.value)); /// FIXME: this dumb indexing. play flag not stored correctly... json_object_set(o, "play", json_boolean(net_get_in_play(i + net->numIns))); json_array_append(l, o); } json_object_set(params, "data", l); return params; }
json_t *ConstructorInfoWriter::write() { json_t *json = json_object(); json_object_set(json, "type", json_string("CONSTRUCTOR")); json_object_set(json, "defaultconstructor", defaultConstructor ? json_true() : json_false()); MethodBaseWriter::write(json); return json; }
void OUTPUT_FORMATTER::object_start(const char *name) { #if HAVE_JANSSON json_t *json_object_current = NULL; json_t *json_object_existing = NULL; json_t *json_object_array = NULL; json_t *json_object_new = json_object(); #endif Dmsg1(800, "obj start: %s\n", name); switch (api) { #if HAVE_JANSSON case API_MODE_JSON: json_object_current = (json_t *)result_stack_json->last(); if (json_object_current == NULL) { json_object_current = json_object(); json_array_append_new(result_array_json, json_object_current); } if (name == NULL) { /* * Add nameless object. */ result_stack_json->push(json_object_current); } else { json_object_existing = json_object_get(json_object_current, name); if (json_object_existing) { if (json_is_array(json_object_existing)) { Dmsg2(800, "json object %s (stack size: %d) already exits and is an array: appending\n", name, result_stack_json->size()); json_array_append_new(json_object_existing, json_object_new); } else { Dmsg2(800, "json object %s (stack size: %d) already exits: converting to array and appending\n", name, result_stack_json->size()); json_object_array = json_array(); json_array_append_new(json_object_array, json_object_existing); json_array_append_new(json_object_array, json_object_new); json_object_set(json_object_current, name, json_object_array); } } else { Dmsg2(800, "create new json object %s (stack size: %d)\n", name, result_stack_json->size()); json_object_set(json_object_current, name, json_object_new); } result_stack_json->push(json_object_new); } Dmsg1(800, "result stack: %d\n", result_stack_json->size()); break; #endif default: break; } }
json_t* internal_error(int code, json_t* data) { json_t* ret = json_object(); json_t* inner = json_object(); char* message; switch(code){ case JRPC_ERR_REQ_BUILD: message = "Failed to build request"; break; case JRPC_ERR_SEND: message = "Failed to send"; break; case JRPC_ERR_BAD_RESP: message = "Bad response result"; json_object_set(ret, "data", data); break; case JRPC_ERR_RETRY: message = "Retry failed"; break; case JRPC_ERR_SERVER_DISCONNECT: message = "Server disconnected"; break; case JRPC_ERR_TIMEOUT: message = "Message timeout"; break; case JRPC_ERR_PARSING: message = "JSON parse error"; break; case JRPC_ERR_BUG: message = "There is a bug"; break; default: ERR("Unrecognized error code: %d\n", code); message = "Unknown error"; break; } json_t* message_js = json_string(message); json_object_set(inner, "message", message_js); if(message_js) json_decref(message_js); json_t* code_js = json_integer(code); json_object_set(inner, "code", code_js); if(code_js) json_decref(code_js); if(data) { json_object_set(inner, "data", data); } json_object_set(ret, "internal_error", inner); if(inner) json_decref(inner); return ret; }
json_t * rdis_serialize (struct _rdis * rdis) { json_t * json = json_object(); json_object_set(json, "ot", json_integer(SERIALIZE_RDIS)); json_object_set(json, "graph", object_serialize(rdis->graph)); json_object_set(json, "labels", object_serialize(rdis->labels)); json_object_set(json, "functions", object_serialize(rdis->functions)); json_object_set(json, "memory", object_serialize(rdis->memory)); return json; }