[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
Mon Oct 10 18:18:25 CDT 2011


branch "party-id" has been updated
       via  bf350ea67b03b6acaba27ae3f3e4a2f2b88fb6f9 (commit)
       via  62c5c1710036c4212f605088b7ae150fda0be6fc (commit)
      from  3fff8394ae39b9151fc277e18e8249fca07b6882 (commit)

Summary of changes:
 src/PJSipSessionModule.cpp |   26 ++++++++++++++++++++---
 src/SipSession.cpp         |   47 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 66 insertions(+), 7 deletions(-)


- Log -----------------------------------------------------------------
commit bf350ea67b03b6acaba27ae3f3e4a2f2b88fb6f9
Author: Mark Michelson <mmichelson at digium.com>
Date:   Mon Oct 10 18:15:32 2011 -0500

    Adjust algorithm for getting IDs out of a SIP message.
    
    This prevents some crashes that I saw since we were doing
    some invalid casts.
    
    I like how I say "we" like it's more than one person making
    the mistake. It's really just me. I screwed it up. Maybe I'm
    using the royal we like some pompous monarch. No, I'd never do
    something so douchey.

diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index 9f2e038..2fe4ec1 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -539,10 +539,27 @@ void PJSipSessionModule::getIds(const char *headerName, pjsip_rx_data *rdata, Id
     pj_str_t hdrName;
     pj_cstr(&hdrName, headerName);
 
-    pjsip_fromto_hdr *hdr = (pjsip_fromto_hdr *) &rdata->msg_info.msg->hdr;
-    while ((hdr = (pjsip_fromto_hdr *) pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &hdrName, hdr->next)))
-    {
-        pjsip_name_addr *idNameAddr = (pjsip_name_addr*) hdr->uri;
+    pjsip_hdr *hdr = &rdata->msg_info.msg->hdr;
+    while ((hdr = (pjsip_hdr *) pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &hdrName, hdr->next)))
+    { 
+        pjsip_name_addr *idNameAddr;
+        if (pj_strcmp2(&hdr->name, "From") == 0)
+        {
+            //This is the easy case. The From header is parsed in a way
+            //that makes it super easy to grab a URI.
+            pjsip_fromto_hdr *fromHdr = (pjsip_fromto_hdr *) hdr;
+            idNameAddr = (pjsip_name_addr*) fromHdr->uri;
+        }
+        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
+            //turn it into a name_addr.
+            pjsip_generic_string_hdr *strHdr = (pjsip_generic_string_hdr *) hdr;
+            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);
+        }
 
         NamePtr name(new Name(std::string(pj_strbuf(&idNameAddr->display), pj_strlen(&idNameAddr->display))));
 

commit 62c5c1710036c4212f605088b7ae150fda0be6fc
Author: Mark Michelson <mmichelson at digium.com>
Date:   Mon Oct 10 11:57:41 2011 -0500

    * Add diversion header for outgoing calls.
    * Actually put a source address in P-Asserted-Identity and Diversion headers.
    * Call updateConnectedLine() where we should.

diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index cb70181..9f2e038 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -1212,6 +1212,7 @@ protected:
             }
         }
         mSession->setSessionOwnerId(mConnected);
+        mSession->getSessionControllerProxy()->updateConnectedLine(mConnected);
         return Complete;
     }
 
diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index 2c2b9e5..f3fa314 100755
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -1549,7 +1549,7 @@ private:
             return;
         }
 
-        CallerPtr caller = CallerPtr::dynamicCast(iter->second);
+        ConnectedLinePtr caller = ConnectedLinePtr::dynamicCast(iter->second);
         for (IdSeq::iterator id = caller->ids.begin(); id != caller->ids.end(); ++id)
         {
             std::string connectedName = (*id)->partyName->partyName;
@@ -1563,7 +1563,9 @@ private:
             }
             pj_str_t paiValue;
             std::stringstream ss;
-            ss << "\"" << connectedName << "\" <" << connectedNumber << "@" << /*XXX WTF goes here? */ "..." << ">;party=called";
+
+            SipEndpointConfig &config = mSession->getEndpoint()->getConfig();
+            ss << "\"" << connectedName << "\" <" << connectedNumber << "@" << config.sessionConfig.sourceAddress << ">;party=called";
             pj_cstr(&paiValue, ss.str().c_str());
 
             pjsip_generic_string_hdr *hdr =
@@ -2014,6 +2016,8 @@ public:
 
         addCaller(packet);
 
+        addDiversion(packet);
+
         // Boom! Houston, we have transmission.
         pjsip_inv_send_msg(mImplPriv->mInviteSession, packet);
         return Complete;
@@ -2081,7 +2085,8 @@ private:
             }
             pj_str_t paiValue;
             std::stringstream ss;
-            ss << "\"" << callerName << "\" <" << callerNumber << "@" << /*XXX WTF goes here? */ "..." << ">;party=calling";
+            SipEndpointConfig &config = mSession->getEndpoint()->getConfig();
+            ss << "\"" << callerName << "\" <" << callerNumber << "@" << config.sessionConfig.sourceAddress << ">;party=calling";
             pj_cstr(&paiValue, ss.str().c_str());
 
             pjsip_generic_string_hdr *hdr =
@@ -2090,6 +2095,42 @@ private:
             pjsip_msg_add_hdr(packet->msg, (pjsip_hdr*) hdr);
         }
     }
+
+    void addDiversion(pjsip_tx_data *packet)
+    {
+        AsteriskSCF::SessionCommunications::V1::SessionCookieDict::const_iterator iter =
+            mImplPriv->mSessionCookies.find(Redirections::ice_staticId());
+
+        if (iter == mImplPriv->mSessionCookies.end())
+        {
+            lg(Debug) << "No Redirection cookie present";
+            return;
+        }
+
+        RedirectionsPtr redirections = RedirectionsPtr::dynamicCast(iter->second);
+        for (RedirectionSeq::iterator redirects = redirections->redirects.begin(); redirects != redirections->redirects.end(); ++redirects)
+        {
+            std::string fromName = (*redirects)->fromId->partyName->partyName;
+            std::string fromNumber = (*redirects)->fromId->partyNumber->partyNumber;
+
+            pj_str_t diversionHeader;
+            pj_cstr(&diversionHeader, "Diversion");
+            if (fromName.empty())
+            {
+                fromName = fromNumber;
+            }
+            pj_str_t diversionValue;
+            std::stringstream ss;
+            SipEndpointConfig &config = mSession->getEndpoint()->getConfig();
+            ss << "\"" << fromName << "\" <" << fromNumber << "@" << config.sessionConfig.sourceAddress << ">;reason=unconditional;counter=1";
+            pj_cstr(&diversionValue, ss.str().c_str());
+
+            pjsip_generic_string_hdr *hdr =
+                pjsip_generic_string_hdr_create(packet->pool, &diversionHeader, &diversionValue);
+
+            pjsip_msg_add_hdr(packet->msg, (pjsip_hdr*) hdr);
+        }
+    }
     SipSessionPtr mSession;
     boost::shared_ptr<SipSessionPriv> mImplPriv;
 };

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list