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); } } }
void jaddstr(cJSON *json,char *field,char *str) { cJSON_AddItemToObject(json,field,cJSON_CreateString(str)); }
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; }
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; }
/* 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); }
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", ) //cJSON_AddNumberToObject() //cJSON_AddItemToObject(rootJSON, /*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); { "name": "Jack (\"Bee\") Nimble", "format": { "type": "rect", "width": 1920, "height": 1080, "interlace": false, "frame rate": 24 } } */ }
/* * 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: temp8 = buf[in++]; cJSON_AddNumberToObject(entry,"type",temp8); if(temp8 == 0 || temp8 == 4){ cJSON_AddNumberToObject(entry,"value",buf[in++]); } else if(temp8 == 1 || temp8 == 2){ cJSON_AddNumberToObject(entry,"device",buf[in++]); cJSON_AddNumberToObject(entry,"value",buf[in++]); } break; case VBOX_STATUS_RPT: temp8 = buf[in++]; cJSON_AddNumberToObject(entry,"check_st",(temp8 >> 6) & 0x03); cJSON_AddNumberToObject(entry,"bv_st",(temp8 >> 4) & 0x03); cJSON_AddNumberToObject(entry,"cc_st",(temp8 >> 2) & 0x03); cJSON_AddNumberToObject(entry,"vmc_st",(temp8 >> 0) & 0x03); cJSON_AddNumberToObject(entry,"post_st",buf[in++]); cJSON_AddNumberToObject(entry,"change",INTEG16(buf[in+0],buf[in+1]));in+=2; cJSON_AddNumberToObject(entry,"tem1",buf[in++]); cJSON_AddNumberToObject(entry,"tem2",buf[in++]); cJSON_AddNumberToObject(entry,"tem3",buf[in++]); cJSON_AddNumberToObject(entry,"tem4",buf[in++]); cJSON_AddNumberToObject(entry,"tem_st",buf[in++]); cJSON_AddNumberToObject(entry,"auto_payout",buf[in++]); break; case VBOX_HUODAO_RPT: cJSON_AddNumberToObject(entry,"device",buf[in++]); temp8 = 5 + 1 + 2; temp8 = vmsg->recvlen > temp8 ?vmsg->recvlen - temp8: 0; cJSON_AddItemToObject(entry,"huodao",jsonarr = cJSON_CreateArray()); for(i = 0;i < temp8;i++){ cJSON_AddItemToArray(jsonarr,jsonobj = cJSON_CreateObject()); cJSON_AddNumberToObject(jsonobj,"no",i + 1); temp81 = buf[in++]; cJSON_AddNumberToObject(jsonobj,"state",(temp81 & (0x01 << 6)) ? 1 : 0); cJSON_AddNumberToObject(jsonobj,"remain",(temp81 & 0x3F)); } break; case VBOX_COST_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_INFO_RPT: temp8 = buf[in++]; cJSON_AddNumberToObject(entry,"type",temp8); if(temp8 == 3){ cJSON_AddNumberToObject(entry,"total_value",INTEG16(buf[in+0],buf[in+1]));in+=2; } else if(temp8 == 4){ temp8 = 0; } else if(temp8 == 5){ cJSON_AddNumberToObject(entry,"year",INTEG16(buf[in+0],buf[in+1]));in+=2; cJSON_AddNumberToObject(entry,"month",buf[in++]); cJSON_AddNumberToObject(entry,"day",buf[in++]); cJSON_AddNumberToObject(entry,"hour",buf[in++]); cJSON_AddNumberToObject(entry,"min",buf[in++]); cJSON_AddNumberToObject(entry,"sec",buf[in++]); cJSON_AddNumberToObject(entry,"xq",buf[in++]); } else if(temp8 == 6){ temp8 = 0; } else if(temp8 == 10){ temp8 = 0; cJSON_AddNumberToObject(entry,"device",buf[in++]); temp8 = 5 + 1 + 1 + 2; temp8 = vmsg->recvlen > temp8 ?vmsg->recvlen - temp8: 0; cJSON_AddItemToObject(entry,"sp_id",jsonarr = cJSON_CreateArray()); for(i = 0;i < temp8;i++){ cJSON_AddItemToArray(jsonarr,jsonobj = cJSON_CreateObject()); //cJSON_AddNumberToObject(jsonobj,"no",i + 1); //cJSON_AddNumberToObject(jsonobj,"sp_id",buf[in++]); cJSON_AddNumberToObject(jsonobj,"id",buf[in++]); } } else if(temp8 == 12){ temp8 = 0; cJSON_AddNumberToObject(entry,"device",buf[in++]); temp8 = 5 + 1 + 1 + 2; temp8 = vmsg->recvlen > temp8 ?vmsg->recvlen - temp8: 0; cJSON_AddItemToObject(entry,"sp_price",jsonarr = cJSON_CreateArray()); for(i = 0;i < (temp8 / 2);i++){ cJSON_AddItemToArray(jsonarr,jsonobj = cJSON_CreateObject()); //cJSON_AddNumberToObject(jsonobj,"no",i + 1); //cJSON_AddNumberToObject(jsonobj,"sp_price",INTEG16(buf[in + 0],buf[in + 1]));in += 2; cJSON_AddNumberToObject(jsonobj,"id",INTEG16(buf[in + 0],buf[in + 1]));in += 2; } } else{ temp8 = 0; } break; default:break; } } else{
/* 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; } }
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);*/ }
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 ); return result; }
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; }
/* 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) { cJSON_AddStringToObject(file_diff, "sha1_after", lf->sha1_after); } if (lf->uname_before) { cJSON_AddStringToObject(file_diff, "uname_before", lf->uname_before); } if (lf->uname_after) { cJSON_AddStringToObject(file_diff, "uname_after", lf->uname_after); } if (lf->gname_before) { cJSON_AddStringToObject(file_diff, "gname_before", lf->gname_before); } if (lf->gname_after) { cJSON_AddStringToObject(file_diff, "gname_after", lf->gname_after); } if (lf->mtime_before) { char mtime[20]; strftime(mtime, 20, "%FT%T", localtime(&lf->mtime_before)); cJSON_AddStringToObject(file_diff, "mtime_before", mtime); } if (lf->mtime_after) { char mtime[20]; strftime(mtime, 20, "%FT%T", localtime(&lf->mtime_after)); cJSON_AddStringToObject(file_diff, "mtime_after", mtime); } if (lf->inode_before) { cJSON_AddNumberToObject(file_diff, "inode_before", lf->inode_before); } if (lf->inode_after) { cJSON_AddNumberToObject(file_diff, "inode_after", lf->inode_after); } if (lf->diff) { cJSON_AddStringToObject(file_diff, "diff", lf->diff); } switch (lf->event_type) { case FIM_ADDED: cJSON_AddStringToObject(file_diff, "event", "added"); break; case FIM_MODIFIED: cJSON_AddStringToObject(file_diff, "event", "modified"); break; case FIM_READDED: cJSON_AddStringToObject(file_diff, "event", "readded"); break; case FIM_DELETED: cJSON_AddStringToObject(file_diff, "event", "deleted"); break; default: ; } } // RuleInfo if(lf->generated_rule) { cJSON* rule; cJSON_AddItemToObject(root, "rule", rule = cJSON_CreateObject()); if(lf->generated_rule->level) cJSON_AddNumberToObject(rule, "level", lf->generated_rule->level); if(lf->comment) cJSON_AddStringToObject(rule, "comment", lf->comment); if(lf->generated_rule->sigid) cJSON_AddNumberToObject(rule, "sidid", lf->generated_rule->sigid); if(lf->generated_rule->cve) cJSON_AddStringToObject(rule, "cve", lf->generated_rule->cve); if(lf->generated_rule->info) cJSON_AddStringToObject(rule, "info", lf->generated_rule->info); if(lf->generated_rule->frequency) cJSON_AddNumberToObject(rule, "frequency", lf->generated_rule->frequency); if(lf->generated_rule->firedtimes) cJSON_AddNumberToObject(rule, "firedtimes", lf->generated_rule->firedtimes); if(lf->generated_rule->group) { W_JSON_ParseGroups(root, lf, 1); } if(lf->full_log && W_isRootcheck(root, 1)) { W_JSON_ParseRootcheck(root, lf, 1); } } // DecoderInfo if(lf->decoder_info) { cJSON* decoder; // Dynamic fields, except for syscheck events if (lf->decoder_info->fields && !lf->filename) { for (i = 0; i < Config.decoder_order_size; i++) { if (lf->decoder_info->fields[i] && lf->fields[i]) { cJSON_AddStringToObject(root, lf->decoder_info->fields[i], lf->fields[i]); } } } cJSON_AddItemToObject(root, "decoder", decoder = cJSON_CreateObject()); if(lf->decoder_info->fts) cJSON_AddNumberToObject(decoder, "fts", lf->decoder_info->fts); if(lf->decoder_info->accumulate) cJSON_AddNumberToObject(decoder, "accumulate", lf->decoder_info->accumulate); if(lf->decoder_info->parent) cJSON_AddStringToObject(decoder, "parent", lf->decoder_info->parent); if(lf->decoder_info->name) cJSON_AddStringToObject(decoder, "name", lf->decoder_info->name); if(lf->decoder_info->ftscomment) cJSON_AddStringToObject(decoder, "ftscomment", lf->decoder_info->ftscomment); } if(lf->full_log) cJSON_AddStringToObject(root, "full_log", lf->full_log); if(lf->year && lf->mon[0] && lf->day && lf->hour[0]) W_JSON_ParseTimestamp(root, lf); if(lf->hostname) { W_JSON_ParseHostname(root, lf->hostname); W_JSON_ParseAgentIP(root, lf); } if (lf->agent_id) { cJSON_AddStringToObject(root, "AgentID", lf->agent_id); } if(lf->location) W_JSON_ParseLocation(root, lf, 0); out = cJSON_PrintUnformatted(root); cJSON_Delete(root); return out; }
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; }
void conference_event_mod_channel_handler(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id) { cJSON *data, *addobj = NULL; const char *action = NULL; char *value = NULL; cJSON *jid = 0; char *conference_name = strdup(event_channel + 15); char cid[32] = ""; char *p; switch_stream_handle_t stream = { 0 }; char *exec = NULL; cJSON *msg, *jdata, *jvalue; char *argv[10] = {0}; int argc = 0; if (conference_name && (p = strchr(conference_name, '@'))) { *p = '\0'; } if ((data = cJSON_GetObjectItem(json, "data"))) { action = cJSON_GetObjectCstr(data, "command"); if ((jid = cJSON_GetObjectItem(data, "id"))) { if (jid->valueint) { switch_snprintf(cid, sizeof(cid), "%d", jid->valueint); } else if (!zstr(jid->valuestring)) { switch_snprintf(cid, sizeof(cid), "%s", jid->valuestring); } } if ((jvalue = cJSON_GetObjectItem(data, "value"))) { if (jvalue->type == cJSON_Array) { int i; argc = cJSON_GetArraySize(jvalue); if (argc > 10) argc = 10; for (i = 0; i < argc; i++) { cJSON *str = cJSON_GetArrayItem(jvalue, i); if (str->type == cJSON_String) { argv[i] = str->valuestring; } } } else if (jvalue->type == cJSON_String) { value = jvalue->valuestring; argv[argc++] = value; } } } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "conf %s CMD %s [%s] %s\n", conference_name, key, action, cid); if (zstr(action)) { goto end; } SWITCH_STANDARD_STREAM(stream); if (!strcasecmp(action, "kick")) { exec = switch_mprintf("%s %s %s", conference_name, action, cid); } else if (!strcasecmp(action, "mute") || !strcasecmp(action, "unmute") || !strcasecmp(action, "tmute") || !strcasecmp(action, "vmute") || !strcasecmp(action, "unvmute") || !strcasecmp(action, "tvmute")) { if (argv[0]) { exec = switch_mprintf("%s %s %s %s", conference_name, action, cid, argv[0]); } else { exec = switch_mprintf("%s %s %s", conference_name, action, cid); } } else if (!strcasecmp(action, "volume_in") || !strcasecmp(action, "volume_out") || !strcasecmp(action, "vid-res-id") || !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); }
static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_sensitive) { cJSON *path = NULL; cJSON *value = NULL; cJSON *parent = NULL; enum patch_operation opcode = INVALID; unsigned char *parent_pointer = NULL; unsigned char *child_pointer = NULL; int status = 0; path = get_object_item(patch, "path", case_sensitive); if (!cJSON_IsString(path)) { /* malformed patch. */ status = 2; goto cleanup; } opcode = decode_patch_operation(patch, case_sensitive); if (opcode == INVALID) { status = 3; goto cleanup; } else if (opcode == TEST) { /* compare value: {...} with the given path */ status = !compare_json(get_item_from_pointer(object, path->valuestring, case_sensitive), get_object_item(patch, "value", case_sensitive), case_sensitive); goto cleanup; } /* special case for replacing the root */ if (path->valuestring[0] == '\0') { if (opcode == REMOVE) { static const cJSON invalid = { NULL, NULL, NULL, cJSON_Invalid, NULL, 0, 0, NULL}; overwrite_item(object, invalid); status = 0; goto cleanup; } if ((opcode == REPLACE) || (opcode == ADD)) { 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; } overwrite_item(object, *value); /* delete the duplicated value */ cJSON_free(value); value = NULL; /* the string "value" isn't needed */ if (object->string != NULL) { cJSON_free(object->string); object->string = NULL; } status = 0; goto cleanup; } } if ((opcode == REMOVE) || (opcode == REPLACE)) { /* Get rid of old. */ cJSON *old_item = detach_path(object, (unsigned char*)path->valuestring, case_sensitive); if (old_item == NULL) { status = 13; goto cleanup; } cJSON_Delete(old_item); if (opcode == REMOVE) { /* For Remove, this job is done. */ status = 0; goto cleanup; } } /* Copy/Move uses "from". */ if ((opcode == MOVE) || (opcode == COPY)) { cJSON *from = get_object_item(patch, "from", case_sensitive); if (from == NULL) { /* missing "from" for copy/move. */ status = 4; goto cleanup; } if (opcode == MOVE) { value = detach_path(object, (unsigned char*)from->valuestring, case_sensitive); } if (opcode == COPY) { 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)) { cJSON_DeleteItemFromObject(parent, (char*)child_pointer); cJSON_AddItemToObject(parent, (char*)child_pointer, value); value = NULL; } cleanup: if (value != NULL) { cJSON_Delete(value); } if (parent_pointer != NULL) { cJSON_free(parent_pointer); } return status; }
void web_pipeline_status(struct evhttp_request *req, void *arg) { std::map<std::string, moProperty*>::iterator it; unsigned int i, j; int k; char buffer[64]; cJSON *root, *data, *modules, *mod, *properties, *io, *observers, *array, *property; moDataStream *ds; root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "success", 1); cJSON_AddStringToObject(root, "message", "ok"); cJSON_AddItemToObject(root, "status", data=cJSON_CreateObject()); cJSON_AddStringToObject(data, "version", MO_VERSION); cJSON_AddNumberToObject(data, "size", pipeline->size()); cJSON_AddNumberToObject(data, "running", pipeline->isStarted() ? 1 : 0); cJSON_AddItemToObject(data, "modules", modules=cJSON_CreateObject()); for ( i = 0; i < pipeline->size(); i++ ) { moModule *module = pipeline->getModule(i); assert( module != NULL ); cJSON_AddItemToObject(modules, module->property("id").asString().c_str(), mod=cJSON_CreateObject()); cJSON_AddStringToObject(mod, "name", module->getName().c_str()); cJSON_AddStringToObject(mod, "description", module->getDescription().c_str()); cJSON_AddStringToObject(mod, "author", module->getAuthor().c_str()); cJSON_AddNumberToObject(mod, "running", module->isStarted() ? 1 : 0); cJSON_AddItemToObject(mod, "properties", properties=cJSON_CreateObject()); for ( it = module->getProperties().begin(); it != module->getProperties().end(); it++ ) { cJSON_AddStringToObject(properties, it->first.c_str(), it->second->asString().c_str()); } cJSON_AddItemToObject(mod, "propertiesInfos", properties=cJSON_CreateObject()); for ( it = module->getProperties().begin(); it != module->getProperties().end(); it++ ) { moProperty *p = it->second; cJSON_AddItemToObject(properties, it->first.c_str(), property=cJSON_CreateObject()); cJSON_AddStringToObject(property, "type", moProperty::getPropertyTypeName(p->getType()).c_str()); cJSON_AddNumberToObject(property, "readonly", p->isReadOnly() ? 1 : 0); if ( p->haveMax() ) cJSON_AddNumberToObject(property, "max", p->getMax()); if ( p->haveMin() ) cJSON_AddNumberToObject(property, "min", p->getMin()); if ( p->haveChoices() ) cJSON_AddStringToObject(property, "choices", p->getChoices().c_str()); } if ( module->getInputCount() ) { cJSON_AddItemToObject(mod, "inputs", array=cJSON_CreateArray()); for ( k = 0; k < module->getInputCount(); k++ ) { ds = module->getInput(k); cJSON_AddItemToArray(array, io=cJSON_CreateObject()); cJSON_AddNumberToObject(io, "index", k); cJSON_AddStringToObject(io, "name", module->getInputInfos(k)->getName().c_str()); cJSON_AddStringToObject(io, "type", module->getInputInfos(k)->getType().c_str()); cJSON_AddNumberToObject(io, "used", ds == NULL ? 0 : 1); } } if ( module->getOutputCount() ) { cJSON_AddItemToObject(mod, "outputs", array=cJSON_CreateArray()); for ( k = 0; k < module->getOutputCount(); k++ ) { ds = module->getOutput(k); cJSON_AddItemToArray(array, io=cJSON_CreateObject()); cJSON_AddNumberToObject(io, "index", k); cJSON_AddStringToObject(io, "name", module->getOutputInfos(k)->getName().c_str()); cJSON_AddStringToObject(io, "type", module->getOutputInfos(k)->getType().c_str()); cJSON_AddNumberToObject(io, "used", ds == NULL ? 0 : 1); cJSON_AddItemToObject(io, "observers", observers=cJSON_CreateObject()); if ( ds != NULL ) { for ( j = 0; j < ds->getObserverCount(); j++ ) { snprintf(buffer, sizeof(buffer), "%d", j); cJSON_AddStringToObject(observers, buffer, ds->getObserver(j)->property("id").asString().c_str()); } } } } } web_json(req, root); }
void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item, ngx_pool_t *pool) {cJSON_AddItemToObject(object,string,create_reference(item, pool), pool);}
void web_factory_desribe(struct evhttp_request *req, void *arg) { std::map<std::string, moProperty*>::iterator it; cJSON *root, *mod, *properties, *io, *array; moDataStream *ds; moModule *module; struct evkeyvalq headers; const char *uri; int i; uri = evhttp_request_uri(req); if ( uri == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "unable to retreive uri"); } evhttp_parse_query(uri, &headers); if ( evhttp_find_header(&headers, "name") == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "missing name"); } module = moFactory::getInstance()->create(evhttp_find_header(&headers, "name")); if ( module == NULL ) { evhttp_clear_headers(&headers); return web_error(req, "invalid name"); } root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "success", 1); cJSON_AddStringToObject(root, "message", "ok"); cJSON_AddItemToObject(root, "describe", mod=cJSON_CreateObject()); cJSON_AddStringToObject(mod, "name", module->getName().c_str()); cJSON_AddStringToObject(mod, "description", module->getDescription().c_str()); cJSON_AddStringToObject(mod, "author", module->getAuthor().c_str()); cJSON_AddNumberToObject(mod, "running", module->isStarted() ? 1 : 0); cJSON_AddItemToObject(mod, "properties", properties=cJSON_CreateObject()); for ( it = module->getProperties().begin(); it != module->getProperties().end(); it++ ) { cJSON_AddStringToObject(properties, it->first.c_str(), it->second->asString().c_str()); } if ( module->getInputCount() ) { cJSON_AddItemToObject(mod, "inputs", array=cJSON_CreateArray()); for ( i = 0; i < module->getInputCount(); i++ ) { ds = module->getInput(i); cJSON_AddItemToArray(array, io=cJSON_CreateObject()); cJSON_AddNumberToObject(io, "index", i); cJSON_AddStringToObject(io, "name", module->getInputInfos(i)->getName().c_str()); cJSON_AddStringToObject(io, "type", module->getInputInfos(i)->getType().c_str()); } } if ( module->getOutputCount() ) { cJSON_AddItemToObject(mod, "outputs", array=cJSON_CreateArray()); for ( i = 0; i < module->getOutputCount(); i++ ) { ds = module->getOutput(i); cJSON_AddItemToArray(array, io=cJSON_CreateObject()); cJSON_AddNumberToObject(io, "index", i); cJSON_AddStringToObject(io, "name", module->getOutputInfos(i)->getName().c_str()); cJSON_AddStringToObject(io, "type", module->getOutputInfos(i)->getType().c_str()); } } delete module; evhttp_clear_headers(&headers); web_json(req, root); }
int ICACHE_FLASH_ATTR http_wifi_api_scan(http_connection *c) { NODE_DBG("http_wifi_api_scan"); //wait for whole body if(c->state <HTTPD_STATE_BODY_END) return HTTPD_CGI_MORE; api_cgi_scan_status * status = c->cgi.data; if(status==NULL){ //first call, create status //create status status = (api_cgi_scan_status*)os_malloc(sizeof(api_cgi_scan_status)); status->state=1; status->ap_index=0; c->cgi.data=status; if(!wifi_status.scanning){ //if not already scanning, request scan NODE_DBG("Starting scan"); wifi_station_scan(NULL,http_wifi_api_scan_callback); wifi_status.scanning=1; } //write headers http_SET_HEADER(c,HTTP_CONTENT_TYPE,JSON_CONTENT_TYPE); http_response_OK(c); //set state to 1 - waiting status->state=1; return HTTPD_CGI_MORE; } else{ if(wifi_status.scanning){ NODE_DBG("Waiting scan done"); //set timer to check again os_timer_disarm(&status->timer); os_timer_setfn(&status->timer, http_execute_cgi, c); os_timer_arm(&status->timer, 500, 0); return HTTPD_CGI_MORE; } else if(status->state==1){ //clear timer os_timer_disarm(&status->timer); NODE_DBG("Scan complete %d",status->ap_index); //create json cJSON *root = cJSON_CreateObject(); cJSON_AddNumberToObject(root,"ap_count",wifi_status.scan_result.ap_count); cJSON * array; cJSON * item; cJSON_AddItemToObject(root, "ap", array = cJSON_CreateArray()); //check max count on query string char *query=http_url_get_query_param(c,"max"); int max = INT_MAX; if(query!=NULL) max = atoi(query); int i; for(i=0;i< wifi_status.scan_result.ap_count && i<max;i++){ cJSON_AddItemToArray(array,item=cJSON_CreateObject()); cJSON_AddStringToObject(item,"ssid",(const char *)wifi_status.scan_result.ap[i]->ssid); cJSON_AddNumberToObject(item,"rssi",wifi_status.scan_result.ap[i]->rssi); cJSON_AddNumberToObject(item,"enc",wifi_status.scan_result.ap[i]->enc); cJSON_AddNumberToObject(item,"channel",wifi_status.scan_result.ap[i]->channel); } http_write_json(c,root); //delete json struct cJSON_Delete(root); status->state=99; return HTTPD_CGI_MORE; } else{ //free resources NODE_DBG("Freeing alloced memory"); os_free(c->cgi.data); return HTTPD_CGI_DONE; } } }
void save_presets(int do_update) { //*/ int i, count; char * outputdata; cJSON *root, *userobj, *versionobj, *recobj, *graphicsobj, *hudobj; FILE *f = fopen("powder.pref", "wb"); if(!f) return; root = cJSON_CreateObject(); cJSON_AddStringToObject(root, "Powder Toy 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"); } //Fav Menu/Records cJSON_AddItemToObject(root, "records", recobj=cJSON_CreateObject()); cJSON_AddNumberToObject(recobj, "num elements in menu", locked); for (i = 0; i < locked; i++) { char eltext[128] = ""; sprintf(eltext,"element %i",i); cJSON_AddNumberToObject(recobj, eltext, favMenu[18-i]); } cJSON_AddNumberToObject(recobj, "Alternate HUD ON", alt_hud); cJSON_AddNumberToObject(recobj, "Total Time Played", ((double)currentTime/1000)+((double)totaltime/1000)-((double)totalafktime/1000)-((double)afktime/1000)); cJSON_AddNumberToObject(recobj, "Average FPS", totalfps/frames); cJSON_AddNumberToObject(recobj, "Number of frames", frames); cJSON_AddNumberToObject(recobj, "Max FPS", maxfps); cJSON_AddNumberToObject(recobj, "Total AFK Time", ((double)totalafktime/1000)+((double)afktime/1000)+((double)prevafktime/1000)); cJSON_AddNumberToObject(recobj, "Times Played", timesplayed); //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)); //HUDs cJSON_AddItemToObject(root, "HUD", hudobj=cJSON_CreateObject()); cJSON_AddItemToObject(hudobj, "normal", cJSON_CreateIntArray(hud_normal, HUD_OPTIONS)); cJSON_AddItemToObject(hudobj, "debug", cJSON_CreateIntArray(hud_debug, HUD_OPTIONS)); cJSON_AddItemToObject(hudobj, "modnormal", cJSON_CreateIntArray(hud_modnormal, HUD_OPTIONS)); cJSON_AddItemToObject(hudobj, "moddebug", cJSON_CreateIntArray(hud_moddebug, HUD_OPTIONS)); //General settings cJSON_AddStringToObject(root, "proxy", http_proxy_string); cJSON_AddNumberToObject(root, "scale", sdl_scale); cJSON_AddNumberToObject(root, "Debug mode", DEBUG_MODE); outputdata = cJSON_Print(root); cJSON_Delete(root); 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); /*/ }
static int set_value(cJSON *root, const char *json_pointer, cJSON *value) { if (root == NULL) { return -1; } const int len = strlen(json_pointer); int offset = 0; if (offset == len) { //如果为"" return -1; } cJSON *parent = root; char *key = NULL; while (1) { free(key); key = get_key(json_pointer, &offset); if (key == NULL) { return -1; } if (offset >= len) { //表示没有下一个key了 break; } cJSON *child = NULL; if (parent->type == cJSON_Object) { child = cJSON_GetObjectItem(parent, key); if (child == NULL) { //总是创建object而不是数组 child = cJSON_CreateObject(); cJSON_AddItemToObject(parent, key, child); } else if (child->type != cJSON_Object && child->type != cJSON_Array) { child = cJSON_CreateObject(); cJSON_ReplaceItemInObject(parent, key, child); } else { //do nothing } } else if (parent->type == cJSON_Array) { int index = atoi(key); child = cJSON_GetArrayItem(parent, index); if (child == NULL) { //总是创建object而不是数组 child = cJSON_CreateObject(); cJSON_InsertItemInArray(parent, index, child); } else if (child->type != cJSON_Object && child->type != cJSON_Array) { child = cJSON_CreateObject(); cJSON_ReplaceItemInArray(parent, index, child); } else { //do nothing } } else { //不应该执行到这里 printf("===>not impossible\n"); } parent = child; } if (parent->type == cJSON_Array) { //key必须为0 or 123,456, '-'表示添加到最后面 if (strcmp("-", key) == 0) { cJSON_AddItemToArray(parent, value); } else { int index = atoi(key); //strtol() cJSON_InsertItemInArray(parent, index, value); } } else if (parent->type == cJSON_Object) { //cJSON_AddItemToObject(parent,key,value); cJSON *oldValue = cJSON_GetObjectItem(parent, key); if (oldValue == NULL) { cJSON_AddItemToObject(parent, key, value); } else { cJSON_ReplaceItemInObject(parent, key, value); } //cJSON *kk = cJSON_GetObjectItem(parent, key); } else { //null,number,string,boolean //不能够添加 printf("=====>noooo\n"); } free(key); return 0; }
int main(int argc, char **argv) { CGI_varlist *varlist; const char *name; CGI_value *value; int i,j,iter,portflag = 0; cJSON *json; long offset; char urlbuf[512],namebuf[512],postbuf[65536],*retstr,*delim,*url = 0; setenv("CONTENT_TYPE", "application/x-www-form-urlencoded", 1); json = cJSON_CreateObject(); for (i=j=0; argv[0][i]!=0; i++) if ( argv[0][i] == '/' || argv[0][i] == '\\' ) j = i+1; strcpy(namebuf,&argv[0][j]); offset = strlen(namebuf) - 4; if ( offset > 0 && strcmp(".exe",namebuf + offset) == 0 ) namebuf[offset] = 0; if ( strcmp(namebuf,"api") != 0 ) cJSON_AddItemToObject(json,"agent",cJSON_CreateString(namebuf)); if ( strcmp("nxt",namebuf) == 0 ) url = "http://127.0.0.1:7876/nxt"; else if ( strcmp("nxts",namebuf) == 0 ) url = "https://127.0.0.1:7876/nxt"; else if ( strcmp("port",namebuf) == 0 ) url = "http://127.0.0.1", portflag = 1; else if ( strcmp("ports",namebuf) == 0 ) url = "https://127.0.0.1", portflag = 1; if ( url != 0 ) postbuf[0] = 0, delim = ""; for (iter=0; iter<2; iter++) { if ( (varlist= ((iter==0) ? CGI_get_post(0,0) : CGI_get_query(0))) != 0 ) { for (name=CGI_first_name(varlist); name!=0; name=CGI_next_name(varlist)) { value = CGI_lookup_all(varlist,0); for (i=0; value[i]!=0; i++) { //fprintf(stderr,"%s [%d] = %s\r\n", name, i, value[i]); if ( i == 0 ) { if ( url == 0 ) cJSON_AddItemToObject(json,name,cJSON_CreateString(value[i])); else { if ( portflag != 0 && strncmp(name,"port",strlen("port")) == 0 ) sprintf(urlbuf,"%s:%s",url,value[i]), url = urlbuf, portflag = 0; else sprintf(postbuf + strlen(postbuf),"%s%s=%s",delim,name,value[i]), delim = "&"; } } } } } CGI_free_varlist(varlist); } fputs("Access-Control-Allow-Origin: null\r\n",stdout); fputs("Access-Control-Allow-Headers: Authorization, Content-Type\r\n",stdout); fputs("Access-Control-Allow-Credentials: true\r\n",stdout); fputs("Access-Control-Allow-Methods: GET, POST, OPTIONS\r\n",stdout); fputs("Content-type: text/plain\r\n",stdout); if ( url != 0 ) { fprintf(stderr,"url.(%s) (%s)\n",url,postbuf); if ( (retstr= issue_POST(url,postbuf)) != 0 ) { //fprintf(stderr,"%s",retstr); printf("Content-Length: %ld\r\n\r\n",strlen(retstr)+2); printf("%s\r\n",retstr); free(retstr); } else printf("{\"error\":\"null return from issue_NXTPOST\"}\r\n"); } else { process_json(json); } free_json(json); return 0; }
char *NpEpg_GetPF(int serv_id, int ts_id, int on_id, int flag) { time_td_t temp_time; EVENT_TEXT *temp_SHORT_EPG; ext_eit *temp_extended_EVENT; Extended_Items *temp_Extended_Items; char short_str[24]; cJSON *root, *short_epg, *extended_epg, *items, *fir, *second; EVENT *new_event = NULL; int i = 0, j = 0; char *out; int strLen; char *conv_temp = NULL; epg_debug(__FUNCTION__); new_event = App_Get_Pf_Event(serv_id, ts_id, on_id, flag); if(new_event == NULL) { return NULL; } root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "serv_id", serv_id); cJSON_AddNumberToObject(root, "ts_id", ts_id); cJSON_AddNumberToObject(root, "on_id", on_id); cJSON_AddNumberToObject(root, "P/F", flag); cJSON_AddNumberToObject(root, "event_id", new_event->event_id); App_Get_Event_Start_Time(&temp_time, new_event); cJSON_AddNumberToObject(root, "start_year", temp_time.year); cJSON_AddNumberToObject(root, "start_month", temp_time.month); cJSON_AddNumberToObject(root, "start_date", temp_time.date); cJSON_AddNumberToObject(root, "start_hour", temp_time.hour); cJSON_AddNumberToObject(root, "start_minute", temp_time.minute); cJSON_AddNumberToObject(root, "start_second", temp_time.second); cJSON_AddNumberToObject(root, "start_week", temp_time.week); App_Get_Event_End_Time(&temp_time, new_event); cJSON_AddNumberToObject(root, "end_year", temp_time.year); cJSON_AddNumberToObject(root, "end_month", temp_time.month); cJSON_AddNumberToObject(root, "end_date", temp_time.date); cJSON_AddNumberToObject(root, "end_hour", temp_time.hour); cJSON_AddNumberToObject(root, "end_minute", temp_time.minute); cJSON_AddNumberToObject(root, "end_second", temp_time.second); cJSON_AddNumberToObject(root, "end_week", temp_time.week); memset(&short_str, 0, 24); memcpy(&short_str, &(new_event->duration), 3); cJSON_AddStringToObject(root, "duration", short_str); cJSON_AddNumberToObject(root, "nibble_level", new_event->content_nibble_level); if(new_event->parental_rating != NULL) { memset(&short_str, 0, 24); memcpy(&short_str, &(new_event->parental_rating->country_code), 3); cJSON_AddStringToObject(root, "parental_country", &short_str); cJSON_AddNumberToObject(root, "parental_rate", new_event->parental_rating->rate); } if(new_event->short_epg != NULL) { cJSON_AddItemToObject(root, "short", short_epg = cJSON_CreateArray()); i = 0; temp_SHORT_EPG = new_event->short_epg; while(temp_SHORT_EPG != NULL) { cJSON_AddItemToArray(short_epg, fir = cJSON_CreateObject()); memset(&short_str, 0, 24); memcpy(&short_str, &(temp_SHORT_EPG->ISO_639_language_code), 3); cJSON_AddStringToObject(fir, "short_language", &short_str); if(temp_SHORT_EPG->event_name != NULL) { DebugMessage("========= PXWANG CALL BY strlen(temp_SHORT_EPG->event_name):%d", strlen(temp_SHORT_EPG->event_name)); conv_temp = Code_ToChar((int)(temp_SHORT_EPG->event_name[0]), temp_SHORT_EPG->event_name, temp_SHORT_EPG->name_length); if(conv_temp != NULL) { cJSON_AddStringToObject(fir, "short_name", conv_temp); free(conv_temp); } } if(temp_SHORT_EPG->short_event != NULL) { conv_temp = Code_ToChar((int)(temp_SHORT_EPG->short_event[0]), temp_SHORT_EPG->short_event, temp_SHORT_EPG->short_length); if(conv_temp != NULL) { cJSON_AddStringToObject(fir, "short_event", conv_temp); free(conv_temp); } } temp_SHORT_EPG = temp_SHORT_EPG->next; i++; } cJSON_AddNumberToObject(root, "short_num", i); } if(new_event->extended_epg != NULL) { cJSON_AddItemToObject(root, "extended", extended_epg = cJSON_CreateArray()); i = 0; temp_extended_EVENT = new_event->extended_epg; while(temp_extended_EVENT != NULL) { cJSON_AddItemToArray(extended_epg, fir = cJSON_CreateObject()); cJSON_AddNumberToObject(fir, "extended_descriptor_number", temp_extended_EVENT->descriptor_number); cJSON_AddNumberToObject(fir, "extended_last_descriptor_number", temp_extended_EVENT->last_descriptor_number); memset(&short_str, 0, 24); memcpy(&short_str, &(temp_extended_EVENT->ISO_639_language_code), 3); cJSON_AddStringToObject(fir, "extended_language", &short_str); if(temp_extended_EVENT->text != NULL) { conv_temp = Code_ToChar((int)(temp_extended_EVENT->text[0]), temp_extended_EVENT->text, temp_extended_EVENT->text_length); if(conv_temp != NULL) { cJSON_AddStringToObject(fir, "extended_text", conv_temp); free(conv_temp); } } cJSON_AddItemToObject(fir, "extended", items = cJSON_CreateArray()); j = 0; temp_Extended_Items = temp_extended_EVENT->ExtItems; while(temp_Extended_Items != NULL) { cJSON_AddItemToArray(items, second = cJSON_CreateObject()); if(temp_Extended_Items->pcItemsName != NULL) { conv_temp = Code_ToChar((int)(temp_Extended_Items->pcItemsName[0]), temp_Extended_Items->pcItemsName, temp_Extended_Items->usItemsName_Lenth); if(conv_temp != NULL) { cJSON_AddStringToObject(second, "ExtItems_ItemsName", conv_temp); free(conv_temp); } } if(temp_Extended_Items->pcItems != NULL) { conv_temp = Code_ToChar((int)(temp_Extended_Items->pcItems[0]), temp_Extended_Items->pcItems, temp_Extended_Items->usItems_Lenth); if(conv_temp != NULL) { cJSON_AddStringToObject(second, "ExtItems_Items", conv_temp); free(conv_temp); } } temp_Extended_Items = temp_Extended_Items->next; j++; } cJSON_AddNumberToObject(fir, "ExtItems_num", j); temp_extended_EVENT = temp_extended_EVENT->next; i++; } cJSON_AddNumberToObject(root, "extern_num", i); } out = cJSON_Print(root); cJSON_Delete(root); if(epg_outstr != NULL) { free(epg_outstr); epg_outstr = NULL; } strLen = strlen(out); if(strLen > 0) { epg_outstr = (char *)malloc(strLen + 10); if(epg_outstr == NULL) { return epg_outstr; } sprintf( epg_outstr, "%s", out); } free(out); return epg_outstr; }
int main(int argc, char **argv) { void portable_OS_init(); CGI_varlist *varlist; const char *name; char namebuf[512],postbuf[65536],*remoteaddr,*str=0,*retstr,*delim,*url = 0; int i,j,iter,localaccess=0,doneflag=0,portflag = 0; cJSON *json; long offset; CGI_value *value; struct destbuf urlbuf; portable_OS_init(); setenv("CONTENT_TYPE", "application/x-www-form-urlencoded", 1); json = cJSON_CreateObject(); if ( (remoteaddr= getenv("REMOTE_ADDR")) == 0 || strncmp("127.0.0.1",remoteaddr,strlen("127.0.0.1")) == 0 ) remoteaddr = 0,localaccess = 1; else cJSON_AddItemToObject(json,"remoteaddr",cJSON_CreateString(remoteaddr)); for (i=j=0; argv[0][i]!=0; i++) if ( argv[0][i] == '/' || argv[0][i] == '\\' ) j = i+1; strcpy(namebuf,&argv[0][j]); offset = strlen(namebuf) - 4; if ( offset > 0 && strcmp(".exe",namebuf + offset) == 0 ) namebuf[offset] = 0; if ( offset > 0 && strcmp(".cgi",namebuf + offset) == 0 ) namebuf[offset] = 0; if ( strcmp(namebuf,"init") == 0 || strcmp(namebuf,"") == 0 || strcmp(namebuf,"index.cgi") == 0 ) { // "http://178.63.60.131/init/?requestType=status&coin=VRC" //"http://78.47.115.250:7777/public?plugin=relay&method=busdata&servicename=MGW&serviceNXT=8119557380101451968&destplugin=MGW&submethod=status&coin=BTC" if ( strcmp(namebuf,"api") != 0 ) cJSON_AddItemToObject(json,"agent",cJSON_CreateString(namebuf)); cJSON_AddItemToObject(json,"plugin",cJSON_CreateString("relay")); cJSON_AddItemToObject(json,"method",cJSON_CreateString("busdata")); cJSON_AddItemToObject(json,"servicename",cJSON_CreateString("MGW")); cJSON_AddItemToObject(json,"serviceNXT",cJSON_CreateString("8119557380101451968")); cJSON_AddItemToObject(json,"destplugin",cJSON_CreateString("MGW")); if ( jstr(json,"requestType") != 0 ) cJSON_AddItemToObject(json,"submethod",cJSON_CreateString(jstr(json,"requestType"))); } if ( strcmp("nxt",namebuf) == 0 ) { if ( setnxturl(&urlbuf) != 0 ) url = urlbuf.buf; else url = "http://127.0.0.1:7876/nxt"; } else if ( strcmp("nxts",namebuf) == 0 ) url = "https://127.0.0.1:7876/nxt"; else if ( strcmp("port",namebuf) == 0 ) url = "http://127.0.0.1", portflag = 1; else if ( strcmp("ports",namebuf) == 0 ) url = "https://127.0.0.1", portflag = 1; fprintf(stderr,"namebuf.(%s)\n",namebuf); if ( url != 0 ) postbuf[0] = 0, delim = ""; for (iter=0; iter<3; iter++) { if ( (varlist= ((iter==0) ? CGI_get_post(0,0) : ((iter==1) ? CGI_get_query(0) : CGI_get_cookie(0)))) != 0 ) { for (name=CGI_first_name(varlist); name!=0&&doneflag==0; name=CGI_next_name(varlist)) { value = CGI_lookup_all(varlist,0); for (i=0; value[i]!=0; i++) { fprintf(stderr,"iter.%d %s [%d] = %s\r\n",iter,name,i,value[i]); if ( i == 0 ) { if ( url == 0 ) { if ( strcmp(name,"stringified") == 0 || strcmp(namebuf,"stringified") == 0 ) { char *unstringify(char *str); cJSON *obj; if ( (obj= cJSON_Parse(name)) == 0 ) { str = malloc(strlen(value[i])+1); strcpy(str,value[i]); unstringify(str); printf("unstringify (%s) -> (%s)\n",value[i],str); obj= cJSON_Parse(str); } if ( obj != 0 ) { //unstringified ((null)) -> ({"stringified":{"method":"orderbook","baseid":"12071612744977229797","relid":"5527630","maxdepth":"1"},"agent":"InstantDEX"}) free_json(json); if ( jobj(obj,"stringified") != 0 ) json = cJSON_Duplicate(jobj(obj,"stringified"),1), free_json(obj); else json = obj; cJSON_AddItemToObject(json,"agent",cJSON_CreateString("InstantDEX")); if ( remoteaddr != 0 && remoteaddr[0] != 0 ) cJSON_AddItemToObject(json,"remoteaddr",cJSON_CreateString(remoteaddr)); fprintf(stderr,"unstringified (%s) -> (%s)\n",str!=0?str:"",jprint(json,0)); if ( str != 0 ) free(str); doneflag = 1; break; } } cJSON_AddItemToObject(json,name,cJSON_CreateString(value[i])); } else { if ( portflag != 0 && strncmp(name,"port",strlen("port")) == 0 ) sprintf(urlbuf.buf,"%s:%s",url,value[i]), url = urlbuf.buf, portflag = 0; else sprintf(postbuf + strlen(postbuf),"%s%s=%s",delim,name,value[i]), delim = "&"; } } } } } CGI_free_varlist(varlist); } if ( localaccess == 0 ) fputs("Access-Control-Allow-Origin: *\r\n",stdout); else fputs("Access-Control-Allow-Origin: null\r\n",stdout); fputs("Access-Control-Allow-Credentials: true\r\n",stdout); fputs("Access-Control-Allow-Headers: Authorization, Content-Type\r\n",stdout); fputs("Access-Control-Allow-Methods: GET, POST, OPTIONS\r\n",stdout); fputs("Cache-Control: no-cache, no-store, must-revalidate\r\n",stdout); fputs("Content-type: text/plain\r\n",stdout); if ( url != 0 ) { fprintf(stderr,"url.(%s) (%s)\n",url,postbuf); if ( (retstr= issue_POST(url,postbuf)) != 0 ) { //fprintf(stderr,"%s",retstr); printf("Content-Length: %ld\r\n\r\n",strlen(retstr)+2); printf("%s\r\n",retstr); free(retstr); } else printf("{\"error\":\"null return from issue_NXTPOST\"}\r\n"); } else { if ( jobj(json,"agent") == 0 && strcmp(namebuf,"api") != 0 ) cJSON_AddItemToObject(json,"agent",cJSON_CreateString(namebuf)); fprintf(stderr,"PROCESS.(%s)\n",jprint(json,0)); process_json(json,remoteaddr,localaccess); } free_json(json); return 0; }
void jadd(cJSON *json,char *field,cJSON *item) { cJSON_AddItemToObject(json,field,item); }
void wanwuyun_task(void * pvParameters) { //创建Queue SENSOR_STRUCT *pRxSensorFrame; portBASE_TYPE xStatus; struct ip_addr WanWuYunIPaddr; static err_t err,recv_err; //网络相关结构体 struct netbuf *inbuf; uint8_t *buf; uint16_t buflen; //成功发送 = true,其他状态为 = false bool wan_send_success_flag = false; //创建Json的结构体 cJSON *DataUpReqJson, *RowJson, *DataUpResJson,*fld; char *DataOut; char double_string[]={0}; #if 0 cJSON *SignInReqJson ,*SignInResJson; SignInReqJson=cJSON_CreateObject(); cJSON_AddStringToObject(SignInReqJson, "username", "jackeyjiang"); cJSON_AddStringToObject(SignInReqJson, "accessid", "AMFJA2V5AMLHBMCXNDI5NZE2NDIXMTMW"); cJSON_AddStringToObject(SignInReqJson, "appid", "9785739981"); cJSON_AddStringToObject(SignInReqJson, "dev_id", "stm32_test"); DataOut = cJSON_Print(DataUpReqJson); cJSON_Delete(SignInReqJson); vPortFree(DataOut); DataUpReqJson=cJSON_CreateArray(); cJSON_AddItemToObject(DataUpReqJson,NULL,fld = cJSON_CreateObject()); cJSON_AddStringToObject(fld, "seckey", "HgqoOLTlav5jTsefyj3nL5AkRu8UAFRf"); cJSON_AddItemToObject(fld, "row", RowJson=cJSON_CreateObject()); cJSON_AddStringToObject(RowJson, "DEV_ID", "stm32_test"); cJSON_AddNumberToObject(RowJson, "TEMPERATURE", 12.5); cJSON_AddNumberToObject(RowJson, "LATITUDE", 12.7); cJSON_AddNumberToObject(RowJson, "LONGITUDE", 12.8); //转换数据为cJSON数据 DataOut = cJSON_Print(DataUpReqJson); cJSON_Delete(DataUpReqJson); printf("%s",DataOut); vPortFree(DataOut); //解析返回的Json数据 SignInResJson = cJSON_Parse(SignInResponse); if (!SignInResJson) vPrintString("Error before: [%s]\n",cJSON_GetErrorPtr()); else {}; DataUpResJson = cJSON_Parse(DataUpResponse); if (!DataUpResJson) vPrintString("Error before: [%s]\n",cJSON_GetErrorPtr()); else {}; #endif //创建传感器队列 pRxSensor_xQueue = xQueueCreate( 2, sizeof( struct _SENSOR_STRUCT * ) ); //建立短连接,接收到队列传过来的数据,将其打包成json数据传送到万物云。 IP4_ADDR( &WanWuYunIPaddr, WANWUYUN_IP_ADDR0, WANWUYUN_IP_ADDR1, WANWUYUN_IP_ADDR2, WANWUYUN_IP_ADDR3 ); while(1) { /* Create a new connection identifier. */ STM_EVAL_LEDOff(LED2); wanwuyun_clientconn = netconn_new_with_callback(NETCONN_TCP,wanwuyun_callback); //测试 if (wanwuyun_clientconn!=NULL) { /*built a connect to wanwuyun.com server*/ //netconn_set_nonblocking(wanwuyun_clientconn, 1); //测试 err = netconn_connect(wanwuyun_clientconn,&WanWuYunIPaddr,WANWUYUN_SERVER_PORT); if (err != ERR_OK) netconn_delete(wanwuyun_clientconn); else if (err == ERR_OK) { STM_EVAL_LEDOn(LED2); vPrintString("netconn_connect wanwuyun_clientconn\r\n"); /*timeout to wait for new data to be received <Avoid death etc.> */ netconn_set_sendtimeout(wanwuyun_clientconn,300); netconn_set_recvtimeout(wanwuyun_clientconn,700); while(!ERR_IS_FATAL(wanwuyun_clientconn->last_err)) { STM_EVAL_LEDToggle(LED3); xStatus = xQueueReceive(pRxSensor_xQueue,&(pRxSensorFrame),( portTickType ) 1 ); if(xStatus == pdPASS) { //提取结构体中的数据 DataUpReqJson=cJSON_CreateArray(); cJSON_AddItemToObject(DataUpReqJson,NULL,fld = cJSON_CreateObject()); cJSON_AddStringToObject(fld, "seckey", "HgqoOLTlav5jTsefyj3nL5AkRu8UAFRf"); cJSON_AddItemToObject(fld, "row", RowJson=cJSON_CreateObject()); cJSON_AddStringToObject(RowJson, "DEV_ID", "stm32_test"); sprintf(double_string,"%f",pRxSensorFrame->temperature[0]); cJSON_AddStringToObject(RowJson, "TEMPERATURE", double_string); sprintf(double_string,"%f",pRxSensorFrame->latitude[0]); cJSON_AddStringToObject(RowJson, "LATITUDE", double_string); sprintf(double_string,"%f",pRxSensorFrame->longitude[0]); cJSON_AddStringToObject(RowJson, "LONGITUDE", double_string); //转换数据为cJSON数据 DataOut = cJSON_Print(DataUpReqJson); //printf("%d",strlen(DataOut)); cJSON_Delete(DataUpReqJson); vPrintString("%s\r\n",DataOut); //vPortFree(DataOut); err=netconn_write(wanwuyun_clientconn,\ DataOut,strlen(DataOut),\ NETCONN_COPY); if(err != ERR_OK) { vPortFree(DataOut); vPrintString("StatuUploadReq erro code is %d\r\n",err); break; } else { wan_send_success_flag = true; //表示数据已经发送了 vPortFree(DataOut); } } //netconn_recved(wanwuyun_clientconn,100); //测试 recv_err = netconn_recv(wanwuyun_clientconn, &inbuf); if (recv_err == ERR_OK) { if (netconn_err(wanwuyun_clientconn) == ERR_OK) { netbuf_data(inbuf, (void**)&buf, &buflen); DataUpResJson = cJSON_Parse((char *)buf); DataOut = cJSON_Print(DataUpResJson); vPrintString("%s\r\n",DataOut); netbuf_delete(inbuf); wan_send_success_flag = false; //使用短链接,成功后跳出while(1) //break; } else { vPrintString("recv_err != ERR_OK \r\n"); } } #if 1 //测试当断开连接的时候的状态 else if((recv_err == ERR_TIMEOUT)&&(wan_send_success_flag == true)) { wan_send_success_flag = false; vPrintString("recv_err == %d\r\n",recv_err); netconn_close(wanwuyun_clientconn); netbuf_delete(inbuf); netconn_delete(wanwuyun_clientconn); //为发送的数据重新入队 xQueueSendToFront(pRxSensor_xQueue,&(pRxSensorFrame),( portTickType )1); break; } #endif } } } } }
void jaddnum(cJSON *json,char *field,double num) { cJSON_AddItemToObject(json,field,cJSON_CreateNumber(num)); }
static cJSON *generate_merge_patch(cJSON * const from, cJSON * const to, const cJSON_bool case_sensitive) { cJSON *from_child = NULL; cJSON *to_child = NULL; cJSON *patch = NULL; if (to == NULL) { /* patch to delete everything */ return cJSON_CreateNull(); } if (!cJSON_IsObject(to) || !cJSON_IsObject(from)) { return cJSON_Duplicate(to, 1); } sort_object(from, case_sensitive); sort_object(to, case_sensitive); from_child = from->child; to_child = to->child; patch = cJSON_CreateObject(); while (from_child || to_child) { int diff; if (from_child != NULL) { if (to_child != NULL) { diff = strcmp(from_child->string, to_child->string); } else { diff = -1; } } else { diff = 1; } if (diff < 0) { /* from has a value that to doesn't have -> remove */ cJSON_AddItemToObject(patch, from_child->string, cJSON_CreateNull()); from_child = from_child->next; } else if (diff > 0) { /* to has a value that from doesn't have -> add to patch */ cJSON_AddItemToObject(patch, to_child->string, cJSON_Duplicate(to_child, 1)); to_child = to_child->next; } else { /* object key exists in both objects */ if (!compare_json(from_child, to_child, case_sensitive)) { /* not identical --> generate a patch */ cJSON_AddItemToObject(patch, to_child->string, cJSONUtils_GenerateMergePatch(from_child, to_child)); } /* next key in the object */ from_child = from_child->next; to_child = to_child->next; } } if (patch->child == NULL) { /* no patch generated */ cJSON_Delete(patch); return NULL; } return patch; }
void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {cJSON_AddItemToObject(object,string,create_reference(item));}
void conference_event_chat_channel_handler(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id) { cJSON *data; cJSON *jid = 0; const char *type = NULL; const char *action = NULL; cJSON *msg; char *conference_name = strdup(event_channel + 15); char *message = NULL; cJSON *jdata; char *p; const char *uid = NULL; const char *display = NULL; if (conference_name && (p = strchr(conference_name, '@'))) { *p = '\0'; } uid = cJSON_GetObjectCstr(json, "userid"); display = cJSON_GetObjectCstr(json, "fromDisplay"); if ((data = cJSON_GetObjectItem(json, "data"))) { type = cJSON_GetObjectCstr(data, "type"); action = cJSON_GetObjectCstr(data, "action"); if ((jid = cJSON_GetObjectItem(data, "message"))) { if (!zstr(jid->valuestring)) { message = jid->valuestring; } } } if (action && !strcasecmp(action, "send")) { msg = cJSON_CreateObject(); jdata = json_add_child_obj(msg, "data", NULL); cJSON_AddItemToObject(msg, "eventChannel", cJSON_CreateString(event_channel)); cJSON_AddItemToObject(jdata, "direction", cJSON_CreateString("outbound")); if (message) { cJSON_AddItemToObject(jdata, "message", cJSON_CreateString(message)); } if (display) { cJSON_AddItemToObject(jdata, "fromDisplay", cJSON_CreateString(display)); } if (uid) { cJSON_AddItemToObject(jdata, "from", cJSON_CreateString(uid)); } if (type) { cJSON_AddItemToObject(jdata, "type", cJSON_CreateString(type)); } else { cJSON_AddItemToObject(jdata, "type", cJSON_CreateString("message")); } switch_event_channel_broadcast(event_channel, &msg, __FILE__, conference_globals.event_channel_id); } switch_safe_free(conference_name); }