int callno = (long)data;
/* Ping only if it's real not if it's bridged */
ast_mutex_lock(&iaxsl[callno]);
- if (iaxs[callno] && iaxs[callno]->lagid != -1) {
+ if (iaxs[callno] && iaxs[callno]->lagid > -1) {
send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_LAGRQ, 0, NULL, 0, -1);
iaxs[callno]->lagid = iax2_sched_add(sched, lagrq_time * 1000, send_lagrq, data);
}
static void iax2_frame_free(struct iax_frame *fr)
{
- if (fr->retrans > -1)
- ast_sched_del(sched, fr->retrans);
+ AST_SCHED_DEL(sched, fr->retrans);
iax_frame_free(fr);
}
ast_clear_flag(pvt, IAX_MAXAUTHREQ);
}
/* No more pings or lagrq's */
- if (pvt->pingid > -1)
- ast_sched_del(sched, pvt->pingid);
- pvt->pingid = -1;
- if (pvt->lagid > -1)
- ast_sched_del(sched, pvt->lagid);
- pvt->lagid = -1;
- if (pvt->autoid > -1)
- ast_sched_del(sched, pvt->autoid);
- pvt->autoid = -1;
- if (pvt->authid > -1)
- ast_sched_del(sched, pvt->authid);
- pvt->authid = -1;
- if (pvt->initid > -1)
- ast_sched_del(sched, pvt->initid);
- pvt->initid = -1;
- if (pvt->jbid > -1)
- ast_sched_del(sched, pvt->jbid);
- pvt->jbid = -1;
+ AST_SCHED_DEL(sched, pvt->pingid);
+ AST_SCHED_DEL(sched, pvt->lagid);
+ AST_SCHED_DEL(sched, pvt->autoid);
+ AST_SCHED_DEL(sched, pvt->authid);
+ AST_SCHED_DEL(sched, pvt->initid);
+ AST_SCHED_DEL(sched, pvt->jbid);
}
/*!
when = ast_tvdiff_ms(ast_tvnow(), pvt->rxcore);
when = jb_next(pvt->jb) - when;
-
- if(when <= 0) {
+
+ if (when <= 0) {
/* XXX should really just empty until when > 0.. */
when = 1;
}
jb_reset(iaxs[fr->callno]->jb);
- if (iaxs[fr->callno]->jbid > -1)
- ast_sched_del(sched, iaxs[fr->callno]->jbid);
-
- iaxs[fr->callno]->jbid = -1;
+ AST_SCHED_DEL(sched, iaxs[fr->callno]->jbid);
/* deliver this frame now */
if (tsout)
}
}
if (f.frametype == AST_FRAME_IAX) {
- if (iaxs[fr->callno]->initid > -1) {
- /* Don't auto congest anymore since we've gotten something usefulb ack */
- ast_sched_del(sched, iaxs[fr->callno]->initid);
- iaxs[fr->callno]->initid = -1;
- }
+ AST_SCHED_DEL(sched, iaxs[fr->callno]->initid);
/* Handle the IAX pseudo frame itself */
if (iaxdebug)
ast_debug(1, "IAX subclass %d received\n", f.subclass);
}
} else {
/* Non-dynamic. Make sure we become that way if we're not */
- if (peer->expire > -1)
- ast_sched_del(sched, peer->expire);
- peer->expire = -1;
+ AST_SCHED_DEL(sched, peer->expire);
ast_clear_flag(peer, IAX_DYNAMIC);
if (ast_dnsmgr_lookup(v->value, &peer->addr.sin_addr, &peer->dnsmgr))
return peer_unref(peer);
AST_LIST_LOCK(®istrations);
while ((reg = AST_LIST_REMOVE_HEAD(®istrations, entry))) {
- if (reg->expire > -1)
- ast_sched_del(sched, reg->expire);
+ AST_SCHED_DEL(sched, reg->expire);
if (reg->callno) {
ast_mutex_lock(&iaxsl[reg->callno]);
if (iaxs[reg->callno]) {
int useglobal_nat, const int intended_method);
static int __sip_autodestruct(const void *data);
static void sip_scheddestroy(struct sip_pvt *p, int ms);
-static void sip_cancel_destroy(struct sip_pvt *p);
+static int sip_cancel_destroy(struct sip_pvt *p);
static struct sip_pvt *sip_destroy(struct sip_pvt *p);
static void __sip_destroy(struct sip_pvt *p, int lockowner, int lockdialoglist);
static void __sip_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod);
if (xmitres == XMIT_ERROR) { /* Serious network trouble, no need to try again */
append_history(pkt->owner, "XmitErr", "%s", pkt->is_fatal ? "(Critical)" : "(Non-critical)");
- ast_sched_del(sched, pkt->retransid); /* No more retransmission */
- pkt->retransid = -1;
return AST_FAILURE;
- } else
+ } else {
+ /* Schedule retransmission */
+ pkt->retransid = ast_sched_add_variable(sched, siptimer_a, retrans_pkt, pkt, 1);
return AST_SUCCESS;
+ }
}
/*! \brief Kill a SIP dialog (called only by the scheduler)
}
if (sip_debug_test_pvt(p))
ast_verbose("Scheduling destruction of SIP dialog '%s' in %d ms (Method: %s)\n", p->callid, ms, sip_methods[p->method].text);
- sip_cancel_destroy(p);
+ if (sip_cancel_destroy(p))
+ ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n");
+
if (p->do_history)
append_history(p, "SchedDestroy", "%d ms", ms);
p->autokillid = ast_sched_add(sched, ms, __sip_autodestruct, dialog_ref(p));
* Be careful as this also absorbs the reference - if you call it
* from within the scheduler, this might be the last reference.
*/
-static void sip_cancel_destroy(struct sip_pvt *p)
+static int sip_cancel_destroy(struct sip_pvt *p)
{
+ int res = 0;
if (p->autokillid > -1) {
- ast_sched_del(sched, p->autokillid);
- append_history(p, "CancelDestroy", "");
- p->autokillid = -1;
+ if (!(res = ast_sched_del(sched, p->autokillid))) {
+ append_history(p, "CancelDestroy", "");
+ p->autokillid = -1;
+ }
dialog_unref(p);
}
+ return res;
}
/*! \brief Acknowledges receipt of a packet and stops retransmission */
if (cur->retransid > -1) {
if (sipdebug)
ast_debug(4, "** SIP TIMER: Cancelling retransmit of packet (reply received) Retransid #%d\n", cur->retransid);
- ast_sched_del(sched, cur->retransid);
- cur->retransid = -1;
}
UNLINK(cur, p->packets, prev);
dialog_unref(cur->owner);
if (cur->retransid > -1) {
if (sipdebug)
ast_debug(4, "*** SIP TIMER: Cancelling retransmission #%d - %s (got response)\n", cur->retransid, sip_methods[sipmethod].text);
- ast_sched_del(sched, cur->retransid);
- cur->retransid = -1;
}
+ AST_SCHED_DEL(sched, cur->retransid);
res = 0;
break;
}
*
* NOTE: once peer is refcounted, this probably is no longer necessary.
*/
- while (peer->expire > -1 && ast_sched_del(sched, peer->expire))
- usleep(1);
- while (peer->pokeexpire > -1 && ast_sched_del(sched, peer->pokeexpire))
- usleep(1);
+ AST_SCHED_DEL(sched, peer->expire);
+ AST_SCHED_DEL(sched, peer->pokeexpire);
register_peer_exten(peer, FALSE);
ast_free_ha(peer->ha);
ast_debug(3, "Destroying active SIP dialog for registry %s@%s\n", reg->username, reg->hostname);
reg->call = sip_destroy(reg->call);
}
- if (reg->expire > -1)
- ast_sched_del(sched, reg->expire);
- if (reg->timeout > -1)
- ast_sched_del(sched, reg->timeout);
+ AST_SCHED_DEL(sched, reg->expire);
+ AST_SCHED_DEL(sched, reg->timeout);
ast_string_field_free_memory(reg);
regobjs--;
ast_free(reg);
if (p->stateid > -1)
ast_extension_state_del(p->stateid, NULL);
- if (p->initid > -1)
- ast_sched_del(sched, p->initid);
- if (p->waitid > -1)
- ast_sched_del(sched, p->waitid);
- if (p->autokillid > -1)
- ast_sched_del(sched, p->autokillid);
+ AST_SCHED_DEL(sched, p->initid);
+ AST_SCHED_DEL(sched, p->waitid);
+ AST_SCHED_DEL(sched, p->autokillid);
if (p->rtp)
ast_rtp_destroy(p->rtp);
/* remove all current packets in this dialog */
while((cp = p->packets)) {
p->packets = p->packets->next;
- if (cp->retransid > -1)
- ast_sched_del(sched, cp->retransid);
+ AST_SCHED_DEL(sched, cp->retransid);
dialog_unref(cp->owner);
ast_free(cp);
}
update_call_counter(p, DEC_CALL_LIMIT);
}
ast_debug(4, "SIP Transfer: Not hanging up right now... Rescheduling hangup for %s.\n", p->callid);
- if (p->autokillid > -1)
- sip_cancel_destroy(p);
+ if (p->autokillid > -1 && sip_cancel_destroy(p))
+ ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n");
sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
ast_clear_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Really hang up next time */
p->needdestroy = 0;
but we can't send one while we have "INVITE" outstanding. */
ast_set_flag(&p->flags[0], SIP_PENDINGBYE);
ast_clear_flag(&p->flags[0], SIP_NEEDREINVITE);
- if (p->waitid)
- ast_sched_del(sched, p->waitid);
- p->waitid = -1;
- sip_cancel_destroy(p);
+ AST_SCHED_DEL(sched, p->waitid);
+ if (sip_cancel_destroy(p))
+ ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n");
}
}
}
global_reg_timeout * 1000, sip_reg_timeout, r);
ast_log(LOG_WARNING, "Still have a registration timeout for %s@%s (create_addr() error), %d\n", r->username, r->hostname, r->timeout);
} else {
- r->timeout = ast_sched_add(sched, global_reg_timeout*1000, sip_reg_timeout, r);
+ r->timeout = ast_sched_add(sched, global_reg_timeout * 1000, sip_reg_timeout, r);
ast_log(LOG_WARNING, "Probably a DNS error for registration to %s@%s, trying REGISTER again (after %d seconds)\n", r->username, r->hostname, global_reg_timeout);
}
r->regattempts++;
} else if (!strcasecmp(curi, "*") || !expiry) { /* Unregister this peer */
/* This means remove all registrations and return OK */
memset(&peer->addr, 0, sizeof(peer->addr));
- if (peer->expire > -1)
- ast_sched_del(sched, peer->expire);
- peer->expire = -1;
+ AST_SCHED_DEL(sched, peer->expire);
destroy_association(peer);
if (!ast_strlen_zero(curi) && ast_strlen_zero(peer->username))
ast_copy_string(peer->username, curi, sizeof(peer->username));
- if (peer->expire > -1) {
- ast_sched_del(sched, peer->expire);
- peer->expire = -1;
- }
+ AST_SCHED_DEL(sched, peer->expire);
if (expiry > max_expiry)
expiry = max_expiry;
if (expiry < min_expiry)
switch(state) {
case AST_EXTENSION_DEACTIVATED: /* Retry after a while */
case AST_EXTENSION_REMOVED: /* Extension is gone */
- if (p->autokillid > -1)
- sip_cancel_destroy(p); /* Remove subscription expiry for renewals */
+ if (p->autokillid > -1 && sip_cancel_destroy(p)) /* Remove subscription expiry for renewals */
+ ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n");
sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); /* Delete subscription in 32 secs */
ast_verb(2, "Extension state: Watcher for hint %s %s. Notify User %s\n", exten, state == AST_EXTENSION_DEACTIVATED ? "deactivated" : "removed", p->username);
p->stateid = -1;
if (ast_test_flag(&p->flags[1], SIP_PAGE2_REGISTERTRYING))
transmit_response(p, "100 Trying", req);
if (!(res = check_auth(p, req, peer->name, peer->secret, peer->md5secret, SIP_REGISTER, uri, XMIT_UNRELIABLE, req->ignore))) {
- sip_cancel_destroy(p);
+ if (sip_cancel_destroy(p))
+ ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n");
/* We have a successful registration attempt with proper authentication,
now, update the peer */
peer = temp_peer(name);
if (peer) {
ASTOBJ_CONTAINER_LINK(&peerl, peer);
- sip_cancel_destroy(p);
+ if (sip_cancel_destroy(p))
+ ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n");
switch (parse_register_contact(p, peer, req)) {
case PARSE_REGISTER_FAILED:
ast_log(LOG_WARNING, "Failed to parse contact info\n");
}
/* Acknowledge sequence number - This only happens on INVITE from SIP-call */
- if (p->initid > -1) {
- /* Don't auto congest anymore since we've gotten something useful back */
- ast_sched_del(sched, p->initid);
- p->initid = -1;
- }
+ /* Don't auto congest anymore since we've gotten something useful back */
+ AST_SCHED_DEL(sched, p->initid);
/* RFC3261 says we must treat every 1xx response (but not 100)
that we don't recognize as if it was 183.
switch (resp) {
case 100: /* Trying */
case 101: /* Dialog establishment */
- if (!req->ignore && p->invitestate != INV_CANCELLED)
- sip_cancel_destroy(p);
+ if (!req->ignore && p->invitestate != INV_CANCELLED && sip_cancel_destroy(p))
+ ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n");
check_pendings(p);
break;
case 180: /* 180 Ringing */
case 182: /* 182 Queued */
- if (!req->ignore && p->invitestate != INV_CANCELLED)
- sip_cancel_destroy(p);
+ if (!req->ignore && p->invitestate != INV_CANCELLED && sip_cancel_destroy(p))
+ ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n");
if (!req->ignore && p->owner) {
ast_queue_control(p->owner, AST_CONTROL_RINGING);
if (p->owner->_state != AST_STATE_UP) {
break;
case 183: /* Session progress */
- if (!req->ignore && (p->invitestate != INV_CANCELLED))
- sip_cancel_destroy(p);
+ if (!req->ignore && (p->invitestate != INV_CANCELLED) && sip_cancel_destroy(p))
+ ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n");
/* Ignore 183 Session progress without SDP */
if (find_sdp(req)) {
if (p->invitestate != INV_CANCELLED)
break;
case 200: /* 200 OK on invite - someone's answering our call */
- if (!req->ignore && (p->invitestate != INV_CANCELLED))
- sip_cancel_destroy(p);
+ if (!req->ignore && (p->invitestate != INV_CANCELLED) && sip_cancel_destroy(p))
+ ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n");
p->authtries = 0;
if (find_sdp(req)) {
if ((res = process_sdp(p, req)) && !req->ignore)
break;
case 403: /* Forbidden */
ast_log(LOG_WARNING, "Forbidden - wrong password on authentication for REGISTER for '%s' to '%s'\n", p->registry->username, p->registry->hostname);
- ast_sched_del(sched, r->timeout);
- r->timeout = -1;
+ AST_SCHED_DEL(sched, r->timeout);
r->regstate = REG_STATE_NOAUTH;
p->needdestroy = 1;
break;
p->needdestroy = 1;
r->call = NULL;
r->regstate = REG_STATE_REJECTED;
- ast_sched_del(sched, r->timeout);
- r->timeout = -1;
+ AST_SCHED_DEL(sched, r->timeout);
break;
case 407: /* Proxy auth */
if (p->authtries == MAX_AUTHTRIES || do_register_auth(p, req, resp)) {
p->registry->regattempts = global_regattempts_max+1;
p->needdestroy = 1;
r->call = NULL;
- ast_sched_del(sched, r->timeout);
- r->timeout = -1;
+ AST_SCHED_DEL(sched, r->timeout);
break;
case 423: /* Interval too brief */
r->expiry = atoi(get_header(req, "Min-Expires"));
p->needdestroy = 1;
r->call = NULL;
r->regstate = REG_STATE_REJECTED;
- ast_sched_del(sched, r->timeout);
- r->timeout = -1;
+ AST_SCHED_DEL(sched, r->timeout);
break;
case 200: /* 200 OK */
if (!r) {
ast_debug(1, "Registration successful\n");
if (r->timeout > -1) {
ast_debug(1, "Cancelling timeout %d\n", r->timeout);
- ast_sched_del(sched, r->timeout);
}
- r->timeout=-1;
+ AST_SCHED_DEL(sched, r->timeout);
r->call = NULL;
p->registry = NULL;
/* Let this one hang around until we have all the responses */
/* set us up for re-registering */
/* figure out how long we got registered for */
- if (r->expire > -1)
- ast_sched_del(sched, r->expire);
+ AST_SCHED_DEL(sched, r->expire);
/* according to section 6.13 of RFC, contact headers override
expires headers, so check those first */
expires = 0;
p->needdestroy = 1;
} else if ((resp >= 100) && (resp < 200)) {
if (sipmethod == SIP_INVITE) {
- if (!req->ignore)
- sip_cancel_destroy(p);
+ if (!req->ignore && sip_cancel_destroy(p))
+ ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n");
if (find_sdp(req))
process_sdp(p, req);
if (p->owner) {
default: /* Errors without handlers */
if ((resp >= 100) && (resp < 200)) {
if (sipmethod == SIP_INVITE) { /* re-invite */
- if (!req->ignore)
- sip_cancel_destroy(p);
+ if (!req->ignore && sip_cancel_destroy(p))
+ ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n");
}
}
if ((resp >= 300) && (resp < 700)) {
case 503: /* Service Unavailable */
case 504: /* Server timeout */
- if (sipmethod == SIP_INVITE) { /* re-invite failed */
- sip_cancel_destroy(p);
- }
+ /* re-invite failed */
+ if (sipmethod == SIP_INVITE && sip_cancel_destroy(p))
+ ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n");
break;
}
}
if (!req->ignore) {
int newcall = (p->initreq.headers ? TRUE : FALSE);
- sip_cancel_destroy(p);
+ if (sip_cancel_destroy(p))
+ ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n");
/* This also counts as a pending invite */
p->pendinginvite = seqno;
check_via(p, req);
else
ast_debug(2, "Adding subscription for extension %s context %s for peer %s\n", p->exten, p->context, p->username);
}
- if (p->autokillid > -1)
- sip_cancel_destroy(p); /* Remove subscription expiry for renewals */
+ if (p->autokillid > -1 && sip_cancel_destroy(p)) /* Remove subscription expiry for renewals */
+ ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n");
if (p->expiry > 0)
sip_scheddestroy(p, (p->expiry + 10) * 1000); /* Set timer for destruction of call at expiration */
if (!peer->maxms || !peer->addr.sin_addr.s_addr) {
/* IF we have no IP, or this isn't to be monitored, return
immediately after clearing things out */
- if (peer->pokeexpire > -1)
- ast_sched_del(sched, peer->pokeexpire);
+ AST_SCHED_DEL(sched, peer->pokeexpire);
peer->lastms = 0;
- peer->pokeexpire = -1;
peer->call = NULL;
return 0;
}
build_via(p);
build_callid_pvt(p);
- if (peer->pokeexpire > -1)
- ast_sched_del(sched, peer->pokeexpire);
+ AST_SCHED_DEL(sched, peer->pokeexpire);
p->relatedpeer = peer;
ast_set_flag(&p->flags[0], SIP_OUTGOING);
#ifdef VOCAL_DATA_HACK
peer->host_dynamic = TRUE;
} else {
/* Non-dynamic. Make sure we become that way if we're not */
- if (peer->expire > -1)
- ast_sched_del(sched, peer->expire);
- peer->expire = -1;
+ AST_SCHED_DEL(sched, peer->expire);
peer->host_dynamic = FALSE;
srvlookup = v->value;
}
int expire = default_expiration;
char data[256];
int needqual = 0;
- if (peer->registerexpire > -1)
- ast_sched_del(sched, peer->registerexpire);
+ AST_SCHED_DEL(sched, peer->registerexpire);
peer->registerexpire = ast_sched_add(sched, (expire + 10) * 1000, do_register_expire, peer);
snprintf(data, sizeof(data), "%s:%d:%d", ast_inet_ntoa(trans->addr.sin_addr),
ntohs(trans->addr.sin_port), expire);
struct dundi_packet *pack;
while ((pack = AST_LIST_REMOVE_HEAD(p, list))) {
- if (pack->retransid > -1)
- ast_sched_del(sched, pack->retransid);
+ AST_SCHED_DEL(sched, pack->retransid);
ast_free(pack);
}
}
destroy_packets(&trans->lasttrans);
}
AST_LIST_INSERT_HEAD(&trans->lasttrans, pack, list);
- if (trans->autokillid > -1)
- ast_sched_del(sched, trans->autokillid);
- trans->autokillid = -1;
+ AST_SCHED_DEL(sched, trans->autokillid);
return 1;
}
}
{
if (pack->parent)
AST_LIST_REMOVE(&pack->parent->packets, pack, list);
- if (pack->retransid > -1)
- ast_sched_del(sched, pack->retransid);
+ AST_SCHED_DEL(sched, pack->retransid);
if (needfree)
ast_free(pack);
- else
- pack->retransid = -1;
}
static void destroy_trans(struct dundi_transaction *trans, int fromtimeout)
AST_LIST_REMOVE(&alltrans, trans, all);
destroy_packets(&trans->packets);
destroy_packets(&trans->lasttrans);
- if (trans->autokillid > -1)
- ast_sched_del(sched, trans->autokillid);
- trans->autokillid = -1;
+ AST_SCHED_DEL(sched, trans->autokillid);
if (trans->thread) {
/* If used by a thread, mark as dead and be done */
ast_set_flag(trans, FLAG_DEAD);
static void destroy_peer(struct dundi_peer *peer)
{
- if (peer->registerid > -1)
- ast_sched_del(sched, peer->registerid);
+ AST_SCHED_DEL(sched, peer->registerid);
if (peer->regtrans)
destroy_trans(peer->regtrans, 0);
- if (peer->qualifyid > -1)
- ast_sched_del(sched, peer->qualifyid);
+ AST_SCHED_DEL(sched, peer->qualifyid);
destroy_permissions(&peer->permit);
destroy_permissions(&peer->include);
ast_free(peer);
static void qualify_peer(struct dundi_peer *peer, int schedonly)
{
int when;
- if (peer->qualifyid > -1)
- ast_sched_del(sched, peer->qualifyid);
- peer->qualifyid = -1;
+ AST_SCHED_DEL(sched, peer->qualifyid);
if (peer->qualtrans)
destroy_trans(peer->qualtrans, 0);
peer->qualtrans = NULL;
peer->us_eid = global_eid;
destroy_permissions(&peer->permit);
destroy_permissions(&peer->include);
- if (peer->registerid > -1)
- ast_sched_del(sched, peer->registerid);
- peer->registerid = -1;
+ AST_SCHED_DEL(sched, peer->registerid);
for (; v; v = v->next) {
if (!strcasecmp(v->name, "inkey")) {
ast_copy_string(peer->inkey, v->value, sizeof(peer->inkey));