int ixcgi_reqstb_recording(char *handle, int fe_id, int ch_id, char *in, size_t in_size)
{
    cJSON   *root;
    char    *out;
    size_t  n_recv;

    if ((root = cJSON_CreateObject()) == NULL)
        return -1;

    cJSON_AddItemToObject(root, HTTPD_OPCODE, cJSON_CreateString(HTTPD_RECORDING));
    cJSON_AddItemToObject(root, HTTPD_RECORDING_MY_IP, cJSON_CreateString(getenv("REMOTE_ADDR")));

    if (handle[0]) {
        cJSON_AddItemToObject(root, HTTPD_RECORDING_STOP, cJSON_CreateString(handle));
    } else {
        cJSON_AddItemToObject(root, HTTPD_RECORDING_FE_ID, cJSON_CreateNumber(fe_id));
        if (ch_id > 0)
            cJSON_AddItemToObject(root, HTTPD_RECORDING_CH_ID, cJSON_CreateNumber(ch_id));
    }

    n_recv = send_recv_stbd(out = cJSON_Print(root), in, in_size, 2000);

    cJSON_Delete(root);
    free(out);

    return (n_recv == 0) ? -1 : 0 ;
}
int ixcgi_reqstb_channel_list(int fe_id, int rf_id, char *in, size_t in_size)
{
    cJSON   *root;
    char    *out;
    size_t  n_recv;

    if ((root = cJSON_CreateObject()) == NULL)
        return -1;

    cJSON_AddItemToObject(root, HTTPD_OPCODE, cJSON_CreateString(HTTPD_CHANNEL_LIST));
    cJSON_AddItemToObject(root, HTTPD_CHANNEL_LIST_MY_IP, cJSON_CreateString(getenv("REMOTE_ADDR")));

    if (fe_id >= 0) {
        cJSON_AddItemToObject(root, HTTPD_CHANNEL_LIST_FE_ID, cJSON_CreateNumber(fe_id));
        if (rf_id > 0)
            cJSON_AddItemToObject(root, HTTPD_CHANNEL_LIST_RF_ID, cJSON_CreateNumber(rf_id));
    }

    n_recv = send_recv_stbd(out = cJSON_Print(root), in, in_size, 2000);

    cJSON_Delete(root);
    free(out);

    return (n_recv == 0) ? -1 : 0 ;
}
int ixcgi_reqstb_update_dvbs_tp(ix_dvbs_tp_t *dvbs_tp, char *in, size_t in_size)
{
    cJSON   *root, *item;
    char    *out;
    size_t  n_recv;

    if ((root = cJSON_CreateObject()) == NULL)
        return -1;

    cJSON_AddItemToObject(root, HTTPD_OPCODE, cJSON_CreateString(HTTPD_UPDATE_DVBS_TP));
    cJSON_AddItemToObject(root, HTTPD_UPDATE_DVBS_TP_MY_IP, cJSON_CreateString(getenv("REMOTE_ADDR")));
    cJSON_AddItemToObject(root, HTTPD_UPDATE_DVBS_TP_DVBS_TP, item = cJSON_CreateObject());

    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_TP_DVBS_RF_ID, cJSON_CreateNumber(dvbs_tp->rf_id));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_TP_DVBS_TP_FREQ, cJSON_CreateNumber(dvbs_tp->freq));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_TP_DVBS_TP_SYM, cJSON_CreateNumber(dvbs_tp->sym));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_TP_DVBS_TP_POLAR, cJSON_CreateNumber(dvbs_tp->polar));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_TP_DVBS_TP_DELIVERY, cJSON_CreateNumber(dvbs_tp->system));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_TP_DVBS_TP_MODULATION, cJSON_CreateNumber(dvbs_tp->modulation));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_TP_DVBS_TP_ORG_NETID, cJSON_CreateNumber(dvbs_tp->org_netid));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_TP_DVBS_TP_NETID, cJSON_CreateNumber(dvbs_tp->netid));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_TP_DVBS_TP_TSID, cJSON_CreateNumber(dvbs_tp->tsid));

    n_recv = send_recv_stbd(out = cJSON_Print(root), in, in_size, 2000);

    cJSON_Delete(root);
    free(out);

    return (n_recv == 0) ? -1 : 0 ;
}
int ixcgi_reqstb_update_dvbs(ix_dvbs_t *dvbs, char *in, size_t in_size)
{
    cJSON   *root, *item;
    char    *out;
    size_t  n_recv;

    if ((root = cJSON_CreateObject()) == NULL)
        return -1;

    cJSON_AddItemToObject(root, HTTPD_OPCODE, cJSON_CreateString(HTTPD_UPDATE_DVBS));
    cJSON_AddItemToObject(root, HTTPD_UPDATE_DVBS_MY_IP, cJSON_CreateString(getenv("REMOTE_ADDR")));
    cJSON_AddItemToObject(root, HTTPD_UPDATE_DVBS_DVBS, item = cJSON_CreateObject());

    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_DVBS_SAT_ID, cJSON_CreateNumber(dvbs->sat_id));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_DVBS_NAME, cJSON_CreateString(dvbs->name));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_DVBS_LNB, cJSON_CreateNumber(dvbs->lnb));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_DVBS_LNBF_LO, cJSON_CreateNumber(dvbs->lnbf_lo));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_DVBS_LNBF_HI, cJSON_CreateNumber(dvbs->lnbf_hi));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_DVBS_LNBF_REF, cJSON_CreateNumber(dvbs->lnbf_ref));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_DVBS_LNBP, cJSON_CreateNumber(dvbs->lnbp));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_DVBS_DISEQC, cJSON_CreateNumber(dvbs->diseqc));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_DVBS_DISEQC_PORT, cJSON_CreateNumber(dvbs->diseqc_port));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_DVBS_SAT_POS, cJSON_CreateNumber(dvbs->sat_pos));
    cJSON_AddItemToObject(item, HTTPD_UPDATE_DVBS_DVBS_KEY_TP, cJSON_CreateNumber(dvbs->key_tp));

    n_recv = send_recv_stbd(out = cJSON_Print(root), in, in_size, 2000);

    cJSON_Delete(root);
    free(out);

    return (n_recv == 0) ? -1 : 0 ;
}
예제 #5
0
void WebInterface::onGrooveEvent(GrooveEvent& event)
{
	// send event to websocket
	unsigned char outbuf[128];

	cJSON* pJson = cJSON_CreateObject();

	const char* eventName = nullptr;
	eventName = GrooveEvent_getNameString(event.getEvent());
	cJSON_AddItemToObject(pJson,"event",cJSON_CreateString(eventName));

	const char* controlName = nullptr;
	controlName = GrooveControl_getNameString(event.getControl());
	cJSON_AddItemToObject(pJson,"control",cJSON_CreateString(controlName));

	cJSON_AddItemToObject(pJson,"argv",cJSON_CreateNumber(event.getInt()));
	cJSON_AddItemToObject(pJson,"string",cJSON_CreateString(event.getString()));

	char* c = cJSON_PrintUnformatted(pJson);

	printf ("send: %s\n",c);

	outbuf[0] = 0x81;
	outbuf[1] = snprintf((char *) outbuf + 2, sizeof(outbuf) - 2, "%s", c);
	mg_write(_conn, outbuf, 2 + outbuf[1]);

	free(c);
	cJSON_Delete(pJson);
}
예제 #6
0
파일: server.c 프로젝트: DariaDar/Reposit
void server_dB(socket_t * client, db_t * db, list_t * lt)
{
    int cntPens = db_countPensioner(db);
    for(int i = 0; i < cntPens; i++)
    {
        list_push_back(lt, db_getPensionerById(db, i));
    }

    cJSON * arr = cJSON_CreateArray();

    for(int i = 1; i < list_getSize(lt); i++)
    {
        cJSON * pens = cJSON_CreateObject();
        pensioner_t * ps = list_get(lt, i);
        cJSON_AddItemToObject(pens, "name", cJSON_CreateString(pensioner_getName(ps)));
        cJSON_AddItemToObject(pens, "surname", cJSON_CreateString(pensioner_getSurname(ps)));
        cJSON_AddItemToObject(pens, "year", cJSON_CreateNumber(pensioner_getAge(ps)));
        cJSON_AddItemToObject(pens, "experience", cJSON_CreateNumber(pensioner_getExperience(ps)));
        cJSON_AddItemToObject(pens, "pension", cJSON_CreateNumber(pensioner_getPension(ps)));
        cJSON_AddItemToObject(pens, "surname", cJSON_CreateString(pensioner_getYear(ps)));
        cJSON_AddItemToArray(arr, pens);
    }
    char * Jtext = cJSON_Print(arr);
    server_sent(client, Jtext);
    free(Jtext);
}
예제 #7
0
파일: struct.c 프로젝트: lwch/QQRobot
char* msg_content_array_to_json_object_string(msg_content_array_t* array, const char* key)
{
    size_t i;
    cJSON* cjson_object = cJSON_CreateObject();
    cJSON* cjson_array = cJSON_CreateArray();
    char* ret;

    for (i = 0; i < array->count; ++i)
    {
        switch (array->vals[i].type)
        {
        case MSG_CONTENT_TYPE_STRING:
            cJSON_AddItemToArray(cjson_array, cJSON_CreateString(array->vals[i].string.ptr));
            break;
        case MSG_CONTENT_TYPE_FACE:
            {
                cJSON* cjson_tmp = cJSON_CreateArray();
                cJSON_AddItemToArray(cjson_tmp, cJSON_CreateString("face"));
                cJSON_AddItemToArray(cjson_tmp, cJSON_CreateNumber(array->vals[i].face_id));
                cJSON_AddItemToArray(cjson_array, cjson_tmp);
            }
            break;
        default:
            break;
        }
    }
    cJSON_AddItemToObject(cjson_object, key, cjson_array);
    ret = cJSON_PrintUnformatted(cjson_object);
    cJSON_Delete(cjson_object);
    return ret;
}
예제 #8
0
static int st_setVideoFormat(const char *output, const char *mode)
{
	elcdRpcType_t type;
	cJSON *res  = NULL;
	cJSON *params = cJSON_CreateObject();
	int    ret = 1;

	cJSON_AddItemToObject(params, "output", cJSON_CreateString(output));
	cJSON_AddItemToObject(params, "mode", cJSON_CreateString(mode));
	ret = st_rpcSync(elcmd_setvmode, params, &type, &res);
//	ret = st_rpcSyncTimeout( elcmd_setvmode, mode, 1, &type, &res );

	if( ret == 0 && type == elcdRpcResult && res && res->type == cJSON_String ) {
		if( strcmp(res->valuestring, "ok") ) {
			eprintf("%s: failed: %s\n", __FUNCTION__, res->valuestring);
			ret = 1;
		} else {
			stHelper_indicatorShowVideoFormat(mode);
		}
	} else if ( type == elcdRpcError && res && res->type == cJSON_String ) {
		eprintf("%s: error: %s\n", __FUNCTION__, res->valuestring);
		ret = 1;
	}
	cJSON_Delete(res);
	cJSON_Delete(params);

	return ret;
}
예제 #9
0
ssap_message* generateSIBDefinedSubscribeMessageWithParam(const char* sessionKey, const char* query, map_t *params){
    ssap_message* queryMessage = allocateSsapMessage();
    cJSON *body;
    
    body=cJSON_CreateObject();  
    
    cJSON_AddItemToObject(body, "data", cJSON_CreateNull());
    cJSON_AddItemToObject(body, "query", cJSON_CreateString(query));
    cJSON_AddItemToObject(body, "queryType", cJSON_CreateString("SIB_DEFINED"));
    
    cJSON *queryParams;
    queryParams=cJSON_CreateObject();
    
    size_t i;
    for(i=0;i<params->size;i++){
        cJSON_AddItemToObject(queryParams, params->data[i].key, cJSON_CreateString(params->data[i].value));
    }
    
    cJSON_AddItemToObject(body, "queryParams", queryParams);
    
    queryMessage->body=cJSON_PrintUnformatted(body);
    queryMessage->direction = REQUEST;
    queryMessage->messageId = NULL;
    queryMessage->messageType=QUERY;
    queryMessage->ontology=NULL;
   
    queryMessage->sessionKey=(char*) malloc((strlen(sessionKey)+1)*sizeof(char));
    strcpy(queryMessage->sessionKey, sessionKey);
    
    queryMessage->persistenceType=MONGODB;
    
    cJSON_Delete(body); //This method frees the memory of the key-value pairs
    freeMap(params);
    return queryMessage;
}
예제 #10
0
ssap_message* generateBulkMessage(const char* sessionKey, const char* ontology, bulkRequest* request){
    ssap_message* bulkMessage = allocateSsapMessage();
    cJSON *body;
    
    body = cJSON_CreateArray();
    size_t i;
    for (i = 0; i < request->size; i++){
      cJSON *ssapBulkItem = cJSON_CreateObject();
      ssap_message* msg = request->payload[i];
      cJSON_AddItemToObject(ssapBulkItem, "type", cJSON_CreateString(messageTypeToString(msg->messageType)));
      cJSON_AddItemToObject(ssapBulkItem, "body", cJSON_CreateString(msg->body));
      cJSON_AddItemToObject(ssapBulkItem, "ontology", cJSON_CreateString(msg->ontology));
      cJSON_AddItemToArray(body, ssapBulkItem);
    }    
    
    bulkMessage->body=cJSON_PrintUnformatted(body);
    bulkMessage->direction = REQUEST;
    bulkMessage->messageId=NULL;
    bulkMessage->messageType=BULK;
    bulkMessage->ontology=(char*) malloc((strlen(ontology)+1)*sizeof(char));
    strcpy(bulkMessage->ontology, ontology);
    bulkMessage->sessionKey=(char*) malloc((strlen(sessionKey)+1)*sizeof(char));
    strcpy(bulkMessage->sessionKey, sessionKey);
    bulkMessage->persistenceType=MONGODB;
 
    cJSON_Delete(body);
    freeBulkRequest(request);
    return bulkMessage;
}
void conference_event_adv_la(conference_obj_t *conference, conference_member_t *member, switch_bool_t join)
{

	//if (switch_core_session_media_flow(member->session, SWITCH_MEDIA_TYPE_VIDEO) == SWITCH_MEDIA_FLOW_SENDONLY) {
	switch_channel_set_flag(member->channel, CF_VIDEO_REFRESH_REQ);
	switch_core_media_gen_key_frame(member->session);
	//}

	if (conference && conference->la && member->session &&
		!switch_channel_test_flag(member->channel, CF_VIDEO_ONLY)) {
		cJSON *msg, *data;
		const char *uuid = switch_core_session_get_uuid(member->session);
		const char *cookie = switch_channel_get_variable(member->channel, "event_channel_cookie");
		const char *event_channel = cookie ? cookie : uuid;
		switch_event_t *variables;
		switch_event_header_t *hp;

		msg = cJSON_CreateObject();
		data = json_add_child_obj(msg, "pvtData", NULL);

		cJSON_AddItemToObject(msg, "eventChannel", cJSON_CreateString(event_channel));
		cJSON_AddItemToObject(msg, "eventType", cJSON_CreateString("channelPvtData"));

		cJSON_AddItemToObject(data, "action", cJSON_CreateString(join ? "conference-liveArray-join" : "conference-liveArray-part"));
		cJSON_AddItemToObject(data, "laChannel", cJSON_CreateString(conference->la_event_channel));
		cJSON_AddItemToObject(data, "laName", cJSON_CreateString(conference->la_name));
		cJSON_AddItemToObject(data, "role", cJSON_CreateString(conference_utils_member_test_flag(member, MFLAG_MOD) ? "moderator" : "participant"));
		cJSON_AddItemToObject(data, "chatID", cJSON_CreateString(conference->chat_id));
		cJSON_AddItemToObject(data, "canvasCount", cJSON_CreateNumber(conference->canvas_count));

		if (conference_utils_member_test_flag(member, MFLAG_SECOND_SCREEN)) {
			cJSON_AddItemToObject(data, "secondScreen", cJSON_CreateTrue());
		}

		if (conference_utils_member_test_flag(member, MFLAG_MOD)) {
			cJSON_AddItemToObject(data, "modChannel", cJSON_CreateString(conference->mod_event_channel));
		}

		cJSON_AddItemToObject(data, "chatChannel", cJSON_CreateString(conference->chat_event_channel));

		switch_core_get_variables(&variables);
		for (hp = variables->headers; hp; hp = hp->next) {
			if (!strncasecmp(hp->name, "conference_verto_", 17)) {
				char *var = hp->name + 17;
				if (var) {
					cJSON_AddItemToObject(data, var, cJSON_CreateString(hp->value));
				}
			}
		}
		switch_event_destroy(&variables);

		switch_event_channel_broadcast(event_channel, &msg, "mod_conference", conference_globals.event_channel_id);

		if (cookie) {
			switch_event_channel_permission_modify(cookie, conference->la_event_channel, join);
			switch_event_channel_permission_modify(cookie, conference->mod_event_channel, join);
			switch_event_channel_permission_modify(cookie, conference->chat_event_channel, join);
		}
	}
}
//Handler for Observe request
void messageObserve(MessageData* md) {
	int i = 0;
	MQTTMessage* message = md->message;
	void *payload = message->payload;
	char* respMsg;
	cJSON *resPayload, *resd, *resFields;
	resPayload = cJSON_CreateObject();
	cJSON_AddItemToObject(resPayload, "rc",
			cJSON_CreateNumber(RESPONSE_SUCCESS));
	cJSON * jsonPayload = cJSON_Parse(payload);
	cJSON* jreqId = cJSON_GetObjectItem(jsonPayload, "reqId");
	strcpy(currentRequestID, jreqId->valuestring);
	printf("Observe reqId:%s\n", currentRequestID);
	cJSON_AddItemToObject(resPayload, "reqId",
			cJSON_CreateString(currentRequestID));

	cJSON_AddItemToObject(resPayload, "d", resd = cJSON_CreateObject());

	cJSON_AddItemToObject(resd, "fields", resFields =
			cJSON_CreateArray());

	cJSON *d = cJSON_GetObjectItem(jsonPayload, "d");

	cJSON *fields = cJSON_GetObjectItem(d, "fields");

	//cJSON *fields = cJSON_GetObjectItem(jsonPayload,"fields");
	for (i = 0; i < cJSON_GetArraySize(fields); i++) {
		cJSON * field = cJSON_GetArrayItem(fields, i);

		cJSON* fieldName = cJSON_GetObjectItem(field, "field");

		cJSON * value = cJSON_GetArrayItem(fields, i);

		printf("Observe called for fieldName:%s\n",fieldName->valuestring);
		if (!strcmp(fieldName->valuestring, "mgmt.firmware")) {
			dmClient.bObserve = true;
			cJSON* resValue;
			cJSON* resField = cJSON_CreateObject();
			cJSON_AddItemToObject(resField, "field", cJSON_CreateString("mgmt.firmware"));
			cJSON_AddItemToObject(resField, "value", resValue = cJSON_CreateObject());
			cJSON_AddItemToObject(resValue, "state",
					cJSON_CreateNumber(
							dmClient.DeviceData.mgmt.firmware.state));

			cJSON_AddItemToObject(resValue, "updateStatus",
					cJSON_CreateNumber(
							dmClient.DeviceData.mgmt.firmware.updateStatus));

			cJSON_AddItemToArray(resFields,resField);

		}
	}
	respMsg = cJSON_Print(resPayload);
	cJSON_Delete(resPayload);
	//Publish the response to the IoTF
	publishActionResponse(RESPONSE, respMsg);

	cJSON_Delete(jsonPayload);
	free(respMsg);
}
예제 #13
0
    void
    OutofcoreOctreeBaseMetadata::serializeMetadataToDisk ()
    {
      // Create JSON object
      boost::shared_ptr<cJSON> idx (cJSON_CreateObject (), cJSON_Delete);
  
      cJSON* name = cJSON_CreateString (tree_name_.c_str ());
      cJSON* version = cJSON_CreateNumber ( __PCL_OUTOFCORE_VERSION__ );
      cJSON* pointtype = cJSON_CreateString (point_type_.c_str ());
      cJSON* lod = cJSON_CreateNumber (static_cast<double> (levels_of_depth_));

      // cJSON does not allow 64 bit ints.  Have to put the points in a double to
      // use this api, will allow counts up to 2^52 points to be stored correctly
      //or split into LSB MSB?
      std::vector<double> lodPoints_db;
      lodPoints_db.insert (lodPoints_db.begin (), LOD_num_points_.begin (), LOD_num_points_.end ());

      cJSON* numpts = cJSON_CreateDoubleArray ( &(lodPoints_db.front ()), static_cast<int>(lodPoints_db.size ()));

      cJSON_AddItemToObject (idx.get (), "name", name);
      cJSON_AddItemToObject (idx.get (), "version", version);
      cJSON_AddItemToObject (idx.get (), "pointtype", pointtype);
      cJSON_AddItemToObject (idx.get (), "lod", lod);
      cJSON_AddItemToObject (idx.get (), "numpts", numpts);
      cJSON_AddStringToObject(idx.get(), "coord_system", coordinate_system_.c_str());

      char* idx_txt = cJSON_Print (idx.get ());

      std::ofstream f (metadata_filename_.string ().c_str (), std::ios::out | std::ios::trunc);
      f << idx_txt;
      f.close ();

      free (idx_txt);
    }
