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

Contents of /main/sip/resiprocate/dum/test/basicRegister.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4601 - (show annotations) (download)
Thu May 12 01:10:49 2005 UTC (14 years, 6 months ago) by derek
File size: 4100 byte(s)
merged identity branch(4598) into main--removing identity branch after this
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/MasterProfile.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 using namespace std;
19
20 class RegisterAppDialogSet : public AppDialogSet
21 {
22 public:
23 RegisterAppDialogSet(DialogUsageManager& dum) : AppDialogSet(dum)
24 {}
25 };
26
27
28
29 class Client : public ClientRegistrationHandler
30 {
31 public:
32 Client() : done(false), removing(true) {}
33
34 virtual void onSuccess(ClientRegistrationHandle h, const SipMessage& response)
35 {
36 InfoLog( << "Client::Success: " << endl << response );
37 if (removing)
38 {
39 removing = false;
40 #ifdef WIN32
41 Sleep(2000);
42 #else
43 sleep(5);
44 #endif
45 //ClientRegistration* foo = h.get();
46 h->removeAll();
47 }
48 else
49 {
50 done = true;
51 }
52 }
53
54 virtual void onRemoved(ClientRegistrationHandle)
55 {
56 InfoLog ( << "Client::onRemoved ");
57 }
58
59 virtual void onFailure(ClientRegistrationHandle, const SipMessage& response)
60 {
61 InfoLog ( << "Client::onFailure: " << response );
62 done = true;
63 }
64
65 virtual int onRequestRetry(ClientRegistrationHandle, int retrySeconds, const SipMessage& response)
66 {
67 return 0;
68 }
69
70
71 bool done;
72 bool removing;
73 };
74
75 /*
76 class RegistrationServer : public ServerRegistrationHandler
77 {
78 public:
79 RegistrationServer() : done(false) {}
80 virtual void onRefresh(ServerRegistrationHandle, const SipMessage& reg)=0;
81
82 /// called when one of the contacts is removed
83 virtual void onRemoveOne(ServerRegistrationHandle, const SipMessage& reg)=0;
84
85 /// Called when all the contacts are removed
86 virtual void onRemoveAll(ServerRegistrationHandle, const SipMessage& reg)=0;
87
88 /// Called when a new contact is added. This is after authentication has
89 /// all sucseeded
90 virtual void onAdd(ServerRegistrationHandle, const SipMessage& reg)=0;
91
92 /// Called when an registration expires
93 virtual void onExpired(ServerRegistrationHandle, const NameAddr& contact)=0;
94
95 private:
96 bool done;
97 };
98 */
99
100 int
101 main (int argc, char** argv)
102 {
103 int level=(int)Log::Debug;
104 if (argc >1 ) level = atoi(argv[1]);
105
106 Log::initialize(Log::Cout, (resip::Log::Level)level, argv[0]);
107
108 Client client;
109 MasterProfile profile;
110 auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager);
111
112 SipStack stack;
113 DialogUsageManager clientDum(stack);
114 clientDum.addTransport(UDP, 15066);
115 clientDum.setMasterProfile(&profile);
116
117 clientDum.setClientRegistrationHandler(&client);
118 clientDum.setClientAuthManager(clientAuth);
119 clientDum.getMasterProfile()->setDefaultRegistrationTime(70);
120
121 NameAddr from("sip:derek@foo.net");
122 clientDum.getMasterProfile()->setDefaultFrom(from);
123
124
125 profile.setDigestCredential( "foo.net", "derek", "derek");
126
127
128 SipMessage & regMessage = clientDum.makeRegistration(from, new RegisterAppDialogSet(clientDum));
129 NameAddr contact;
130 // contact.uri().user() = "13015604286";
131 // regMessage.header(h_Contacts).push_back(contact);
132
133 InfoLog( << regMessage << "Generated register: " << endl << regMessage );
134 clientDum.send( regMessage );
135
136 int n = 0;
137 while ( !client.done )
138
139 {
140 FdSet fdset;
141
142 stack.buildFdSet(fdset);
143 int err = fdset.selectMilliSeconds(100);
144 assert ( err != -1 );
145
146 stack.process(fdset);
147 while(clientDum.process());
148
149 if (!(n++ % 10)) cerr << "|/-\\"[(n/10)%4] << '\b';
150 }
151 return 0;
152 }

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27