|
@ -15,13 +15,18 @@ |
|
|
|
|
|
|
|
|
// included from basilisk.c
|
|
|
// included from basilisk.c
|
|
|
|
|
|
|
|
|
char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen,int32_t sendping) |
|
|
char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen,int32_t sendping,uint32_t duration) |
|
|
{ |
|
|
{ |
|
|
struct basilisk_message *msg; |
|
|
struct basilisk_message *msg; |
|
|
if ( keylen == sizeof(bits256)+sizeof(uint32_t)*2 ) |
|
|
if ( keylen == BASILISK_KEYSIZE ) |
|
|
{ |
|
|
{ |
|
|
msg = calloc(1,sizeof(*msg) + datalen); |
|
|
msg = calloc(1,sizeof(*msg) + datalen); |
|
|
msg->expiration = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME*2; |
|
|
if ( duration == 0 ) |
|
|
|
|
|
duration = BASILISK_MSGDURATION; |
|
|
|
|
|
else if ( duration > INSTANTDEX_LOCKTIME*2 ) |
|
|
|
|
|
duration = INSTANTDEX_LOCKTIME*2; |
|
|
|
|
|
msg->duration = duration; |
|
|
|
|
|
msg->expiration = (uint32_t)time(NULL) + duration; |
|
|
msg->keylen = keylen; |
|
|
msg->keylen = keylen; |
|
|
memcpy(msg->key,key,keylen); |
|
|
memcpy(msg->key,key,keylen); |
|
|
msg->datalen = datalen; |
|
|
msg->datalen = datalen; |
|
@ -37,69 +42,7 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 |
|
|
} else return(0); |
|
|
} else return(0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int32_t basilisk_ping_processMSG(struct supernet_info *myinfo,uint32_t senderipbits,uint8_t *data,int32_t datalen) |
|
|
cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen) |
|
|
{ |
|
|
|
|
|
int32_t i,msglen,len=0; uint8_t num,keylen,*msg,*key; |
|
|
|
|
|
if ( (num= data[len++]) > 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
printf("processMSG num.%d datalen.%d\n",num,datalen); |
|
|
|
|
|
for (i=0; i<num; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
keylen = data[len++]; |
|
|
|
|
|
if ( keylen != sizeof(bits256)+sizeof(uint32_t)*2 ) |
|
|
|
|
|
{ |
|
|
|
|
|
printf("invalid keylen.%d != %d\n",keylen,(int32_t)(sizeof(bits256)+sizeof(uint32_t)*2)); |
|
|
|
|
|
return(0); |
|
|
|
|
|
} |
|
|
|
|
|
key = &data[len], len += keylen; |
|
|
|
|
|
if ( len+sizeof(msglen) > datalen ) |
|
|
|
|
|
{ |
|
|
|
|
|
printf("processMSG overflow len.%d msglen.%d %d > %d\n",len,msglen,(int32_t)(len+sizeof(msglen)),datalen); |
|
|
|
|
|
return(0); |
|
|
|
|
|
} |
|
|
|
|
|
len += iguana_rwnum(0,&data[len],sizeof(msglen),&msglen); |
|
|
|
|
|
msg = &data[len], len += msglen; |
|
|
|
|
|
if ( msglen <= 0 || len > datalen ) |
|
|
|
|
|
{ |
|
|
|
|
|
printf("illegal msglen.%d or len.%d > %d\n",msglen,len,datalen); |
|
|
|
|
|
return(0); |
|
|
|
|
|
} |
|
|
|
|
|
printf("i.%d: keylen.%d msglen.%d\n",i,keylen,msglen); |
|
|
|
|
|
basilisk_respond_addmessage(myinfo,key,keylen,msg,msglen,0); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return(len); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int32_t basilisk_ping_genMSG(struct supernet_info *myinfo,uint8_t *data,int32_t maxlen) |
|
|
|
|
|
{ |
|
|
|
|
|
struct basilisk_message *msg; int32_t datalen = 0; |
|
|
|
|
|
if ( maxlen > sizeof(msg->key) && (msg= queue_dequeue(&myinfo->msgQ,0)) != 0 ) // oneshot ping
|
|
|
|
|
|
{ |
|
|
|
|
|
data[datalen++] = 1; |
|
|
|
|
|
data[datalen++] = msg->keylen; |
|
|
|
|
|
memcpy(&data[datalen],msg->key,msg->keylen), datalen += msg->keylen; |
|
|
|
|
|
datalen += iguana_rwnum(1,&data[datalen],sizeof(msg->datalen),&msg->datalen); |
|
|
|
|
|
if ( maxlen > datalen+msg->datalen ) |
|
|
|
|
|
{ |
|
|
|
|
|
printf("SEND keylen.%d msglen.%d\n",msg->keylen,msg->datalen); |
|
|
|
|
|
memcpy(&data[datalen],msg->data,msg->datalen), datalen += msg->datalen; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
printf("basilisk_ping_genMSG message doesnt fit %d vs %d\n",maxlen,datalen+msg->datalen); |
|
|
|
|
|
datalen = 0; |
|
|
|
|
|
} |
|
|
|
|
|
//printf("\n-> ");
|
|
|
|
|
|
//int32_t i;
|
|
|
|
|
|
//for (i=0; i<datalen; i++)
|
|
|
|
|
|
// printf("%02x",data[i]);
|
|
|
|
|
|
//printf(" <- genMSG\n");
|
|
|
|
|
|
} else data[datalen++] = 0; |
|
|
|
|
|
return(datalen); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
char *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen) |
|
|
|
|
|
{ |
|
|
{ |
|
|
cJSON *retjson,*msgjson; struct basilisk_message *msg; char *ptr = 0,strbuf[32768]; |
|
|
cJSON *retjson,*msgjson; struct basilisk_message *msg; char *ptr = 0,strbuf[32768]; |
|
|
retjson = cJSON_CreateObject(); |
|
|
retjson = cJSON_CreateObject(); |
|
@ -111,64 +54,90 @@ char *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int3 |
|
|
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 ) |
|
|
{ |
|
|
{ |
|
|
jadd(retjson,"message",msgjson); |
|
|
jadd(retjson,"message",msgjson); |
|
|
|
|
|
jaddnum(retjson,"expiration",msg->expiration); |
|
|
|
|
|
jaddnum(retjson,"duration",msg->duration); |
|
|
jaddstr(retjson,"result","success"); |
|
|
jaddstr(retjson,"result","success"); |
|
|
printf("havemessage len.%d\n",msg->datalen); |
|
|
printf("havemessage len.%d\n",msg->datalen); |
|
|
} else jaddstr(retjson,"error","couldnt add message"); |
|
|
} else jaddstr(retjson,"error","couldnt add message"); |
|
|
} else jaddstr(retjson,"error","no message"); |
|
|
} else jaddstr(retjson,"error","no message"); |
|
|
portable_mutex_unlock(&myinfo->messagemutex); |
|
|
portable_mutex_unlock(&myinfo->messagemutex); |
|
|
return(jprint(retjson,1)); |
|
|
return(retjson); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// respond to incoming OUT, MSG
|
|
|
// respond to incoming OUT, MSG
|
|
|
|
|
|
|
|
|
int32_t basilisk_messagekey(uint8_t *key,bits256 hash,cJSON *valsobj) |
|
|
int32_t basilisk_messagekey(uint8_t *key,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash) |
|
|
{ |
|
|
{ |
|
|
uint32_t channel,msgid; int32_t keylen = 0; |
|
|
int32_t keylen = 0; |
|
|
channel = juint(valsobj,"channel"); |
|
|
|
|
|
msgid = juint(valsobj,"msgid"); |
|
|
|
|
|
keylen += iguana_rwbignum(1,&key[keylen],sizeof(hash),hash.bytes); |
|
|
|
|
|
keylen += iguana_rwnum(1,&key[keylen],sizeof(uint32_t),&channel); |
|
|
keylen += iguana_rwnum(1,&key[keylen],sizeof(uint32_t),&channel); |
|
|
keylen += iguana_rwnum(1,&key[keylen],sizeof(uint32_t),&msgid); |
|
|
keylen += iguana_rwnum(1,&key[keylen],sizeof(uint32_t),&msgid); |
|
|
|
|
|
keylen += iguana_rwbignum(1,&key[keylen],sizeof(srchash),srchash.bytes); |
|
|
|
|
|
keylen += iguana_rwbignum(1,&key[keylen],sizeof(desthash),desthash.bytes); |
|
|
return(keylen); |
|
|
return(keylen); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
uint32_t basilisk_msgid(struct supernet_info *myinfo,uint32_t channel,bits256 hash,uint8_t *data,int32_t datalen) |
|
|
char *basilisk_respond_OUT(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) |
|
|
{ |
|
|
{ |
|
|
bits256 msghash; int32_t msgid = 0; |
|
|
int32_t keylen,duration; uint8_t key[BASILISK_KEYSIZE]; bits256 senderhash; |
|
|
vcalc_sha256(0,msghash.bytes,data,datalen); |
|
|
senderhash = jbits256(valsobj,"sender"); |
|
|
if ( bits256_nonz(hash) == 0 ) // broadcast
|
|
|
duration = juint(valsobj,"duration"); |
|
|
{ |
|
|
keylen = basilisk_messagekey(key,juint(valsobj,"channel"),juint(valsobj,"msgid"),senderhash,hash); |
|
|
// find msghash and return its ind, or allocate new one
|
|
|
if( bits256_nonz(senderhash) == 0 && bits256_nonz(hash) == 0 && duration > BASILISK_MSGDURATION ) |
|
|
} |
|
|
duration = BASILISK_MSGDURATION; |
|
|
else |
|
|
printf("OUT keylen.%d datalen.%d\n",keylen,datalen); |
|
|
{ |
|
|
//char str[65]; printf("add message.[%d] channel.%u msgid.%x %s\n",datalen,juint(valsobj,"channel"),juint(valsobj,"msgid"),bits256_str(str,hash));
|
|
|
// check against most recent small n for hash, return ind or allocate new one
|
|
|
return(basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration)); |
|
|
} |
|
|
|
|
|
return(msgid); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
char *basilisk_respond_OUT(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) |
|
|
char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash,int32_t width) |
|
|
{ |
|
|
{ |
|
|
int32_t keylen; uint8_t key[64]; char *origcmd; uint32_t channel,msgid; |
|
|
uint8_t key[BASILISK_KEYSIZE]; int32_t i,keylen; cJSON *item,*array; bits256 zero; |
|
|
if ( (origcmd= jstr(valsobj,"origcmd")) != 0 && strlen(origcmd) == 3 ) |
|
|
memset(zero.bytes,0,sizeof(zero)); |
|
|
|
|
|
array = cJSON_CreateArray(); |
|
|
|
|
|
if ( width > 3600 ) |
|
|
|
|
|
width = 3600; |
|
|
|
|
|
else if ( width < 1 ) |
|
|
|
|
|
width = 1; |
|
|
|
|
|
for (i=0; i<width; i++) |
|
|
{ |
|
|
{ |
|
|
channel = origcmd[0] + ((uint32_t)origcmd[1] << 8) + ((uint32_t)origcmd[2] << 16); |
|
|
keylen = basilisk_messagekey(key,channel,msgid,srchash,desthash); |
|
|
msgid = basilisk_msgid(myinfo,channel,hash,data,datalen); |
|
|
if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) |
|
|
jaddnum(valsobj,"channel",channel); |
|
|
jaddi(array,item); |
|
|
jaddnum(valsobj,"msgid",msgid); |
|
|
if ( width > 0 ) |
|
|
} else origcmd = ""; |
|
|
{ |
|
|
keylen = basilisk_messagekey(key,hash,valsobj); |
|
|
if ( bits256_nonz(srchash) != 0 ) |
|
|
printf("OUT orig.(%s) keylen.%d datalen.%d\n",origcmd,keylen,datalen); |
|
|
{ |
|
|
//char str[65]; printf("add message.[%d] channel.%u msgid.%x %s\n",datalen,juint(valsobj,"channel"),juint(valsobj,"msgid"),bits256_str(str,hash));
|
|
|
keylen = basilisk_messagekey(key,channel,msgid,zero,desthash); |
|
|
return(basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1)); |
|
|
if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) |
|
|
|
|
|
jaddi(array,item); |
|
|
|
|
|
} |
|
|
|
|
|
if ( bits256_nonz(desthash) != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
keylen = basilisk_messagekey(key,channel,msgid,srchash,zero); |
|
|
|
|
|
if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) |
|
|
|
|
|
jaddi(array,item); |
|
|
|
|
|
} |
|
|
|
|
|
if ( bits256_nonz(srchash) != 0 || bits256_nonz(desthash) != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
keylen = basilisk_messagekey(key,channel,msgid,zero,zero); |
|
|
|
|
|
if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) |
|
|
|
|
|
jaddi(array,item); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
msgid--; |
|
|
|
|
|
iguana_rwnum(1,&key[0],sizeof(uint32_t),&msgid); |
|
|
|
|
|
} |
|
|
|
|
|
return(jprint(array,1)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) |
|
|
char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) |
|
|
{ |
|
|
{ |
|
|
int32_t keylen; uint8_t key[64]; |
|
|
int32_t width; uint32_t msgid,channel; |
|
|
keylen = basilisk_messagekey(key,hash,valsobj); |
|
|
width = juint(valsobj,"width"); |
|
|
//char str[65]; printf("%s channel.%u msgid.%x datalen.%d\n",bits256_str(str,hash),juint(valsobj,"channel"),juint(valsobj,"msgid"),datalen);
|
|
|
msgid = juint(valsobj,"msgid"); |
|
|
return(basilisk_respond_getmessage(myinfo,key,keylen)); |
|
|
channel = juint(valsobj,"channel"); |
|
|
|
|
|
char str[65]; printf("%s channel.%u msgid.%x datalen.%d width.%d\n",bits256_str(str,hash),juint(valsobj,"channel"),msgid,datalen,width); |
|
|
|
|
|
return(basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(valsobj,"sender"),hash,width)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#include "../includes/iguana_apidefs.h" |
|
|
#include "../includes/iguana_apidefs.h" |
|
@ -176,22 +145,24 @@ 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) |
|
|
{ |
|
|
{ |
|
|
int32_t keylen; uint8_t key[64]; |
|
|
uint32_t msgid,width,channel; |
|
|
if ( myinfo->RELAYID >= 0 ) |
|
|
if ( myinfo->RELAYID >= 0 ) |
|
|
{ |
|
|
{ |
|
|
keylen = basilisk_messagekey(key,hash,vals); |
|
|
channel = juint(vals,"channel"); |
|
|
return(basilisk_respond_getmessage(myinfo,key,keylen)); |
|
|
msgid = juint(vals,"msgid"); |
|
|
|
|
|
width = juint(vals,"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)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) |
|
|
HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) |
|
|
{ |
|
|
{ |
|
|
int32_t keylen,datalen; uint8_t key[64],space[16384],*data,*ptr = 0; char *retstr=0; |
|
|
int32_t keylen,datalen; uint8_t key[BASILISK_KEYSIZE],space[16384],*data,*ptr = 0; char *retstr=0; |
|
|
if ( myinfo->RELAYID >= 0 ) |
|
|
if ( myinfo->RELAYID >= 0 ) |
|
|
{ |
|
|
{ |
|
|
keylen = basilisk_messagekey(key,hash,vals); |
|
|
keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"sender"),hash); |
|
|
if ( (data= get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,space,sizeof(space),hexstr)) != 0 ) |
|
|
if ( (data= get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,space,sizeof(space),hexstr)) != 0 ) |
|
|
retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0); |
|
|
retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration")); |
|
|
if ( ptr != 0 ) |
|
|
if ( ptr != 0 ) |
|
|
free(ptr); |
|
|
free(ptr); |
|
|
if ( retstr != 0 ) |
|
|
if ( retstr != 0 ) |
|
@ -203,14 +174,18 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) |
|
|
} |
|
|
} |
|
|
#include "../includes/iguana_apiundefs.h" |
|
|
#include "../includes/iguana_apiundefs.h" |
|
|
|
|
|
|
|
|
int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 hash,uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen) |
|
|
int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 hash,uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen,uint32_t duration) |
|
|
{ |
|
|
{ |
|
|
char *retstr,*hexstr,strbuf[4096],*ptr = 0; int32_t retval = -1; cJSON *valsobj; |
|
|
char *retstr,*hexstr,strbuf[4096],*ptr = 0; int32_t retval = -1; cJSON *valsobj; |
|
|
if ( (hexstr= basilisk_addhexstr(&ptr,0,strbuf,sizeof(strbuf),data,datalen)) != 0 ) |
|
|
if ( (hexstr= basilisk_addhexstr(&ptr,0,strbuf,sizeof(strbuf),data,datalen)) != 0 ) |
|
|
{ |
|
|
{ |
|
|
valsobj = cJSON_CreateObject(); |
|
|
valsobj = cJSON_CreateObject(); |
|
|
jaddnum(valsobj,"channel",channel); |
|
|
jaddnum(valsobj,"channel",channel); |
|
|
|
|
|
if ( msgid == 0 ) |
|
|
|
|
|
msgid = (uint32_t)time(NULL); |
|
|
jaddnum(valsobj,"msgid",msgid); |
|
|
jaddnum(valsobj,"msgid",msgid); |
|
|
|
|
|
jaddnum(valsobj,"duration",duration); |
|
|
|
|
|
jaddbits256(valsobj,"sender",myinfo->myaddr.persistent); |
|
|
//char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s\n",datalen,channel,msgid,bits256_str(str,hash));
|
|
|
//char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s\n",datalen,channel,msgid,bits256_str(str,hash));
|
|
|
if ( (retstr= basilisk_sendmessage(myinfo,0,0,0,hash,valsobj,hexstr)) != 0 ) |
|
|
if ( (retstr= basilisk_sendmessage(myinfo,0,0,0,hash,valsobj,hexstr)) != 0 ) |
|
|
free(retstr); |
|
|
free(retstr); |
|
@ -241,31 +216,52 @@ int32_t basilisk_message_returned(uint8_t *data,int32_t maxlen,cJSON *item) |
|
|
return(retval); |
|
|
return(retval); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int32_t basilisk_channelget(struct supernet_info *myinfo,bits256 hash,uint32_t channel,uint32_t msgid,uint8_t *data,int32_t maxlen) |
|
|
cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 hash,uint32_t channel,uint32_t msgid,int32_t width) |
|
|
{ |
|
|
{ |
|
|
char *retstr; cJSON *valsobj,*retarray,*item; int32_t i,datalen=0; |
|
|
char *retstr; cJSON *valsobj,*retarray=0,*item; |
|
|
valsobj = cJSON_CreateObject(); |
|
|
valsobj = cJSON_CreateObject(); |
|
|
jaddnum(valsobj,"channel",channel); |
|
|
jaddnum(valsobj,"channel",channel); |
|
|
|
|
|
if ( msgid == 0 ) |
|
|
|
|
|
msgid = (uint32_t)time(NULL); |
|
|
jaddnum(valsobj,"msgid",msgid); |
|
|
jaddnum(valsobj,"msgid",msgid); |
|
|
|
|
|
jaddnum(valsobj,"width",width); |
|
|
jaddnum(valsobj,"fanout",1); |
|
|
jaddnum(valsobj,"fanout",1); |
|
|
if ( (retstr= basilisk_getmessage(myinfo,0,0,0,hash,valsobj,0)) != 0 ) |
|
|
if ( (retstr= basilisk_getmessage(myinfo,0,0,0,hash,valsobj,0)) != 0 ) |
|
|
{ |
|
|
{ |
|
|
//printf("channel.%u msgid.%u gotmessage.(%s)\n",channel,msgid,retstr);
|
|
|
//printf("channel.%u msgid.%u gotmessage.(%s)\n",channel,msgid,retstr);
|
|
|
if ( (retarray= cJSON_Parse(retstr)) != 0 ) |
|
|
if ( (retarray= cJSON_Parse(retstr)) != 0 ) |
|
|
{ |
|
|
{ |
|
|
if ( is_cJSON_Array(retarray) != 0 ) |
|
|
if ( is_cJSON_Array(retarray) == 0 ) |
|
|
{ |
|
|
{ |
|
|
for (i=0; i<cJSON_GetArraySize(retarray); i++) |
|
|
item = cJSON_CreateArray(); |
|
|
{ |
|
|
jaddi(item,retarray); |
|
|
item = jitem(retarray,i); |
|
|
retarray = item; |
|
|
if ( (datalen= basilisk_message_returned(data,maxlen,item)) > 0 ) |
|
|
} |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
} else datalen = basilisk_message_returned(data,maxlen,retarray); |
|
|
|
|
|
free_json(retarray); |
|
|
|
|
|
} else printf("cant parse message\n"); |
|
|
|
|
|
free(retstr); |
|
|
free(retstr); |
|
|
} else printf("null getmessage\n"); |
|
|
} |
|
|
free_json(valsobj); |
|
|
free_json(valsobj); |
|
|
return(datalen); |
|
|
return(retarray); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int32_t basilisk_process_retarray(struct supernet_info *myinfo,void *ptr,int32_t (*process_func)(struct supernet_info *myinfo,void *ptr,int32_t (*internal_func)(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen),uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen,uint32_t expiration,uint32_t duration),uint8_t *data,int32_t maxlen,uint32_t channel,uint32_t msgid,cJSON *retarray,int32_t (*internal_func)(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen)) |
|
|
|
|
|
{ |
|
|
|
|
|
cJSON *item; uint32_t duration,expiration; int32_t i,n,datalen,errs = 0; |
|
|
|
|
|
if ( (n= cJSON_GetArraySize(retarray)) > 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
for (i=0; i<n; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
item = jitem(retarray,i); |
|
|
|
|
|
if ( (datalen= basilisk_message_returned(data,maxlen,item)) > 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
duration = juint(item,"duration"); |
|
|
|
|
|
expiration = juint(item,"expiration"); |
|
|
|
|
|
if ( (*process_func)(myinfo,ptr,internal_func,channel,msgid,data,datalen,expiration,duration) < 0 ) |
|
|
|
|
|
errs++; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if ( errs > 0 ) |
|
|
|
|
|
return(-errs); |
|
|
|
|
|
else return(n); |
|
|
} |
|
|
} |
|
|