Beispiel #1
0
Datei: json.c Projekt: Goos/r3
json_object * r3_node_to_json_object(const node * n) {
    json_object *obj;

    obj = json_object_new_object();

    if (n->combined_pattern) {
        json_object_object_add(obj, "re", json_object_new_string(n->combined_pattern));
    }
    json_object_object_add(obj, "endpoint", json_object_new_int(n->endpoint));
    json_object_object_add(obj, "compare", json_object_new_int(n->compare_type));


    int i;

    if ( n->edge_len > 0 ) {
        json_object *edges_array = json_object_new_array();
        json_object_object_add(obj, "edges", edges_array);
        for (i = 0 ; i < n->edge_len ; i++ ) {
            json_object *edge_json_obj = r3_edge_to_json_object(n->edges[i]);
            json_object_array_add(edges_array, edge_json_obj);
        }
    }
    
    if ( n->route_len > 0 ) {
        json_object *routes_array = json_object_new_array();
        json_object_object_add(obj, "routes", routes_array);
        for (i = 0; i < n->route_len; i++ ) {
            json_object *route_json_obj = r3_route_to_json_object(n->routes[i]);
            json_object_array_add(routes_array, route_json_obj);
        }
    }


    return obj;
}
Beispiel #2
0
json_object * api_json_tuples(Buffer::Ptr buf) {

	json_object *json_tuples = json_object_new_array();
	Buffer::iterator it;

	print(log_debug, "==> number of tuples: %d", "api", buf->size());

	for (it = buf->begin(); it != buf->end(); it++) {
		struct json_object *json_tuple = json_object_new_array();

		buf->lock();

		// TODO use long int of new json-c version
		// API requires milliseconds => * 1000
		double timestamp = it->tvtod() * 1000; 
		double value = it->value();
		buf->unlock();

		json_object_array_add(json_tuple, json_object_new_double(timestamp));
		json_object_array_add(json_tuple, json_object_new_double(value));

		json_object_array_add(json_tuples, json_tuple);
	}

	return json_tuples;
}
json_object* LocalePrefsHandler::valuesForLocale()
{
	json_object* json = json_object_new_object();
	json_object* langArrayObj = json_object_new_array();

	for (LocaleEntryList::const_iterator it = m_localeEntryList.begin();
	it != m_localeEntryList.end(); ++it) {

		const LocaleEntry& locEntry = (*it);
		json_object* langObj = json_object_new_object();
		json_object_object_add(langObj, (char*) "languageName",
				json_object_new_string((char*) locEntry.language.first.c_str()));
		json_object_object_add(langObj, (char*) "languageCode",
				json_object_new_string((char*) locEntry.language.second.c_str()));

		json_object* countryArrayObj = json_object_new_array();
		for (NameCodePairList::const_iterator iter = locEntry.countries.begin();
		iter != locEntry.countries.end(); ++iter) {
			json_object* countryObj = json_object_new_object();
			json_object_object_add(countryObj, (char*) "countryName",
					json_object_new_string((char*) (*iter).first.c_str()));
			json_object_object_add(countryObj, (char*) "countryCode",
					json_object_new_string((char*) (*iter).second.c_str()));
			json_object_array_add(countryArrayObj, countryObj);
		}

		json_object_object_add(langObj, (char*) "countries", countryArrayObj);
		json_object_array_add(langArrayObj, langObj);
	}

	json_object_object_add(json, (char*) "locale", langArrayObj);

	return json;

}
Beispiel #4
0
json_object *ipc_json_describe_container_recursive(swayc_t *c) {
	json_object *object = ipc_json_describe_container(c);
	int i;

	json_object *floating = json_object_new_array();
	if (c->type != C_VIEW && c->floating && c->floating->length > 0) {
		for (i = 0; i < c->floating->length; ++i) {
			json_object_array_add(floating, ipc_json_describe_container_recursive(c->floating->items[i]));
		}
	}
	json_object_object_add(object, "floating_nodes", floating);

	json_object *children = json_object_new_array();
	if (c->type != C_VIEW && c->children && c->children->length > 0) {
		for (i = 0; i < c->children->length; ++i) {
			json_object_array_add(children, ipc_json_describe_container_recursive(c->children->items[i]));
		}
	}
	json_object_object_add(object, "nodes", children);

	if (c->type == C_ROOT) {
		json_object *scratchpad_json = json_object_new_array();
		if (scratchpad->length > 0) {
			for (i = 0; i < scratchpad->length; ++i) {
				json_object_array_add(scratchpad_json, ipc_json_describe_container_recursive(scratchpad->items[i]));
			}
		}
		json_object_object_add(object, "scratchpad", scratchpad_json);
	}

	return object;
}
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();
}
/*
*
*2.1.6	请求同步DTS配置
*返回类型: unsigned char*
*返回值: json格式数据
*author  mleaf_hexi
*mail:[email protected]
*
*/
static unsigned char* RequestSyncDtsAllConfigOptions(void)
{
		char struuidget[36];
		int L = 0;
		int n;
		unsigned char*RequestSyncDtsAllConfigOptions_string;
		unsigned char RequestSyncDtsAllConfigOptions_buf[LWS_SEND_BUFFER_PRE_PADDING + 4096 +
									  LWS_SEND_BUFFER_POST_PADDING];
		json_object *mainjson=json_object_new_object();
		json_object *header=json_object_new_object();
		json_object *action=json_object_new_object();
		
		json_object *action1=json_object_new_array();
		json_object *requestId=json_object_new_array();
		json_object_array_add(action1,json_object_new_string("REQUEST_SYNC_DTS_ALL_CONFIG_OPTIONS"));
		uuidget(struuidget);//读取UUID到struuidget
		printf("uuidget = %s\n", struuidget);
		json_object_array_add(requestId,json_object_new_string(struuidget));
	
		json_object_object_add(action,"action",action1);
		json_object_object_add(action,"requestId",requestId);
		json_object_object_add(mainjson,"header",action);
		
		const char *str=json_object_to_json_string(mainjson);
		printf("%s\n",str);
		
		for (n = 0; n < 1; n++)//转换成libwebsocket 可以发送的数据
			L += sprintf((char *)&RequestSyncDtsAllConfigOptions_buf[LWS_SEND_BUFFER_PRE_PADDING + L],"%s",json_object_to_json_string(mainjson));
		RequestSyncDtsAllConfigOptions_string=&RequestSyncDtsAllConfigOptions_buf[LWS_SEND_BUFFER_PRE_PADDING];
		json_object_put(mainjson);
		json_object_put(header);
		json_object_put(action);
		json_object_put(action1);
		json_object_put(requestId);
		return RequestSyncDtsAllConfigOptions_string;

/*输出格式
{
    "header": {
        "action": [
            "REQUEST_SYNC_DTS_ALL_CONFIG_OPTIONS"
        ],
        "requestId": [
            "157ed038-1c6d-44f4-a036-1d52bb9314f3"
        ]
    }
}

*/


}
Beispiel #7
0
json_object
*influxdb_serie_to_json(s_influxdb_series *series)
{
    json_object *jo = json_object_new_object();

    /* Name */
    json_object_object_add(jo, "name", json_object_new_string(series->name));

    /* Columns */
    {
        size_t i;
        json_object *cols = json_object_new_array();

        for (i = 0; i < series->columns_length; i++)
            json_object_array_add(cols,
                                  json_object_new_string(series->columns[i]));

        json_object_object_add(jo, "columns", cols);
    }

    /* Points */
    {
        size_t i, j;
        struct json_object * json_obj;
        json_object *cols = json_object_new_array();

        for (i = 0; i < series->points_length; i++)
        {
            json_object *row = json_object_new_array();

            for (j = 0; j < series->columns_length; j++){
            	switch(series->column_types[j]){
            	case COLUMN_TYPE_INT:
            		json_obj = json_object_new_int(atoi(series->points[i][j]));
            		break;
            	case COLUMN_TYPE_DOUBLE:
            		json_obj = json_object_new_double(atof(series->points[i][j]));
            		break;
            	case COLUMN_TYPE_STRING:
            		json_obj = json_object_new_string(series->points[i][j]);
            	}
            	json_object_array_add(row,json_obj);
            }
            json_object_array_add(cols, row);
        }

        json_object_object_add(jo, "points", cols);
    }

    return jo;
}
int bridge_request_json_params(bridge_request_t *self, DBusMessageIter *it,
			       struct json_object **result, int is_array)
{
	struct json_object *tmp;
	const char *key;
	char *signature;

