static int relaxdtmf = 0;
+static int globalrtptimeout = 0;
+
+static int globalrtpholdtimeout = 0;
+
static int usecnt =0;
static ast_mutex_t usecnt_lock = AST_MUTEX_INITIALIZER;
int maxtime; /* Max time for first response */
int initid; /* Auto-congest ID if appropriate */
int autokillid; /* Auto-kill ID */
+ time_t lastrtprx; /* Last RTP received */
+ int rtptimeout; /* RTP timeout time */
+ int rtpholdtimeout; /* RTP timeout when on hold */
int subscribed;
int stateid;
int expire;
int expiry;
int capability;
+ int rtptimeout;
+ int rtpholdtimeout;
int insecure;
int nat;
int canreinvite;
ast_mutex_unlock(&usecnt_lock);
ast_update_use_count();
- needdestroy = 1;
+ needdestroy = 1;
/* Start the process if it's not already started */
if (!p->alreadygone && !ast_strlen_zero(p->initreq.data)) {
if (needcancel) {
struct sip_pvt *p = ast->pvt->pvt;
ast_mutex_lock(&p->lock);
fr = sip_rtp_read(ast, p);
+ time(&p->lastrtprx);
ast_mutex_unlock(&p->lock);
return fr;
}
/* Assign default music on hold class */
strncpy(p->musicclass, globalmusicclass, sizeof(p->musicclass));
p->dtmfmode = globaldtmfmode;
+ p->rtptimeout = globalrtptimeout;
+ p->rtpholdtimeout = globalrtpholdtimeout;
p->capability = capability;
if (p->dtmfmode & SIP_DTMF_RFC2833)
p->noncodeccapability |= AST_RTP_DTMF;
int sendonly = 0;
int x;
+ /* Update our last rtprx when we receive an SDP, too */
+ time(&p->lastrtprx);
+
/* Get codec and RTP info from SDP */
if (strcasecmp(get_header(req, "Content-Type"), "application/sdp")) {
ast_log(LOG_NOTICE, "Content is '%s', not 'application/sdp'\n", get_header(req, "Content-Type"));
add_line(resp, m2);
add_line(resp, a2);
}
+ /* Update lastrtprx when we send our SDP */
+ time(&p->lastrtprx);
return 0;
}
}
transmit_response(p, "200 OK", req);
return;
+ } else {
+ transmit_response(p, "481 Call leg/transaction does not exist", req);
+ p->needdestroy = 1;
}
- transmit_response(p, "481 Call leg/transaction does not exist", req);
return;
}
/* Other type of INFO message, not really understood by Asterisk */
/* This call is no longer outgoing if it ever was */
p->outgoing = 0;
/* This also counts as a pending invite */
- p->pendinginvite = 1;
+ p->pendinginvite = seqno;
copy_request(&p->initreq, req);
check_via(p, req);
if (!ast_strlen_zero(get_header(req, "Content-Type"))) {
ast_verbose("Receiving DTMF!\n");
receive_info(p, req);
}
- transmit_response(p, "200 OK", req);
} else if (!strcasecmp(cmd, "REGISTER")) {
/* Use this as the basis */
if (sip_debug_test_pvt(p))
sip_scheddestroy(p, 15*1000);
}
} else if (!strcasecmp(cmd, "ACK")) {
- /* Uhm, I haven't figured out the point of the ACK yet. Are we
- supposed to retransmit responses until we get an ack?
- Make sure this is on a valid call */
- p->pendinginvite = 0;
- __sip_ack(p, seqno, FLAG_RESPONSE);
- if (!ast_strlen_zero(get_header(req, "Content-Type"))) {
- if (process_sdp(p, req))
- return -1;
- }
- check_pendings(p);
+ /* Make sure we don't ignore this */
+ if (seqno == p->pendinginvite) {
+ p->pendinginvite = 0;
+ __sip_ack(p, seqno, FLAG_RESPONSE);
+ if (!ast_strlen_zero(get_header(req, "Content-Type"))) {
+ if (process_sdp(p, req))
+ return -1;
+ }
+ check_pendings(p);
+ }
if (!p->lastinvite && ast_strlen_zero(p->randdata))
p->needdestroy = 1;
} else if (!strcasecmp(cmd, "SIP/2.0")) {
/* Check for interfaces needing to be killed */
ast_mutex_lock(&iflock);
restartsearch:
+ time(&t);
sip = iflist;
while(sip) {
ast_mutex_lock(&sip->lock);
+ if (sip->rtp && sip->lastrtprx && (sip->rtptimeout || sip->rtpholdtimeout)) {
+ if (t > sip->lastrtprx + sip->rtptimeout) {
+ /* Might be a timeout now -- see if we're on hold */
+ struct sockaddr_in sin;
+ ast_rtp_get_peer(sip->rtp, &sin);
+ if (sin.sin_addr.s_addr ||
+ (sip->rtpholdtimeout &&
+ (t > sip->lastrtprx + sip->rtpholdtimeout))) {
+ /* Needs a hangup */
+ if (sip->rtptimeout) {
+ while(sip->owner && ast_mutex_trylock(&sip->owner->lock)) {
+ ast_mutex_unlock(&sip->lock);
+ usleep(1);
+ ast_mutex_lock(&sip->lock);
+ }
+ if (sip->owner) {
+ ast_log(LOG_NOTICE, "Disconnecting call '%s' for lack of RTP activity in %ld seconds\n", sip->owner->name, (long)(t - sip->lastrtprx));
+ /* Issue a softhangup */
+ ast_softhangup(sip->owner, AST_SOFTHANGUP_DEV);
+ ast_mutex_unlock(&sip->owner->lock);
+ }
+ }
+ }
+ }
+ }
if (sip->needdestroy && !sip->packets) {
ast_mutex_unlock(&sip->lock);
__sip_destroy(sip, 1);
peer->canreinvite = globalcanreinvite;
peer->dtmfmode = globaldtmfmode;
peer->nat = globalnat;
+ peer->rtptimeout = globalrtptimeout;
+ peer->rtpholdtimeout = globalrtpholdtimeout;
peer->selfdestruct = 1;
peer->dynamic = 1;
reg_source_db(peer);
peer->capability = capability;
/* Assume can reinvite */
peer->canreinvite = globalcanreinvite;
+ peer->rtptimeout = globalrtptimeout;
+ peer->rtpholdtimeout = globalrtpholdtimeout;
peer->dtmfmode = 0;
while(v) {
if (!strcasecmp(v->name, "secret"))
peer->insecure = 1;
else
peer->insecure = 0;
+ } else if (!strcasecmp(v->name, "rtptimeout")) {
+ if ((sscanf(v->value, "%d", &peer->rtptimeout) != 1) || (peer->rtptimeout < 0)) {
+ ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno);
+ peer->rtptimeout = globalrtptimeout;
+ }
+ } else if (!strcasecmp(v->name, "rtpholdtimeout")) {
+ if ((sscanf(v->value, "%d", &peer->rtpholdtimeout) != 1) || (peer->rtpholdtimeout < 0)) {
+ ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno);
+ peer->rtpholdtimeout = globalrtpholdtimeout;
+ }
} else if (!strcasecmp(v->name, "qualify")) {
if (!strcasecmp(v->value, "no")) {
peer->maxms = 0;
globalcanreinvite = REINVITE_INVITE;
videosupport = 0;
relaxdtmf = 0;
+ globalrtptimeout = 0;
+ globalrtpholdtimeout = 0;
pedanticsipchecking=0;
v = ast_variable_browse(cfg, "general");
while(v) {
ast_log(LOG_WARNING, "Unknown dtmf mode '%s', using rfc2833\n", v->value);
globaldtmfmode = SIP_DTMF_RFC2833;
}
+ } else if (!strcasecmp(v->name, "rtptimeout")) {
+ if ((sscanf(v->value, "%d", &globalrtptimeout) != 1) || (globalrtptimeout < 0)) {
+ ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno);
+ globalrtptimeout = 0;
+ }
+ } else if (!strcasecmp(v->name, "rtpholdtimeout")) {
+ if ((sscanf(v->value, "%d", &globalrtpholdtimeout) != 1) || (globalrtpholdtimeout < 0)) {
+ ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno);
+ globalrtpholdtimeout = 0;
+ }
} else if (!strcasecmp(v->name, "videosupport")) {
videosupport = ast_true(v->value);
} else if (!strcasecmp(v->name, "notifymimetype")) {