static void ac_json_80211_wtpradioconf_createjson(struct json_object* jsonparent, void* data) {
	char buffer[CAPWAP_MACADDRESS_EUI48_BUFFER];
	struct json_object* jsonitem;
	struct capwap_80211_wtpradioconf_element* wtpradioconf = (struct capwap_80211_wtpradioconf_element*)data;

	jsonitem = json_object_new_object();
	json_object_object_add(jsonitem, "ShortPreamble", json_object_new_int((int)wtpradioconf->shortpreamble));
	json_object_object_add(jsonitem, "NumBSSIDs", json_object_new_int((int)wtpradioconf->maxbssid));
	json_object_object_add(jsonitem, "DTIMPeriod", json_object_new_int((int)wtpradioconf->dtimperiod));
	json_object_object_add(jsonitem, "BSSID", json_object_new_string(capwap_printf_macaddress(buffer, wtpradioconf->bssid, MACADDRESS_EUI48_LENGTH)));
	json_object_object_add(jsonitem, "BeaconPeriod", json_object_new_int((int)wtpradioconf->beaconperiod));
	json_object_object_add(jsonitem, "CountryString", json_object_new_string((char*)wtpradioconf->country));
	json_object_object_add(jsonparent, "IEEE80211WTPRadioConfiguration", jsonitem);
}
Ejemplo n.º 2
0
static char *imagePlayer_GetMediaInfo(ImagePlayer *IP)	//bug!!!!!
{
    #if 0
	t_MEDIA_INFO* minfo = IP->player->GetMediaInfo(IP->player);

	json_object *output = json_object_new_object();
	json_object_object_add(output, "w", json_object_new_int(minfo->resWidth));
	json_object_object_add(output, "h", json_object_new_int(minfo->resHeight));
	char *result = (char *)json_object_to_json_string(output);
	json_object_put(output);
	return result;
    #endif
    return NULL;
}
Ejemplo n.º 3
0
//TODO: this is kind of funky; a launchpoint of an app should really just present the info for the app.
json_object* LaunchPoint::toJSON() const
{
	json_object* json = json_object_new_object();
	json_object_object_add(json, (char*) "id",   json_object_new_string((char*) id().c_str()));
	if (m_appDesc) {
		json_object_object_add(json, (char*) "version", json_object_new_string(m_appDesc->version().c_str()));
		json_object_object_add(json, (char*) "appId", json_object_new_string((char*) m_appDesc->id().c_str()));
		json_object_object_add(json, (char*) "vendor", json_object_new_string((char*) m_appDesc->vendorName().c_str()));
		json_object_object_add(json, (char*) "vendorUrl", json_object_new_string((char *) m_appDesc->vendorUrl().c_str()));
		int appSize = 0;
		std::string packageId = m_appDesc->id();
		if (this->isDefault()) {
			PackageDescription* packageDesc = ApplicationManager::instance()->getPackageInfoByAppId(m_appDesc->id());
			if (packageDesc) {
				appSize = packageDesc->packageSize();
				packageId = packageDesc->id();
			}

		}
		json_object_object_add(json, (char*) "size", json_object_new_int(appSize));
		json_object_object_add(json, (char*) "packageId", json_object_new_string((char*) packageId.c_str()));

		if (m_appDesc->dockModeStatus()) {
			json_object_object_add(json, (char*) "exhibitionMode", json_object_new_boolean(true));
			json_object_object_add(json, (char*) "exhibitionModeTitle", json_object_new_string((char*)m_appDesc->dockModeTitle().c_str()));
		}
	} else {
		json_object_object_add(json, (char*) "size", json_object_new_int(0));
		json_object_object_add(json, (char*) "packageId", json_object_new_string((char*) m_appDesc->id().c_str()));
	}
	json_object_object_add(json, (char*) "removable", json_object_new_boolean(m_removable));

	json_object_object_add(json, (char*) "launchPointId", json_object_new_string((char*) launchPointId().c_str()));
	json_object_object_add(json, (char*) "title", json_object_new_string((char*) title().c_str()));
	json_object_object_add(json, (char*) "appmenu", json_object_new_string((char*)menuName().c_str()));
	json_object_object_add(json, (char*) "icon", json_object_new_string((char*) iconPath().c_str()));

	if (!params().empty() && m_appDesc->type() != ApplicationDescription::Type_Qt) {
        if (m_appDesc->type() == ApplicationDescription::Type_Qt) {
            json_object_object_add(json, (char*) "params", json_object_new_string(params().c_str()));
        }
        else {
    		json_object* paramsJson = json_tokener_parse(params().c_str());
	    	json_object_object_add(json, (char*) "params", paramsJson);
        }
	}

	return json;
}
Ejemplo n.º 4
0
/* Make data JSON string from punch data */
char *si_data_json(struct s_sidata *card){
	json_object *jo, *ji, *jp, *ja;
	int i;
	const char *result;
	char *jsonstr;

	jo = json_object_new_object();
	
	ji = json_object_new_int(card->cardnum);
	json_object_object_add(jo, "si_number", ji);

	ji = json_object_new_int(card->cardtype);
	json_object_object_add(jo, "si_type", ji);

	if(card->lname){
		ji = json_object_new_string(card->lname);
		json_object_object_add(jo, "si_lname", ji);
	}
	if(card->fname){
		ji = json_object_new_string(card->fname);
		json_object_object_add(jo, "si_fname", ji);
	}

	jp = make_json_punch(&card->clear);
	json_object_object_add(jo, "clear", jp);
	jp = make_json_punch(&card->check);
	json_object_object_add(jo, "check", jp);
	jp = make_json_punch(&card->start);
	json_object_object_add(jo, "start", jp);
	jp = make_json_punch(&card->finish);
	json_object_object_add(jo, "finish", jp);

	ja = json_object_new_array();
	for(i = 0; i < card->npunch; i++){
		jp = make_json_punch(&card->punches[i]);
		json_object_array_add(ja, jp);
	}
	json_object_object_add(jo, "punches", ja);

	result = json_object_to_json_string(jo);

	if((jsonstr = (char *) malloc(strlen(result)+1)) == NULL){
		json_object_put(jo);
		return NULL;
	}
	strcpy(jsonstr, result);
	json_object_put(jo);
	return jsonstr;
}
Ejemplo n.º 5
0
void pa_format_info_set_prop_int_range(pa_format_info *f, const char *key, int min, int max) {
    json_object *o;

    pa_assert(f);
    pa_assert(key);

    o = json_object_new_object();

    json_object_object_add(o, PA_JSON_MIN_KEY, json_object_new_int(min));
    json_object_object_add(o, PA_JSON_MAX_KEY, json_object_new_int(max));

    pa_proplist_sets(f->plist, key, json_object_to_json_string(o));

    json_object_put(o);
}
Ejemplo n.º 6
0
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)->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, "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);
}
Ejemplo n.º 7
0
int CJsonEncoder::SetValue(const string& strParentKey, const string& strKey,const vector<int>& vecIntValue)
{
	json_object* pArray = json_object_new_array();  
	
	vector<int>::const_iterator iter;
	for(iter = vecIntValue.begin(); iter != vecIntValue.end(); iter++)
	{
		int nTemp = *iter;
		json_object_array_add(pArray, json_object_new_int(nTemp));  
	}
	
    int nRet = 0;
	if(strParentKey.empty())
	{
		json_object_object_add((json_object*)m_root, strKey.c_str(), pArray);
	}
	else 
	{
		json_object* pParent = json_object_object_get((json_object*)m_root, strParentKey.c_str());
		if(pParent)
		{
			json_object_object_add(pParent, strKey.c_str(), pArray);
		}
		else 
		{
			nRet = -1;
		}
	}
	return nRet;
}
Ejemplo n.º 8
0
const char *json_option(char * property , int value)
{
	json_object * jobj = json_object_new_object();
	json_object *jint = json_object_new_int(value);
 	json_object_object_add(jobj,property, jint);
	return json_object_to_json_string(jobj);
}
Ejemplo n.º 9
0
static struct json_object * respondd_provider_nodeinfo(void) {
	struct json_object *ret = json_object_new_object();

