本文整理汇总了C++中cJSON_AddItemToObject函数的典型用法代码示例。如果您正苦于以下问题:C++ cJSON_AddItemToObject函数的具体用法?C++ cJSON_AddItemToObject怎么用?C++ cJSON_AddItemToObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cJSON_AddItemToObject函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: conference_event_adv_la
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);
}
}
}
开发者ID:prashantchoudhary,项目名称:FreeswitchModified,代码行数:60,代码来源:conference_event.c
示例2: jaddstr
void jaddstr(cJSON *json,char *field,char *str) { cJSON_AddItemToObject(json,field,cJSON_CreateString(str)); }
开发者ID:jonesnxt,项目名称:SuperNET_API,代码行数:1,代码来源:cJSON.c
示例3: joylink_package_scan
char *
joylink_package_scan(const char *retMsg, const int retCode,
int scan_type, JLDevice_t *dv)
{
if(NULL == retMsg ){
return NULL;
}
cJSON *root, *arrary;
char *out = NULL;
root = cJSON_CreateObject();
if(NULL == root){
goto RET;
}
arrary = cJSON_CreateArray();
if(NULL == arrary){
cJSON_Delete(root);
goto RET;
}
cJSON_AddNumberToObject(root, "code", retCode);
cJSON_AddStringToObject(root, "msg", retMsg);
cJSON_AddStringToObject(root, "mac", dv->jlp.mac);
cJSON_AddStringToObject(root, "productuuid", dv->jlp.uuid);
cJSON_AddStringToObject(root, "feedid", dv->jlp.feedid);
cJSON_AddStringToObject(root, "devkey", dv->jlp.pubkeyS);
cJSON_AddNumberToObject(root, "lancon", dv->jlp.lancon);
cJSON_AddNumberToObject(root, "trantype", dv->jlp.cmd_tran_type);
cJSON_AddNumberToObject(root, "devtype", dv->jlp.devtype);
JLDevInfo_t *sdev = NULL;
int count = 0;
char *jsdev = NULL;
if(dv->jlp.devtype == E_JLDEV_TYPE_GW){
sdev = joylink_dev_sub_devs_get(&count, scan_type);
if(NULL != sdev){
jsdev = joylink_package_subdev(sdev, count);
cJSON *jsp_dev = cJSON_Parse(jsdev);
if(jsp_dev){
cJSON_AddItemToObject(root,"subdev", jsp_dev);
}
}
if(sdev != NULL){
free(sdev);
}
if(jsdev != NULL){
free(jsdev);
}
}
out=cJSON_Print(root);
cJSON_Delete(root);
RET:
return out;
}
开发者ID:Learn-iot,项目名称:gitfile,代码行数:62,代码来源:joylink_json.c
示例4: BinToDoxmJSON
char * BinToDoxmJSON(const OicSecDoxm_t * doxm)
{
if (NULL == doxm)
{
return NULL;
}
char *jsonStr = NULL;
cJSON *jsonDoxm = NULL;
char base64Buff[B64ENCODE_OUT_SAFESIZE(sizeof(((OicUuid_t*)0)->id)) + 1] = {};
uint32_t outLen = 0;
B64Result b64Ret = B64_OK;
cJSON *jsonRoot = cJSON_CreateObject();
VERIFY_NON_NULL(TAG, jsonRoot, ERROR);
jsonDoxm = cJSON_CreateObject();
VERIFY_NON_NULL(TAG, jsonDoxm, ERROR);
cJSON_AddItemToObject(jsonRoot, OIC_JSON_DOXM_NAME, jsonDoxm );
//OxmType -- Not Mandatory
if(doxm->oxmTypeLen > 0)
{
cJSON *jsonOxmTyArray = cJSON_CreateArray();
VERIFY_NON_NULL(TAG, jsonOxmTyArray, ERROR);
cJSON_AddItemToObject (jsonDoxm, OIC_JSON_OXM_TYPE_NAME, jsonOxmTyArray );
for (size_t i = 0; i < doxm->oxmTypeLen; i++)
{
cJSON_AddItemToArray (jsonOxmTyArray, cJSON_CreateString(doxm->oxmType[i]));
}
}
//Oxm -- Not Mandatory
if(doxm->oxmLen > 0)
{
cJSON *jsonOxmArray = cJSON_CreateArray();
VERIFY_NON_NULL(TAG, jsonOxmArray, ERROR);
cJSON_AddItemToObject (jsonDoxm, OIC_JSON_OXM_NAME,jsonOxmArray );
for (size_t i = 0; i < doxm->oxmLen; i++)
{
cJSON_AddItemToArray (jsonOxmArray, cJSON_CreateNumber(doxm->oxm[i]));
}
}
//OxmSel -- Mandatory
cJSON_AddNumberToObject(jsonDoxm, OIC_JSON_OXM_SEL_NAME, (int)doxm->oxmSel);
//Owned -- Mandatory
cJSON_AddBoolToObject(jsonDoxm, OIC_JSON_OWNED_NAME, doxm->owned);
//TODO: Need more clarification on deviceIDFormat field type.
#if 0
//DeviceIdFormat -- Mandatory
cJSON_AddNumberToObject(jsonDoxm, OIC_JSON_DEVICE_ID_FORMAT_NAME, doxm->deviceIDFormat);
#endif
//DeviceId -- Mandatory
outLen = 0;
b64Ret = b64Encode(doxm->deviceID.id, sizeof(doxm->deviceID.id), base64Buff,
sizeof(base64Buff), &outLen);
VERIFY_SUCCESS(TAG, b64Ret == B64_OK, ERROR);
cJSON_AddStringToObject(jsonDoxm, OIC_JSON_DEVICE_ID_NAME, base64Buff);
//Owner -- Mandatory
outLen = 0;
b64Ret = b64Encode(doxm->owner.id, sizeof(doxm->owner.id), base64Buff,
sizeof(base64Buff), &outLen);
VERIFY_SUCCESS(TAG, b64Ret == B64_OK, ERROR);
cJSON_AddStringToObject(jsonDoxm, OIC_JSON_OWNER_NAME, base64Buff);
jsonStr = cJSON_PrintUnformatted(jsonRoot);
exit:
if (jsonRoot)
{
cJSON_Delete(jsonRoot);
}
return jsonStr;
}
开发者ID:HoTaeWang,项目名称:iotivity,代码行数:79,代码来源:doxmresource.c
示例5: create_objects
/* Create a bunch of objects as demonstration. */
void create_objects() {
cJSON *root, *fmt, *img, *thm, *fld;
char *out;
int i; /* declare a few. */
/* Our "days of the week" array: */
const char *strings[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
/* Our matrix: */
int numbers[3][3] = {{0, -1, 0},
{1, 0, 0},
{0, 0, 1}};
/* Our "gallery" item: */
int ids[4] = {116, 943, 234, 38793};
/* Our array of "records": */
struct record fields[2] = {
{"zip", 37.7668, -1.223959e+2, "", "SAN FRANCISCO", "CA", "94107", "US", "100011"},
{"zip", 37.371991, -1.22026e+2, "", "SUNNYVALE", "CA", "94085", "US", "100012"}};
/* Here we construct some JSON standards, from the JSON site. */
/* Our "Video" datatype: */
root = cJSON_CreateObject();
cJSON_AddItemToObject(root, "name", cJSON_CreateString("Jack (\"Bee\") Nimble"));
cJSON_AddItemToObject(root, "format", fmt = cJSON_CreateObject());
cJSON_AddStringToObject(fmt, "type", "rect");
cJSON_AddNumberToObject(fmt, "width", 1920);
cJSON_AddNumberToObject(fmt, "height", 1080);
cJSON_AddFalseToObject (fmt, "interlace");
cJSON_AddNumberToObject(fmt, "frame rate", 24);
out = cJSON_Print(root);
cJSON_Delete(root);
printf("%s\n", out);
free(out); /* Print to text, Delete the cJSON, print it, release the string. */
/* Our "days of the week" array: */
root = cJSON_CreateStringArray(strings, 7);
out = cJSON_Print(root);
cJSON_Delete(root);
printf("%s\n", out);
free(out);
/* Our matrix: */
root = cJSON_CreateArray();
for (i = 0; i < 3; i++) cJSON_AddItemToArray(root, cJSON_CreateIntArray(numbers[i], 3));
/* cJSON_ReplaceItemInArray(root,1,cJSON_CreateString("Replacement")); */
out = cJSON_Print(root);
cJSON_Delete(root);
printf("%s\n", out);
free(out);
/* Our "gallery" item: */
root = cJSON_CreateObject();
cJSON_AddItemToObject(root, "Image", img = cJSON_CreateObject());
cJSON_AddNumberToObject(img, "Width", 800);
cJSON_AddNumberToObject(img, "Height", 600);
cJSON_AddStringToObject(img, "Title", "View from 15th Floor");
cJSON_AddItemToObject(img, "Thumbnail", thm = cJSON_CreateObject());
cJSON_AddStringToObject(thm, "Url", "http:/*www.example.com/image/481989943");
cJSON_AddNumberToObject(thm, "Height", 125);
cJSON_AddStringToObject(thm, "Width", "100");
cJSON_AddItemToObject(img, "IDs", cJSON_CreateIntArray(ids, 4));
out = cJSON_Print(root);
cJSON_Delete(root);
printf("%s\n", out);
free(out);
/* Our array of "records": */
root = cJSON_CreateArray();
for (i = 0; i < 2; i++) {
cJSON_AddItemToArray(root, fld = cJSON_CreateObject());
cJSON_AddStringToObject(fld, "precision", fields[i].precision);
cJSON_AddNumberToObject(fld, "Latitude", fields[i].lat);
cJSON_AddNumberToObject(fld, "Longitude", fields[i].lon);
cJSON_AddStringToObject(fld, "Address", fields[i].address);
cJSON_AddStringToObject(fld, "City", fields[i].city);
cJSON_AddStringToObject(fld, "State", fields[i].state);
cJSON_AddStringToObject(fld, "Zip", fields[i].zip);
cJSON_AddStringToObject(fld, "Country", fields[i].country);
cJSON_AddStringToObject(fld, "Code", fields[i].code);
}
/* cJSON_ReplaceItemInObject(cJSON_GetArrayItem(root,1),"City",cJSON_CreateIntArray(ids,4)); */
out = cJSON_Print(root);
cJSON_Delete(root);
printf("%s\n", out);
free(out);
}
开发者ID:yafengli,项目名称:project-samples,代码行数:96,代码来源:test.c
示例6: cJSON_CreateObject
DiagnosticVisualisation::DiagnosticVisualisation(UdpClient *udpClient,
unsigned int numberParticles, Particle2 *particleTable,
RoboclawProxy *roboClaw, HokuyoProxy *hokuyo) {
client = udpClient;
NumberParticles = numberParticles;
Particles = particleTable;
RoboClaw = roboClaw;
Hokuyo = hokuyo;
rootJSON = cJSON_CreateObject();
roboClawJSON = cJSON_CreateObject();
hokuyoJSON = cJSON_CreateObject();
particlesJSONTable = cJSON_CreateArray();
//cJSON_AddItemToObject(rootJSON, "RoboClaw", roboClawJSON);
cJSON_AddItemToObject(rootJSON, "Hokuyo", hokuyoJSON);
cJSON_AddItemToObject(rootJSON, "Particles", particlesJSONTable);
hokuyoJSONAngleTable = cJSON_CreateDoubleArray(Hokuyo->Angles,
Hokuyo->Length);
hokuyoJSONDistancesTable = cJSON_CreateIntArray(Hokuyo->Distances,
Hokuyo->Length);
cJSON_AddItemToObject(hokuyoJSON, "Angles", hokuyoJSONAngleTable);
cJSON_AddItemToObject(hokuyoJSON, "Distances", hokuyoJSONDistancesTable);
cJSON *itemParticle;
cJSON *tableCalculatedProbability;
cJSON *tableCalculatedDistances;
for (unsigned int i = 0; i < NumberParticles; i++) {
itemParticle = cJSON_CreateObject();
cJSON_AddNumberToObject(itemParticle, "X", Particles[i].X);
cJSON_AddNumberToObject(itemParticle, "Y", Particles[i].Y);
cJSON_AddNumberToObject(itemParticle, "P", Particles[i].P);
cJSON_AddNumberToObject(itemParticle, "Angle", Particles[i].Angle);
tableCalculatedProbability = cJSON_CreateDoubleArray(
Particles[i].CalculatedProbability, Particles[i].Length);
cJSON_AddItemToObject(itemParticle, "CalculatedProbability",
tableCalculatedProbability);
tableCalculatedDistances = cJSON_CreateDoubleArray(
Particles[i].CalculatedDistances, Particles[i].Length);
cJSON_AddItemToObject(itemParticle, "CalculatedDistances",
tableCalculatedDistances);
cJSON_AddItemToArray(particlesJSONTable, itemParticle);
}
/*particlesJSONTable = cJSON_CreateArray();
cJSON *itemParticle;
for(int i = 0; i < NumberParticles;i++)
{
itemParticle = cJSON_CreateObject();
cJSON_AddNumberToObject(itemParticle,"X",Particles[i].X);
cJSON_AddItemToArray(particlesJSONTable,itemParticle);
}
*/
// cJSON_AddItemToObject(particlesJSON,"Particle",particlesJSONTable);
//(Particles,
// NumberParticles);
//cJSON_AddNumberToObject(particlesJSON,"X",)
char * rendered = cJSON_Print(rootJSON);
printf(rendered);
fflush(NULL);
Hokuyo->Distances[0] = 777;
Hokuyo->Angles[0] = 555;
Particles[0].X = Particles[0].Angle = 888;
Particles[0].CalculatedDistances[0] = 0.7777;
Particles[0].CalculatedProbability[0] = 5000;
Send();
rendered = cJSON_Print(rootJSON);
printf(rendered);
fflush(NULL);
//particlesJSONTable = cJSON_CreateArray();
//cJSON_AddItemToArray()
//
// cJSON_AddItemToObject(particlesJSON, "X", )
//.........这里部分代码省略.........
开发者ID:project-capo,项目名称:amber-cpp-drivers,代码行数:101,代码来源:DiagnosticVisualisation.cpp
示例7: VBOX_readMsg
/*
* Class: com_easivend_evprotocol_VboxProtocol
* Method: EV_portRegister
* Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_com_easivend_evprotocol_VboxProtocol_VboxReadMsg
(JNIEnv *env, jclass cls, jint fd, jint timeout)
{
jstring msg;
char *text = NULL;
cJSON *root,*entry,*jsonarr,*jsonobj;
VBOX_MSG *vmsg;
unsigned char *buf,in,temp8,temp81,textbuf[32],i;
vmsg = VBOX_readMsg(fd,(uint32)timeout);
root=cJSON_CreateObject();
entry = cJSON_CreateObject();
cJSON_AddItemToObject(root, JSON_HEAD,entry);
cJSON_AddNumberToObject(entry,JSON_TYPE,VBOX_TYPE);
if(vmsg == NULL){
cJSON_AddNumberToObject(entry,"mt",VBOX_TIMEOUT);
}
else{
cJSON_AddNumberToObject(entry,"port",vmsg->port);
if(vmsg->res == 0){
cJSON_AddNumberToObject(entry,"mt",VBOX_TIMEOUT);
}
else if(vmsg->res == 1){
cJSON_AddNumberToObject(entry,"mt",vmsg->mt);
cJSON_AddNumberToObject(entry,"sn",vmsg->sn);
cJSON_AddNumberToObject(entry,"ver",vmsg->ver);
cJSON_AddNumberToObject(entry,"F7",vmsg->F7);
buf = (unsigned char *)vmsg->recvbuf;in = 5;
switch(vmsg->mt){
case VBOX_POLL:case VBOX_ACK_RPT:case VBOX_NAK_RPT:
in = 5;
break;
case VBOX_VMC_SETUP:
cJSON_AddNumberToObject(entry,"hd_num",buf[in++]);
cJSON_AddNumberToObject(entry,"pos_num",buf[in++]);
cJSON_AddNumberToObject(entry,"magic1",INTEG16(buf[in+0],buf[in+1]));in+=2;
cJSON_AddNumberToObject(entry,"scale_factor",buf[in++]);
cJSON_AddNumberToObject(entry,"decimal_places",buf[in++]);
cJSON_AddNumberToObject(entry,"feature",INTEG32(buf[in + 0],buf[in + 1],buf[in + 2],buf[in + 3])); in += 4;
break;
case VBOX_PAYIN_RPT:
cJSON_AddNumberToObject(entry,"dt",buf[in++]);
cJSON_AddNumberToObject(entry,"value",INTEG16(buf[in+0],buf[in+1]));in+=2;
cJSON_AddNumberToObject(entry,"total_value",INTEG16(buf[in+0],buf[in+1]));in+=2;
break;
case VBOX_PAYOUT_RPT:
cJSON_AddNumberToObject(entry,"device",buf[in++]);
cJSON_AddNumberToObject(entry,"value",INTEG16(buf[in+0],buf[in+1]));in+=2;
cJSON_AddNumberToObject(entry,"total_value",INTEG16(buf[in+0],buf[in+1]));in+=2;
cJSON_AddNumberToObject(entry,"type",buf[in++]);
break;
case VBOX_VENDOUT_RPT:
cJSON_AddNumberToObject(entry,"device",buf[in++]);
cJSON_AddNumberToObject(entry,"status",buf[in++]);
cJSON_AddNumberToObject(entry,"hd_id",buf[in++]);
cJSON_AddNumberToObject(entry,"type",buf[in++]);
cJSON_AddNumberToObject(entry,"cost",INTEG16(buf[in+0],buf[in+1]));in+=2;
cJSON_AddNumberToObject(entry,"total_value",INTEG16(buf[in+0],buf[in+1]));in+=2;
cJSON_AddNumberToObject(entry,"huodao",buf[in++]);
break;
case VBOX_REQUEST:
temp8 = buf[in++];
cJSON_AddNumberToObject(entry,"type",temp8);
break;
case VBOX_ADMIN_RPT:
temp8 = buf[in++];
cJSON_AddNumberToObject(entry,"type",temp8);
if(temp8 == 2){
cJSON_AddNumberToObject(entry,"data1",buf[in++]);
cJSON_AddNumberToObject(entry,"data2",buf[in++]);
}
break;
case VBOX_ACTION_RPT:
temp8 = buf[in++];
cJSON_AddNumberToObject(entry,"action",temp8);
if(temp8 == 1){
cJSON_AddNumberToObject(entry,"seconds",buf[in++]);
cJSON_AddNumberToObject(entry,"hd_id",buf[in++]);
cJSON_AddNumberToObject(entry,"type",buf[in++]);
cJSON_AddNumberToObject(entry,"cost",INTEG16(buf[in+0],buf[in+1]));in+=2;
cJSON_AddNumberToObject(entry,"total_value",INTEG16(buf[in+0],buf[in+1]));in+=2;
}
else if(temp8 == 2){
cJSON_AddNumberToObject(entry,"seconds",buf[in++]);
cJSON_AddNumberToObject(entry,"value",INTEG16(buf[in+0],buf[in+1]));in+=2;
cJSON_AddNumberToObject(entry,"total_value",INTEG16(buf[in+0],buf[in+1]));in+=2;
cJSON_AddNumberToObject(entry,"type",buf[in++]);
}
else if(temp8 == 5){
cJSON_AddNumberToObject(entry,"value",buf[in++]);
}
break;
case VBOX_BUTTON_RPT:
//.........这里部分代码省略.........
开发者ID:guozhenzhen260,项目名称:VmcJNI,代码行数:101,代码来源:com_easivend_evprotocol_VboxProtocol.c
示例8: on_cmd_test
/* a callback function that parse "cmd" & do actions, such as tun on/of LED */
int on_cmd_test(cJSON *request, cJSON **response)
{
if (!request)
{
return -1;
}
//find out the key word "cmd" from json
cJSON *child = cJSON_GetObjectItem(request, "cmd");
if (child)
{
//"cmd"都是字符串,"cmd"对应的值就是命令
char *cmd = child->valuestring;
/*the "set-led" command
* {
* "cmd": "set-led"
* "params": {
* "num": 1
* "status": "on"
* }
* }
*/
if (!strncmp(cmd, "set-led", strlen("set-led")))
{
int led_num = 0;
int led_status = 0;
cJSON *params = cJSON_GetObjectItem(request, "params");
cJSON *num = cJSON_GetObjectItem(params, "num");
cJSON *status = cJSON_GetObjectItem(params, "status");
if (num->type == cJSON_Number && status->type == cJSON_String)
{
led_num = num->valueint;
if (!strncmp(status->valuestring, "on", strlen("on")))
{
led_status = 1;
}
else
{
led_status = 0;
}
//TODO: set_led_status(led_num, led_status);
}
else
{
return -1;
}
/* to generate the info that will be returned
* format that as below
* {
* "cmd": "test",
* "result": {
* "info": "this is just a test"
* }
* }
* */
cJSON *result = NULL;
cJSON *res = cJSON_CreateObject();
cJSON_AddStringToObject(res, "cmd", "test");
cJSON_AddItemToObject(res, "result", result = cJSON_CreateObject());
cJSON_AddStringToObject(result, "info", "this is just a test");
*response = res;
return 0;
}
}
else
{
return -1;
}
}
开发者ID:vpathela,项目名称:OmnyIQ-SDK,代码行数:73,代码来源:client_thread.c
示例9: save_presets
void save_presets(int do_update)
{
char * outputdata;
int count, i;
cJSON *root, *userobj, *versionobj, *graphicsobj;
FILE* f;
root = cJSON_CreateObject();
cJSON_AddStringToObject(root, "Powder Sim Preferences", "Don't modify this file unless you know what you're doing. P.S: editing the admin/mod fields in your user info doesn't give you magical powers");
//User Info
if(svf_login){
cJSON_AddItemToObject(root, "user", userobj=cJSON_CreateObject());
cJSON_AddStringToObject(userobj, "name", svf_user);
cJSON_AddStringToObject(userobj, "id", svf_user_id);
cJSON_AddStringToObject(userobj, "session_id", svf_session_id);
if(svf_admin){
cJSON_AddTrueToObject(userobj, "admin");
cJSON_AddFalseToObject(userobj, "mod");
} else if(svf_mod){
cJSON_AddFalseToObject(userobj, "admin");
cJSON_AddTrueToObject(userobj, "mod");
} else {
cJSON_AddFalseToObject(userobj, "admin");
cJSON_AddFalseToObject(userobj, "mod");
}
}
//Version Info
cJSON_AddItemToObject(root, "version", versionobj=cJSON_CreateObject());
cJSON_AddNumberToObject(versionobj, "major", SAVE_VERSION);
cJSON_AddNumberToObject(versionobj, "minor", MINOR_VERSION);
cJSON_AddNumberToObject(versionobj, "build", BUILD_NUM);
if(do_update){
cJSON_AddTrueToObject(versionobj, "update");
} else {
cJSON_AddFalseToObject(versionobj, "update");
}
//Display settings
cJSON_AddItemToObject(root, "graphics", graphicsobj=cJSON_CreateObject());
cJSON_AddNumberToObject(graphicsobj, "colour", colour_mode);
count = 0; i = 0; while(display_modes[i++]){ count++; }
cJSON_AddItemToObject(graphicsobj, "display", cJSON_CreateIntArray(display_modes, count));
count = 0; i = 0; while(render_modes[i++]){ count++; }
cJSON_AddItemToObject(graphicsobj, "render", cJSON_CreateIntArray(render_modes, count));
//General settings
cJSON_AddStringToObject(root, "proxy", http_proxy_string);
cJSON_AddNumberToObject(root, "scale", sdl_scale);
cJSON_AddItemToObject(root,"favourites",cJSON_CreateIntArray(favourites, menuitems));
int q = 0;
while(quickmenu[q].icon!=NULL)
{
cJSON_AddNumberToObject(root, quickmenu[q].name, *quickmenu[q].variable);
q++;
}
outputdata = cJSON_Print(root);
cJSON_Delete(root);
f = fopen("powder.pref", "wb");
if(!f)
return;
fwrite(outputdata, 1, strlen(outputdata), f);
fclose(f);
free(outputdata);
//Old format, here for reference only
/*FILE *f=fopen("powder.def", "wb");
unsigned char sig[4] = {0x50, 0x44, 0x65, 0x68};
unsigned char tmp = sdl_scale;
if (!f)
return;
fwrite(sig, 1, 4, f);
save_string(f, svf_user);
//save_string(f, svf_pass);
save_string(f, svf_user_id);
save_string(f, svf_session_id);
fwrite(&tmp, 1, 1, f);
tmp = cmode;
fwrite(&tmp, 1, 1, f);
tmp = svf_admin;
fwrite(&tmp, 1, 1, f);
tmp = svf_mod;
fwrite(&tmp, 1, 1, f);
save_string(f, http_proxy_string);
tmp = SAVE_VERSION;
fwrite(&tmp, 1, 1, f);
tmp = MINOR_VERSION;
fwrite(&tmp, 1, 1, f);
tmp = BUILD_NUM;
fwrite(&tmp, 1, 1, f);
tmp = do_update;
fwrite(&tmp, 1, 1, f);
fclose(f);*/
}
开发者ID:tommig,项目名称:Powder-Sim,代码行数:98,代码来源:misc.c
示例10: _ciel_spawn_chkpt_task
int _ciel_spawn_chkpt_task( cielID *new_task_id, cielID *output_task_id,
cielID *input_id[], size_t input_count,
int is_continuation ){
int result;
char *path;
ASPRINTF_ORDIE( _ciel_spawn_chkpt_task(), &path, "/tmp/checkpoint.%s", new_task_id->id_str );
result = blcr_checkpoint( path );
if( result > 0 ){ /* checkpointing succeeded */
cJSON *jsonenc_args;
cJSON *jsonenc_dpnds;
cJSON *jsonenc_private;
swref *chkpt_ref;
swref *args_ref;
char *tmp;
#ifdef DEBUG
printf( "_ciel_spawn_chkpt_task(): spawning checkpoint task\n" );
#endif
chkpt_ref = sw_move_file_to_store( NULL, path, NULL );
cJSON *tmpJSON = cJSON_CreateObject();
cJSON_AddItemToObject( tmpJSON, "checkpoint", swref_serialize( chkpt_ref ) );
swref_free( chkpt_ref );
tmp = cJSON_PrintUnformatted( tmpJSON );
cJSON_Delete( tmpJSON );
args_ref = sw_save_string_to_store( NULL, NULL, tmp );
free( tmp );
jsonenc_args = cJSON_CreateObject();
cJSON_AddItemToObject( jsonenc_args, "simple_exec_args", swref_serialize(args_ref) );
swref_free( args_ref );
tmp = cJSON_PrintUnformatted( jsonenc_args );
cJSON_Delete( jsonenc_args );
args_ref = sw_save_string_to_store( NULL, NULL, tmp );
free( tmp );
jsonenc_private = swref_serialize( args_ref );
swref_free( args_ref );
jsonenc_dpnds = cJSON_CreateObject();
swref *ref;
size_t i;
for(i = 0; i < input_count; i++ ){
ref = swref_create( FUTURE, input_id[i]->id_str, NULL, 0, NULL );
cJSON_AddItemToArray( jsonenc_dpnds, swref_serialize( ref) );
swref_free( ref );
free(tmp);
}
/* Attempt to POST a new task to CIEL */
result = sw_spawntask( new_task_id->id_str,
is_continuation ? sw_get_current_output_id() : output_task_id->id_str,
sw_get_current_task_id(),
"cldthread",
jsonenc_dpnds,
jsonenc_private,
is_continuation );
cJSON_Delete( jsonenc_dpnds );
if( !result ){
fprintf( stderr, "<FATAL ERROR> unable to spawn task %s\n", new_task_id->id_str );
exit( EXIT_FAILURE );
}
/* If we managed to spawn a new continuation task, then terminate this process */
if( is_continuation ) exit( 20 );
cielID_free( new_task_id );
} else if (result < 0) { /* resumed checkpoint */
_ciel_update_env( new_task_id, input_id, input_count );
} else { /* error while attempting to checkpoint */
fprintf( stderr, "<FATAL ERROR> unable to checkpoint process\n" );
exit( EXIT_FAILURE );
}
free( path );
//.........这里部分代码省略.........
开发者ID:GunioRobot,项目名称:skywriting,代码行数:101,代码来源:ciel_checkpoint.c
示例11: cJSON_CreateObject
static char *print_json(switch_memory_pool_t *pool, http_data_t *http_data)
{
cJSON *top = cJSON_CreateObject(),
*headers = cJSON_CreateArray();
char *data = NULL;
char tmp[32], *f = NULL;
switch_curl_slist_t *header = http_data->headers;
if(!top || !headers) {
cJSON_Delete(headers);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to alloc memory for cJSON structures.\n");
goto curl_json_output_end;
}
switch_snprintf(tmp, sizeof(tmp), "%ld", http_data->http_response_code);
cJSON_AddItemToObject(top, "status_code", cJSON_CreateString(tmp));
if (http_data->http_response) {
cJSON_AddItemToObject(top, "body", cJSON_CreateString(http_data->http_response));
}
/* parse header data */
while (header) {
cJSON *obj = NULL;
/* remove trailing \r */
if ((data = strrchr(header->data, '\r'))) {
*data = '\0';
}
if (zstr(header->data)) {
header = header->next;
continue;
}
if ((data = strchr(header->data, ':'))) {
*data = '\0';
data++;
while (*data == ' ' && *data != '\0') {
data++;
}
obj = cJSON_CreateObject();
cJSON_AddItemToObject(obj, "key", cJSON_CreateString(header->data));
cJSON_AddItemToObject(obj, "value", cJSON_CreateString(data));
cJSON_AddItemToArray(headers, obj);
} else {
if (!strncmp("HTTP", header->data, 4)) {
char *argv[3] = { 0 };
int argc;
if ((argc = switch_separate_string(header->data, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
if (argc > 2) {
cJSON_AddItemToObject(top, "version", cJSON_CreateString(argv[0]));
cJSON_AddItemToObject(top, "phrase", cJSON_CreateString(argv[2]));
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unparsable header: argc: %d\n", argc);
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Starts with HTTP but not parsable: %s\n", header->data);
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unparsable header: %s\n", header->data);
}
}
header = header->next;
}
cJSON_AddItemToObject(top, "headers", headers);
f = cJSON_PrintUnformatted(top);
data = switch_core_strdup(pool, f);
switch_safe_free(f);
curl_json_output_end:
cJSON_Delete(top); /* should free up all children */
return data;
}
开发者ID:odmanV2,项目名称:freecenter,代码行数:73,代码来源:mod_curl.c
示例12: Archiveinfo_to_jsonstr
/* Convert Archiveinfo to json */
char* Archiveinfo_to_jsonstr(const Eventinfo* lf)
{
cJSON* root;
char* out;
int i;
root = cJSON_CreateObject();
if(lf->program_name)
cJSON_AddStringToObject(root, "program_name", lf->program_name);
if(lf->log)
cJSON_AddStringToObject(root, "log", lf->log);
if(lf->srcip)
cJSON_AddStringToObject(root, "srcip", lf->srcip);
if(lf->dstip)
cJSON_AddStringToObject(root, "dstip", lf->dstip);
if(lf->srcport)
cJSON_AddStringToObject(root, "srcport", lf->srcport);
if(lf->dstport)
cJSON_AddStringToObject(root, "dstport", lf->dstport);
if(lf->protocol)
cJSON_AddStringToObject(root, "protocol", lf->protocol);
if(lf->action)
cJSON_AddStringToObject(root, "action", lf->action);
if(lf->srcuser)
cJSON_AddStringToObject(root, "srcuser", lf->srcuser);
if(lf->dstuser)
cJSON_AddStringToObject(root, "dstuser", lf->dstuser);
if(lf->id)
cJSON_AddStringToObject(root, "id", lf->id);
if(lf->status)
cJSON_AddStringToObject(root, "status", lf->status);
if(lf->command)
cJSON_AddStringToObject(root, "command", lf->command);
if(lf->url)
cJSON_AddStringToObject(root, "url", lf->url);
if(lf->data)
cJSON_AddStringToObject(root, "data", lf->data);
if(lf->systemname)
cJSON_AddStringToObject(root, "systemname", lf->systemname);
if(lf->filename) {
cJSON *file_diff = cJSON_CreateObject();
cJSON_AddItemToObject(root, "SyscheckFile", file_diff);
cJSON_AddStringToObject(file_diff, "path", lf->filename);
if (lf->size_before) {
cJSON_AddStringToObject(file_diff, "size_before", lf->size_before);
}
if (lf->size_after) {
cJSON_AddStringToObject(file_diff, "size_after", lf->size_after);
}
if (lf->perm_before) {
char perm[7];
snprintf(perm, 7, "%6o", lf->perm_before);
cJSON_AddStringToObject(file_diff, "perm_before", perm);
}
if (lf->perm_after) {
char perm[7];
snprintf(perm, 7, "%6o", lf->perm_after);
cJSON_AddStringToObject(file_diff, "perm_after", perm);
}
if (lf->owner_before) {
cJSON_AddStringToObject(file_diff, "owner_before", lf->owner_before);
}
if (lf->owner_after) {
cJSON_AddStringToObject(file_diff, "owner_after", lf->owner_after);
}
if (lf->gowner_before) {
cJSON_AddStringToObject(file_diff, "gowner_before", lf->gowner_before);
}
if (lf->gowner_after) {
cJSON_AddStringToObject(file_diff, "gowner_after", lf->gowner_after);
}
if (lf->md5_before) {
cJSON_AddStringToObject(file_diff, "md5_before", lf->md5_before);
}
if (lf->md5_after) {
cJSON_AddStringToObject(file_diff, "md5_after", lf->md5_after);
}
if (lf->sha1_before) {
cJSON_AddStringToObject(file_diff, "sha1_before", lf->sha1_before);
}
if (lf->sha1_after) {
//.........这里部分代码省略.........
开发者ID:Cryptophobia,项目名称:ossec-wazuh,代码行数:101,代码来源:to_json.c
示例13: SAManager_WrapEventNotifyPacket
susiaccess_packet_body_t * SAManager_WrapEventNotifyPacket(Handler_info const * plugin, HANDLER_NOTIFY_SEVERITY severity, void const * const requestData, unsigned int const requestLen, bool bCust)
{
PJSON ReqInfoJSON = NULL;
char* pReqInfoPayload = NULL;
char* data = NULL;
susiaccess_packet_body_t* packet = NULL;
cJSON* node = NULL;
cJSON* root = NULL;
cJSON* pfinfoNode = NULL;
char* buff = NULL;
int length = 0;
if(plugin == NULL)
return packet;
if(plugin->agentInfo == NULL)
return packet;
if(requestData)
{
data = ConvertMessageToUTF8(requestData);
}
root = cJSON_CreateObject();
pfinfoNode = cJSON_CreateObject();
//node = cJSON_Parse((const char *)requestData);
node = cJSON_Parse((const char *)data);
free(data);
if(pfinfoNode)
{
cJSON* chNode = node->child;
while(chNode)
{
cJSON_AddItemToObject(pfinfoNode, chNode->string, cJSON_Duplicate(chNode, true));
chNode = chNode->next;
}
cJSON_AddNumberToObject(pfinfoNode, "severity", severity);
cJSON_AddStringToObject(pfinfoNode, "handler", plugin->Name);
}
cJSON_Delete(node);
cJSON_AddItemToObject(root, "eventnotify", pfinfoNode);
buff = cJSON_PrintUnformatted(root);
cJSON_Delete(root);
length = strlen(buff);
packet = malloc(sizeof(susiaccess_packet_body_t));
memset(packet, 0, sizeof(susiaccess_packet_body_t));
packet->content = (char*)malloc(length+1);
memset(packet->content, 0, length+1);
memcpy(packet->content, buff, length);
free(buff);
strcpy(packet->devId, plugin->agentInfo->devId);
strcpy(packet->handlerName, "general"); //Special case for event notify.
packet->requestID = cagent_action_general;
packet->cmd = general_event_notify_rep;
//SAManagerLog(g_samanagerlogger, Normal, "Parser_CreateRequestInfo");
return packet;
}
开发者ID:advlinda,项目名称:cagentoniotcore,代码行数:63,代码来源:SAManager.c
示例14: conference_event_mod_channel_handler
//.........这里部分代码省略.........
!strcasecmp(action, "vid-floor") ||
!strcasecmp(action, "vid-layer") ||
!strcasecmp(action, "vid-canvas") ||
!strcasecmp(action, "vid-watching-canvas") ||
!strcasecmp(action, "vid-banner")) {
exec = switch_mprintf("%s %s %s %s", conference_name, action, cid, argv[0]);
} else if (!strcasecmp(action, "play") || !strcasecmp(action, "stop")) {
exec = switch_mprintf("%s %s %s", conference_name, action, argv[0]);
} else if (!strcasecmp(action, "recording") || !strcasecmp(action, "vid-layout") || !strcasecmp(action, "vid-write-png")) {
if (!argv[1]) {
argv[1] = "all";
}
exec = switch_mprintf("%s %s %s %s", conference_name, action, argv[0], argv[1]);
} else if (!strcasecmp(action, "transfer")) {
conference_member_t *member;
conference_obj_t *conference;
if (cid[0] == '\0') {
stream.write_function(&stream, "-ERR Call transfer requires id");
goto end;
}
exec = switch_mprintf("%s %s %s", argv[0], switch_str_nil(argv[1]), switch_str_nil(argv[2]));
stream.write_function(&stream, "+OK Call transferred to %s", argv[0]);
if ((conference = conference_find(conference_name, NULL))) {
if ((member = conference_member_get(conference, atoi(cid)))) {
switch_ivr_session_transfer(member->session, argv[0], argv[1], argv[2]);
switch_thread_rwlock_unlock(member->rwlock);
}
switch_thread_rwlock_unlock(conference->rwlock);
}
goto end;
} else if (!strcasecmp(action, "list-videoLayouts")) {
switch_hash_index_t *hi;
void *val;
const void *vvar;
cJSON *array = cJSON_CreateArray();
conference_obj_t *conference = NULL;
if ((conference = conference_find(conference_name, NULL))) {
switch_mutex_lock(conference_globals.setup_mutex);
if (conference->layout_hash) {
for (hi = switch_core_hash_first(conference->layout_hash); hi; hi = switch_core_hash_next(&hi)) {
switch_core_hash_this(hi, &vvar, NULL, &val);
cJSON_AddItemToArray(array, cJSON_CreateString((char *)vvar));
}
}
if (conference->layout_group_hash) {
for (hi = switch_core_hash_first(conference->layout_group_hash); hi; hi = switch_core_hash_next(&hi)) {
char *name;
switch_core_hash_this(hi, &vvar, NULL, &val);
name = switch_mprintf("group:%s", (char *)vvar);
cJSON_AddItemToArray(array, cJSON_CreateString(name));
free(name);
}
}
switch_mutex_unlock(conference_globals.setup_mutex);
switch_thread_rwlock_unlock(conference->rwlock);
}
addobj = array;
}
if (exec) {
conference_api_main_real(exec, NULL, &stream);
}
end:
msg = cJSON_CreateObject();
jdata = json_add_child_obj(msg, "data", NULL);
cJSON_AddItemToObject(msg, "eventChannel", cJSON_CreateString(event_channel));
cJSON_AddItemToObject(jdata, "action", cJSON_CreateString("response"));
if (addobj) {
cJSON_AddItemToObject(jdata, "conf-command", cJSON_CreateString(action));
cJSON_AddItemToObject(jdata, "response", cJSON_CreateString("OK"));
cJSON_AddItemToObject(jdata, "responseData", addobj);
} else if (exec) {
cJSON_AddItemToObject(jdata, "conf-command", cJSON_CreateString(exec));
cJSON_AddItemToObject(jdata, "response", cJSON_CreateString((char *)stream.data));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT,"RES [%s][%s]\n", exec, (char *)stream.data);
} else {
cJSON_AddItemToObject(jdata, "error", cJSON_CreateString("Invalid Command"));
}
switch_event_channel_broadcast(event_channel, &msg, __FILE__, conference_globals.event_channel_id);
switch_safe_free(stream.data);
switch_safe_free(exec);
switch_safe_free(conference_name);
}
开发者ID:prashantchoudhary,项目名称:FreeswitchModified,代码行数:101,代码来源:conference_event.c
示例15: apply_patch
//.........这里部分代码省略.........
value = get_item_from_pointer(object, from->valuestring, case_sensitive);
}
if (value == NULL)
{
/* missing "from" for copy/move. */
status = 5;
goto cleanup;
}
if (opcode == COPY)
{
value = cJSON_Duplicate(value, 1);
}
if (value == NULL)
{
/* out of memory for copy/move. */
status = 6;
goto cleanup;
}
}
else /* Add/Replace uses "value". */
{
value = get_object_item(patch, "value", case_sensitive);
if (value == NULL)
{
/* missing "value" for add/replace. */
status = 7;
goto cleanup;
}
value = cJSON_Duplicate(value, 1);
if (value == NULL)
{
/* out of memory for add/replace. */
status = 8;
goto cleanup;
}
}
/* Now, just add "value" to "path". */
/* split pointer in parent and child */
parent_pointer = cJSONUtils_strdup((unsigned char*)path->valuestring);
child_pointer = (unsigned char*)strrchr((char*)parent_pointer, '/');
if (child_pointer != NULL)
{
child_pointer[0] = '\0';
child_pointer++;
}
parent = get_item_from_pointer(object, (char*)parent_pointer, case_sensitive);
decode_pointer_inplace(child_pointer);
/* add, remove, replace, move, copy, test. */
if ((parent == NULL) || (child_pointer == NULL))
{
/* Couldn't find object to add to. */
status = 9;
goto cleanup;
}
else if (cJSON_IsArray(parent))
{
if (strcmp((char*)child_pointer, "-") == 0)
{
cJSON_AddItemToArray(parent, value);
value = NULL;
}
else
{
size_t index = 0;
if (!decode_array_index_from_pointer(child_pointer, &index))
{
status = 11;
goto cleanup;
}
if (!insert_item_in_array(parent, index, value))
{
status = 10;
goto cleanup;
}
value = NULL;
}
}
else if (cJSON_IsObject(parent
|
请发表评论