Exemple #1
0
static void add_loadavg(struct json_object *obj) {
	FILE *f = fopen("/proc/loadavg", "r");
	if (!f)
		return;

	double loadavg;
	unsigned proc_running, proc_total;
	if (fscanf(f, "%lf %*f %*f %u/%u", &loadavg, &proc_running, &proc_total) == 3) {
		struct json_object *jso = json_object_new_double(loadavg);
		json_object_set_serializer(jso, json_object_double_to_json_string, "%.2f", NULL);
		json_object_object_add(obj, "loadavg", jso);

		struct json_object *processes = json_object_new_object();
		json_object_object_add(processes, "running", json_object_new_int(proc_running));
		json_object_object_add(processes, "total", json_object_new_int(proc_total));
		json_object_object_add(obj, "processes", processes);
	}

	fclose(f);
}
Exemple #2
0
static void pausing (struct afb_req request) {     /* AFB_SESSION_CHECK */

    mediaCtxHandleT *ctx = afb_req_context_get(request);
    json_object *jresp;

    /* check that context is initialized */
    if (ctx == NULL) {
      afb_req_fail (request, "failed", "uninitialized");
      return;
    }

    if (!_rygel_do (ctx, PAUSE, NULL)) {
      afb_req_fail (request, "failed", "could not pause chosen media");
      return;
    }

    jresp = json_object_new_object();
    json_object_object_add (jresp, "pause", json_object_new_string ("success"));
    afb_req_success (request, jresp, "Media - Paused");
}
Exemple #3
0
ipc::Message* constructIpcMessage(const rho::String& id, const rho::String& funcName, const int integer)
{
    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_object_add(obj, 
        const_cast<char*>(ServerParameterConstants::rhoInt), 
        json_object_new_int(integer));

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

    return message;
}
//find parent of leaf, if the path is not completely in SharedPreferences, append the lh obj
json_object * tg_shared_preferences_check_parent_of_leaf(SharedPreferences* thiz,const CHAR* key_path,CHAR** leaf_key)
{
    struct json_object *jso=NULL;
    struct json_object *next_jso=NULL;
    struct array_list* key_list = NULL;
    INT32 key_list_len = 0;
    INT32 idx = 0;
    return_val_if_fail((thiz&&key_path),NULL);
    key_list = array_list_new(tg_shared_preferences_key_free);
    return_val_if_fail((key_list),NULL);
    return_val_if_fail(tg_shared_preferences_parse_keypath(key_path,key_list,&key_list_len),NULL);
    for (jso=thiz->obj; idx<key_list_len-1; idx++)
    {
        next_jso = json_object_object_get(jso,(CHAR*)array_list_get_idx(key_list,idx));
        if (next_jso==NULL)
        {
            do {
                CHAR*key = (CHAR*)array_list_get_idx(key_list,idx);
                next_jso=json_object_new_object();
                json_object_object_add(jso,key,next_jso);
                idx++;
                jso = next_jso;
            } while (idx<key_list_len-1);

            break;
        }
        else
            jso = next_jso;

    }
    if (jso!=NULL)
    {
        CHAR* key = (CHAR*)array_list_get_idx(key_list,key_list_len-1);
        //ASSERT(key);
        *leaf_key = TG_CALLOC((strlen(key)+1),1);
        strcpy(*leaf_key,key);
    }
    array_list_free(key_list);
    return jso;

}
json_object* PackageDescription::toJSON() const
{
	json_object* json = NULL;
	if (m_isOldStyle) {
		json = json_object_new_object();
		json_object_object_add(json, (char*) "id",   json_object_new_string((char*) m_id.c_str()));
		json_object_object_add(json, (char*) "version", json_object_new_string(m_version.c_str()));
		json_object_object_add(json, (char*) "size", json_object_new_int((int)m_packageSize));

		json_object* apps = json_object_new_array();
		std::vector<std::string>::const_iterator appIdIt, appIdItEnd;
		for (appIdIt = m_appIds.begin(), appIdItEnd = m_appIds.end(); appIdIt != appIdItEnd; ++appIdIt) {
			json_object_array_add(apps, json_object_new_string((*appIdIt).c_str()));
		}
		json_object_object_add(json, (char*) "apps", apps);

	} else {
		json = json_tokener_parse(m_jsonString.c_str());
		if (!json || is_error(json)) {
			g_warning("%s: Failed to parse '%s' into a JSON string", __PRETTY_FUNCTION__, m_jsonString.c_str());
			return NULL;
		}
		json_object_object_add(json, (char*) "size", json_object_new_int((int)m_packageSize));

		json_object* label = JsonGetObject(json, "icon");
		if (label) {
			std::string icon = json_object_get_string(label);
			json_object_object_del(json, (char*) "icon");
			json_object_object_add(json, (char*) "icon", json_object_new_string((char*) (m_folderPath + "/" + icon).c_str()));
		}

		label = JsonGetObject(json, "miniicon");
		if (label) {
			std::string miniicon = json_object_get_string(label);
			json_object_object_del(json, (char*) "miniicon");
			json_object_object_add(json, (char*) "miniicon", json_object_new_string((char*) (m_folderPath + "/" + miniicon).c_str()));
		}

	}
	return json;
}
void ApplicationDescription::getAppDescriptionString(std::string &descString) const
{
    // Compose json string from the app description object  -------------------------------
    // This will only include the integer and string fields of App Description

    json_object* json = json_object_new_object();

    json_object_object_add(json, (char*) "id",   json_object_new_string((char*) m_id.c_str()));
    json_object_object_add(json, (char*) "category",   json_object_new_string((char*) m_category.c_str()));
    json_object_object_add(json, (char*) "main",   json_object_new_string((char*) m_entryPoint.c_str()));
    json_object_object_add(json, (char*) "version",   json_object_new_string((char*) m_version.c_str()));
    json_object_object_add(json, (char*) "noWindow",   json_object_new_boolean(m_isHeadLess));
    json_object_object_add(json, (char*) "splashicon", json_object_new_string((char*) m_splashIconName.c_str()));
    json_object_object_add(json, (char*) "splashBackground", json_object_new_string((char*) m_splashBackgroundName.c_str()));
    json_object_object_add(json, (char*) "miniicon", json_object_new_string((char*) m_miniIconName.c_str()));
    json_object_object_add(json, (char*) "transparent",   json_object_new_boolean(m_hasTransparentWindows));
    json_object_object_add(json, (char*) "folderPath", json_object_new_string((char*) m_folderPath.c_str()));
    json_object_object_add(json, (char*) "removable",   json_object_new_boolean(m_isRemovable));
    json_object_object_add(json, (char*) "userHideable",   json_object_new_boolean(m_isUserHideable));
    json_object_object_add(json, (char*) "visible",   json_object_new_boolean(m_isVisible));
    json_object_object_add(json, (char*) "hardwareFeaturesNeeded",   json_object_new_int(m_hardwareFeaturesNeeded));
    json_object_object_add(json, (char*) "type",   json_object_new_int(m_type));
    json_object_object_add(json, (char*) "attributes", json_object_new_string((char*) m_attributes.c_str()));
    json_object_object_add(json, (char*) "vendor", json_object_new_string((char*) m_vendorName.c_str()));
    json_object_object_add(json, (char*) "vendorUrl", json_object_new_string((char*) m_vendorUrl.c_str()));
    json_object_object_add(json, (char*) "size", json_object_new_int((int)m_appSize));
    json_object_object_add(json, (char*) "runtimeMemoryRequired", json_object_new_int((int)m_runtimeMemoryRequired));
    json_object_object_add(json, (char*) "appmenu",json_object_new_string((char*) m_appmenuName.c_str()));
    json_object_object_add(json, (char*) "launchinnewgroup", json_object_new_boolean(m_launchInNewGroup));
    json_object_object_add(json, (char*) "requestedWindowOrientation", json_object_new_string((char*) m_requestedWindowOrientation.c_str()));
    json_object_object_add(json, (char*) "tapToShareSupported",   json_object_new_boolean(m_tapToShareSupported));

    if (m_dockMode) {
        json_object_object_add(json, (char*) "dockMode", json_object_new_boolean(true));
        json_object_object_add(json, (char*) "exhibitionMode", json_object_new_boolean(true));
    }

    descString = json_object_to_json_string(json);

    json_object_put(json);
}
Exemple #7
0
void AppEffector::remove(ExternalApp * pApp)
{
	//TODO: IMPLEMENT (unfinished)
	if (!pApp)
	{
		return;
	}

	WebOSApp * pWebOSapp = qobject_cast<WebOSApp *>(pApp);
	pApp->m_stateBeingRemoved = true;		//this is set in case at some point the removal process needs to go async
	qDebug() << __FUNCTION__ << ": Removing app " << pApp->m_uid
			<< (pWebOSapp ? QString(" , ") + pWebOSapp->appId()
												: QString(" (not a webOS app type)"));

	if (!pWebOSapp)
	{
		qDebug() << __FUNCTION__ << ": not supporting removal of non-WebOSApp type at this point";
		return;
	}

	//I'm going to hijack ApplicationManager's LS handle to make a call to remove an app
	json_object* payload = json_object_new_object();
	LSError lserror;
	LSErrorInit(&lserror);

	///TODO: do I want to track remove status???
	json_object_object_add(payload, "id", json_object_new_string(pWebOSapp->appId().toAscii().constData()));
	if (!LSCall(ApplicationManager::instance()->m_serviceHandlePrivate,
			"palm://com.palm.appInstallService/remove",json_object_to_json_string(payload),
			NULL, NULL, NULL, &lserror)) {
		LSErrorFree(&lserror);
	}
	json_object_put(payload);

	//!...this HAS TO BE THE LAST CALL IN THIS FUNCTION!!! and also, make sure nothing much happens up the chain either
#if defined(TARGET_DESKTOP)
	LauncherObject::primaryInstance()->slotAppPreRemove(*pWebOSapp,DimensionsSystemInterface::AppMonitorSignalType::AppManSourced);
#endif

	return;
}
Exemple #8
0
static struct ac_soap_response* ac_session_action_authorizestation_request(struct ac_session_t* session, uint8_t radioid, uint8_t wlanid, uint8_t* address) {
	const char* jsonmessage;
	char* base64confstatus;
	struct json_object* jsonparam;
	struct ac_soap_response* response;
	char addrtext[CAPWAP_MACADDRESS_EUI48_BUFFER];

