From 5898f6807f1cee65244a13a29952ba40615a1f07 Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Sun, 1 Feb 2009 12:51:06 +0000 Subject: [PATCH] take account optionally from config file (overrides P-App-Param git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1252 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- apps/auth_b2b/AuthB2B.cpp | 39 +++++++++++++++++++++++---------- apps/auth_b2b/AuthB2B.h | 4 ++++ apps/auth_b2b/etc/auth_b2b.conf | 7 ++++++ 3 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 apps/auth_b2b/etc/auth_b2b.conf diff --git a/apps/auth_b2b/AuthB2B.cpp b/apps/auth_b2b/AuthB2B.cpp index 125b2195..4e5bd727 100644 --- a/apps/auth_b2b/AuthB2B.cpp +++ b/apps/auth_b2b/AuthB2B.cpp @@ -34,9 +34,13 @@ #include "AmAudio.h" #include "AmPlugIn.h" #include "AmMediaProcessor.h" -//#include "AmConfigReader.h" +#include "AmConfigReader.h" #include "AmSessionContainer.h" +string AuthB2BFactory::user; +string AuthB2BFactory::domain; +string AuthB2BFactory::pwd; + EXPORT_SESSION_FACTORY(AuthB2BFactory,MOD_NAME); AuthB2BFactory::AuthB2BFactory(const string& _app_name) @@ -48,9 +52,16 @@ AuthB2BFactory::AuthB2BFactory(const string& _app_name) int AuthB2BFactory::onLoad() { -// AmConfigReader cfg; -// if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) -// return -1; + AmConfigReader cfg; + if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) { + INFO("No configuration for auth_b2b present (%s)\n", + (AmConfig::ModConfigPath + string(MOD_NAME ".conf")).c_str() + ); + } else { + user = cfg.getParameter("user"); + domain = cfg.getParameter("domain"); + pwd = cfg.getParameter("pwd"); + } // user_timer_fact = AmPlugIn::instance()->getFactory4Di("user_timer"); // if(!user_timer_fact) { @@ -101,16 +112,22 @@ void AuthB2BDialog::onInvite(const AmSipRequest& req) setReceiving(false); AmMediaProcessor::instance()->removeSession(this); - string app_param = getHeader(req.hdrs, PARAM_HDR); + if (AuthB2BFactory::user.empty()) { + string app_param = getHeader(req.hdrs, PARAM_HDR); - if (!app_param.length()) { - AmSession::Exception(500, "auth_b2b: parameters not found"); + if (!app_param.length()) { + AmSession::Exception(500, "auth_b2b: parameters not found"); + } + + domain = get_header_keyvalue(app_param,"d"); + user = get_header_keyvalue(app_param,"u"); + password = get_header_keyvalue(app_param,"p"); + } else { + domain = AuthB2BFactory::domain; + user = AuthB2BFactory::user; + password = AuthB2BFactory::pwd; } - domain = get_header_keyvalue(app_param,"d"); - user = get_header_keyvalue(app_param,"u"); - password = get_header_keyvalue(app_param,"p"); - from = "sip:"+user+"@"+domain; to = "sip:"+req.user+"@"+domain; diff --git a/apps/auth_b2b/AuthB2B.h b/apps/auth_b2b/AuthB2B.h index e6791e11..5a841961 100644 --- a/apps/auth_b2b/AuthB2B.h +++ b/apps/auth_b2b/AuthB2B.h @@ -44,6 +44,10 @@ class AuthB2BFactory: public AmSessionFactory int onLoad(); AmSession* onInvite(const AmSipRequest& req); + static string user; + static string domain; + static string pwd; + }; class AuthB2BDialog : public AmB2BCallerSession diff --git a/apps/auth_b2b/etc/auth_b2b.conf b/apps/auth_b2b/etc/auth_b2b.conf new file mode 100644 index 00000000..e9803e18 --- /dev/null +++ b/apps/auth_b2b/etc/auth_b2b.conf @@ -0,0 +1,7 @@ + +# Account to use on the outgoing call leg. If this is not set, +# the account is taken from P-App-Param header (see Readme.auth_b2b) +# +# user=someuser +# domain=somedomain.net +# pwd=sompwd