[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "registrar" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Tue Jul 5 13:35:00 CDT 2011
branch "registrar" has been updated
via e528d7be81f34ac1789b74ad7415de949a1c19ed (commit)
via b61e242edd548a82eb5a492c7ffb16835746ceaa (commit)
via 32c65526dd56d0bc7e03148dfd407bfa40423fff (commit)
from ef373b282be4a218a92e9981fc0c3163c181603b (commit)
Summary of changes:
src/PJSipRegistrarModule.cpp | 167 +++++++++++++++++++++++-------------
src/PJSipRegistrarModule.h | 3 +-
src/SipStateReplicatorListener.cpp | 8 +-
3 files changed, 115 insertions(+), 63 deletions(-)
- Log -----------------------------------------------------------------
commit e528d7be81f34ac1789b74ad7415de949a1c19ed
Author: Mark Michelson <mmichelson at digium.com>
Date: Tue Jul 5 13:34:47 2011 -0500
s/updateBindings/addAndRemoveBindings/
The name change helps to differentiate it from updateBinding() and
it also makes it more clear what is actually being done.
diff --git a/src/PJSipRegistrarModule.cpp b/src/PJSipRegistrarModule.cpp
index 67697b7..b01832a 100644
--- a/src/PJSipRegistrarModule.cpp
+++ b/src/PJSipRegistrarModule.cpp
@@ -471,10 +471,10 @@ void PJSipRegistrarModule::replicateState(
//XXX This and the method that queues this work should
//have different names. It's easy to get confused with
//UpdateBinding, and this could stand to be more descriptive
-class UpdateBindings : public Work
+class AddAndRemoveBindings : public Work
{
public:
- UpdateBindings(
+ AddAndRemoveBindings(
const RegistrarIPtr& registrar,
const std::string& aor,
const BindingWrapperSeq& newBindings,
@@ -532,9 +532,9 @@ private:
BindingWrapperSeq mRemovedBindings;
};
-void RegistrarI::updateBindings(const std::string &aor, BindingWrapperSeq& newBindings, BindingWrapperSeq& removedBindings, const QueuePtr& queue)
+void RegistrarI::addAndRemoveBindings(const std::string &aor, BindingWrapperSeq& newBindings, BindingWrapperSeq& removedBindings, const QueuePtr& queue)
{
- queue->enqueueWork(new UpdateBindings(this, aor, newBindings, removedBindings));
+ queue->enqueueWork(new AddAndRemoveBindings(this, aor, newBindings, removedBindings));
}
BindingUpdateSeq RegistrarI::createBindingUpdateSeq(const std::string& aor, BindingWrapperSeq& bindings)
@@ -784,7 +784,7 @@ pj_bool_t PJSipRegistrarModule::on_rx_request(pjsip_rx_data *rdata)
}
}
- mRegistrar->updateBindings(aor, newBindings, removedBindings, mRegistrar->getQueue());
+ mRegistrar->addAndRemoveBindings(aor, newBindings, removedBindings, mRegistrar->getQueue());
// We enqueue the SIP response to make sure we send it and replicate state AFTER we have updated
// our internal bindings.
diff --git a/src/PJSipRegistrarModule.h b/src/PJSipRegistrarModule.h
index c29e24b..6105e5d 100644
--- a/src/PJSipRegistrarModule.h
+++ b/src/PJSipRegistrarModule.h
@@ -64,7 +64,7 @@ public:
void removeBinding(BindingWrapperSeq& currentBindings, BindingWrapperPtr wrapper);
void removeAOR(const std::string& aor);
- void updateBindings(
+ void addAndRemoveBindings(
const std::string &aor,
BindingWrapperSeq& newBindings,
BindingWrapperSeq& removedBindings,
diff --git a/src/SipStateReplicatorListener.cpp b/src/SipStateReplicatorListener.cpp
index c25b800..41f1fd9 100644
--- a/src/SipStateReplicatorListener.cpp
+++ b/src/SipStateReplicatorListener.cpp
@@ -126,7 +126,7 @@ public:
//that we've already expired and removed. No biggie. Just
//keep going.
}
- regModule->getRegistrar()->updateBindings(dictIter->first, emptySeq, toRemove, regModule->getRegistrar()->getQueue());
+ regModule->getRegistrar()->addAndRemoveBindings(dictIter->first, emptySeq, toRemove, regModule->getRegistrar()->getQueue());
}
}
@@ -153,7 +153,7 @@ public:
void setNewRegistrationState(const PJSipRegistrarModulePtr& regModule, const SipRegistrarStateItemPtr& regItem)
{
//For new registrations, we need to create a sequence of BindingWrappers and call the registrar's
- //updateBindings() function.
+ //addAndRemoveBindings() function.
for (BindingDict::iterator dictIter = regItem->bindings.begin();
dictIter != regItem->bindings.end(); ++dictIter)
{
@@ -166,7 +166,7 @@ public:
BindingWrapperPtr wrapper = createBindingWrapper(dictIter->first, *seqIter, regModule);
wrapperSeq.push_back(wrapper);
}
- regModule->getRegistrar()->updateBindings(dictIter->first, wrapperSeq, emptySeq, regModule->getRegistrar()->getQueue());
+ regModule->getRegistrar()->addAndRemoveBindings(dictIter->first, wrapperSeq, emptySeq, regModule->getRegistrar()->getQueue());
}
}
@@ -203,7 +203,7 @@ public:
}
if (!newBindings.empty())
{
- regModule->getRegistrar()->updateBindings(dictIter->first, newBindings, emptySeq, regModule->getRegistrar()->getQueue());
+ regModule->getRegistrar()->addAndRemoveBindings(dictIter->first, newBindings, emptySeq, regModule->getRegistrar()->getQueue());
}
}
}
commit b61e242edd548a82eb5a492c7ffb16835746ceaa
Author: Mark Michelson <mmichelson at digium.com>
Date: Tue Jul 5 13:19:51 2011 -0500
Fix the addListener method to actually return content.
diff --git a/src/PJSipRegistrarModule.cpp b/src/PJSipRegistrarModule.cpp
index a8e18f7..67697b7 100644
--- a/src/PJSipRegistrarModule.cpp
+++ b/src/PJSipRegistrarModule.cpp
@@ -177,9 +177,7 @@ public:
lg(Debug) << "Adding Listener " << mListener->ice_getIdentity().name << " to registrar";
listeners.push_back(mListener);
}
- //We should maybe throw an exception if someone tries to insert a duplicate?
- //XXX Need to update this to actually return something.
- mCB->ice_response(ContactDict());
+ mCB->ice_response(mRegistrar->createContactDict(mRegistrar->getBindings()));
}
private:
AMD_Registrar_addListenerPtr mCB;
@@ -337,6 +335,22 @@ void RegistrarI::removeAOR(const std::string& aor)
mBindings.erase(aor);
}
+ContactDict RegistrarI::createContactDict(const BindingWrapperDict& bindings)
+{
+ Ice::StringSeq returnedContacts;
+ ContactDict dict;
+ for (BindingWrapperDict::const_iterator dictIter = bindings.begin();
+ dictIter != bindings.end(); ++dictIter)
+ {
+ for (BindingWrapperSeq::const_iterator seqIter = dictIter->second.begin();
+ seqIter != dictIter->second.end(); ++seqIter)
+ {
+ dict[dictIter->first].push_back((*seqIter)->mBinding->contact);
+ }
+ }
+ return dict;
+}
+
BindingDict RegistrarI::createBindingDict(const std::string& aor, const BindingWrapperSeq& bindings)
{
BindingSeq returnedBindings;
diff --git a/src/PJSipRegistrarModule.h b/src/PJSipRegistrarModule.h
index 76b422a..c29e24b 100644
--- a/src/PJSipRegistrarModule.h
+++ b/src/PJSipRegistrarModule.h
@@ -76,6 +76,7 @@ public:
AsteriskSCF::SIP::Registration::V1::BindingDict createBindingDict(const std::string& aor, const BindingWrapperSeq& bindings);
+ AsteriskSCF::SIP::Registration::V1::ContactDict createContactDict(const BindingWrapperDict& bindings);
std::vector<AsteriskSCF::SIP::Registration::V1::RegistrarListenerPrx>& getListeners();
commit 32c65526dd56d0bc7e03148dfd407bfa40423fff
Author: Mark Michelson <mmichelson at digium.com>
Date: Tue Jul 5 11:09:27 2011 -0500
Get state replication and the SIP response to the REGISTER properly queued.
diff --git a/src/PJSipRegistrarModule.cpp b/src/PJSipRegistrarModule.cpp
index 8fd413e..a8e18f7 100644
--- a/src/PJSipRegistrarModule.cpp
+++ b/src/PJSipRegistrarModule.cpp
@@ -21,6 +21,7 @@
#include <AsteriskSCF/WorkQueue/DefaultQueueListener.h>
#include "PJSipRegistrarModule.h"
+#include "PJSipManager.h"
using namespace AsteriskSCF::SIP::Registration::V1;
using namespace AsteriskSCF::System::Logging;
@@ -82,7 +83,6 @@ BindingWrapper::BindingWrapper(
pj_timer_entry_init(&mEntry, expirationId++, this, registrationExpired);
lg(Debug) << "Scheduling binding " << mBinding->contact << " for expiration in " << expiration << " seconds.";
scheduleRegistrationExpiration(expiration);
- pjsip_endpt_schedule_timer(mEndpoint, &mEntry, &delay);
}
BindingWrapper::~BindingWrapper()
@@ -143,7 +143,7 @@ RegistrarI::RegistrarI(const RegistrarListenerPrx& defaultListener)
{
lg(Debug) << "In RegistrarI constructor, should be adding a listener...";
mQueue = new AsteriskSCF::WorkQueue::WorkQueue();
- AsteriskSCF::WorkQueue::DefaultQueueListenerPtr listener(new AsteriskSCF::WorkQueue::DefaultQueueListener(mQueue));
+ AsteriskSCF::WorkQueue::DefaultQueueListenerPtr listener(new AsteriskSCF::WorkQueue::DefaultQueueListener(mQueue, new pjlibHook()));
mQueue->setListener(listener);
mListeners.push_back(defaultListener);
}
@@ -365,21 +365,80 @@ QueuePtr RegistrarI::getQueue()
return mQueue;
}
-//XXX
-//This function is called both from the work queue and from outside the
-//work queue. Either this needs to be made into its own queueable operation,
-//or it needs locking. Preferably, this will just be another queueable operation
-//though.
+class ReplicateState : public Work
+{
+public:
+ ReplicateState(
+ const AsteriskSCF::Replication::SipSessionManager::V1::SipStateReplicatorPrx& stateReplicator,
+ const std::string &aor,
+ const BindingWrapperSeq& existingBindings,
+ const BindingWrapperSeq& newBindings,
+ const BindingWrapperSeq& removedBindings,
+ const RegistrarIPtr& registrar)
+ : mStateReplicator(stateReplicator), mAOR(aor), mExistingBindings(existingBindings), mNewBindings(newBindings),
+ mRemovedBindings(removedBindings), mRegistrar(registrar) { }
+
+ void execute()
+ {
+ try
+ {
+ if (!mNewBindings.empty())
+ {
+ BindingDict newDict = mRegistrar->createBindingDict(mAOR, mNewBindings);
+ SipRegistrarStateItemPtr newItem(new SipRegistrarStateItem(mAOR, mAOR, newDict, true));
+ SipStateItemSeq items;
+ items.push_back(newItem);
+ mStateReplicator->setState(items);
+ }
+
+ if (!mExistingBindings.empty())
+ {
+ BindingDict existingDict = mRegistrar->createBindingDict(mAOR, mExistingBindings);
+ SipRegistrarStateItemPtr existingItem(new SipRegistrarStateItem(mAOR, mAOR, existingDict, false));
+ SipStateItemSeq items;
+ items.push_back(existingItem);
+ mStateReplicator->setState(items);
+ }
+
+ if (!mRemovedBindings.empty())
+ {
+ BindingDict removedDict = mRegistrar->createBindingDict(mAOR, mRemovedBindings);
+ SipRegistrarStateItemPtr removedItem(new SipRegistrarStateItem(mAOR, mAOR, removedDict, false));
+ SipStateItemSeq items;
+ items.push_back(removedItem);
+ mStateReplicator->removeStateForItems(items);
+ }
+ }
+ catch (const Ice::TwowayOnlyException&)
+ {
+ lg(Error) << "State replication operations are not oneway";
+ }
+ catch (const Ice::Exception& ex)
+ {
+ lg(Error) << "Exception caught attempting to replicate state in registrar\n" << ex.what();
+ }
+
+ }
+private:
+ AsteriskSCF::Replication::SipSessionManager::V1::SipStateReplicatorPrx mStateReplicator;
+ const std::string mAOR;
+ BindingWrapperSeq mExistingBindings;
+ BindingWrapperSeq mNewBindings;
+ BindingWrapperSeq mRemovedBindings;
+ RegistrarIPtr mRegistrar;
+};
+
void PJSipRegistrarModule::replicateState(
const std::string &aor,
const BindingWrapperSeq& existingBindings,
const BindingWrapperSeq& newBindings,
const BindingWrapperSeq& removedBindings)
{
+
+ AsteriskSCF::Replication::SipSessionManager::V1::SipStateReplicatorPrx oneWayStateReplicator;
try
{
- AsteriskSCF::Replication::SipSessionManager::V1::SipStateReplicatorPrx oneWayStateReplicator =
- AsteriskSCF::Replication::SipSessionManager::V1::SipStateReplicatorPrx::uncheckedCast(mStateReplicator->ice_oneway());
+ oneWayStateReplicator = AsteriskSCF::Replication::SipSessionManager::V1::SipStateReplicatorPrx::uncheckedCast(mStateReplicator->ice_oneway());
}
catch (const Ice::NoEndpointException&)
{
@@ -392,43 +451,7 @@ void PJSipRegistrarModule::replicateState(
return;
}
- try
- {
- if (!newBindings.empty())
- {
- BindingDict newDict = mRegistrar->createBindingDict(aor, newBindings);
- SipRegistrarStateItemPtr newItem(new SipRegistrarStateItem(aor, aor, newDict, true));
- SipStateItemSeq items;
- items.push_back(newItem);
- mStateReplicator->setState(items);
- }
-
- if (!existingBindings.empty())
- {
- BindingDict existingDict = mRegistrar->createBindingDict(aor, existingBindings);
- SipRegistrarStateItemPtr existingItem(new SipRegistrarStateItem(aor, aor, existingDict, false));
- SipStateItemSeq items;
- items.push_back(existingItem);
- mStateReplicator->setState(items);
- }
-
- if (!removedBindings.empty())
- {
- BindingDict removedDict = mRegistrar->createBindingDict(aor, removedBindings);
- SipRegistrarStateItemPtr removedItem(new SipRegistrarStateItem(aor, aor, removedDict, false));
- SipStateItemSeq items;
- items.push_back(removedItem);
- mStateReplicator->removeStateForItems(items);
- }
- }
- catch (const Ice::TwowayOnlyException&)
- {
- lg(Error) << "State replication operations are not oneway";
- }
- catch (const Ice::Exception& ex)
- {
- lg(Error) << "Exception caught attempting to replicate state in registrar\n" << ex.what();
- }
+ mRegistrar->getQueue()->enqueueWork(new ReplicateState(oneWayStateReplicator, aor, existingBindings, newBindings, removedBindings, mRegistrar));
}
//XXX This and the method that queues this work should
@@ -495,10 +518,8 @@ private:
BindingWrapperSeq mRemovedBindings;
};
-//XXX Potential queueable operation
void RegistrarI::updateBindings(const std::string &aor, BindingWrapperSeq& newBindings, BindingWrapperSeq& removedBindings, const QueuePtr& queue)
{
-
queue->enqueueWork(new UpdateBindings(this, aor, newBindings, removedBindings));
}
@@ -661,6 +682,20 @@ BindingWrapperPtr PJSipRegistrarModule::createNewBinding(pjsip_contact_hdr *cont
return wrapper;
}
+class Response : public Work
+{
+public:
+ Response(pjsip_transaction *tsx, pjsip_tx_data *tdata)
+ : mTsx(tsx), mTdata(tdata) { }
+ void execute()
+ {
+ pjsip_tsx_send_msg(mTsx, mTdata);
+ }
+private:
+ pjsip_transaction *mTsx;
+ pjsip_tx_data *mTdata;
+};
+
pj_bool_t PJSipRegistrarModule::on_rx_request(pjsip_rx_data *rdata)
{
if (rdata->msg_info.msg->line.req.method.id != PJSIP_REGISTER_METHOD)
@@ -737,11 +772,13 @@ pj_bool_t PJSipRegistrarModule::on_rx_request(pjsip_rx_data *rdata)
mRegistrar->updateBindings(aor, newBindings, removedBindings, mRegistrar->getQueue());
+ // We enqueue the SIP response to make sure we send it and replicate state AFTER we have updated
+ // our internal bindings.
pjsip_tx_data *tdata;
pjsip_endpt_create_response(tsx->endpt, rdata, 200, NULL, &tdata);
- pjsip_tsx_send_msg(tsx, tdata);
+ mRegistrar->getQueue()->enqueueWork(new Response(tsx, tdata));
- replicateState(aor, newBindings, existingBindings, removedBindings);
+ replicateState(aor, existingBindings, newBindings, removedBindings);
return PJ_TRUE;
}
-----------------------------------------------------------------------
--
asterisk-scf/integration/sip.git
More information about the asterisk-scf-commits
mailing list