[asterisk-scf-commits] asterisk-scf/release/sip.git branch "authexten" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Tue Feb 15 14:05:47 CST 2011
branch "authexten" has been updated
via f63d75ebd26753eed1a2733ecbd21fe8f2a58044 (commit)
from b5c03db28904b7ab0b220ca5030a1dd4828169a1 (commit)
Summary of changes:
src/AuthManager.cpp | 71 +++++++++++++++++++++++++++++++-------------------
src/AuthManager.h | 12 ++++----
2 files changed, 50 insertions(+), 33 deletions(-)
- Log -----------------------------------------------------------------
commit f63d75ebd26753eed1a2733ecbd21fe8f2a58044
Author: Mark Michelson <mmichelson at digium.com>
Date: Tue Feb 15 14:05:01 2011 -0600
Make some final improvements.
* Use const and use references where it makes sense to do so.
* Split some of the longer lines so they go on multiples.
Next stop: crucible!
diff --git a/src/AuthManager.cpp b/src/AuthManager.cpp
index 1b348f1..b74db56 100644
--- a/src/AuthManager.cpp
+++ b/src/AuthManager.cpp
@@ -31,7 +31,8 @@ namespace SipSessionManager
class AuthHookData
{
public:
- AuthHookData(int priority, AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx hook, AsteriskSCF::SIP::ExtensionPoint::V1::RequestTypeSeq types)
+ AuthHookData(int priority, const AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx &hook,
+ AsteriskSCF::SIP::ExtensionPoint::V1::RequestTypeSeq &types)
: mPriority(priority), mHook(hook), mTypes(types) { }
bool operator< (const AuthHookData &rhs) const
@@ -47,7 +48,8 @@ public:
class AuthInstancePriv
{
public:
- AuthInstancePriv(pjsip_rx_data *rdata, moduleHookVector moduleHooks, RequestType type, pj_pool_t *pool, const Logger &logger)
+ AuthInstancePriv(pjsip_rx_data *rdata, const moduleHookVector &moduleHooks,
+ RequestType type, pj_pool_t *pool, const Logger &logger)
: mPool(pool), mLogger(logger),
fromTag(pj_strbuf(&rdata->msg_info.from->tag), pj_strlen(&rdata->msg_info.from->tag)),
callId(pj_strbuf(&rdata->msg_info.cid->id), pj_strlen(&rdata->msg_info.cid->id))
@@ -57,7 +59,7 @@ public:
return;
}
- for (moduleHookVector::iterator iter = moduleHooks.begin(); iter != moduleHooks.end(); ++iter)
+ for (moduleHookVector::const_iterator iter = moduleHooks.begin(); iter != moduleHooks.end(); ++iter)
{
RequestTypeSeq types = (*iter)->mTypes;
AuthHookPrx hook = (*iter)->mHook;
@@ -71,21 +73,27 @@ public:
}
}
- void getURIParams(pjsip_uri *uri, ParamDict ¶ms)
+ void getURIParams(const pjsip_uri *uri, ParamDict ¶ms)
{
pjsip_sip_uri *sipURI = (pjsip_sip_uri *) pjsip_uri_get_uri(uri);
if (pj_strlen(&sipURI->user_param) != 0)
{
- params.insert(std::make_pair("user", std::string(pj_strbuf(&sipURI->user_param), pj_strlen(&sipURI->user_param))));
+ params.insert(std::make_pair("user",
+ std::string(pj_strbuf(&sipURI->user_param),
+ pj_strlen(&sipURI->user_param))));
}
if (pj_strlen(&sipURI->method_param) != 0)
{
- params.insert(std::make_pair("method", std::string(pj_strbuf(&sipURI->method_param), pj_strlen(&sipURI->method_param))));
+ params.insert(std::make_pair("method",
+ std::string(pj_strbuf(&sipURI->method_param),
+ pj_strlen(&sipURI->method_param))));
}
if (pj_strlen(&sipURI->transport_param) != 0)
{
- params.insert(std::make_pair("transport", std::string(pj_strbuf(&sipURI->transport_param), pj_strlen(&sipURI->transport_param))));
+ params.insert(std::make_pair("transport",
+ std::string(pj_strbuf(&sipURI->transport_param),
+ pj_strlen(&sipURI->transport_param))));
}
if (sipURI->ttl_param != -1)
{
@@ -100,7 +108,8 @@ public:
params.insert(std::make_pair("lr", std::string()));
}
- for (pjsip_param *iter = sipURI->other_param.next; iter != &sipURI->other_param; iter = iter->next)
+ for (pjsip_param *iter = sipURI->other_param.next;
+ iter != &sipURI->other_param; iter = iter->next)
{
std::string name(pj_strbuf(&iter->name), pj_strlen(&iter->name));
std::string value(pj_strbuf(&iter->value), pj_strlen(&iter->value));
@@ -117,7 +126,8 @@ public:
std::string callId;
};
-AuthInstance::AuthInstance(pjsip_rx_data *rdata, moduleHookVector hooks, RequestType type, pj_pool_t *pool, const Logger &logger)
+AuthInstance::AuthInstance(pjsip_rx_data *rdata, const moduleHookVector &hooks,
+ RequestType type, pj_pool_t *pool, const Logger &logger)
: mImpl(new AuthInstancePriv(rdata, hooks, type, pool, logger)) { }
std::vector<AuthHookPrx> AuthInstance::getHooks()
@@ -125,7 +135,8 @@ std::vector<AuthHookPrx> AuthInstance::getHooks()
return mImpl->hooks;
}
-static pj_status_t lookup_cred(pj_pool_t *pool, const pj_str_t *realm, const pj_str_t *acc_name, pjsip_cred_info *cred_info)
+static pj_status_t lookup_cred(pj_pool_t *pool, const pj_str_t *realm,
+ const pj_str_t *acc_name, pjsip_cred_info *cred_info)
{
//XXX I'm still not 100% sure I understand the purpose of this function. Apparently, when I call
//pjsip_srv_auth_verify(), it then will call into this function with a realm and account name, and
@@ -149,7 +160,8 @@ bool AuthInstance::authenticate(pjsip_rx_data *rdata)
//For each server auth, we need to call pjsip_auth_srv_verify(), which will then
//annoyingly call into the lookup function we created for pjsip. That's where the
//real fun begins :(
- for (std::vector<pjsip_auth_srv *>::iterator iter = mImpl->authServers.begin(); iter != mImpl->authServers.end(); ++iter)
+ for (std::vector<pjsip_auth_srv *>::iterator iter = mImpl->authServers.begin();
+ iter != mImpl->authServers.end(); ++iter)
{
int status_code;
pj_status_t status = pjsip_auth_srv_verify(*iter, rdata, &status_code);
@@ -176,11 +188,12 @@ void AuthInstance::scheduleAuthTimeout(pjsip_endpoint *endpt, int id)
pjsip_endpt_schedule_timer(endpt, &mImpl->entry, &time);
}
-void AuthInstance::addDigests(pjsip_tx_data *tdata, DigestChallengeSeq digests)
+void AuthInstance::addDigests(pjsip_tx_data *tdata, const DigestChallengeSeq &digests)
{
static char qop[] = "auth";
pj_str_t pjqop = pj_str(qop);
- for (DigestChallengeSeq::iterator digest = digests.begin(); digest != digests.end(); ++digest)
+ for (DigestChallengeSeq::const_iterator digest = digests.begin();
+ digest != digests.end(); ++digest)
{
pjsip_auth_srv *authServer = PJ_POOL_ZALLOC_T(mImpl->mPool, pjsip_auth_srv);
pj_str_t realm;
@@ -202,12 +215,12 @@ void AuthInstance::addDigests(pjsip_tx_data *tdata, DigestChallengeSeq digests)
}
}
-void AuthInstance::fillInRequestInfo(pjsip_rx_data *rdata, RequestInfoPtr info)
+void AuthInstance::fillInRequestInfo(pjsip_rx_data *rdata, RequestInfoPtr &info)
{
char buf[512];
size_t pos;
- pjsip_name_addr *from = (pjsip_name_addr *)rdata->msg_info.from->uri;
+ pjsip_name_addr *from = (pjsip_name_addr *) rdata->msg_info.from->uri;
info->fromName = std::string(pj_strbuf(&from->display), pj_strlen(&from->display));
mImpl->mLogger(Debug) << "from name is " << info->fromName;
@@ -224,7 +237,7 @@ void AuthInstance::fillInRequestInfo(pjsip_rx_data *rdata, RequestInfoPtr info)
mImpl->getURIParams(from->uri, info->fromParams);
}
- pjsip_name_addr *to = (pjsip_name_addr *)rdata->msg_info.to->uri;
+ pjsip_name_addr *to = (pjsip_name_addr *) rdata->msg_info.to->uri;
info->toName = std::string(pj_strbuf(&to->display), pj_strlen(&to->display));
mImpl->mLogger(Debug) << "to name is " << info->toName;
@@ -241,7 +254,7 @@ void AuthInstance::fillInRequestInfo(pjsip_rx_data *rdata, RequestInfoPtr info)
mImpl->getURIParams(to->uri, info->toParams);
}
- pjsip_uri *rURI = (pjsip_uri *) pjsip_uri_get_uri(rdata->msg_info.msg->line.req.uri);
+ pjsip_uri *rURI = static_cast<pjsip_uri *>(pjsip_uri_get_uri(rdata->msg_info.msg->line.req.uri));
pjsip_uri_print(PJSIP_URI_IN_REQ_URI, rURI, buf, sizeof(buf));
std::string rURIStr(buf, strlen(buf));
pos = rURIStr.find_first_of(';');
@@ -254,7 +267,8 @@ void AuthInstance::fillInRequestInfo(pjsip_rx_data *rdata, RequestInfoPtr info)
mImpl->getURIParams(rURI, info->requestURIParams);
}
- info->IPAddr = std::string(pj_sockaddr_print((pj_sockaddr_t *) &rdata->pkt_info.src_addr, buf, rdata->pkt_info.src_addr_len, 0), rdata->pkt_info.src_addr_len);
+ info->IPAddr = std::string(pj_sockaddr_print(static_cast<pj_sockaddr_t *> (&rdata->pkt_info.src_addr),
+ buf, rdata->pkt_info.src_addr_len, 0), rdata->pkt_info.src_addr_len);
info->port = rdata->pkt_info.src_port;
std::string transport(rdata->tp_info.transport->type_name);
if (transport == "tcp")
@@ -287,7 +301,7 @@ void AuthInstance::cancelAuthTimeout(pjsip_endpoint *endpt)
class AuthManagerPriv
{
public:
- AuthManagerPriv(pjsip_endpoint *endpt, Logger &logger)
+ AuthManagerPriv(pjsip_endpoint *endpt, const Logger &logger)
: mPool(pjsip_endpt_create_pool(endpt, "auth%p", 1200, 512)),
mLogger(logger) { }
@@ -307,7 +321,7 @@ public:
boost::mutex mAuthInstancesLock;
};
-AuthManager::AuthManager(pjsip_endpoint *endpt, Logger &logger)
+AuthManager::AuthManager(pjsip_endpoint *endpt, const Logger &logger)
: mImpl(new AuthManagerPriv(endpt, logger)) { }
AuthManager::~AuthManager()
@@ -316,7 +330,8 @@ AuthManager::~AuthManager()
boost::shared_ptr<AuthInstance> AuthManager::createAuthInstance(pjsip_rx_data *rdata, RequestType type)
{
- boost::shared_ptr<AuthInstance> instance(new AuthInstance(rdata, mImpl->mRegisteredHooks, type, mImpl->mPool, mImpl->mLogger));
+ boost::shared_ptr<AuthInstance> instance(new AuthInstance(rdata, mImpl->mRegisteredHooks,
+ type, mImpl->mPool, mImpl->mLogger));
boost::lock_guard<boost::mutex> lock(mImpl->mAuthInstancesLock);
mImpl->mAuthInstances.push_back(instance);
return instance;
@@ -324,8 +339,10 @@ boost::shared_ptr<AuthInstance> AuthManager::createAuthInstance(pjsip_rx_data *r
bool AuthManager::authenticate(pjsip_rx_data *rdata)
{
- const std::string fromTag(pj_strbuf(&rdata->msg_info.from->tag), pj_strlen(&rdata->msg_info.from->tag));
- const std::string callId(pj_strbuf(&rdata->msg_info.cid->id), pj_strlen(&rdata->msg_info.cid->id));
+ const std::string fromTag(pj_strbuf(&rdata->msg_info.from->tag),
+ pj_strlen(&rdata->msg_info.from->tag));
+ const std::string callId(pj_strbuf(&rdata->msg_info.cid->id),
+ pj_strlen(&rdata->msg_info.cid->id));
boost::shared_ptr<AuthInstance> instance;
boost::lock_guard<boost::mutex> lock(mImpl->mAuthInstancesLock);
for (std::vector<boost::shared_ptr<AuthInstance> >::iterator iter = mImpl->mAuthInstances.begin();
@@ -368,12 +385,12 @@ void AuthManager::scheduleAuthTimeout(const boost::shared_ptr<AuthInstance> &ins
void AuthManager::authTimeout(pj_timer_heap_t *timer_heap, pj_timer_entry *entry)
{
- boost::shared_ptr<AuthInstance> killMe((AuthInstance *)entry->user_data);
+ boost::shared_ptr<AuthInstance> killMe(static_cast<AuthInstance *>(entry->user_data));
destroyAuthInstance(killMe);
}
-void AuthManager::addAuthHook(AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx hook,
- int priority, AsteriskSCF::SIP::ExtensionPoint::V1::RequestTypeSeq types)
+void AuthManager::addAuthHook(const AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx &hook,
+ int priority, AsteriskSCF::SIP::ExtensionPoint::V1::RequestTypeSeq &types)
{
boost::shared_ptr<AuthHookData> hookData(new AuthHookData(priority, hook, types));
boost::lock_guard<boost::mutex> lock(mImpl->mHooksLock);
@@ -381,7 +398,7 @@ void AuthManager::addAuthHook(AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx
std::stable_sort(mImpl->mRegisteredHooks.begin(), mImpl->mRegisteredHooks.end());
}
-void AuthManager::removeAuthHook(AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx hook)
+void AuthManager::removeAuthHook(const AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx &hook)
{
boost::lock_guard<boost::mutex> lock(mImpl->mHooksLock);
for (moduleHookVector::iterator iter = mImpl->mRegisteredHooks.begin();
diff --git a/src/AuthManager.h b/src/AuthManager.h
index a6003de..57b1333 100644
--- a/src/AuthManager.h
+++ b/src/AuthManager.h
@@ -47,7 +47,7 @@ class AuthInstance
{
public:
AuthInstance(pjsip_rx_data *rdata,
- moduleHookVector hooks,
+ const moduleHookVector &hooks,
AsteriskSCF::SIP::ExtensionPoint::V1::RequestType type,
pj_pool_t *pool,
const AsteriskSCF::System::Logging::Logger &logger);
@@ -65,12 +65,12 @@ public:
* data elements of a RequestInfo class given incoming request
* data.
*/
- void fillInRequestInfo(pjsip_rx_data *rdata, AsteriskSCF::SIP::ExtensionPoint::V1::RequestInfoPtr info);
+ void fillInRequestInfo(pjsip_rx_data *rdata, AsteriskSCF::SIP::ExtensionPoint::V1::RequestInfoPtr &info);
/**
* Add digest information to an outgoing response
*/
- void addDigests(pjsip_tx_data *tdata, AsteriskSCF::SIP::ExtensionPoint::V1::DigestChallengeSeq digests);
+ void addDigests(pjsip_tx_data *tdata, const AsteriskSCF::SIP::ExtensionPoint::V1::DigestChallengeSeq &digests);
/**
* Attempt to authenticate an incoming request.
@@ -114,7 +114,7 @@ class AuthManagerPriv;
class AuthManager
{
public:
- AuthManager(pjsip_endpoint *endpt, AsteriskSCF::System::Logging::Logger& logger);
+ AuthManager(pjsip_endpoint *endpt, const AsteriskSCF::System::Logging::Logger& logger);
~AuthManager();
/**
* Attempt to authenticate a request
@@ -162,11 +162,11 @@ public:
/**
* Register a new authentication hook with the AuthManager
*/
- void addAuthHook(AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx hook, int priority, AsteriskSCF::SIP::ExtensionPoint::V1::RequestTypeSeq types);
+ void addAuthHook(const AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx &hook, int priority, AsteriskSCF::SIP::ExtensionPoint::V1::RequestTypeSeq &types);
/**
* Remove a registered authentication hook from the AuthManager
*/
- void removeAuthHook(AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx hook);
+ void removeAuthHook(const AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx &hook);
/**
* Remove all registered authentication hooks from the AuthManager
*/
-----------------------------------------------------------------------
--
asterisk-scf/release/sip.git
More information about the asterisk-scf-commits
mailing list