reSIProcate/DialogUsageManager  9694
Classes | Defines | Functions
testIdentity.cxx File Reference
#include "resip/dum/ClientAuthManager.hxx"
#include "resip/dum/ClientRegistration.hxx"
#include "resip/dum/DialogUsageManager.hxx"
#include "resip/dum/MasterProfile.hxx"
#include "resip/dum/Profile.hxx"
#include "resip/dum/UserProfile.hxx"
#include "resip/dum/RegistrationHandler.hxx"
#include "resip/dum/ClientPagerMessage.hxx"
#include "resip/dum/ServerPagerMessage.hxx"
#include "resip/dum/AppDialogSet.hxx"
#include "resip/dum/AppDialog.hxx"
#include "resip/dum/PagerMessageHandler.hxx"
#include "resip/stack/PlainContents.hxx"
#include "resip/stack/external/HttpGetMessage.hxx"
#include "curlHttp/CurlHttpProvider.hxx"
#include "rutil/Log.hxx"
#include "rutil/Logger.hxx"
#include "rutil/Subsystem.hxx"
#include <iostream>
#include <string>
#include <sstream>
Include dependency graph for testIdentity.cxx:

Go to the source code of this file.

Classes

class  TestIdentityHandler

Defines

#define RESIPROCATE_SUBSYSTEM   Subsystem::TEST

Functions

int main (int argc, char *argv[])

Define Documentation

#define RESIPROCATE_SUBSYSTEM   Subsystem::TEST

Definition at line 36 of file testIdentity.cxx.


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 131 of file testIdentity.cxx.

References resip::DialogUsageManager::addTransport(), resip::SipStack::buildFdSet(), resip::Handle< T >::get(), resip::DialogUsageManager::getMasterProfile(), resip::Uri::host(), InfoLog, TestIdentityHandler::isEnded(), TestIdentityHandler::isRcvd(), TestIdentityHandler::isRegistered(), resip::DialogUsageManager::makePagerMessage(), resip::DialogUsageManager::makeRegistration(), resip::SipStack::process(), resip::DialogUsageManager::process(), resip::FdSet::selectMilliSeconds(), resip::DialogUsageManager::send(), resip::DialogUsageManager::setClientAuthManager(), resip::DialogUsageManager::setClientPagerMessageHandler(), resip::DialogUsageManager::setClientRegistrationHandler(), resip::DialogUsageManager::setMasterProfile(), resip::DialogUsageManager::setServerPagerMessageHandler(), TCP, TLS, UDP, resip::NameAddr::uri(), resip::Uri::user(), and V4.

{

   if ( argc < 3 ) {
      cout << "usage: " << argv[0] << " sip:user passwd\n";
      return 0;
   }

   Log::initialize(Log::Cout, Log::Debug, argv[0]);

   HttpProvider::setFactory(
      std::auto_ptr<HttpProviderFactory>(new CurlHttpProviderFactory()));

   bool first = true;
   NameAddr userAor(argv[1]);
   Data passwd(argv[2]);

   InfoLog(<< "user: " << userAor << ", passwd: " << passwd << "\n");

#ifdef WIN32
   WinSecurity* security = new WinSecurity;
#else
   Security* security = new Security;
#endif

   assert( security );

   SipStack clientStack(security);
   DialogUsageManager clientDum(clientStack);
   clientDum.addTransport(UDP, 0, V4);
   clientDum.addTransport(TCP, 0, V4);
   clientDum.addTransport(TLS, 0, V4);
   // clientDum.addTransport(UDP, 0, V6);
   // clientDum.addTransport(TCP, 0, V6);
   // clientDum.addTransport(TLS, 0, V6);

   SharedPtr<MasterProfile> clientProfile(new MasterProfile);   
   auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager());   
   TestIdentityHandler clientHandler;

   clientDum.setMasterProfile(clientProfile);
   clientDum.setClientAuthManager(clientAuth);
   clientDum.setClientRegistrationHandler(&clientHandler);
   clientDum.setClientPagerMessageHandler(&clientHandler);
   clientDum.setServerPagerMessageHandler(&clientHandler);
   clientDum.getMasterProfile()->setDefaultRegistrationTime(70);                
   clientDum.getMasterProfile()->addSupportedMethod(MESSAGE);
   clientDum.getMasterProfile()->addSupportedMimeType(MESSAGE, Mime("text", "plain"));

   clientProfile->setDefaultFrom(userAor);

   InfoLog( << userAor.uri().host() << " " << userAor.uri().user() 
            << " " << passwd );

   clientProfile->setDigestCredential(userAor.uri().host(),
                                     userAor.uri().user(),
                                     passwd);
        
   SipMessage & regMessage = clientDum.makeRegistration(userAor);
        
   InfoLog( << regMessage << "Generated register: " << endl << regMessage );
   clientDum.send( regMessage );

   while (!clientHandler.isEnded() || !clientHandler.isRcvd() )
   {
      FdSet fdset;

      // Should these be buildFdSet on the DUM?
      clientStack.buildFdSet(fdset);
      int err = fdset.selectMilliSeconds(100);
      assert ( err != -1 );
      
      clientStack.process(fdset);
      while(clientDum.process());
      //if (!(n++ % 10)) cerr << "|/-\\"[(n/10)%4] << '\b';
                
      if (first && clientHandler.isRegistered()) {
         first = false;
         InfoLog( << "client registered!!\n" );
         InfoLog( << "Sending MESSAGE\n" );
         ClientPagerMessageHandle cpmh = clientDum.makePagerMessage(userAor);                   
         auto_ptr<Contents> content(new PlainContents(Data("message")));
         cpmh.get()->page(content); 
      }
   } 

   return 0;
}

Here is the call graph for this function: