[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "party-id" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Tue Oct 11 14:44:57 CDT 2011
branch "party-id" has been updated
via 74e6bddde07e381181f09c6fd9091f223fb0b615 (commit)
from bf350ea67b03b6acaba27ae3f3e4a2f2b88fb6f9 (commit)
Summary of changes:
src/PJSipSessionModule.cpp | 74 ++++++++++++++++++++++++++++++++++++++++---
src/PJSipSessionModule.h | 1 +
src/SipSession.cpp | 6 +++
src/SipSession.h | 2 +
4 files changed, 77 insertions(+), 6 deletions(-)
- Log -----------------------------------------------------------------
commit 74e6bddde07e381181f09c6fd9091f223fb0b615
Author: Mark Michelson <mmichelson at digium.com>
Date: Tue Oct 11 14:44:06 2011 -0500
Set redirections on incoming session based on Diversion headers.
diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 2fe4ec1..d233572 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -407,8 +407,17 @@ public:
pjsip_tx_data *tdata,
pjsip_dialog *replacedDialog,
const std::string destination,
- const CallerPtr& callerID)
- : mSessionModule(module), mCaller(caller), mSessionRouter(router), mInv(inv), mTdata(tdata), mReplacedDialog(replacedDialog), mDestination(destination), mCallerID(callerID) { }
+ const CallerPtr& callerID,
+ const RedirectionsPtr& redirections)
+ : mSessionModule(module),
+ mCaller(caller),
+ mSessionRouter(router),
+ mInv(inv),
+ mTdata(tdata),
+ mReplacedDialog(replacedDialog),
+ mDestination(destination),
+ mCallerID(callerID),
+ mRedirections(redirections) { }
protected:
SuspendableWorkResult initial(const SuspendableWorkListenerPtr&)
@@ -431,6 +440,7 @@ protected:
mSession->setTelephonyEventSourcesAndSinks(mCaller->getConfig());
mSession->setSessionOwnerId(mCallerID);
+ mSession->setRedirections(mRedirections);
// Create an SDP offer or answer
const pjmedia_sdp_session *remote_sdp = NULL;
@@ -532,6 +542,7 @@ private:
const std::string mDestination;
SipSessionPtr mSession;
CallerPtr mCallerID;
+ RedirectionsPtr mRedirections;
};
void PJSipSessionModule::getIds(const char *headerName, pjsip_rx_data *rdata, IdSeq& ids)
@@ -552,10 +563,18 @@ void PJSipSessionModule::getIds(const char *headerName, pjsip_rx_data *rdata, Id
}
else
{
- //This sucks. P-Asserted-Identity and Remote-Party-ID are parsed
- //as generic strings, so we have to take the string we have and
+ //This sucks. P-Asserted-Identity, Remote-Party-ID, and others are
+ //parsed as generic strings, so we have to take the string we have and
//turn it into a name_addr.
pjsip_generic_string_hdr *strHdr = (pjsip_generic_string_hdr *) hdr;
+
+ //pjsip_parse_uri is incredibly clear that the input string must be
+ //null-terminated. The header we have grabbed is NOT null-terminated,
+ //so we need to create a null-terminated copy.
+ //
+ //Furthermore, I can't use a std::string here because std::string::c_str()
+ //returns a const char *, and pjsip_parse_uri takes a non-const char * as
+ //its second parameter.
pj_str_t strCopy;
pj_strdup_with_null(rdata->tp_info.pool, &strCopy, &strHdr->hvalue);
idNameAddr = (pjsip_name_addr*) pjsip_parse_uri(rdata->tp_info.pool, strCopy.ptr, strCopy.slen, PJSIP_PARSE_URI_AS_NAMEADDR);
@@ -586,6 +605,40 @@ CallerPtr PJSipSessionModule::getCallerID(pjsip_rx_data *rdata)
return caller;
}
+RedirectionsPtr PJSipSessionModule::getRedirections(pjsip_rx_data *rdata, pjsip_sip_uri *ruri)
+{
+ RedirectionsPtr redirections(new Redirections);
+ IdSeq ids;
+ getIds("Diversion", rdata, ids);
+
+ NamePtr rURIName(new Name(std::string(pj_strbuf(&ruri->user), pj_strlen(&ruri->user))));
+ NumberPtr rURINumber(new Number(std::string(pj_strbuf(&ruri->user), pj_strlen(&ruri->user))));
+ IdPtr rURIId(new Id(rURIName, rURINumber));
+ for (IdSeq::iterator id = ids.begin(); id != ids.end(); ++id)
+ {
+ //Each ID we've read indicates a redirection *from* something,
+ //so we'll fill in the redirecting from information based on it.
+ //Unfortunately, Diversion doesn't record each of its redirection's
+ //targets, so we will just have to fill in the to information with
+ //the data from the next diversion if it is present or from the
+ //RURI if we've reached the end of the list.
+ IdSeq::iterator nextId = id + 1;
+ IdPtr toId;
+ if (nextId == ids.end())
+ {
+ //End of the list. Use RURI.
+ toId = rURIId;
+ }
+ else
+ {
+ toId = *nextId;
+ }
+ RedirectionPtr redirect(new Redirection(*id, toId));
+ redirections->redirects.push_back(redirect);
+ }
+ return redirections;
+}
+
ConnectedLinePtr PJSipSessionModule::getConnectedID(pjsip_rx_data *rdata)
{
ConnectedLinePtr connected(new ConnectedLine);
@@ -750,20 +803,29 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
//We've created our calling endpoint. Now we need to look up the destination.
pjsip_uri *ruri = rdata->msg_info.msg->line.req.uri;
std::string destination("");
+ pjsip_sip_uri *sipRuri;
if (PJSIP_URI_SCHEME_IS_SIP(ruri) || PJSIP_URI_SCHEME_IS_SIPS(ruri))
{
- pjsip_sip_uri *sipRuri = (pjsip_sip_uri *)pjsip_uri_get_uri(ruri);
+ sipRuri = (pjsip_sip_uri *)pjsip_uri_get_uri(ruri);
//For now, we only know about destination "100" so we'll
//grab that from the URI to pass to the locator.
destination = std::string(pj_strbuf(&sipRuri->user), pj_strlen(&sipRuri->user));
lg(Debug) << "Call is destined for " << destination;
}
+ else
+ {
+ //We don't support non-SIP URIs.
+ pjsip_inv_end_session(inv_session, 500, NULL, &tdata);
+ pjsip_inv_send_msg(inv_session, tdata);
+ return;
+ }
//Now let's see if they've identified themselves somehow...
CallerPtr callerID = getCallerID(rdata);
+ RedirectionsPtr redirections = getRedirections(rdata, sipRuri);
lg(Debug) << "Queueing a SessionCreationOperation";
- sessionWork->enqueueWork(new SessionCreationOperation(this, caller, mSessionRouter, inv_session, tdata, replaced_dlg, destination, callerID));
+ sessionWork->enqueueWork(new SessionCreationOperation(this, caller, mSessionRouter, inv_session, tdata, replaced_dlg, destination, callerID, redirections));
}
void PJSipSessionModule::handleRefer(pjsip_inv_session *inv, pjsip_rx_data *rdata)
diff --git a/src/PJSipSessionModule.h b/src/PJSipSessionModule.h
index c28e055..d34fe6b 100644
--- a/src/PJSipSessionModule.h
+++ b/src/PJSipSessionModule.h
@@ -143,6 +143,7 @@ private:
void getIds(const char *headerName, pjsip_rx_data *rdata, AsteriskSCF::SessionCommunications::PartyIdentification::V1::IdSeq& ids);
AsteriskSCF::SessionCommunications::PartyIdentification::V1::CallerPtr getCallerID(pjsip_rx_data *rdata);
AsteriskSCF::SessionCommunications::PartyIdentification::V1::ConnectedLinePtr getConnectedID(pjsip_rx_data *rdata);
+ AsteriskSCF::SessionCommunications::PartyIdentification::V1::RedirectionsPtr getRedirections(pjsip_rx_data *rdata, pjsip_sip_uri *ruri);
void handleInviteResponse(pjsip_inv_session *inv, pjsip_rx_data *rdata, pjsip_dialog *dlg);
void handleRefer(pjsip_inv_session *inv, pjsip_rx_data *rdata);
void handleInfo(pjsip_inv_session *inv, pjsip_rx_data *rdata);
diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index f3fa314..cec0879 100755
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -942,6 +942,12 @@ void SipSession::setSessionOwnerId(const SessionOwnerIdPtr& owner)
mImplPriv->cookiesUpdated();
}
+void SipSession::setRedirections(const RedirectionsPtr& redirections)
+{
+ mImplPriv->mSessionCookies[redirections->ice_id()] = redirections;
+ mImplPriv->cookiesUpdated();
+}
+
class CheckDirectConnectionsOperation : public SuspendableWork
{
public:
diff --git a/src/SipSession.h b/src/SipSession.h
index 3ac4ba2..8568f7a 100644
--- a/src/SipSession.h
+++ b/src/SipSession.h
@@ -351,6 +351,8 @@ public:
//Must be called from a queued operation
void setSessionOwnerId(const AsteriskSCF::SessionCommunications::PartyIdentification::V1::SessionOwnerIdPtr& owner);
+ void setRedirections(const AsteriskSCF::SessionCommunications::PartyIdentification::V1::RedirectionsPtr& redirections);
+
private:
SipSession(const Ice::ObjectAdapterPtr&, const SipEndpointPtr&, const std::string&,
const std::vector<AsteriskSCF::SessionCommunications::V1::SessionListenerPrx>&,
-----------------------------------------------------------------------
--
asterisk-scf/integration/sip.git
More information about the asterisk-scf-commits
mailing list