From ab7bdb2634ca1866bb9c8db53e7f5848b8146f8e Mon Sep 17 00:00:00 2001 From: z3bra Date: Fri, 25 Nov 2016 17:29:00 +0100 Subject: Cancel calls ringing longer than RINGINGDELAY --- ratox.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ratox.c b/ratox.c index 6bf8e38..3953fa0 100644 --- a/ratox.c +++ b/ratox.c @@ -448,7 +448,7 @@ cancelcall(struct friend *f, char *action) { logmsg(": %s : Audio > %s\n", f->name, action); - if (f->av.state & TRANSMITTING) { + if (f->av.state & TRANSMITTING || f->av.state & RINGING) { if (!toxav_call_control(toxav, f->num, TOXAV_CALL_CONTROL_CANCEL, NULL)) weprintf("Failed to terminate call\n"); } @@ -1545,6 +1545,7 @@ loop(void) struct friend *f, *ftmp; struct request *req, *rtmp; struct timeval tv; + struct timespec callstart, now; fd_set rfds; time_t t0, t1; size_t i; @@ -1598,7 +1599,7 @@ loop(void) if (f->tx.state == TRANSFER_NONE) FD_APPEND(f->fd[FFILE_IN]); - if (!f->av.state || (f->av.state & OUTGOING)) + if (!f->av.state || ((f->av.state & TRANSMITTING) && (f->av.state & OUTGOING))) FD_APPEND(f->fd[FCALL_IN]); } FD_APPEND(f->fd[FREMOVE]); @@ -1671,7 +1672,13 @@ loop(void) if (f->av.state == TRANSMITTING) cancelcall(f, "Hung up"); + if (f->av.state & RINGING) { + if (f->av.state & OUTGOING) { + clock_gettime(CLOCK_MONOTONIC, &now); + if (now.tv_sec - callstart.tv_sec > RINGINGDELAY) + cancelcall(f, "Timeout"); + } if (!(f->av.state & INCOMING)) continue; if (!toxav_answer(toxav, f->num, AUDIOBITRATE, 0, NULL)) { @@ -1754,6 +1761,7 @@ loop(void) fiforeset(f->dirfd, &f->fd[FCALL_IN], ffiles[FCALL_IN]); break; } + clock_gettime(CLOCK_MONOTONIC, &callstart); f->av.n = 0; f->av.lastsent.tv_sec = 0; f->av.lastsent.tv_nsec = 0; -- cgit v1.2.3