mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-20 05:37:57 +00:00
fixed various bugs in servald monitor. now receives commands,
and can act on them.
This commit is contained in:
parent
6718d06421
commit
91d875d70a
38
monitor.c
38
monitor.c
@ -39,7 +39,7 @@ struct ucred {
|
|||||||
1 for VoMP call
|
1 for VoMP call
|
||||||
but spares never hurt, and the cost is low
|
but spares never hurt, and the cost is low
|
||||||
*/
|
*/
|
||||||
#define MONITOR_LINE_LENGTH 80
|
#define MONITOR_LINE_LENGTH 160
|
||||||
#define MONITOR_DATA_SIZE MAX_AUDIO_BYTES
|
#define MONITOR_DATA_SIZE MAX_AUDIO_BYTES
|
||||||
struct monitor_context {
|
struct monitor_context {
|
||||||
#define MONITOR_VOMP (1<<0)
|
#define MONITOR_VOMP (1<<0)
|
||||||
@ -101,7 +101,7 @@ int monitor_setup_sockets()
|
|||||||
int res = setsockopt(monitor_named_socket, SOL_SOCKET, SO_RCVBUF,
|
int res = setsockopt(monitor_named_socket, SOL_SOCKET, SO_RCVBUF,
|
||||||
&send_buffer_size, sizeof(send_buffer_size));
|
&send_buffer_size, sizeof(send_buffer_size));
|
||||||
if (res) WHYF("setsockopt() failed: errno=%d",errno);
|
if (res) WHYF("setsockopt() failed: errno=%d",errno);
|
||||||
|
else WHY("Monitor server socket setup");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,6 +190,7 @@ int monitor_poll()
|
|||||||
close(s);
|
close(s);
|
||||||
} else {
|
} else {
|
||||||
struct monitor_context *c=&monitor_sockets[monitor_socket_count];
|
struct monitor_context *c=&monitor_sockets[monitor_socket_count];
|
||||||
|
c->socket=s;
|
||||||
c->line_length=0;
|
c->line_length=0;
|
||||||
c->state=MONITOR_STATE_COMMAND;
|
c->state=MONITOR_STATE_COMMAND;
|
||||||
monitor_socket_count++;
|
monitor_socket_count++;
|
||||||
@ -224,11 +225,11 @@ int monitor_poll()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
bytes=read(c->socket,&c->line[c->line_length],1);
|
bytes=read(c->socket,&c->line[c->line_length],1);
|
||||||
if (bytes>0) WHYF("Read monitor byte 0x%02x",c->line[c->line_length]);
|
|
||||||
if (bytes==-1) {
|
if (bytes==-1) {
|
||||||
switch(errno) {
|
switch(errno) {
|
||||||
case EAGAIN: case EINTR:
|
case EAGAIN: case EINTR:
|
||||||
/* transient errors */
|
/* transient errors */
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
/* all other errors; close socket */
|
/* all other errors; close socket */
|
||||||
WHYF("Tearing down monitor client #%d due to errno=%d",
|
WHYF("Tearing down monitor client #%d due to errno=%d",
|
||||||
@ -246,13 +247,16 @@ int monitor_poll()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bytes>0) c->line_length+=bytes;
|
if (bytes>0&&(c->line[c->line_length]!='\r'))
|
||||||
if (c->line[c->line_length-1]=='\n') {
|
{
|
||||||
/* got command */
|
c->line_length+=bytes;
|
||||||
c->line[c->line_length]=0; /* trim new line for easier parsing */
|
if (c->line[c->line_length-1]=='\n') {
|
||||||
monitor_process_command(i,c->line);
|
/* got command */
|
||||||
break;
|
c->line[c->line_length-1]=0; /* trim new line for easier parsing */
|
||||||
}
|
monitor_process_command(i,c->line);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MONITOR_STATE_DATA:
|
case MONITOR_STATE_DATA:
|
||||||
@ -263,6 +267,7 @@ int monitor_poll()
|
|||||||
switch(errno) {
|
switch(errno) {
|
||||||
case EAGAIN: case EINTR:
|
case EAGAIN: case EINTR:
|
||||||
/* transient errors */
|
/* transient errors */
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
/* all other errors; close socket */
|
/* all other errors; close socket */
|
||||||
WHYF("Tearing down monitor client #%d due to errno=%d",
|
WHYF("Tearing down monitor client #%d due to errno=%d",
|
||||||
@ -301,11 +306,12 @@ int monitor_poll()
|
|||||||
int monitor_process_command(int index,char *cmd)
|
int monitor_process_command(int index,char *cmd)
|
||||||
{
|
{
|
||||||
int callSessionToken,sampleType,bytes;
|
int callSessionToken,sampleType,bytes;
|
||||||
char sid[80],localDid[80],remoteDid[80];
|
char sid[MONITOR_LINE_LENGTH],localDid[MONITOR_LINE_LENGTH];
|
||||||
|
char remoteDid[MONITOR_LINE_LENGTH];
|
||||||
overlay_mdp_frame mdp;
|
overlay_mdp_frame mdp;
|
||||||
mdp.packetTypeAndFlags=MDP_VOMPEVENT;
|
mdp.packetTypeAndFlags=MDP_VOMPEVENT;
|
||||||
|
|
||||||
WHYF("Received monitor instruction: %s\n",cmd);
|
WHYF("Received monitor instruction: '%s'",cmd);
|
||||||
|
|
||||||
struct monitor_context *c=&monitor_sockets[index];
|
struct monitor_context *c=&monitor_sockets[index];
|
||||||
c->line_length=0;
|
c->line_length=0;
|
||||||
@ -313,7 +319,7 @@ int monitor_process_command(int index,char *cmd)
|
|||||||
fcntl(c->socket,F_SETFL,
|
fcntl(c->socket,F_SETFL,
|
||||||
fcntl(c->socket, F_GETFL, NULL)|O_NONBLOCK);
|
fcntl(c->socket, F_GETFL, NULL)|O_NONBLOCK);
|
||||||
|
|
||||||
if (strlen(cmd)>80) {
|
if (strlen(cmd)>MONITOR_LINE_LENGTH) {
|
||||||
write(c->socket,"ERROR:Command too long\n",
|
write(c->socket,"ERROR:Command too long\n",
|
||||||
strlen("ERROR:Command too long\n"));
|
strlen("ERROR:Command too long\n"));
|
||||||
return -1;
|
return -1;
|
||||||
@ -338,18 +344,18 @@ int monitor_process_command(int index,char *cmd)
|
|||||||
c->flags|=MONITOR_RHIZOME;
|
c->flags|=MONITOR_RHIZOME;
|
||||||
else if (!strcasecmp(cmd,"ignore rhizome"))
|
else if (!strcasecmp(cmd,"ignore rhizome"))
|
||||||
c->flags&=~MONITOR_RHIZOME;
|
c->flags&=~MONITOR_RHIZOME;
|
||||||
else if (sscanf(cmd,"CREATECALL:%s:%s:%s",sid,localDid,remoteDid)==3) {
|
else if (sscanf(cmd,"call %s %s %s",sid,localDid,remoteDid)==3) {
|
||||||
mdp.vompevent.flags=VOMPEVENT_DIAL;
|
mdp.vompevent.flags=VOMPEVENT_DIAL;
|
||||||
if (overlay_mdp_getmyaddr(0,&mdp.vompevent.local_sid[0])) return -1;
|
if (overlay_mdp_getmyaddr(0,&mdp.vompevent.local_sid[0])) return -1;
|
||||||
stowSid(&mdp.vompevent.remote_sid[0],0,sid);
|
stowSid(&mdp.vompevent.remote_sid[0],0,sid);
|
||||||
vomp_mdp_event(&mdp,NULL,0);
|
vomp_mdp_event(&mdp,NULL,0);
|
||||||
}
|
}
|
||||||
else if (sscanf(cmd,"PICKUP:%x",&callSessionToken)==1) {
|
else if (sscanf(cmd,"pickup %x",&callSessionToken)==1) {
|
||||||
mdp.vompevent.flags=VOMPEVENT_PICKUP;
|
mdp.vompevent.flags=VOMPEVENT_PICKUP;
|
||||||
mdp.vompevent.call_session_token=callSessionToken;
|
mdp.vompevent.call_session_token=callSessionToken;
|
||||||
vomp_mdp_event(&mdp,NULL,0);
|
vomp_mdp_event(&mdp,NULL,0);
|
||||||
}
|
}
|
||||||
else if (sscanf(cmd,"HANGUP:%x",&callSessionToken)==1) {
|
else if (sscanf(cmd,"hangup %x",&callSessionToken)==1) {
|
||||||
mdp.vompevent.flags=VOMPEVENT_HANGUP;
|
mdp.vompevent.flags=VOMPEVENT_HANGUP;
|
||||||
mdp.vompevent.call_session_token=callSessionToken;
|
mdp.vompevent.call_session_token=callSessionToken;
|
||||||
vomp_mdp_event(&mdp,NULL,0);
|
vomp_mdp_event(&mdp,NULL,0);
|
||||||
|
Loading…
Reference in New Issue
Block a user