int createServerUserFindUser(int sock,int clienttype,user_info_t* userinfo){ client_header_2_t* header = createClientHeader(COMMAND_OTHER_MESSAGE,MESSAGE_TYPE_USER_LOGIN,clienttype); cJSON* json = cJSON_CreateObject(); if(userinfo != NULL){ cJSON_AddStringToObject(json,"username",userinfo->username); cJSON_AddStringToObject(json,"userid",userinfo->userid); cJSON_AddNumberToObject(json,"isSuccess",1); cJSON* arr = cJSON_CreateArray(); if(userinfo->drivces){ list_node_t* node = NULL; int i = 0; for(i=0;i<userinfo->drivces->len;i++) { node = list_at(userinfo->drivces,i); printf("pop list=%s\n",node->val); cJSON_AddItemToArray(arr,cJSON_CreateString(node->val)); } } cJSON_AddItemToObject(json,"driveces",arr); } else{ cJSON_AddNumberToObject(json,"isSuccess",0); } char* str = cJSON_Print(json); printf("%s,%d",str,strlen(str)); int total = sizeof(server_header_2_t)+sizeof(uint16_t)+strlen(str); void* bufs = malloc(total); void* buf = bufs; header->total = total; memcpy(buf,header,sizeof(server_header_2_t)); buf += sizeof(server_header_2_t); *(uint16_t*)buf = htons(strlen(str)); buf += sizeof(uint16_t); memcpy(buf,str,strlen(str)); int ret =send(sock,bufs,total,0); free(bufs); cJSON_Delete(json); //free(str); return ret; }
void CRedWoodDataParse::testAddSensorData() { FILE *f;long len;char *data; f=fopen("json.dat","rb");fseek(f,0,SEEK_END);len=ftell(f);fseek(f,0,SEEK_SET); data=(char*)malloc(len+1);fread(data,1,len,f);fclose(f); char *out;cJSON *json, *newjson; json=cJSON_Parse(data); newjson = cJSON_CreateObject(); AddSensorDataToJson(cJSON_GetObjectItem(json, "sensorStats"), newjson); out=cJSON_Print(newjson); cJSON_Delete(json); cJSON_Delete(newjson); printf("%s\n",out); free(out); free(data); }
bool MSI_SM_Stream::CleanMSIStream(char *strUserId,char *strSerialno) { if(!Connect_MSIServer()) { LOG_ERROR_FORMAT("ERROR - [SM]:%s %d error can't connect to server\n",__FUNCTION__,__LINE__); return false; } if(pRet_root) { cJSON_Delete(pRet_root); pRet_root = NULL; } //printf("--begin json\n"); pRet_root = cJSON_CreateObject(); Requst_Json_str(2,"cmd","stream_unbind"); Requst_Json_str(2,"username",strUserId); Requst_Json_str(2,"serialno",strSerialno); Send_Jsoon_str(); return true; }
//同步更新,生成info数据 static bool synch_create_info(data_synch_request *data_request) { cJSON *root; relater_inf *p = protodata->relaterlist.head; root = cJSON_CreateArray(); while (p != NULL) { cJSON *user = cJSON_CreateObject(); cJSON_AddStringToObject(user, SYNCH_INFO_ACCOUNT, p->username); cJSON_AddNumberToObject(user, SYNCH_INFO_RIGHT, p->right); cJSON_AddStringToObject(user, SYNCH_INFO_ALIAS, p->alias); cJSON_AddStringToObject(user, SYNCH_INFO_PASS, p->password); cJSON_AddNumberToObject(user, SYNCH_INFO_TIME, p->regtime); cJSON_AddNumberToObject(user, SYNCH_INFO_STATE, p->regstatus); cJSON_AddItemToArray(root, user); p = p->next; } data_request->json_info = root; strcpy(data_request->user, protodata->cfg.devname); data_request->kind = 2; return true; }
char * joylink_package_subdev(JLDevInfo_t *sdev, int count) { if(NULL == sdev){ return NULL; } cJSON *arrary; char *out = NULL; unsigned int i; cJSON **js_devs = (cJSON **)malloc(sizeof(cJSON *) * count); if(js_devs == NULL){ goto RET; } if(NULL == (arrary = cJSON_CreateArray())){ free(js_devs); goto RET; } for(i = 0; i < count; i ++){ js_devs[i] =cJSON_CreateObject(); if(NULL != js_devs[i]){ cJSON_AddItemToArray(arrary, js_devs[i]); cJSON_AddNumberToObject(js_devs[i], "state", sdev[i].state); cJSON_AddNumberToObject(js_devs[i], "protocol", sdev[i].jlp.protocol); cJSON_AddStringToObject(js_devs[i], "mac", sdev[i].jlp.mac); cJSON_AddStringToObject(js_devs[i], "productuuid", sdev[i].jlp.uuid); cJSON_AddNumberToObject(js_devs[i], "lancon", sdev[i].jlp.lancon); cJSON_AddNumberToObject(js_devs[i], "trantype", sdev[i].jlp.cmd_tran_type); cJSON_AddStringToObject(js_devs[i], "feedid", sdev[i].jlp.feedid); cJSON_AddStringToObject(js_devs[i], "devkey", sdev[i].jlp.pubkeyS); } } out=cJSON_Print(arrary); cJSON_Delete(arrary); RET: return out; }
cJSON *InstantDEX_argjson(char *reference,char *message,bits256 basetxid,bits256 reltxid,int32_t iter,int32_t val,int32_t val2) { cJSON *argjson = cJSON_CreateObject(); jaddstr(argjson,"ref",reference); if ( message != 0 && message[0] != 0 ) jaddstr(argjson,"message",message); jaddbits256(argjson,"basetxid",basetxid); jaddbits256(argjson,"reltxid",reltxid); if ( iter != 3 ) { jaddnum(argjson,"duration",val); jaddnum(argjson,"flags",val2); } else { if ( val > 0 ) jaddnum(argjson,"baseheight",val); if ( val2 > 0 ) jaddnum(argjson,"relheight",val2); } return(argjson); }
// Push a Serialiser instance onto the stack void JPLua_Serialiser_CreateRef( lua_State *L, const char *path, fsMode_t mode ) { jplua_serialiser_t *serialiser = NULL; int len = 0; serialiser = (jplua_serialiser_t *)lua_newuserdata( L, sizeof(jplua_serialiser_t) ); if (JPLua.currentPlugin){ Com_sprintf(serialiser->fileName, sizeof(serialiser->fileName), "%s%s/%s", pluginDir, JPLua.currentPlugin->name, path); } else{ Com_sprintf(serialiser->fileName, sizeof(serialiser->fileName), "%s%s", pluginDir, path); } len = trap->FS_Open( serialiser->fileName, &serialiser->fileHandle, mode ); if ( mode == FS_WRITE ) { serialiser->write = qtrue; serialiser->read = qfalse; serialiser->outRoot = cJSON_CreateObject(); } else if ( mode == FS_READ ) { serialiser->read = qtrue; serialiser->write = qfalse; if ( len > 0 ) { char *contents = (char *)malloc( len ); trap->FS_Read( contents, len, serialiser->fileHandle ); serialiser->inRoot = cJSON_Parse( contents ); if ( !serialiser->inRoot ) Com_Printf( "Couldn't parse serialised JSON data %s\n", path ); free( contents ); contents = NULL; } else serialiser->inRoot = NULL; } luaL_getmetatable( L, SERIALISER_META ); lua_setmetatable( L, -2 ); }
HASH_AND_INT(ramchain,getrawtransaction,txid,verbose) { struct iguana_txid *tx,T; char *txbytes; bits256 checktxid; int32_t len,height; cJSON *retjson; if ( (tx= iguana_txidfind(coin,&height,&T,txid)) != 0 ) { retjson = cJSON_CreateObject(); if ( (len= iguana_txbytes(coin,coin->blockspace,sizeof(coin->blockspace),&checktxid,tx,height,0,0)) > 0 ) { txbytes = mycalloc('x',1,len*2+1); init_hexbytes_noT(txbytes,coin->blockspace,len*2+1); jaddstr(retjson,"result",txbytes); myfree(txbytes,len*2+1); return(jprint(retjson,1)); } else if ( height >= 0 ) { if ( coin->APIblockstr != 0 ) jaddstr(retjson,"error","already have pending request"); else { int32_t datalen; uint8_t *data; char *blockstr; bits256 blockhash; blockhash = iguana_blockhash(coin,height); if ( (blockstr= iguana_APIrequest(coin,blockhash,txid,2)) != 0 ) { datalen = (int32_t)(strlen(blockstr) >> 1); data = malloc(datalen); decode_hex(data,datalen,blockstr); if ( (txbytes= iguana_txscan(coin,verbose != 0 ? retjson : 0,data,datalen,txid)) != 0 ) { jaddstr(retjson,"result",txbytes); jaddbits256(retjson,"blockhash",blockhash); jaddnum(retjson,"height",height); free(txbytes); } else jaddstr(retjson,"error","cant find txid in block"); free(blockstr); free(data); } else jaddstr(retjson,"error","cant find blockhash"); return(jprint(retjson,1)); }
Eina_Bool azy_content_serialize_request_json(Azy_Content *content) { Eina_List *l; Eina_Value *v; cJSON *object, *params; char *msg; if ((!content) || (content->buffer)) return EINA_FALSE; object = cJSON_CreateObject(); cJSON_AddStringToObject(object, "method", content->method); if (content->params) { params = cJSON_CreateArray(); EINA_LIST_FOREACH(content->params, l, v) cJSON_AddItemToArray(params, azy_value_serialize_json(v)); cJSON_AddItemToObject(object, "params", params); } cJSON_AddNumberToObject(object, "id", content->id); if (eina_log_domain_level_check(azy_log_dom, EINA_LOG_LEVEL_DBG)) msg = cJSON_Print(object); else msg = cJSON_PrintUnformatted(object); if(!msg) goto free_object; azy_content_buffer_set_(content, (unsigned char *)msg, strlen(msg)); cJSON_Delete(object); return EINA_TRUE; free_object: cJSON_Delete(object); return EINA_FALSE; }
void util_print_point(uint32 time, float target, float temperature) { cJSON *root; char *tmpMessage; sint32 tmp_targ; sint32 tmp_temp; tmp_targ = (sint32)( target + 0.5 ); tmp_temp = (sint32)( temperature + 0.5 ); root = cJSON_CreateObject(); cJSON_AddNumberToObject( root, "type", POINT ); cJSON_AddNumberToObject( root, "time", time ); cJSON_AddNumberToObject( root, "target", tmp_targ ); cJSON_AddNumberToObject( root, "temp", tmp_temp ); tmpMessage = cJSON_Print( root ); printf( "%s", tmpMessage ); fflush( stdout ); cJSON_Delete(root); return; }
cJSON *JSONNode::spawnNode(int nodeType, char *name) { cJSON *node = NULL; if(nodeType == cJSON_Object) { node = cJSON_CreateObject(); node -> string = name; }else if(nodeType == cJSON_Array){ node = cJSON_CreateArray(); node -> string = name; }else if(nodeType == cJSON_True){ node = cJSON_CreateTrue(); node -> string = name; }else if(nodeType == cJSON_False){ node = cJSON_CreateFalse(); node -> string = name; }else if(nodeType == cJSON_NULL){ node = cJSON_CreateNull(); node -> string = name; } return node; }
int Parser_swm_get_smi_rep(char *pCommData, char **outputStr) { sys_mon_info_t * pSysMonInfo = (sys_mon_info_t *)pCommData; char * out = NULL; int outLen = 0; cJSON *pSUSICommDataItem = NULL; if(pCommData == NULL || outputStr == NULL) return outLen; pSUSICommDataItem = cJSON_CreateObject(); cJSON_AddSysMonInfoToObject(pSUSICommDataItem, SWM_SYS_MON_INFO, pSysMonInfo); out = cJSON_PrintUnformatted(pSUSICommDataItem); outLen = strlen(out) + 1; *outputStr = (char *)(malloc(outLen)); memset(*outputStr, 0, outLen); strcpy(*outputStr, out); cJSON_Delete(pSUSICommDataItem); printf("%s\n",out); free(out); return outLen; }
void krad_websocket_add_portgroup ( krad_ipc_session_data_t *krad_ipc_session_data, char *portname, float floatval, char *crossfade_name, float crossfade_val, int xmms2 ) { //printkd ("add a portgroup called %s withe a volume of %f", portname, floatval); cJSON *msg; cJSON_AddItemToArray(krad_ipc_session_data->msgs, msg = cJSON_CreateObject()); cJSON_AddStringToObject (msg, "com", "kradmixer"); cJSON_AddStringToObject (msg, "cmd", "add_portgroup"); cJSON_AddStringToObject (msg, "portgroup_name", portname); cJSON_AddNumberToObject (msg, "volume", floatval); cJSON_AddStringToObject (msg, "crossfade_name", crossfade_name); cJSON_AddNumberToObject (msg, "crossfade", crossfade_val); cJSON_AddNumberToObject (msg, "xmms2", xmms2); krad_ipc_get_tags (krad_ipc_session_data->krad_ipc_client, portname); }
cJSON *socket_end_serialize(struct socket_end_st *se) { cJSON *result, *pipelines; char keybuf[SHAREDKEY_BYTESIZE*4], byte[8]; int i; result = cJSON_CreateObject(); pipelines = cJSON_CreateArray(); cJSON_AddNumberToObject(result, "id", se->id); keybuf[0]=0; for (i=0;i<SHAREDKEY_BYTESIZE;++i) { snprintf(byte, 8, "%.2x ", se->shared_key[i]); strcat(keybuf, byte); } cJSON_AddStringToObject(result, "SharedKey", keybuf); cJSON_AddNumberToObject(result, "SendBuffer", streambuf_nr_bytes(se->send_buffer)); for (i=se->pipeline_1; i!=-1; i=se->pipeline_end[i]->next_id) { cJSON_AddItemToArray(pipelines, pipeline_end_serialize(se->pipeline_end[i])); } cJSON_AddItemToObject(result, "Pipelines", pipelines); return result; }
void Cursynth::saveConfiguration() { confirmPathExists(getConfigPath()); // Store all the MIDI learn data into JSON. cJSON* root = cJSON_CreateObject(); std::map<int, std::string>::iterator iter = midi_learn_.begin(); for (; iter != midi_learn_.end(); ++iter) { cJSON* midi = cJSON_CreateNumber(iter->first); cJSON_AddItemToObject(root, iter->second.c_str(), midi); } // Write the configuration JSON to the configuration file. char* json = cJSON_Print(root); std::ofstream save_file; save_file.open(getConfigFile().c_str()); MOPO_ASSERT(save_file.is_open()); save_file << json; save_file.close(); free(json); cJSON_Delete(root); }
bool Advertisement_Stream::CheckStatus(int iStreamID,char *serialno) { if(!Connect_AdvServer()) { LOG_ERROR_FORMAT("ERROR - [SM]:%s %d Connect_AdvServer ERROR\n",__FUNCTION__,__LINE__); return false; } char strSeesionId[32]={0}; sprintf(strSeesionId,"%d",iStreamID); if(pRet_root) { cJSON_Delete(pRet_root); pRet_root = NULL; } pRet_root = cJSON_CreateObject(); Requst_Json_str(2,"cmd","check_session"); Requst_Json_str(2,"sessionid",strSeesionId); Requst_Json_str(2,"serialno",serialno); Send_Jsoon_str(); }
STRING_AND_INT(iguana,bundlehashes,activecoin,height) { struct iguana_info *ptr; struct iguana_bundle *bp; int32_t i,hdrsi; cJSON *retjson,*array; struct iguana_ramchaindata *rdata; if ( (ptr= iguana_coinfind(activecoin)) != 0 ) { hdrsi = height / coin->chain->bundlesize; if ( hdrsi < coin->bundlescount && hdrsi >= 0 && (bp= coin->bundles[hdrsi]) != 0 ) { if ( (rdata= bp->ramchain.H.data) != 0 ) { array = cJSON_CreateArray(); for (i=0; i<IGUANA_NUMLHASHES; i++) jaddinum(array,rdata->lhashes[i].txid); retjson = cJSON_CreateObject(); jaddstr(retjson,"result","success"); jaddbits256(retjson,"sha256",rdata->sha256); jadd(retjson,"bundlehashes",array); return(jprint(retjson,1)); } else return(clonestr("{\"error\":\"ramchain not there\"}")); } else return(clonestr("{\"error\":\"height is too big\"}")); } else return(clonestr("{\"error\":\"activecoin is not active\"}")); }
int createServerUserReg(int sock,int serverid,int isSuccess,char* userid,char* username){ server_header_2_t* header = createServerHeader(serverid,COMMAND_OTHER_MESSAGE,MESSAGE_TYPE_USER_REG); cJSON* json = cJSON_CreateObject(); cJSON_AddNumberToObject(json,"result",isSuccess); cJSON_AddStringToObject(json,"username",username); cJSON_AddStringToObject(json,"userid","userid"); char* str = cJSON_Print(json); int total = sizeof(server_header_2_t)+sizeof(uint16_t)+strlen(str); void* bufs = malloc(total); void* buf = bufs; header->total = total; memcpy(buf,header,sizeof(server_header_2_t)); buf += sizeof(server_header_2_t); *(uint16_t*)buf = htons(strlen(str)); buf += sizeof(uint16_t); memcpy(buf,str,strlen(str)); int ret =send(sock,bufs,total,0); free(bufs); cJSON_Delete(json); //free(str); return ret; }
int createClientUserGetFriends(int sock,int clienttype,char* username){ client_header_2_t* header = createClientHeader(COMMAND_OTHER_MESSAGE,MESSAGE_TYPE_USER_GET_FRIEND,clienttype); cJSON* json = cJSON_CreateObject(); cJSON_AddStringToObject(json,"username",username); char* str = cJSON_Print(json); int total = sizeof(client_header_2_t)+sizeof(uint16_t)+strlen(str); void* bufs = malloc(total); void* buf = bufs; header->total = total; memcpy(buf,header,sizeof(client_header_2_t)); buf += sizeof(client_header_2_t); *(uint16_t*)buf = htons(strlen(str)); buf += sizeof(uint16_t); memcpy(buf,str,strlen(str)); dump_data(bufs,total); int ret =send(sock,bufs,total,0); printf("%d\n",ret); free(bufs); // free(str); cJSON_Delete(json); return ret; }
ssap_message* generateDeleteMessageWithQueryType(const char * sessionKey, const char* ontology, const char* query, SSAPQueryType queryType){ ssap_message* removeMessage = allocateSsapMessage(); cJSON *body; //Crea la raiz del JSON body=cJSON_CreateObject(); //Añade las propiedades al body cJSON_AddItemToObject(body, "data", cJSON_CreateNull()); cJSON_AddItemToObject(body, "query", cJSON_CreateString(query)); switch(queryType){ case NATIVE: cJSON_AddItemToObject(body, "queryType", cJSON_CreateString("NATIVE")); break; case SQLLIKE: cJSON_AddItemToObject(body, "queryType", cJSON_CreateString("SQLLIKE")); break; case BDH: cJSON_AddItemToObject(body, "queryType", cJSON_CreateString("BDH")); break; default: cJSON_AddItemToObject(body, "queryType", cJSON_CreateNull()); break; } removeMessage->body=cJSON_PrintUnformatted(body); removeMessage->direction = REQUEST; removeMessage->messageId = NULL; removeMessage->messageType=DELETE; removeMessage->ontology=(char*) malloc((strlen(ontology)+1)*sizeof(char)); strcpy(removeMessage->ontology, ontology); removeMessage->sessionKey=(char*) malloc((strlen(sessionKey)+1)*sizeof(char)); strcpy(removeMessage->sessionKey, sessionKey); removeMessage->persistenceType=MONGODB; cJSON_Delete(body); return removeMessage; }
// Called on game shutdown void G_WriteClientSessionData( const gclient_t *client ) { const clientSession_t *sess = &client->sess; cJSON *root; fileHandle_t f; char fileName[MAX_QPATH] = {}; Com_sprintf( fileName, sizeof(fileName), "session/client%02i.json", (int)(client - level.clients) ); Com_Printf( "Writing session file %s\n", fileName ); root = cJSON_CreateObject(); cJSON_AddIntegerToObject( root, "sessionTeam", sess->sessionTeam ); cJSON_AddIntegerToObject( root, "spectatorNum", sess->spectatorNum ); cJSON_AddIntegerToObject( root, "spectatorState", sess->spectatorState ); cJSON_AddIntegerToObject( root, "spectatorClient", sess->spectatorClient ); cJSON_AddIntegerToObject( root, "wins", sess->wins ); cJSON_AddIntegerToObject( root, "losses", sess->losses ); cJSON_AddIntegerToObject( root, "setForce", sess->setForce ); cJSON_AddIntegerToObject( root, "saberLevel", sess->saberLevel ); cJSON_AddIntegerToObject( root, "selectedFP", sess->selectedFP ); cJSON_AddIntegerToObject( root, "updateUITime", sess->updateUITime ); cJSON_AddIntegerToObject( root, "teamLeader", sess->teamLeader ); cJSON_AddIntegerToObject( root, "duelTeam", sess->duelTeam ); cJSON_AddIntegerToObject( root, "siegeDesiredTeam", sess->siegeDesiredTeam ); cJSON_AddStringToObject( root, "siegeClass", *sess->siegeClass ? sess->siegeClass : "none" ); cJSON_AddStringToObject( root, "saberType", *sess->saberType ? sess->saberType : "" ); cJSON_AddStringToObject( root, "saber2Type", *sess->saber2Type ? sess->saber2Type : "" ); cJSON_AddStringToObject( root, "IP", sess->IP ); cJSON_AddIntegerToObject( root, "connTime", sess->connTime ); cJSON_AddIntegerToObject( root, "noq3fill", sess->noq3fill ); cJSON_AddIntegerToObject( root, "validated", sess->validated ); cJSON_AddIntegerToObject( root, "adminRank", sess->adminRank ); cJSON_AddIntegerToObject( root, "canUseCheats", sess->canUseCheats ? 1 : 0 ); trap->FS_Open( fileName, &f, FS_WRITE ); Q_FSWriteJSON( root, f ); }
// Print JSON header to gzout static void bubble_caller_print_header(gzFile gzout, const char* out_path, BubbleCallingPrefs prefs, cJSON **hdrs, size_t nhdrs, const dBGraph *db_graph) { size_t i; // Construct cJSON cJSON *json = cJSON_CreateObject(); cJSON_AddStringToObject(json, "file_format", "CtxBubbles"); cJSON_AddNumberToObject(json, "format_version", BUBBLE_FORMAT_VERSION); // Add standard cortex headers json_hdr_make_std(json, out_path, hdrs, nhdrs, db_graph); // Add parameters used in bubble calling to the header json_hdr_augment_cmd(json, "bubbles", "max_flank_kmers", cJSON_CreateInt(prefs.max_flank_len)); json_hdr_augment_cmd(json, "bubbles", "max_allele_kmers", cJSON_CreateInt(prefs.max_allele_len)); cJSON *haploids = cJSON_CreateArray(); for(i = 0; i < prefs.num_haploid; i++) cJSON_AddItemToArray(haploids, cJSON_CreateInt(prefs.haploid_cols[i])); json_hdr_augment_cmd(json, "bubbles", "haploid_colours", haploids); // Write header to file json_hdr_gzprint(json, gzout); // Print comments about the format gzputs(gzout, "\n"); gzputs(gzout, "# This file was generated with McCortex\n"); gzputs(gzout, "# written by Isaac Turner <*****@*****.**>\n"); gzputs(gzout, "# url: "CORTEX_URL"\n"); gzputs(gzout, "# \n"); gzputs(gzout, "# Comment lines begin with a # and are ignored, but must come after the header\n"); gzputs(gzout, "\n"); cJSON_Delete(json); }
bool register_namepwd(int sockfd) { /////////////////////////////// bool res = true; cJSON *root; root = cJSON_CreateObject(); if(NULL == root) { printf("createobject error\n"); res = false; return res; } printf("please input usename\n"); char buff[128]={0}; fgets(buff,128,stdin); printf("usename: %s",buff); cJSON_AddStringToObject(root,"usename",buff); printf("please input password\n"); fgets(buff,128,stdin); printf("password: %s",buff); cJSON_AddStringToObject(root,"password",buff); char *s=cJSON_Print(root); strncpy(buff,s,128); write(sockfd,buff,strlen(buff)); read(sockfd,buff,128); if(strcmp(buff,"no") == 0) { res=false; printf("register failed\n"); } else if(strcmp(buff,"yes")==0) { printf("register successful,please login\n"); } cJSON_Delete(root); free(s); return res; }
void Client::joinRoomInUserRange(int minJoinedUsers, int maxJoinedUsers, bool maxPreferred) { if((_state != ConnectionState::connected) || (_socket == NULL)){ if(_roomlistener != NULL) { room _room; _room.result = ResultCode::connection_error; _roomlistener->onJoinRoomDone(_room); } return; } int byteLen; byte *req; std::string payload; cJSON *payloadJSON; payloadJSON = cJSON_CreateObject(); cJSON_AddNumberToObject(payloadJSON, "minUsers", minJoinedUsers); cJSON_AddNumberToObject(payloadJSON, "maxUsers", maxJoinedUsers); maxPreferred ? cJSON_AddTrueToObject(payloadJSON, "maxPreferred") : cJSON_AddFalseToObject(payloadJSON, "maxPreferred"); char *cRet = cJSON_PrintUnformatted(payloadJSON); payload = cRet; req = buildWarpRequest(RequestType::join_room_range, payload, byteLen); char *data = new char[byteLen]; for(int i=0; i< byteLen; ++i) { data[i] = req[i]; } _socket->sockSend(data, byteLen); delete[] data; delete[] req; cJSON_Delete(payloadJSON); free(cRet); }
int Parser_swm_mon_prc_event_rep(char *pCommData, char **outputStr) { swm_thr_rep_info_t *pThrRepInfo = (swm_thr_rep_info_t *)pCommData; char * out = NULL; int outLen = 0; cJSON *pSUSICommDataItem = NULL; if(pCommData == NULL || outputStr == NULL) return outLen; pSUSICommDataItem = cJSON_CreateObject(); if(pThrRepInfo) { if(pThrRepInfo->isTotalNormal) { cJSON_AddStringToObject(pSUSICommDataItem, SWM_NORMAL_STATUS, "True"); } else { cJSON_AddStringToObject(pSUSICommDataItem, SWM_NORMAL_STATUS, "False"); } if(pThrRepInfo->repInfo) { cJSON_AddStringToObject(pSUSICommDataItem, SWM_PRC_MON_EVENT_MSG, pThrRepInfo->repInfo); } } out = cJSON_PrintUnformatted(pSUSICommDataItem); outLen = strlen(out) + 1; *outputStr = (char *)(malloc(outLen)); memset(*outputStr, 0, outLen); strcpy(*outputStr, out); cJSON_Delete(pSUSICommDataItem); printf("%s\n",out); free(out); return outLen; }
// TODO; prefer GET/POST static stat_query_t *StatQuery_CreateQuery( const char *iface, const char *str, bool get ) { stat_query_t *query; assert( str != NULL ); if( str == NULL ) { return NULL; } query = SQALLOC( sizeof( *query ) ); memset( query, 0, sizeof( *query ) ); if( iface && *iface ) { query->iface = SQALLOC( strlen( iface ) + 1 ); strcpy( query->iface, iface ); } query->json_out = cJSON_CreateObject(); if( str[0] == '/' ) { str += 1; } if( !get ) query->req = wswcurl_create( iface, "%s/%s", mm_url->string, str ); else { // add in '/', '?' and '\0' = 3 query->url = SQALLOC( strlen( mm_url->string ) + strlen( str ) + 3 ); // ch : lazy code :( strcpy( query->url, mm_url->string ); strcat( query->url, "/" ); strcat( query->url, str ); strcat( query->url, "?" ); } return query; }
bool MSI_SM_Stream::CleanMSIStream(char *strUserId,char *strSerialno) { if(!Connect_MSIServer()) { printf("error can't connect to server \n"); fflush(stdout); return false; } if(pRet_root) { cJSON_Delete(pRet_root); pRet_root = NULL; } //printf("--begin json\n"); pRet_root = cJSON_CreateObject(); Requst_Json_str(2,"cmd","stream_unbind"); Requst_Json_str(2,"username",strUserId); Requst_Json_str(2,"serialno",strSerialno); Send_Jsoon_str(); return true; }
int ont_video_dev_set_channels(void *_dev, int channels) { ont_device_t *dev = _dev; char dsname[32]; int i = 0; cJSON *json = cJSON_CreateObject(); cJSON_AddItemToObject(json, "dst", cJSON_CreateString("video")); cJSON_AddItemToObject(json, "beginTime", cJSON_CreateString("")); cJSON_AddItemToObject(json, "endTime", cJSON_CreateString("")); cJSON_AddItemToObject(json, "vedioDesc", cJSON_CreateString("Nothing to show")); char *jsonValue = cJSON_PrintUnformatted(json); for (i = 0; i < channels; i++) { ont_platform_snprintf(dsname, sizeof(dsname), "ont_video_%d_mqtt_test_video", i + 1); ont_device_add_dp_object(dev, dsname, jsonValue); } ont_device_send_dp(dev); ont_platform_free(jsonValue); cJSON_Delete(json); return 0; }
int auth_client_login_publish(const unsigned char *mac, const char *ssid, unsigned int uid) { char buf[128]; char *msgstr; cJSON *msg; sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X,%s,%X\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], ssid, uid); msg = cJSON_CreateObject(); cJSON_AddStringToObject(msg, "cmd", "login_success"); cJSON_AddStringToObject(msg, "data", buf); msgstr = cJSON_PrintUnformatted(msg); printf("%s\n", msgstr); auth_mqtt_publish("a/vlan/local", msgstr, strlen(msgstr)); cJSON_Delete(msg); free(msgstr); return 0; }
bool Advertisement_Stream::CleanALLAdverStream() { if(!Connect_AdvServer()) { LOG_ERROR_FORMAT("ERROR - [SM]:%s %d error can't connect to server\n",__FUNCTION__,__LINE__); return false; } if(pRet_root) { cJSON_Delete(pRet_root); pRet_root = NULL; } pRet_root = cJSON_CreateObject(); Requst_Json_str(2,"cmd","reset_device"); Requst_Json_str(2,"returnCode","0"); Requst_Json_str(2,"serialno","11111111"); Send_Jsoon_str(); return true; }