/[resiprocate]/main/resip/dum/test/basicRegister.cxx
ViewVC logotype

Diff of /main/resip/dum/test/basicRegister.cxx

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4602 by derek, Thu May 12 01:27:52 2005 UTC revision 4740 by daniel, Tue May 24 21:30:57 2005 UTC
# Line 2  Line 2 
2  #include "resiprocate/dum/ClientAuthManager.hxx"  #include "resiprocate/dum/ClientAuthManager.hxx"
3  #include "resiprocate/dum/ClientRegistration.hxx"  #include "resiprocate/dum/ClientRegistration.hxx"
4  #include "resiprocate/dum/DialogUsageManager.hxx"  #include "resiprocate/dum/DialogUsageManager.hxx"
 #include "resiprocate/dum/InviteSessionHandler.hxx"  
5  #include "resiprocate/dum/MasterProfile.hxx"  #include "resiprocate/dum/MasterProfile.hxx"
6  #include "resiprocate/dum/RegistrationHandler.hxx"  #include "resiprocate/dum/RegistrationHandler.hxx"
7  #include "resiprocate/os/Log.hxx"  #include "resiprocate/os/Log.hxx"
8  #include "resiprocate/os/Logger.hxx"  #include "resiprocate/os/Logger.hxx"
9  #include "resiprocate/os/Subsystem.hxx"  #include "resiprocate/os/Subsystem.hxx"
10  #include "resiprocate/dum/AppDialogSet.hxx"  #include "resiprocate/dum/KeepAliveManager.hxx"
 #include "resiprocate/dum/AppDialog.hxx"  
11    
12    #ifdef WIN32
13    #include "resiprocate/WinSecurity.hxx"
14    #endif
15    
16  #define RESIPROCATE_SUBSYSTEM Subsystem::TEST  #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
17    
18  using namespace resip;  using namespace resip;
19  using namespace std;  using namespace std;
20    
21  class RegisterAppDialogSet : public AppDialogSet  class ClientHandler : public ClientRegistrationHandler
 {  
    public:  
       RegisterAppDialogSet(DialogUsageManager& dum) : AppDialogSet(dum)  
       {}        
 };  
   
     
   
 class Client : public ClientRegistrationHandler  
22  {  {
23     public:     public:
24        Client() : done(false), removing(true) {}        ClientHandler() : done(false) {}
25    
26        virtual void onSuccess(ClientRegistrationHandle h, const SipMessage& response)        virtual void onSuccess(ClientRegistrationHandle h, const SipMessage& response)
27        {        {
28           InfoLog( << "Client::Success: " << endl << response );           InfoLog( << "ClientHandler::onSuccess: " << endl );
29           if (removing)  
30           {           cerr << "Pausing before unregister" << endl;
31              removing = false;                      
32  #ifdef WIN32  #ifdef WIN32
33              Sleep(2000);              Sleep(2000);
34  #else  #else
35              sleep(5);              sleep(5);
36  #endif  #endif
             //ClientRegistration* foo = h.get();            
37              h->removeAll();              h->removeAll();
38           }           }
          else  
          {              
             done = true;  
          }            
       }  
39    
40        virtual void onRemoved(ClientRegistrationHandle)        virtual void onRemoved(ClientRegistrationHandle)
41        {        {
42           InfoLog ( << "Client::onRemoved ");           InfoLog ( << "ClientHandler::onRemoved ");
43             done = true;
44        }        }
45    
46        virtual void onFailure(ClientRegistrationHandle, const SipMessage& response)        virtual void onFailure(ClientRegistrationHandle, const SipMessage& response)
47        {        {
48           InfoLog ( << "Client::onFailure: " << response );           InfoLog ( << "ClientHandler::onFailure: " << response );
          done = true;  
49        }        }
50    
51        virtual int onRequestRetry(ClientRegistrationHandle, int retrySeconds, const SipMessage& response)        virtual int onRequestRetry(ClientRegistrationHandle, int retrySeconds, const SipMessage& response)
52        {        {
53           return 0;           InfoLog ( << "ClientHandler:onRequestRetry");
54             return -1;
55        }        }
56                
   
57        bool done;        bool done;
       bool removing;        
58  };  };
59    
 /*  
   class RegistrationServer : public ServerRegistrationHandler  
   {  
   public:  
   RegistrationServer() : done(false) {}  
   virtual void onRefresh(ServerRegistrationHandle, const SipMessage& reg)=0;  
         
   /// called when one of the contacts is removed  
   virtual void onRemoveOne(ServerRegistrationHandle, const SipMessage& reg)=0;  
         
   /// Called when all the contacts are removed  
   virtual void onRemoveAll(ServerRegistrationHandle, const SipMessage& reg)=0;  
         
   /// Called when a new contact is added. This is after authentication has  
   /// all sucseeded  
   virtual void onAdd(ServerRegistrationHandle, const SipMessage& reg)=0;  
60    
   /// Called when an registration expires  
   virtual void onExpired(ServerRegistrationHandle, const NameAddr& contact)=0;  
         
   private:  
   bool done;  
   };  
 */  