예제 #14
0
void ensure_jsonitem(cJSON *json,char *field,char *value)
{
    cJSON *obj = cJSON_GetObjectItem(json,field);
    if ( obj == 0 )
        cJSON_AddItemToObject(json,field,cJSON_CreateString(value));
    else cJSON_ReplaceItemInObject(json,field,cJSON_CreateString(value));
}
예제 #15
0
파일: struct.c 프로젝트: lwch/QQRobot
cJSON* msg_content_array_to_json_value(msg_content_array_t* array)
{
    size_t i;
    cJSON* cjson_array = cJSON_CreateArray();

    for (i = 0; i < array->count; ++i)
    {
        switch (array->vals[i].type)
        {
        case MSG_CONTENT_TYPE_STRING:
            cJSON_AddItemToArray(cjson_array, cJSON_CreateString(array->vals[i].string.ptr));
            break;
        case MSG_CONTENT_TYPE_FACE:
            {
                cJSON* cjson_tmp = cJSON_CreateArray();
                cJSON_AddItemToArray(cjson_tmp, cJSON_CreateString("face"));
                cJSON_AddItemToArray(cjson_tmp, cJSON_CreateNumber(array->vals[i].face_id));
                cJSON_AddItemToArray(cjson_array, cjson_tmp);
            }
            break;
        default:
            break;
        }
    }
    return cjson_array;
}
예제 #16
0
template<typename Container, typename PointT> void
octree_base<Container, PointT>::saveToFile ()
{
    // Create JSON object
    boost::shared_ptr<cJSON> idx (cJSON_CreateObject (), cJSON_Delete);

    cJSON* name = cJSON_CreateString ("test");
    cJSON* version = cJSON_CreateNumber ( OUTOFCORE_VERSION_ );
    cJSON* pointtype = cJSON_CreateString ("urp");
    cJSON* lod = cJSON_CreateNumber (static_cast<double>(root_->m_tree_->max_depth_));

    // cJSON does not allow 64 bit ints.  Have to put the points in a double to
    // use this api, will allow counts up to 2^52 points to be stored correctly
    std::vector<double> lodPoints_db;
    lodPoints_db.insert (lodPoints_db.begin (), lodPoints_.begin (), lodPoints_.end ());

    cJSON* numpts = cJSON_CreateDoubleArray ( &(lodPoints_db.front ()), static_cast<int>(lodPoints_db.size ()) );

    cJSON_AddItemToObject (idx.get (), "name", name);
    cJSON_AddItemToObject (idx.get (), "version", version);
    cJSON_AddItemToObject (idx.get (), "pointtype", pointtype);
    cJSON_AddItemToObject (idx.get (), "lod", lod);
    cJSON_AddItemToObject (idx.get (), "numpts", numpts);
    cJSON_AddStringToObject(idx.get(), "coord_system", coord_system_.c_str());

    char* idx_txt = cJSON_Print (idx.get ());

    std::ofstream f (treepath_.string ().c_str (), std::ios::out | std::ios::trunc);
    f << idx_txt;
    f.close ();

    free (idx_txt);
}
예제 #17
0
static void compose_patch(cJSON * const patches, const unsigned char * const operation, const unsigned char * const path, const unsigned char *suffix, const cJSON * const value)
{
    cJSON *patch = cJSON_CreateObject();
    if (patch == NULL)
    {
        return;
    }
    cJSON_AddItemToObject(patch, "op", cJSON_CreateString((const char*)operation));

    if (suffix == NULL)
    {
        cJSON_AddItemToObject(patch, "path", cJSON_CreateString((const char*)path));
    }
    else
    {
        size_t suffix_length = pointer_encoded_length(suffix);
        size_t path_length = strlen((const char*)path);
        unsigned char *full_path = (unsigned char*)cJSON_malloc(path_length + suffix_length + sizeof("/"));

        sprintf((char*)full_path, "%s/", (const char*)path);
        encode_string_as_pointer(full_path + path_length + 1, suffix);

        cJSON_AddItemToObject(patch, "path", cJSON_CreateString((const char*)full_path));
        cJSON_free(full_path);
    }

    if (value != NULL)
    {
        cJSON_AddItemToObject(patch, "value", cJSON_Duplicate(value, 1));
    }
    cJSON_AddItemToArray(patches, patch);
}
예제 #18
0
파일: Value.cpp 프로젝트: hjanetzek/rct
cJSON *Value::toCJSON(const Value &value)
{
    switch (value.type()) {
    case Value::Type_Boolean: return value.toBool() ? cJSON_CreateTrue() : cJSON_CreateFalse();
    case Value::Type_Date:
    case Value::Type_Integer: return cJSON_CreateNumber(value.toInteger());
    case Value::Type_Double: return cJSON_CreateNumber(value.toDouble());
    case Value::Type_String: return cJSON_CreateString(value.toString().constData());
    case Value::Type_List: {
        cJSON *array = cJSON_CreateArray();
        for (const auto &v : *value.listPtr())
            cJSON_AddItemToArray(array, toCJSON(v));
        return array; }
    case Value::Type_Map: {
        cJSON *object = cJSON_CreateObject();
        for (const auto &v : *value.mapPtr())
            cJSON_AddItemToObject(object, v.first.constData(), v.second.toCJSON(v.second));
        return object; }
    case Value::Type_Invalid:
        break;
    case Value::Type_Undefined:
        break;
    case Value::Type_Custom:
        if (std::shared_ptr<Value::Custom> custom = value.toCustom()) {
            cJSON *ret = cJSON_CreateString(custom->toString().constData());
            if (ret) {
                ret->type = cJSON_RawString;
                return ret;
            }
        }
        break;
    }
    return cJSON_CreateNull();
}
예제 #19
0
int ont_video_dev_fileinfo_upload(void *_dev, int channel, t_ont_video_file *list, int n)
{
	ont_device_t *dev = _dev;
	char dsname[64];
	int i = 0;
	
	ont_platform_snprintf(dsname, sizeof(dsname), "ont_video_%d_mqtt_test_video", channel);

	cJSON *json = NULL;
	char *jsonValue = NULL;
	//"beginTime" : "2016-10-19 16:30:30",
	//"endTime" : "2016-10-20 16:30:30",  
	//"vedioDesc" : "video2"
	for (i = 0; i < n; i++)
	{
		json = cJSON_CreateObject();
		cJSON_AddItemToObject(json, "dst", cJSON_CreateString("video"));
		cJSON_AddItemToObject(json, "beginTime", cJSON_CreateString(list[i].begin_time));
		cJSON_AddItemToObject(json, "endTime", cJSON_CreateString(list[i].end_time));
		cJSON_AddItemToObject(json, "vedioDesc", cJSON_CreateString(list[i].descrtpion));
		jsonValue = cJSON_PrintUnformatted(json);
		ont_device_add_dp_object(dev, dsname, jsonValue);
		ont_platform_free(jsonValue);
		cJSON_Delete(json);
	}
	ont_device_send_dp(dev);
	return 0;
}
예제 #20
0
int32_t ramchain_ledgerhash(char *retbuf,int32_t maxlen,struct coin777 *coin,struct ramchain *ramchain,cJSON *argjson)
{
    struct coin777_hashes H[32]; int32_t i,n; char ledgerhash[65],*jsonstr; cJSON *item,*array,*json;
    if ( coin == 0 )
    {
        sprintf(retbuf,"{\"error\":\"null coin ptr\",\"coin\":\"%s\"}",coin->name);
        return(-1);
    }
    json = cJSON_CreateObject();
    if ( (n= coin777_syncblocks(H,(int32_t)(sizeof(H)/sizeof(*H)),coin)) > 0 )
    {
        array = cJSON_CreateArray();
        for (i=0; i<n; i++)
        {
            if ( coin777_ledgerhash(ledgerhash,&H[i]) == 0 )
            {
                item = cJSON_CreateArray();
                cJSON_AddItemToArray(item,cJSON_CreateNumber(H[i].blocknum));
                cJSON_AddItemToArray(item,cJSON_CreateString(ledgerhash));
                cJSON_AddItemToArray(array,item);
            }
        }
        cJSON_AddItemToObject(json,"result",cJSON_CreateString("success"));
        cJSON_AddItemToObject(json,"coin",cJSON_CreateString(coin->name));
        cJSON_AddItemToObject(json,"latest",cJSON_CreateNumber(ramchain->blocknum));
        cJSON_AddItemToObject(json,"ledgerhashes",array);
        jsonstr = cJSON_Print(json), free_json(json);
        _stripwhite(jsonstr,' ');
        strncpy(retbuf,jsonstr,maxlen-1), retbuf[maxlen-1] = 0;
        free(jsonstr);
        return(0);
    }
    sprintf(retbuf,"{\"error\":\"no sync data\",\"coin\":\"%s\"}",coin->name);
    return(-1);
}
예제 #21
0
파일: cosm.c 프로젝트: alexandre72/edams
/*
 *Add location feed to cosm. Return EINA_TRUE if success.
 */
