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

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