json_object *base64_json_encode (uint8_t *dat, int len) { char *buf; int dstlen; json_object *o; int size = base64_encode_length (len); buf = xzmalloc (size); (void) base64_encode_block (buf, &dstlen, dat, len); if (!(o = json_object_new_string (buf))) oom (); free (buf); return o; }
static struct json_object *_build_id_array(const struct regid regids[]) { struct json_object *id_array = json_object_new_array(); const struct regid *id = regids; while (id->id[0]) { #if DEBUG printf("Adding %s\n", id->id); #endif json_object_array_add(id_array, json_object_new_string(id->id)); id++; } return id_array; }
json_object* SearchServiceManager::getSearchServiceList() { json_object* objArray = json_object_new_array(); for(ServiceInfoList::iterator it=m_serviceInfoList.begin(); it != m_serviceInfoList.end(); ++it) { const SearchServiceInfo* serviceInfo = (*it); json_object* infoObj = json_object_new_object(); json_object_object_add(infoObj,(char*) "serviceID",json_object_new_string((char*) serviceInfo->m_serviceID.c_str())); json_object_object_add(infoObj,(char*) "title",json_object_new_string((char*) serviceInfo->m_title.c_str())); json_object_object_add(infoObj,(char*) "serviceURL",json_object_new_string((char*) serviceInfo->m_serviceURL.c_str())); json_object_object_add(infoObj,(char*) "action",json_object_new_string((char*) serviceInfo->m_action.c_str())); json_object_object_add(infoObj,(char*) "timeout",json_object_new_int((int) serviceInfo->m_timeout)); json_object_object_add(infoObj,(char*) "enabled",json_object_new_boolean(serviceInfo->m_enabled)); json_object_object_add(infoObj,(char*) "preventDelete",json_object_new_boolean(serviceInfo->m_preventDelete)); json_object_array_add(objArray, infoObj); } return objArray; }
struct json_object *util_bus_to_json(struct ndctl_bus *bus) { struct json_object *jbus = json_object_new_object(); struct json_object *jobj; if (!jbus) return NULL; jobj = json_object_new_string(ndctl_bus_get_provider(bus)); if (!jobj) goto err; json_object_object_add(jbus, "provider", jobj); jobj = json_object_new_string(ndctl_bus_get_devname(bus)); if (!jobj) goto err; json_object_object_add(jbus, "dev", jobj); return jbus; err: json_object_put(jbus); return NULL; }
static void json_output_file_store_data(json_object *obj, const u_char *packet, size_t buflen) { unsigned int i; char *buf; buf = malloc((buflen*2)+1); buf[buflen*2] = 0; for (i=0; i<buflen; i++) snprintf(buf + (i*2), 3, "%.2x", packet[i]); json_object_object_add(obj, "data", json_object_new_string(buf)); json_object_object_add(obj, "length", json_object_new_int(buflen)); free(buf); }
void fcgi_print_result(struct fcgi_recv_fileser* recv_data,int result,uint32_t reason_id) { struct json_object *my_object; struct json_object *sub_array; uint32_t i = 0; my_object = json_object_new_object(); sub_array = json_object_new_array(); char str_tmp[32]; if(result == FAIL){ json_object_object_add(my_object,"result",json_object_new_string("fail")); json_object_object_add(my_object,"reason",json_object_new_int(reason_id)); goto PRINT_END; } if(recv_data == NULL){ json_object_object_add(my_object,"result",json_object_new_string("fail")); json_object_object_add(my_object,"reason",json_object_new_int(reason_id)); goto PRINT_END; } json_object_object_add(my_object,"result",json_object_new_string("success")); json_object_object_add(my_object,"key",json_object_new_int(recv_data->key)); json_object_object_add(my_object,"lloccode",json_object_new_string(recv_data->lloccode)); json_object_object_add(my_object,"cnt",json_object_new_int(recv_data->cnt)); if(recv_data->cnt == 0){ goto PRINT_END; } for(i = 0;i < recv_data->cnt && i < CNT_MAX; i++){ sprintf(str_tmp,"%u",recv_data->Thumbid[i]); json_object_array_add(sub_array, json_object_new_string(str_tmp)); } json_object_object_add(my_object,"thumbid",sub_array); PRINT_END: printf("%s\n",json_object_to_json_string(my_object)); json_object_put(sub_array); json_object_put(my_object); return ; }
iot_json_t *iot_json_add_member(iot_json_t *o, const char *key, iot_json_type_t type, ...) { iot_json_t *m; const char *s; bool b; int i, l; double d; va_list ap; va_start(ap, type); switch (type) { case IOT_JSON_STRING: s = va_arg(ap, const char *); l = va_arg(ap, int); if (l < 0) m = json_object_new_string(s); else m = json_object_new_string_len(s, l); break; case IOT_JSON_BOOLEAN: b = va_arg(ap, int); m = json_object_new_boolean(b); break; case IOT_JSON_INTEGER: i = va_arg(ap, int); m = json_object_new_int(i); break; case IOT_JSON_DOUBLE: d = va_arg(ap, double); m = json_object_new_double(d); break; case IOT_JSON_OBJECT: m = json_object_new_object(); break; case IOT_JSON_ARRAY: m = json_object_new_array(); break; default: m = NULL; errno = EINVAL; } va_end(ap); if (m != NULL) json_object_object_add(o, key, m); return m; }
OSStatus MICOAddSector(json_object* sectors, char* const name, json_object *menus) { OSStatus err; json_object *object; err = kNoErr; object = json_object_new_object(); require_action(object, exit, err = kNoMemoryErr); json_object_object_add(object, "N", json_object_new_string(name)); json_object_object_add(object, "C", menus); json_object_array_add(sectors, object); exit: return err; }
OSStatus MICOAddTopMenu(json_object **outTopMenu, char* const inName, json_object* sectors, OTA_Versions_t inVersions) { OSStatus err; json_object *object; err = kNoErr; require_action(inVersions.protocol, exit, err = kParamErr); require_action(inVersions.hdVersion, exit, err = kParamErr); require_action(inVersions.fwVersion, exit, err = kParamErr); object = json_object_new_object(); require_action(object, exit, err = kNoMemoryErr); json_object_object_add(object, "N", json_object_new_string(inName)); json_object_object_add(object, "C", sectors); json_object_object_add(object, "PO", json_object_new_string(inVersions.protocol)); json_object_object_add(object, "HD", json_object_new_string(inVersions.hdVersion)); json_object_object_add(object, "FW", json_object_new_string(inVersions.fwVersion)); if(inVersions.rfVersion) json_object_object_add(object, "RF", json_object_new_string(inVersions.rfVersion)); *outTopMenu = object; exit: return err; }
int main(int argc, char *argv[]) { json_object *jobj; (void)argc; (void)argv; jobj = json_object_new_object(); if (!jobj) { return 1; } json_object_object_add(jobj, "key", json_object_new_string("value")); printf("%s", json_object_to_json_string(jobj)); return 0; }
json_object* LocalePrefsHandler::valuesForRegion() { json_object* json = json_object_new_object(); json_object* regArrayObj = json_object_new_array(); for (RegionEntryList::const_iterator it = m_regionEntryList.begin(); it != m_regionEntryList.end(); ++it) { const RegionEntry& regEntry = (*it); json_object* regObj = json_object_new_object(); json_object_object_add(regObj,(char*) "shortCountryName", json_object_new_string((char*) regEntry.region[0].c_str())); json_object_object_add(regObj, (char*) "countryName", json_object_new_string((char*) regEntry.region[1].c_str())); json_object_object_add(regObj, (char*) "countryCode", json_object_new_string((char*) regEntry.region[2].c_str())); json_object_array_add(regArrayObj, regObj); } json_object_object_add(json, (char*) "region", regArrayObj); return json; }
int nf_json_config_init_string(json_object *parent, const char *childkey, json_object **child, const char *str) { if((parent == NULL) || (childkey == NULL) || (child == NULL)) return -1; *child = json_object_object_get(parent, childkey); if(*child == NULL){ *child = json_object_new_string(str); VALUE_IS_NULL_RETURN(*child, 1); json_object_object_add(parent, childkey, *child); } return 0; }
int test_jsonc() { json_tokener *tok; json_object *my_string, *my_int, *my_object, *my_array; json_object *new_obj; int i; MC_SET_DEBUG(1); my_string = json_object_new_string("\t"); printf("my_string=%s\n", json_object_get_string(my_string)); printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string)); json_object_put(my_string); my_string = json_object_new_string("\\"); printf("my_string=%s\n", json_object_get_string(my_string)); printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string)); json_object_put(my_string); my_string = json_object_new_string("foo"); printf("my_string=%s\n", json_object_get_string(my_string)); printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string)); my_int = json_object_new_int(9); printf("my_int=%d\n", json_object_get_int(my_int)); printf("my_int.to_string()=%s\n", json_object_to_json_string(my_int)); my_array = json_object_new_array(); json_object_array_add(my_array, json_object_new_int(1)); json_object_array_add(my_array, json_object_new_int(2)); json_object_array_add(my_array, json_object_new_int(3)); json_object_array_put_idx(my_array, 4, json_object_new_int(5)); printf("my_array=\n"); for(i=0; i < json_object_array_length(my_array); i++) { json_object *obj = json_object_array_get_idx(my_array, i); printf("\t[%d]=%s\n", i, json_object_to_json_string(obj)); } printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array)); my_object = json_object_new_object(); json_object_object_add(my_object, "abc", json_object_new_int(12)); json_object_object_add(my_object, "foo", json_object_new_string("bar")); json_object_object_add(my_object, "bool0", json_object_new_boolean(0)); json_object_object_add(my_object, "bool1", json_object_new_boolean(1)); json_object_object_add(my_object, "baz", json_object_new_string("bang")); json_object_object_add(my_object, "baz", json_object_new_string("fark")); json_object_object_del(my_object, "baz"); /*json_object_object_add(my_object, "arr", my_array);*/ printf("my_object=\n"); json_object_object_foreach(my_object, key, val) { printf("\t%s: %s\n", key, json_object_to_json_string(val)); }
static int doc_to_tempfile(u1db_document *doc, int gen, const char *trans_id, FILE *fd) { int status = U1DB_OK; json_object *json = NULL; fputs(",\r\n", fd); json = json_object_new_object(); if (json == NULL) { status = U1DB_NOMEM; goto finish; } json_object_object_add(json, "id", json_object_new_string(doc->doc_id)); json_object_object_add(json, "rev", json_object_new_string(doc->doc_rev)); json_object_object_add( json, "content", doc->json?json_object_new_string(doc->json):NULL); json_object_object_add(json, "gen", json_object_new_int(gen)); json_object_object_add(json, "trans_id", json_object_new_string(trans_id)); fputs(json_object_to_json_string(json), fd); finish: if (json != NULL) { json_object_put(json); } return status; }
OSStatus MICOAddMenuCellToSector(json_object* sector, char* const name, json_object* lowerSectorArray) { OSStatus err; json_object *object; err = kNoErr; object = json_object_new_object(); require_action(object, exit, err = kNoMemoryErr); json_object_object_add(object, "N", json_object_new_string(name)); json_object_object_add(object, "C", lowerSectorArray); json_object_array_add(sector, object); exit: return err; }
/** * @ingroup VuoGradientNoise * Encodes @c value as a JSON object. */ json_object * VuoGradientNoise_getJson(const VuoGradientNoise value) { char * valueAsString = ""; switch (value) { case VuoGradientNoise_Perlin: valueAsString = "perlin"; break; case VuoGradientNoise_Simplex: valueAsString = "simplex"; break; } return json_object_new_string(valueAsString); }
/** * Encodes @c value as a JSON object. */ json_object *VuoDmxColorMap_getJson(const VuoDmxColorMap value) { char *valueAsString = "rgb"; if (value == VuoDmxColorMap_RGBA) valueAsString = "rgba"; else if (value == VuoDmxColorMap_RGBAW) valueAsString = "rgbaw"; else if (value == VuoDmxColorMap_RGBW) valueAsString = "rgbw"; else if (value == VuoDmxColorMap_WWCW) valueAsString = "wwcw"; return json_object_new_string(valueAsString); }
/* write cracked list to session file */ hash_stat session_write_crackedlist(FILE *sessionfile) { #ifdef HAVE_JSON_JSON_H json_object *jobj; json_object *jchild; struct hash_list_s *mylist; char buff[1024]; if (get_cracked_num()==get_hashes_num()) return(hash_ok); cracked_list_node = json_object_new_array(); pthread_mutex_lock(&crackedmutex); mylist = cracked_list; while ((mylist)&&(mylist->username)) { jchild = json_object_new_object(); if (!jchild) return hash_err; jobj = json_object_new_string(mylist->username); json_object_object_add(jchild,"username", jobj); str2hex(mylist->hash, buff, hash_ret_len); jobj = json_object_new_string(buff); json_object_object_add(jchild,"hash", jobj); jobj = json_object_new_string(mylist->salt); json_object_object_add(jchild,"salt", jobj); jobj = json_object_new_string(mylist->salt); json_object_object_add(jchild,"salt", jobj); jobj = json_object_new_string(mylist->salt2); json_object_object_add(jchild,"salt2", jobj); json_object_array_add(cracked_list_node,jchild); mylist = mylist->next; } pthread_mutex_unlock(&crackedmutex); json_object_object_add(root_node,"crackedlist", cracked_list_node); #endif return hash_ok; }
/** * Encodes @c value as a JSON object. */ json_object *VuoIconPosition_getJson(const VuoIconPosition value) { char *valueAsString = "left"; if (value == VuoIconPosition_Right) valueAsString = "right"; else if (value == VuoIconPosition_Above) valueAsString = "above"; else if (value == VuoIconPosition_Below) valueAsString = "below"; else if (value == VuoIconPosition_Behind) valueAsString = "behind"; return json_object_new_string(valueAsString); }
char *cws_query2json (char *dbfile, char *stmt) { int i; const char *aux; char *json; json_object *root; json_object *array; sqlite3 *db; sqlite3_stmt *pp; sqlite3_open (dbfile, &db); sqlite3_prepare (db, stmt, strlen (stmt), &pp, NULL); array = json_object_new_array (); while (sqlite3_step (pp) == SQLITE_ROW) { int ncol = sqlite3_column_count (pp); json_object *row = json_object_new_object (); for (i = 0; i < ncol; i++) { json_object *col = NULL; switch (sqlite3_column_type (pp, i)) { case SQLITE_FLOAT : col = json_object_new_double (sqlite3_column_double (pp, i)); break; case SQLITE_INTEGER : col = json_object_new_int (sqlite3_column_int (pp, i)); break; case SQLITE_TEXT : col = json_object_new_string ((char *) sqlite3_column_text (pp, i)); break; } json_object_object_add (row, sqlite3_column_name (pp, i), col); } json_object_array_add (array, row); } sqlite3_finalize (pp); sqlite3_close (db); root = json_object_new_object (); json_object_object_add (root, "records", array); aux = json_object_to_json_string (root); json = malloc (sizeof (char) * (strlen (aux) + 1)); strcpy (json, aux); json_object_put (root); return json; }
void mjson_asm_objs(HDF *hdf, struct json_object **out) { if (hdf == NULL) return; struct json_object *jret, *jso; char *val, *type; bool array = false; type = mcs_obj_attr(hdf, "type"); if (type && !strcmp(type, "array")) { array = true; jret = json_object_new_array(); } else { jret = json_object_new_object(); } hdf = hdf_obj_child(hdf); while (hdf) { jso = NULL; if ((val = hdf_obj_value(hdf)) != NULL) { type = mcs_obj_attr(hdf, "type"); if (type != NULL && !strcmp(type, "int")) { jso = json_object_new_int(atoi(val)); } else { jso = json_object_new_string(val); } if (array) json_object_array_add(jret, jso); else json_object_object_add(jret, hdf_obj_name(hdf), jso); } if (hdf_obj_child(hdf) != NULL) { mjson_asm_objs(hdf, &jso); if (array) json_object_array_add(jret, jso); else json_object_object_add(jret, hdf_obj_name(hdf), jso); } hdf = hdf_obj_next(hdf); } *out = jret; }
void pa_format_info_set_prop_string_array(pa_format_info *f, const char *key, const char **values, int n_values) { json_object *o; int i; pa_assert(f); pa_assert(key); o = json_object_new_array(); for (i = 0; i < n_values; i++) json_object_array_add(o, json_object_new_string(values[i])); pa_proplist_sets(f->plist, key, json_object_to_json_string(o)); json_object_put(o); }
static void ipc_json_describe_view(swayc_t *c, json_object *object) { json_object *props = json_object_new_object(); float percent = ipc_json_child_percentage(c); const char *layout = (c->parent->type == C_CONTAINER) ? ipc_json_layout_description(c->parent->layout) : "none"; const char *last_layout = (c->parent->type == C_CONTAINER) ? ipc_json_layout_description(c->parent->prev_layout) : "none"; wlc_handle parent = wlc_view_get_parent(c->handle); json_object_object_add(object, "type", json_object_new_string((c->is_floating) ? "floating_con" : "con")); json_object_object_add(object, "scratchpad_state", json_object_new_string(ipc_json_get_scratchpad_state(c))); json_object_object_add(object, "percent", (percent > 0) ? json_object_new_double(percent) : NULL); // TODO: make urgency actually work once Sway supports it json_object_object_add(object, "urgent", json_object_new_boolean(false)); json_object_object_add(object, "layout", (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout)); json_object_object_add(object, "last_split_layout", (strcmp(last_layout, "null") == 0) ? NULL : json_object_new_string(last_layout)); json_object_object_add(object, "workspace_layout", json_object_new_string(ipc_json_layout_description(swayc_parent_by_type(c, C_WORKSPACE)->workspace_layout))); json_object_object_add(object, "border", json_object_new_string(ipc_json_border_description(c))); json_object_object_add(object, "current_border_width", json_object_new_int(c->border_thickness)); json_object_object_add(object, "rect", ipc_json_create_rect(c)); json_object_object_add(object, "deco_rect", ipc_json_create_rect_from_geometry(c->title_bar_geometry)); json_object_object_add(object, "geometry", ipc_json_create_rect_from_geometry(c->cached_geometry)); json_object_object_add(object, "window_rect", ipc_json_create_rect_from_geometry(c->actual_geometry)); json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL); json_object_object_add(object, "window", json_object_new_int(c->handle)); // for the sake of i3 compat json_object_object_add(props, "class", c->class ? json_object_new_string(c->class) : c->app_id ? json_object_new_string(c->app_id) : NULL); json_object_object_add(props, "instance", c->instance ? json_object_new_string(c->instance) : c->app_id ? json_object_new_string(c->app_id) : NULL); json_object_object_add(props, "title", (c->name) ? json_object_new_string(c->name) : NULL); json_object_object_add(props, "transient_for", parent ? json_object_new_int(parent) : NULL); json_object_object_add(object, "window_properties", props); json_object_object_add(object, "fullscreen_mode", json_object_new_int(swayc_is_fullscreen(c) ? 1 : 0)); json_object_object_add(object, "sticky", json_object_new_boolean(c->sticky)); json_object_object_add(object, "floating", json_object_new_string( c->is_floating ? "auto_on" : "auto_off")); // we can't state the cause json_object_object_add(object, "app_id", c->app_id ? json_object_new_string(c->app_id) : NULL); }
static struct json_object *serialize_delete_key_share_pub( const union command_args *args_u, uint16_t version){ const struct delete_key_share_pub *delete_key_share = &args_u->delete_key_share_pub; struct json_object *ret; if(version != 1) return NULL; ret = json_object_new_object(); json_object_object_add(ret, "key_id", json_object_new_string(delete_key_share->key_id)); return ret; }
int http_response_json_msg (struct http_request *req, int result, const char *msg) { const char *resp = NULL; json_object *json_msg = NULL; json_msg = json_object_new_object (); json_object_object_add (json_msg, "result", json_object_new_int (result)); json_object_object_add (json_msg, "data", json_object_new_string (msg)); resp = json_object_to_json_string(json_msg); http_response (req, 200, resp, strlen(resp)); json_object_put (json_msg); json_msg = NULL; return KORE_RESULT_OK; }
void Frontend::json( json_object *entry ) const { ScopeLock _l( mutex_ports ); json_object_object_add( entry, "name", json_object_new_string( name.c_str( ))); json_object_object_add( entry, "id", json_object_new_int( GetKey( ))); json_object_object_add( entry, "type", json_object_new_int( type )); json_object *a = json_object_new_array(); for( std::map<int, Port *>::const_iterator it = ports.begin( ); it != ports.end( ); it++ ) { json_object *entry = json_object_new_object( ); it->second->json( entry ); json_object_array_add( a, entry ); } json_object_object_add( entry, "ports", a ); }
static rsRetVal addContextForReporting(json_object *to, const uchar* field_name, const uchar* value) { json_object *v = NULL; DEFiRet; CHKmalloc(v = json_object_new_string((const char*) value)); json_object_object_add(to, (const char*) field_name, v); finalize_it: if (iRet != RS_RET_OK) { if (v != NULL) { json_object_put(v); } } RETiRet; }
char *alfred_xbmc_request_new(const char *method, int player, json_object *params) { json_object *obj = alfred_xbmc_json_new(method, player, params); char *data = alfred_utils_curl_post_login("http://" XBMC_HOST ":" XBMC_PORT "/jsonrpc", json_object_to_json_string(obj), XBMC_USER, XBMC_PASS); printf("%s\n", data); alfred_xbmc_json_free(obj); json_object *msg_params = json_object_new_object(); json_object *msg = json_object_new_string("Command sent."); json_object_object_add(msg_params, "message", msg); alfred_json_create_display(0, "Method success.", msg_params); return data; }
/** * @ingroup VuoLeapPointableType * Encodes @c value as a JSON object. */ json_object * VuoLeapPointableType_getJson(const VuoLeapPointableType value) { char *valueAsString = ""; switch (value) { case VuoLeapPointableType_Finger: valueAsString = "finger"; break; case VuoLeapPointableType_Tool: valueAsString = "tool"; break; } return json_object_new_string(valueAsString); }
int main (int argc, char *argv[]) { char * filename; if (argc < 4 || argc < 3 || argc < 2 || argc < 1) show_usage(argv[0], TRUE, -1); filename = argv[1]; if (file_exists(filename) != 1) { file_write(filename, "{ }"); } char * cNewValue = argv[argc-1]; json_object * jobj = json_object_from_file(filename); json_object * jobj2 = jobj; json_object * jLast; json_object * jobj3; int i; char *key; //skip the first argument and the last argument for(i = 2; i < argc-1; i++) { key = argv[i]; jLast = jobj2; if (i == argc-2) { jobj3 = json_object_new_string(argv[argc-1]); json_object_get(jobj3); json_object_object_add(jLast, key, (jobj3)); json_object_put(jobj3); break; } //this gets an existing field, if it exists, otherwise creates a new one. if (json_object_object_get_ex(jLast, key, &jobj2) != TRUE) { jobj2 = json_object_new_object(); } json_object_object_add(jLast, key, json_object_get(jobj2)); } json_object_to_file(filename, jobj); exit(0); }