mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-18 20:57:56 +00:00
Expunge old DNA protocol code (cleans up warnings)
This commit is contained in:
parent
1fbf957a9d
commit
67e2e98867
@ -67,11 +67,8 @@ static char *handle_cli_sdnalookup(int fd, int argc, char *argv[])
|
||||
|
||||
did=argv[3];
|
||||
|
||||
if (requestItem(did,sid,"locations",instance,buffer,sizeof(buffer),&len,NULL))
|
||||
{
|
||||
ast_cli(fd,"Serval DNA Lookup: requestItem() failed (len=%d).\n\n",len);
|
||||
return RESULT_FAILURE;
|
||||
}
|
||||
ast_cli(fd,"Serval DNA Lookup: NOT IMPLEMENTED\n\n",len);
|
||||
return RESULT_FAILURE;
|
||||
|
||||
buffer[len]=0;
|
||||
ast_cli(fd,"%s resolves to %s (len=%d)\n",did,buffer,len);
|
||||
@ -199,12 +196,10 @@ static int sdnalookup_exec(struct ast_channel *chan, void *data)
|
||||
(b) retrieve the SID for the DID for further use
|
||||
(c) fetch the voicesig as well if requested
|
||||
*/
|
||||
if (requestItem(did,sid,"locations",instance,buffer,sizeof(buffer),&len,NULL))
|
||||
{
|
||||
pbx_builtin_setvar_helper(chan,"SNASTATUS","FAILED");
|
||||
if (debug) fprintf(stderr,"SDNASTATUS=FAILED\n");
|
||||
return -1;
|
||||
}
|
||||
// NOT IMPLEMENTED
|
||||
pbx_builtin_setvar_helper(chan,"SNASTATUS","FAILED");
|
||||
if (debug) fprintf(stderr,"SDNASTATUS=FAILED\n");
|
||||
return -1;
|
||||
|
||||
/* It worked, so set appropriate variables and return happily */
|
||||
pbx_builtin_setvar_helper(chan,"SNADID",did);
|
||||
|
428
client.c
428
client.c
@ -410,431 +410,3 @@ int getReplyPackets(int method,int peer,int batchP,struct response_set *response
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int writeItem(char *sid,int var_id,int instance,unsigned char *value,
|
||||
int value_start,int value_length,int flags,
|
||||
int recvttl,struct sockaddr *recvaddr)
|
||||
{
|
||||
unsigned char packet[8000];
|
||||
int packet_len=0;
|
||||
struct response_set responses;
|
||||
struct response *r;
|
||||
unsigned char transaction_id[TRANSID_SIZE];
|
||||
|
||||
bzero(&responses,sizeof(responses));
|
||||
|
||||
if (debug&DEBUG_DNAVARS) fprintf(stderr,"Writing %d bytes of var %02x/%02x @ 0x%d flags=%d\n",
|
||||
value_length,var_id,instance,value_start,flags);
|
||||
|
||||
if (!sid) {
|
||||
printf("ERROR:Must use SID when writing values.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Split long writes into many short writes.
|
||||
(since each write is acknowledged, we don't have to worry about batch mode) */
|
||||
if (value_length-value_start>MAX_DATA_BYTES)
|
||||
{
|
||||
int o;
|
||||
if (debug&DEBUG_DNAVARS) fprintf(stderr,"Writing large value (%d bytes)\n",value_length-value_start);
|
||||
for(o=value_start;o<value_length;o+=MAX_DATA_BYTES)
|
||||
{
|
||||
int bytes=MAX_DATA_BYTES;
|
||||
if (o+bytes>value_length) bytes=value_length-o;
|
||||
if (debug&DEBUG_DNAVARS) fprintf(stderr," writing [%d,%d)\n",o,o+bytes-1);
|
||||
if (writeItem(sid,var_id,instance,&value[o-value_start],o,bytes,
|
||||
flags|((o>value_start)?SET_FRAGMENT:0),recvttl,NULL))
|
||||
{
|
||||
if (debug&DEBUG_DNAVARS) fprintf(stderr," - writing installment failed\n");
|
||||
return WHY("Failure during multi-packet write of long-value");
|
||||
}
|
||||
}
|
||||
printf("OK:%s\n",sid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Prepare the request packet to write the variable */
|
||||
if (packetMakeHeader(packet,8000,&packet_len,NULL,CRYPT_SIGNED|CRYPT_CIPHERED)) return -1;
|
||||
bcopy(&packet[OFS_TRANSIDFIELD],transaction_id,TRANSID_SIZE);
|
||||
#warning packetSetSid has been deprecated, which is why we have removed the prototype.
|
||||
if (packetSetSid(packet,8000,&packet_len,sid)) return -1;
|
||||
if (packetAddVariableWrite(packet,8000,&packet_len,var_id,instance,
|
||||
value,value_start,value_length,flags)) return -1;
|
||||
if (packetFinalise(packet,8000,recvttl,&packet_len,CRYPT_SIGNED|CRYPT_CIPHERED)) return -1;
|
||||
|
||||
/* XXX should be able to target to the peer holding the SID, if we have it.
|
||||
In any case, we */
|
||||
if (packetSendRequest(REQ_FIRSTREPLY,packet,packet_len,NONBATCH,transaction_id,recvaddr,&responses)) return -1;
|
||||
|
||||
r=responses.responses;
|
||||
while(r)
|
||||
{
|
||||
int slen=0;
|
||||
char sid[SID_STRLEN+1];
|
||||
extractSid(r->sid,&slen,sid);
|
||||
switch(r->code)
|
||||
{
|
||||
case ACTION_ERROR:
|
||||
/* We allocate an extra byte to allow us to do this */
|
||||
r->response[r->response_len]=0;
|
||||
printf("ERROR:%s\n",(char *)r->response);
|
||||
break;
|
||||
case ACTION_OKAY: printf("ERROR:Unexpected OK response\n"); break;
|
||||
case ACTION_DECLINED: printf("DECLINED:%s\n",sid); break;
|
||||
case ACTION_WROTE:
|
||||
/* Supress success messages when writing fragments */
|
||||
if (!(flags&SET_FRAGMENT)) printf("WROTE:%s\n",sid); break;
|
||||
case ACTION_DATA: printf("ERROR:DATA reponse not implemented\n"); break;
|
||||
case ACTION_GET: printf("ERROR:You cant respond with GET\n"); break;
|
||||
case ACTION_SET: printf("ERROR:You cant respond with SET\n"); break;
|
||||
case ACTION_DEL: printf("ERROR:You cant respond with DEL\n"); break;
|
||||
case ACTION_CREATEHLR: printf("ERROR:You cant respond with CREATEHLR\n"); break;
|
||||
case ACTION_PAD: /* ignore it */ break;
|
||||
case ACTION_EOT: /* ignore it */ break;
|
||||
case ACTION_RECVTTL: /* ignore it */ break;
|
||||
default: printf("ERROR:Unexpected response code 0x%02x\n",r->code);
|
||||
}
|
||||
fflush(stdout);
|
||||
r=r->next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int peerAddress(char *did,char *sid,int flags)
|
||||
{
|
||||
unsigned char transaction_id[TRANSID_SIZE];
|
||||
unsigned char packet[8000];
|
||||
int packet_len=0;
|
||||
struct response *r;
|
||||
struct response_set responses;
|
||||
|
||||
int i;
|
||||
int pc=0;
|
||||
struct in_addr mypeers[256];
|
||||
int method;
|
||||
|
||||
bzero(&responses,sizeof(responses));
|
||||
|
||||
for(i=0;i<TRANSID_SIZE;i++) transaction_id[i]=random()&0xff;
|
||||
|
||||
/* Prepare the request packet: this is broadcast, so make it public.
|
||||
As these can get sent out quite often, don't waste time and energy signing. */
|
||||
if (packetMakeHeader(packet,8000,&packet_len,transaction_id,CRYPT_PUBLIC))
|
||||
{
|
||||
if (debug&DEBUG_PACKETFORMATS) fprintf(stderr,"%s() failed at line %d\n",__FUNCTION__,__LINE__);
|
||||
return -1;
|
||||
}
|
||||
if (did&&(!sid))
|
||||
{ if (packetSetDid(packet,8000,&packet_len,did)) {
|
||||
if (debug&DEBUG_PACKETFORMATS) fprintf(stderr,"%s() failed at line %d\n",__FUNCTION__,__LINE__);
|
||||
return -1; }
|
||||
}
|
||||
else if (sid&&(!did))
|
||||
{ if (packetSetSid(packet,8000,&packet_len,sid)) {
|
||||
if (debug&DEBUG_PACKETFORMATS) fprintf(stderr,"%s() failed at line %d\n",__FUNCTION__,__LINE__);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (debug&DEBUG_PACKETFORMATS) fprintf(stderr,"%s() failed at line %d\n",__FUNCTION__,__LINE__);
|
||||
return WHY("You must request items by DID or SID, not neither, nor both");
|
||||
}
|
||||
|
||||
|
||||
if (packetAddVariableRequest(packet,8000,&packet_len,
|
||||
"dids",0,0,128 /* only small things please */)) {
|
||||
if (debug&DEBUG_DNAVARS) fprintf(stderr,"%s() failed at line %d\n",__FUNCTION__,__LINE__);
|
||||
return -1;
|
||||
}
|
||||
if (packetFinalise(packet,8000,-1,&packet_len,CRYPT_PUBLIC)) {
|
||||
if (debug&DEBUG_PACKETFORMATS) fprintf(stderr,"%s() failed at line %d\n",__FUNCTION__,__LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
method=REQ_PARALLEL;
|
||||
if (sid) method=REQ_FIRSTREPLY;
|
||||
if (packetSendRequest(method,packet,packet_len,NONBATCH,transaction_id,NULL,&responses)) {
|
||||
if (debug&DEBUG_PACKETTX) fprintf(stderr,"peerAddress() failed because packetSendRequest() failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
r=responses.responses;
|
||||
if (!r)
|
||||
{
|
||||
if (debug&DEBUG_PEERS) fprintf(stderr,"peerAddress() failed because noone answered.\n");
|
||||
return -1;
|
||||
}
|
||||
while(r)
|
||||
{
|
||||
if (flags&1) printf("%s\n",inet_ntoa(r->sender));
|
||||
if (flags&2) {
|
||||
if (pc<256) mypeers[pc++]=r->sender;
|
||||
}
|
||||
break;
|
||||
r=r->next;
|
||||
}
|
||||
|
||||
/* Set the peer list to exactly the list of nodes that we have identified */
|
||||
if (flags&2)
|
||||
{
|
||||
for(i=0;i<pc;i++)
|
||||
peers[i]=mypeers[i];
|
||||
peer_count=pc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int requestItem(char *did,char *sid,char *item,int instance,
|
||||
unsigned char *buffer,int buffer_length,int *len,
|
||||
unsigned char *transaction_id)
|
||||
{
|
||||
unsigned char packet[8000];
|
||||
int packet_len=0;
|
||||
struct response *r;
|
||||
struct response_set responses;
|
||||
|
||||
int successes=0;
|
||||
int errors=0;
|
||||
int method;
|
||||
|
||||
bzero(&responses,sizeof(responses));
|
||||
|
||||
/* Prepare the request packet. Don't let anyone else see what we are asking for. */
|
||||
if (packetMakeHeader(packet,8000,&packet_len,transaction_id,CRYPT_SIGNED|CRYPT_CIPHERED))
|
||||
{
|
||||
if (debug&DEBUG_DNAREQUESTS) fprintf(stderr,"requestItem() failed at line %d\n",__LINE__);
|
||||
return -1;
|
||||
}
|
||||
if (did&&(!sid))
|
||||
{ if (packetSetDid(packet,8000,&packet_len,did)) {
|
||||
if (debug&DEBUG_DNAREQUESTS) fprintf(stderr,"requestItem() failed at line %d\n",__LINE__);
|
||||
return -1; }
|
||||
}
|
||||
else if (sid&&(!did))
|
||||
{ if (packetSetSid(packet,8000,&packet_len,sid)) {
|
||||
if (debug&DEBUG_DNAREQUESTS) fprintf(stderr,"requestItem() failed at line %d\n",__LINE__);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (debug&DEBUG_DNAREQUESTS) fprintf(stderr,"requestItem() failed at line %d\n",__LINE__);
|
||||
return WHY("You must request items by DID or SID, not neither, nor both");
|
||||
}
|
||||
|
||||
|
||||
if (packetAddVariableRequest(packet,8000,&packet_len,
|
||||
item,instance,0,buffer_length)) {
|
||||
if (debug&DEBUG_PACKETFORMATS) fprintf(stderr,"requestItem() failed at line %d\n",__LINE__);
|
||||
return -1;
|
||||
}
|
||||
if (packetFinalise(packet,8000,-1,&packet_len,CRYPT_SIGNED|CRYPT_CIPHERED)) {
|
||||
if (debug&DEBUG_PACKETFORMATS) fprintf(stderr,"requestItem() failed at line %d\n",__LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
method=REQ_PARALLEL;
|
||||
if (sid) method=REQ_FIRSTREPLY;
|
||||
if (packetSendRequest(method,packet,packet_len,(instance==-1)?BATCH:NONBATCH,transaction_id,NULL,&responses)) {
|
||||
if (debug&DEBUG_PACKETTX) fprintf(stderr,"requestItem() failed because packetSendRequest() failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
r=responses.responses;
|
||||
while(r)
|
||||
{
|
||||
char sid[SID_STRLEN+1];
|
||||
int slen=0;
|
||||
extractSid(r->sid,&slen,sid);
|
||||
switch(r->code)
|
||||
{
|
||||
case ACTION_OKAY: printf("OK:%s:%d\n",sid,r->recvttl); if (buffer) {strcpy((char *)buffer,sid); *len=strlen(sid); } successes++; break;
|
||||
case ACTION_DECLINED: printf("DECLINED:%s:%d\n",sid,r->recvttl); errors++; break;
|
||||
case ACTION_DATA:
|
||||
/* Display data.
|
||||
The trick is knowing the format of the data.
|
||||
Fortunately we get the variable id etc.
|
||||
XXX Need to deal with fragmented values.
|
||||
(perhaps the fragments should get auto-assembled when accepting the responses)
|
||||
*/
|
||||
switch(r->var_id)
|
||||
{
|
||||
case VAR_DIDS:
|
||||
{
|
||||
char did[DID_MAXSIZE+1];
|
||||
int dlen=0;
|
||||
did[0]=0;
|
||||
extractDid(r->response,&dlen,did);
|
||||
printf("DIDS:%s:%d:%d:%s\n",sid,r->recvttl,r->var_instance,did);
|
||||
if (buffer) {strcpy((char *)buffer,did); *len=strlen(did); }
|
||||
successes++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* ASCII formatted variable types */
|
||||
{
|
||||
int v=0;
|
||||
int i=0;
|
||||
FILE *outputfile=stdout;
|
||||
while(vars[v].name&&vars[v].id!=r->var_id) v++;
|
||||
if (!vars[v].id) printf("0x%02x",r->var_id);
|
||||
while(vars[v].name[i]) fputc(toupper(vars[v].name[i++]),stdout);
|
||||
printf(":%s:%d:%d:",sid,r->recvttl,r->var_instance);
|
||||
*len=r->value_len;
|
||||
|
||||
if (outputtemplate)
|
||||
{
|
||||
char outputname[8192];
|
||||
snprintf(outputname,8192,outputtemplate,sid,r->var_id,r->var_instance);
|
||||
outputfile=fopen(outputname,"w");
|
||||
if (!outputfile) printf("ERROR:Could not open output file '%s'",outputname);
|
||||
if (debug&DEBUG_VERBOSE) fprintf(stderr,"Writing output to '%s'\n",outputname);
|
||||
}
|
||||
|
||||
if (outputfile) fwrite(r->response,r->value_bytes,1,outputfile);
|
||||
|
||||
if (r->value_bytes<r->value_len)
|
||||
{
|
||||
/* Partial response, so ask for the rest of it */
|
||||
unsigned char packet[8000];
|
||||
int packet_len=0;
|
||||
struct response *rr;
|
||||
struct response_set responses;
|
||||
int offset,max_bytes;
|
||||
int *recv_map;
|
||||
int recv_map_size=1+(r->value_len/MAX_DATA_BYTES);
|
||||
int needMoreData;
|
||||
int tries=0;
|
||||
|
||||
recv_map=alloca(recv_map_size);
|
||||
|
||||
/* work out EXACTLY how many installments we need */
|
||||
while (((recv_map_size-1)*MAX_DATA_BYTES)>=r->value_len) recv_map_size--;
|
||||
|
||||
recv_map[0]=0; /* we received the first installment, so mark it off ... */
|
||||
/* ... but we haven't received the rest */
|
||||
for(i=1;i<recv_map_size;i++) recv_map[i]=0;
|
||||
|
||||
/* Ask for all remaining pieces in parallel, then keep track of what has arrived
|
||||
XXX - Not yet implemented. Currently uses a slow serial method, worse than TFTP */
|
||||
needMoreData=recv_map_size-1;
|
||||
|
||||
while(needMoreData&&(tries++<15))
|
||||
{
|
||||
if (debug&DEBUG_DNAREQUESTS) fprintf(stderr,"Multi-packet request: try %d, %d fragments remaining.\n",tries,needMoreData);
|
||||
needMoreData=0;
|
||||
for(i=0;i<recv_map_size;i++)
|
||||
if (!recv_map[i])
|
||||
{
|
||||
needMoreData++;
|
||||
offset=i*MAX_DATA_BYTES;
|
||||
|
||||
if (debug&DEBUG_DNAREQUESTS) fprintf(stderr,"Asking for variable segment @ offset %d\n",offset);
|
||||
|
||||
/* Send accumulated request direct to the responder */
|
||||
if (packet_len>=MAX_DATA_BYTES)
|
||||
{
|
||||
if (packetFinalise(packet,8000,-1,&packet_len,CRYPT_CIPHERED|CRYPT_SIGNED)) {
|
||||
if (debug&DEBUG_DNAREQUESTS) fprintf(stderr,"requestItem() failed at line %d\n",__LINE__);
|
||||
return -1;
|
||||
}
|
||||
packetSendFollowup(r->sender,packet,packet_len);
|
||||
packet_len=0;
|
||||
}
|
||||
/* Prepare a new request packet if one is not currently being built */
|
||||
if (!packet_len)
|
||||
{
|
||||
/* We are requesting data, so ask for privacy */
|
||||
if (packetMakeHeader(packet,8000,&packet_len,transaction_id,CRYPT_CIPHERED|CRYPT_SIGNED)) {
|
||||
if (debug&DEBUG_PACKETFORMATS) fprintf(stderr,"requestItem() failed at line %d\n",__LINE__);
|
||||
return -1;
|
||||
}
|
||||
if (packetSetSid(packet,8000,&packet_len,sid)) {
|
||||
if (debug&DEBUG_PACKETFORMATS) fprintf(stderr,"requestItem() failed at line %d\n",__LINE__);
|
||||
return WHY("SID went mouldy during multi-packet get");
|
||||
}
|
||||
}
|
||||
|
||||
max_bytes=65535-offset;
|
||||
if (max_bytes>buffer_length) max_bytes=buffer_length;
|
||||
if (packetAddVariableRequest(packet,8000,&packet_len,
|
||||
item,r->var_instance,offset,max_bytes)) {
|
||||
if (debug&DEBUG_DNAREQUESTS) fprintf(stderr,"requestItem() failed at line %d\n",__LINE__);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/* Send accumulated request direct to the responder */
|
||||
if (packet_len)
|
||||
{
|
||||
if (packetFinalise(packet,8000,-1,&packet_len,CRYPT_SIGNED|CRYPT_CIPHERED)) {
|
||||
if (debug&DEBUG_PACKETFORMATS) fprintf(stderr,"requestItem() failed at line %d\n",__LINE__);
|
||||
return -1;
|
||||
}
|
||||
packetSendFollowup(r->sender,packet,packet_len);
|
||||
packet_len=0;
|
||||
}
|
||||
|
||||
/* Collect responses to our multiple requests */
|
||||
bzero(&responses,sizeof(responses));
|
||||
|
||||
/* XXX should target specific peer that sent first piece */
|
||||
getReplyPackets(REQ_PARALLEL,i,0,&responses,transaction_id,(struct sockaddr *)&r->sender,250);
|
||||
rr=responses.responses;
|
||||
while(rr)
|
||||
{
|
||||
if (rr->code==ACTION_DATA&&rr->var_id==r->var_id&&rr->var_instance==r->var_instance)
|
||||
{
|
||||
int piece=rr->value_offset/MAX_DATA_BYTES;
|
||||
if (!recv_map[piece])
|
||||
{
|
||||
if (debug&DEBUG_DNARESPONSES) fprintf(stderr,"Extracted value fragment @ offset %d, with %d bytes\n",rr->value_offset,rr->value_bytes);
|
||||
if (debug&DEBUG_DNARESPONSES) dump("Fragment",rr->response,rr->value_bytes);
|
||||
fseek(outputfile,rr->value_offset,SEEK_SET);
|
||||
fwrite(rr->response,rr->value_bytes,1,outputfile);
|
||||
if (buffer) bcopy(rr->response,&buffer[rr->value_offset],rr->value_bytes);
|
||||
recv_map[piece]=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (debug&DEBUG_DNARESPONSES) fprintf(stderr,"DUPLICATE value fragment @ offset %d, with %d bytes\n",rr->value_offset,rr->value_bytes);
|
||||
|
||||
}
|
||||
}
|
||||
rr=rr->next;
|
||||
}
|
||||
clearResponses(&responses);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (buffer) bcopy(r->response,&buffer[r->value_offset],r->value_bytes);
|
||||
}
|
||||
if (outputtemplate) fclose(outputfile); else fflush(outputfile);
|
||||
printf("\n");
|
||||
if (debug&DEBUG_DNARESPONSES) fprintf(stderr,"requestItem() returned DATA\n");
|
||||
if (!returnMultiVars) return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ACTION_DONE:
|
||||
printf("DONE:%s:%d:%d\n",sid,r->recvttl,r->response[0]);
|
||||
break;
|
||||
case ACTION_GET: printf("ERROR:You cant respond with GET\n"); break;
|
||||
case ACTION_SET: printf("ERROR:You cant respond with SET\n"); break;
|
||||
case ACTION_WROTE: printf("ERROR:You cant respond with WROTE\n"); break;
|
||||
case ACTION_DEL: printf("ERROR:You cant respond with DEL\n"); break;
|
||||
case ACTION_CREATEHLR: printf("ERROR:You cant respond with CREATEHLR\n"); break;
|
||||
case ACTION_PAD: /* ignore it */ break;
|
||||
case ACTION_EOT: /* ignore it */ break;
|
||||
case ACTION_RECVTTL: /* ignore it */ break;
|
||||
default: printf("ERROR:Unexpected response code 0x%02x\n",r->code);
|
||||
}
|
||||
fflush(stdout);
|
||||
r=r->next;
|
||||
}
|
||||
|
||||
if (debug&DEBUG_VERBOSE) fprintf(stderr,"requestItem() failed at line %d\n",__LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
59
dna.c
59
dna.c
@ -27,21 +27,12 @@ int usage(char *complaint)
|
||||
fprintf(stderr,"usage:\n");
|
||||
fprintf(stderr," dna [-v <flags>] -S [-f keyring file] [-N interface,...] [-G gateway specification] [-r rhizome path]\n");
|
||||
fprintf(stderr,"or\n");
|
||||
fprintf(stderr," dna <-d|-s> id -A\n");
|
||||
fprintf(stderr,"or\n");
|
||||
fprintf(stderr," dna <-d|-s> id [-p pin] [-i variable instance] <-R variable[=value]>\n");
|
||||
fprintf(stderr," [-v <flags>] [-t request timeout in ms] [-O output file name template]\n");
|
||||
fprintf(stderr,"or\n");
|
||||
fprintf(stderr," dna <-d|-s> id [-p pin] [-i variable instance] <-W|-U|-D variable[=[$|@]value]>\n");
|
||||
fprintf(stderr," [-v <flags>] [-t request timeout in ms]\n");
|
||||
fprintf(stderr,"or\n");
|
||||
fprintf(stderr," dna [-v <flags>] [-t timeout] -d did -C\n");
|
||||
fprintf(stderr,"or\n");
|
||||
fprintf(stderr," dna [-v <flags>] -f <keyring file> -E <export.txt>\n");
|
||||
|
||||
fprintf(stderr,"\n");
|
||||
fprintf(stderr," -v - Set verbosity.\n");
|
||||
fprintf(stderr," -A - Ask for address of subscriber.\n");
|
||||
fprintf(stderr," -b - Specify BATMAN socket to obtain peer list (flaky).\n");
|
||||
fprintf(stderr," -l - Specify BATMAN socket to obtain peer list (better, but requires Serval patched BATMAN).\n");
|
||||
fprintf(stderr," -L - Log mesh statistics to specified file.\n");
|
||||
@ -50,23 +41,15 @@ int usage(char *complaint)
|
||||
fprintf(stderr," -n - Do not detach from foreground in server mode.\n");
|
||||
fprintf(stderr," -S - Run in server mode.\n");
|
||||
fprintf(stderr," -f - Location of keyring file.\n");
|
||||
fprintf(stderr," -d - Search by Direct Inward Dial (DID) number.\n");
|
||||
fprintf(stderr," -s - Search by Subscriber ID (SID) number.\n");
|
||||
fprintf(stderr," -p - Specify additional DNA nodes to query.\n");
|
||||
fprintf(stderr," -P - Authenticate using the supplied pin.\n");
|
||||
fprintf(stderr," -r - Enable Rhizome store-and-forward transport using the specified data store directory.\n");
|
||||
fprintf(stderr," To limit the storage: echo space=[KB] > path/rhizome.conf\n");
|
||||
fprintf(stderr," -R - Read a variable value.\n");
|
||||
fprintf(stderr," -O - Place read variable value into files using argument as a template.\n");
|
||||
fprintf(stderr," The following template codes can be used (interpretted by sprintf):\n");
|
||||
fprintf(stderr," %%1$s - Subscriber ID\n");
|
||||
fprintf(stderr," %%2$d - Variable ID (0-255)\n");
|
||||
fprintf(stderr," %%3$d - Variable instance number (0-255)\n");
|
||||
fprintf(stderr," -W - Write a variable value, keeping previous values.\n");
|
||||
fprintf(stderr," -U - Update a variable value, replacing the previous value.\n");
|
||||
fprintf(stderr," -D - Delete a variable value.\n");
|
||||
fprintf(stderr," $value means interpret value as hexidecimal bytes.\n");
|
||||
fprintf(stderr," @value means read value from file called value.\n");
|
||||
fprintf(stderr," -C - Request the creation of a new subscriber with the specified DID.\n");
|
||||
fprintf(stderr," -t - Specify the request timeout period.\n");
|
||||
fprintf(stderr," -G - Offer gateway services. Argument specifies locations of necessary files.\n");
|
||||
@ -82,8 +65,6 @@ int parseOldCommandLine(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
//char *pin=NULL;
|
||||
char *did=NULL;
|
||||
char *sid=NULL;
|
||||
char *keyring_file=NULL;
|
||||
int instance=-1;
|
||||
int foregroundMode=0;
|
||||
@ -91,7 +72,7 @@ int parseOldCommandLine(int argc, char **argv)
|
||||
const char *rhizome_path = NULL;
|
||||
WARNF("The use of the old command line structure is being deprecated.");
|
||||
WARNF("Type '%s help' to learn about the new command line structure.", argv[0]);
|
||||
while ((c = getopt(argc,argv,"Ab:B:E:G:I:Sf:d:i:l:L:mnp:P:r:s:t:v:R:W:U:D:CO:N:")) != -1) {
|
||||
while ((c = getopt(argc,argv,"b:B:E:G:I:Sf:i:l:L:mnp:P:r:t:v:CO:N:")) != -1) {
|
||||
switch(c)
|
||||
{
|
||||
case 'S': serverMode=1; break;
|
||||
@ -139,50 +120,12 @@ int parseOldCommandLine(int argc, char **argv)
|
||||
//pin=strdup(optarg);
|
||||
clientMode=1;
|
||||
break;
|
||||
case 'd': /* Ask by DID */
|
||||
clientMode=1;
|
||||
did=strdup(optarg);
|
||||
break;
|
||||
case 's': /* Ask by subscriber ID */
|
||||
clientMode=1;
|
||||
sid=strdup(optarg);
|
||||
break;
|
||||
case 't': /* request timeout (ms) */
|
||||
dnatimeout=atoi(optarg);
|
||||
break;
|
||||
case 'v': /* set verbosity */
|
||||
debug |= debugFlagMask(optarg);
|
||||
break;
|
||||
case 'A': /* get address (IP or otherwise) of a given peer */
|
||||
peerAddress(did,sid,3 /* 1 = print list of addresses to stdout, 2 = set peer list to responders */);
|
||||
break;
|
||||
case 'R': /* read a variable */
|
||||
{
|
||||
unsigned char buffer[65535];
|
||||
int len=0;
|
||||
requestItem(did,sid,(char *)optarg,instance,buffer,sizeof(buffer),&len,NULL);
|
||||
}
|
||||
break;
|
||||
case 'W': /* write a variable */
|
||||
{
|
||||
int var_id;
|
||||
unsigned char value[65536];
|
||||
int value_len=65535;
|
||||
if (parseAssignment((unsigned char *)optarg,&var_id,value,&value_len)) return -1;
|
||||
value[value_len]=0;
|
||||
return writeItem(did?did:sid,var_id,instance,value,0,value_len,SET_NOREPLACE,-1,NULL);
|
||||
}
|
||||
break;
|
||||
case 'U': /* write or update a variable */
|
||||
{
|
||||
int var_id;
|
||||
unsigned char value[65536];
|
||||
int value_len=65535;
|
||||
if (parseAssignment((unsigned char *)optarg,&var_id,value,&value_len)) return -1;
|
||||
value[value_len]=0;
|
||||
return writeItem(did?did:sid,var_id,instance,value,0,value_len,SET_REPLACE,-1,NULL);
|
||||
}
|
||||
break;
|
||||
case 'C': /* create a new keyring entry */
|
||||
return WHY("Entries in new keyring format must be used with new command line framework.");
|
||||
break;
|
||||
|
4
serval.h
4
serval.h
@ -475,9 +475,6 @@ int hlrSetVariable(unsigned char *hlr,int hofs,int varid,int varinstance,
|
||||
unsigned char *value,int len);
|
||||
int extractDid(unsigned char *packet,int *ofs,char *did);
|
||||
char *hlrSid(unsigned char *hlr, int ofs, char *sid);
|
||||
int writeItem(char *sid,int var_id,int instance,unsigned char *value,
|
||||
int value_start,int value_length,int flags,
|
||||
int recvttl,struct sockaddr *recvaddr);
|
||||
int packetAddVariableWrite(unsigned char *packet,int packet_maxlen,int *packet_len,
|
||||
int itemId,int instance,unsigned char *value,int start_offset,int value_len,int flags);
|
||||
int processRequest(unsigned char *packet,int len,struct sockaddr *sender,int sender_len,
|
||||
@ -499,7 +496,6 @@ int readRoutingTable(struct in_addr peers[],int *peer_count,int peer_max);
|
||||
int readBatmanPeerFile(char *file_path,struct in_addr peers[],int *peer_count,int peer_max);
|
||||
int getBatmanPeerList(char *socket_path,struct in_addr peers[],int *peer_count,int peer_max);
|
||||
int hlrDump(unsigned char *hlr,int hofs);
|
||||
int peerAddress(char *did,char *sid,int flags);
|
||||
int fixResponses(struct response_set *responses);
|
||||
int importHlr(char *textfile);
|
||||
int exportHlr(unsigned char *hlr,char *text);
|
||||
|
Loading…
Reference in New Issue
Block a user