/[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 10999 - (show annotations) (download)
Sun Feb 23 21:16:40 2014 UTC (5 years, 6 months ago) by sgodin
File MIME type: text/plain
File size: 5832 byte(s)
-implement sleepMs and sleepSeconds api's in Time.hxx and removed the custom implementations around the code 

1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include "resip/stack/SipStack.hxx"
6 #include "resip/dum/ClientAuthManager.hxx"
7 #include "resip/dum/ClientRegistration.hxx"
8 #include "resip/dum/DialogUsageManager.hxx"
9 #include "resip/dum/MasterProfile.hxx"
10 #include "resip/dum/RegistrationHandler.hxx"
11 #include "rutil/Time.hxx"
12 #include "rutil/Log.hxx"
13 #include "rutil/Logger.hxx"
14 #include "rutil/Subsystem.hxx"
15 #include "resip/dum/KeepAliveManager.hxx"
16
17 #if defined (USE_SSL)
18 #if defined(WIN32)
19 #include "resip/stack/ssl/WinSecurity.hxx"
20 #else
21 #include "resip/stack/ssl/Security.hxx"
22 #endif
23 #endif
24
25 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
26
27 using namespace resip;
28 using namespace std;
29
30 class ClientHandler : public ClientRegistrationHandler
31 {
32 public:
33 ClientHandler() : done(false) {}
34
35 virtual void onSuccess(ClientRegistrationHandle h, const SipMessage& response)
36 {
37 InfoLog( << "ClientHandler::onSuccess: " << endl );
38
39 resipCerr << "Pausing before unregister" << endl;
40
41 sleepMs(2000);
42 h->removeAll();
43 }
44
45 virtual void onRemoved(ClientRegistrationHandle, const SipMessage& response)
46 {
47 InfoLog ( << "ClientHandler::onRemoved ");
48 done = true;
49 }
50
51 virtual void onFailure(ClientRegistrationHandle, const SipMessage& response)
52 {
53 InfoLog ( << "ClientHandler::onFailure: " << response );
54 }
55
56 virtual int onRequestRetry(ClientRegistrationHandle, int retrySeconds, const SipMessage& response)
57 {
58 InfoLog ( << "ClientHandler:onRequestRetry");
59 return -1;
60 }
61
62 bool done;
63 };
64
65
66
67 int
68 main (int argc, char** argv)
69 {
70
71 if ( argc < 3 ) {
72 resipCout << "usage: " << argv[0] << " sip:user passwd\n";
73 return 0;
74 }
75
76 Log::initialize(Log::Cout, Log::Stack, argv[0]);
77
78 NameAddr userAor(argv[1]);
79 Data passwd(argv[2]);
80
81 #ifdef USE_SSL
82 #ifdef WIN32
83 Security* security = new WinSecurity;
84 #else
85 Security* security = new Security;
86 #endif
87 SipStack stack(security);
88 #else
89 SipStack stack;
90 #endif
91
92 DialogUsageManager clientDum(stack);
93 SharedPtr<MasterProfile> profile(new MasterProfile);
94 auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager);
95 ClientHandler clientHandler;
96
97 stack.addTransport(UDP, 0, V4);
98 // stack.addTransport(UDP, 0, V6);
99 stack.addTransport(TCP, 0, V4);
100 // stack.addTransport(TCP, 0, V6);
101 #ifdef USE_SSL
102 stack.addTransport(TLS, 0, V4);
103 // stack.addTransport(TLS, 0, V6);
104 #endif
105 clientDum.setMasterProfile(profile);
106 clientDum.setClientRegistrationHandler(&clientHandler);
107 clientDum.setClientAuthManager(clientAuth);
108 clientDum.getMasterProfile()->setDefaultRegistrationTime(70);
109
110 // keep alive test.
111 auto_ptr<KeepAliveManager> keepAlive(new KeepAliveManager);
112 clientDum.setKeepAliveManager(keepAlive);
113
114 clientDum.getMasterProfile()->setDefaultFrom(userAor);
115 profile->setDigestCredential(userAor.uri().host(),
116 userAor.uri().user(),
117 passwd);
118
119 SharedPtr<SipMessage> regMessage = clientDum.makeRegistration(userAor);
120 NameAddr contact;
121
122 clientDum.send( regMessage );
123
124 int n = 0;
125 while ( !clientHandler.done )
126 {
127 stack.process(100);
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 native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.26