	*result = 0;

	/* empty array */
	if (is_array && dbus_message_iter_get_arg_type(it) == DBUS_TYPE_INVALID) {
		// empty array of dict entries => empty json object
		// empty array of other types => empty json array
		signature = dbus_message_iter_get_signature(it);
		if(signature && signature[0] == '{') {
			*result = json_object_new_object();
			dbus_free(signature);
		}
		else
			*result = json_object_new_array();
		return 0;
	}

	do {
		bridge_request_json_params_parse(self, it, &tmp, &key);
		if (!tmp) {
			bridge_request_error(self ,
				"unsupported dbus argument type.");
			FCGX_FPrintF(self->request.err, "type: %c\n", dbus_message_iter_get_arg_type(it));
			return EINVAL;
		}

		if (key != 0) {
			if (!*result)
				*result = json_object_new_object();
			json_object_object_add(*result, key, tmp);
		}
		else if (is_array) {
			if (!*result)
				*result = json_object_new_array();
			json_object_array_add(*result, tmp);
		}
		else {
			*result = tmp;
			break;
		}
	} while (dbus_message_iter_next(it));

	return 0;
}
/*
* 2.1.2	上传DTS日志
*返回类型: unsigned char*
*返回值: json格式数据
*author  mleaf_hexi
*mail:[email protected]
*/
static unsigned char* reportDeviceLog(void) 
{
	char struuidget[36];
	int L = 0;
	int n;
	unsigned char*reportDeviceLog_string;
	unsigned char DeviceLog_buf[LWS_SEND_BUFFER_PRE_PADDING + 4096 +
								  LWS_SEND_BUFFER_POST_PADDING];
	json_object *mainjson=json_object_new_object();
	json_object *header=json_object_new_object();
	json_object *action=json_object_new_object();
	json_object *data=json_object_new_object();
	
	
	json_object *action1=json_object_new_array();
	json_object *requestId=json_object_new_array();
	json_object_array_add(action1,json_object_new_string("REPORT_DTS_DEVICE_LOG"));
	uuidget(struuidget);//读取UUID到struuidget
	printf("uuidget = %s\n", struuidget);
	json_object_array_add(requestId,json_object_new_string(struuidget));//获取UUID写入requestId
	json_object_object_add(action,"action",action1);
	json_object_object_add(action,"requestId",requestId);
	json_object_object_add(mainjson,"header",action);


	json_object_object_add(data,
	   "fromDatetime",json_object_new_int64(9223372036854775807));
	json_object_object_add(data,
	   "toDatetime",json_object_new_int(39));
	json_object_object_add(data,
	   "logData",json_object_new_string("Logdatafromdtsdevice1asdfaew"));
	json_object_object_add(mainjson,"data",data);

	
	const unsigned char *str=json_object_to_json_string(mainjson);
	printf("%s\n",str);
	for (n = 0; n < 1; n++)//转换成libwebsocket 可以发送的数据
		   L += sprintf((char *)&DeviceLog_buf[LWS_SEND_BUFFER_PRE_PADDING + L],"%s",json_object_to_json_string(mainjson));
	reportDeviceLog_string=&DeviceLog_buf[LWS_SEND_BUFFER_PRE_PADDING];
	json_object_put(action);//在程序最后释放资源
	json_object_put(action1);
	json_object_put(header);
	json_object_put(requestId);
	json_object_put(data);
	json_object_put(mainjson);
	
	return reportDeviceLog_string;
	
}
Beispiel #10
0
static struct json_object* serialize_vars_set(int mode, struct var* set[], size_t n){
	struct json_object* json_vars = json_object_new_array();
	for ( size_t i = 0; i < n; i++ ){;
		json_object_array_add(json_vars, serialize_var(set[i], mode));
	}
	return json_vars;
}
Beispiel #11
0
void 
ldapInfoDB::buildJsonUser(string &json_Users){
	
	int rowNum;
	struct json_object *infor_group_object = NULL;
	infor_group_object = json_object_new_object();
	struct json_object *array_object = NULL;
	array_object = json_object_new_array();
	
	for(rowNum = 0; rowNum < _vec_User_Js.size(); ++rowNum){
		struct json_object *infor_object = NULL;
		infor_object = json_object_new_object();
		json_object_object_add(infor_object, "user_id", json_object_new_int(_vec_User_Js[rowNum].user_id));
		json_object_object_add(infor_object, "email", json_object_new_string(_vec_User_Js[rowNum].email.c_str()));
		json_object_object_add(infor_object, "password", json_object_new_string(_vec_User_Js[rowNum].password.c_str()));
		json_object_object_add(infor_object, "is_staff", json_object_new_int(_vec_User_Js[rowNum].is_staff));
		json_object_object_add(infor_object, "is_active", json_object_new_int(_vec_User_Js[rowNum].is_active));
		json_object_object_add(infor_object, "jurisdiction", json_object_new_int(_vec_User_Js[rowNum].jurisdiction));
		json_object_array_add(array_object, infor_object);
	}
	json_object_object_add(infor_group_object,"user",array_object);
	json_Users = json_object_to_json_string(infor_group_object);
	
#ifdef TRACE	
	printf("%s\n",json_object_to_json_string(infor_group_object));
#endif

	json_object_put(array_object);
	json_object_put(infor_group_object);
	
}
Beispiel #12
0
static json_object *get_video_html5(int fmt_type, char *key)
{
	int ret = -1;
	char **strArr;
	char *url = "http://vv.video.qq.com/geturl?vid=";
	url = join_str(url, key);
	url = join_str(url, "&otype=json");
	ret = request(url);
	if(ret < 1) return json_tokener_parse("[]");
	set_refer("http://v.qq.com");
	set_user_agent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36");
	char *result = response();
	strArr = preg_match("QZOutputJson\\s*=\\s*(.*);", result);
	
	json_object *json, *arr;
	json = json_tokener_parse(strArr[1]);
	json = json_object_object_get(json, "vd");
	json = json_object_object_get(json, "vi");
	json = json_object_array_get_idx(json, 0);
	
	if(json_object_object_exist(json, "url") == 0) return json_tokener_parse("[]");
	url = get_json_string_val(json, "url");
	arr = json_object_new_array();
	json = json_object_new_object();
	json_object_object_add(json, "url", json_object_new_string(url));
	json_object_array_add(arr, json);
	
	return arr;
}
Beispiel #13
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);

}
/*
 * Get called when a connman dbus method return. This function format parameters
 * and "forward" the callback to commands_callback.
 *
 * Format of the callback:
 *	- error: { key_error: [ "error string" ] }
 *	- success: { key_command: "command string", ... }
 *	- with user data: { ... , key_return_force_refresh: "user data string" }
 *
 * Note: setting user data will force refresh in context CONTEXT_SERVICES.
 *
 * @param iter answer to the command
 * @param error if an error occured, this will be filled with the appropriate
 *		error message
 * @param user_data data passed by the user while calling the method
 */