Eina_Bool
cosm_location_feed_add(Location *location)
{
	Ecore_Con_Url *cosm_url = NULL;
	char *s;

	//Don't add cosm url feed if already there...
	if(!location || (location_cosm_feedid_get(location) != 0) || !edams_settings_cosm_apikey_get())
		return EINA_FALSE;

	debug(MSG_COSM, _("Creating cosm feed '%s'..."), location_name_get(location));

   	ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, (Ecore_Event_Handler_Cb)_url_feed_add_complete_cb,NULL);
   	cosm_url = ecore_con_url_custom_new("http://api.cosm.com/v2/feeds", "POST");
   	if (!cosm_url)
     {
		debug(MSG_COSM, _("Can't create Ecore_Con_Url object"));
		return EINA_FALSE;
     }
	//ecore_con_url_verbose_set(cosm_url, edams_settings_debug_get());
   	ecore_con_url_additional_header_add(cosm_url, "X-ApiKey", edams_settings_cosm_apikey_get());;
    ecore_con_url_data_set(cosm_url, (void*)location);

    char *locale = setlocale(LC_NUMERIC, NULL);
     setlocale(LC_NUMERIC, "POSIX");

	cJSON *root,*fmt;
	root=cJSON_CreateObject();
	asprintf(&s, "%s sensor.basic", location_name_get(location));
	cJSON_AddItemToObject(root, "title", cJSON_CreateString(s));
	FREE(s);
	cJSON_AddItemToObject(root, "version", cJSON_CreateString("1.0.0"));
	cJSON_AddItemToObject(root, "location", fmt=cJSON_CreateObject());
	cJSON_AddStringToObject(fmt, "name", location_name_get(location));
	//cJSON_AddStringToObject(fmt, "description", location_description_get(location));
	cJSON_AddStringToObject(fmt, "disposition", "fixed");
	cJSON_AddStringToObject(fmt, "exposure", "indoor");
	cJSON_AddStringToObject(fmt, "domain", "physical");

	if(location_latitude_get(location) != -1)
		cJSON_AddNumberToObject(fmt, "lat", location_latitude_get(location));

	if(location_longitude_get(location) != -1)
		cJSON_AddNumberToObject(fmt, "lon", location_longitude_get(location));

	s = cJSON_PrintUnformatted(root);
	cJSON_Delete(root);
    setlocale(LC_NUMERIC, locale);

	if(!ecore_con_url_post(cosm_url, (void*)s, strlen(s), NULL))
	{
		debug(MSG_COSM, _("Can't realize url PUT request"));
		return EINA_FALSE;
	}
	FREE(s);

	return EINA_TRUE;
}/*cosm_location_feed_add*/
예제 #22
0
파일: server.c 프로젝트: LinaDovhaniuk/lina
void server_deletePupil(socket_t * client,list_t * l,int id, db_t * self){
    if(db_deletePupilById(self,l,id) == 1){
        cJSON *jResp = cJSON_CreateObject();
        cJSON_AddItemToObject(jResp, "status", cJSON_CreateString("Ok"));
        cJSON_AddItemToObject(jResp, "description", cJSON_CreateString("Pupil with this Id deleted"));
        server_sendJson(client,jResp);
    }
    else server_sendWrongIndex(client);
}
예제 #23
0
void server_info(socket_t* clientSocket)
{
    cJSON * SM = cJSON_CreateObject();
    cJSON_AddItemToObject(SM, "student", cJSON_CreateString("Zakharchenko Vitaliy"));
    cJSON_AddItemToObject(SM, "group", cJSON_CreateString("KP-51"));
    cJSON_AddItemToObject(SM, "variant", cJSON_CreateNumber(12));
    char * jsonSM = cJSON_Print(SM);
    server_sent(clientSocket,jsonSM);
}
예제 #24
0
파일: server.c 프로젝트: lemeshkob/Repo1
void server_mastersByID(socket_t * client, http_request_t * req, db_t * db)
{
    char buffer[10240] = "";

    char * point = strstr(req->uri, "/api/ScrumMasters/");
    point += 18;
    int index = atoi(point);

    if(0 < index && index < db_count(db) + 1)
    {
        if (strcmp(req->method, "GET") == 0)
        {
            master_t * master = db_getDataById(db, index - 1);

            cJSON * jText = cJSON_CreateObject();
            cJSON_AddItemToObject(jText, "Name", cJSON_CreateString(master_getName(master)));
            cJSON_AddItemToObject(jText, "Surname", cJSON_CreateString(master_getSurname(master)));
            cJSON_AddItemToObject(jText, "CountK", cJSON_CreateNumber(master_getCountK(master)));
            cJSON_AddItemToObject(jText, "CountP", cJSON_CreateNumber(master_getCountP(master)));
            char * pageText = cJSON_Print(jText);

            free(master);

            char * textJSON = textToJSON(pageText);
            strcat(buffer, textJSON);
            free(textJSON);
        }
        else if (strcmp(req->method, "DELETE") == 0)
        {
            master_t * master = db_getDataById(db, index - 1);
            db_deleteData(db, master_getID(master));
            free(master);

            cJSON * jText = cJSON_CreateObject();
            cJSON_AddItemToObject(jText, "Success", cJSON_CreateString("Successfully deleted"));
            char * pageText = cJSON_Print(jText);

            char * textJSON = textToJSON(pageText);
            strcat(buffer, textJSON);
            free(textJSON);
        }
    }
    else
    {
        cJSON * jText = cJSON_CreateObject();
        cJSON_AddItemToObject(jText, "Error", cJSON_CreateString("ID Not Found"));
        char * pageText = cJSON_Print(jText);

        char * textJSON = textToJSON(pageText);
        strcat(buffer, textJSON);
        free(textJSON);
    }

    socket_write_string(client, buffer);
    socket_close(client);
}
예제 #25
0
파일: ed25519.c 프로젝트: himu007/komodo
static void ed25519ToJSON(const CC *cond, cJSON *params) {
    unsigned char *b64 = base64_encode(cond->publicKey, 32);
    cJSON_AddItemToObject(params, "publicKey", cJSON_CreateString(b64));
    free(b64);
    if (cond->signature) {
        b64 = base64_encode(cond->signature, 64);
        cJSON_AddItemToObject(params, "signature", cJSON_CreateString(b64));
        free(b64);
    }
}
예제 #26
0
파일: pupil.c 프로젝트: LinaDovhaniuk/lina
cJSON* pupil_pupilToJson(pupil_t * p){
    cJSON *pupil = cJSON_CreateObject();
    cJSON_AddItemToObject(pupil, "id", cJSON_CreateNumber(pupil_getId(p)));
    cJSON_AddItemToObject(pupil, "name", cJSON_CreateString(pupil_getName(p)));
    cJSON_AddItemToObject(pupil, "surname", cJSON_CreateString(pupil_getSurname(p)));
    cJSON_AddItemToObject(pupil, "score", cJSON_CreateNumber(pupil_getScore(p)));
    cJSON_AddItemToObject(pupil, "class", cJSON_CreateNumber(pupil_getClass(p)));
    cJSON_AddItemToObject(pupil, "growth", cJSON_CreateNumber(pupil_getGrowth(p)));
    return pupil;
}
char * teacher_toJSON (teacher_t self) {
    cJSON * SM = cJSON_CreateObject();
    cJSON_AddItemToObject(SM, "name", cJSON_CreateString(teacher_getName(self)));
    cJSON_AddItemToObject(SM, "birthdate", cJSON_CreateString(teacher_getBirthdate(self)));
    cJSON_AddItemToObject(SM, "years", cJSON_CreateNumber(teacher_getYears(self)));
    cJSON_AddItemToObject(SM, "rate", cJSON_CreateNumber(teacher_getRate(self)));
    cJSON_AddItemToObject(SM, "subjects", cJSON_CreateNumber(teacher_getSubjects(self)));
    char * jsonSM = cJSON_Print(SM);
    return jsonSM;
}
예제 #28
0
void * lanser_toJSON(lanser * self)
{
    cJSON * SM = cJSON_CreateObject();
    cJSON_AddItemToObject(SM, "name", cJSON_CreateString(Freelanser_name_get(self)));
    cJSON_AddItemToObject(SM, "surname", cJSON_CreateString(Freelanser_surname_get(self)));
    cJSON_AddItemToObject(SM, "age", cJSON_CreateNumber(Freelanser_age_get(self)));
    cJSON_AddItemToObject(SM, "date", cJSON_CreateString(Freelanser_date_get(self)));
    cJSON_AddItemToObject(SM, "salary", cJSON_CreateNumber(Freelanser_salary_get(self)));
    return SM;
}
예제 #29
0
static cJSON *
azy_value_serialize_basic_json(const Eina_Value *val)
{
   switch (azy_value_util_type_get(val))
     {
      case AZY_VALUE_INT:
        {
           int int_val = -1;
           eina_value_get(val, &int_val);
           return cJSON_CreateNumber(int_val);
        }

      case AZY_VALUE_TIME:
        {
           time_t t;
           struct tm *tim;
           char buf[1024];

           eina_value_get(val, &t);
           tim = localtime(&t);
           strftime(buf, sizeof(buf), "%Y%m%dT%H:%M:%S", tim);
           return cJSON_CreateString(buf);
        }

      case AZY_VALUE_STRING:
      case AZY_VALUE_BASE64:
        {
           const char *str_val;
           eina_value_get(val, &str_val);
           return cJSON_CreateString(str_val);
        }

      case AZY_VALUE_BOOL:
        {
           Eina_Bool bool_val;
           eina_value_get(val, &bool_val);

           if (bool_val)
             return cJSON_CreateTrue();

           return cJSON_CreateFalse();
        }

      case AZY_VALUE_DOUBLE:
        {
           double dbl_val = -1;
           eina_value_get(val, &dbl_val);
           return cJSON_CreateNumber(dbl_val);
        }
      default: break;
     }

   return NULL;
}
예제 #30
0
static void mod_amqp_command_response(mod_amqp_command_profile_t *profile, char *command, switch_stream_handle_t stream,
									  char *fs_resp_exchange, char *fs_resp_key, switch_status_t status)
{
	char *json_output = NULL;
	amqp_basic_properties_t props;
	cJSON *message = NULL;

	if (! profile->conn_active) {
		/* No connection, so we can not send the message. */
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Profile[%s] not active\n", profile->name);
		return;
	}

	/* Construct the api response */
	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Preparing api command response: [%s]\n", (char *)stream.data);
	message = cJSON_CreateObject();

	cJSON_AddItemToObject(message, "output", cJSON_CreateString((const char *) stream.data));
	cJSON_AddItemToObject(message, "command", cJSON_CreateString(command));
	cJSON_AddItemToObject(message, "status", cJSON_CreateNumber((double) status));

	json_output = cJSON_Print(message);
	cJSON_Delete(message);

	memset(&props, 0, sizeof(amqp_basic_properties_t));

	props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG;
	props.content_type = amqp_cstring_bytes("text/json");

	status = amqp_basic_publish(
								profile->conn_active->state,
								1,
								amqp_cstring_bytes(fs_resp_exchange),
								amqp_cstring_bytes(fs_resp_key),
								0,
								0,
								&props,
								amqp_cstring_bytes(json_output));

	switch_safe_free(json_output);

	if (status < 0) {
		const char *errstr = amqp_error_string2(-status);
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Profile[%s] failed to send event on connection[%s]: %s\n",
						  profile->name, profile->conn_active->name, errstr);

		/* This is bad, we couldn't send the message. Clear up any connection */
		mod_amqp_connection_close(profile->conn_active);
		profile->conn_active = NULL;
		return;
	}

	return;
}