Added new static mutex to protect channel disconnect parameters during access.
git-svn-id: http://voip.null.ro/svn/yate@4662 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
e48bdcbefe
commit
4d74b5138f
|
@ -320,6 +320,9 @@ bool CallEndpoint::clearData(DataNode* node, const char* type)
|
|||
|
||||
static const String s_disconnected("chan.disconnected");
|
||||
|
||||
// Mutex used to lock disconnect parameters during access
|
||||
static Mutex s_paramMutex(true,"ChannelParams");
|
||||
|
||||
Channel::Channel(Driver* driver, const char* id, bool outgoing)
|
||||
: CallEndpoint(id),
|
||||
m_parameters(""), m_driver(driver), m_outgoing(outgoing),
|
||||
|
@ -355,6 +358,11 @@ void* Channel::getObject(const String& name) const
|
|||
return CallEndpoint::getObject(name);
|
||||
}
|
||||
|
||||
Mutex& Channel::paramMutex()
|
||||
{
|
||||
return s_paramMutex;
|
||||
}
|
||||
|
||||
void Channel::init()
|
||||
{
|
||||
status(direction());
|
||||
|
@ -455,17 +463,21 @@ void Channel::disconnected(bool final, const char* reason)
|
|||
return;
|
||||
// last chance to get reconnected to something
|
||||
Message* m = getDisconnect(reason);
|
||||
s_paramMutex.lock();
|
||||
m_targetid.clear();
|
||||
m_parameters.clearParams();
|
||||
s_paramMutex.unlock();
|
||||
Engine::enqueue(m);
|
||||
}
|
||||
|
||||
void Channel::setDisconnect(const NamedList* params)
|
||||
{
|
||||
DDebug(this,DebugInfo,"setDisconnect(%p) [%p]",params,this);
|
||||
s_paramMutex.lock();
|
||||
m_parameters.clearParams();
|
||||
if (params)
|
||||
m_parameters.copyParams(*params);
|
||||
s_paramMutex.unlock();
|
||||
}
|
||||
|
||||
void Channel::endDisconnect(const Message& msg, bool handled)
|
||||
|
@ -488,7 +500,9 @@ void Channel::setId(const char* newId)
|
|||
Message* Channel::getDisconnect(const char* reason)
|
||||
{
|
||||
Message* msg = new Message(s_disconnected);
|
||||
s_paramMutex.lock();
|
||||
msg->copyParams(m_parameters);
|
||||
s_paramMutex.unlock();
|
||||
complete(*msg);
|
||||
if (reason)
|
||||
msg->setParam("reason",reason);
|
||||
|
@ -536,8 +550,11 @@ void Channel::complete(Message& msg, bool minimal) const
|
|||
msg.setParam("id",id());
|
||||
if (m_driver)
|
||||
msg.setParam("module",m_driver->name());
|
||||
if (s_hangup == msg)
|
||||
if (s_hangup == msg) {
|
||||
s_paramMutex.lock();
|
||||
msg.copyParams(parameters());
|
||||
s_paramMutex.unlock();
|
||||
}
|
||||
|
||||
if (minimal)
|
||||
return;
|
||||
|
|
|
@ -1394,7 +1394,9 @@ void YateH323Connection::OnCleared()
|
|||
YateH323Chan* tmp = m_chan;
|
||||
m_chan = 0;
|
||||
lock.drop();
|
||||
paramMutex().lock();
|
||||
tmp->parameters().setParam("cause_q931",String(GetQ931Cause()));
|
||||
paramMutex().unlock();
|
||||
tmp->disconnect(error ? error : rtext,tmp->parameters());
|
||||
tmp->finish();
|
||||
tmp->deref();
|
||||
|
|
|
@ -1553,9 +1553,11 @@ void SigChannel::endDisconnect(const Message& params, bool handled)
|
|||
const char* prefix = params.getValue("message-oprefix");
|
||||
if (TelEngine::null(prefix))
|
||||
return;
|
||||
paramMutex().lock();
|
||||
parameters().clearParams();
|
||||
parameters().setParam("message-oprefix",prefix);
|
||||
parameters().copySubParams(params,prefix,false);
|
||||
paramMutex().unlock();
|
||||
}
|
||||
|
||||
void SigChannel::hangup(const char* reason, SignallingEvent* event, const NamedList* extra)
|
||||
|
@ -1581,13 +1583,19 @@ void SigChannel::hangup(const char* reason, SignallingEvent* event, const NamedL
|
|||
ev = new SignallingEvent(SignallingEvent::Release,msg,m_call);
|
||||
TelEngine::destruct(msg);
|
||||
TelEngine::destruct(m_call);
|
||||
if (!extra)
|
||||
extra = ¶meters();
|
||||
plugin.copySigMsgParams(ev,*extra,"i");
|
||||
if (extra)
|
||||
plugin.copySigMsgParams(ev,*extra,"i");
|
||||
else {
|
||||
paramMutex().lock();
|
||||
plugin.copySigMsgParams(ev,parameters(),"i");
|
||||
paramMutex().unlock();
|
||||
}
|
||||
}
|
||||
if (event) {
|
||||
paramMutex().lock();
|
||||
parameters().clearParams();
|
||||
plugin.copySigMsgParams(parameters(),event,¶ms);
|
||||
paramMutex().unlock();
|
||||
}
|
||||
lock2.drop();
|
||||
lock.drop();
|
||||
|
|
|
@ -88,6 +88,7 @@ QuerySipChannel::~QuerySipChannel()
|
|||
void QuerySipChannel::disconnected(bool final, const char *reason)
|
||||
{
|
||||
DDebug(this,DebugAll,"QuerySipChannel::disconnected() '%s'",reason);
|
||||
paramMutex().lock();
|
||||
switch (m_type) {
|
||||
case CNAM:
|
||||
endCnam(parameters());
|
||||
|
@ -96,6 +97,7 @@ void QuerySipChannel::disconnected(bool final, const char *reason)
|
|||
endLnp(parameters());
|
||||
break;
|
||||
}
|
||||
paramMutex().unlock();
|
||||
}
|
||||
|
||||
void QuerySipChannel::endCnam(const NamedList& params)
|
||||
|
|
|
@ -1494,13 +1494,15 @@ bool YJGConnection::handleEvent(JGEvent* event)
|
|||
}
|
||||
}
|
||||
else {
|
||||
parameters().clearParams();
|
||||
URI uri(event->text());
|
||||
paramMutex().lock();
|
||||
parameters().clearParams();
|
||||
parameters().addParam("called",uri.getUser());
|
||||
parameters().addParam("calledname",uri.getDescription(),false);
|
||||
parameters().addParam("calleduri",event->text());
|
||||
parameters().addParam("copyparams","");
|
||||
copySessionParams(parameters());
|
||||
paramMutex().unlock();
|
||||
}
|
||||
}
|
||||
const char* reason = event->reason();
|
||||
|
|
|
@ -5007,7 +5007,9 @@ void YateSIPConnection::clearTransaction()
|
|||
if (m_tr->setResponse()) {
|
||||
SIPMessage* m = new SIPMessage(m_tr->initialMessage(),m_reasonCode,
|
||||
m_reason.safe("Request Terminated"));
|
||||
paramMutex().lock();
|
||||
copySipHeaders(*m,parameters(),0);
|
||||
paramMutex().unlock();
|
||||
m->setBody(buildSIPBody());
|
||||
m_tr->setResponse(m);
|
||||
TelEngine::destruct(m);
|
||||
|
@ -5108,10 +5110,12 @@ void YateSIPConnection::hangup()
|
|||
hl->setParam("text",MimeHeaderLine::quote(m_reason));
|
||||
m->addHeader(hl);
|
||||
}
|
||||
paramMutex().lock();
|
||||
const char* stats = parameters().getValue(YSTRING("rtp_stats"));
|
||||
if (stats)
|
||||
m->addHeader("P-RTP-Stat",stats);
|
||||
copySipHeaders(*m,parameters(),0);
|
||||
paramMutex().unlock();
|
||||
m->setBody(buildSIPBody());
|
||||
plugin.ep()->engine()->addMessage(m);
|
||||
m->deref();
|
||||
|
@ -5257,8 +5261,11 @@ void YateSIPConnection::mediaChanged(const SDPMedia& media)
|
|||
m.addParam("call_billid",billid());
|
||||
Engine::dispatch(m);
|
||||
const char* stats = m.getValue(YSTRING("stats"));
|
||||
if (stats)
|
||||
if (stats) {
|
||||
paramMutex().lock();
|
||||
parameters().setParam("rtp_stats"+media.suffix(),stats);
|
||||
paramMutex().unlock();
|
||||
}
|
||||
}
|
||||
// Clear the data endpoint, will be rebuilt later if required
|
||||
clearEndpoint(media);
|
||||
|
@ -5296,13 +5303,17 @@ bool YateSIPConnection::process(SIPEvent* ev)
|
|||
updateTags = false;
|
||||
m_cancel = false;
|
||||
m_byebye = false;
|
||||
paramMutex().lock();
|
||||
parameters().clearParams();
|
||||
parameters().addParam("cause_sip",String(code));
|
||||
parameters().addParam("reason_sip",msg->reason);
|
||||
setReason(msg->reason,code);
|
||||
if (msg->body) {
|
||||
paramMutex().unlock();
|
||||
Message tmp("isup.decode");
|
||||
if (decodeIsupBody(tmp,msg->body))
|
||||
bool ok = decodeIsupBody(tmp,msg->body);
|
||||
paramMutex().lock();
|
||||
if (ok)
|
||||
parameters().copyParams(tmp);
|
||||
}
|
||||
copySipHeaders(parameters(),*msg);
|
||||
|
@ -5340,6 +5351,7 @@ bool YateSIPConnection::process(SIPEvent* ev)
|
|||
else
|
||||
Debug(this,DebugMild,"Received %d redirect without Contact [%p]",code,this);
|
||||
}
|
||||
paramMutex().unlock();
|
||||
hangup();
|
||||
}
|
||||
else if (code == 408) {
|
||||
|
@ -5347,7 +5359,9 @@ bool YateSIPConnection::process(SIPEvent* ev)
|
|||
updateTags = false;
|
||||
if (m_dialog.remoteTag.null())
|
||||
m_byebye = false;
|
||||
paramMutex().lock();
|
||||
parameters().setParam("cause_sip","408");
|
||||
paramMutex().unlock();
|
||||
setReason("Request Timeout",code);
|
||||
hangup();
|
||||
}
|
||||
|
@ -5750,10 +5764,19 @@ void YateSIPConnection::doBye(SIPTransaction* t)
|
|||
const SIPMessage* msg = t->initialMessage();
|
||||
if (msg->body) {
|
||||
Message tmp("isup.decode");
|
||||
if (decodeIsupBody(tmp,msg->body))
|
||||
if (decodeIsupBody(tmp,msg->body)) {
|
||||
paramMutex().lock();
|
||||
parameters().copyParams(tmp);
|
||||
paramMutex().unlock();
|
||||
}
|
||||
}
|
||||
SIPMessage* m = new SIPMessage(t->initialMessage(),200);
|
||||
paramMutex().lock();
|
||||
copySipHeaders(parameters(),*msg);
|
||||
const char* stats = parameters().getValue(YSTRING("rtp_stats"));
|
||||
if (stats)
|
||||
m->addHeader("P-RTP-Stat",stats);
|
||||
paramMutex().unlock();
|
||||
const MimeHeaderLine* hl = msg->getHeader("Reason");
|
||||
if (hl) {
|
||||
const NamedString* text = hl->getParam("text");
|
||||
|
@ -5762,10 +5785,6 @@ void YateSIPConnection::doBye(SIPTransaction* t)
|
|||
// FIXME: add SIP and Q.850 cause codes
|
||||
}
|
||||
setMedia(0);
|
||||
SIPMessage* m = new SIPMessage(t->initialMessage(),200);
|
||||
const char* stats = parameters().getValue(YSTRING("rtp_stats"));
|
||||
if (stats)
|
||||
m->addHeader("P-RTP-Stat",stats);
|
||||
t->setResponse(m);
|
||||
m->deref();
|
||||
m_byebye = false;
|
||||
|
@ -6216,6 +6235,7 @@ void YateSIPConnection::endDisconnect(const Message& msg, bool handled)
|
|||
const char* mPrefix = msg.getValue(YSTRING("message-prefix"));
|
||||
if (!(sPrefix || mPrefix))
|
||||
return;
|
||||
paramMutex().lock();
|
||||
parameters().clearParams();
|
||||
if (sPrefix) {
|
||||
parameters().setParam("osip-prefix",sPrefix);
|
||||
|
@ -6225,6 +6245,7 @@ void YateSIPConnection::endDisconnect(const Message& msg, bool handled)
|
|||
parameters().setParam("message-prefix",mPrefix);
|
||||
parameters().copySubParams(msg,mPrefix,false);
|
||||
}
|
||||
paramMutex().unlock();
|
||||
}
|
||||
|
||||
void YateSIPConnection::statusParams(String& str)
|
||||
|
@ -6520,7 +6541,9 @@ MimeBody* YateSIPConnection::buildSIPBody()
|
|||
if (!s_sipt_isup)
|
||||
return 0;
|
||||
Message msg("");
|
||||
paramMutex().lock();
|
||||
msg.copyParams(parameters());
|
||||
paramMutex().unlock();
|
||||
return doBuildSIPBody(this,msg,0);
|
||||
}
|
||||
|
||||
|
|
|
@ -1650,6 +1650,12 @@ public:
|
|||
*/
|
||||
virtual void* getObject(const String& name) const;
|
||||
|
||||
/**
|
||||
* Get the big mutex that serializes access to all disconnect parameter lists
|
||||
* @return A reference to the mutex
|
||||
*/
|
||||
static Mutex& paramMutex();
|
||||
|
||||
/**
|
||||
* Put channel variables into a message
|
||||
* @param msg Message to fill in
|
||||
|
|
Loading…
Reference in New Issue