[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "jira-astscf-397-sipuseragent" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Jan 13 15:29:16 CST 2012


branch "jira-astscf-397-sipuseragent" has been created
        at  d1d1ac375f2c94c687bb47307d96a6c5b4fdf8e7 (commit)

- Log -----------------------------------------------------------------
commit d1d1ac375f2c94c687bb47307d96a6c5b4fdf8e7
Author: Brent Eagles <beagles at digium.com>
Date:   Fri Jan 13 17:35:19 2012 -0330

    initial crack at supporting configuration of the "User-Agent" general
    configuration item.

diff --git a/config/SipConfigurator.py b/config/SipConfigurator.py
index 49cc83f..d7aa10b 100755
--- a/config/SipConfigurator.py
+++ b/config/SipConfigurator.py
@@ -37,6 +37,14 @@ class SIPSectionVisitors(Configurator.SectionVisitors):
     def visit_general(self, config, section):
         group = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPGeneralGroup()
         group.configurationItems = { }
+        mapper = Configurator.OptionMapper()
+        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipUserAgentItem()
+        mapper.map('useragent', item, 'userAgent', 'userAgent', config.get, None)
+        for option in config.options(section):
+            mapper.execute(group, section, option)
+
+        mapper.finish(group)
+        
         self.groups.append(group)
 
     def visit_transport_udp(self, config, section):
diff --git a/src/PJSIPManager.cpp b/src/PJSIPManager.cpp
index b8d3f45..d706c29 100644
--- a/src/PJSIPManager.cpp
+++ b/src/PJSIPManager.cpp
@@ -251,6 +251,11 @@ void PJSIPManager::handleEvents()
     pjsip_endpt_handle_events(mEndpoint, &delay);
 }
 
+void PJSIPManager::setUserAgent(const string& userAgent)
+{
+    mSessionModule->setUserAgent(userAgent);
+}
+
 pj_caching_pool* PJSIPManager::getCachingPool()
 {
     return &mCachingPool;
diff --git a/src/PJSIPManager.h b/src/PJSIPManager.h
index f718ae7..ca10ca6 100644
--- a/src/PJSIPManager.h
+++ b/src/PJSIPManager.h
@@ -138,6 +138,15 @@ public:
 
     void handleEvents();
 
+    /**
+     * This would be better defined somewhere else, but at the moment
+     * configuration can't quite reach the PJSIPSessionModule definition
+     * While configuration could pull it in via include, it brings in a
+     * boat-load of extra build-time dependencies. The proper way to do
+     * this is to have a general configuration proxy class.
+     */
+    void setUserAgent(const std::string& userAgent);
+
 private:
     pjsip_endpoint *mEndpoint;
     PJSIPSessionModulePtr mSessionModule;
diff --git a/src/PJSIPSessionModule.cpp b/src/PJSIPSessionModule.cpp
index 79a58a5..8bedeb0 100644
--- a/src/PJSIPSessionModule.cpp
+++ b/src/PJSIPSessionModule.cpp
@@ -823,6 +823,35 @@ ConnectedLinePtr PJSIPSessionModule::getConnectedID(pjsip_rx_data *rdata)
     return connected;
 }
 