61    
62  int  int
63  main (int argc, char** argv)  main (int argc, char** argv)
64  {  {
    int level=(int)Log::Debug;  
    if (argc >1 ) level = atoi(argv[1]);  
65    
66     Log::initialize(Log::Cout, (resip::Log::Level)level, argv[0]);     if ( argc < 3 ) {
67          cout << "usage: " << argv[0] << " sip:user passwd\n";
68          return 0;
69       }
70    
71       Log::initialize(Log::Cout, Log::Stack, argv[0]);
72    
73     Client client;     NameAddr userAor(argv[1]);
74     MasterProfile profile;       Data passwd(argv[2]);
    auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager);    
75    
76    #ifdef WIN32
77       WinSecurity* security = new WinSecurity;
78       SipStack stack(security);
79    #else
80    #ifdef USE_SSL
81       Security* security = new Security;
82       SipStack stack(security);
83    #else
84     SipStack stack;     SipStack stack;
85    #endif
86    #endif
87    
88     DialogUsageManager clientDum(stack);     DialogUsageManager clientDum(stack);
89     clientDum.addTransport(UDP, 15066);     MasterProfile profile;  
90     clientDum.setMasterProfile(&profile);     auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager);  
91       ClientHandler clientHandler;
92    
93     clientDum.setClientRegistrationHandler(&client);     clientDum.addTransport(UDP, 10000 + rand()&0x7fff, V4);
94       // clientDum.addTransport(UDP, 10000 + rand()&0x7fff, V6);
95       clientDum.addTransport(TCP, 10000 + rand()&0x7fff, V4);
96       // clientDum.addTransport(TCP, 10000 + rand()&0x7fff, V6);
97       clientDum.addTransport(TLS, 10000 + rand()&0x7fff, V4);
98       // clientDum.addTransport(TLS, 10000 + rand()&0x7fff, V6);
99       clientDum.setMasterProfile(&profile);
100       clientDum.setClientRegistrationHandler(&clientHandler);
101     clientDum.setClientAuthManager(clientAuth);     clientDum.setClientAuthManager(clientAuth);
102     clientDum.getMasterProfile()->setDefaultRegistrationTime(70);     clientDum.getMasterProfile()->setDefaultRegistrationTime(70);
103    
104     NameAddr from("sip:derek@foo.net");     // keep alive test.
105     clientDum.getMasterProfile()->setDefaultFrom(from);     auto_ptr<KeepAliveManager> keepAlive(new KeepAliveManager);
106       clientDum.setKeepAliveManager(keepAlive);
107    
108     profile.setDigestCredential( "foo.net", "derek", "derek");     clientDum.getMasterProfile()->setDefaultFrom(userAor);
109       profile.setDigestCredential(userAor.uri().host(),
110                                         userAor.uri().user(),
111                                         passwd);
112        
113       SipMessage & regMessage = clientDum.makeRegistration(userAor);
    SipMessage & regMessage = clientDum.makeRegistration(from, new RegisterAppDialogSet(clientDum));  
114     NameAddr contact;     NameAddr contact;
 //   contact.uri().user() = "13015604286";    
 //   regMessage.header(h_Contacts).push_back(contact);    
115    
    InfoLog( << regMessage << "Generated register: " << endl << regMessage );  
116     clientDum.send( regMessage );     clientDum.send( regMessage );
117    
118     int n = 0;     int n = 0;
119     while ( !client.done )     while ( !clientHandler.done )
   
120     {     {
121        FdSet fdset;        FdSet fdset;
122    
# Line 146  Line 127 
127        stack.process(fdset);        stack.process(fdset);
128        while(clientDum.process());        while(clientDum.process());
129    
130          if (n == 1000) clientHandler.done = true;
131    
132        if (!(n++ % 10)) cerr << "|/-\\"[(n/10)%4] << '\b';        if (!(n++ % 10)) cerr << "|/-\\"[(n/10)%4] << '\b';
133     }       }  
134     return 0;     return 0;

Legend:
Removed from v.4602  
changed lines
  Added in v.4740

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27