	/* Create SOAP request with JSON param
		{
			RadioID: [int],
			WLANID: [int],
			Station: [string],
		}
	*/

	/* */
	jsonparam = json_object_new_object();

	/* RadioID */
	json_object_object_add(jsonparam, "RadioID", json_object_new_int((int)radioid));

	/* WLANID */
	json_object_object_add(jsonparam, "WLANID", json_object_new_int((int)wlanid));

	/* Station */
	json_object_object_add(jsonparam, "Station", json_object_new_string(capwap_printf_macaddress(addrtext, address, MACADDRESS_EUI48_LENGTH)));

	/* Get JSON param and convert base64 */
	jsonmessage = json_object_to_json_string(jsonparam);
	base64confstatus = capwap_alloc(AC_BASE64_ENCODE_LENGTH(strlen(jsonmessage)));
	ac_base64_string_encode(jsonmessage, base64confstatus);

	/* Send message */
	response = ac_soap_authorizestation(session, session->wtpid, base64confstatus);

	/* Free JSON */
	json_object_put(jsonparam);
	capwap_free(base64confstatus);

	return response;
}
void flow_local_sdp_req(struct flow *flow, const char *type, const char *sdp)
{
	struct call *call = flow_call(flow);
	struct json_object *jobj = NULL;
	struct rr_resp *rr;
	char url[256];
	int err;

	if (!call) {
		warning("flowmgr: local_sdp_req: no call\n");
		return;
	}

	err = rr_alloc(&rr, call_flowmgr(call), call, sdp_resp, flow);
	if (err) {
		warning("flowmgr: local_sdp_req: rest response (%m)\n", err);
		goto out;
	}

	snprintf(url, sizeof(url),
		 CREQ_LSDP, call_convid(call), flow_flowid(flow));

	jobj = json_object_new_object();
	json_object_object_add(jobj, "type", json_object_new_string(type));
	json_object_object_add(jobj, "sdp", json_object_new_string(sdp));

	err = flowmgr_send_request(call_flowmgr(call), call, rr, url,
				   HTTP_PUT, CTYPE_JSON, jobj);
	if (err) {
		warning("flowmgr: local_sdp_req: send_request() (%m)\n", err);
		goto out;
	}

 out:
	mem_deref(jobj);

	/* if an error happened here, we must inform the application */
	if (err) {
		flow_error(flow, err);
	}
}
Exemple #10
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;
        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++)
                json_object_array_add(row,
                                      json_object_new_string(series->points[i][j]));

            json_object_array_add(cols, row);
        }

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

    return jo;
}
Exemple #11
0
int sysmon_event(const char *module,
		 const char *event,
		 const char *param,
		 const char *msg)
{
	struct sockaddr_un servaddr;
	socklen_t addr_len;
	size_t msg_len;
	int sockfd, ret;
	char msg_buf[1024];
	json_object *jmsg;

	if ((sockfd = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) {
		return -1;
	}

	servaddr.sun_family = AF_UNIX;
	strcpy(servaddr.sun_path, SYSMON_ADDR);
	addr_len = strlen(servaddr.sun_path) + sizeof(servaddr.sun_family);

	jmsg = json_object_new_object();
	json_object_object_add(jmsg, "module", json_object_new_string(module));
	json_object_object_add(jmsg, "event", json_object_new_string(event));
	json_object_object_add(jmsg, "param", json_object_new_string(param));
	json_object_object_add(jmsg, "msg", json_object_new_string(msg));

	strcpy(msg_buf, json_object_to_json_string(jmsg));
	msg_len = strlen(msg_buf);

	/* ret = connect(sockfd, (struct sockaddr *)&servaddr, addr_len); */
	/* if (ret == -1){ */
	/* 	printf("connect error!\n"); */
	/* 	return -1; */
	/* } */

	/* send(sockfd, msg_buf, msg_len, 0); */
	sendto(sockfd, msg_buf, msg_len, 0, (struct sockaddr *)&servaddr, addr_len);

	close(sockfd);
	return 0;
}
Exemple #12
0
void distance_cb(struct evhttp_request *req, struct evbuffer *evb, void *ctx)
{
    double lat1, lng1, lat2, lng2;
    char *uri, *json;
    struct evkeyvalq args;
    struct json_object *jsobj;
    
    uri = evhttp_decode_uri(req->uri);
    evhttp_parse_query(uri, &args);
    free(uri);
    
    argtof(&args, "lat1", &lat1, 0);
    argtof(&args, "lng1", &lng1, 0);
    argtof(&args, "lat2", &lat2, 0);
    argtof(&args, "lng2", &lng2, 0);

    jsobj = json_object_new_object();
    json_object_object_add(jsobj, "distance", json_object_new_double(geo_distance(lat1, lng1, lat2, lng2)));

    finalize_json(req, evb, &args, jsobj);
}
static struct json_object *embed(const char *tag, struct json_object *obj)
{
	struct json_object *result;

	if (obj == NULL)
		result = NULL;
	else if (!tag)
		result = obj;
	else {
		result = json_object_new_object();
		if (result == NULL) {
			/* can't embed */
			result = obj;
		}
		else {
			/* TODO why is json-c not returning a status? */
			json_object_object_add(result, tag, obj);
		}
	}
	return result;
}
Exemple #14
0
ipc::Message* constructIpcMessage(const rho::String& id, const rho::String& funcName, const rho::Hashtable<rho::String, rho::String>& hash)
{
    json_object* obj      = json_object_new_object();
    json_object* jsonHash = constructParameter(hash);

    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_object_add(obj, 
        const_cast<char*>(ServerParameterConstants::hashTable), 
        jsonHash);

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

    return message;
}
/***************************
In deze functie is een vast commando geprogrammeerd dat altijd 
hetzelfde JSON commando teruggeeft om naar de client op te sturen, 
enkel de snelheid waaraan de client moet opladen variëert.
****************************/
char* giveJSON(){
	char* terug=(char*)malloc(500*sizeof(char));
	char * string1 = "{\"load\" : \"15\"}";	
	json_object * jobj1 = json_tokener_parse(string1);
	json_object * jobj2 = json_object_new_object();
	json_object *jarray = json_object_new_array();

	json_object *jarray2 = json_object_new_array();
  	json_object *jstring1 = json_object_new_string("voltage");
 	json_object *jstring2 = json_object_new_string("loadspeed");
  	json_object *jstring3 = json_object_new_string("temperature");
  	json_object_array_add(jarray2,jstring1);
  	json_object_array_add(jarray2,jstring2);
  	json_object_array_add(jarray2,jstring3);
	json_object_object_add(jobj2,"GET",jarray2);
	
	json_object_array_add(jarray,jobj1);
	json_object_array_add(jarray,jobj2);	
	sprintf(terug,"%s",json_object_to_json_string(jarray));
	return  terug;
}
static int json_luks1_segments(const struct luks_phdr *hdr_v1, struct json_object **segments_object)
{
	char num[16];
	int r;
	struct json_object *segments_obj, *field;

	segments_obj = json_object_new_object();
	if (!segments_obj)
		return -ENOMEM;

	r = json_luks1_segment(hdr_v1, &field);
	if (r) {
		json_object_put(segments_obj);
		return r;
	}
	snprintf(num, sizeof(num), "%u", CRYPT_DEFAULT_SEGMENT);
	json_object_object_add(segments_obj, num, field);

	*segments_object = segments_obj;
	return 0;
}
Exemple #17
0
OSStatus MICOAddFloatCellToSector(json_object* menus, char* const name,  float content, char* const privilege, json_object* secectionArray)
{
  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", json_object_new_double(content));
  json_object_object_add(object, "P", json_object_new_string(privilege)); 

  if(secectionArray)
    json_object_object_add(object, "S", secectionArray); 

  json_object_array_add(menus, object);

exit:
  return err;  
}
Exemple #18
0
/**
 * @ingroup VuoMathExpressionList
 * Encodes the value as a JSON object.
 *
 * Includes the expression's variables in the JSON object, to be used when generating the Calculate node class.
 * However, the variables are ignored by VuoMathExpression_valueFromJson().
 *
 * @eg{
 *   {
 *     "expression" : [ "y = x + 4", "2 * x" ],
 *     "inputVariables" : [ "x" ],
 *     "outputVariables" : [ "y", "result" ]
 *   }
 * }
 */
json_object * VuoMathExpressionList_jsonFromValue(const VuoMathExpressionList me)
{
	json_object *js = json_object_new_object();

	json_object_object_add(js, "expressions", VuoList_VuoText_jsonFromValue(me.expressions));

	if (me.parser)
	{
		VuoList_VuoText inputVariables = VuoMathExpressionParser_getInputVariables(me.parser);
		json_object_object_add(js, "inputVariables", VuoList_VuoText_jsonFromValue(inputVariables));
		VuoRetain(inputVariables);
		VuoRelease(inputVariables);

		VuoList_VuoText outputVariables = VuoMathExpressionParser_getOutputVariables(me.parser);
		json_object_object_add(js, "outputVariables", VuoList_VuoText_jsonFromValue(outputVariables));
		VuoRetain(outputVariables);
		VuoRelease(outputVariables);
	}

	return js;
}
Exemple #19
0
void BootManager::postCurrentState()
{
	LSError error;
	json_object* json = 0;

    if (m_currentState == BOOT_STATE_FIRSTUSE ||
        m_currentState == BOOT_STATE_NORMAL)
        Q_EMIT bootFinished();

	LSErrorInit(&error);

	json = json_object_new_object();

	std::string stateStr = bootStateToStr(m_currentState);
	json_object_object_add(json, (char*) "state", json_object_new_string(stateStr.c_str()));

	if (!LSSubscriptionPost(m_service, "/", "getStatus", json_object_to_json_string(json), &error))
		LSErrorFree (&error);

	json_object_put(json);
}
TEST(zapi, local_sdp)
{
	const char *msg = "v=0\r\no=- 177043771 1811780385 IN IP4 192.168.10.69\r\ns=-\r\nc=IN IP4 192.168.10.69\r\nt=0 0\r\na=ice-options:trickle\r\na=OFFER\r\nm=audio 21960 RTP/SAVPF 96 0 8\r\na=rtpmap:96 opus/48000/2\r\na=fmtp:96 stereo=0;sprop-stereo=0\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtcp:21961\r\na=sendrecv\r\na=rtcp-mux\r\na=ice-ufrag:w0KwpCImvqEEO6I\r\na=ice-pwd:XyEeYe2AY9ctgOIFCUfMk0lRJ468y7d\r\na=fingerprint:sha-1 5d:d1:13:5d:bb:72:f3:34:6d:db:bd:2f:e1:c5:72:bf:1a:e5:eb:ad\r\na=setup:actpass\r\na=candidate:1 1 udp 2113929471 192.168.10.69 21960 typ host\r\n";
	struct json_object *jobj;
	struct zapi_local_sdp b, a = {"offer", msg};
	int err;


	jobj = json_object_new_object();

	err = zapi_local_sdp_encode(jobj, &a);
	ASSERT_EQ(0, err);

	err = zapi_local_sdp_decode(&b, jobj);
	ASSERT_EQ(0, err);

	ASSERT_STREQ(a.type, b.type);
	ASSERT_STREQ(a.sdp, b.sdp);

	mem_deref(jobj);
}
Exemple #21
0
int main(int argc, char *argv[]) {
    int c;
    extern char* optarg;
    struct json_object* response;

    char* title = NULL;
    char* body = NULL;
    char* token = config_get_token();
    char* repo = repo_get_repo();
    struct json_object* issue = json_object_new_object();

    if (token == NULL || repo == NULL)
        return 1;

    while ((c = getopt(argc, argv, "t:m:")) != EOF) {
        switch (c) {
            case 't':
                title = optarg;
                break;
            case 'm':
                body = optarg;
                break;
        }
    }
    if (title == NULL || body == NULL) {
        fprintf(stderr, "Usage: git issue -m \"issue body\" -t \"issue title\"\n");
        return 1;
    }

    json_object_object_add(issue, "title", json_object_new_string(title));
    json_object_object_add(issue, "body", json_object_new_string(body));
    
    response = github_create_issue(repo, issue, token);
    if (response) {
        printf("Created issue #%s\n", jsonh_get_string(response, "number"));
        return 0;
    }

    return 1;
}
Exemple #22
0
json_object* OGRGMEFeatureToGeoJSON(OGRFeature* poFeature)

{
    if( NULL == poFeature )
        return NULL;

    json_object* pjoFeature = json_object_new_object();
    CPLAssert( NULL != pjoFeature );

    json_object_object_add( pjoFeature, "type",
                            json_object_new_string("Feature") );

    /* -------------------------------------------------------------------- */
    /*      Write feature geometry to GeoJSON "geometry" object.            */
    /* -------------------------------------------------------------------- */
    json_object* pjoGeometry = NULL;
    OGRGeometry* poGeometry = poFeature->GetGeometryRef();

    pjoGeometry = OGRGMEGeometryToGeoJSON(poGeometry);
    if ( NULL == pjoGeometry ) {
        CPLError( CE_Failure, CPLE_AppDefined,
                  "GME: NULL Geometry detected in feature " CPL_FRMT_GIB ". Ignoring feature.",
                  poFeature->GetFID() );
        json_object_put( pjoFeature );
        return NULL;
    }
    json_object_object_add( pjoFeature, "geometry", pjoGeometry );

    /* -------------------------------------------------------------------- */
    /*      Write feature attributes to GeoJSON "properties" object.        */
    /* -------------------------------------------------------------------- */
    json_object* pjoProps = NULL;

    pjoProps = OGRGMEAttributesToGeoJSON( poFeature );
    if ( pjoProps )
        json_object_object_add( pjoFeature, "properties", pjoProps );

    return pjoFeature;
}
Exemple #23
0
json_object *hostspec_collect_cpu() {
  json_object *obj = json_object_new_array();
  assert(obj);

  FILE *fp = fopen("/proc/cpuinfo", "r");
  if (!fp) {
    ULOG_ERR("Unable to open /proc/cpuinfo: %s\n", strerror(errno));
    goto error;
  }

  char buf[1024], *p;
  json_object *obj_proc = NULL;
  while ((p = fgets(buf, sizeof buf, fp))) {
    chomp(p);

    if (begin_with(p, "processor\t")) {
      obj_proc = json_object_new_object();
      json_object_array_add(obj, obj_proc);
    }

    // Only send the model name for now: this should work for x86/amd64/arm/mips
    if (obj_proc) {
      if (begin_with(p, "cpu model\t") || begin_with(p, "model name\t")) {
        json_object_object_add(obj_proc, "model_name", json_object_new_string(after_colon(p)));
      }
    }
  }

  fclose(fp);
  return obj;

error:
  if (fp) {
    fclose(fp);
  }

  json_object_put(obj);
  return NULL;
}
static int _get_player_heroes(json_object *result, struct H3M_PLAYER_AI_ABSOD *player_ai)
{	
	json_object *items;
	json_object *hero_item;
	items = json_object_new_array();
	hero_item = json_object_new_object();

	for (unsigned int i = 0; i < player_ai->heroes_count; ++i) {
		// int player_type = player_ai->heroes[i].type;
		// json_object_object_add(hero_item, "type", 
		// 	json_object_new_int(player_type));

		// json_object_object_add(hero_item, "name", 
		// 	json_object_new_string(player_ai->heroes[i].name));

		json_object_array_add(items, hero_item);
	}
	
	json_object_array_add(result, items);

	return 0;
}
TEST(zapi, remote_sdp)
{
	const char *msg = "v=0\r\no=- 177043771 1811780385 IN IP4 192.168.10.69\r\ns=-\r\nc=IN IP4 192.168.10.69\r\nt=0 0\r\na=ice-options:trickle\r\na=OFFER\r\nm=audio 21960 RTP/SAVPF 96 0 8\r\na=rtpmap:96 opus/48000/2\r\na=fmtp:96 stereo=0;sprop-stereo=0\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtcp:21961\r\na=sendrecv\r\na=rtcp-mux\r\na=ice-ufrag:w0KwpCImvqEEO6I\r\na=ice-pwd:XyEeYe2AY9ctgOIFCUfMk0lRJ468y7d\r\na=fingerprint:sha-1 5d:d1:13:5d:bb:72:f3:34:6d:db:bd:2f:e1:c5:72:bf:1a:e5:eb:ad\r\na=setup:actpass\r\na=candidate:1 1 udp 2113929471 192.168.10.69 21960 typ host\r\n";
	struct json_object *jobj;
	struct zapi_remote_sdp b, a = {"answer", msg, "688c7157-e351-4c2c-ae82-2b991172e813", "29951b76-8d4a-4da6-859b-b85eac641412"};
	int err;

	jobj = json_object_new_object();

	err = zapi_remote_sdp_encode(jobj, &a);
	ASSERT_EQ(0, err);

	err = zapi_remote_sdp_decode(&b, jobj);
	ASSERT_EQ(0, err);

	ASSERT_STREQ(a.state, b.state);
	ASSERT_STREQ(a.sdp,   b.sdp);
	ASSERT_STREQ(a.flow,  b.flow);
	ASSERT_STREQ(a.conv,  b.conv);

	mem_deref(jobj);
}
/*do_send_voice*/
int do_send_voice(const char * did, const char * uri, const char * contact)
{
        json_object * pjson_obj_msg = NULL;

        printf("send voice uri 2:%s\n", uri);
        pjson_obj_msg = json_object_new_object();
        printf("send voice uri 3:%s\n", uri);
        json_object_object_add(pjson_obj_msg, "cmd",            json_object_new_string("send_voice"));
        printf("send voice uri 3:%s\n", uri);
        json_object_object_add(pjson_obj_msg, "device_id",      json_object_new_string(did));
        printf("send voice uri 3:%s\n", uri);
        json_object_object_add(pjson_obj_msg, "contact_id",     json_object_new_string(contact));
        json_object_object_add(pjson_obj_msg, "voice_uri",             json_object_new_string(uri));

        printf("send voice uri 2:%s\n", uri);
        printf("msg:%s\n", json_object_to_json_string(pjson_obj_msg));
        mosquitto_publish_send_msg(MQTT_SERVER_TOPIC, strlen(json_object_to_json_string(pjson_obj_msg)), json_object_to_json_string(pjson_obj_msg));

        json_object_put(pjson_obj_msg);
        return 0;

}
PUBLIC int  get_bus_config_bus_driving_data(char *buf, int size){
	int sta_count,ret;
	if( size <= 1024){
		return RET_ERROR;
	}
	json_object *new_obj = NULL, *arr_obj=NULL;
	new_obj = json_object_new_array();
	
	for (sta_count = 0; sta_count < BUS_STA_MX_COUNT ; sta_count ++){
		arr_obj = json_object_new_object();
		json_object_object_add(arr_obj, "id", json_object_new_int(sta_count));

		json_object_object_add(arr_obj, "st", json_object_new_int(bus_sta_status[sta_count] ));
		json_object_array_add(new_obj, arr_obj);
	}
	snprintf(buf, size, "%s",json_object_to_json_string(new_obj));
	ret = json_object_put(new_obj);
	WEB_STRACE(" ret:%d ,info NULL: %d, arr_obj :%d\n", ret,(new_obj == NULL)? 1:0,
		(arr_obj == NULL) ?1:0);
	
	return RET_OK;
}
static void
json_spit_jobq(eventer_jobq_t *jobq, void *closure) {
  struct json_object *doc = closure;
  struct json_object *jo = json_object_new_object();
  if(jobq->backq && jobq->backq->queue_name)
    json_object_object_add(jo, "backq", json_object_new_string(jobq->backq->queue_name));
  json_object_object_add(jo, "concurrency", json_object_new_int(jobq->concurrency));
  json_object_object_add(jo, "desired_concurrency", json_object_new_int(jobq->desired_concurrency));
  struct json_object *li = json_object_new_int(0);
  json_object_set_int_overflow(li, json_overflow_int64);
  json_object_set_int64(li, (long long int)jobq->total_jobs);
  json_object_object_add(jo, "total_jobs", li);
  json_object_object_add(jo, "backlog", json_object_new_int(jobq->backlog));
  json_object_object_add(jo, "inflight", json_object_new_int(jobq->inflight));
  li = json_object_new_int(0);
  json_object_set_int_overflow(li, json_overflow_int64);
  json_object_set_int64(li, (long long int)jobq->timeouts);
  json_object_object_add(jo, "timeouts", li);
  json_object_object_add(jo, "avg_wait_ms", json_object_new_double((double)jobq->avg_wait_ns/1000000.0));
  json_object_object_add(jo, "avg_run_ms", json_object_new_double((double)jobq->avg_run_ns/1000000.0));
  json_object_object_add(doc, jobq->queue_name, jo);
}
Exemple #29
0
json_object *ipc_json_describe_container(swayc_t *c) {
	if (!(sway_assert(c, "Container must not be null."))) {
		return NULL;
	}

	json_object *object = json_object_new_object();

	json_object_object_add(object, "id", json_object_new_int((int)c->id));
	json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL);
	json_object_object_add(object, "rect", ipc_json_create_rect(c));
	json_object_object_add(object, "visible", json_object_new_boolean(c->visible));
	json_object_object_add(object, "focused", json_object_new_boolean(c == current_focus));

	switch (c->type) {
	case C_ROOT:
		json_object_object_add(object, "type", json_object_new_string("root"));
		break;

	case C_OUTPUT:
		ipc_json_describe_output(c, object);
		break;

	case C_CONTAINER: // fallthrough
	case C_VIEW:
		ipc_json_describe_view(c, object);
		break;

	case C_WORKSPACE:
		ipc_json_describe_workspace(c, object);
		break;

	case C_TYPES: // fallthrough; this should never happen, I'm just trying to silence compiler warnings
	default:
		break;
	}

	return object;
}
int
write_handler(int fd)
{
    json_object *jobj;

    // Should we assume that even the TCP send's cannot be made when we want ?
    // In other words is it possible that TCP send's would wait or get stuck ? 
    // If so we cannot use send_json instead improve the logic here -- kmuriki
#ifdef WWDEBUG
    fprintf(stderr, "About to write on FD - %d, type - %d\n", fd, sock_data[fd].ctype);
#endif

    jobj = json_object_new_object();
    if (sock_data[fd].ctype == UNKNOWN) {
        json_object_object_add(jobj, "COMMAND", json_object_new_string("Send Type"));
    } else if (sock_data[fd].ctype == COLLECTOR) {
        json_object_object_add(jobj, "COMMAND", json_object_new_string("Send Data"));
    } else if (sock_data[fd].ctype == APPLICATION) {
        if (sock_data[fd].sqlite_cmd != NULL) {
            //printf("SQL cmd - %s\n", sock_data[fd].sqlite_cmd);
            json_object_object_add(jobj, "JSON_CT", json_object_new_int(0));
            sqlite3_exec(db, sock_data[fd].sqlite_cmd, json_from_db, jobj, NULL);
            //printf("JSON - %s\n",json_object_to_json_string(jobj));
            free(sock_data[fd].sqlite_cmd);
        } else {
            json_object_object_add(jobj, "COMMAND", json_object_new_string("Send SQL query"));
        }
    }

    send_json(fd, jobj);
    json_object_put(jobj);
    //printf("send successful!\n");

    FD_CLR(fd, &wfds);
    FD_SET(fd, &rfds);

    return 0;
}