+std::string PJSIPSessionModule::getUserAgent()
+{
+    boost::shared_lock<boost::shared_mutex> lock(mUserAgentMutex);
+    return mUserAgent;
+}
+
+void PJSIPSessionModule::setUserAgent(const std::string& userAgent)
+{
+    boost::unique_lock<boost::shared_mutex> lock(mUserAgentMutex);
+    mUserAgent = userAgent;
+}
+
+void PJSIPSessionModule::addDefaultHeaders(pjsip_tx_data *tx)
+{
+    std::string userAgent = getUserAgent();
+    if (userAgent.empty() || !tx)
+    {
+        return;
+    }
+
+    pj_str_t uaHeaderField;
+    pj_cstr(&uaHeaderField, "User-Agent");
+    pj_str_t uaHeaderValue;
+    pj_strset(&uaHeaderValue, (char*)userAgent.c_str(), userAgent.length());
+    pjsip_generic_string_hdr* hdr =
+        pjsip_generic_string_hdr_create(tx->pool, &uaHeaderField, &uaHeaderValue);
+    pjsip_msg_add_hdr(tx->msg, (pjsip_hdr*)hdr);
+}
+
 void PJSIPSessionModule::handleNewInvite(pjsip_rx_data *rdata)
 {
     //We handle most of the processing here synchronously since
@@ -1379,12 +1408,14 @@ pj_bool_t PJSIPSessionModule::on_rx_response(pjsip_rx_data*)
 {
     return PJ_FALSE;
 }
-pj_status_t PJSIPSessionModule::on_tx_request(pjsip_tx_data*)
+pj_status_t PJSIPSessionModule::on_tx_request(pjsip_tx_data* tx)
 {
+    addDefaultHeaders(tx);
     return PJ_SUCCESS;
 }
-pj_status_t PJSIPSessionModule::on_tx_response(pjsip_tx_data*)
+pj_status_t PJSIPSessionModule::on_tx_response(pjsip_tx_data* tx)
 {
+    addDefaultHeaders(tx);
     return PJ_SUCCESS;
 }
 void PJSIPSessionModule::on_tsx_state(pjsip_transaction*, pjsip_event*)
diff --git a/src/PJSIPSessionModule.h b/src/PJSIPSessionModule.h
index 7a6cbec..f9874ed 100644
--- a/src/PJSIPSessionModule.h
+++ b/src/PJSIPSessionModule.h
@@ -142,7 +142,13 @@ public:
 
     AsteriskSCF::SessionCommunications::ExtensionPoints::V1::SessionCreationHookSeq getSessionCreationHooks();
 
+    std::string getUserAgent();
+    void setUserAgent(const std::string& userAgent);
+
 private:
+
+    void addDefaultHeaders(pjsip_tx_data* tx);
+    
     void handleNewInvite(pjsip_rx_data *rdata);
 
     /**
@@ -237,6 +243,13 @@ private:
     AsteriskSCF::SessionCommunications::ExtensionPoints::V1::SessionCreationExtensionPointPrx mSessionCreationExtensionPointPrx;
     Ice::ObjectAdapterPtr mAdapter;
     AsteriskSCF::Core::Discovery::V1::ServiceManagementPrx mSessionCreationExtensionPointService;
+
+    //
+    // This is really the only thing that needs locking, so the mutex
+    // variable is named with that intent.
+    //
+    boost::shared_mutex mUserAgentMutex;
+    std::string mUserAgent;
 };
 
 typedef IceUtil::Handle<PJSIPSessionModule> PJSIPSessionModulePtr;
diff --git a/src/PJSIPSessionModuleConstruction.cpp b/src/PJSIPSessionModuleConstruction.cpp
index 002e09f..4fbfe8d 100644
--- a/src/PJSIPSessionModuleConstruction.cpp
+++ b/src/PJSIPSessionModuleConstruction.cpp
@@ -69,6 +69,16 @@ static pj_bool_t sessionOnRxRequest(pjsip_rx_data *rdata)
     return sessionModule->on_rx_request(rdata);
 }
 
+static pj_bool_t sessionOnTxRequest(pjsip_tx_data *tdata)
+{
+    return sessionModule->on_tx_request(tdata);
+}
+
+static pj_bool_t sessionOnTxResponse(pjsip_tx_data *tdata)
+{
+    return sessionModule->on_tx_response(tdata);
+}
+
 static void invOnStateChanged(pjsip_inv_session *inv, pjsip_event *e)
 {
     sessionModule->invOnStateChanged(inv, e);
@@ -140,8 +150,8 @@ PJSIPSessionModule::PJSIPSessionModule(pjsip_endpoint *endpt,
     mModule.unload = sessionUnload;
     mModule.on_rx_request = sessionOnRxRequest;
     mModule.on_rx_response = NULL;
-    mModule.on_tx_request = NULL;
-    mModule.on_tx_response = NULL;
+    mModule.on_tx_request = sessionOnTxRequest;
+    mModule.on_tx_response = sessionOnTxResponse;
     mModule.on_tsx_state = NULL;
 
     mSessionCreationExtensionPointPrx =
diff --git a/src/SIPConfiguration.cpp b/src/SIPConfiguration.cpp
index badd6b0..9699a63 100644
--- a/src/SIPConfiguration.cpp
+++ b/src/SIPConfiguration.cpp
@@ -291,6 +291,69 @@ private:
 
 }; // class IdentityConfig
 
+class GeneralGroupConfig : public ConfigBase, public boost::enable_shared_from_this<GeneralGroupConfig>
+{
+    class Visitor : public SIPConfigurationItemVisitor
+    {
+    public:
+        Visitor(const boost::shared_ptr<GeneralGroupConfig>& config) :
+            mConfig(config)
+        {
+        }
+
+        ~Visitor()
+        {
+            mConfig->finish();
+        }
+
+        void visitSIPUserAgent(const SIPUserAgentItemPtr& userAgent)
+        {
+            mConfig->setUserAgentField(userAgent);
+        }
+
+    private:
+        boost::shared_ptr<GeneralGroupConfig> mConfig;
+    };
+public:
+    GeneralGroupConfig(const PJSIPManagerPtr& manager, const SIPGeneralGroupPtr& group):
+        mManager(manager),
+        mGroup(group)
+    {
+    }
+
+    void setUserAgentField(const SIPUserAgentItemPtr& userAgent)
+    {
+        boost::unique_lock<boost::shared_mutex> lock(mLock);
+        mUserAgent = userAgent;
+        mGroup->configurationItems["user-agent"] = userAgent;
+    }
+
+    void finish()
+    {
+        boost::shared_lock<boost::shared_mutex> lock(mLock);
+        if (mUserAgent)
+        {
+            mManager->setUserAgent(mUserAgent->userAgent);
+        }
+    }
+
+    SIPGeneralGroupPtr getTypedGroup() const
+    {
+        return mGroup;
+    }
+
+    SIPConfigurationItemVisitorPtr getVisitor()
+    {
+        return new Visitor(shared_from_this());
+    }
+
+private:
+    boost::shared_mutex mLock;
+    SIPUserAgentItemPtr mUserAgent;
+    SIPGeneralGroupPtr mGroup;
+    PJSIPManagerPtr mManager;
+};
+
 /**
  * A helper class and visitor for propogating configuration changes to the SIPEndPoint implementation.
  **/
@@ -1139,7 +1202,7 @@ public:
         return updateGroup(v);
     }
 
