[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 11:27:51 CST 2011
branch "authexten" has been updated
via b5c03db28904b7ab0b220ca5030a1dd4828169a1 (commit)
via e006915bdba4e8dead401dd98c896122e32b8974 (commit)
from 53b69af9a3afc348e8a00f2ca45ccd1225155c07 (commit)
Summary of changes:
src/AuthManager.cpp | 55 ++++++++++++++++++++-----------------------
src/AuthManager.h | 52 ++++++++++++++++-------------------------
src/PJSipSessionModule.cpp | 2 +-
3 files changed, 47 insertions(+), 62 deletions(-)
- Log -----------------------------------------------------------------
commit b5c03db28904b7ab0b220ca5030a1dd4828169a1
Author: Mark Michelson <mmichelson at digium.com>
Date: Tue Feb 15 11:07:04 2011 -0600
Add locking to the AuthManager. I'm trying to determine if it's necessary for the AuthInstance.
diff --git a/src/AuthManager.cpp b/src/AuthManager.cpp
index 0f8cc58..1b348f1 100644
--- a/src/AuthManager.cpp
+++ b/src/AuthManager.cpp
@@ -14,6 +14,8 @@
* at the top of the source tree.
*/
+#include <boost/thread.hpp>
+
#include "AuthManager.h"
using namespace AsteriskSCF::SIP::ExtensionPoint::V1;
@@ -301,6 +303,8 @@ public:
moduleHookVector mRegisteredHooks;
Logger mLogger;
int mCounter;
+ boost::mutex mHooksLock;
+ boost::mutex mAuthInstancesLock;
};
AuthManager::AuthManager(pjsip_endpoint *endpt, Logger &logger)
@@ -313,6 +317,7 @@ 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::lock_guard<boost::mutex> lock(mImpl->mAuthInstancesLock);
mImpl->mAuthInstances.push_back(instance);
return instance;
}
@@ -322,6 +327,7 @@ 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));
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();
iter != mImpl->mAuthInstances.end(); ++iter)
{
@@ -343,6 +349,7 @@ bool AuthManager::authenticate(pjsip_rx_data *rdata)
void AuthManager::destroyAuthInstance(const 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();
iter != mImpl->mAuthInstances.end(); ++ iter)
{
@@ -369,12 +376,14 @@ void AuthManager::addAuthHook(AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx
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);
mImpl->mRegisteredHooks.push_back(hookData);
std::stable_sort(mImpl->mRegisteredHooks.begin(), mImpl->mRegisteredHooks.end());
}
void AuthManager::removeAuthHook(AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx hook)
{
+ boost::lock_guard<boost::mutex> lock(mImpl->mHooksLock);
for (moduleHookVector::iterator iter = mImpl->mRegisteredHooks.begin();
iter != mImpl->mRegisteredHooks.end(); ++iter)
{
@@ -388,6 +397,7 @@ void AuthManager::removeAuthHook(AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookP
void AuthManager::clearAuthHooks()
{
+ boost::lock_guard<boost::mutex> lock(mImpl->mHooksLock);
mImpl->mRegisteredHooks.clear();
}
commit e006915bdba4e8dead401dd98c896122e32b8974
Author: Mark Michelson <mmichelson at digium.com>
Date: Tue Feb 15 10:12:42 2011 -0600
Some general cleanup.
* Move the scheduling and cancellation of timer entries into the
AuthInstance.
* Get rid of some of the one-off public AuthInstance methods in
favor of more generally useful ones.
* Fix up some documentation.
diff --git a/src/AuthManager.cpp b/src/AuthManager.cpp
index d212f6c..0f8cc58 100644
--- a/src/AuthManager.cpp
+++ b/src/AuthManager.cpp
@@ -167,10 +167,11 @@ bool AuthInstance::authenticate(pjsip_rx_data *rdata)
return false;
}
-pj_timer_entry *AuthInstance::createTimerEntry(int id)
+void AuthInstance::scheduleAuthTimeout(pjsip_endpoint *endpt, int id)
{
+ const pj_time_val time = {60, 0};
pj_timer_entry_init(&mImpl->entry, id, this, sessionAuthTimeout);
- return &mImpl->entry;
+ pjsip_endpt_schedule_timer(endpt, &mImpl->entry, &time);
}
void AuthInstance::addDigests(pjsip_tx_data *tdata, DigestChallengeSeq digests)
@@ -271,19 +272,14 @@ void AuthInstance::fillInRequestInfo(pjsip_rx_data *rdata, RequestInfoPtr info)
}
}
-std::string AuthInstance::getFromTag()
-{
- return mImpl->fromTag;
-}
-
-std::string AuthInstance::getCallId()
+bool AuthInstance::isEqual(const std::string &fromTag, const std::string &callId)
{
- return mImpl->callId;
+ return fromTag == mImpl->fromTag && callId == mImpl->callId;
}
-pj_timer_entry *AuthInstance::getTimerEntry()
+void AuthInstance::cancelAuthTimeout(pjsip_endpoint *endpt)
{
- return &mImpl->entry;
+ pjsip_endpt_cancel_timer(endpt, &mImpl->entry);
}
class AuthManagerPriv
@@ -323,19 +319,19 @@ boost::shared_ptr<AuthInstance> AuthManager::createAuthInstance(pjsip_rx_data *r
bool AuthManager::authenticate(pjsip_rx_data *rdata)
{
- std::string fromTag(pj_strbuf(&rdata->msg_info.from->tag), pj_strlen(&rdata->msg_info.from->tag));
- 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;
for (std::vector<boost::shared_ptr<AuthInstance> >::iterator iter = mImpl->mAuthInstances.begin();
iter != mImpl->mAuthInstances.end(); ++iter)
{
- if (fromTag == (*iter)->getFromTag() && callId == (*iter)->getCallId())
+ if ((*iter)->isEqual(fromTag, callId))
{
- if ((*iter)->authenticate(rdata) == true)
+ if ((*iter)->authenticate(rdata))
{
//If authentication has succeeded, then we can remove this AuthInstance
//from our list, and we need to cancel the scheduled task
- pjsip_endpt_cancel_timer(mImpl->mEndpoint, (*iter)->getTimerEntry());
+ (*iter)->cancelAuthTimeout(mImpl->mEndpoint);
mImpl->mAuthInstances.erase(iter);
return true;
}
@@ -358,24 +354,15 @@ void AuthManager::destroyAuthInstance(const boost::shared_ptr<AuthInstance> &ins
}
}
-void AuthManager::scheduleAuthDestruction(const boost::shared_ptr<AuthInstance> &instance)
+void AuthManager::scheduleAuthTimeout(const boost::shared_ptr<AuthInstance> &instance)
{
- const pj_time_val time = {60, 0};
- pj_timer_entry *entry = instance->createTimerEntry(mImpl->mCounter++);
- pjsip_endpt_schedule_timer(mImpl->mEndpoint, entry, &time);
+ instance->scheduleAuthTimeout(mImpl->mEndpoint, mImpl->mCounter++);
}
void AuthManager::authTimeout(pj_timer_heap_t *timer_heap, pj_timer_entry *entry)
{
- for (std::vector<boost::shared_ptr<AuthInstance> >::iterator iter = mImpl->mAuthInstances.begin();
- iter != mImpl->mAuthInstances.end(); ++iter)
- {
- if (entry->id == (*iter)->getTimerEntry()->id)
- {
- mImpl->mAuthInstances.erase(iter);
- return;
- }
- }
+ boost::shared_ptr<AuthInstance> killMe((AuthInstance *)entry->user_data);
+ destroyAuthInstance(killMe);
}
void AuthManager::addAuthHook(AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx hook,
diff --git a/src/AuthManager.h b/src/AuthManager.h
index b67bd4a..a6003de 100644
--- a/src/AuthManager.h
+++ b/src/AuthManager.h
@@ -51,6 +51,7 @@ public:
AsteriskSCF::SIP::ExtensionPoint::V1::RequestType type,
pj_pool_t *pool,
const AsteriskSCF::System::Logging::Logger &logger);
+
/**
* The AuthInstance is able to distill all of the registered hooks
* down to a smaller list based on the request types that the hooks
@@ -58,59 +59,46 @@ public:
* list of hooks.
*/
std::vector<AsteriskSCF::SIP::ExtensionPoint::V1::AuthHookPrx> getHooks();
+
/**
* This function is a convenience function to fill in the common
* data elements of a RequestInfo class given incoming request
* data.
*/
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);
+
/**
* Attempt to authenticate an incoming request.
*
- * It's not necessary to call this function directly since
- * the AuthManager will take care of it for you. The method needs
- * to be public so that the AuthManager is capable of calling it.
+ * It's most convenient to just call AuthManager::authenticate() so
+ * that the proper AuthInstance may be found for you.
*/
bool authenticate(pjsip_rx_data *rdata);
+
/**
- * Create a pj_timer_entry with the given id.
- * For more information about our interaction with
- * PJLIB's scheduler, see AuthManager::scheduleAuthDestruction.
- *
- * It's not necessary to call this function directly since
- * the AuthManager will take care of it for you. The method needs
- * to be public so that the AuthManager is capable of calling it.
- */
- pj_timer_entry *createTimerEntry(int id);
- /**
- * Get the From tag from the original unauthenticated request.
+ * Schedule the destruction of this AuthInstance.
*
- * It's likely you'll never need to use this function yourself.
- * The method needs to be public so that the AuthManager is
- * capable of calling it
+ * This will generally be called via AuthManager::scheduleAuthTimeout
+ * so that the id parameter can be guaranteed to be unique per
+ * AuthInstance.
*/
- std::string getFromTag();
+ void scheduleAuthTimeout(pjsip_endpoint *endpt, int id);
+
/**
- * Get the Call-id from the original unauthenticated request.
- *
- * It's likely you'll never need to use this function yourself.
- * The method needs to be public so that the AuthManager is
- * capable of calling it
+ * Cancel the current scheduled auth timeout task on the AuthInstance.
*/
- std::string getCallId();
+ void cancelAuthTimeout(pjsip_endpoint *endpt);
+
/**
- * Get the pj_timer_entry that was created using
- * createTimerEntry().
- *
- * It's likely you'll never need to use this function yourself.
- * The method needs to be public so that the AuthManager is
- * capable of calling it
+ * Determine if this AuthInstance matches a message with the given
+ * from tag and call-id.
*/
- pj_timer_entry *getTimerEntry();
+ bool isEqual(const std::string &fromTag, const std::string &callId);
private:
boost::shared_ptr<AuthInstancePriv> mImpl;
};
@@ -156,7 +144,7 @@ public:
* the requester does not attempt to authenticate or never succeeds
* in authenticating, the AuthInstance will eventually be destroyed.
*/
- void scheduleAuthDestruction(const boost::shared_ptr<AuthInstance> &instance);
+ void scheduleAuthTimeout(const boost::shared_ptr<AuthInstance> &instance);
/**
* Destroy an AuthInstance
*
diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 5a37de0..3462438 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -483,7 +483,7 @@ bool PJSipSessionModule::checkAuth(pjsip_rx_data *rdata, pjsip_inv_session *inv,
pjsip_inv_send_msg(inv, tdata);
- mAuthManager->scheduleAuthDestruction(authInstance);
+ mAuthManager->scheduleAuthTimeout(authInstance);
return true;
}
}
-----------------------------------------------------------------------
--
asterisk-scf/release/sip.git
More information about the asterisk-scf-commits
mailing list