	json_object_object_add(ret, "node_id", gluonutil_wrap_and_free_string(gluonutil_get_node_id()));
	json_object_object_add(ret, "hostname", get_hostname());

	struct json_object *hardware = json_object_new_object();
	json_object_object_add(hardware, "model", json_object_new_string(platforminfo_get_model()));
	json_object_object_add(hardware, "nproc", json_object_new_int(sysconf(_SC_NPROCESSORS_ONLN)));
	json_object_object_add(ret, "hardware", hardware);

	struct json_object *network = json_object_new_object();
	json_object_object_add(network, "mac", gluonutil_wrap_and_free_string(gluonutil_get_sysconfig("primary_mac")));
	json_object_object_add(ret, "network", network);

	struct json_object *software = json_object_new_object();
	struct json_object *software_firmware = json_object_new_object();
	json_object_object_add(software_firmware, "base", gluon_version());
	json_object_object_add(software_firmware, "release", gluonutil_wrap_and_free_string(gluonutil_read_line("/lib/gluon/release")));
	json_object_object_add(software, "firmware", software_firmware);
	json_object_object_add(ret, "software", software);

	struct json_object *system = json_object_new_object();
	json_object_object_add(system, "site_code", get_site_code());
	json_object_object_add(ret, "system", system);

	return ret;
}
Ejemplo n.º 10
0
int libgcm_send_json(struct gcm *g, struct json_object *j, const struct regid regids[])
{
	int ret = 0;
	struct json_object *id_array = _build_id_array(regids);

	struct json_object *body = json_object_new_object();
	json_object_object_add(body, "registration_ids", id_array);
	json_object_get(j);
	json_object_object_add(body, "data", j);

	//json_object_object_add(body, "collapse_key", j);
	json_object_object_add(body, "delay_while_idle", json_object_new_boolean(0));
	json_object_object_add(body, "time_to_live", json_object_new_int(43200));
	//json_object_object_add(body, "dry_run", json_object_new_boolean(1));

	const char *body_str = json_object_to_json_string(body);

	curl_easy_setopt(g->curl, CURLOPT_POSTFIELDS, body_str);
	curl_easy_setopt(g->curl, CURLOPT_HTTPHEADER, g->headerlist);

	g->last_result = curl_easy_perform(g->curl);

	if(g->last_result != CURLE_OK) {
		ret = -1;
	}

	json_object_put(body);

	return ret;
}
static void _mmsvc_core_msg_json_factory_args(json_object *jobj, va_list ap)
{
	int type;
	char *name;

	while ((type = va_arg(ap, int)) != 0) {
		name = va_arg(ap, char *);
		LOGD("name: %s ", name);
		switch (type) {
		case MUSED_TYPE_INT:
			json_object_object_add(jobj, name, json_object_new_int(va_arg(ap, int)));
			break;
		case MUSED_TYPE_DOUBLE:
			json_object_object_add(jobj, name, json_object_new_double(va_arg(ap, double)));
			break;
		case MUSED_TYPE_STRING:
			json_object_object_add(jobj, name, json_object_new_string(va_arg(ap, char *)));
			break;
		case MUSED_TYPE_ARRAY:
			{
				int len = va_arg(ap, int);
				int *value = va_arg(ap, int *);
				int i;
				json_object *jarr = json_object_new_array();

				for (i = 0; i < len; i++)
					json_object_array_add(jarr, json_object_new_int(value[i]));
				json_object_object_add(jobj, name, jarr);
			}
			break;
		default:
			LOGE("Unexpected type");
		}
	}
}
Ejemplo n.º 12
0
static struct json_object *jsonrpc_error_response(int jsonrpc_rc,
							 struct json_object *id)
{
	struct json_object *response = json_object_new_object();
	struct json_object *error = json_object_new_object();
	char msg[32];

