[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "modular-transport-refactor" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Jun 28 09:44:10 CDT 2011


branch "modular-transport-refactor" has been updated
       via  d546f6a31b6c8795fcd99264f3b493abac7202c4 (commit)
      from  5963cd0bcb35f29b6b3ea9051480e3115c43f2a2 (commit)

Summary of changes:
 config/test_sip.conf         |    2 +
 src/PJSipManager.cpp         |  100 ++++++++++++++++++++----------------------
 src/PJSipManager.h           |   12 +++--
 src/SipEndpoint.h            |   12 +++++
 src/SipSession.cpp           |    9 +++-
 src/SipSessionManagerApp.cpp |    6 ++-
 6 files changed, 83 insertions(+), 58 deletions(-)


- Log -----------------------------------------------------------------
commit d546f6a31b6c8795fcd99264f3b493abac7202c4
Author: brent <brent at ascf2.(none)>
Date:   Tue Jun 28 10:32:06 2011 -0230

    Fix allocation bug in pjsipmanager (invalid use of this in constructor).
    Add some tracing around sdp.

diff --git a/config/test_sip.conf b/config/test_sip.conf
index b96ee9c..53416f1 100644
--- a/config/test_sip.conf
+++ b/config/test_sip.conf
@@ -39,6 +39,8 @@ Sip.StateReplicatorListener=no
 # Endpoints that we know about
 Sip.Endpoints=cisco 18005558355
 
+Sip.Standalone=true
+
 # This is Josh's phone
 Sip.Endpoint.cisco.Session.CallDirection=Both
 
diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
index db1f9f6..e9dde6b 100644
--- a/src/PJSipManager.cpp
+++ b/src/PJSipManager.cpp
@@ -60,61 +60,14 @@ static void *monitorThread(void *endpt)
     return NULL;
 }
 
-PJSipManager::PJSipManager(const Ice::PropertiesPtr& props) :
-    mEndpoint(0),
-    mSessionModule(0),
-    mLoggingModule(0),
-    mPjThread(0),
-    mMemoryPool(0)
+PJSipManagerPtr AsteriskSCF::SipSessionManager::PJSipManager::create(const Ice::PropertiesPtr& properties)
 {
-    memset(&mCachingPool, 0, sizeof(mCachingPool));
-
-    pj_status_t status = pj_init();
-    if (fail(status))
-    {
-        const char* message = "Failed to Initialize PJSIP";
-        logger(Error) << message;
-        throw InternalInitializationException(message);
-    }
-    // The third parameter is just copied from
-    // example code from PJLIB. This can be adjusted
-    // if necessary.
-    pj_caching_pool_init(&mCachingPool, NULL, 1024 * 1024);
-    pjsip_endpt_create(&mCachingPool.factory, "SIP", &mEndpoint);
-
-    //
-    // Careful! This was after the setTransports call, so reordering it might cause issues.
-    //
-    mMemoryPool = pj_pool_create(&mCachingPool.factory, "SIP", 1024, 1024, NULL);
-    if (!mMemoryPool)
-    {
-        const char* message = "Failed to create a memory pool";
-        logger(Error) << message;
-        throw InternalInitializationException(message);
-    }
-    
-    //
-    // Initialize the global STUN configuration if it is enabled.
-    //
-    if (props)
-    {
-        if (props->getPropertyAsIntWithDefault("Sip.Transport.STUN.Enable", 0) == 1)
-        {
-            mModules["STUN"] = STUNModule::create(shared_from_this(), props, logger);
-        }
-    }
-    initializeDefaultTransports(props);
-
-    status = pj_thread_create(mMemoryPool, "SIP", (pj_thread_proc *) &monitorThread,
-        this, PJ_THREAD_DEFAULT_STACK_SIZE * 2, 0, &mPjThread);
-    if (fail(status))
-    {
-        const char* message = "Failed to create SIP maintenance thread";
-        logger(Error) << message;
-        throw InternalInitializationException(message);
-    }
+    PJSipManagerPtr result(new PJSipManager);
+    result->initializeDefaultTransports(properties);
+    return result;
 }
 
+
 PJSipManager::~PJSipManager()
 {
     for (SipModuleMap::iterator i = mModules.begin(); i != mModules.end(); ++i)
@@ -256,6 +209,49 @@ void PJSipManager::initializeDefaultTransports(const Ice::PropertiesPtr& propert
     mTransports.insert(make_pair(defaultUDPTransport->id(), defaultUDPTransport));
 }
 
+PJSipManager::PJSipManager() :
+    mEndpoint(0),
+    mSessionModule(0),
+    mLoggingModule(0),
+    mPjThread(0),
+    mMemoryPool(0)
+{
+    memset(&mCachingPool, 0, sizeof(mCachingPool));
+
+    pj_status_t status = pj_init();
+    if (fail(status))
+    {
+        const char* message = "Failed to Initialize PJSIP";
+        logger(Error) << message;
+        throw InternalInitializationException(message);
+    }
+    // The third parameter is just copied from
+    // example code from PJLIB. This can be adjusted
+    // if necessary.
+    pj_caching_pool_init(&mCachingPool, NULL, 1024 * 1024);
+    pjsip_endpt_create(&mCachingPool.factory, "SIP", &mEndpoint);
+
+    //
+    // Careful! This was after the setTransports call, so reordering it might cause issues.
+    //
+    mMemoryPool = pj_pool_create(&mCachingPool.factory, "SIP", 1024, 1024, NULL);
+    if (!mMemoryPool)
+    {
+        const char* message = "Failed to create a memory pool";
+        logger(Error) << message;
+        throw InternalInitializationException(message);
+    }
+    
+    status = pj_thread_create(mMemoryPool, "SIP", (pj_thread_proc *) &monitorThread,
+        this, PJ_THREAD_DEFAULT_STACK_SIZE * 2, 0, &mPjThread);
+    if (fail(status))
+    {
+        const char* message = "Failed to create SIP maintenance thread";
+        logger(Error) << message;
+        throw InternalInitializationException(message);
+    }
+}
+
 }; //End namespace SipSessionManager
 
 }; //End namespace AsteriskSCF
