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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3608 - (hide annotations) (download)
Tue Nov 23 21:18:26 2004 UTC (15 years ago) by sgodin
Original Path: main/sip/resiprocate/dum/test/basicRegister.cxx
File size: 4070 byte(s)
fixes for new multi-profile/identity stuff
1 jason 2941 #include "resiprocate/SipStack.hxx"
2     #include "resiprocate/dum/ClientAuthManager.hxx"
3     #include "resiprocate/dum/ClientRegistration.hxx"
4     #include "resiprocate/dum/DialogUsageManager.hxx"
5 derek 2850 #include "resiprocate/dum/InviteSessionHandler.hxx"
6 sgodin 3608 #include "resiprocate/dum/MasterProfile.hxx"
7 derek 2850 #include "resiprocate/dum/RegistrationHandler.hxx"
8 alan 2861 #include "resiprocate/os/Log.hxx"
9 alan 2906 #include "resiprocate/os/Logger.hxx"
10     #include "resiprocate/os/Subsystem.hxx"
11 derek 2955 #include "resiprocate/dum/AppDialogSet.hxx"
12     #include "resiprocate/dum/AppDialog.hxx"
13 derek 2850
14 derek 2955
15 alan 2906 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
16    
17 derek 2850 using namespace resip;
18    
19 derek 2955 class RegisterAppDialogSet : public AppDialogSet
20     {
21     public:
22     RegisterAppDialogSet(DialogUsageManager& dum) : AppDialogSet(dum)
23     {}
24     };
25    
26    
27    
28 derek 2850 class Client : public ClientRegistrationHandler
29     {
30     public:
31 derek 2984 Client() : done(false), removing(true) {}
32 derek 2850
33 jason 2941 virtual void onSuccess(ClientRegistrationHandle h, const SipMessage& response)
34 derek 2850 {
35 derek 2984 InfoLog( << "Client::Success: " << endl << response );
36     if (removing)
37     {
38     removing = false;
39 derek 2929 #ifdef WIN32
40     Sleep(2000);
41     #else
42     sleep(5);
43     #endif
44 jason 3150 ClientRegistration* foo = h.get();
45 derek 2929 h->removeAll();
46 derek 2984 }
47     else
48     {
49     done = true;
50     }
51 derek 2850 }
52    
53 sgodin 3458 virtual void onRemoved(ClientRegistrationHandle)
54     {
55     InfoLog ( << "Client::onRemoved ");
56     }
57    
58 jason 2941 virtual void onFailure(ClientRegistrationHandle, const SipMessage& response)
59 derek 2850 {
60 sgodin 3458 InfoLog ( << "Client::onFailure: " << response );
61 derek 2929 done = true;
62 derek 2850 }
63 alan 2906
64 derek 2850 bool done;
65 derek 2984 bool removing;
66 derek 2850 };
67    
68     /*
69     class RegistrationServer : public ServerRegistrationHandler
70     {
71     public:
72     RegistrationServer() : done(false) {}
73 jason 2941 virtual void onRefresh(ServerRegistrationHandle, const SipMessage& reg)=0;
74 derek 2850
75     /// called when one of the contacts is removed
76 jason 2941 virtual void onRemoveOne(ServerRegistrationHandle, const SipMessage& reg)=0;
77 derek 2850
78     /// Called when all the contacts are removed
79 jason 2941 virtual void onRemoveAll(ServerRegistrationHandle, const SipMessage& reg)=0;
80 derek 2850
81     /// Called when a new contact is added. This is after authentication has
82     /// all sucseeded
83 jason 2941 virtual void onAdd(ServerRegistrationHandle, const SipMessage& reg)=0;
84 derek 2850
85     /// Called when an registration expires
86 jason 2941 virtual void onExpired(ServerRegistrationHandle, const NameAddr& contact)=0;
87 derek 2850 private:
88     bool done;
89     };
90     */
91    
92     int
93     main (int argc, char** argv)
94     {
95 sgodin 3458 int level=(int)Log::Info;
96     if (argc >1 ) level = atoi(argv[1]);
97 alan 2877
98 sgodin 3458 Log::initialize(Log::Cout, (resip::Log::Level)level, argv[0]);
99 alan 2877
100 derek 2850 Client client;
101 sgodin 3608 MasterProfile profile;
102     auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager);
103 derek 2929
104 sgodin 3458 DialogUsageManager clientDum;
105     clientDum.addTransport(UDP, 15060);
106 sgodin 3608 clientDum.setMasterProfile(&profile);
107 alan 2895
108 derek 2850 clientDum.setClientRegistrationHandler(&client);
109 sgodin 3458 clientDum.setClientAuthManager(clientAuth);
110 sgodin 3608 clientDum.getMasterProfile()->setDefaultRegistrationTime(70);
111 derek 2991
112 jason 3150 NameAddr from("sip:101@proxy.internal.xten.net");
113 sgodin 3608 clientDum.getMasterProfile()->setDefaultFrom(from);
114 alan 2877
115 derek 2991
116     // profile.addDigestCredential( "xten.gloo.net", "derek@xten.gloo.net", "123456" );
117 derek 2984 // profile.addDigestCredential( "sphone.vopr.vonage.net", "13015604286", "" );
118 fluffy 2882
119 jason 3150 SipMessage & regMessage = clientDum.makeRegistration(from, new RegisterAppDialogSet(clientDum));
120 derek 2984 NameAddr contact;
121 derek 2991 // contact.uri().user() = "13015604286";
122     // regMessage.header(h_Contacts).push_back(contact);
123 alan 2877
124 alan 2906 InfoLog( << regMessage << "Generated register: " << endl << regMessage );
125 fluffy 2870 clientDum.send( regMessage );
126 alan 2877
127     int n = 0;
128     while ( !client.done )
129    
130 derek 2850 {
131     FdSet fdset;
132 fluffy 2870
133 alan 2877 // Should these be buildFdSet on the DUM?
134 derek 2984 clientDum.buildFdSet(fdset);
135 derek 2850 int err = fdset.selectMilliSeconds(100);
136     assert ( err != -1 );
137 alan 2877
138     clientDum.process(fdset);
139     if (!(n++ % 10)) cerr << "|/-\\"[(n/10)%4] << '\b';
140    
141 derek 2850 }
142 derek 2984 return 0;
143 derek 2850 }

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27