本文整理汇总了C++中cJSON_Print函数的典型用法代码示例。如果您正苦于以下问题:C++ cJSON_Print函数的具体用法?C++ cJSON_Print怎么用?C++ cJSON_Print使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cJSON_Print函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cJSON_CreateObject
void ScreenOverlayManager::SaveLayouts()
{
#if MYFW_WINDOWS && MYFW_USING_WX
cJSON* layouts = cJSON_CreateObject();
for( int i=0; i<ScreenOverlay_NumScreens; i++ )
{
if( m_LayoutJSONStrings[i][LayoutType_Wide] != 0 ||
m_LayoutJSONStrings[i][LayoutType_Tall] != 0 ||
m_LayoutJSONStrings[i][LayoutType_Square] != 0 )
{
cJSON* screenlayout = cJSON_CreateObject();
cJSON_AddItemToObject( layouts, ScreenOverlayNames[i], screenlayout );
if( m_LayoutJSONStrings[i][LayoutType_Wide] )
cJSON_AddStringToObject( screenlayout, "Wide", m_LayoutJSONStrings[i][LayoutType_Wide] );
if( m_LayoutJSONStrings[i][LayoutType_Tall] )
cJSON_AddStringToObject( screenlayout, "Tall", m_LayoutJSONStrings[i][LayoutType_Tall] );
if( m_LayoutJSONStrings[i][LayoutType_Square] )
cJSON_AddStringToObject( screenlayout, "Square", m_LayoutJSONStrings[i][LayoutType_Square] );
}
}
char* layoutstring = cJSON_Print( layouts );
cJSON_Delete( layouts );
char filename[MAX_PATH];
sprintf_s( filename, MAX_PATH, "Data/Layouts/allscreens.layout" );
FILE* file;
fopen_s( &file, filename, "wb" );
fprintf( file, layoutstring );
fclose( file );
free( layoutstring );
#endif
}
示例2: cJSON_Print
bool Stream::Send_Jsoon_str()
{
char cJsonBuff[1024 * 2];
char * m_tmp;
m_tmp = cJSON_Print(pRet_root);
memset(cJsonBuff, 0, sizeof(cJsonBuff));
sprintf(cJsonBuff, "%sXXEE", m_tmp);
free(m_tmp);
printf("-----%s \n",cJsonBuff);
fflush(stdout);
cJSON_Delete(pRet_root);
pRet_root = NULL;
if(m_clientSocket != -1)
{
send(m_clientSocket, cJsonBuff, strlen(cJsonBuff), 0);
printf("---send len=%d\n",strlen(cJsonBuff));
printf("---send over\n");
fflush(stdout);
}
}
示例3: parse
size_t parse(char *ptr, size_t size, size_t nmemb, char *data)
{
if(size*nmemb <= 2)
{
return size*nmemb;
}
printf("%s\n", ptr); //DEBUG
cJSON *root = cJSON_Parse(ptr);
struct cJSON *current = root->child;
while(strcmp(current->string, "text") != 0)
{
if(current->next != NULL)
{
current = current->next;
} else {
break;
printf("done"); //DEBUG
}
}
if(strstr(current->valuestring, "START") != NULL)
{
bcm2835_gpio_write(PIN, HIGH);
} else if(strstr(current->valuestring, "OFF") != NULL)
{
bcm2835_gpio_write(PIN, LOW);
}
printf("Current object: %s\n", cJSON_Print(current)); //DEBUG
return size*nmemb;
}
示例4: ixcgi_reqstb_streaming
int ixcgi_reqstb_streaming(char *handle, char *type, int16_t port, int16_t ttl, int fe_id, int ch_id, char *path, char *in, size_t in_size)
{
cJSON *root;
char *out;
size_t n_recv;
int timeout = 12000;
if ((root = cJSON_CreateObject()) == NULL)
return -1;
cJSON_AddItemToObject(root, HTTPD_OPCODE, cJSON_CreateString(HTTPD_STREAMING));
cJSON_AddItemToObject(root, HTTPD_STREAMING_MY_IP, cJSON_CreateString(getenv("REMOTE_ADDR")));
if (handle[0]) {
cJSON_AddItemToObject(root, HTTPD_STREAMING_STOP, cJSON_CreateString(handle));
timeout = 2000;
} else {
cJSON_AddItemToObject(root, HTTPD_STREAMING_TYPE, cJSON_CreateString(type));
cJSON_AddItemToObject(root, HTTPD_STREAMING_PORT, cJSON_CreateNumber(port));
cJSON_AddItemToObject(root, HTTPD_STREAMING_TTL, cJSON_CreateNumber(ttl));
if ((fe_id >= 0) && (ch_id > 0)) {
cJSON_AddItemToObject(root, HTTPD_STREAMING_FE_ID, cJSON_CreateNumber(fe_id));
cJSON_AddItemToObject(root, HTTPD_STREAMING_CH_ID, cJSON_CreateNumber(ch_id));
} else {
cJSON_AddItemToObject(root, HTTPD_STREAMING_PATH, cJSON_CreateString(path));
}
}
n_recv = send_recv_stbd(out = cJSON_Print(root), in, in_size, timeout);
cJSON_Delete(root);
free(out);
return (n_recv == 0) ? -1 : 0 ;
}
示例5: main
//.........这里部分代码省略.........
for(i=LEN;i<len[id]-req_pam_len;i++){ // All possible gRNAs, +direction
if(check_pam(str[id]+i,req_pam)){
psb_site[pi].index=i;
psb_site[pi].strand='+';
psb_site[pi].chromosome=id;
for(j=0;j<req_pam_len;j++) psb_site[pi].pam[j]=(str[id]+i)[j];
psb_site[pi].pam[j]=0;
for(j=0;j<LEN;j++) psb_site[pi].nt[j]=(str[id]+i-LEN)[j];
psb_site[pi].nt[j]=0;
pi++;
}
}
char req_pam_rev[PAM_LEN];
int last=-1;
dna_rev(req_pam_rev,req_pam,req_pam_len);
for(i=0;i<len[id]-LEN-req_pam_len;i++){ // All possible gRNAs, -direction
if(check_pam(str[id]+i,req_pam_rev)){
psb_site[pi].index=i+req_pam_len-1;
psb_site[pi].strand='-';
psb_site[pi].chromosome=id;
if(req_pam_len!=last){
last=req_pam_len;
}
for(j=0;j<req_pam_len;j++) psb_site[pi].pam[j]=dna_rev_char((str[id]+i)[req_pam_len-1-j]);
psb_site[pi].pam[j]=0;
for(j=0;j<LEN;j++) psb_site[pi].nt[j]=dna_rev_char((str[id]+i+req_pam_len)[LEN-j-1]);
psb_site[pi].nt[j]=0;
pi++;
}
}
}
for(i=0;i<pi;i++){
fflush(stdout);
if(psb_site[i].chromosome!=req_id) continue;
if(psb_site[i].strand=='+'){
if(psb_site[i].index<req_gene_start || psb_site[i].index+req_pam_len-1>req_gene_end) continue;
for(j=psb_site[i].index-LEN;j<psb_site[i].index+req_pam_len-1;j++){
if(wai[req_id][j]!=1) break;
}
if(j<psb_site[i].index+req_pam_len-1) j=0;
else j=1;
}else{
if(psb_site[i].index-req_pam_len+1<req_gene_start || psb_site[i].index>req_gene_end) continue;
for(j=psb_site[i].index-req_pam_len+1;j<psb_site[i].index+LEN;j++){
if(wai[req_id][j]!=1) break;
}
if(j<psb_site[i].index+LEN) j=0;
else j=1;
}
if(j){
score(i,&ini,req_type,req_r1);
}
}
dc_save();
sort(in_site,in_site+ini,cmp_in_site); // Sort & Output
root=cJSON_CreateObject();
cJSON_AddNumberToObject(root,"status",0);
msg=cJSON_CreateObject();
cJSON_AddStringToObject(msg,"specie",req_specie);
cJSON_AddStringToObject(msg,"kind",req_kind);
cJSON_AddStringToObject(msg,"gene",req_gene);
sprintf(buffer,"%d:%d..%d",req_id,req_gene_start,req_gene_end);
cJSON_AddStringToObject(msg,"location",buffer);
cJSON_AddItemToObject(root,"message",msg);
vector<cJSON*> list;
list.clear();
for(i=0;i<ini && i!=smallOutputNumber;i++){
cJSON *ans=cJSON_CreateObject();
sprintf(buffer,"#%d",i+1);
cJSON_AddStringToObject(ans,"key",buffer);
sprintf(buffer,"%s%s",in_site[i].nt,in_site[i].pam);
cJSON_AddStringToObject(ans,"grna",buffer);
sprintf(buffer,"%d:%d",in_site[i].chromosome,in_site[i].index);
cJSON_AddStringToObject(ans,"position",buffer);
char xs[2];
xs[0]=in_site[i].strand;
xs[1]=0;
cJSON_AddStringToObject(ans,"strand",xs);
cJSON_AddNumberToObject(ans,"total_score",(int)in_site[i].score);
cJSON_AddNumberToObject(ans,"Sspe",(int)(req_r1*in_site[i].Sspe_nor));
cJSON_AddNumberToObject(ans,"Seff",(int)((1.0-req_r1)*in_site[i].Seff_nor));
cJSON_AddNumberToObject(ans,"count",in_site[i].count);
cJSON_AddItemToObject(ans,"offtarget",in_site[i].otj);
list.push_back(ans);
}
cJSON_AddItemToObject(root,"result",Create_array_of_anything(&(list[0]),list.size()));
printf("%s\n",NomoreSpace(argv[0]=cJSON_Print(root)));
free(argv[0]);
return 0;
}
示例6: process_NXT_event
int32_t process_NXT_event(struct NXThandler_info *mp,int32_t histmode,char *txid,int64_t type,int64_t subtype,struct NXT_AMhdr *AMhdr,char *sender,char *receiver,char *assetid,int64_t assetoshis,char *comment,cJSON *json)
{
int32_t i,count,highest_priority;
NXT_handler NXT_handler = 0;
void *handlerdata = 0;
struct NXT_protocol *p;
struct NXT_protocol_parms PARMS;
count = 0;
highest_priority = -1;
memset(&PARMS,0,sizeof(PARMS));
if ( Num_NXThandlers == 0 )
printf("WARNING: process_NXT_event Num_NXThandlers.%d\n",Num_NXThandlers);
for (i=0; i<Num_NXThandlers; i++)
{
if ( (p= NXThandlers[i]) != 0 )
{
if ( AMhdr != 0 || ((p->type < 0 || p->type == type) && (p->subtype < 0 || p->subtype == subtype)) )
{
if ( AMhdr != 0 )
{
if ( p->AMsigfilter != 0 && p->AMsigfilter != AMhdr->sig )
continue;
}
else if ( p->assetlist != 0 && assetid != 0 && listcmp(p->assetlist,assetid) != 0 )
continue;
if ( strcmp(sender,GENESISACCT) == 0 || strcmp(receiver,GENESISACCT) == 0 || //is_gateway_addr(sender) != 0 ||
(AMhdr == 0 || p->whitelist == 0 || listcmp(p->whitelist,sender) == 0) ||
(AMhdr != 0 && cmp_nxt64bits(sender,AMhdr->nxt64bits) == 0) )
{
if ( p->priority > highest_priority )
{
count = 1;
highest_priority = p->priority;
NXT_handler = p->NXT_handler;
handlerdata = p->handlerdata;
PARMS.argjson = json; PARMS.txid = txid; PARMS.sender = sender; PARMS.receiver = receiver;
PARMS.type = (int32_t)type; PARMS.subtype = (int32_t)subtype; PARMS.priority = highest_priority; PARMS.histflag = histmode;
if ( AMhdr != 0 )
{
PARMS.mode = NXTPROTOCOL_AMTXID;
PARMS.AMptr = AMhdr;
}
else
{
PARMS.mode = NXTPROTOCOL_TYPEMATCH;
PARMS.assetid = assetid;
PARMS.assetoshis = assetoshis;
PARMS.comment = comment;
}
//printf("call NXT_handler\n");
(*NXT_handler)(mp,&PARMS,handlerdata);
}
else if ( p->priority == highest_priority )
count++;
}
//printf("end iter\n");
}
}
}
if ( count > 1 )
printf("WARNING: (%s) claimed %d times, priority.%d\n",cJSON_Print(json),count,highest_priority); // this is bad, also leaks mem!
if ( 0 && highest_priority >= 0 && NXT_handler != 0 )
{
//printf("count.%d handler.%p NXThandler_info_handler.%p AMhdr.%p\n",count,NXT_handler,multigateway_handler,AMhdr);
PARMS.argjson = json; PARMS.txid = txid; PARMS.sender = sender; PARMS.receiver = receiver;
PARMS.type = (int32_t)type; PARMS.subtype = (int32_t)subtype; PARMS.priority = highest_priority; PARMS.histflag = histmode;
if ( AMhdr != 0 )
{
PARMS.mode = NXTPROTOCOL_AMTXID;
PARMS.AMptr = AMhdr;
}
else
{
PARMS.mode = NXTPROTOCOL_TYPEMATCH;
PARMS.assetid = assetid;
PARMS.assetoshis = assetoshis;
PARMS.comment = comment;
}
(*NXT_handler)(mp,&PARMS,handlerdata);///histmode,txid,AMhdr,sender,receiver,assetid,assetoshis,comment,json);
}
return(count != 0);
}
示例7: thread_ssid_msgio
void thread_ssid_msgio(void)
{
int ret = pthread_detach(pthread_self());
Debug("pthread_self():%lu, ret[%d]", pthread_self(), ret);
char mac[32] = {0};
char ssid[14] = {"FotileAP_"};
int retssid = 0;
while (1)
{
fd_set rset, wset;
FD_ZERO(&rset);
//FD_ZERO(&wset);
int i, maxfd, rcvfd;
maxfd = set_get_max(&ssid_fdset);
for(i=0;i<set_get_elem_num(&ssid_fdset);i++)
{
FD_SET(set_at(&ssid_fdset, i),&rset);
}
//FD_SET(socket_fd,&wset);
struct timeval tval;
tval.tv_sec = 0;
tval.tv_usec = 10000;
if(select(maxfd+1, &rset, NULL, NULL,&tval) > 0)
{
int i;
for(i=0;i<set_get_elem_num(&ssid_fdset);i++)
{
if(FD_ISSET(set_at(&ssid_fdset, i), &rset))
{
rcvfd = set_at(&ssid_fdset, i);
break;
}
}
char szRcv[MAX_MESSAGE_LEN] = {0};
int len = 0;
int lens =0;
unsigned char mac_arr[6] = {0}; //not use
if (retssid == 0){
retssid = get_eth0_mac(mac, mac_arr, 32);
ssid[9] = mac[12];
ssid[10] = mac[13];
ssid[11] = mac[15];
ssid[12] = mac[16];
Debug("first time get ssid!");
}else{
}
int ret = recv(rcvfd, szRcv, MAX_MESSAGE_LEN, 0);
//Info("ret[%d]%s", ret, szRcv);
if (ret > 0)
{
cJSON *root1 = cJSON_Parse(szRcv);
cJSON *root2 = cJSON_CreateObject();
if(strcmp(cJSON_GetObjectItem(root1,"type")->valuestring,"reqssid") == 0)
{
cJSON_AddItemToObject(root2, "type", cJSON_CreateString("reqssid"));
cJSON_AddNumberToObject(root2, "seq", cJSON_GetObjectItem(root1,"seq")->valueint);
if(retssid > 0)
{
cJSON_AddNumberToObject(root2, "respcode", 0);
cJSON_AddStringToObject(root2, "respmsg", ssid);
}
else
{
cJSON_AddNumberToObject(root2, "respcode", -1);
cJSON_AddStringToObject(root2,"respmsg", "error:get ssid failed!");
}
char *out = cJSON_Print(root2);
//Info("out[%s]", out);
lens = strlen(out);
send(rcvfd, out , lens ,0);
//Info("%s",rendered);
cJSON_Delete(root1);
cJSON_Delete(root2);
free(out);
}else{
Warn("param error!");
}
}
else
{
//Warn("[fd:%d]rcv error! close socket", rcvfd);
set_erase(rcvfd, &ssid_fdset);
close(rcvfd);
}
}
}
}
示例8: cJSON_Print
/**
* @brief Convert the JSON object to a string.
* @return A JSON string representation of the object.
*/
std::string JsonObject::toString() {
char *data = cJSON_Print(m_node);
std::string ret(data);
free(data);
return ret;
} // toString
示例9: memset
char *InstantDEX_parser(char *forwarder,char *sender,int32_t valid,char *origargstr,cJSON *origargjson)
{
static char *allorderbooks[] = { (char *)allorderbooks_func, "allorderbooks", "", 0 };
static char *orderbook[] = { (char *)orderbook_func, "orderbook", "", "baseid", "relid", "allfields", "oldest", "maxdepth", "base", "rel", "gui", "showall", "exchange", 0 };
static char *lottostats[] = { (char *)lottostats_func, "lottostats", "", "timestamp", 0 };
static char *cancelquote[] = { (char *)cancelquote_func, "cancelquote", "", "quoteid", 0 };
static char *openorders[] = { (char *)openorders_func, "openorders", "", 0 };
static char *placebid[] = { (char *)placebid_func, "placebid", "", "baseid", "relid", "volume", "price", "timestamp", "baseamount", "relamount", "gui", "automatch", "minperc", "duration", "exchange", "offerNXT", 0 };
static char *placeask[] = { (char *)placeask_func, "placeask", "", "baseid", "relid", "volume", "price", "timestamp", "baseamount", "relamount", ",gui", "automatch", "minperc", "duration", "exchange", "offerNXT", 0 };
static char *bid[] = { (char *)bid_func, "bid", "", "baseid", "relid", "volume", "price", "timestamp", "baseamount", "relamount", "gui", "automatch", "minperc", "duration", "exchange", "offerNXT", 0 };
static char *ask[] = { (char *)ask_func, "ask", "", "baseid", "relid", "volume", "price", "timestamp", "baseamount", "relamount", "gui", "automatch", "minperc", "duration", "exchange", "offerNXT", 0 };
static char *makeoffer3[] = { (char *)makeoffer3_func, "makeoffer3", "", "baseid", "relid", "quoteid", "perc", "deprecated", "baseiQ", "reliQ", "askoffer", "price", "volume", "exchange", "baseamount", "relamount", "offerNXT", "minperc", "jumpasset", 0 };
static char *respondtx[] = { (char *)respondtx_func, "respondtx", "", "cmd", "assetid", "quantityQNT", "priceNQT", "triggerhash", "quoteid", "sig", "data", "minperc", "offerNXT", "otherassetid", "otherqty", 0 };
static char *jumptrades[] = { (char *)jumptrades_func, "jumptrades", "", 0 };
static char *tradehistory[] = { (char *)tradehistory_func, "tradehistory", "", "timestamp", 0 };
static char **commands[] = { allorderbooks, lottostats, cancelquote, respondtx, jumptrades, tradehistory, openorders, makeoffer3, placebid, bid, placeask, ask, orderbook };
int32_t i,j,localaccess = 0;
cJSON *argjson,*obj,*nxtobj,*secretobj,*objs[64];
char NXTaddr[MAX_JSON_FIELD],NXTACCTSECRET[MAX_JSON_FIELD],command[MAX_JSON_FIELD],offerNXT[MAX_JSON_FIELD],**cmdinfo,*argstr,*retstr=0;
memset(objs,0,sizeof(objs));
command[0] = 0;
valid = 1;
memset(NXTaddr,0,sizeof(NXTaddr));
if ( is_cJSON_Array(origargjson) != 0 )
{
argjson = cJSON_GetArrayItem(origargjson,0);
argstr = cJSON_Print(argjson), _stripwhite(argstr,' ');
} else argjson = origargjson, argstr = origargstr;
NXTACCTSECRET[0] = 0;
if ( argjson != 0 )
{
if ( (obj= cJSON_GetObjectItem(argjson,"requestType")) == 0 )
obj = cJSON_GetObjectItem(argjson,"method");
nxtobj = cJSON_GetObjectItem(argjson,"NXT");
secretobj = cJSON_GetObjectItem(argjson,"secret");
copy_cJSON(NXTaddr,nxtobj);
copy_cJSON(offerNXT,cJSON_GetObjectItem(argjson,"offerNXT"));
if ( NXTaddr[0] == 0 && offerNXT[0] == 0 )
{
strcpy(NXTaddr,SUPERNET.NXTADDR);
strcpy(offerNXT,SUPERNET.NXTADDR);
strcpy(sender,SUPERNET.NXTADDR);
ensure_jsonitem(argjson,"NXT",NXTaddr);
ensure_jsonitem(argjson,"offerNXT",offerNXT);
}
else if ( offerNXT[0] == 0 && strcmp(NXTaddr,SUPERNET.NXTADDR) == 0 )
{
strcpy(offerNXT,SUPERNET.NXTADDR);
strcpy(sender,SUPERNET.NXTADDR);
ensure_jsonitem(argjson,"offerNXT",offerNXT);
}
else strcpy(sender,offerNXT);
if ( strcmp(offerNXT,SUPERNET.NXTADDR) == 0 )
localaccess = 1;
if ( localaccess != 0 && strcmp(NXTaddr,SUPERNET.NXTADDR) != 0 )
{
strcpy(NXTaddr,SUPERNET.NXTADDR);
ensure_jsonitem(argjson,"NXT",NXTaddr);
//printf("subsititute NXT.%s\n",NXTaddr);
}
//printf("localaccess.%d myaddr.(%s) NXT.(%s) offerNXT.(%s)\n",localaccess,SUPERNET.NXTADDR,NXTaddr,offerNXT);
copy_cJSON(command,obj);
copy_cJSON(NXTACCTSECRET,secretobj);
if ( NXTACCTSECRET[0] == 0 )
{
if ( localaccess != 0 || strcmp(command,"findnode") != 0 )
{
safecopy(NXTACCTSECRET,SUPERNET.NXTACCTSECRET,sizeof(NXTACCTSECRET));
strcpy(NXTaddr,SUPERNET.NXTADDR);
}
}
//printf("(%s) argstr.(%s) command.(%s) NXT.(%s) valid.%d\n",cJSON_Print(argjson),argstr,command,NXTaddr,valid);
//fprintf(stderr,"SuperNET_json_commands sender.(%s) valid.%d | size.%d | command.(%s) orig.(%s)\n",sender,valid,(int32_t)(sizeof(commands)/sizeof(*commands)),command,origargstr);
for (i=0; i<(int32_t)(sizeof(commands)/sizeof(*commands)); i++)
{
cmdinfo = commands[i];
if ( strcmp(cmdinfo[1],command) == 0 )
{
//printf("needvalid.(%c) valid.%d %d of %d: cmd.(%s) vs command.(%s)\n",cmdinfo[2][0],valid,i,(int32_t)(sizeof(commands)/sizeof(*commands)),cmdinfo[1],command);
if ( cmdinfo[2][0] != 0 && valid <= 0 )
return(0);
for (j=3; cmdinfo[j]!=0&&j<3+(int32_t)(sizeof(objs)/sizeof(*objs)); j++)
objs[j-3] = cJSON_GetObjectItem(argjson,cmdinfo[j]);
retstr = (*(json_handler)cmdinfo[0])(localaccess,valid,sender,objs,j-3,argstr);
break;
}
}
} else printf("not JSON to parse?\n");
if ( argstr != origargstr )
free(argstr);
return(retstr);
}
示例10: while
void *ChangeLightRepresentation (void *param)
{
(void)param;
OCStackResult result = OC_STACK_ERROR;
uint8_t j = 0;
uint8_t numNotifies = (SAMPLE_MAX_NUM_OBSERVATIONS)/2;
OCObservationId obsNotify[numNotifies];
while (!gQuitFlag)
{
sleep(10);
Light.power += 5;
if (gLightUnderObservation)
{
OC_LOG_V(INFO, TAG, " =====> Notifying stack of new power level %d\n", Light.power);
if (gObserveNotifyType == 1)
{
// Notify list of observers. Alternate observers on the list will be notified.
j = 0;
for (uint8_t i = 0; i < SAMPLE_MAX_NUM_OBSERVATIONS; (i=i+2))
{
if (interestedObservers[i].valid == true)
{
obsNotify[j] = interestedObservers[i].observationId;
j++;
}
}
cJSON *json = cJSON_CreateObject();
cJSON *format;
cJSON_AddStringToObject(json,"href",gResourceUri);
cJSON_AddItemToObject(json, "rep", format=cJSON_CreateObject());
cJSON_AddStringToObject(format, "state", (char *) (Light.state ? "on":"off"));
cJSON_AddNumberToObject(format, "power", Light.power);
char * obsResp = cJSON_Print(json);
cJSON_Delete(json);
result = OCNotifyListOfObservers (Light.handle, obsNotify, j,
(unsigned char *)obsResp, OC_NA_QOS);
free(obsResp);
}
else if (gObserveNotifyType == 0)
{
// Notifying all observers
result = OCNotifyAllObservers (Light.handle, OC_NA_QOS);
if (OC_STACK_NO_OBSERVERS == result)
{
OC_LOG (INFO, TAG,
"=======> No more observers exist, stop sending observations");
gLightUnderObservation = 0;
}
}
else
{
OC_LOG (ERROR, TAG, "Incorrect notification type selected");
}
}
#ifdef WITH_PRESENCE
if(stopPresenceCount > 0)
{
OC_LOG_V(INFO, TAG, "================ presence count %d", stopPresenceCount);
}
if(!stopPresenceCount--)
{
OC_LOG(INFO, TAG, "================ stopping presence");
OCStopPresence();
}
#endif
}
return NULL;
}
示例11: calloc
struct coin777 *coin777_create(char *coinstr,cJSON *argjson)
{
char *serverport,*path=0,*conf=0; struct destbuf tmp;
struct coin777 *coin = calloc(1,sizeof(*coin));
safecopy(coin->name,coinstr,sizeof(coin->name));
if ( argjson == 0 )
{
coin->minconfirms = (strcmp("BTC",coinstr) == 0) ? 3 : 10;
coin->estblocktime = (strcmp("BTC",coinstr) == 0) ? 600 : 120;
}
else
{
coin->minoutput = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"minoutput"));
coin->minconfirms = get_API_int(cJSON_GetObjectItem(argjson,"minconfirms"),(strcmp("BTC",coinstr) == 0) ? 3 : 10);
coin->estblocktime = get_API_int(cJSON_GetObjectItem(argjson,"estblocktime"),(strcmp("BTC",coinstr) == 0) ? 600 : 120);
coin->jsonstr = cJSON_Print(argjson);
coin->argjson = cJSON_Duplicate(argjson,1);
if ( (serverport= cJSON_str(cJSON_GetObjectItem(argjson,"rpc"))) != 0 )
safecopy(coin->serverport,serverport,sizeof(coin->serverport));
path = cJSON_str(cJSON_GetObjectItem(argjson,"path"));
conf = cJSON_str(cJSON_GetObjectItem(argjson,"conf"));
copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"assetid")), safecopy(coin->mgw.assetidstr,tmp.buf,sizeof(coin->mgw.assetidstr));
coin->mgw.assetidbits = calc_nxt64bits(coin->mgw.assetidstr);
copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"issuer")), safecopy(coin->mgw.issuer,tmp.buf,sizeof(coin->mgw.issuer));;
coin->mgw.issuerbits = conv_acctstr(coin->mgw.issuer);
printf(">>>>>>>>>>>> a issuer.%s %llu assetid.%llu minoutput.%llu\n",coin->mgw.issuer,(long long)coin->mgw.issuerbits,(long long)coin->mgw.assetidbits,(long long)coin->minoutput);
//uint32_t set_assetname(uint64_t *multp,char *name,uint64_t assetbits);
_set_assetname(&coin->mgw.ap_mult,coin->mgw.assetname,0,coin->mgw.assetidbits);
printf("assetname.(%s) mult.%llu\n",coin->mgw.assetname,coin->mgw.ap_mult);
strcpy(coin->mgw.coinstr,coinstr);
if ( (coin->mgw.special= cJSON_GetObjectItem(argjson,"special")) == 0 )
coin->mgw.special = cJSON_GetObjectItem(COINS.argjson,"special");
if ( coin->mgw.special != 0 )
coin->mgw.special = NXT_convjson(coin->mgw.special);
printf("CONVERTED.(%s)\n",cJSON_Print(coin->mgw.special));
coin->mgw.limbo = cJSON_GetObjectItem(argjson,"limbo");
coin->mgw.dust = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"dust"));
coin->mgw.txfee = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"txfee_satoshis"));
if ( coin->mgw.txfee == 0 )
coin->mgw.txfee = (uint64_t)(SATOSHIDEN * get_API_float(cJSON_GetObjectItem(argjson,"txfee")));
if ( coin->mgw.txfee == 0 )
coin->mgw.txfee = 10000;
coin->mgw.NXTfee_equiv = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"NXTfee_equiv_satoshis"));
if ( coin->mgw.NXTfee_equiv == 0 )
coin->mgw.NXTfee_equiv = (uint64_t)(SATOSHIDEN * get_API_float(cJSON_GetObjectItem(argjson,"NXTfee_equiv")));
copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"opreturnmarker")), safecopy(coin->mgw.opreturnmarker,tmp.buf,sizeof(coin->mgw.opreturnmarker));
printf("OPRETURN.(%s)\n",coin->mgw.opreturnmarker);
copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"marker2")), safecopy(coin->mgw.marker2,tmp.buf,sizeof(coin->mgw.marker2));
coin->mgw.redeemheight = get_API_int(cJSON_GetObjectItem(argjson,"redeemheight"),430000);
coin->mgw.use_addmultisig = get_API_int(cJSON_GetObjectItem(argjson,"useaddmultisig"),(strcmp("BTC",coinstr) != 0));
coin->mgw.do_opreturn = get_API_int(cJSON_GetObjectItem(argjson,"do_opreturn"),(strcmp("BTC",coinstr) == 0));
coin->mgw.oldtx_format = get_API_int(cJSON_GetObjectItem(argjson,"oldtx_format"),(strcmp("BTC",coinstr) == 0));
coin->mgw.firstunspentind = get_API_int(cJSON_GetObjectItem(argjson,"firstunspent"),(strcmp("BTCD",coinstr) == 0) ? 2500000 : 0);
if ( (coin->mgw.NXTconvrate = get_API_float(cJSON_GetObjectItem(argjson,"NXTconvrate"))) == 0 )
{
if ( coin->mgw.NXTfee_equiv != 0 && coin->mgw.txfee != 0 )
coin->mgw.NXTconvrate = ((double)coin->mgw.NXTfee_equiv / coin->mgw.txfee);
}
copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"marker")), safecopy(coin->mgw.marker,tmp.buf,sizeof(coin->mgw.marker));
printf("OPRETURN.(%s)\n",coin->mgw.opreturnmarker);
}
printf("coin777_create %s: (%s) %llu mult.%llu NXTconvrate %.8f minconfirms.%d issuer.(%s) %llu opreturn.%d oldformat.%d\n",coin->mgw.coinstr,coin->mgw.assetidstr,(long long)coin->mgw.assetidbits,(long long)coin->mgw.ap_mult,coin->mgw.NXTconvrate,coin->minconfirms,coin->mgw.issuer,(long long)coin->mgw.issuerbits,coin->mgw.do_opreturn,coin->mgw.oldtx_format);
extract_userpass(coin->serverport,coin->userpass,coinstr,SUPERNET.userhome,path,conf);
printf("COIN.%s serverport.(%s) userpass.(%s)\n",coin->name,coin->serverport,coin->userpass);
COINS.LIST = realloc(COINS.LIST,(COINS.num+1) * sizeof(*coin));
COINS.LIST[COINS.num] = coin, COINS.num++;
//ensure_packedptrs(coin);
return(coin);
}
示例12: http_server_start
void http_server_start(http_server_t *http_server) {
WSADATA wsa;
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) {
printf("Failed. Error Code : %d", WSAGetLastError());
exit(1);
}
SOCKET s;
if ((s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
printf("Could not create socket : %d" , WSAGetLastError());
exit(1);
}
struct sockaddr_in server;
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons(8888);
if (bind(s, (struct sockaddr *)&server, sizeof(server)) == SOCKET_ERROR) {
printf("Bind failed with error code : %d" , WSAGetLastError());
exit(EXIT_FAILURE);
}
listen(s, 3);
int c = sizeof(struct sockaddr_in);
SOCKET newSocket;
struct sockaddr_in client;
while ((newSocket = accept(s, (struct sockaddr *)&client, &c)) != INVALID_SOCKET) {
char message[500000];
char request[500000];
int recvSize = recv(newSocket, request, sizeof(request), 0);
request[recvSize] = '\0';
http_server_request_method_t http_server_request_method;
char url[128];
char requestMessage[500000];
parseHttpRequest(request, &http_server_request_method, url, requestMessage);
printf("%s\n", url);
if (strcmp(url, "/directors") == 0) {
cJSON *json = cJSON_CreateArray();
for (size_t i = 0; i < directors_size(http_server->directors); ++i) {
director_t *director = directors_get(http_server->directors, i);
cJSON *jsonDir = cJSON_CreateObject();
cJSON_AddStringToObject(jsonDir, "name", director->name);
cJSON_AddStringToObject(jsonDir, "surname", director->surname);
char birthdateStr[128];
sprintf(birthdateStr, "%i-%i-%i", director->birth_date.tm_year, director->birth_date.tm_mday, director->birth_date.tm_mon);
cJSON_AddStringToObject(jsonDir, "birthdate", birthdateStr);
cJSON *jsonStartup = cJSON_CreateObject();
cJSON_AddStringToObject(jsonStartup, "name", director->startup.name);
cJSON_AddStringToObject(jsonStartup, "country", director->startup.country);
cJSON_AddItemToObject(jsonDir, "startup", jsonStartup);
cJSON_AddNumberToObject(jsonDir, "salary", director->salary);
cJSON_AddNumberToObject(jsonDir, "rating", director->rating);
cJSON_AddItemToArray(json, jsonDir);
}
char *jsonStr = cJSON_Print(json);
makeHttpResponse(jsonStr, message);
cJSON_Delete(json);
send(newSocket, message, strlen(message), 0);
} else if (strncmp(url, "/directors/", strlen("/directors/")) == 0) {
size_t directorIndex = atoi(strstr(url + 1, "/") + 1);
director_t *director = directors_get(http_server->directors, directorIndex);
if (http_server_request_method == http_server_request_method_delete) {
directors_remove(http_server->directors, directorIndex);
makeHttpResponse("", message);
send(newSocket, message, strlen(message), 0);
} else if (http_server_request_method == http_server_request_method_post) {
cJSON *json = cJSON_Parse(requestMessage);
cJSON *subItem = json->child;
while (subItem) {
if ((subItem->type == cJSON_String) && (strcmp(subItem->string, "name") == 0))
director_update(director, subItem->valuestring, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
if ((subItem->type == cJSON_String) && (strcmp(subItem->string, "surname") == 0))
director_update(director, NULL, subItem->valuestring, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
if ((subItem->type == cJSON_String) && (strcmp(subItem->string, "birthdate") == 0)) {
int year;
int day;
int month;
sscanf(subItem->valuestring, "%i-%i-%i", &year, &day, &month);
director_update(director, NULL, NULL, &year, &day, &month, NULL, NULL, NULL, NULL);
}
if ((subItem->type == cJSON_Object) && (strcmp(subItem->string, "startup") == 0)) {
cJSON *subJtem = subItem->child;
while (subJtem) {
if ((subJtem->type == cJSON_String) && (strcmp(subJtem->string, "name") == 0))
director_update(director, NULL, NULL, NULL, NULL, NULL, subJtem->valuestring, NULL, NULL, NULL);
if ((subJtem->type == cJSON_String) && (strcmp(subJtem->string, "country") == 0))
director_update(director, NULL, NULL, NULL, NULL, NULL, NULL, subJtem->valuestring, NULL, NULL);
//.........这里部分代码省略.........
示例13: write_bb_black_respond
int write_bb_black_respond(char* fileName,char *rev)
{
long len;
char sw[15];
char uid[60];
char ip_s[20];
char port_s[10];
char port_l[10];
char* pContent;
//First read the old config
FILE* fp = fopen(fileName, "rb+");
if(fp==NULL)
{
DEBUG_printf("open error\n");
exit(1);
}
fseek(fp,0,SEEK_END);
len=ftell(fp);
if(0 == len)
{
return 0;
}
fseek(fp,0,SEEK_SET);
pContent = (char*) malloc(sizeof(char)*len+100);
fread(pContent,1,len,fp);
fclose(fp);
cJSON *jsonroot = cJSON_Parse(pContent); //json
strcpy(sw,cJSON_GetObjectItem(jsonroot,"api-switch")->valuestring);
strcpy(uid,cJSON_GetObjectItem(jsonroot,"api-uid")->valuestring);
strcpy(ip_s,cJSON_GetObjectItem(jsonroot,"ip_server")->valuestring);
strcpy(port_s,cJSON_GetObjectItem(jsonroot,"port_server")->valuestring);
strcpy(port_l,cJSON_GetObjectItem(jsonroot,"port_local")->valuestring);
cJSON_Delete(jsonroot);
//Write configuration, update
fp = fopen(fileName, "w+");
if(fp==NULL)
{
DEBUG_printf("open error\n");
}
cJSON *root;
char *out;
root=cJSON_CreateObject();
cJSON_AddStringToObject(root, "api-switch" , sw);
cJSON_AddStringToObject(root, "api-uid", uid);
cJSON_AddStringToObject(root, "auth", rev);
cJSON_AddStringToObject(root, "ip_server" ,ip_s);
cJSON_AddStringToObject(root, "port_server", port_s);
cJSON_AddStringToObject(root, "port_local", port_l);
out=cJSON_Print(root);
fprintf(fp,"%s",out);
fclose(fp);
cJSON_Delete(root);
free(out);
out = NULL;
root = NULL;
free(pContent);
return 1;
}
示例14: _load_config
static int _load_config()
{
cJSON *config = NULL;
cJSON *data = NULL;
cJSON *elm = NULL;
cJSON *startTime = NULL;
cJSON *command = NULL;
int cnt = 0;
int index = 0;
int hour,min,second;
int ret = OK;
if (NULL != task)
{
free(task);
task = NULL;
}
config = _get_JSON_from_file(CONFIG_FILE_PATH);
if (NULL == config)
{
LOG_ERR("get config errer");
ret = ERROR;
goto leave;
}
/* attendtion free */
PRINTF("data = %s", cJSON_Print(config));
data = cJSON_GetObjectItem(config, "data");
cnt = cJSON_GetArraySize(data);
task = (TASK_ENTRY *)malloc(sizeof(TASK_ENTRY)*cnt);
if (NULL == task)
{
LOG_ERR("malloc error!");
ret = ERROR;
goto leave;
}
for(index = 0; index < cnt; index++)
{
elm = cJSON_GetArrayItem(data, index);
startTime = cJSON_GetObjectItem(elm, "startTime");
if( startTime != NULL && startTime->type == cJSON_String )
{
sscanf(startTime->valuestring, "%d:%d:%d", &hour, &min, &second);
task[index].startTime = hour * 60 * 60 + min * 60 + second;
}
command = cJSON_GetObjectItem(elm, "command");
if( command != NULL && command->type == cJSON_String )
{
if(strlen(command->valuestring) < MAX_COMMAND_LENGTH)
{
strcpy(task[index].command, command->valuestring);
}
else
{
LOG_ERR("command %s size %d error!", command->valuestring, strlen(command->valuestring));
_log_to_file(ERROR_LOG_FILE_PATH, "command %s size %d error!", command->valuestring, strlen(command->valuestring));
}
}
}
_quick_sort(0, cnt - 1, task);
task_index = 0;
task_MAX = cnt;
#ifdef LOG_DEBUG
for(index = 0; index < cnt; index++)
{
PRINTF("%02d:%02d:%02d %s", task[index].startTime/3600, (task[index].startTime % 3600)/60, task[index].startTime%60, task[index].command);
}
#endif
leave:
if(config)
cJSON_Delete(config);
return ret;
}
示例15: if
char *jprint(cJSON *json,int32_t freeflag) { char *str; if ( json == 0 ) return(clonestr("{}")); str = cJSON_Print(json), _stripwhite(str,' '); if ( freeflag != 0 ) free_json(json); return(str); }