	switch (jsonrpc_rc) {
	case JSONRPC_RC_INVALID_REQUEST:
		strncpy(msg, "Invalid request", sizeof(msg));
		break;
	case JSONRPC_RC_INVALID_PARAMS:
		strncpy(msg, "Invalid params", sizeof(msg));
		break;
	case JSONRPC_RC_METHOD_NOT_FOUND:
		strncpy(msg, "Method not found", sizeof(msg));
		break;
	default:
		snprintf(msg, sizeof(msg), "Error code: %d", jsonrpc_rc);
		break;
	}

	json_object_object_add(error, "code", json_object_new_int(jsonrpc_rc));
	json_object_object_add(error, "message", json_object_new_string(msg));

	json_object_object_add(response, "jsonrpc",
						 json_object_new_string("2.0"));
	json_object_object_add(response, "error", error);
	json_object_object_add(response, "id", id);

	return response;
}
Ejemplo n.º 13
0
/* Added functions for supporting features */
int createproject (const char *file, int ndirs,
                   const char *srcdirs[])
{
    json_object     *proj = NULL;
    int             success = 0;
    json_object     *dirs = NULL;
    int             i;

    /* Build only json file */
    proj = json_object_new_object();
    if (proj) {
        json_object_object_add(proj, NAME, json_object_new_string(file));
        json_object_object_add(proj, NOFSRCDIRS, json_object_new_int(ndirs));
        dirs = json_object_new_array();
        for (i = 1; i <= ndirs; i++) {
            json_object_array_add(dirs, json_object_new_string(srcdirs[i - 1]));
        }
        json_object_object_add(proj, SRCDIRS, dirs);
    }

    json_object_to_file(file, proj);
    json_object_put(proj);
    openproject(file);
    return success;
}
Ejemplo n.º 14
0
/**
 * Creates service discovery announcement content.
 *
 * {
 *     "serviceType" : "user",
 *     "serviceName" : "memcached",
 *     "serviceId" : "eebf4159-c0d4-4d27-b002-43df95ef5824",
 *     "properties" : {
 *        "servicePort" : "21212",
 *        "serviceAddress" : "192.168.1.32",
 *        "serviceScheme" : "auto-negotiate"
 * }
 */
