mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 02:39:44 +00:00
Clean up compile warnings and fix bugs
In monitor_process_command() for "call" command, was not handling SID "*" case properly, nor checking validity of hex SID.
This commit is contained in:
parent
07c507017a
commit
735d9a42cc
@ -68,10 +68,15 @@ char *tohex(char *dstHex, const unsigned char *srcBinary, size_t bytes)
|
||||
return dstHex;
|
||||
}
|
||||
|
||||
size_t fromhex(unsigned char *dstBinary, const char *srcHex, size_t bytes)
|
||||
/* Convert nbinary*2 ASCII hex characters [0-9A-Fa-f] to nbinary bytes of data. Can be used to
|
||||
perform the conversion in-place, eg, fromhex(buf, (char*)buf, n); Returns -1 if a non-hex-digit
|
||||
character is encountered, otherwise returns the number of binary bytes produced (= nbinary).
|
||||
@author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
size_t fromhex(unsigned char *dstBinary, const char *srcHex, size_t nbinary)
|
||||
{
|
||||
size_t count = 0;
|
||||
while (count != bytes) {
|
||||
while (count != nbinary) {
|
||||
unsigned char high = hexvalue(*srcHex++);
|
||||
if (high & 0xf0) return -1;
|
||||
unsigned char low = hexvalue(*srcHex++);
|
||||
@ -81,9 +86,15 @@ size_t fromhex(unsigned char *dstBinary, const char *srcHex, size_t bytes)
|
||||
return count;
|
||||
}
|
||||
|
||||
int fromhexstr(unsigned char *dstBinary, const char *srcHex, size_t bytes)
|
||||
/* Convert nbinary*2 ASCII hex characters [0-9A-Fa-f] followed by a nul '\0' character to nbinary bytes of data. Can be used to
|
||||
perform the conversion in-place, eg, fromhex(buf, (char*)buf, n); Returns -1 if a non-hex-digit
|
||||
character is encountered or the character immediately following the last hex digit is not a nul,
|
||||
otherwise returns zero.
|
||||
@author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
int fromhexstr(unsigned char *dstBinary, const char *srcHex, size_t nbinary)
|
||||
{
|
||||
return (fromhex(dstBinary, srcHex, bytes) == bytes && srcHex[bytes * 2] == '\0') ? 0 : -1;
|
||||
return (fromhex(dstBinary, srcHex, nbinary) == nbinary && srcHex[nbinary * 2] == '\0') ? 0 : -1;
|
||||
}
|
||||
|
||||
int rhizome_strn_is_manifest_id(const char *id)
|
||||
|
51
monitor.c
51
monitor.c
@ -321,12 +321,9 @@ int monitor_process_command(struct monitor_context *c)
|
||||
int callSessionToken,sampleType,bytes;
|
||||
char sid[MONITOR_LINE_LENGTH],localDid[MONITOR_LINE_LENGTH];
|
||||
char remoteDid[MONITOR_LINE_LENGTH],digits[MONITOR_LINE_LENGTH];
|
||||
overlay_mdp_frame mdp;
|
||||
char *cmd = c->line;
|
||||
IN();
|
||||
|
||||
mdp.packetTypeAndFlags=MDP_VOMPEVENT;
|
||||
|
||||
c->line_length=0;
|
||||
|
||||
if (strlen(cmd)>MONITOR_LINE_LENGTH) {
|
||||
@ -384,32 +381,36 @@ int monitor_process_command(struct monitor_context *c)
|
||||
}
|
||||
else if (sscanf(cmd,"call %s %s %s",sid,localDid,remoteDid)==3) {
|
||||
DEBUG("here");
|
||||
int gotSid = 0;
|
||||
if (sid[0]=='*') {
|
||||
/* For testing, pick a peer and call them */
|
||||
int bin,slot;
|
||||
for(bin=0;bin<overlay_bin_count;bin++)
|
||||
for(slot=0;slot<overlay_bin_size;slot++)
|
||||
{
|
||||
if (!overlay_nodes[bin][slot].sid[0])
|
||||
continue;
|
||||
tohex(sid, overlay_nodes[bin][slot].sid, SID_SIZE);
|
||||
/* For testing, pick any peer and call them */
|
||||
int bin, slot;
|
||||
for (bin = 0; bin < overlay_bin_count; bin++)
|
||||
for (slot = 0; slot < overlay_bin_size; slot++) {
|
||||
if (overlay_nodes[bin][slot].sid[0]) {
|
||||
memcpy(sid, overlay_nodes[bin][slot].sid, SID_SIZE);
|
||||
gotSid = 1;
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
}
|
||||
if (!gotSid)
|
||||
WRITE_STR(c->alarm.poll.fd,"\nERROR:no known peers, so cannot place call\n");
|
||||
} else {
|
||||
// pack the binary representation of the sid into the same buffer.
|
||||
stowSid(sid,0,sid);
|
||||
if (stowSid((unsigned char*)sid, 0, sid) == -1)
|
||||
WRITE_STR(c->alarm.poll.fd,"\nERROR:invalid SID, so cannot place call\n");
|
||||
else
|
||||
gotSid = 1;
|
||||
}
|
||||
|
||||
int cn=0,in=0,kp=0;
|
||||
if(!keyring_next_identity(keyring,&cn,&in,&kp))
|
||||
{
|
||||
if (gotSid) {
|
||||
int cn=0, in=0, kp=0;
|
||||
if (!keyring_next_identity(keyring, &cn, &in, &kp))
|
||||
WRITE_STR(c->alarm.poll.fd,"\nERROR:no local identity, so cannot place call\n");
|
||||
else {
|
||||
vomp_dial(keyring->contexts[cn]->identities[in]->keypairs[kp]->public_key, (unsigned char *)sid, localDid, remoteDid);
|
||||
}
|
||||
else {
|
||||
vomp_dial(keyring->contexts[cn]->identities[in]
|
||||
->keypairs[kp]->public_key, sid, localDid, remoteDid);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (sscanf(cmd,"status %x",&callSessionToken)==1) {
|
||||
int i;
|
||||
for(i=0;i<vomp_call_count;i++)
|
||||
@ -427,10 +428,6 @@ int monitor_process_command(struct monitor_context *c)
|
||||
} else if (sscanf(cmd,"dtmf %x %s",&callSessionToken,digits)==2) {
|
||||
vomp_call_state *call=vomp_find_call_by_session(callSessionToken);
|
||||
if (call){
|
||||
/* One digit per sample block. */
|
||||
mdp.vompevent.audio_sample_codec=VOMP_CODEC_DTMF;
|
||||
mdp.vompevent.audio_sample_bytes=1;
|
||||
|
||||
int i;
|
||||
for(i=0;i<strlen(digits);i++) {
|
||||
int digit=vomp_parse_dtmf_digit(digits[i]);
|
||||
@ -438,12 +435,10 @@ int monitor_process_command(struct monitor_context *c)
|
||||
snprintf(msg,1024,"\nERROR: invalid DTMF digit 0x%02x\n",digit);
|
||||
WRITE_STR(c->alarm.poll.fd,msg);
|
||||
}
|
||||
|
||||
/* 80ms standard tone duration, so that it is a multiple
|
||||
of the majority of codec time units (70ms is the nominal
|
||||
DTMF tone length for most systems). */
|
||||
|
||||
char code = digit <<4;
|
||||
unsigned char code = digit <<4;
|
||||
vomp_send_status_remote_audio(call, VOMP_CODEC_DTMF, &code, 1);
|
||||
}
|
||||
}
|
||||
|
1
serval.h
1
serval.h
@ -1455,6 +1455,7 @@ int vomp_parse_dtmf_digit(char c);
|
||||
int vomp_dial(unsigned char *local_sid, unsigned char *remote_sid, char *local_did, char *remote_did);
|
||||
int vomp_pickup(vomp_call_state *call);
|
||||
int vomp_hangup(vomp_call_state *call);
|
||||
int vomp_send_status_remote_audio(vomp_call_state *call, int audio_codec, const unsigned char *audio, int audio_length);
|
||||
|
||||
|
||||
typedef struct command_line_option {
|
||||
|
6
vomp.c
6
vomp.c
@ -184,7 +184,7 @@ vomp_call_state *vomp_find_or_create_call(unsigned char *remote_sid,
|
||||
/* send updated call status to end-point and to any interested listeners as
|
||||
appropriate */
|
||||
|
||||
int vomp_send_status_remote_audio(vomp_call_state *call, int audio_codec, char *audio, int audio_length)
|
||||
int vomp_send_status_remote_audio(vomp_call_state *call, int audio_codec, const unsigned char *audio, int audio_length)
|
||||
{
|
||||
overlay_mdp_frame mdp;
|
||||
|
||||
@ -298,7 +298,7 @@ int vomp_send_status_remote(vomp_call_state *call){
|
||||
return vomp_send_status_remote_audio(call, 0, NULL, 0);
|
||||
}
|
||||
|
||||
int vomp_send_mdp_status_audio(vomp_call_state *call, int audio_codec, unsigned int start_time, unsigned int end_time, char *audio, int audio_length){
|
||||
int vomp_send_mdp_status_audio(vomp_call_state *call, int audio_codec, unsigned int start_time, unsigned int end_time, const unsigned char *audio, int audio_length){
|
||||
if (audio && audio_length && vomp_sample_size(audio_codec)!=audio_length)
|
||||
return WHY("Audio frame is the wrong length");
|
||||
|
||||
@ -404,7 +404,7 @@ int vomp_process_audio(vomp_call_state *call,unsigned int sender_duration,overla
|
||||
// WHYF("got here (payload has %d bytes)",mdp->in.payload_length);
|
||||
|
||||
/* Get end time marker for sample block collection */
|
||||
unsigned int e=0, s=0, duration;
|
||||
unsigned int e=0, s=0;
|
||||
e=mdp->in.payload[ofs++]<<24;
|
||||
e|=mdp->in.payload[ofs++]<<16;
|
||||
e|=mdp->in.payload[ofs++]<<8;
|
||||
|
Loading…
Reference in New Issue
Block a user