From 747e32afd876074f782c1853dfc7784ac65d9f6f Mon Sep 17 00:00:00 2001 From: paulc Date: Wed, 18 Nov 2015 14:20:00 +0000 Subject: [PATCH] Added helper class to keep extra account parameters for calls and registration. Added extra account parameters handling to SIP channel. git-svn-id: http://voip.null.ro/svn/yate@6066 acf43c95-373e-0410-b603-e72c3f656dc1 --- engine/Channel.cpp | 54 ++++++++++++++++++++++++++++++++++ modules/ysipchan.cpp | 38 ++++++++++++++---------- yatephone.h | 70 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+), 16 deletions(-) diff --git a/engine/Channel.cpp b/engine/Channel.cpp index 148dfaee..27a3ca8f 100644 --- a/engine/Channel.cpp +++ b/engine/Channel.cpp @@ -1809,4 +1809,58 @@ void Router::cleanup() destruct(m_msg); } + +void CallAccount::pickAccountParams(const NamedList& params) +{ + NamedIterator iter(params); + Lock mylock(m_mutex); + m_inbParams.clearParams(); + m_outParams.clearParams(); + m_regParams.clearParams(); + while (const NamedString* n = iter.get()) { + if (n->name().length() <= 4) + continue; + String name = n->name().substr(4).trimSpaces(); + if (n->name().startsWith("reg:")) + m_regParams.setParam(name,*n); + else if (n->name().startsWith("inb:")) + m_inbParams.setParam(name,*n); + else if (n->name().startsWith("out:")) + m_outParams.setParam(name,*n); + } +} + +void CallAccount::setInboundParams(NamedList& params) +{ + Lock mylock(m_mutex); + NamedIterator iter(m_inbParams); + while (const NamedString* n = iter.get()) { + String tmp(*n); + params.replaceParams(tmp); + params.setParam(n->name(),tmp); + } +} + +void CallAccount::setOutboundParams(NamedList& params) +{ + Lock mylock(m_mutex); + NamedIterator iter(m_outParams); + while (const NamedString* n = iter.get()) { + String tmp(*n); + params.replaceParams(tmp); + params.setParam(n->name(),tmp); + } +} + +void CallAccount::setRegisterParams(NamedList& params) +{ + Lock mylock(m_mutex); + NamedIterator iter(m_regParams); + while (const NamedString* n = iter.get()) { + String tmp(*n); + params.replaceParams(tmp); + params.setParam(n->name(),tmp); + } +} + /* vi: set ts=8 sw=4 sts=4 noet: */ diff --git a/modules/ysipchan.cpp b/modules/ysipchan.cpp index 505b3d37..921f1b56 100644 --- a/modules/ysipchan.cpp +++ b/modules/ysipchan.cpp @@ -663,7 +663,7 @@ private: bool m_foreignAuth; }; -class YateSIPLine : public String, public Mutex, public YateSIPPartyHolder +class YateSIPLine : public String, public Mutex, public CallAccount, public YateSIPPartyHolder { YCLASS(YateSIPLine,String) public: @@ -5910,6 +5910,8 @@ YateSIPConnection::YateSIPConnection(SIPEvent* ev, SIPTransaction* tr) DDebug(this,DebugAll,"RTP addr '%s' [%p]",m_rtpAddr.c_str(),this); if (reason) m->addParam("reason",reason); + if (line) + line->setInboundParams(*m); m_route = m; Message* s = message("chan.startup"); s->addParam("caller",m_uri.getUser()); @@ -5931,10 +5933,17 @@ YateSIPConnection::YateSIPConnection(Message& msg, const String& uri, const char m_honorDtmfDetect(s_honorDtmfDetect), m_referring(false), m_reInviting(ReinviteNone), m_lastRseq(0), m_revert("") { - m_ipv6 = msg.getBoolValue(YSTRING("ipv6_support"),s_ipv6); - setSdpDebug(this,this); Debug(this,DebugAll,"YateSIPConnection::YateSIPConnection(%p,'%s') [%p]", &msg,uri.c_str(),this); + m_line = msg.getValue(YSTRING("line")); + YateSIPLine* line = 0; + if (m_line) { + line = plugin.findLine(m_line); + if (line) + line->setOutboundParams(msg); + } + m_ipv6 = msg.getBoolValue(YSTRING("ipv6_support"),s_ipv6); + setSdpDebug(this,this); m_targetid = target; setReason(); m_checkAllowInfo = msg.getBoolValue(YSTRING("ocheck_allow_info"),m_checkAllowInfo); @@ -5954,20 +5963,15 @@ YateSIPConnection::YateSIPConnection(Message& msg, const String& uri, const char setRfc2833(msg.getParam(YSTRING("rfc2833"))); m_rtpForward = msg.getBoolValue(YSTRING("rtp_forward")); m_user = msg.getValue(YSTRING("user")); - m_line = msg.getValue(YSTRING("line")); String tmp; - YateSIPLine* line = 0; - if (m_line) { - line = plugin.findLine(m_line); - if (line) { - if (uri.find('@') < 0 && !uri.startsWith("tel:")) { - if (!uri.startsWith("sip:")) - tmp = "sip:"; - tmp << uri << "@"; - SocketAddr::appendAddr(tmp,line->domain()); - } - m_externalAddr = line->getLocalAddr(); + if (line) { + if (uri.find('@') < 0 && !uri.startsWith("tel:")) { + if (!uri.startsWith("sip:")) + tmp = "sip:"; + tmp << uri << "@"; + SocketAddr::appendAddr(tmp,line->domain()); } + m_externalAddr = line->getLocalAddr(); } if (tmp.null()) { if (!(uri.startsWith("tel:") || uri.startsWith("sip:"))) { @@ -8066,7 +8070,7 @@ bool YateSIPConnection::sendTone(Message& msg, const char* tone, int meth, bool& YateSIPLine::YateSIPLine(const String& name) - : String(name), Mutex(true,"YateSIPLine"), + : String(name), Mutex(true,"YateSIPLine"), CallAccount(this), m_resend(0), m_keepalive(0), m_interval(0), m_alive(0), m_flags(-1), m_trans(-1), m_tr(0), m_marked(false), m_valid(false), m_localPort(0), m_partyPort(0), m_localDetect(false), @@ -8172,6 +8176,7 @@ SIPMessage* YateSIPLine::buildRegister(int expires) *hl = display + " " + *hl; } } + copySipHeaders(*m,registerParams()); return m; } @@ -8432,6 +8437,7 @@ bool YateSIPLine::update(const Message& msg) setParty(); return true; } + pickAccountParams(msg); bool chg = updateProto(msg); bool transChg = chg; transChg = updateLocalAddr(msg) || transChg; diff --git a/yatephone.h b/yatephone.h index e055b02e..b4b3e009 100644 --- a/yatephone.h +++ b/yatephone.h @@ -2471,6 +2471,76 @@ protected: { return m_id; } }; +/** + * This helper class holds generic account parameters that are applied to calls + * @short Settings for an account handling calls + */ +class YATE_API CallAccount +{ + YNOCOPY(CallAccount); +private: + Mutex* m_mutex; + NamedList m_inbParams; + NamedList m_outParams; + NamedList m_regParams; + +public: + /** + * Make a copy of the inbound and outbound parameter templates + * @param params List of parameters to copy from + */ + void pickAccountParams(const NamedList& params); + + + /** + * Patch the inbound call parameters + * @param params List of parameters to be patched + */ + void setInboundParams(NamedList& params); + + /** + * Patch the outbound call parameters + * @param params List of parameters to be patched + */ + void setOutboundParams(NamedList& params); + + /** + * Patch registration parameters + * @param params List of parameters to be patched + */ + void setRegisterParams(NamedList& params); + + /** + * Accessor for the inbound call parameters list + * @return Reference to the inbound call parameters + */ + inline const NamedList& inboundParams() const + { return m_inbParams; } + + /** + * Accessor for the outbound call parameters list + * @return Reference to the outbound call parameters + */ + inline const NamedList& outboundParams() const + { return m_outParams; } + + /** + * Accessor for the registration parameters list + * @return Reference to the registration parameters + */ + inline const NamedList& registerParams() const + { return m_regParams; } + +protected: + /** + * Constructor + * @param mutex The mutex that is used to lock object's variables + */ + inline CallAccount(Mutex* mutex) + : m_mutex(mutex), m_inbParams(""), m_outParams(""), m_regParams("") + { } +}; + /** * Find if a string appears to be an E164 phone number * @param str String to check