static bool build_announcement_content() {
    json_object * announce_object;
    json_object * properties_object;

    announce_object = json_object_new_object();
    properties_object = json_object_new_object();
    json_object_object_add(announce_object, SD_SERVICE_NAME, json_object_new_string(settings.zookeeper_service_name));
    json_object_object_add(announce_object, SD_SERVICE_ID,   json_object_new_string(announce_id));
    if (settings.zookeeper_service_type) {
        json_object_object_add(announce_object, SD_SERVICE_TYPE, json_object_new_string(settings.zookeeper_service_type));
    }

    json_object_object_add(properties_object, SD_PROP_SERVICE_SCHEME, json_object_new_string(prot_text(settings.binding_protocol)));
    json_object_object_add(properties_object, SD_PROP_SERVICE_PORT,   json_object_new_int(settings.port));
    json_object_object_add(announce_object,   SD_PROPERTIES,          properties_object);

    char *announce_ip = get_announce_ip();

    if (!announce_ip) {
        LOG_ERROR(("Could not determine announcement IP, vetoing announcement!"));
        return false;
    }

    json_object_object_add(properties_object, SD_PROP_SERVICE_ADDRESS, json_object_new_string(announce_ip));

    announce_data = json_object_get_string(announce_object);
    LOG_DEBUG(("Announcement data is %s", announce_data));

    return true;
}
Ejemplo n.º 15
0
int json_output_file_ip(fieldset_t *fs)
{
	if (!file) {
		return EXIT_SUCCESS;
	}
	json_object *obj = json_object_new_object();
	json_object_object_add(obj, "type", json_object_new_string("result"));
	for (int i=0; i < fs->len; i++) {
		field_t *f = &(fs->fields[i]);
		if (f->type == FS_STRING) {
			json_object_object_add(obj, f->name,
					json_object_new_string((char *) f->value.ptr));
		} else if (f->type == FS_UINT64) {
			json_object_object_add(obj, f->name,
					json_object_new_int((int) f->value.num));
		} else if (f->type == FS_BINARY) {
			json_output_file_store_data(obj,
					(const u_char*) f->value.ptr, f->len); 
		} else if (f->type == FS_NULL) {
			// do nothing
		} else {
			log_fatal("json", "received unknown output type");
		}
	}

	fprintf(file, "%s\n", json_object_to_json_string(obj));
	fflush(file);
	// free memory
	json_object_put(obj);
	return EXIT_SUCCESS;
}
Ejemplo n.º 16
0
int cli_jsonint(json_object *obj, const char* key, int32_t i)
{
    json_type objty;
    json_object *fpobj;
    if (NULL == obj) {
        cli_dbgmsg("json: no parent object specified to cli_jsonint\n");
        return CL_ENULLARG;
    }
    objty = json_object_get_type(obj);

    if (objty == json_type_object) {    
        if (NULL == key) {
            cli_dbgmsg("json: null string specified as key to cli_jsonint\n");
            return CL_ENULLARG;
        }
    }
    else if (objty != json_type_array) {
        return CL_EARG;
    }

    fpobj = json_object_new_int(i);
    if (NULL == fpobj) {
        cli_errmsg("json: no memory for json int object\n");
        return CL_EMEM;
    }

    if (objty == json_type_object)
        json_object_object_add(obj, key, fpobj);
    else if (objty == json_type_array)
        json_object_array_add(obj, fpobj);

    return CL_SUCCESS;
}
Ejemplo n.º 17
0
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 );
}
Ejemplo n.º 18
0
static struct json_object *create_fake_gps_rmc_obj()
{
    struct json_object *obj = NULL, *obj_add = NULL;
    struct timeval tv;

