/*! \brief sip_pvt: PVT structures are used for each SIP dialog, ie. a call, a registration, a subscribe */
struct sip_pvt {
- ast_mutex_t lock; /*!< Dialog private lock */
+ ast_mutex_t pvt_lock; /*!< Dialog private lock */
int method; /*!< SIP method that opened this dialog */
AST_DECLARE_STRING_FIELDS(
AST_STRING_FIELD(callid); /*!< Global CallID */
get_codec: sip_get_codec,
};
+/*!
+ * Helper functions to lock/unlock pvt, hiding the
+ * underlying locking mechanism.
+ */
+static void sip_pvt_lock(struct sip_pvt *pvt)
+{
+ ast_mutex_lock(&pvt->pvt_lock);
+}
+
+static void sip_pvt_unlock(struct sip_pvt *pvt)
+{
+ ast_mutex_unlock(&pvt->pvt_lock);
+}
+
/*! \brief Interface structure with callbacks used to connect to UDPTL module*/
static struct ast_udptl_protocol sip_udptl = {
type: "SIP",
int reschedule = DEFAULT_RETRANS;
/* Lock channel PVT */
- ast_mutex_lock(&pkt->owner->lock);
+ sip_pvt_lock(pkt->owner);
if (pkt->retrans < MAX_RETRANS) {
pkt->retrans++;
append_history(pkt->owner, "ReTx", "%d %s", reschedule, pkt->data);
__sip_xmit(pkt->owner, pkt->data, pkt->packetlen);
- ast_mutex_unlock(&pkt->owner->lock);
+ sip_pvt_unlock(pkt->owner);
return reschedule;
}
/* Too many retries */
if (ast_test_flag(pkt, FLAG_FATAL)) {
while(pkt->owner->owner && ast_channel_trylock(pkt->owner->owner)) {
- ast_mutex_unlock(&pkt->owner->lock); /* SIP_PVT, not channel */
+ sip_pvt_unlock(pkt->owner); /* SIP_PVT, not channel */
usleep(1);
- ast_mutex_lock(&pkt->owner->lock);
+ sip_pvt_lock(pkt->owner);
}
if (pkt->owner->owner) {
ast_set_flag(&pkt->owner->flags[0], SIP_ALREADYGONE);
prev->next = cur->next;
else
pkt->owner->packets = cur->next;
- ast_mutex_unlock(&pkt->owner->lock);
+ sip_pvt_unlock(pkt->owner);
free(cur);
pkt = NULL;
} else
ast_log(LOG_WARNING, "Weird, couldn't find packet owner!\n");
if (pkt)
- ast_mutex_unlock(&pkt->owner->lock);
+ sip_pvt_unlock(pkt->owner);
return 0;
}
msg = sip_methods[sipmethod].text;
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
for (cur = p->packets; cur; prev = cur, cur = cur->next) {
if ((cur->seqno == seqno) && ((ast_test_flag(cur, FLAG_RESPONSE)) == resp) &&
((ast_test_flag(cur, FLAG_RESPONSE)) ||
break;
}
}
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
if (option_debug)
ast_log(LOG_DEBUG, "Stopping retransmission on '%s' of %s %d: Match %s\n", p->callid, resp ? "Response" : "Request", seqno, res ? "Not Found" : "Found");
}
{
struct sip_pvt *p = nothing;
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
p->initid = -1;
if (p->owner) {
/* XXX fails on possible deadlock */
ast_channel_unlock(p->owner);
}
}
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return 0;
}
ast_variables_destroy(p->chanvars);
p->chanvars = NULL;
}
- ast_mutex_destroy(&p->lock);
+ ast_mutex_destroy(&p->pvt_lock);
ast_string_field_free_pools(p);
if (option_debug && ast_test_flag(ast, AST_FLAG_ZOMBIE))
ast_log(LOG_DEBUG, "Hanging up zombie call. Be scared.\n");
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
if (option_debug && sipdebug)
ast_log(LOG_DEBUG, "update_call_counter(%s) - decrement call limit counter on hangup\n", p->username);
update_call_counter(p, DEC_CALL_LIMIT);
/* Determine how to disconnect */
if (p->owner != ast) {
ast_log(LOG_WARNING, "Huh? We aren't the owner? Can't hangup call.\n");
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return 0;
}
/* If the call is not UP, we need to send CANCEL instead of BYE */
}
if (needdestroy)
ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return 0;
}
int res = 0;
struct sip_pvt *p = ast->tech_pvt;
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
if (ast->_state != AST_STATE_UP) {
try_suggested_sip_codec(p);
} else
res = transmit_response_with_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL);
}
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return res;
}
return 0;
}
if (p) {
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
if (p->rtp) {
/* If channel is not up, activate early media session */
if ((ast->_state != AST_STATE_UP) &&
p->lastrtptx = time(NULL);
res = ast_rtp_write(p->rtp, frame);
}
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
}
break;
case AST_FRAME_VIDEO:
if (p) {
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
if (p->vrtp) {
/* Activate video early media */
if ((ast->_state != AST_STATE_UP) &&
p->lastrtptx = time(NULL);
res = ast_rtp_write(p->vrtp, frame);
}
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
}
break;
case AST_FRAME_IMAGE:
break;
case AST_FRAME_MODEM:
if (p) {
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
if (p->udptl) {
if ((ast->_state != AST_STATE_UP) &&
!ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) &&
}
res = ast_udptl_write(p->udptl, frame);
}
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
}
break;
default:
}
p = newchan->tech_pvt;
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
append_history(p, "Masq", "Old channel: %s\n", oldchan->name);
append_history(p, "Masq (cont)", "...new owner: %s\n", newchan->name);
if (p->owner != oldchan)
if (option_debug > 2)
ast_log(LOG_DEBUG, "SIP Fixup: New owner for dialogue %s: %s (Old parent: %s)\n", p->callid, p->owner->name, oldchan->name);
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return ret;
}
struct sip_pvt *p = ast->tech_pvt;
int res = 0;
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
switch (ast_test_flag(&p->flags[0], SIP_DTMF)) {
case SIP_DTMF_INBAND:
res = -1; /* Tell Asterisk to generate inband indications */
default:
break;
}
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return res;
}
struct sip_pvt *p = ast->tech_pvt;
int res = 0;
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
switch (ast_test_flag(&p->flags[0], SIP_DTMF)) {
case SIP_DTMF_INFO:
transmit_info_with_digit(p, digit);
res = -1; /* Tell Asterisk to stop inband indications */
break;
}
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return res;
}
struct sip_pvt *p = ast->tech_pvt;
int res;
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
if (ast->_state == AST_STATE_RING)
res = sip_sipredirect(p, dest);
else
res = transmit_refer(p, dest);
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return res;
}
struct sip_pvt *p = ast->tech_pvt;
int res = 0;
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
switch(condition) {
case AST_CONTROL_RINGING:
if (ast->_state == AST_STATE_RING) {
res = -1;
break;
}
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return res;
}
int what;
int needvideo = 0;
- ast_mutex_unlock(&i->lock);
+ sip_pvt_unlock(i);
/* Don't hold a sip pvt lock while we allocate a channel */
tmp = ast_channel_alloc(1);
- ast_mutex_lock(&i->lock);
+ sip_pvt_lock(i);
if (!tmp) {
ast_log(LOG_WARNING, "Unable to allocate AST channel structure for SIP channel\n");
return NULL;
struct sip_pvt *p = ast->tech_pvt;
int faxdetected = FALSE;
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
fr = sip_rtp_read(ast, p, &faxdetected);
p->lastrtprx = time(NULL);
}
}
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return fr;
}
return NULL;
}
- ast_mutex_init(&p->lock);
+ ast_mutex_init(&p->pvt_lock);
p->method = intended_method;
p->initid = -1;
if (!p->rtp || (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) && !p->vrtp)) {
ast_log(LOG_WARNING, "Unable to create RTP audio %s session: %s\n",
ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "and video" : "", strerror(errno));
- ast_mutex_destroy(&p->lock);
+ ast_mutex_destroy(&p->pvt_lock);
if (p->chanvars) {
ast_variables_destroy(p->chanvars);
p->chanvars = NULL;
if (found) {
/* Found the call */
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
ast_mutex_unlock(&iflock);
return p;
}
/* Ok, time to create a new SIP dialog object, a pvt */
if ((p = sip_alloc(callid, sin, 1, intended_method)))
/* Ok, we've created a dialog, let's go and process it */
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
}
return p;
} else if( sip_methods[intended_method].can_create == CAN_CREATE_DIALOG_UNSUPPORTED_METHOD) {
char *ourtag = sip_pvt_ptr->tag;
/* Go ahead and lock it (and its owner) before returning */
- ast_mutex_lock(&sip_pvt_ptr->lock);
+ sip_pvt_lock(sip_pvt_ptr);
/* Check if tags match. If not, this is not the call we want
(With a forking SIP proxy, several call legs share the
match = 0;
if (!match) {
- ast_mutex_unlock(&sip_pvt_ptr->lock);
+ sip_pvt_unlock(sip_pvt_ptr);
break;
}
/* deadlock avoidance... */
while (sip_pvt_ptr->owner && ast_channel_trylock(sip_pvt_ptr->owner)) {
- ast_mutex_unlock(&sip_pvt_ptr->lock);
+ sip_pvt_unlock(sip_pvt_ptr);
usleep(1);
- ast_mutex_lock(&sip_pvt_ptr->lock);
+ sip_pvt_lock(sip_pvt_ptr);
}
break;
}
} else {
if (option_debug > 1)
ast_log(LOG_DEBUG, "Strange... The other side of the bridge does not have a udptl struct\n");
- ast_mutex_lock(&bridgepvt->lock);
+ sip_pvt_lock(bridgepvt);
bridgepvt->t38.state = T38_DISABLED;
- ast_mutex_unlock(&bridgepvt->lock);
+ sip_pvt_unlock(bridgepvt);
if (option_debug)
ast_log(LOG_DEBUG,"T38 state changed to %d on channel %s\n", bridgepvt->t38.state, bridgepeer->tech->type);
p->t38.state = T38_DISABLED;
transmit_response_with_sdp(p, "200 OK", req, 1);
/* Do something more clever here */
ast_channel_unlock(c);
- ast_mutex_unlock(&p->refer->refer_call->lock);
+ sip_pvt_unlock(p->refer->refer_call);
return 1;
}
if (!c) {
transmit_response_with_sdp(p, "503 Service Unavailable", req, 1);
append_history(p, "Xfer", "INVITE/Replace Failed. No new channel.");
sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
- ast_mutex_unlock(&p->refer->refer_call->lock);
+ sip_pvt_unlock(p->refer->refer_call);
return 1;
}
append_history(p, "Xfer", "INVITE/Replace received");
ast_channel_unlock(c);
/* Unlock PVT */
- ast_mutex_unlock(&p->refer->refer_call->lock);
+ sip_pvt_unlock(p->refer->refer_call);
/* Make sure that the masq does not free our PVT for the old call */
ast_set_flag(&p->refer->refer_call->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Delay hangup */
}
ast_channel_unlock(replacecall);
}
- ast_mutex_unlock(&p->refer->refer_call->lock);
+ sip_pvt_unlock(p->refer->refer_call);
ast_setstate(c, AST_STATE_DOWN);
if (option_debug > 3) {
}
ast_channel_unlock(p->owner); /* Unlock new owner */
- ast_mutex_unlock(&p->lock); /* Unlock SIP structure */
+ sip_pvt_unlock(p); /* Unlock SIP structure */
/* The call should be down with no ast_channel, so hang it up */
c->tech_pvt = NULL;
if (error) { /* Give up this dialog */
append_history(p, "Xfer", "INVITE/Replace Failed.");
sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
if (p->refer->refer_call) {
- ast_mutex_unlock(&p->refer->refer_call->lock);
+ sip_pvt_unlock(p->refer->refer_call);
ast_channel_unlock(p->refer->refer_call->owner);
}
return -1;
/* Unlock locks so ast_hangup can do its magic */
ast_mutex_unlock(&c->lock);
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
ast_hangup(c);
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
c = NULL;
}
} else { /* Pickup call in call group */
transmit_response_reliable(p, "503 Unavailable", req);
ast_set_flag(&p->flags[0], SIP_ALREADYGONE);
/* Unlock locks so ast_hangup can do its magic */
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
c->hangupcause = AST_CAUSE_CALL_REJECTED;
} else {
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
ast_setstate(c, AST_STATE_DOWN);
c->hangupcause = AST_CAUSE_NORMAL_CLEARING;
}
ast_hangup(c);
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
c = NULL;
}
break;
sip_handle_t38_reinvite(bridgepeer, p, 1);
} else { /* Something is wrong with peers udptl struct */
ast_log(LOG_WARNING, "Strange... The other side of the bridge don't have udptl struct\n");
- ast_mutex_lock(&bridgepvt->lock);
+ sip_pvt_lock(bridgepvt);
bridgepvt->t38.state = T38_DISABLED;
- ast_mutex_unlock(&bridgepvt->lock);
+ sip_pvt_unlock(bridgepvt);
if (option_debug > 1)
ast_log(LOG_DEBUG,"T38 state changed to %d on channel %s\n", bridgepvt->t38.state, bridgepeer->name);
if (ast_test_flag(req, SIP_PKT_IGNORE))
append_history(transferer, "Xfer", "Refer failed");
ast_clear_flag(&transferer->flags[0], SIP_GOTREFER);
transferer->refer->status = REFER_FAILED;
- ast_mutex_unlock(&targetcall_pvt->lock);
+ sip_pvt_unlock(targetcall_pvt);
ast_channel_unlock(current->chan1);
ast_channel_unlock(target.chan1);
return -1;
/* Perform the transfer */
res = attempt_transfer(current, &target);
- ast_mutex_unlock(&targetcall_pvt->lock);
+ sip_pvt_unlock(targetcall_pvt);
if (res) {
/* Failed transfer */
/* Could find better message, but they will get the point */
continue;
if (p_old->subscribed == NONE)
continue;
- ast_mutex_lock(&p_old->lock);
+ sip_pvt_lock(p_old);
if (!strcmp(p_old->username, p->username)) {
if (!strcmp(p_old->exten, p->exten) &&
!strcmp(p_old->context, p->context)) {
ast_set_flag(&p_old->flags[0], SIP_NEEDDESTROY);
- ast_mutex_unlock(&p_old->lock);
+ sip_pvt_unlock(p_old);
break;
}
}
- ast_mutex_unlock(&p_old->lock);
+ sip_pvt_unlock(p_old);
}
ast_mutex_unlock(&iflock);
}
break; /* locking succeeded */
if (option_debug)
ast_log(LOG_DEBUG, "Failed to grab owner channel lock, trying again. (SIP call %s)\n", p->callid);
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
ast_mutex_unlock(&netlock);
/* Sleep for a very short amount of time */
usleep(1);
if (p->owner && !nounlock)
ast_channel_unlock(p->owner);
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
ast_mutex_unlock(&netlock);
if (recount)
ast_update_use_count();
/* Needs a hangup */
if (sip->rtptimeout) {
while (sip->owner && ast_channel_trylock(sip->owner)) {
- ast_mutex_unlock(&sip->lock);
+ sip_pvt_unlock(sip);
usleep(1);
- ast_mutex_lock(&sip->lock);
+ sip_pvt_lock(sip);
}
if (sip->owner) {
if (!(ast_rtp_get_bridged(sip->rtp))) {
get back to this point every millisecond or less)
*/
for (sip = iflist; !fastrestart && sip; sip = sip->next) {
- ast_mutex_lock(&sip->lock);
+ sip_pvt_lock(sip);
/* Check RTP timeouts and kill calls if we have a timeout set and do not get RTP */
check_rtp_timeout(sip, t);
/* If we have sessions that needs to be destroyed, do it now */
if (ast_test_flag(&sip->flags[0], SIP_NEEDDESTROY) && !sip->packets &&
!sip->owner) {
- ast_mutex_unlock(&sip->lock);
+ sip_pvt_unlock(sip);
__sip_destroy(sip, 1);
goto restartsearch;
}
- ast_mutex_unlock(&sip->lock);
+ sip_pvt_unlock(sip);
}
ast_mutex_unlock(&iflock);
printf("Setting up to call extension '%s' at '%s'\n", ext ? ext : "<none>", host);
#endif
p->prefcodec = oldformat; /* Format for this call */
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
tmpc = sip_new(p, AST_STATE_DOWN, host); /* Place the call */
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
if (!tmpc)
sip_destroy(p);
ast_update_use_count();
if (!p)
return NULL;
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
if (p->udptl && ast_test_flag(&p->flags[0], SIP_CAN_REINVITE))
udptl = p->udptl;
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return udptl;
}
p = chan->tech_pvt;
if (!p)
return -1;
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
if (udptl)
ast_udptl_get_peer(udptl, &p->udptlredirip);
else
}
/* Reset lastrtprx timer */
p->lastrtprx = p->lastrtptx = time(NULL);
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return 0;
}
return -1;
/* Setup everything on the other side like offered/responded from first side */
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
p->t38.jointcapability = p->t38.peercapability = pvt->t38.jointcapability;
ast_udptl_set_far_max_datagram(p->udptl, ast_udptl_get_local_max_datagram(pvt->udptl));
ast_udptl_set_local_max_datagram(p->udptl, ast_udptl_get_local_max_datagram(pvt->udptl));
}
/* Reset lastrtprx timer */
p->lastrtprx = p->lastrtptx = time(NULL);
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return 0;
} else { /* If we are handling sending 200 OK to the other side of the bridge */
if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE) && ast_test_flag(&pvt->flags[0], SIP_CAN_REINVITE)) {
}
transmit_response_with_t38_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL);
p->lastrtprx = p->lastrtptx = time(NULL);
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return 0;
}
}
if (!(p = chan->tech_pvt))
return AST_RTP_GET_FAILED;
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
if (!(p->rtp)) {
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return AST_RTP_GET_FAILED;
}
else if (ast_test_flag(&global_jbconf, AST_JB_FORCED))
res = AST_RTP_GET_FAILED;
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return res;
}
if (!(p = chan->tech_pvt))
return AST_RTP_GET_FAILED;
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
if (!(p->vrtp)) {
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return AST_RTP_GET_FAILED;
}
if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE))
res = AST_RTP_TRY_NATIVE;
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return res;
}
p = chan->tech_pvt;
if (!p)
return -1;
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
if (ast_test_flag(&p->flags[0], SIP_ALREADYGONE)) {
/* If we're destroyed, don't bother */
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return 0;
}
that are known to be behind a NAT, then stop the process now
*/
if (nat_active && !ast_test_flag(&p->flags[0], SIP_CAN_REINVITE_NAT)) {
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return 0;
}
}
/* Reset lastrtprx timer */
p->lastrtprx = p->lastrtptx = time(NULL);
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
return 0;
}
ast_channel_unlock(chan);
return 0;
}
- ast_mutex_lock(&p->lock);
+ sip_pvt_lock(p);
if (!strcasecmp(mode,"info")) {
ast_clear_flag(&p->flags[0], SIP_DTMF);
ast_set_flag(&p->flags[0], SIP_DTMF_INFO);
p->vad = NULL;
}
}
- ast_mutex_unlock(&p->lock);
+ sip_pvt_unlock(p);
ast_channel_unlock(chan);
return 0;
}
pl = p;
p = p->next;
/* Free associated memory */
- ast_mutex_destroy(&pl->lock);
+ ast_mutex_destroy(&pl->pvt_lock);
if (pl->chanvars) {
ast_variables_destroy(pl->chanvars);
pl->chanvars = NULL;