/[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 4781 - (show annotations) (download)
Mon May 30 16:35:33 2005 UTC (14 years, 5 months ago) by sgodin
File size: 6013 byte(s)
modified to work with new ShartPtr management of Master/UserProfiles
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/MasterProfile.hxx"
6 #include "resiprocate/dum/RegistrationHandler.hxx"
7 #include "resiprocate/os/Log.hxx"
8 #include "resiprocate/os/Logger.hxx"
9 #include "resiprocate/os/Subsystem.hxx"
10 #include "resiprocate/dum/KeepAliveManager.hxx"
11
12 #ifdef WIN32
13 #include "resiprocate/WinSecurity.hxx"
14 #endif
15
16 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
17
18 using namespace resip;
19 using namespace std;
20
21 class ClientHandler : public ClientRegistrationHandler
22 {
23 public:
24 ClientHandler() : done(false) {}
25
26 virtual void onSuccess(ClientRegistrationHandle h, const SipMessage& response)
27 {
28 InfoLog( << "ClientHandler::onSuccess: " << endl );
29
30 cerr << "Pausing before unregister" << endl;
31
32 #ifdef WIN32
33 Sleep(2000);
34 #else
35 sleep(5);
36 #endif
37 h->removeAll();
38 }
39
40 virtual void onRemoved(ClientRegistrationHandle)
41 {
42 InfoLog ( << "ClientHandler::onRemoved ");
43 done = true;
44 }
45
46 virtual void onFailure(ClientRegistrationHandle, const SipMessage& response)
47 {
48 InfoLog ( << "ClientHandler::onFailure: " << response );
49 }
50
51 virtual int onRequestRetry(ClientRegistrationHandle, int retrySeconds, const SipMessage& response)
52 {
53 InfoLog ( << "ClientHandler:onRequestRetry");
54 return -1;
55 }
56
57 bool done;
58 };
59
60
61
62 int
63 main (int argc, char** argv)
64 {
65
66 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 NameAddr userAor(argv[1]);
74 Data passwd(argv[2]);
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;
85 #endif
86 #endif
87
88 DialogUsageManager clientDum(stack);
89 SharedPtr<MasterProfile> profile(new MasterProfile);
90 auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager);
91 ClientHandler clientHandler;
92
93 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);
102 clientDum.getMasterProfile()->setDefaultRegistrationTime(70);
103
104 // keep alive test.
105 auto_ptr<KeepAliveManager> keepAlive(new KeepAliveManager);
106 clientDum.setKeepAliveManager(keepAlive);
107
108 clientDum.getMasterProfile()->setDefaultFrom(userAor);
109 profile->setDigestCredential(userAor.uri().host(),
110 userAor.uri().user(),
111 passwd);
112
113 SipMessage & regMessage = clientDum.makeRegistration(userAor);
114 NameAddr contact;
115
116 clientDum.send( regMessage );
117
118 int n = 0;
119 while ( !clientHandler.done )
120 {
121 FdSet fdset;
122
123 stack.buildFdSet(fdset);
124 int err = fdset.selectMilliSeconds(100);
125 assert ( err != -1 );
126
127 stack.process(fdset);
128 while(clientDum.process());
129
130 if (n == 1000) clientHandler.done = true;
131
132 if (!(n++ % 10)) cerr << "|/-\\"[(n/10)%4] << '\b';
133 }
134 return 0;
135 }
136
137 /* ====================================================================
138 * The Vovida Software License, Version 1.0
139 *
140 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
141 *
142 * Redistribution and use in source and binary forms, with or without
143 * modification, are permitted provided that the following conditions
144 * are met:
145 *
146 * 1. Redistributions of source code must retain the above copyright
147 * notice, this list of conditions and the following disclaimer.
148 *
149 * 2. Redistributions in binary form must reproduce the above copyright
150 * notice, this list of conditions and the following disclaimer in
151 * the documentation and/or other materials provided with the
152 * distribution.
153 *
154 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
155 * and "Vovida Open Communication Application Library (VOCAL)" must
156 * not be used to endorse or promote products derived from this
157 * software without prior written permission. For written
158 * permission, please contact vocal@vovida.org.
159 *
160 * 4. Products derived from this software may not be called "VOCAL", nor
161 * may "VOCAL" appear in their name, without prior written
162 * permission of Vovida Networks, Inc.
163 *
164 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
165 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
166 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
167 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
168 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
169 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
170 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
171 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
172 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
173 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
174 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
175 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
176 * DAMAGE.
177 *
178 * ====================================================================
179 *
180 * This software consists of voluntary contributions made by Vovida
181 * Networks, Inc. and many individuals on behalf of Vovida Networks,
182 * Inc. For more information on Vovida Networks, Inc., please see
183 * <http://www.vovida.org/>.
184 *
185 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27