static void call_return_list(DBusMessageIter *iter, const char *error,
		void *user_data)
{
	struct json_object *res, *array;
	json_bool jerror;

	if (error) {
		res = json_object_new_object();
		array = json_object_new_array();

		json_object_array_add(array, json_object_new_string(error));
		json_object_object_add(res, key_error, array);
		jerror = TRUE;

	} else {
		res = dbus_to_json(iter);
		jerror = FALSE;

		if (!res)
			res = json_object_new_object();
	}

	if (user_data)
		json_object_object_add(res, key_return_force_refresh,
			json_object_new_string((const char*)user_data));

	commands_callback(res, jerror);
}
Beispiel #15
0
int CJsonEncoder::SetValue(const string& strParentKey, const string& strKey,const vector<string>& vecStrValue)
{
	json_object* pArray = json_object_new_array();  
	
	vector<string>::const_iterator iter;
	for(iter = vecStrValue.begin(); iter != vecStrValue.end(); iter++)
	{
		const string& strTemp = *iter;
		json_object_array_add(pArray, json_object_new_string(strTemp.c_str()));  
	}
	
    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;
}
Beispiel #16
0
struct json_object *
pubnub_decrypt_array(const char *cipher_key, struct json_object *message_list)
{
	int msg_n = json_object_array_length(message_list);
	struct json_object *newlist = json_object_new_array();

	for (int i = 0; i < msg_n; i++) {
		struct json_object *msg = json_object_array_get_idx(message_list, i);
		if (!json_object_is_type(msg, json_type_string)) {
			DBGMSG("decrypt fail: message not a string\n");
error:
			/* Format error. This is a most stringent approach. */
			json_object_put(newlist);
			return NULL;
		}

		DBGMSG("decrypting %s\n", json_object_get_string(msg));
		struct json_object *newmsg = pubnub_decrypt(cipher_key, json_object_get_string(msg));
		if (!newmsg) {
			DBGMSG("decrypt fail: message cannot be decrypted\n");
			goto error;
		}

		json_object_array_add(newlist, newmsg);
	}

	return newlist;
}
json_object* OGRGeoJSONWriteMultiPolygon( OGRMultiPolygon* poGeometry, int nCoordPrecision )
{
    CPLAssert( NULL != poGeometry );

    /* Generate "coordinates" object for 2D or 3D dimension. */
    json_object* poObj = NULL;
    poObj = json_object_new_array();

    for( int i = 0; i < poGeometry->getNumGeometries(); ++i )
    {
        OGRGeometry* poGeom = poGeometry->getGeometryRef( i );
        CPLAssert( NULL != poGeom );
        OGRPolygon* poPoly = static_cast<OGRPolygon*>(poGeom);

        json_object* poObjPoly = NULL;
        poObjPoly = OGRGeoJSONWritePolygon( poPoly, nCoordPrecision );
        if( poObjPoly == NULL )
        {
            json_object_put(poObj);
            return NULL;
        }
        
        json_object_array_add( poObj, poObjPoly );
    }

    return poObj;
}
Beispiel #18
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;
}
Beispiel #19
0
void *process(void *a)
{
	char **envp;
	const char *data;
	int res;
	FCGX_Request req;
	json_object *json;
	json_object *jarray;
	FCGX_InitRequest(&req, 0, 0);
	while(1)
	{
		res = FCGX_Accept_r(&req);
		if(res < 0)
		{
			break;
		}
		json = json_object_new_object();
		jarray = json_object_new_array();
		return_header(&req, 200, NULL, "application/json");
		for(envp = req.envp; *envp != NULL; envp++)
		{
//FIXME jsonurlencode...
			json_object_array_add(jarray, json_object_new_string(*envp));
		}
		json_object_object_add(json, "env", jarray);
		data = json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY);
		FCGX_FPrintF(req.out, "%s\n", data);
		json_object_put(json);
		FCGX_Finish_r(&req);
	}
	return NULL;
}
Beispiel #20
0
json_object *ipc_json_describe_input(struct libinput_device *device) {
	char* identifier = libinput_dev_unique_id(device);
	int vendor = libinput_device_get_id_vendor(device);
	int product = libinput_device_get_id_product(device);
	const char *name = libinput_device_get_name(device);
	double width = -1, height = -1;
	int has_size = libinput_device_get_size(device, &width, &height);

	json_object *device_object = json_object_new_object();
	json_object_object_add(device_object,"identifier",
			identifier ? json_object_new_string(identifier) : NULL);
	json_object_object_add(device_object,
			"vendor", json_object_new_int(vendor));
	json_object_object_add(device_object,
			"product", json_object_new_int(product));
	json_object_object_add(device_object,
			"name", json_object_new_string(name));
	if (has_size == 0) {
		json_object *size_object = json_object_new_object();
		json_object_object_add(size_object,
				"width", json_object_new_double(width));
		json_object_object_add(size_object,
				"height", json_object_new_double(height));
	} else {
		json_object_object_add(device_object, "size", NULL);
	}

	struct {
		enum libinput_device_capability cap;
		const char *name;
		// If anyone feels like implementing device-specific IPC output,
		// be my guest
		json_object *(*describe)(struct libinput_device *);
	} caps[] = {
		{ LIBINPUT_DEVICE_CAP_KEYBOARD, "keyboard", NULL },
		{ LIBINPUT_DEVICE_CAP_POINTER, "pointer", NULL },
		{ LIBINPUT_DEVICE_CAP_TOUCH, "touch", NULL },
		{ LIBINPUT_DEVICE_CAP_TABLET_TOOL, "tablet_tool", NULL },
		{ LIBINPUT_DEVICE_CAP_TABLET_PAD, "tablet_pad", NULL },
		{ LIBINPUT_DEVICE_CAP_GESTURE, "gesture", NULL },
#ifdef LIBINPUT_DEVICE_CAP_SWITCH // libinput 1.7.0+
		{ LIBINPUT_DEVICE_CAP_SWITCH, "switch", NULL },
#endif		
	};

	json_object *_caps = json_object_new_array();
	for (size_t i = 0; i < sizeof(caps) / sizeof(caps[0]); ++i) {
		if (libinput_device_has_capability(device, caps[i].cap)) {
			json_object_array_add(_caps, json_object_new_string(caps[i].name));
			if (caps[i].describe) {
				json_object *desc = caps[i].describe(device);
				json_object_object_add(device_object, caps[i].name, desc);
			}
		}
	}
	json_object_object_add(device_object, "capabilities", _caps);

	free(identifier);
	return device_object;
}
Beispiel #21
0
static void AddMetaData(char *oid, const char *metafile) {
  json_object *obj, *result, *child;

  obj = ReadMetaFile(metafile);
  if (obj == NULL) {
    obj = json_object_new_object();
    result = json_object_new_array();
    json_object_object_add(obj, "result", result);
  } else {
    json_object_object_get_ex(obj, "result", &result);
  }

  child = json_object_new_object();
  json_object_object_add(child, "type", json_object_new_string(Type));
  json_object_object_add(child, "object_id", json_object_new_string(oid));
  if (Printer != NULL) {
    json_object_object_add(child, "printer", json_object_new_string(Printer));
  }
  if (Title != NULL) {
    json_object_object_add(child, "title", json_object_new_string(Title));
  }
  if (ShowDialog) {
    json_object_object_add(child, "showdialog", json_object_new_boolean(TRUE));
  }
  if (Filename != NULL) {
    json_object_object_add(child, "filename", json_object_new_string(Filename));
  }
  if (Desc != NULL) {
    json_object_object_add(child, "description", json_object_new_string(Desc));
  }

  json_object_array_add(result, child);

  WriteMetaFile(metafile, obj);
}
Beispiel #22
0
ipc::Message* constructIpcMessage(const rho::String& id, const rho::String& funcName, const rho::Vector<rho::String>& array)
{
    json_object* obj = json_object_new_object();

    json_object_object_add(obj, 
        const_cast<char*>(ServerParameterConstants::methodName), 
        json_object_new_string(const_cast<char*>(funcName.c_str())));

    json_object_object_add(obj, 
        const_cast<char*>(ServerParameterConstants::printerIdType), 
        json_object_new_string(const_cast<char*>(id.c_str())));

    json_object* jsonArray = json_object_new_array();

    rho::Vector<rho::String>::const_iterator cit = array.begin();
    rho::Vector<rho::String>::const_iterator eit = array.end();

    for (; cit != eit; ++cit)
    {
        json_object_array_add(jsonArray, 
            json_object_new_string(const_cast<char*>(cit->c_str())));
    }

    json_object_object_add(obj, 
        const_cast<char*>(ServerParameterConstants::arrayType), jsonArray);

    ipc::Message* message = new ipc::Message(json_object_to_json_string(obj), false);

    return message;
}
Beispiel #23
0
/* Handles adding one or more params for a single key. If the key doesn't
   exist, its a normal object add. If it does exist and is not already an
   array object, delete it and make it into an array object. Otherwise
   add the new param to the existing array object. */
