Sanitize the custom SIP cause codes, must be >= 300.

Allow altering the SIP code in the chan.disconnected message.


git-svn-id: http://yate.null.ro/svn/yate/trunk@4195 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2011-03-18 14:03:42 +00:00
parent 5278f71b7f
commit edf28bc0c7
1 changed files with 15 additions and 5 deletions

View File

@ -1997,7 +1997,7 @@ YateSIPConnection::YateSIPConnection(Message& msg, const String& uri, const char
tmp = "Invalid address: ";
tmp << m_uri;
msg.setParam("reason",tmp);
setReason(tmp);
setReason(tmp,500);
return;
}
int maxf = msg.getIntValue("antiloop",s_maxForwards);
@ -2236,7 +2236,7 @@ void YateSIPConnection::hangup()
if (m_reason) {
// FIXME: add SIP and Q.850 cause codes, set the proper reason
MimeHeaderLine* hl = new MimeHeaderLine("Reason","SIP");
if ((m_reasonCode >= 300) && (m_reasonCode != 487))
if ((m_reasonCode >= 300) && (m_reasonCode <= 699) && (m_reasonCode != 487))
hl->setParam("cause",String(m_reasonCode));
hl->setParam("text",MimeHeaderLine::quote(m_reason));
m->addHeader(hl);
@ -2420,7 +2420,7 @@ bool YateSIPConnection::process(SIPEvent* ev)
m_dialog = *ev->getTransaction()->recentMessage();
mylock.drop();
if (msg && !msg->isOutgoing() && msg->isAnswer() && (code >= 300)) {
if (msg && !msg->isOutgoing() && msg->isAnswer() && (code >= 300) && (code <= 699)) {
updateTags = false;
m_cancel = false;
m_byebye = false;
@ -3035,7 +3035,7 @@ void YateSIPConnection::disconnected(bool final, const char *reason)
Debug(this,DebugAll,"YateSIPConnection::disconnected() '%s' [%p]",reason,this);
if (reason) {
int code = lookup(reason,dict_errors);
if (code)
if (code >= 300 && code <= 699)
setReason(lookup(code,SIPResponses,reason),code);
else
setReason(reason);
@ -3199,7 +3199,7 @@ bool YateSIPConnection::msgDrop(Message& msg, const char* reason)
if (!Channel::msgDrop(msg,reason))
return false;
int code = lookup(reason,dict_errors);
if (code >= 300) {
if (code >= 300 && code <= 699) {
m_reasonCode = code;
m_reason = lookup(code,SIPResponses,reason);
}
@ -3279,6 +3279,14 @@ bool YateSIPConnection::msgUpdate(Message& msg)
void YateSIPConnection::endDisconnect(const Message& msg, bool handled)
{
const String* reason = msg.getParam("reason");
if (!TelEngine::null(reason)) {
int code = reason->toInteger(dict_errors);
if (code >= 300 && code <= 699)
setReason(lookup(code,SIPResponses,*reason),code);
else
setReason(*reason,m_reasonCode);
}
const char* prefix = msg.getValue("osip-prefix");
if (TelEngine::null(prefix))
return;
@ -3388,6 +3396,8 @@ void YateSIPConnection::callRejected(const char* error, const char* reason, cons
{
Channel::callRejected(error,reason,msg);
int code = lookup(error,dict_errors,500);
if (code < 300 || code > 699)
code = 500;
Lock lock(driver());
if (m_tr && (m_tr->getState() == SIPTransaction::Process)) {
if (code == 401)