    if (!(obj = json_object_new_object()))
        return NULL;

    gettimeofday(&tv, NULL);
	if (!(obj_add = json_object_new_int64(tv.tv_sec))) {
        json_object_put(obj);
        return NULL;
    }
    json_object_object_add(obj, "timestamp", obj_add);

    if (!(obj_add = json_object_new_int(META_TYPE_POS))) {
        json_object_put(obj);
        return NULL;
    }
    json_object_object_add(obj, "event_type", obj_add);

    if (!(obj_add = json_object_new_string("$GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68"))) {
        json_object_put(obj);
        return NULL;
    }

    json_object_object_add(obj, "nmea_string", obj_add);

    return obj;
}
Ejemplo n.º 19
0
void response_build_request(char *buffer, int len, response_request_t *request) {
    json_object *jobj;
    jobj = json_object_new_object();
    json_object_object_add(jobj, "msg_id", json_object_new_int(request->msg_id));
    switch(request->msg_id) {
    case REMOVE_PER:
        response_build_remove_per(jobj, request);
        break;
    case ADD_PER:
        response_build_add_per(jobj, request);
        break;
    case LIST_ACC:
        response_build_list_acc(jobj, request);
        break;
    case LIST_PER:
        response_build_list_per(jobj, request);
        break;
    case LIST_ONLINE_ACC:
        response_build_list_online_acc(jobj, request);
        break;
    case REMOVE_ACC:
        response_build_remove_acc(jobj, request);
        break;
    case ADD_ACC:
        response_build_add_acc(jobj, request);
        break;
    default:
        fprintf(stderr, "response_build_request():Invalid msg_id: %d\n", request->msg_id);
        exit(-1);
    }
    strncpy(buffer, json_object_to_json_string_ext(jobj, JSON_C_TO_STRING_PLAIN), len);
    json_object_put(jobj);
}
Ejemplo n.º 20
0
//------------------------------------------------------------------------------
// GeoJSON feature builder
//------------------------------------------------------------------------------
void geoJsonFeatBuilder( float lat, float lon, int id, char notlast_feat ) {

    json_object *jgeom = json_object_new_object();
    json_object *jpointobj = json_object_new_object();
    json_object *jprops = json_object_new_object();

    json_object *jpttype = json_object_new_string( "Point" );
    json_object *jfttype = json_object_new_string( "Feature" );
    json_object *jcoords = json_object_new_array();
    json_object *jlat = json_object_new_double( lat );
    json_object *jlon = json_object_new_double( lon );
    json_object *jid = json_object_new_int( id );

    json_object_array_add( jcoords, jlon );
    json_object_array_add( jcoords, jlat);

    json_object_object_add( jpointobj,"coordinates", jcoords );
    json_object_object_add( jpointobj,"type", jpttype );
    json_object_object_add( jgeom,"type", jfttype );
    json_object_object_add( jgeom,"properties", jprops );
    json_object_object_add( jgeom,"geometry", jpointobj );
    json_object_object_add( jprops,"id", jid );

    fprintf(fgeojsn, "%s%c\n", json_object_to_json_string( jgeom ), notlast_feat);

}
Ejemplo n.º 21
0
static struct json_object *create_fake_gps_gga_obj()
{
    struct json_object *obj = NULL, *obj_add = NULL;
    struct timeval tv;