static void
add_param_to_json_retobj(json_object *retobj, char const *key, json_object *addobj)
{
    json_object *existing_member = 0;

    if (json_object_object_get_ex(retobj, key, &existing_member))
    {
        if (json_object_is_type(existing_member, json_type_array))
        {
            json_object_array_add(existing_member, addobj);
        }
        else
        {
            json_object *addarray = json_object_new_array();
            json_object_array_add(addarray, existing_member);
            json_object_array_add(addarray, addobj);
            json_object_get(existing_member);
            json_object_object_add(retobj, key, addarray); /* replaces */
        }
    }
    else
    {
        json_object_object_add(retobj, key, addobj);
    }
}
Beispiel #24
0
void 
ldapInfoDB::buildJsonGroup(string &json_GroupNames){
		
	//组织json
	int rowNum;
	struct json_object *infor_group_object = NULL;
	infor_group_object = json_object_new_object();
	struct json_object *array_object = NULL;
	array_object = json_object_new_array();
	
	
	for(rowNum = 0; rowNum < _vec_Group_Js.size(); ++rowNum){
		struct json_object *infor_object = NULL;
		infor_object = json_object_new_object();
		json_object_object_add(infor_object, "group_id", json_object_new_int(_vec_Group_Js[rowNum].group_id));
		json_object_object_add(infor_object, "group_name", json_object_new_string(_vec_Group_Js[rowNum].group_name.c_str()));
		json_object_object_add(infor_object, "creator_name", json_object_new_string(_vec_Group_Js[rowNum].creator_name.c_str()));
		json_object_object_add(infor_object, "timestamp", json_object_new_int(_vec_Group_Js[rowNum].timestamp));
		json_object_array_add(array_object, infor_object);
	}
	json_object_object_add(infor_group_object,"group",array_object);
	json_GroupNames = json_object_to_json_string(infor_group_object);
	
#ifdef TRACE	
	printf("%s\n",json_object_to_json_string(infor_group_object));
#endif

	//json_object_put(infor_object);
	json_object_put(array_object);
	json_object_put(infor_group_object);	
}
Beispiel #25
0
json_object *cli_jsonarray(json_object *obj, const char *key)
{
    json_type objty;
    json_object *newobj;

    /* First check to see if this key exists */
    if (obj && key && json_object_object_get_ex(obj, key, &newobj)) {
        return json_object_is_type(newobj, json_type_array) ? newobj : NULL;
    }

    newobj = json_object_new_array();
    if (!(newobj))
        return NULL;

    if (obj) {
        objty = json_object_get_type(obj);

        if (key && objty == json_type_object) {
            json_object_object_add(obj, key, newobj);
            if (!json_object_object_get_ex(obj, key, &newobj))
                return NULL;
        } else if (objty == json_type_array) {
            json_object_array_add(obj, newobj);
        }
    }

    return newobj;
}
Beispiel #26
0
static void fwts_log_section_begin_json(fwts_log_file *log_file, const char *name)
{
	json_object *json_obj;
	json_object *json_log;

	FWTS_UNUSED(log_file);

	if ((json_obj = json_object_new_object()) == NULL)
		fwts_log_out_of_memory_json();

	if ((json_log = json_object_new_array()) == NULL)
		fwts_log_out_of_memory_json();

	/*
	 * unfortunately json_object_object_add can fail on
	 * a strdup, but it doesn't check this and doesn't
	 * tell us about this either. Bit lame really.
	 */
	json_object_object_add(json_obj, name, json_log);


	if (json_stack_index > 0)
		if (json_object_array_add(json_stack[json_stack_index-1].log, json_obj) != 0)
			fwts_log_out_of_memory_json();

	if (json_stack_index < MAX_JSON_STACK) {
		json_stack[json_stack_index].obj = json_obj;
		json_stack[json_stack_index].log = json_log;
		json_stack_index++;
	} else  {
		fprintf(stderr, "json log stack overflow pushing section %s.\n", name);
		exit(EXIT_FAILURE);
	}
}
json_object* OGRGeoJSONWriteGeometryCollection( OGRGeometryCollection* poGeometry, int nCoordPrecision )
{
    CPLAssert( NULL != poGeometry );

    /* Generate "geometries" object. */
    json_object* poObj = NULL;
    poObj = json_object_new_array();

    for( int i = 0; i < poGeometry->getNumGeometries(); ++i )
    {
        OGRGeometry* poGeom = poGeometry->getGeometryRef( i );
        CPLAssert( NULL != poGeom );
        
        json_object* poObjGeom = NULL;
        poObjGeom = OGRGeoJSONWriteGeometry( poGeom, nCoordPrecision );
        if( poGeom == NULL )
        {
            json_object_put(poObj);
            return NULL;
        }
        
        json_object_array_add( poObj, poObjGeom );
    }

    return poObj;
}
Beispiel #28
0
static json_object *gen_json_object_vlan_entry(VLAN_ENTRY *vlanEntry)
{
	if(vlanEntry == NULL){
		ERROR(GLOBAL_OUT_GROUP,"vlanEntry is NULL.\n");
		return NULL;
	}

	json_object *vlnEntry = json_object_new_object();		
	json_object_object_add(vlnEntry, "vlanID", json_object_new_int(vlanEntry->vid));
	json_object_object_add(vlnEntry, "MSTID", json_object_new_int(vlanEntry->sid));
	json_object_object_add(vlnEntry, "memberCount", json_object_new_int(vlanEntry->memberCount));
	if(vlanEntry->memberCount == 0){
		return vlnEntry;
	}
	//add port member
	json_object *portMember = json_object_new_array();
	for(int i=0; i<vlanEntry->memberCount; i++){
		json_object *portAttr = json_object_new_object();	
		BASE_VLAN_PORT *port = (vlanEntry->member) + i;
		//json_object_object_add(portAttr, "portid", json_object_new_int(port->portid));
		//json_object_object_add(portAttr, "egress", json_object_new_int(port->portAttr.egress));
		//json_object_object_add(portAttr, "state", json_object_new_int(port->portAttr.state));
		int portid = port->portid;
		struct ports *devport = gDevPorts + portid;
		json_object_object_add(portAttr, "port", json_object_new_string(devport->name));
		json_object_object_add(portAttr, "egress", json_object_new_string(egress_mode_str[port->portAttr.egress]));
		json_object_object_add(portAttr, "state", json_object_new_string(port_state_str[port->portAttr.state]));

		json_object_array_add(portMember, portAttr);
	}

	json_object_object_add(vlnEntry, "member", portMember);
	return vlnEntry;
}
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");
		}
	}
}
Beispiel #30
0
int CJsonEncoder::SetValue(const string& strParentKey, const string& strKey, const vector<CJsonEncoder>& vecEncoder)
{
	json_object* pArray = json_object_new_array();  
	
	vector<CJsonEncoder>::const_iterator iter;
	for(iter = vecEncoder.begin(); iter != vecEncoder.end(); iter++)
	{
		const CJsonEncoder &encoder = *iter;
		json_object_array_add(pArray, (json_object*)encoder.GetJsonObj());  
	}
	
    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;
}