Added option to copy message headers in user.auth messages.

git-svn-id: http://voip.null.ro/svn/yate@6117 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2016-05-23 14:43:33 +00:00
parent ceeb2a87a6
commit 2b26a219a7
2 changed files with 34 additions and 5 deletions

View File

@ -257,6 +257,10 @@
; This parameter is applied on reload
;auth_foreign=disable
;auth_copy_headers: string: Comma separated list of headers to be copied in user.auth message
; This parameter is applied on reload
;auth_copy_headers=
; body_encoding: keyword: Encoding used for received generic binary bodies
; Can be one of: base64, hex, hexs, raw
;body_encoding=base64

View File

@ -1219,6 +1219,7 @@ static bool s_preventive_bye = true;
static bool s_ignoreVia = true; // Ignore Via headers and send answer back to the source
static bool s_sipt_isup = false; // Control the application/isup body processing
static bool s_printMsg = true; // Print sent/received SIP messages to output
static ObjList* s_authCopyHeader = 0; // Copy headers in user.auth
static bool s_ipv6 = false; // IPv6 support enabled
static u_int64_t s_waitActiveUdpTrans = 1000000; // Time to wait for active UDP transactions
@ -1299,6 +1300,12 @@ const TokenDict SipHandler::s_bodyEnc[] = {
{ 0, 0 },
};
static inline String& getGlobal(String& dest, String& src)
{
Lock lck(s_globalMutex);
return (dest = src);
}
// Get an address. Check if enclosed in []
static inline void getAddrCheckIPv6(String& dest, const String& src)
{
@ -2172,8 +2179,8 @@ static void setAuthError(SIPTransaction* trans, const NamedList& params,
m->deref();
return;
}
Lock lck(s_globalMutex);
trans->requestAuth(s_realm,domain,stale);
String r;
trans->requestAuth(getGlobal(r,s_realm),domain,stale);
}
@ -4508,6 +4515,9 @@ bool YateSIPEngine::copyAuthParams(NamedList* dest, const NamedList& src, bool o
NamedString* s = src.getParam(i);
if (!s)
continue;
// Don't copy added SIP headers: on success they will be added again
if (s->name().startsWith("sip_"))
continue;
String name = s->name();
if (name.startSkip("authfail_",false) == ok)
continue;
@ -4559,16 +4569,19 @@ bool YateSIPEngine::checkUser(String& username, const String& realm, const Strin
hl = message->getHeader("User-Agent");
if (hl)
m.addParam("device",*hl);
s_globalMutex.lock();
for (const ObjList* l = message->header.skipNull(); l; l = l->skipNext()) {
hl = static_cast<const MimeHeaderLine*>(l->get());
String name(hl->name());
name.toLower();
if (!name.startsWith("security-"))
if (!(name.startsWith("security-") ||
(s_authCopyHeader && s_authCopyHeader->find(name))))
continue;
String tmp;
hl->buildLine(tmp,false);
m.addParam("sip_" + name,tmp);
}
s_globalMutex.unlock();
}
if (params) {
@ -7804,8 +7817,8 @@ void YateSIPConnection::callRejected(const char* error, const char* reason, cons
Lock lock(driver());
if (m_tr && (m_tr->getState() == SIPTransaction::Process)) {
if ((code == 401) && (s_noAutoAuth != error)) {
Lock lck(s_globalMutex);
m_tr->requestAuth(s_realm,m_domain,false);
String r;
m_tr->requestAuth(getGlobal(r,s_realm),m_domain,false);
}
else if (msg) {
SIPMessage* m = new SIPMessage(m_tr->initialMessage(),code,reason);
@ -8858,6 +8871,7 @@ SIPDriver::SIPDriver()
SIPDriver::~SIPDriver()
{
Output("Unloading module SIP Channel");
TelEngine::destruct(s_authCopyHeader);
}
void SIPDriver::initialize()
@ -8869,6 +8883,7 @@ void SIPDriver::initialize()
s_globalMutex.lock();
s_cfg.load();
NamedList* general = s_cfg.getSection("general");
TelEngine::destruct(s_authCopyHeader);
if (general) {
String* dtmfMethods = general->getParam("dtmfmethods");
if (dtmfMethods) {
@ -8880,6 +8895,16 @@ void SIPDriver::initialize()
s_dtmfMethods.getDeprecatedDtmfMethod(*general,"dtmfinfo",DtmfMethods::Info,&s_warnDtmfInfoCfg);
s_dtmfMethods.getDeprecatedDtmfMethod(*general,"dtmfinband",DtmfMethods::Inband,&s_warnDtmfInbandCfg);
}
const String& tmp = (*general)[YSTRING("auth_copy_headers")];
if (tmp) {
s_authCopyHeader = tmp.split(',',false);
ObjList* o = s_authCopyHeader->skipNull();
if (o)
for (; o; o = o->skipNext())
(static_cast<String*>(o->get()))->toLower();
else
TelEngine::destruct(s_authCopyHeader);
}
}
else
s_dtmfMethods.setDefault();