    if (!(obj = json_object_new_object()))
        return NULL;

    gettimeofday(&tv, NULL);
	if (!(obj_add = json_object_new_int64(tv.tv_sec))) {
        json_object_put(obj);
        return NULL;
    }
    json_object_object_add(obj, "timestamp", obj_add);

    if (!(obj_add = json_object_new_int(META_TYPE_POS))) {
        json_object_put(obj);
        return NULL;
    }
    json_object_object_add(obj, "event_type", obj_add);

    if (!(obj_add = json_object_new_string("$GPGGA,190406.0,5103.732280,N,01701.493660,E,1,05,1.7,130.0,M,42.0,M,,*53"))) {
        json_object_put(obj);
        return NULL;
    }

    json_object_object_add(obj, "nmea_string", obj_add);

    return obj;
}
Ejemplo n.º 22
0
int
json_from_db(void *void_json, int ncolumns, char **col_values, char **col_names)
{
    int i;
    json_object *json_db = (json_object *) void_json;
    int nodename_idx = -1, jsonblob_idx = -1, json_ct;

    // Find the indices
    for (i = 0; i < ncolumns; i++) {
        if (!strcmp(col_names[i], "nodename")) {
            nodename_idx = i;
        } else if (!strcmp(col_names[i], "jsonblob")) {
            jsonblob_idx = i;
        }
    }

    if (nodename_idx < 0) {
        // There are no nodes to be returned just return.
        return 0;
    }

    json_object_object_add(json_db, col_values[nodename_idx], json_object_new_string(col_values[jsonblob_idx]));
    json_ct = get_int_from_json(json_db, "JSON_CT");
    json_ct++;
    json_object_object_add(json_db, "JSON_CT", json_object_new_int(json_ct));

    return 0;
}
Ejemplo n.º 23
0
int MwsIdsResponseFormatter::writeData(const MwsAnswset& answerSet,
                                       FILE* output) const {
    json_object* json_doc = json_object_new_object();

    // Creating qvars field
    json_object* json_qvars = json_object_new_array();
    for (int i = 0; i < (int)answerSet.qvarNames.size(); i++) {
        json_object* json_qvar = json_object_new_object();
        json_object_object_add(
            json_qvar, "name",
            json_object_new_string(answerSet.qvarNames[i].c_str()));
        json_object_object_add(
            json_qvar, "xpath",
            json_object_new_string(answerSet.qvarXpaths[i].c_str()));

        json_object_array_add(json_qvars, json_qvar);
    }
    json_object_object_add(json_doc, "qvars", json_qvars);

    // Create ids field
    json_object* json_ids = json_object_new_array();
    for (FormulaId formulaId : answerSet.ids) {
        json_object_array_add(json_ids, json_object_new_int(formulaId));
    }
    json_object_object_add(json_doc, "ids", json_ids);

    string json_string = json_object_to_json_string(json_doc);
    fwrite(json_string.c_str(), json_string.size(), 1, output);

    json_object_put(json_doc);

    return json_string.size();
}
Ejemplo n.º 24
0
static void xr_call_serialize_response_json(xr_call* call, char** buf, int* len)
{
    GSList* i;
    struct json_object *r, *error;

    if (call->error_set)
    {
        r = json_object_new_object();
        json_object_object_add(r, "result", NULL);
        json_object_object_add(r, "error", error = json_object_new_object());
        json_object_object_add(r, "id", json_object_new_string("1"));
        json_object_object_add(error, "code", json_object_new_int(call->errcode));
        json_object_object_add(error, "message", json_object_new_string(call->errmsg));
    }
    else if (call->retval)
    {
        r = json_object_new_object();
        json_object_object_add(r, "result", _xr_value_serialize_json(call->retval));
        json_object_object_add(r, "error", NULL);
        json_object_object_add(r, "id", json_object_new_string("1"));
    }
    else
        g_return_if_reached();

    *buf = g_strdup(json_object_to_json_string(r));
    *len = strlen(*buf);

    json_object_put(r);
}
Ejemplo n.º 25
0
static int _add_artifact(json_object *result, char *name, int16_t value)
{
	if (value != -1) {
		json_object_object_add(result, name, json_object_new_int(value));
		return 1;
	}
	return 0;
}
Ejemplo n.º 26
0
int SchemaJsonResponseFormatter::writeData(const GenericAnswer* ans,
                                           FILE* output) const {
    const SchemaAnswset& answSet = *((const SchemaAnswset*)ans);
    json_object* json_doc, *schemata;

    json_doc = json_object_new_object();
    schemata = json_object_new_array();

    /* Total number of formulae considered
     * (some schemata might have been dropped) */
    json_object_object_add(json_doc, "total",
                           json_object_new_int(answSet.total));
    json_object_object_add(json_doc, "size",
                           json_object_new_int(answSet.schemata.size()));

    for (const ExprSchema& exprSch : answSet.schemata) {
        json_object* schema = json_object_new_object();

        json_object_object_add(
            schema, "cmmlSchema",
            json_object_new_string(exprSch.root->toString().c_str()));
        json_object_object_add(schema, "coverage",
                               json_object_new_int(exprSch.coverage));

        json_object* formulae = json_object_new_array();
        for (const uint32_t f_id : exprSch.formulae) {
            json_object_array_add(formulae, json_object_new_int(f_id));
        }
        json_object_object_add(schema, "formulae", formulae);

        json_object* subst = json_object_new_array();
        for (const string& xref : exprSch.subst) {
            json_object_array_add(subst, json_object_new_string(xref.c_str()));
        }
        json_object_object_add(schema, "subst", subst);

        json_object_array_add(schemata, schema);
    }
    json_object_object_add(json_doc, "schemata", schemata);

    string json_string = json_object_to_json_string(json_doc);
    fwrite(json_string.c_str(), json_string.size(), 1, output);

    json_object_put(json_doc);
    return json_string.size();
}
Ejemplo n.º 27
0
void db_error_to_json(int code, struct json_object *jsobj)
{
    fprintf(stderr, "error(%d): %s\n", code, tcrdberrmsg(code));
    json_object_object_add(jsobj, "status", json_object_new_string("error"));
    json_object_object_add(jsobj, "code", json_object_new_int(code));
    json_object_object_add(jsobj, "message",
                            json_object_new_string((char *)tcrdberrmsg(code)));
}
Ejemplo n.º 28
0
void Adapter::json( json_object *entry ) const
{
  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, "path", json_object_new_string( uid.c_str( )));
  json_object_object_add( entry, "present", json_object_new_int( IsPresent( )));
  json_object *a = json_object_new_array();

  for( std::vector<Frontend *>::const_iterator it = frontends.begin( ); it != frontends.end( ); it++ )
  {
    json_object *entry = json_object_new_object( );
    (*it)->json( entry );
    json_object_array_add( a, entry );
  }

  json_object_object_add( entry, "frontends", a );
}
static void ac_json_80211_wtpradioinformation_createjson(struct json_object* jsonparent, void* data) {
	struct json_object* jsonitem;
	struct capwap_80211_wtpradioinformation_element* wtpradioinformation = (struct capwap_80211_wtpradioinformation_element*)data;

	jsonitem = json_object_new_object();
	json_object_object_add(jsonitem, "Mode", json_object_new_int((int)wtpradioinformation->radiotype));
	json_object_object_add(jsonparent, "IEEE80211WTPRadioInformation", jsonitem);
}
Ejemplo n.º 30
0
json_object *ipc_json_describe_output(swayc_t *output) {
	json_object *object = json_object_new_object();
	json_object *rect = json_object_new_object();
	json_object_object_add(rect, "x", json_object_new_int((int32_t) output->x));
	json_object_object_add(rect, "y", json_object_new_int((int32_t) output->y));
	json_object_object_add(rect, "width", json_object_new_int((int32_t) output->width));
	json_object_object_add(rect, "height", json_object_new_int((int32_t) output->height));

	json_object_object_add(object, "name", json_object_new_string(output->name));
	json_object_object_add(object, "active", json_object_new_boolean(true));
	json_object_object_add(object, "primary", json_object_new_boolean(false));
	json_object_object_add(object, "rect", rect);
	json_object_object_add(object, "current_workspace",
		output->focused ? json_object_new_string(output->focused->name) : NULL);

	return object;
}