예제 #1
0
파일: main.cpp 프로젝트: astubbs/sipxecs
//
// The main entry point to the sipXpark
//
int main(int argc, char* argv[])
{
   // Block all signals in this the main thread.
   // Any threads created from now on will have all signals masked.
   OsTask::blockSignals();

   // Create a new task to wait for signals.  Only that task
   // will ever see a signal from the outside.
   SignalTask* signalTask = new SignalTask();
   signalTask->start();

    // Configuration Database (used for OsSysLog)
    OsConfigDb configDb;

    UtlString argString;
    for(int argIndex = 1; argIndex < argc; argIndex++)
    {
        osPrintf("arg[%d]: %s\n", argIndex, argv[argIndex]);
        argString = argv[argIndex];
        NameValueTokenizer::frontBackTrim(&argString, "\t ");
        if(argString.compareTo("-v") == 0)
        {
            osPrintf("Version: %s (%s)\n", SIPX_VERSION, SIPX_BUILD);
            return(1);
        } else
        {
           osPrintf("usage: %s [-v]\nwhere:\n -v provides the software version\n",
            argv[0]);
            return(1);
        }
    }

    // Load configuration file file
    OsPath workingDirectory;
    if (OsFileSystem::exists(CONFIG_ETC_DIR))
    {
        workingDirectory = CONFIG_ETC_DIR;
        OsPath path(workingDirectory);
        path.getNativePath(workingDirectory);
    } else
    {
        OsPath path;
        OsFileSystem::getWorkingDirectory(path);
        path.getNativePath(workingDirectory);
    }

    UtlString fileName =  workingDirectory +
      OsPathBase::separator +
      CONFIG_SETTINGS_FILE;

    if (configDb.loadFromFile(fileName) != OS_SUCCESS)
    {
       exit(1);
    }

    // Initialize log file
    initSysLog(&configDb);

    // Read the user agent parameters from the config file.
    int UdpPort;
    if (configDb.get(CONFIG_SETTING_UDP_PORT, UdpPort) != OS_SUCCESS)
        UdpPort = PARK_DEFAULT_UDP_PORT;

    int TcpPort;
    if (configDb.get(CONFIG_SETTING_TCP_PORT, TcpPort) != OS_SUCCESS)
        TcpPort = PARK_DEFAULT_TCP_PORT;

    int RtpBase;
    if (configDb.get(CONFIG_SETTING_RTP_PORT, RtpBase) != OS_SUCCESS)
        RtpBase = DEFAULT_RTP_PORT;

    UtlString bindIp;
    if (configDb.get(CONFIG_SETTING_BIND_IP, bindIp) != OS_SUCCESS ||
            !OsSocket::isIp4Address(bindIp))
        bindIp = PARK_DEFAULT_BIND_IP;

    int MaxSessions;
    if (configDb.get(CONFIG_SETTING_MAX_SESSIONS, MaxSessions) != OS_SUCCESS)
    {
        MaxSessions = DEFAULT_MAX_SESSIONS;
    }

    UtlBoolean OneButtonBLF =
       configDb.getBoolean(CONFIG_SETTING_ONE_BUTTON_BLF, DEFAULT_ONE_BUTTON_BLF);

    UtlString   domain;
    UtlString   realm;
    UtlString   user;

    SipLine*    line = NULL;
    SipLineMgr* lineMgr = NULL;

    OsConfigDb  domainConfiguration;
    OsPath      domainConfigPath = SipXecsService::domainConfigPath();

    if (OS_SUCCESS == domainConfiguration.loadFromFile(domainConfigPath.data()))
    {
       domainConfiguration.get(SipXecsService::DomainDbKey::SIP_DOMAIN_NAME, domain);
       domainConfiguration.get(SipXecsService::DomainDbKey::SIP_REALM, realm);

       if (!domain.isNull() && !realm.isNull())
       {
          CredentialDB* credentialDb;
          if ((credentialDb = CredentialDB::getInstance()))
          {
             Url identity;

             identity.setUserId(PARK_SERVER_ID_TOKEN);
             identity.setHostAddress(domain);

             UtlString ha1_authenticator;
             UtlString authtype;

             if (credentialDb->getCredential(identity, realm, user, ha1_authenticator, authtype))
             {
                if ((line = new SipLine( identity // user entered url
                                        ,identity // identity url
                                        ,user     // user
                                        ,TRUE     // visible
                                        ,SipLine::LINE_STATE_PROVISIONED
                                        ,TRUE     // auto enable
                                        ,FALSE    // use call handling
                                        )))
                {
                   if ((lineMgr = new SipLineMgr()))
                   {
                      if (lineMgr->addLine(*line))
                      {
                         if (lineMgr->addCredentialForLine( identity, realm, user, ha1_authenticator
                                                           ,HTTP_DIGEST_AUTHENTICATION
                                                           )
                             )
                         {
                            OsSysLog::add(LOG_FACILITY, PRI_INFO,
                                          "Added identity '%s': user='******' realm='%s'"
                                          ,identity.toString().data(), user.data(), realm.data()
                                          );
                         }
                         else
                         {
                            OsSysLog::add(LOG_FACILITY, PRI_ERR,
                                          "Error adding identity '%s': user='******' realm='%s'\n"
                                          "  escape and timeout from park may not work.",
                                          identity.toString().data(), user.data(), realm.data()
                                          );
                         }

                         lineMgr->setDefaultOutboundLine(identity);
                      }     // end addLine
                      else
                      {
                         OsSysLog::add(LOG_FACILITY, PRI_ERR,
                                       "addLine failed: "
                                       "  escape and timeout from park may not work."
                                       );
                      }
                   }
                   else
                   {
                      OsSysLog::add(LOG_FACILITY, PRI_ERR,
                                    "Constructing SipLineMgr failed:  "
                                    "  escape and timeout from park may not work."
                                    );
                   }
                }   // end new SipLine
                else
                {
                   OsSysLog::add(LOG_FACILITY, PRI_ERR,
                                 "Constructing SipLine failed:  "
                                 "  escape and timeout from park may not work."
                                 );
                }
             }  // end getCredential
             else
             {
                OsSysLog::add(LOG_FACILITY, PRI_ERR,
                              "No credential found for '%s@%s' in realm '%s'"
                              "; transfer functions will not work",
                              PARK_SERVER_ID_TOKEN, domain.data(), realm.data()
                              );
             }

             credentialDb->releaseInstance();
          }   // end credentialDB
          else
          {
             OsSysLog::add(LOG_FACILITY, PRI_ERR,
                           "Failed to open credentials database"
                           "; transfer functions will not work"
                           );
          }
       }    // end have domain and realm
       else
       {
          OsSysLog::add(LOG_FACILITY, PRI_ERR,
                        "Domain or Realm not configured:"
                        "\n  '%s' : '%s'\n  '%s' : '%s'"
                        "  transfer functions will not work.",
                        SipXecsService::DomainDbKey::SIP_DOMAIN_NAME, domain.data(),
                        SipXecsService::DomainDbKey::SIP_REALM, realm.data()
                        );
       }
    }       // end found domain config
    else
    {
       OsSysLog::add(LOG_FACILITY, PRI_ERR,
                     "main: failed to load domain configuration from '%s'",
                     domainConfigPath.data()
                     );
    }

    // Read Park Server parameters from the config file.
    int Lifetime, BlindXferWait, KeepAliveTime, ConsXferWait;
    if (configDb.get(CONFIG_SETTING_LIFETIME, Lifetime) != OS_SUCCESS)
    {
       Lifetime = DEFAULT_LIFETIME;
    }
    if (configDb.get(CONFIG_SETTING_BLIND_WAIT, BlindXferWait) != OS_SUCCESS)
    {
       BlindXferWait = DEFAULT_BLIND_WAIT;
    }
    if (configDb.get(CONFIG_SETTING_KEEPALIVE_TIME, KeepAliveTime) != OS_SUCCESS)
    {
       KeepAliveTime = DEFAULT_KEEPALIVE_TIME;
    }
    // This is not configurable, as consultative transfers should
    // succeed or fail immediately.
    ConsXferWait = CONS_XFER_WAIT;

    // Bind the SIP user agent to a port and start it up
    SipUserAgent* userAgent = new SipUserAgent(TcpPort,
                                               UdpPort,
                                               TcpPort+1,
                                               NULL, // publicAddress
                                               user.isNull() ? NULL : user.data(), // default user
                                               bindIp,
                                               domain.isNull() ? NULL : domain.data(), // outbound proxy
                                               NULL, // sipDirectoryServers (deprecated)
                                               NULL, // sipRegistryServers (deprecated)
                                               NULL, // authenticationScheme
                                               NULL, // authenicateRealm
                                               NULL, // authenticateDb
                                               NULL, // authorizeUserIds (deprecated)
                                               NULL, // authorizePasswords (deprecated)
                                               lineMgr
                                               );
    userAgent->setUserAgentHeaderProperty("sipXecs/park");
    userAgent->start();

    if (!userAgent->isOk())
    {
       OsSysLog::add(LOG_FACILITY, PRI_EMERG, "SipUserAgent failed to initialize, requesting shutdown");
       gShutdownFlag = TRUE;
    }

    // Read the list of codecs from the configuration file.
    SdpCodecFactory codecFactory;
    initCodecs(&codecFactory, &configDb);

    // Initialize and start up the media subsystem
    mpStartUp(MP_SAMPLE_RATE, MP_SAMPLES_PER_FRAME, 6 * MaxSessions, &configDb);
    MpMediaTask::getMediaTask(MaxSessions);

#ifdef INCLUDE_RTCP
    CRTCManager::getRTCPControl();
#endif //INCLUDE_RTCP

    mpStartTasks();

    // Instantiate the call processing subsystem
    UtlString localAddress;
    int localPort ;
    userAgent->getLocalAddress(&localAddress, &localPort) ;
    if (localAddress.isNull())
        OsSocket::getHostIp(&localAddress);

    // Construct an address to be used in outgoing requests (primarily
    // INVITEs stimulated by REFERs).
    UtlString outgoingAddress;
    {
       char buffer[100];
       sprintf(buffer, "sip:sipXpark@%s:%d", localAddress.data(),
               portIsValid(UdpPort) ? UdpPort : TcpPort);
       outgoingAddress = buffer;
    }
    CallManager callManager(FALSE,
                           NULL,
                           TRUE,                              // early media in 180 ringing
                           &codecFactory,
                           RtpBase,                           // rtp start
                           RtpBase + (2 * MaxSessions),       // rtp end
                           localAddress,
                           localAddress,
                           userAgent,
                           0,                                 // sipSessionReinviteTimer
                           NULL,                              // mgcpStackTask
                           outgoingAddress,                   // defaultCallExtension
                           Connection::RING,                  // availableBehavior
                           NULL,                              // unconditionalForwardUrl
                           -1,                                // forwardOnNoAnswerSeconds
                           NULL,                              // forwardOnNoAnswerUrl
                           Connection::BUSY,                  // busyBehavior
                           NULL,                              // sipForwardOnBusyUrl
                           NULL,                              // speedNums
                           CallManager::SIP_CALL,             // phonesetOutgoingCallProtocol
                           4,                                 // numDialPlanDigits
                           CallManager::NEAR_END_HOLD,        // holdType
                           5000,                              // offeringDelay
                           "",                                // pLocal
                           CP_MAXIMUM_RINGING_EXPIRE_SECONDS, // inviteExpiresSeconds
                           QOS_LAYER3_LOW_DELAY_IP_TOS,       // expeditedIpTos
                           MaxSessions,                       // maxCalls
                           sipXmediaFactoryFactory(NULL));    // CpMediaInterfaceFactory



    // Create a listener (application) to deal with call
    // processing events (e.g. incoming call and hang ups)
    OrbitListener listener(&callManager, Lifetime, BlindXferWait, KeepAliveTime, ConsXferWait);

    callManager.addTaoListener(&listener);
    listener.start();

    // Create the SIP Subscribe Server
    SipPersistentSubscriptionMgr
       subscriptionMgr(SUBSCRIPTION_COMPONENT_PARK,
                       domain,
                       "subscription"); // Component for holding the subscription data
    SipSubscribeServerEventHandler policyHolder; // Component for granting the subscription rights
    SipPublishContentMgr publisher; // Component for publishing the event contents

    SipSubscribeServer subscribeServer(*userAgent, publisher,
                                       subscriptionMgr, policyHolder);
    subscribeServer.enableEventType(DIALOG_EVENT_TYPE);
    subscribeServer.start();

    // Create the DialogEventPublisher.
    // Use the sipX domain as the hostport of resource-IDs of the
    // published events, as that will be the request-URIs of SUBSCRIBEs.
    DialogEventPublisher dialogEvents(&callManager, &publisher, domain, PORT_NONE, OneButtonBLF);
    callManager.addTaoListener(&dialogEvents);
    dialogEvents.start();

    // Start up the call processing system
    callManager.start();

    // Loop forever until signaled to shut down

    int numTwoSecIntervals = 0;
    int CleanLoopWaitTimeSecs = 10;

    while (!gShutdownFlag)
    {
       OsTask::delay(2000);

       if (2*numTwoSecIntervals >= CleanLoopWaitTimeSecs)
       {
           numTwoSecIntervals = 0;
           if (OsSysLog::willLog(FAC_PARK, PRI_DEBUG))
           {
               OsSysLog::add(LOG_FACILITY, PRI_DEBUG,
                             "park main "
                             "logging call status"
                             );
               callManager.printCalls(0) ;
               listener.dumpCallsAndTransfers();
           }
       }
       else
       {
           numTwoSecIntervals += 1;
       }

    }

    // Flush the log file
    OsSysLog::flush();

    // Say goodnight Gracie...
    return 0;
}
예제 #2
0
파일: main.cpp 프로젝트: ciuc/sipxecs
//
// The main entry point to sipXrls.
//
int main(int argc, char* argv[])
{
   // Configuration Database (used for OsSysLog)
   OsConfigDb configDb;

   UtlString argString;
   for (int argIndex = 1; argIndex < argc; argIndex++)
   {
      osPrintf("arg[%d]: %s\n", argIndex, argv[argIndex]);
      argString = argv[argIndex];
      NameValueTokenizer::frontBackTrim(&argString, "\t ");
      if (argString.compareTo("-v") == 0)
      {
         osPrintf("Version: %s (%s)\n", VERSION, PACKAGE_REVISION);
         return 1;
      }
      else
      {
         osPrintf("usage: %s [-v]\nwhere:\n -v provides the software version\n",
                  argv[0]);
         return 1;
      }
   }

   // Load configuration file.
   OsPath workingDirectory;
   if (OsFileSystem::exists(CONFIG_ETC_DIR))
   {
      workingDirectory = CONFIG_ETC_DIR;
      OsPath path(workingDirectory);
      path.getNativePath(workingDirectory);
   }
   else
   {
      OsPath path;
      OsFileSystem::getWorkingDirectory(path);
      path.getNativePath(workingDirectory);
   }

   UtlString fileName =  workingDirectory +
      OsPathBase::separator +
      CONFIG_SETTINGS_FILE;

   if (configDb.loadFromFile(fileName) != OS_SUCCESS)
   {
      fprintf(stderr, "Failed to load config DB from file '%s'",
              fileName.data());
      exit(1);
   }

   // Initialize log file
   initSysLog(&configDb);

   // Read the user agent parameters from the config file.
   int udpPort;
   if (configDb.get(CONFIG_SETTING_UDP_PORT, udpPort) != OS_SUCCESS)
   {
      udpPort = RLS_DEFAULT_UDP_PORT;
   }

   int tcpPort;
   if (configDb.get(CONFIG_SETTING_TCP_PORT, tcpPort) != OS_SUCCESS)
   {
      tcpPort = RLS_DEFAULT_TCP_PORT;
   }

    UtlString bindIp;
    if (configDb.get(CONFIG_SETTING_BIND_IP, bindIp) != OS_SUCCESS ||
            !OsSocket::isIp4Address(bindIp))
        bindIp = RLS_DEFAULT_BIND_IP;

   UtlString resourceListFile;
   if ((configDb.get(CONFIG_SETTING_RLS_FILE, resourceListFile) !=
        OS_SUCCESS) ||
       resourceListFile.isNull())
   {
      Os::Logger::instance().log(LOG_FACILITY, PRI_CRIT,
                    "Resource list file name is not configured");
      return 1;
   }

   UtlString domainName;
   if ((configDb.get(CONFIG_SETTING_DOMAIN_NAME, domainName) !=
        OS_SUCCESS) ||
       domainName.isNull())
   {
      Os::Logger::instance().log(LOG_FACILITY, PRI_CRIT,
                    "Resource domain name is not configured");
      return 1;
   }

   UtlString realm;
   if ((configDb.get(CONFIG_SETTING_AUTHENTICATE_REALM, realm) !=
        OS_SUCCESS) ||
       realm.isNull())
   {
      Os::Logger::instance().log(LOG_FACILITY, PRI_CRIT,
                    "Resource realm is not configured");
      return 1;
   }

   int resubscribeInterval;
   if (configDb.get(CONFIG_SETTING_RESUBSCRIBE_INTERVAL, resubscribeInterval) != OS_SUCCESS)
   {
      resubscribeInterval = RLS_DEFAULT_RESUBSCRIBE_INTERVAL;
   }

   int minResubscribeInterval;
   if (configDb.get(CONFIG_SETTING_MIN_RESUBSCRIBE_INTERVAL, minResubscribeInterval) != OS_SUCCESS)
   {
       minResubscribeInterval = RLS_DEFAULT_MIN_RESUBSCRIBE_INTERVAL;
   }

   int serverMinExpiration;
   if (configDb.get(CONFIG_SETTING_SERVER_MIN_EXPIRATION, serverMinExpiration) != OS_SUCCESS)
   {
       serverMinExpiration = RLS_DEFAULT_SERVER_MIN_EXPIRATION;
   }

   int serverDefaultExpiration;
   if (configDb.get(CONFIG_SETTING_SERVER_DEFAULT_EXPIRATION, serverDefaultExpiration) != OS_SUCCESS)
   {
       serverDefaultExpiration = RLS_DEFAULT_SERVER_DEFAULT_EXPIRATION;
   }

   int serverMaxExpiration;
   if (configDb.get(CONFIG_SETTING_SERVER_MAX_EXPIRATION, serverMaxExpiration) != OS_SUCCESS)
   {
       serverMaxExpiration = RLS_DEFAULT_SERVER_MAX_EXPIRATION;
   }

   // add the ~~sipXrls credentials so that sipXrls can respond to challenges
   SipLineMgr* lineMgr = addCredentials(domainName, realm);
   if(NULL == lineMgr)
   {
      return 1;
   }

   if (!gShutdownFlag)
   {
      // Initialize the ResourceListServer.
      ResourceListServer rls(domainName, realm, lineMgr,
                             DIALOG_EVENT_TYPE, DIALOG_EVENT_CONTENT_TYPE,
                             tcpPort, udpPort, PORT_NONE, bindIp,
                             &resourceListFile,
                             resubscribeInterval, minResubscribeInterval,
                             RLS_PUBLISH_DELAY,
                             20, 20, 20, 20,
                             serverMinExpiration,
                             serverDefaultExpiration,
                             serverMaxExpiration);
      rls.start();

      // Loop forever until signaled to shut down
      while (!Os::UnixSignals::instance().isTerminateSignalReceived() && !gShutdownFlag)
      {
         OsTask::delay(2000);
         // See if the list configuration file has changed.
         rls.getResourceListFileReader().refresh();
      }

      // Shut down the server.
      rls.shutdown();
   }

   lineMgr->requestShutdown();
   
   while (!lineMgr->isShutDown())
   {
      OsTask::delay(100);
   }
   
   // Delete the LineMgr Object
   delete lineMgr;

   
   // Flush the log file
   Os::Logger::instance().flush();
   
   
		    
   // Say goodnight Gracie...
   return 0;
}
예제 #3
0
// Get and add the credentials for sipXregistrar
SipLineMgr*
SipRedirectorJoin::addCredentials (UtlString domain, UtlString realm)
{
   SipLine* line = NULL;
   SipLineMgr* lineMgr = NULL;
   UtlString user;


      Url identity;

      identity.setUserId(REGISTRAR_ID_TOKEN);
      identity.setHostAddress(domain);
      UtlString ha1_authenticator;
      UtlString authtype;
      bool bSuccess = false;

      EntityDB* entityDb = SipRegistrar::getInstance(NULL)->getEntityDB();
      if (entityDb->getCredential(identity, realm, user, ha1_authenticator, authtype))
      {
         if ((line = new SipLine( identity // user entered url
                                 ,identity // identity url
                                 ,user     // user
                                 ,TRUE     // visible
                                 ,SipLine::LINE_STATE_PROVISIONED
                                 ,TRUE     // auto enable
                                 ,FALSE    // use call handling
                                 )))
         {
            if ((lineMgr = new SipLineMgr()))
            {
               if (lineMgr->addLine(*line))
               {
                  if (lineMgr->addCredentialForLine( identity, realm, user, ha1_authenticator
                                                    ,HTTP_DIGEST_AUTHENTICATION
                                                    )
                      )
                  {
                     lineMgr->setDefaultOutboundLine(identity);
                     bSuccess = true;

                     Os::Logger::instance().log(FAC_SIP, PRI_INFO,
                                   "Added identity '%s': user='******' realm='%s'"
                                   ,identity.toString().data(), user.data(), realm.data()
                                   );
                  }
                  else
                  {
                     Os::Logger::instance().log(FAC_SIP, PRI_ERR,
                                   "Error adding identity '%s': user='******' realm='%s'\n"
                                   "Call Join feature will not work!",
                                   identity.toString().data(), user.data(), realm.data()
                                   );
                  }
               }
               else
               {
                  Os::Logger::instance().log(FAC_SIP, PRI_ERR, "addLine failed. Call Join feature will not work!" );
               }
            }
            else
            {
               Os::Logger::instance().log(FAC_SIP, PRI_ERR,
                             "Constructing SipLineMgr failed. Call Join feature will not work!" );
            }
         }
         else
         {
            Os::Logger::instance().log(FAC_SIP, PRI_ERR,
                          "Constructing SipLine failed. Call Join feature will not work!" );
         }
      }
      else
      {
         Os::Logger::instance().log(FAC_SIP, PRI_ERR,
                       "No credential found for '%s' in realm '%s'. "
                       "Call Join feature will not work!"
                       ,identity.toString().data(), realm.data()
                       );
      }

      if( !bSuccess )
      {
         delete line;
         line = NULL;

         delete lineMgr;
         lineMgr = NULL;
      }


   return lineMgr;
}
예제 #4
0
   void testShutdownNonBlocking()
   {
      int myPID = OsProcess::getCurrentPID();
      int startingThreads;

      // Stop TimerTask and NatAgentTask before counting threads.
      // Some tests do not bother stopping them, so they may come started.
      OsTimerTask::destroyTimerTask();
      OsNatAgentTask::releaseInstance();

      // Count number of threads now.
      startingThreads = getNumThreads(myPID);

      // Simple invite message from siptest/src/siptest/invite.txt
      const char* SimpleMessage = 
          "INVITE sip:[email protected] SIP/2.0\r\n"
          "Route: <sip:[email protected]:5064;lr>\r\n"
          "From: <sip:[email protected];user=phone>;tag=bbb\r\n"
          "To: <sip:[email protected]:3000;user=phone>\r\n"
          "Call-Id: 8\r\n"
          "Cseq: 1 INVITE\r\n"
          "Content-Length: 0\r\n"
          "\r\n";

      SipMessage testMsg( SimpleMessage, strlen( SimpleMessage ) );

      for(int i = 0; i < SHUTDOWN_TEST_ITERATIONS; ++i)
      {
         // Limit life time of lineMgr and refreshMgr. They should be freed
         // before releasing OsNatAgentTask instance, or we will crash.
         {
            SipLineMgr    lineMgr;
            SipRefreshMgr refreshMgr;

            lineMgr.StartLineMgr();
            lineMgr.initializeRefreshMgr( &refreshMgr );

            SipUserAgent sipUA( 5090
                              ,5090
                              ,5091
                              ,NULL     // default publicAddress
                              ,NULL     // default defaultUser
                              ,"127.0.0.1"     // default defaultSipAddress
                              ,NULL     // default sipProxyServers
                              ,NULL     // default sipDirectoryServers
                              ,NULL     // default sipRegistryServers
                              ,NULL     // default authenticationScheme
                              ,NULL     // default authenicateRealm
                              ,NULL     // default authenticateDb
                              ,NULL     // default authorizeUserIds
                              ,NULL     // default authorizePasswords
                              ,&lineMgr
                              );

            sipUA.start();
            refreshMgr.init(&sipUA);

            sipUA.send(testMsg);

            // Wait long enough for some stack timeouts/retransmits to occur
            OsTask::delay(10000); // 10 seconds

            sipUA.shutdown(FALSE);
            lineMgr.requestShutdown();
            refreshMgr.requestShutdown();

            while(!sipUA.isShutdownDone())
            {
               ;
            }
            CPPUNIT_ASSERT(sipUA.isShutdownDone());
         }

         // Stop TimerTask and NatAgentTask again before counting threads.
         // They were started while testing.
         OsTimerTask::destroyTimerTask();
         OsNatAgentTask::releaseInstance();

         // Test to see that all the threads created by the above operations
         // get properly shut down.
         // Since the threads do not shut down synchronously with the above
         // calls, we have to wait before we know they will be cleared.
         OsTask::delay(1000);   // 1 second
         int numThreads = getNumThreads(myPID);
         CPPUNIT_ASSERT_EQUAL(startingThreads,numThreads);
      }
   };
