|
@ -49,7 +49,7 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 |
|
|
|
|
|
|
|
|
cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen) |
|
|
cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen) |
|
|
{ |
|
|
{ |
|
|
cJSON *retjson=0,*msgjson; struct basilisk_message *msg; char *ptr = 0,strbuf[32768]; |
|
|
cJSON *msgjson; struct basilisk_message *msg; char *ptr = 0,strbuf[32768]; |
|
|
portable_mutex_lock(&myinfo->messagemutex); |
|
|
portable_mutex_lock(&myinfo->messagemutex); |
|
|
HASH_FIND(hh,myinfo->messagetable,key,keylen,msg); |
|
|
HASH_FIND(hh,myinfo->messagetable,key,keylen,msg); |
|
|
if ( msg != 0 ) |
|
|
if ( msg != 0 ) |
|
@ -57,11 +57,10 @@ cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int |
|
|
msgjson = cJSON_CreateObject(); |
|
|
msgjson = cJSON_CreateObject(); |
|
|
if ( basilisk_addhexstr(&ptr,msgjson,strbuf,sizeof(strbuf),msg->data,msg->datalen) != 0 ) |
|
|
if ( basilisk_addhexstr(&ptr,msgjson,strbuf,sizeof(strbuf),msg->data,msg->datalen) != 0 ) |
|
|
{ |
|
|
{ |
|
|
retjson = cJSON_CreateObject(); |
|
|
//retjson = cJSON_CreateObject();
|
|
|
jadd(retjson,"message",msgjson); |
|
|
jaddnum(msgjson,"expiration",msg->expiration); |
|
|
jaddnum(retjson,"expiration",msg->expiration); |
|
|
jaddnum(msgjson,"duration",msg->duration); |
|
|
jaddnum(retjson,"duration",msg->duration); |
|
|
//jadd(retjson,"message",msgjson);
|
|
|
jaddstr(retjson,"result","success"); |
|
|
|
|
|
printf("havemessage len.%d\n",msg->datalen); |
|
|
printf("havemessage len.%d\n",msg->datalen); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
@ -69,10 +68,11 @@ cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int |
|
|
//jaddstr(retjson,"error","couldnt add message");
|
|
|
//jaddstr(retjson,"error","couldnt add message");
|
|
|
printf("couldnt add message\n"); |
|
|
printf("couldnt add message\n"); |
|
|
free_json(msgjson); |
|
|
free_json(msgjson); |
|
|
|
|
|
msgjson = 0; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
portable_mutex_unlock(&myinfo->messagemutex); |
|
|
portable_mutex_unlock(&myinfo->messagemutex); |
|
|
return(retjson); |
|
|
return(msgjson); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// respond to incoming OUT, MSG
|
|
|
// respond to incoming OUT, MSG
|
|
@ -163,10 +163,15 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha |
|
|
HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr) |
|
|
HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr) |
|
|
{ |
|
|
{ |
|
|
uint32_t msgid,width,channel; |
|
|
uint32_t msgid,width,channel; |
|
|
|
|
|
if ( (msgid= juint(vals,"msgid")) == 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
msgid = (uint32_t)time(NULL); |
|
|
|
|
|
jdelete(vals,"msgid"); |
|
|
|
|
|
jaddnum(vals,"msgid",msgid); |
|
|
|
|
|
} |
|
|
if ( RELAYID >= 0 ) |
|
|
if ( RELAYID >= 0 ) |
|
|
{ |
|
|
{ |
|
|
channel = juint(vals,"channel"); |
|
|
channel = juint(vals,"channel"); |
|
|
msgid = juint(vals,"msgid"); |
|
|
|
|
|
width = juint(vals,"width"); |
|
|
width = juint(vals,"width"); |
|
|
return(basilisk_iterate_MSG(myinfo,channel,msgid,hash,myinfo->myaddr.persistent,width)); |
|
|
return(basilisk_iterate_MSG(myinfo,channel,msgid,hash,myinfo->myaddr.persistent,width)); |
|
|
} else return(basilisk_standardservice("MSG",myinfo,0,myinfo->myaddr.persistent,vals,hexstr,1)); |
|
|
} else return(basilisk_standardservice("MSG",myinfo,0,myinfo->myaddr.persistent,vals,hexstr,1)); |
|
|