-    void remove(const SIPGeneralGroupPtr&)
+    void remove(const SIPGeneralGroupPtr& group)
     {
         boost::unique_lock<boost::shared_mutex> lock(mLock);
         mGroup = 0;
@@ -1454,9 +1517,15 @@ private:
         }
     }
     
-    SIPConfigurationItemVisitorPtr updateGroup(const SIPGeneralGroupPtr&)
+    SIPConfigurationItemVisitorPtr updateGroup(const SIPGeneralGroupPtr& group)
     {
-        return 0;
+        if (!mGroup)
+        {
+            mGroup  = createGroupTemplate(group);
+        }
+       
+        return boost::shared_ptr<GeneralGroupConfig>(
+            new GeneralGroupConfig(mPJSIPManager, mGroup))->getVisitor();
     }
 
     SIPConfigurationItemVisitorPtr updateGroup(const SIPEndpointGroupPtr& group)
diff --git a/src/SIPSession.cpp b/src/SIPSession.cpp
index 00ad31d..cff2dcb 100755
--- a/src/SIPSession.cpp
+++ b/src/SIPSession.cpp
@@ -2045,6 +2045,13 @@ public:
     {
         //lg(Debug) << "Sending new SIP INVITE to " << remote;
 
+        //
+        // XXX Why create a new instance of Session? A default copy is
+        // going to be a shallow copy which just copies the pointer to the
+        // internal state, ie. that data is still going to be shared. I'm
+        // not sure why thiis is necessary. Actually.. it doesn't seem to
+        // be used at all!
+        //
         // Record our session within the dialog so code handling pjsip events can do STUFF
         SIPSessionPtr session = new SIPSession(*mSession);
 

commit d674b4ff321ff8eeb2581246115d820c152c7214
Author: Darren Sessions <dsessions at digium.com>
Date:   Fri Jan 13 13:52:26 2012 -0600

    Updated the SipConfigurator python script to reflect new file paths and naming conventions. Added a quick system path append command for /opt/Ice-3.4/python to make the script work straight from the gitall/sip/config directory. Added a README.txt file with a quick note about needing to set the ASTSCF_HOME env variable which is required within the script to find slice dependancies.

diff --git a/config/README.txt b/config/README.txt
new file mode 100644
index 0000000..2f7d4ac
--- /dev/null
+++ b/config/README.txt
@@ -0,0 +1 @@
+Please set the 'ASTSCF_HOME' environment variable to the Asterisk SCF 'gitall' directory path.
diff --git a/config/SipConfigurator.py b/config/SipConfigurator.py
index c7c9f6f..49cc83f 100755
--- a/config/SipConfigurator.py
+++ b/config/SipConfigurator.py
@@ -16,30 +16,36 @@
 # at the top of the source tree.
 #
 
-# Sip configurator
+# SIP configurator
 
 # Bring in the common configuration infrastructure
-import ConfigParser, Ice, Configurator, sys, os, traceback
+import os, sys
+
+sys.path.append(os.environ["ASTSCF_HOME"] + "/configurator")
+sys.path.append("/opt/Ice-3.4/python")
+
+import ConfigParser, Ice, Configurator, traceback
 
 # Load our component specific configuration definitions
-Ice.loadSlice("--underscore -I\"" + os.environ["ASTSCF_HOME"] + "\"" + " -I" + Ice.getSliceDir() + " --all ../slice/AsteriskSCF/Configuration/SipSessionManager/SipConfigurationIf.ice")
-import AsteriskSCF.Configuration.SipSessionManager.V1
+Ice.loadSlice("--underscore -I\"" + os.environ["ASTSCF_HOME"] + "/slice/slice\"" + " -I" + Ice.getSliceDir() + " --all " + os.environ["ASTSCF_HOME"] + "/sip/slice/AsteriskSCF/Configuration/SIPSessionManager/SIPConfigurationIf.ice")
+
+import AsteriskSCF.Configuration.SIPSessionManager.V1
 
 
 # Add our own visitor implementations for the sections we support
-class SipSectionVisitors(Configurator.SectionVisitors):
+class SIPSectionVisitors(Configurator.SectionVisitors):
     def visit_general(self, config, section):
-        group = AsteriskSCF.Configuration.SipSessionManager.V1.SipGeneralGroup()
+        group = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPGeneralGroup()
         group.configurationItems = { }
         self.groups.append(group)
 
     def visit_transport_udp(self, config, section):
-        group = AsteriskSCF.Configuration.SipSessionManager.V1.SipUDPTransportGroup()
+        group = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPUDPTransportGroup()
         group.name = section
         group.configurationItems = { }
 
         mapper = Configurator.OptionMapper()
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipHostItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPHostItem()
         mapper.map('host', item, 'host', 'address', config.get, None)
         mapper.map('port', item, 'port', 'address', config.getint, 5060)
         for option in config.options(section):
@@ -50,12 +56,12 @@ class SipSectionVisitors(Configurator.SectionVisitors):
         self.groups.append(group)
 
     def visit_transport_tcp(self, config, section):
-        group = AsteriskSCF.Configuration.SipSessionManager.V1.SipTCPTransportGroup()
+        group = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPTCPTransportGroup()
         group.name = section
         group.configurationItems = { }
 
         mapper = Configurator.OptionMapper()
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipHostItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPHostItem()
         mapper.map('host', item, 'host', 'address', config.get, None)
         mapper.map('port', item, 'port', 'address', config.getint, 5060)
         for option in config.options(section):
@@ -66,12 +72,12 @@ class SipSectionVisitors(Configurator.SectionVisitors):
         self.groups.append(group)
 
     def visit_transport_tls(self, config, section):
-        group = AsteriskSCF.Configuration.SipSessionManager.V1.SipTLSTransportGroup()
+        group = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPTLSTransportGroup()
         group.name = section
         group.configurationItems = { }
 
         mapper = Configurator.OptionMapper()
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipHostItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPHostItem()
         mapper.map('host', item, 'host', 'address', config.get, None)
         mapper.map('port', item, 'port', 'address', config.getint, 5060)
         for option in config.options(section):
@@ -82,16 +88,16 @@ class SipSectionVisitors(Configurator.SectionVisitors):
         self.groups.append(group)
 
     def visit_transport_stun(self, config, section):
-        group = AsteriskSCF.Configuration.SipSessionManager.V1.SipSTUNTransportGroup()
+        group = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPSTUNTransportGroup()
         group.name = section
         group.configurationItems = {}
         mapper = Configurator.OptionMapper()
 
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipSignalingSTUNHostItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPSignalingSTUNHostItem()
         mapper.map('stunhost', item, 'address', 'stunServer', config.get, None)
         mapper.map('stunport', item, 'port', 'stunServer', config.getint, 3478)
 
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipHostItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPHostItem()
         mapper.map('baseaddress', item, 'host', 'baseAddress', config.get, None)
         mapper.map('baseport', item, 'port', 'baseAddress', config.getint, 4512)
 
@@ -114,23 +120,23 @@ class SipSectionVisitors(Configurator.SectionVisitors):
 
                 for contact in contacts:
                     uri, slash, expiration = contact.partition('/')
-                    info = AsteriskSCF.Configuration.SipSessionManager.V1.ContactInfo()
+                    info = AsteriskSCF.Configuration.SIPSessionManager.V1.ContactInfo()
                     info.contactURI = uri
                     info.expiration = int(expiration)
                     ret.append(info)
 
                 return ret
 
-        group = AsteriskSCF.Configuration.SipSessionManager.V1.SipRegistrationGroup()
+        group = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPRegistrationGroup()
         group.name = section
         group.configurationItems = {}
 
         mapper = Configurator.OptionMapper()
 
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipClientRegistrationItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPClientRegistrationItem()
 
         mapper.map('aor', item, 'aor', 'registration', config.get, None)
-        mapper.map('expiration', item, 'defaultExpiration', 'registration', config.getint, AsteriskSCF.Configuration.SipSessionManager.V1.DefaultRegistrationExpirationSeconds)
+        mapper.map('expiration', item, 'defaultExpiration', 'registration', config.getint, AsteriskSCF.Configuration.SIPSessionManager.V1.DefaultRegistrationExpirationSeconds)
         handler = RegistrationContactHandler(config)
         mapper.map('contacts', item, 'contacts', 'registration', handler.get, None)
 
@@ -142,13 +148,13 @@ class SipSectionVisitors(Configurator.SectionVisitors):
         self.groups.append(group)
 
     def visit_identity(self, config, section):
-        group = AsteriskSCF.Configuration.SipSessionManager.V1.IdentityGroup()
+        group = AsteriskSCF.Configuration.SIPSessionManager.V1.IdentityGroup()
         group.name = section
         group.configurationItems = { }
 
         mapper = Configurator.OptionMapper()
 
-        item =  AsteriskSCF.Configuration.SipSessionManager.V1.IdentityItem()
+        item =  AsteriskSCF.Configuration.SIPSessionManager.V1.IdentityItem()
 	#      map(option, object, item, item_name, method, default)
         mapper.map('name', item, 'name', 'id', config.get, None)
         mapper.map('number', item, 'number', 'id', config.get, None)
@@ -161,15 +167,15 @@ class SipSectionVisitors(Configurator.SectionVisitors):
         self.groups.append(group)
 
     def visit_endpoint(self, config, section):
-        group = AsteriskSCF.Configuration.SipSessionManager.V1.SipEndpointGroup()
+        group = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPEndpointGroup()
         group.name = section
         group.configurationItems = { }
 
         mapper = Configurator.OptionMapper()
 
-        mapper.map('routing', AsteriskSCF.Configuration.SipSessionManager.V1.SipRoutingItem(), 'routingServiceName', 'routingService', config.get, None)
+        mapper.map('routing', AsteriskSCF.Configuration.SIPSessionManager.V1.SIPRoutingItem(), 'routingServiceName', 'routingService', config.get, None)
 
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.IdentityItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.IdentityItem()
         mapper.map('name', item, 'name', 'identity', config.get, None)
         mapper.map('number', item, 'number', 'identity', config.get, None)
 
@@ -178,29 +184,29 @@ class SipSectionVisitors(Configurator.SectionVisitors):
             ids = config.get(section, 'ids')
             idList = ids.split(',')
             for id in idList:
-                item = AsteriskSCF.Configuration.SipSessionManager.V1.IdentityGroupRef()
+                item = AsteriskSCF.Configuration.SIPSessionManager.V1.IdentityGroupRef()
                 item.identityGroupName = id
                 group.configurationItems[id] = item
 	except ConfigParser.NoOptionError:
 	    # It's legit to omit the ids option from this section.
 	    pass
 
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipSourceTransportAddressItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPSourceTransportAddressItem()
         mapper.map('sourcehost', item, 'host', 'sourceaddress', config.get, None)
         mapper.map('sourceport', item, 'port', 'sourceaddress', config.getint, 5060)
 
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipTargetDestinationAddressItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPTargetDestinationAddressItem()
         mapper.map('targethost', item, 'host', 'targetaddress', config.get, None)
         mapper.map('targetport', item, 'port', 'targetaddress', config.getint, 5060)
 
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipSignalingNATItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPSignalingNATItem()
         mapper.map('enablestun', item, 'stun', 'enableSTUN', config.get, None)
 
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipMediaNATItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPMediaNATItem()
         mapper.map('enablertpoverice', item, 'enableICE', 'enableRTPICE', config.get, None)
         mapper.map('enableturn', item, 'enableTURN', 'enableRTPICE', config.get, None)
 
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SRTPCryptoItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SRTPCryptoItem()
                
         class CryptoKeyHandler:
                 def __init__(self, config, keyItem):
@@ -213,7 +219,7 @@ class SipSectionVisitors(Configurator.SectionVisitors):
                 def getKey(self, section, item):
                     self.item.cryptoKey = self.config.get(section, item)
                     
-        item.cryptoKeys = [ AsteriskSCF.Configuration.SipSessionManager.V1.SRTPCryptoKey() ]
+        item.cryptoKeys = [ AsteriskSCF.Configuration.SIPSessionManager.V1.SRTPCryptoKey() ]
         mapper.map('enableauth', item, 'enableAuthentication', 'srtpCryptoSettings', config.get, None)
         mapper.map('enableencryption', item, 'enableEncryption', 'srtpCryptoSettings', config.get, None)
         handler = CryptoKeyHandler(config, item.cryptoKeys[0])
@@ -225,43 +231,43 @@ class SipSectionVisitors(Configurator.SectionVisitors):
                 self.config = config
             def get(self, section, item):
                 if self.config.get(section, item) == 'inbound':
-                    return AsteriskSCF.Configuration.SipSessionManager.V1.SipAllowableCallDirection.Inbound
+                    return AsteriskSCF.Configuration.SIPSessionManager.V1.SIPAllowableCallDirection.Inbound
                 elif self.config.get(section, item) == 'outbound':
-                    return AsteriskSCF.Configuration.SipSessionManager.V1.SipAllowableCallDirection.Outbound
+                    return AsteriskSCF.Configuration.SIPSessionManager.V1.SIPAllowableCallDirection.Outbound
                 elif self.config.get(section, item) == 'both':
-                    return AsteriskSCF.Configuration.SipSessionManager.V1.SipAllowableCallDirection.Both
+                    return AsteriskSCF.Configuration.SIPSessionManager.V1.SIPAllowableCallDirection.Both
                 elif self.config.get(section, item) == 'none':
-                    return AsteriskSCF.Configuration.SipSessionManager.V1.SipAllowableCallDirection.Disabled
+                    return AsteriskSCF.Configuration.SIPSessionManager.V1.SIPAllowableCallDirection.Disabled
 
         transformer = AllowableCallDirectionTransformer(config)
 
-        mapper.map('direction', AsteriskSCF.Configuration.SipSessionManager.V1.SipAllowableCallDirectionItem(), 'callDirection', 'callDirection', transformer.get, None)
+        mapper.map('direction', AsteriskSCF.Configuration.SIPSessionManager.V1.SIPAllowableCallDirectionItem(), 'callDirection', 'callDirection', transformer.get, None)
 
-        mapper.map('securetransport', AsteriskSCF.Configuration.SipSessionManager.V1.SipEndpointTransportItem(), 'secureTransport', 'transport', transformer.get, None)
+        mapper.map('securetransport', AsteriskSCF.Configuration.SIPSessionManager.V1.SIPEndpointTransportItem(), 'secureTransport', 'transport', transformer.get, None)
 
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipRTPMediaServiceItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPRTPMediaServiceItem()
         mapper.map('rtpoveripv6', item, 'requireIPv6', 'mediaservice', config.getboolean, None)
 
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.DirectMediaItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.DirectMediaItem()
         mapper.map('directmedia', item, 'enabled', 'directmedia', config.getboolean, None)
 
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipUDPTLMediaServiceItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPUDPTLMediaServiceItem()
         mapper.map('udptloveripv6', item, 'requireIPv6', 'udptlmediaservice', config.getboolean, None)
         mapper.map('udptloverice', item, 'enableICE', 'udptlmediaservice', config.getboolean, None)
         mapper.map('udptlwithturn', item, 'enableTURN', 'udptlmediaservice', config.getboolean, None)
 
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipCryptoCertificateItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPCryptoCertificateItem()
         mapper.map('certificateauthorityfile', item, 'certificateAuthority', 'cryptocert', config.get, None)
         mapper.map('certificatefile', item, 'certificate', 'cryptocert', config.get, None)
         mapper.map('privatekeyfile', item, 'privateKey', 'cryptocert', config.get, None)
         mapper.map('privatekeypassword', item, 'privateKeyPassword', 'cryptocert', config.get, None)
 
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipCryptoRequirementsItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPCryptoRequirementsItem()
         mapper.map('requireverifiedserver', item, 'requireVerifiedServer', 'cryptorequirements', config.getboolean, None)
         mapper.map('requireverifiedclient', item, 'requireVerifiedClient', 'cryptorequirements', config.getboolean, None)
         mapper.map('requireclientcertificate', item, 'requireClientCertificate', 'cryptorequirements', config.getboolean, None)
 
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipCryptoItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPCryptoItem()
         mapper.map('supportedciphers', item, 'supportedCiphers', 'crypto', config.get, None)
         mapper.map('tlsservername', item, 'serverName', 'crypto', config.get, None)
         mapper.map('tlstimeout', item, 'timeout', 'crypto', config.getint, None)
@@ -271,15 +277,15 @@ class SipSectionVisitors(Configurator.SectionVisitors):
                 self.config = config
             def get(self, section, item):
                 if self.config.get(section, item) == 'unspecified':
-                    return AsteriskSCF.Configuration.SipSessionManager.V1.TLSProtocolMethod.PROTOCOLMETHODUNSPECIFIED
+                    return AsteriskSCF.Configuration.SIPSessionManager.V1.TLSProtocolMethod.PROTOCOLMETHODUNSPECIFIED
                 elif self.config.get(section, item) == 'tlsv1':
-                    return AsteriskSCF.Configuration.SipSessionManager.V1.TLSProtocolMethod.PROTOCOLMETHODTLSV1
+                    return AsteriskSCF.Configuration.SIPSessionManager.V1.TLSProtocolMethod.PROTOCOLMETHODTLSV1
                 elif self.config.get(section, item) == 'sslv2':
-                    return AsteriskSCF.Configuration.SipSessionManager.V1.TLSProtocolMethod.PROTOCOLMETHODTSSLV2
+                    return AsteriskSCF.Configuration.SIPSessionManager.V1.TLSProtocolMethod.PROTOCOLMETHODTSSLV2
                 elif self.config.get(section, item) == 'sslv3':
-                    return AsteriskSCF.Configuration.SipSessionManager.V1.TLSProtocolMethod.PROTOCOLMETHODSSLV3
+                    return AsteriskSCF.Configuration.SIPSessionManager.V1.TLSProtocolMethod.PROTOCOLMETHODSSLV3
                 elif self.config.get(section, item) == 'sslv23':
-                    return AsteriskSCF.Configuration.SipSessionManager.V1.TLSProtocolMethod.PROTOCOLMETHODSSLV23
+                    return AsteriskSCF.Configuration.SIPSessionManager.V1.TLSProtocolMethod.PROTOCOLMETHODSSLV23
 
         transformer = TLSProtocolMethodTransformer(config)
         mapper.map('tlsprotocolmethod', item, 'protocolMethod', 'crypto', transformer.get, None)
@@ -289,15 +295,15 @@ class SipSectionVisitors(Configurator.SectionVisitors):
                 self.config = config
             def get(self, section, item):
                 if self.config.get(section, item) == 'info':
-                    return AsteriskSCF.Configuration.SipSessionManager.V1.SipDTMFOption.INFO
+                    return AsteriskSCF.Configuration.SIPSessionManager.V1.SIPDTMFOption.INFO
                 if self.config.get(section, item) == 'rfc4733' or self.config.get(section.item) == 'rfc2833':
-                    return AsteriskSCF.Configuration.SipSessionManager.V1.SipDTMFOption.RFC4733
+                    return AsteriskSCF.Configuration.SIPSessionManager.V1.SIPDTMFOption.RFC4733
                 if self.config.get(section, item) == 'inband':
-                    return AsteriskSCF.Configuration.SipSessionManager.V1.SipDTMFOption.Inband
+                    return AsteriskSCF.Configuration.SIPSessionManager.V1.SIPDTMFOption.Inband
 
-        item = AsteriskSCF.Configuration.SipSessionManager.V1.SipDTMFItem()
+        item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPDTMFItem()
         dtmfTransformer = DTMFMethodTransformer(config)
-        mapper.map('dtmfmethod', item, 'dtmf', 'dtmfmethod', dtmfTransformer.get, AsteriskSCF.Configuration.SipSessionManager.V1.SipDTMFOption.RFC4733)
+        mapper.map('dtmfmethod', item, 'dtmf', 'dtmfmethod', dtmfTransformer.get, AsteriskSCF.Configuration.SIPSessionManager.V1.SIPDTMFOption.RFC4733)
 
         for option in config.options(section):
             mapper.execute(group, section, option)
@@ -307,7 +313,7 @@ class SipSectionVisitors(Configurator.SectionVisitors):
             formats = config.get(section, 'formats')
             configuredFormats = formats.split(',')
             for format in configuredFormats:
-                item = AsteriskSCF.Configuration.SipSessionManager.V1.SipMediaFormatItem()
+                item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPMediaFormatItem()
 
                 front, found, rest = format.partition('/')
                 if found:
@@ -351,7 +357,7 @@ class SipSectionVisitors(Configurator.SectionVisitors):
             registrations = config.get(section, 'registrations')
             registrationList = registrations.split(',')
             for reg in registrationList:
-                item = AsteriskSCF.Configuration.SipSessionManager.V1.SipRegistrationGroupRef()
+                item = AsteriskSCF.Configuration.SIPSessionManager.V1.SIPRegistrationGroupRef()
                 item.registrationGroupName = reg
                 group.configurationItems[reg] = item
         except:
@@ -375,9 +381,9 @@ class SipSectionVisitors(Configurator.SectionVisitors):
 
 # In order to do service locator based lookup we need to pass in a params object
 serviceLocatorParams = AsteriskSCF.Core.Discovery.V1.ServiceLocatorParams()
-serviceLocatorParams.category = AsteriskSCF.Configuration.SipSessionManager.V1.ConfigurationDiscoveryCategory
+serviceLocatorParams.category = AsteriskSCF.Configuration.SIPSessionManager.V1.ConfigurationDiscoveryCategory
 serviceLocatorParams.service = 'default' 
 
 # Make a configurator application and let it run
-app = Configurator.ConfiguratorApp('Sip.config', SipSectionVisitors(), None, serviceLocatorParams)
+app = Configurator.ConfiguratorApp('SIP.config', SIPSectionVisitors(), None, serviceLocatorParams)
 sys.exit(app.main(sys.argv))

commit 71d0f466053836c6ffec7a257f4560213a97637a
Author: Mark Michelson <mmichelson at digium.com>
Date:   Thu Jan 12 10:26:28 2012 -0600

    Don't overstep our authority in the PJSIPSessionModule.
    
    The PJSIPSessionModule and the PJSIPRegistrarModule share priority, so
    it's random which could be called into first by PJSIP. In a test case, a REGISTER
    was responded to with a 405 because the PJSIPSessionModule was called into first.
    It didn't know about REGISTER, so it responded with a 405.
    
    Modules should only handle methods they know about. If it's a method that they do
    not know about, then they should let PJSIP move on to a new one.
    
    It may be wise to create an incredibly low-priority module to catch anything that
    higher-priority modules do not catch so that a 405 can be sent in those cases. It
    should not be done by any application-priority modules though.

diff --git a/src/PJSIPSessionModule.cpp b/src/PJSIPSessionModule.cpp
index 7a9476e..79a58a5 100644
--- a/src/PJSIPSessionModule.cpp
+++ b/src/PJSIPSessionModule.cpp
@@ -1326,10 +1326,12 @@ void PJSIPSessionModule::handleInfo(pjsip_inv_session *inv, pjsip_rx_data *rdata
 pj_bool_t PJSIPSessionModule::on_rx_request(pjsip_rx_data *rdata)
 {
     pjsip_dialog *dlg = pjsip_rdata_get_dlg(rdata);
+	pj_bool_t ret;
     switch (rdata->msg_info.msg->line.req.method.id)
     {
     case PJSIP_ACK_METHOD:
-        return PJ_FALSE;
+		ret = PJ_FALSE;
+		break;
     case PJSIP_INVITE_METHOD:
         if (dlg == NULL)
         {
@@ -1339,6 +1341,7 @@ pj_bool_t PJSIPSessionModule::on_rx_request(pjsip_rx_data *rdata)
         {
             lg(Warning) << "on_rx_request called back in mid-dialog?";
         }
+		ret = PJ_TRUE;
         break;
     case PJSIP_OTHER_METHOD:
         pj_str_t info;
@@ -1347,20 +1350,23 @@ pj_bool_t PJSIPSessionModule::on_rx_request(pjsip_rx_data *rdata)
         {
             // We are essentially stopping the pjsip code from sending a 500 here, but this will actually be handled
             // within the transaction code
+			ret = PJ_TRUE;
             break;
         }
         //PJSIP has no knowledge of the INFO method, so we do a straight string comparison dot dot dot
         else if (dlg && !pj_strcmp(&rdata->msg_info.msg->line.req.method.name, &info))
         {
             // Like with REFER, we actually handle this in the transaction code.
+			ret = PJ_TRUE;
             break;
-        }
+		}
     default:
-        pjsip_endpt_respond_stateless(mEndpoint, rdata, 405, NULL, NULL, NULL);
-        break;
+		// This method may be handled by a different PJSIP module we've registered. We can't handle it.
+		ret = PJ_FALSE;
+		break;
     }
 
-    return PJ_TRUE;
+    return ret;
 }
 
 /* The following four member functions are all stubbed out because they

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list