예제 #5
0
파일: main.cpp 프로젝트: ciuc/sipxecs
// Get and add the credentials for sipXrls
SipLineMgr* addCredentials (UtlString domain, UtlString realm)
{
   SipLine* line = NULL;
   SipLineMgr* lineMgr = NULL;
   UtlString user;

   MongoDB::Collection<EntityDB>& credentialDB = EntityDB::defaultCollection();

  Url identity;

  identity.setUserId(RLSSERVER_ID_TOKEN);
  identity.setHostAddress(domain);
  UtlString ha1_authenticator;
  UtlString authtype;
  bool bSuccess = false;

  if (credentialDB.collection().getCredential(identity, realm, user, ha1_authenticator, authtype))
  {
     if ((line = new SipLine( identity // user entered url
                             ,identity // identity url
                             ,user     // user
                             ,TRUE     // visible
                             ,SipLine::LINE_STATE_PROVISIONED
                             ,TRUE     // auto enable
                             ,FALSE    // use call handling
                             )))
     {
        if ((lineMgr = new SipLineMgr()))
        {
           if (lineMgr->addLine(*line))
           {
              if (lineMgr->addCredentialForLine( identity, realm, user, ha1_authenticator
                                                ,HTTP_DIGEST_AUTHENTICATION
                                                )
                  )
              {
                 lineMgr->setDefaultOutboundLine(identity);
                 bSuccess = true;

                 Os::Logger::instance().log(LOG_FACILITY, PRI_INFO,
                               "Added identity '%s': user='******' realm='%s'"
                               ,identity.toString().data(), user.data(), realm.data()
                               );
              }
              else
              {
                 Os::Logger::instance().log(LOG_FACILITY, PRI_CRIT,
                               "Error adding identity '%s': user='******' realm='%s'\n",
                               identity.toString().data(), user.data(), realm.data()
                               );
              }
           }
           else
           {
              Os::Logger::instance().log(LOG_FACILITY, PRI_CRIT, "addLine failed" );
           }
        }
        else
        {
           Os::Logger::instance().log(LOG_FACILITY, PRI_CRIT,
                         "Constructing SipLineMgr failed" );
        }
        // lineMgr does not take ownership of *line, so we have to delete it.
        delete line;
     }
     else
     {
        Os::Logger::instance().log(LOG_FACILITY, PRI_CRIT,
                      "Constructing SipLine failed" );
     }
  }
  else
  {
     Os::Logger::instance().log(LOG_FACILITY, PRI_CRIT,
                   "No credential found for '%s' in realm '%s'"
                   ,identity.toString().data(), realm.data()
                   );
  }

  if( !bSuccess )
  {
     delete line;
     line = NULL;

     delete lineMgr;
     lineMgr = NULL;
  }


   return lineMgr;
}
예제 #6
0
    // Test line adding functions from the SipLineMgr
    void testLineManagerAddLine()
    {
        UtlString lineId ;
        Url identity("\"Display Name\" <sip:[email protected]>", Url::NameAddr, NULL) ;
        Url alias("\"Display Name\" <sip:[email protected]>", Url::NameAddr, NULL) ;
        char cTemp[256] ;
        UtlBoolean bRC ;
        int iRC ;

        SipLineMgr mgr ;
        SipLine line(identity, identity, "userId") ;
        lineId = line.getLineId() ;

        // Add Line
        bRC = mgr.addLine(line, false) ;
        CPPUNIT_ASSERT(bRC) ;

        // Add alias
        bRC = mgr.addLineAlias(identity, alias) ;
        CPPUNIT_ASSERT(bRC) ;

        // Add credential
        UtlString passwordToken;
        HttpMessage::buildMd5UserPasswordDigest("userId", "testRealm", "password", passwordToken);
        bRC = mgr.addCredentialForLine(identity, "testRealm", "userId", passwordToken, HTTP_DIGEST_AUTHENTICATION) ;
        CPPUNIT_ASSERT(bRC) ;


        // Sanity Checking
        iRC = mgr.getNumLines() ;
        CPPUNIT_ASSERT(iRC == 1) ;
        iRC = mgr.getNumOfCredentialsForLine(identity) ;
        CPPUNIT_ASSERT(iRC == 1) ;
        iRC = mgr.getNumOfCredentialsForLine(alias) ;
        CPPUNIT_ASSERT(iRC == 1) ;

        SipLine test ;

        //
        // Test getLine via "To" URL
        //
        bRC = mgr.getLine("sip:[email protected]", "", "", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("sip:[email protected]", "", "", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("sip:[email protected]", "", "", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("sip:example.com", "", "", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("sip:[email protected]", "", "", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("sip:[email protected]", "", "", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("sip:[email protected]", "", "", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("sip:127.0.0.1", "", "", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        sprintf(cTemp, "<sip:127.0.0.1;LINEID=%s>", lineId.data()) ;
        bRC = mgr.getLine(cTemp, "", "", test) ;
        CPPUNIT_ASSERT(bRC) ;

        //
        // Test getLine via local contact
        //
        bRC = mgr.getLine("", "sip:[email protected]", "", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("", "sip:[email protected]", "", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("", "sip:[email protected]", "", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("", "sip:example.com", "", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("", "sip:[email protected]", "", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("", "sip:[email protected]", "", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("", "sip:[email protected]", "", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("", "sip:127.0.0.1", "", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        sprintf(cTemp, "<sip:127.0.0.1;LINEID=%s>", lineId.data()) ;
        bRC = mgr.getLine("", cTemp, "", test) ;
        CPPUNIT_ASSERT(bRC) ;

        //
        // Test getLine via request URI
        //
        bRC = mgr.getLine("", "", "sip:[email protected]", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("", "", "sip:[email protected]", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("", "", "sip:[email protected]", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("", "", "sip:example.com", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("", "", "sip:[email protected]", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("", "", "sip:[email protected]", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("", "", "sip:[email protected]", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("", "", "sip:127.0.0.1", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        sprintf(cTemp, "sip:127.0.0.1;LINEID=%s", lineId.data()) ;
        bRC = mgr.getLine("", "", cTemp, test) ;
        CPPUNIT_ASSERT(bRC) ;
    }
예제 #7
0
    // Test matching line authentication credentials
    void testLineManagerAuthLineSelect()
    {
        UtlString lineId ;
        Url identity("\"Display Name\" <sip:[email protected]>", Url::NameAddr, NULL) ;
        Url alias("\"Display Name\" <sip:[email protected]>", Url::NameAddr, NULL) ;
        UtlBoolean bRC ;
        Url from ;
        Url contact ;
        SipLineMgr mgr ;

        // Add line
        SipLine line(identity, identity, "userId") ;
        lineId = line.getLineId() ;
        bRC = mgr.addLine(line, false) ;
        CPPUNIT_ASSERT(bRC) ;

        // Add alias
        bRC = mgr.addLineAlias(identity, alias) ;
        CPPUNIT_ASSERT(bRC) ;

        // Add credential
        UtlString passwordToken;
        HttpMessage::buildMd5UserPasswordDigest("userId", "testRealm", "password", passwordToken);
        bRC = mgr.addCredentialForLine(identity, "testRealm", "userId", passwordToken, HTTP_DIGEST_AUTHENTICATION) ;
        CPPUNIT_ASSERT(bRC) ;

        // Expected From and Contact
        {
            SipMessage request ;
            SipMessage response ;
            SipMessage requestWithAuth;

            from = identity ;
            from.setFieldParameter("tag", "5678") ;
            line.getPreferredContactUri(contact) ;
            buildRequestAndResponse(from, contact, request, response) ;
            bRC = mgr.buildAuthenticatedRequest(&response, &request, &requestWithAuth);
            CPPUNIT_ASSERT(bRC) ;
        }

        // Expected From and Contact w/o lineId
        {
            SipMessage request ;
            SipMessage response ;
            SipMessage requestWithAuth;

            from = identity ;
            from.setFieldParameter("tag", "5678") ;
            contact = identity ;
            buildRequestAndResponse(from, contact, request, response) ;
            bRC = mgr.buildAuthenticatedRequest(&response, &request, &requestWithAuth);
            CPPUNIT_ASSERT(bRC) ;
        }

        // Unknown identity and Unknown Contact
        {
            SipMessage request ;
            SipMessage response ;
            SipMessage requestWithAuth;

            from = Url("<sip:[email protected]>;tag=5678", Url::NameAddr, NULL) ;
            contact = Url("sip:[email protected]", Url::NameAddr, NULL) ;
            buildRequestAndResponse(from, contact, request, response) ;
            bRC = mgr.buildAuthenticatedRequest(&response, &request, &requestWithAuth);
            CPPUNIT_ASSERT(!bRC) ;
        }

        // Unknown identity and Unknown Contact w/ LineId
        {
            SipMessage request ;
            SipMessage response ;
            SipMessage requestWithAuth;

            from = Url("<sip:[email protected]>;tag=5678", Url::NameAddr, NULL) ;
            contact = Url("sip:[email protected]", Url::NameAddr, NULL) ;
            contact.setUrlParameter("LINEID", lineId) ;
            buildRequestAndResponse(from, contact, request, response) ;
            bRC = mgr.buildAuthenticatedRequest(&response, &request, &requestWithAuth);
            CPPUNIT_ASSERT(bRC) ;
        }

        // Unknown identity and IP w/ LineId
        {
            SipMessage request ;
            SipMessage response ;
            SipMessage requestWithAuth;

            from = Url("<sip:[email protected]>;tag=5678", Url::NameAddr, NULL) ;
            contact = Url("sip:127.0.0.1", Url::NameAddr, NULL) ;
            contact.setUrlParameter("LINEID", lineId) ;
            buildRequestAndResponse(from, contact, request, response) ;
            bRC = mgr.buildAuthenticatedRequest(&response, &request, &requestWithAuth);
            CPPUNIT_ASSERT(bRC) ;
        }

        // Expected identity and Unknown contact
        {
            SipMessage request ;
            SipMessage response ;
            SipMessage requestWithAuth;

            from = identity ;
            from.setFieldParameter("tag", "5678") ;
            contact = Url("sip:127.0.0.1", Url::NameAddr, NULL) ;
            buildRequestAndResponse(from, contact, request, response) ;
            bRC = mgr.buildAuthenticatedRequest(&response, &request, &requestWithAuth);
            CPPUNIT_ASSERT(bRC) ;
        }

        // Alias identity and Unknown contact
        {
            SipMessage request ;
            SipMessage response ;
            SipMessage requestWithAuth;

            from = alias ;
            from.setFieldParameter("tag", "5678") ;
            contact = Url("sip:127.0.0.1", Url::NameAddr, NULL) ;
            buildRequestAndResponse(from, contact, request, response) ;
            bRC = mgr.buildAuthenticatedRequest(&response, &request, &requestWithAuth);
            CPPUNIT_ASSERT(bRC) ;
        }

        // Unknown identity and alias contact
        {
            SipMessage request ;
            SipMessage response ;
            SipMessage requestWithAuth ;

            from = Url("<sip:[email protected]>;tag=5678", Url::NameAddr, NULL) ;
            contact = alias;
            buildRequestAndResponse(from, contact, request, response) ;
            bRC = mgr.buildAuthenticatedRequest(&response, &request, &requestWithAuth);
            CPPUNIT_ASSERT(bRC) ;
        }
    }
예제 #8
0
파일: main.cpp 프로젝트: astubbs/sipxecs
// Get and add the credentials for sipXsaa
SipLineMgr* addCredentials (UtlString domain, UtlString realm)
{
   SipLine* line = NULL;
   SipLineMgr* lineMgr = NULL;
   UtlString user;

   CredentialDB* credentialDb;
   if ((credentialDb = CredentialDB::getInstance()))
   {
      Url identity;

      identity.setUserId(SAASERVER_ID_TOKEN);
      identity.setHostAddress(domain);
      UtlString ha1_authenticator;
      UtlString authtype;
      bool bSuccess = false;

      if (credentialDb->getCredential(identity, realm, user, ha1_authenticator, authtype))
      {
         if ((line = new SipLine( identity // user entered url
                                 ,identity // identity url
                                 ,user     // user
                                 ,TRUE     // visible
                                 ,SipLine::LINE_STATE_PROVISIONED
                                 ,TRUE     // auto enable
                                 ,FALSE    // use call handling
                                 )))
         {
            if ((lineMgr = new SipLineMgr()))
            {
               if (lineMgr->addLine(*line))
               {
                  if (lineMgr->addCredentialForLine( identity, realm, user, ha1_authenticator
                                                    ,HTTP_DIGEST_AUTHENTICATION
                                                    )
                      )
                  {
                     lineMgr->setDefaultOutboundLine(identity);
                     bSuccess = true;

                     OsSysLog::add(LOG_FACILITY, PRI_INFO,
                                   "Added identity '%s': user='******' realm='%s'"
                                   ,identity.toString().data(), user.data(), realm.data()
                                   );
                  }
                  else
                  {
                     OsSysLog::add(LOG_FACILITY, PRI_CRIT,
                                   "Error adding identity '%s': user='******' realm='%s'\n",
                                   identity.toString().data(), user.data(), realm.data()
                                   );
                  }
               }
               else
               {
                  OsSysLog::add(LOG_FACILITY, PRI_CRIT, "addLine failed" );
               }
            }
            else
            {
               OsSysLog::add(LOG_FACILITY, PRI_CRIT,
                             "Constructing SipLineMgr failed" );
            }
         }
         else
         {
            OsSysLog::add(LOG_FACILITY, PRI_CRIT,
                          "Constructing SipLine failed" );
         }
      }
      else
      {
         OsSysLog::add(LOG_FACILITY, PRI_CRIT,
                       "No credential found for '%s' in realm '%s'"
                       ,identity.toString().data(), realm.data()
                       );
      }

      if( !bSuccess )
      {
         delete line;
         line = NULL;

         delete lineMgr;
         lineMgr = NULL;
      }
   }

   credentialDb->releaseInstance();

   return lineMgr;
}
예제 #9
0
int main(int argc, char* argv[])
{
    int port;
    int expiration;
    char* targetURI;
    char* eventType;
    char* contentType;
    char* realm;
    char* user;
    char* password;

   // Initialize logging.
   OsSysLog::initialize(0, "test");
   OsSysLog::setOutputFile(0, "log");
   OsSysLog::setLoggingPriority(PRI_DEBUG);
   OsSysLog::setLoggingPriorityForFacility(FAC_SIP_INCOMING_PARSED, PRI_ERR);

   if (!parseArgs(argc, argv, &port, &expiration,
                  &targetURI, &eventType, &contentType,
                  &realm, &user, &password))
   {
       usage(argv[0]);
       exit(1);
   }

   // The domain name to call myself, obtained from the gethostname()
   // system call.
   char buffer[100];
   memset(buffer, 0, sizeof (buffer));
   // Do not allow gethostname to write over the last NUL in buffer[].
   gethostname(buffer, (sizeof (buffer)) - 1);
   UtlString myDomainName(buffer, strlen(buffer));
   // Use "example.com" if gethostname() failed.
   if (myDomainName.isNull())
   {
      myDomainName = "example.com";
   }

   UtlString fromString = "sip:dialogwatch@" + myDomainName;
   Url fromUri(fromString, TRUE);

   // Create the SIP Subscribe Client

   SipLineMgr lineMgr;

   // Add credentials if they were specified.
   if (realm)
   {
      UtlString id;
      id += "sip:";
      id += user;
      id += "@";
      id += realm;
      Url identity(id, TRUE);

      SipLine line( fromUri  // user entered url
                   ,identity // identity url
                   ,user     // user
                   ,TRUE     // visible
                   ,SipLine::LINE_STATE_PROVISIONED
                   ,TRUE     // auto enable
                   ,FALSE    // use call handling
         );

      lineMgr.addLine(line);

      UtlString cred_input;
      UtlString cred_digest;

      cred_input.append(user);
      cred_input.append(":");
      cred_input.append(realm);
      cred_input.append(":");
      cred_input.append(password);

      NetMd5Codec::encode(cred_input.data(), cred_digest);

      fprintf(stderr,
              "Adding identity '%s': user='******' realm='%s' password='******' H(A1)='%s'\n",
              identity.toString().data(), user, realm, password, cred_digest.data()
         );

      assert(lineMgr.addCredentialForLine(identity, realm, user, cred_digest,
                                          HTTP_DIGEST_AUTHENTICATION));
   }

   SipUserAgent* pSipUserAgent =
      new SipUserAgent(port, port, PORT_NONE,
                       NULL,
                       NULL,
                       NULL,
                       NULL,
                       NULL,
                       NULL,
                       NULL,
                       NULL,
                       NULL,
                       NULL,
                       NULL,
                       &lineMgr);
   // Add the 'eventlist' extension, so dialogwatch can subscribe to
   // event lists.
   pSipUserAgent->allowExtension("eventlist");
   if (!pSipUserAgent->isOk())
   {
       fprintf(stderr, "Unable to bind to port %d\n", port);
       exit(1);
   }

   SipDialogMgr dialogManager;

   SipRefreshManager refreshMgr(*pSipUserAgent, dialogManager);
   refreshMgr.start();

   SipSubscribeClient sipSubscribeClient(*pSipUserAgent, dialogManager,
                                         refreshMgr);
   sipSubscribeClient.start();

   // Construct a name-addr from targetURI, in case it contains parameters.
   UtlString toUri;
   toUri = "<";
   toUri += targetURI;
   toUri += ">";
   UtlString earlyDialogHandle;

   fprintf(stderr,
           "resourceId '%s' fromString '%s' toUri '%s' event '%s' content-type '%s' port=%d expiration=%d\n",
           targetURI, fromString.data(), toUri.data(), eventType, contentType,
           port, expiration);

   UtlBoolean status =
      sipSubscribeClient.addSubscription(targetURI,
                                         eventType,
                                         contentType,
                                         fromString.data(),
                                         toUri.data(),
                                         NULL,
                                         expiration,
                                         (void *) NULL,
                                         subscriptionStateCallback,
                                         notifyEventCallback,
                                         earlyDialogHandle);

   if (!status)
   {
      fprintf(stderr, "Subscription attempt failed.\n");
      exit(1);
   }
   else
   {
      fprintf(stderr, "Subscription attempt succeeded.  Handle: '%s'\n",
              earlyDialogHandle.data());
   }

   while (1)
   {
      sleep(1000);
   }
}
예제 #10
0
int main(int argc, char* argv[])
{
   const char* configFileName = "siptest-config";
   int proxyTcpPort;
   int proxyUdpPort;
   int proxyTlsPort;
   OsConfigDb configDb;

   // siptest uses osPrintf for output, so we have to un-suppress it.
   enableConsoleOutput(TRUE);

   if(configDb.loadFromFile(configFileName) == OS_SUCCESS)
   {
      osPrintf("Found config file: %s\n", configFileName);
   }
   else
   {
      configDb.set("SIP_TEST_UDP_PORT", "3000");
      configDb.set("SIP_TEST_TCP_PORT", "3000");
      configDb.set("SIP_TEST_TLS_PORT", "3001");

      if(configDb.storeToFile(configFileName) == OS_SUCCESS)
      {
         osPrintf("Could not write config file: %s\n", configFileName);
      }
   }

   proxyUdpPort = configDb.getPort("SIP_TEST_UDP_PORT") ;
   proxyTcpPort = configDb.getPort("SIP_TEST_TCP_PORT") ;
   proxyTlsPort = configDb.getPort("SIP_TEST_TLS_PORT") ;

   UtlBoolean commandStatus = CommandProcessor::COMMAND_SUCCESS;
   char buffer[1024];
   char* commandLine;
   CommandProcessor processor;

   SipLineMgr*    lineMgr = new SipLineMgr();
   SipRefreshMgr* refreshMgr = new SipRefreshMgr();

   lineMgr->StartLineMgr();
   lineMgr->initializeRefreshMgr( refreshMgr );

   SipUserAgent*  sipUA = new SipUserAgent( proxyTcpPort
                                            ,proxyUdpPort
                                            ,proxyTlsPort
                                            ,NULL         // default publicAddress
                                            ,NULL         // default defaultUser
                                            ,NULL         // default defaultSipAddress
                                            ,NULL         // default sipProxyServers
                                            ,NULL         // default sipDirectoryServers
                                            ,NULL         // default sipRegistryServers
                                            ,NULL         // default authenicateRealm
                                            ,NULL         // default authenticateDb
                                            ,NULL         // default authorizeUserIds
                                            ,NULL         // default authorizePasswords
                                            ,lineMgr
      );
   sipUA->allowMethod(SIP_REGISTER_METHOD);
   sipUA->allowMethod(SIP_SUBSCRIBE_METHOD);
   sipUA->allowMethod(SIP_NOTIFY_METHOD);

   sipUA->start();

   sipUA->startMessageLog();
   osPrintf( "SIP logging Started\n" );

   refreshMgr->init( sipUA );

   CommandMsgProcessor* msgProc = new CommandMsgProcessor(sipUA);
   msgProc->start();

   processor.registerCommand("help", new HelpCommand(&processor));
   processor.registerCommand("?", new HelpCommand(&processor));
   processor.registerCommand("history", new HistoryCommand(&processor));
   processor.registerCommand("send", new SipSendCommand(sipUA));
   processor.registerCommand("lsend", new SipLSendCommand());
   processor.registerCommand("get", new HttpGetCommand());
   processor.registerCommand("respond", new RespondCommand(msgProc));
   processor.registerCommand("rt", new RespondTemplate(msgProc));
   processor.registerCommand("rrespond", new ResendResponse(msgProc));
   processor.registerCommand("log", new SipLogCommand(*sipUA));
   processor.registerCommand("auth", new AuthCommand(lineMgr));
   processor.registerCommand("sleep", new SleepCommand());
   processor.registerCommand("quit", new ExitCommand());
   processor.registerCommand("exit", new ExitCommand());

   //Initialization
   UtlBoolean doPrompt = isatty(STDIN_FILENO);

   if ( doPrompt )
   {
      printf("Enter command or help/? for help\n");
      printf("SIPdriver: ");
   }

   for ( commandStatus = CommandProcessor::COMMAND_SUCCESS;
         (   commandStatus < CommandProcessor::COMMAND_FAILED_EXIT
             && commandStatus != CommandProcessor::COMMAND_SUCCESS_EXIT
             && (commandLine = fgets(buffer,1024,stdin))
            );
      )
   {
      //printf("GOT command line:\"%s\"\n", commandLine);
      commandStatus = processor.executeCommand(commandLine);
      //printf("command status: %d exit status: %d\n", commandStatus,
      //CommandProcessor::COMMAND_SUCCESS_EXIT);
      if ( doPrompt )
      {
         printf("SIPdriver: ");
      }
   }

   delete msgProc;
   delete sipUA;

   return CommandProcessor::COMMAND_SUCCESS_EXIT != commandStatus;
}
예제 #11
0
    void testRefreshMgrUATeardown()
    {
        for (int i=0; i<NUM_OF_RUNS; ++i)
        {
            SipLineMgr*    lineMgr = new SipLineMgr();
            SipRefreshMgr* refreshMgr = new SipRefreshMgr();

            lineMgr->startLineMgr();
            lineMgr->initializeRefreshMgr( refreshMgr );

            SipUserAgent* sipUA = new SipUserAgent( 5090
                                                    ,5090
                                                    ,5091
                                                    ,NULL     // default publicAddress
                                                    ,NULL     // default defaultUser
                                                    ,"127.0.0.1" // default defaultSipAddress
                                                    ,NULL     // default sipProxyServers
                                                    ,NULL     // default sipDirectoryServers
                                                    ,NULL     // default sipRegistryServers
                                                    ,NULL     // default authenicateRealm
                                                    ,NULL     // default authenticateDb
                                                    ,NULL     // default authorizeUserIds
                                                    ,NULL     // default authorizePasswords
                                                    ,lineMgr
                                                  );

            sipUA->start();
            refreshMgr->init(sipUA);


            CallManager *pCallManager =
                new CallManager(FALSE,
                                NULL, //LineMgr
                                TRUE, // early media in 180 ringing
                                NULL, // CodecFactory
                                9000, // rtp start
                                9002, // rtp end
                                "sip:[email protected]",
                                "sip:[email protected]",
                                sipUA, //SipUserAgent
                                0, // sipSessionReinviteTimer
                                NULL, // mgcpStackTask
                                NULL, // defaultCallExtension
                                Connection::RING, // availableBehavior
                                NULL, // unconditionalForwardUrl
                                -1, // forwardOnNoAnswerSeconds
                                NULL, // forwardOnNoAnswerUrl
                                Connection::BUSY, // busyBehavior
                                NULL, // sipForwardOnBusyUrl
                                NULL, // speedNums
                                CallManager::SIP_CALL, // phonesetOutgoingCallProtocol
                                4, // numDialPlanDigits
                                CallManager::NEAR_END_HOLD, // holdType
                                5000, // offeringDelay
                                "", // pLocal
                                CP_MAXIMUM_RINGING_EXPIRE_SECONDS, //inviteExpireSeconds
                                QOS_LAYER3_LOW_DELAY_IP_TOS, // expeditedIpTos
                                10, //maxCalls
                                sipXmediaFactoryFactory(NULL)); //pMediaFactory
#if 0
            printf("Starting CallManager\n");
#endif
            pCallManager->start();

            lineMgr->requestShutdown();
            refreshMgr->requestShutdown();
            sipUA->shutdown(TRUE);
            pCallManager->requestShutdown();

#if 0
            printf("Deleting CallManager\n");
#endif

            delete pCallManager;
            delete refreshMgr;
            delete lineMgr;
        }

        for (int i=0; i<NUM_OF_RUNS; ++i)
        {
            sipxDestroyMediaFactoryFactory() ;
        }
    }
예제 #12
0
   void testShutdownBlocking()
   {
      pid_t myPID = OsProcess::getCurrentPID();
      int startingThreads = getNumThreads(myPID);

      // Simple invite message from siptest/src/siptest/invite.txt
      const char* SimpleMessage = 
          "INVITE sip:[email protected] SIP/2.0\r\n"
          "Route: <sip:[email protected]:5064;lr>\r\n"
          "From: <sip:[email protected];user=phone>;tag=bbb\r\n"
          "To: <sip:[email protected]:3000;user=phone>\r\n"
          "Call-Id: 8\r\n"
          "Cseq: 1 INVITE\r\n"
          "Content-Length: 0\r\n"
          "\r\n";

      SipMessage testMsg( SimpleMessage, strlen( SimpleMessage ) );

      for(int i = 0; i < SHUTDOWN_TEST_ITERATIONS; ++i)
      {
         {
            SipLineMgr    lineMgr;
            SipRefreshMgr refreshMgr;

            lineMgr.StartLineMgr();
            lineMgr.initializeRefreshMgr( &refreshMgr );

            SipUserAgent sipUA( 5090
                               ,5090
                               ,5091
                               ,NULL     // default publicAddress
                               ,NULL     // default defaultUser
                               ,"127.0.0.1"     // default defaultSipAddress
                               ,NULL     // default sipProxyServers
                               ,NULL     // default sipDirectoryServers
                               ,NULL     // default sipRegistryServers
                               ,NULL     // default authenticationScheme
                               ,NULL     // default authenicateRealm
                               ,NULL     // default authenticateDb
                               ,NULL     // default authorizeUserIds
                               ,NULL     // default authorizePasswords
                               ,&lineMgr
                               );

            sipUA.start();
            refreshMgr.init(&sipUA);

            sipUA.send(testMsg);

            // Wait long enough for some stack timeouts/retansmits to occur
            OsTask::delay(10000); // 10 seconds

            // Shut down the tasks in reverse order.
            refreshMgr.requestShutdown();
            sipUA.shutdown(TRUE);
            lineMgr.requestShutdown();

            CPPUNIT_ASSERT(sipUA.isShutdownDone());

            OsTimerTask::destroyTimerTask();
            OsStunAgentTask::releaseInstance();
         }
      
         // Test to see that all the threads created by the above operations
         // get properly shut down.
         int numThreads = getNumThreads(myPID);

         OsSysLog::add(FAC_SIP, PRI_NOTICE, "SipUserAgentTest::testShutdownBlocking "
                       "numThreads=%d startingThreads=%d",
                       numThreads, startingThreads);
                       
         KNOWN_BUG("XECS-48", "Some threads are not cleaned up?");
         CPPUNIT_ASSERT(numThreads <= startingThreads);
      }
   };