diff --git a/src/PJSipManager.h b/src/PJSipManager.h
index 8bd4fb7..9544bb2 100644
--- a/src/PJSipManager.h
+++ b/src/PJSipManager.h
@@ -39,6 +39,9 @@ namespace AsteriskSCF
 namespace SipSessionManager
 {
 
+class PJSipManager;
+typedef boost::shared_ptr<PJSipManager> PJSipManagerPtr;
+
 /*
  * This class is responsible for providing access to the pjsip_endpoint for the Asterisk SCF SIP component.
  *
@@ -47,9 +50,10 @@ namespace SipSessionManager
 class PJSipManager : public boost::enable_shared_from_this<PJSipManager>
 {
 public:
-    PJSipManager(const Ice::PropertiesPtr& props);
 
-    ~PJSipManager();
+    static PJSipManagerPtr create(const Ice::PropertiesPtr& properties);
+
+    virtual ~PJSipManager();
 
     /**
      * Get a handle to the PJSipEndpoint for operations
@@ -117,9 +121,9 @@ private:
     std::map<std::string, TransportPtr> mTransports;
 
     void initializeDefaultTransports(const Ice::PropertiesPtr& properties);
-};
 
-typedef boost::shared_ptr<PJSipManager> PJSipManagerPtr;
+    PJSipManager();
+};
 
 /**
  * Wrapper class around pj_thread_desc.
diff --git a/src/SipEndpoint.h b/src/SipEndpoint.h
index fb13061..9dff7b1 100644
--- a/src/SipEndpoint.h
+++ b/src/SipEndpoint.h
@@ -93,6 +93,11 @@ public:
     // Enable NAT related features for the signalling transport.
     // 
     bool enableNAT;
+
+    SipEndpointTransportConfig() :
+        enableNAT(false)
+    {
+    }
 };
 
 /**
@@ -159,6 +164,13 @@ public:
     // Enables TURN as a viable mechanism for traversing NATs.
     //
     bool rtpICEIncludeTURN;
+
+    SipEndpointSessionConfig() :
+        rtpOverIPv6(false),
+        rtpOverICE(false),
+        rtpICEIncludeTURN(false)
+    {
+    }
 };
 
 /**
diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index 33416a6..43cce96 100644
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -266,7 +266,7 @@ public:
 
 void SipSession::initializePJSIPStructs()
 {
-    SipEndpointConfig config = mImplPriv->mEndpoint->getConfig();
+    SipEndpointConfig& config = mImplPriv->mEndpoint->getConfig();
     
     std::string prefix;
     if (config.transportConfig.secureTransport == OUTBOUND || config.transportConfig.secureTransport == BOTH)
@@ -311,12 +311,19 @@ void SipSession::initializePJSIPStructs()
             }
         }
     }
+    else
+    {
+        cerr << "\nXXX: Not using NAT" << endl;
+    }
 
     char local[64];
     pj_ansi_sprintf(local, "%s:%s", prefix.c_str(), config.sessionConfig.sourceAddress.c_str());
     pj_str_t local_uri = pj_str(local);
     if (!transport)
     {
+        string foo = local_uri.ptr;
+        cerr << "\nXXX: Our URI today will be " << foo << endl;
+        cerr << "\nXXX: source addr " << config.sessionConfig.sourceAddress << endl;
         contact_uri = local_uri;
     }
 
diff --git a/src/SipSessionManagerApp.cpp b/src/SipSessionManagerApp.cpp
index afaef9f..369dcd1 100644
--- a/src/SipSessionManagerApp.cpp
+++ b/src/SipSessionManagerApp.cpp
@@ -510,7 +510,7 @@ void SipSessionManager::initialize(const string& appName, const Ice::Communicato
         mAppName = appName;
 
         // Initialize PJSIP
-        mPJSipManager.reset(new PJSipManager(ic->getProperties()));
+        mPJSipManager = PJSipManager::create(ic->getProperties());
         lg(Debug) << "Created PJSIP manager";
 
         //As nice as it is of IceBox to provide us with a communicator,
@@ -574,6 +574,10 @@ void SipSessionManager::initialize(const string& appName, const Ice::Communicato
         mGlobalAdapter->activate();
         mLocalAdapter->activate();
         lg(Debug) << "Activated object adapters";
+    } 
+    catch (const std::exception& ex)
+    {
+        lg(Critical) << "Major problems in " << mAppName << " initialization(): " << ex.what();
     }
     catch(...)
     {

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


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list