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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2991 - (show annotations) (download)
Tue Jun 15 08:09:24 2004 UTC (15 years, 7 months ago) by derek
Original Path: main/sip/resiprocate/dum/test/basicRegister.cxx
File size: 3938 byte(s)
moved ClientAuthManager related logic to Dialog instead of DialogSet

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

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27