Пример #1
0
///////////////////////////PUBLIC///////////////////////////////////
UtlBoolean
SubscribeServerThread::initialize (
    SipUserAgent* sipUserAgent,
    int defaultSubscribePeriod,
    const UtlString& minExpiresTime,
    const UtlString& defaultDomain,
    const UtlBoolean& useCredentialDB,
    const UtlString& realm,
    PluginXmlParser* pluginTable)
{
    if ( !mIsStarted )
    {
        //start the thread
        start();
    }

    if ( !minExpiresTime.isNull() )
    {
        mMinExpiresTimeStr.append(minExpiresTime);
        mMinExpiresTimeint = atoi(minExpiresTime.data());
    }

    mDefaultSubscribePeriod = defaultSubscribePeriod;
    if ( mMinExpiresTimeint > mDefaultSubscribePeriod )
    {
       OsSysLog::add(FAC_SIP, PRI_ERR,
                     "SubscribeServerThread::initialize - minimum expiration time (%d)"
                     " > default/maximum expiration time (%d); reset to equal",
                     mMinExpiresTimeint,
                     mDefaultSubscribePeriod
          );
       mMinExpiresTimeint = mDefaultSubscribePeriod;
    }

    if ( !defaultDomain.isNull() )
    {
        mDefaultDomain.remove(0);
        mDefaultDomain.append( defaultDomain );
        Url defaultDomainUrl( mDefaultDomain );
        mDefaultDomainPort = defaultDomainUrl.getHostPort();

        // the isValidDomain compares the server's domain to
        // that in the incoming URI, sometimes the incoming
        // URI is a dotted IP address.
        UtlString ipOrFQDNHost;

        defaultDomainUrl.getHostAddress(ipOrFQDNHost);

        // sometimes the request URI will contain
        // an IP Address and at others it contains a FQDN
        if ( OsSocket::isIp4Address( ipOrFQDNHost.data() ) )
        {
            mDefaultDomainHostIP = ipOrFQDNHost;
            OsSocket::getDomainName( mDefaultDomainHostFQDN );
        } else
        {
            mDefaultDomainHostFQDN = ipOrFQDNHost;
            OsSocket::getHostIp( &mDefaultDomainHostIP );
        }
    }

    if ( !realm.isNull() )
    {
        mRealm.remove(0);
        mRealm.append(realm);
    }

    mIsCredentialDB = useCredentialDB;

    //get sip user agent
    if ( sipUserAgent )
    {
        mpSipUserAgent = sipUserAgent;
    } else
    {
        mpSipUserAgent = NULL;
        return FALSE;
    }

    //get Plugin table
    if ( pluginTable )
    {
        mPluginTable = pluginTable;
    } else
    {
        return FALSE;
    }
    return TRUE;
}
Пример #2
0
// Constructor
SipRegistrar::SipRegistrar(OsConfigDb* configDb) :
   OsServerTask("SipRegistrar", NULL, SIPUA_DEFAULT_SERVER_OSMSG_QUEUE_SIZE),
   mConfigDb(configDb),
   mSipUserAgent(NULL),
   mRedirectServer(NULL),
   mRedirectMsgQ(NULL),
   // Create the SipRegistrarServer object so it will be available immediately,
   // but don't start the associated thread until the registrar is operational.
   mRegistrarServer(new SipRegistrarServer(*this)),
   mRegistrarMsgQ(NULL),
   mRegisterEventServer(NULL),
   mRegistrarPersist(NULL),
   mpRegDb(NULL),
   mpSubscribeDb(NULL),
   mpEntityDb(NULL)
{
   Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "SipRegistrar::SipRegistrar constructed.");


   // Some phones insist (incorrectly) on putting the proxy port number on urls;
   // we get it from the configuration so that we can ignore it.
   mProxyNormalPort = mConfigDb->getPort("SIP_REGISTRAR_PROXY_PORT");
   if (mProxyNormalPort == PORT_DEFAULT)
   {
      mProxyNormalPort = SIP_PORT;
   }

   // Domain Name
   mConfigDb->get("SIP_REGISTRAR_DOMAIN_NAME", mDefaultDomain);
   if ( mDefaultDomain.isNull() )
   {
      OsSocket::getHostIp(&mDefaultDomain);
      Os::Logger::instance().log(FAC_SIP, PRI_CRIT,
                    "SIP_REGISTRAR_DOMAIN_NAME not configured using IP '%s'",
                    mDefaultDomain.data()
                    );
   }
   // get the url parts for the domain
   Url defaultDomainUrl(mDefaultDomain);
   mDefaultDomainPort = defaultDomainUrl.getHostPort();
   defaultDomainUrl.getHostAddress(mDefaultDomainHost);
   // make sure that the unspecified domain name is also valid
   addValidDomain(mDefaultDomainHost, mDefaultDomainPort);

   // read the domain configuration
   OsConfigDb domainConfig;
   domainConfig.loadFromFile(SipXecsService::domainConfigPath());


   // Domain Aliases
   //   (other domain names that this registrar accepts as valid in the request URI)
   UtlString domainAliases;
   domainConfig.get(SipXecsService::DomainDbKey::SIP_DOMAIN_ALIASES, domainAliases);

   if (!domainAliases.isNull())
   {
      Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "SipRegistrar::SipRegistrar "
                    "SIP_DOMAIN_ALIASES : %s", domainAliases.data());
   }
   else
   {
      Os::Logger::instance().log(FAC_SIP, PRI_ERR, "SipRegistrar::SipRegistrar "
                    "SIP_DOMAIN_ALIASES not found.");
   }

   UtlString aliasString;
   int aliasIndex = 0;
   while(NameValueTokenizer::getSubField(domainAliases.data(), aliasIndex,
                                         ", \t", &aliasString))
   {
      Url aliasUrl(aliasString);
      UtlString hostAlias;
      aliasUrl.getHostAddress(hostAlias);
      int port = aliasUrl.getHostPort();

      addValidDomain(hostAlias,port);
      aliasIndex++;
   }

   mongo::ConnectionString mongoConn = MongoDB::ConnectionInfo::connectionStringFromFile();
   mpRegDb = new RegDB(MongoDB::ConnectionInfo(mongoConn, RegDB::NS));
   mpSubscribeDb = new SubscribeDB(MongoDB::ConnectionInfo(mongoConn, SubscribeDB::NS));
   mpEntityDb = new EntityDB(MongoDB::ConnectionInfo(mongoConn, EntityDB::NS));

   mConfigDb->get("SIP_REGISTRAR_BIND_IP", mBindIp);
   if ((mBindIp.isNull()) || !OsSocket::isIp4Address(mBindIp))
   {
	  mBindIp = "0.0.0.0";
   }
}
Пример #3
0
// Constructor
SipRegistrar::SipRegistrar(OsConfigDb* configDb) :
   OsServerTask("SipRegistrar", NULL, SIPUA_DEFAULT_SERVER_OSMSG_QUEUE_SIZE),
   mConfigDb(configDb),
   mRegistrationDB(RegistrationDB::getInstance()), // implicitly loads database
   mHttpServer(NULL),
   mXmlRpcDispatch(NULL),
   mReplicationConfigured(false),
   mSipUserAgent(NULL),
   mRedirectServer(NULL),
   mRedirectMsgQ(NULL),
   // Create the SipRegistrarServer object so it will be available immediately,
   // but don't start the associated thread until the registrar is operational.
   mRegistrarServer(new SipRegistrarServer(*this)),
   mRegistrarMsgQ(NULL),
   mRegistrarInitialSync(NULL),
   mRegistrarSync(NULL),
   mRegisterEventServer(NULL),
   mRegistrarTest(NULL),
   mRegistrarPersist(NULL)
{
   OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipRegistrar::SipRegistrar constructed.");

   mHttpPort = mConfigDb->getPort("SIP_REGISTRAR_XMLRPC_PORT");
   if (PORT_NONE == mHttpPort)
   {
      OsSysLog::add(FAC_SIP, PRI_NOTICE,
                    "SipRegistrar::SipRegistrar"
                    " SIP_REGISTRAR_XMLRPC_PORT == PORT_NONE :"
                    " peer synchronization disabled"
                    );
   }
   else // HTTP/RPC port is configured
   {
      if (PORT_DEFAULT == mHttpPort)
      {
         mHttpPort = SIP_REGISTRAR_DEFAULT_XMLRPC_PORT;
      }

      configurePeers();
   }

   // Some phones insist (incorrectly) on putting the proxy port number on urls;
   // we get it from the configuration so that we can ignore it.
   mProxyNormalPort = mConfigDb->getPort("SIP_REGISTRAR_PROXY_PORT");
   if (mProxyNormalPort == PORT_DEFAULT)
   {
      mProxyNormalPort = SIP_PORT;
   }
    
   // Domain Name
   mConfigDb->get("SIP_REGISTRAR_DOMAIN_NAME", mDefaultDomain);
   if ( mDefaultDomain.isNull() )
   {
      OsSocket::getHostIp(&mDefaultDomain);
      OsSysLog::add(FAC_SIP, PRI_CRIT,
                    "SIP_REGISTRAR_DOMAIN_NAME not configured using IP '%s'",
                    mDefaultDomain.data()
                    );
   }
   // get the url parts for the domain
   Url defaultDomainUrl(mDefaultDomain);
   mDefaultDomainPort = defaultDomainUrl.getHostPort();
   defaultDomainUrl.getHostAddress(mDefaultDomainHost);
   // make sure that the unspecified domain name is also valid
   addValidDomain(mDefaultDomainHost, mDefaultDomainPort);

   // read the domain configuration
   OsConfigDb domainConfig;
   domainConfig.loadFromFile(SipXecsService::domainConfigPath());


   // Domain Aliases
   //   (other domain names that this registrar accepts as valid in the request URI)
   UtlString domainAliases;
   domainConfig.get(SipXecsService::DomainDbKey::SIP_DOMAIN_ALIASES, domainAliases);

   if (!domainAliases.isNull())
   {
      OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipRegistrar::SipRegistrar "
                    "SIP_DOMAIN_ALIASES : %s", domainAliases.data());
   }
   else
   {
      OsSysLog::add(FAC_SIP, PRI_ERR, "SipRegistrar::SipRegistrar "
                    "SIP_DOMAIN_ALIASES not found.");
   }

   UtlString aliasString;
   int aliasIndex = 0;
   while(NameValueTokenizer::getSubField(domainAliases.data(), aliasIndex,
                                         ", \t", &aliasString))
   {
      Url aliasUrl(aliasString);
      UtlString hostAlias;
      aliasUrl.getHostAddress(hostAlias);
      int port = aliasUrl.getHostPort();

      addValidDomain(hostAlias,port);
      aliasIndex++;
   }
   
   mConfigDb->get("SIP_REGISTRAR_BIND_IP", mBindIp);
   if ((mBindIp.isNull()) || !OsSocket::isIp4Address(mBindIp))
   {
	  mBindIp = "0.0.0.0";
   }   
}