示例#1
0
UtlBoolean SipTlsServer::createServerSocket(const char* szBindAddr,
                                            int& port,
                                            const UtlBoolean& bUseNextAvailablePort)
{
   UtlBoolean bSuccess = TRUE;

   OsSSLServerSocket* pSocket =
      new OsSSLServerSocket(ACCEPT_QUEUE_SIZE, port, szBindAddr);

   // If the socket is busy or unbindable and the user requested using the
   // next available port, try the next SIP_MAX_PORT_RANGE ports.
   if (bUseNextAvailablePort)
   {
      for (int i=1; !pSocket->isOk() && i<=SIP_MAX_PORT_RANGE; i++)
      {
         delete pSocket;
         pSocket = new OsSSLServerSocket(ACCEPT_QUEUE_SIZE, port+i, szBindAddr);
      }
   }

   // If we opened the socket.
   if (pSocket->isOk())
   {
      pSocket->setVerifyPeer(true);
      // Inform the SipUserAgent of the contact address.
      if (mSipUserAgent)
      {
         port = pSocket->getLocalHostPort();
         ContactAddress contact;
         strcpy(contact.cIpAddress, szBindAddr);
         contact.iPort = port;
         contact.eContactType = ContactAddress::LOCAL;
         char szAdapterName[16];
         memset((void*)szAdapterName, 0, sizeof(szAdapterName)); // null out the string

         getContactAdapterName(szAdapterName, contact.cIpAddress);

         strcpy(contact.cInterface, szAdapterName);
         mSipUserAgent->addContactAddress(contact);
      }

      // Add address and port to the maps.
      UtlString* address = new UtlString(szBindAddr);
      mServerSocketMap.insertKeyAndValue(address, pSocket);
      mServerPortMap.insertKeyAndValue(address,
                                       new UtlInt(pSocket->getLocalHostPort()));
      // pSocket is owned by the SipServerBroker.
      mServerBrokers.insertKeyAndValue(new UtlString(szBindAddr),
                                       new SipServerBroker(mpServerBrokerListener,
                                                           pSocket));
   }
   else
   {
      bSuccess = false;
   }

   return bSuccess;
}
示例#2
0
OsStatus SipUdpServer::createServerSocket(const char* szBoundIp,
                                          int& port,
                                          const UtlBoolean& bUseNextAvailablePort, 
                                          int udpReadBufferSize)
{
    OsStatus rc = OS_FAILED;
    OsStunDatagramSocket* pSocket =
      new OsStunDatagramSocket(0, NULL, port, szBoundIp, FALSE);
   
    if (pSocket)
    {
        // If the socket is busy or unbindable and the user requested using the
        // next available port, try the next SIP_MAX_PORT_RANGE ports.
        if (bUseNextAvailablePort & portIsValid(port) && pSocket && !pSocket->isOk())
        {
            for (int i=1; i<=SIP_MAX_PORT_RANGE; i++)
            {
                delete pSocket ;
                pSocket = new OsStunDatagramSocket(0, NULL, port+i, szBoundIp, FALSE);
                if (pSocket->isOk())
                {
                    break ;
                }
            }
        }
    }
    
    if (pSocket)
    {     
        port = pSocket->getLocalHostPort();
        CONTACT_ADDRESS contact;
        strcpy(contact.cIpAddress, szBoundIp);
        contact.iPort = port;
        contact.eContactType = LOCAL;
        char szAdapterName[16];
        memset((void*)szAdapterName, 0, sizeof(szAdapterName)); // null out the string
        
        getContactAdapterName(szAdapterName, contact.cIpAddress);

        strcpy(contact.cInterface, szAdapterName);
        mSipUserAgent->addContactAddress(contact);
   
        // add address and port to the maps
        mServerSocketMap.insertKeyAndValue(new UtlString(szBoundIp),
                                            new UtlVoidPtr((void*)pSocket));
        port = pSocket->getLocalHostPort() ;
        mServerPortMap.insertKeyAndValue(new UtlString(szBoundIp), new UtlInt(port));


        int sockbufsize = 0;
        int size = sizeof(int);
            getsockopt(pSocket->getSocketDescriptor(),
                    SOL_SOCKET,
                    SO_RCVBUF,
                    (char*)&sockbufsize,
        #if defined(__pingtel_on_posix__)
                    (socklen_t*) // caste
        #endif
                    &size);
        #ifdef LOG_SIZE
        OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipUdpServer::SipUdpServer UDP buffer size: %d size: %d\n",
                    sockbufsize, size);
        #endif /* LOG_SIZE */

        if(udpReadBufferSize > 0)
        {
            setsockopt(pSocket->getSocketDescriptor(),
            SOL_SOCKET,
            SO_RCVBUF,
            (char*)&udpReadBufferSize,
            sizeof(int));

            getsockopt(pSocket->getSocketDescriptor(),
                SOL_SOCKET,
                SO_RCVBUF,
                (char*)&sockbufsize,
        #if defined(__pingtel_on_posix__)
                (socklen_t*) // caste
        #endif
                &size);
        #ifdef LOG_SIZE
            OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipUdpServer::SipUdpServer reset UDP buffer size: %d size: %d\n",
                        sockbufsize, size);
        #endif /* LOG_SIZE */
        }
    }
    return rc;
}
示例#3
0
void SipUdpServer::createServerSocket(const char* szBindAddr,
                                      int& port,
                                      const UtlBoolean& bUseNextAvailablePort, 
                                      int udpReadBufferSize)
{
   // Create the socket.
   OsStunDatagramSocket* pSocket =
      new OsStunDatagramSocket(0, NULL, port, szBindAddr, FALSE);
   
   // If the socket is busy or unbindable and the user requested using the
   // next available port, try the next SIP_MAX_PORT_RANGE ports.
   if (bUseNextAvailablePort)
   {
      for (int i=1; !pSocket->isOk() && i<=SIP_MAX_PORT_RANGE; i++)
      {
         delete pSocket;
         pSocket = new OsStunDatagramSocket(0, NULL, port+i, szBindAddr, FALSE);
      }
   }
   
   // If we opened the socket.
   if (pSocket->isOk())
   {     
      // Inform the SipUserAgent of the contact address.
      if (mSipUserAgent)
      {
         port = pSocket->getLocalHostPort();
         CONTACT_ADDRESS contact;
         strcpy(contact.cIpAddress, szBindAddr);
         contact.iPort = port;
         contact.eContactType = LOCAL;
         char szAdapterName[16];
         memset((void*)szAdapterName, 0, sizeof(szAdapterName)); // null out the string

         getContactAdapterName(szAdapterName, contact.cIpAddress);

         strcpy(contact.cInterface, szAdapterName);
         mSipUserAgent->addContactAddress(contact);
      }

      // Add address and port to the maps.
      UtlString* address = new UtlString(szBindAddr);
      mServerSocketMap.insertKeyAndValue(address, pSocket);
      port = pSocket->getLocalHostPort();
      mServerPortMap.insertKeyAndValue(address,
                                       new UtlInt(port));

      // Get the UDP buffer size from the kernel.
      int sockbufsize = 0;
      // The type of 'size' depends on the platform.
#if defined(__pingtel_on_posix__)
      socklen_t
#else
         int
#endif
         size = sizeof (sockbufsize);
      getsockopt(pSocket->getSocketDescriptor(),
                 SOL_SOCKET,
                 SO_RCVBUF,
                 (char*) &sockbufsize,
                 &size);
#ifdef LOG_SIZE
      OsSysLog::add(FAC_SIP, PRI_DEBUG,
                    "SipUdpServer[%s]::SipUdpServer UDP buffer size: %d size: %d",
                    getName().data(), sockbufsize, size);
#endif /* LOG_SIZE */

      // If the user specified a UDP buffer size, attempt to set it.
      if (udpReadBufferSize > 0)
      {
         setsockopt(pSocket->getSocketDescriptor(),
                    SOL_SOCKET,
                    SO_RCVBUF,
                    (char*) &udpReadBufferSize,
                    sizeof (udpReadBufferSize));

         getsockopt(pSocket->getSocketDescriptor(),
                    SOL_SOCKET,
                    SO_RCVBUF,
                    (char*) &sockbufsize,
                    &size);
#ifdef LOG_SIZE
         OsSysLog::add(FAC_SIP, PRI_DEBUG,
                       "SipUdpServer[%s]::SipUdpServer reset UDP buffer size: %d size: %d",
                       getName().data(), sockbufsize, size);
#endif /* LOG_SIZE */
      }
   }
}
示例#4
0
OsStatus SipTlsServer::createServerSocket(const char* szBindAddr,
                                int& port,
                                const UtlBoolean& bUseNextAvailablePort)
{
    OsStatus rc = OS_FAILED;                                

    if(portIsValid(port))
    {
#ifdef SIP_TLS
#   ifdef SIP_TLS_NSS
        // TODO - create a new OpenTLSServerSocket
        OsServerSocket* pServerSocket = new OsTLSServerSocket(64, port, mCertNickname, mCertPassword, mDbLocation, szBindAddr);
        if (pServerSocket)
        {
            
        }
#   else
        OsServerSocket* pServerSocket = new OsSSLServerSocket(64, port);
#   endif
#else
        OsServerSocket* pServerSocket = new OsServerSocket(64, port);
#endif

        // If the socket is busy or unbindable and the user requested using the
        // next available port, try the next SIP_MAX_PORT_RANGE ports.
        if (bUseNextAvailablePort && !pServerSocket->isOk())
        {
            for (int i=1; i<=SIP_MAX_PORT_RANGE; i++)
            {
                delete pServerSocket ;
#ifdef SIP_TLS
#   ifdef SIP_TLS_NSS
                pServerSocket = new OsTLSServerSocket(64, port+i, mCertNickname, mCertPassword, mDbLocation);
#   else
                pServerSocket = new OsSSLServerSocket(64, port+i);
#   endif
#else
                pServerSocket = new OsServerSocket(64, port+i);
#endif                
                if (pServerSocket->isOk())
                {
                    break ;
                }
            }
        }
        
        if (pServerSocket && pServerSocket->isOk())
        {
            mServerPort = pServerSocket->getLocalHostPort() ;
            
            port = pServerSocket->getLocalHostPort();
            SIPX_CONTACT_ADDRESS contact;
            strcpy(contact.cIpAddress, szBindAddr);
            contact.iPort = port;
            contact.eContactType = CONTACT_LOCAL;
            char szAdapterName[16];
            memset((void*)szAdapterName, 0, sizeof(szAdapterName)); // null out the string
            

            getContactAdapterName(szAdapterName, contact.cIpAddress, false);
            strcpy(contact.cInterface, szAdapterName);
            contact.eTransportType = TRANSPORT_TLS;
            mSipUserAgent->addContactAddress(contact);
       
            // add address and port to the maps
            mServerSocketMap.insertKeyAndValue(new UtlString(szBindAddr),
                                               new UtlVoidPtr((void*)pServerSocket));
            mServerPortMap.insertKeyAndValue(new UtlString(szBindAddr),
                                                   new UtlInt(pServerSocket->getLocalHostPort()));
            mServerBrokers.insertKeyAndValue(new UtlString(szBindAddr),
                                              new UtlVoidPtr(new SipServerBroker((OsServerTask*)mpServerBrokerListener,
                                                                                                pServerSocket)));                                                   
    
            rc = OS_SUCCESS;
#           ifdef SIP_TLS_NSS
            TlsInitCodes tlsInitCode = ((OsTLSServerSocket*)pServerSocket)->getTlsInitCode();
            if (tlsInitCode != TLS_INIT_SUCCESS)
            {
                switch (tlsInitCode)
                {
                    case TLS_INIT_DATABASE_FAILURE:
                        mTlsInitCode = OS_TLS_INIT_DATABASE_FAILURE;
                        break;
                    case TLS_INIT_BAD_PASSWORD:
                        mTlsInitCode = OS_TLS_INIT_BAD_PASSWORD;
                        break;
                    case TLS_INIT_TCP_IMPORT_FAILURE:
                        mTlsInitCode = OS_TLS_INIT_TCP_IMPORT_FAILURE;
                        break;
                    case TLS_INIT_NSS_FAILURE:
                        mTlsInitCode = OS_TLS_INIT_NSS_FAILURE;
                        break;
                    default:
                        mTlsInitCode = OS_TLS_INIT_NSS_FAILURE;
                        break;
                }
                OsSysLog::add(FAC_SIP, PRI_ERR,
                  "SipTlsServer - init failure = %d",
                  mTlsInitCode);
            }
#           endif
        }
    }
    return rc;
}