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

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27