/[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 8228 - (show annotations) (download)
Tue Sep 23 08:30:37 2008 UTC (11 years, 2 months ago) by bcampen
File MIME type: text/plain
File size: 6018 byte(s)
Merge work from b-bwc-define_cleanup.

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(WIN32) && defined (USE_SSL)
13 #include "resip/stack/ssl/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 resipCerr << "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, const SipMessage& response)
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 resipCout << "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 USE_SSL
77 #ifdef WIN32
78 Security* security = new WinSecurity;
79 #else
80 Security* security = new Security;
81 #endif
82 SipStack stack(security);
83 #else
84 SipStack stack;
85 #endif
86
87 DialogUsageManager clientDum(stack);
88 SharedPtr<MasterProfile> profile(new MasterProfile);
89 auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager);
90 ClientHandler clientHandler;
91
92 clientDum.addTransport(UDP, 10000 + rand()&0x7fff, V4);
93 // clientDum.addTransport(UDP, 10000 + rand()&0x7fff, V6);
94 clientDum.addTransport(TCP, 10000 + rand()&0x7fff, V4);
95 // clientDum.addTransport(TCP, 10000 + rand()&0x7fff, V6);
96 #ifdef USE_SSL
97 clientDum.addTransport(TLS, 10000 + rand()&0x7fff, V4);
98 // clientDum.addTransport(TLS, 10000 + rand()&0x7fff, V6);
99 #endif
100 clientDum.setMasterProfile(profile);
101 clientDum.setClientRegistrationHandler(&clientHandler);
102 clientDum.setClientAuthManager(clientAuth);
103 clientDum.getMasterProfile()->setDefaultRegistrationTime(70);
104
105 // keep alive test.
106 auto_ptr<KeepAliveManager> keepAlive(new KeepAliveManager);
107 clientDum.setKeepAliveManager(keepAlive);
108
109 clientDum.getMasterProfile()->setDefaultFrom(userAor);
110 profile->setDigestCredential(userAor.uri().host(),
111 userAor.uri().user(),
112 passwd);
113
114 SharedPtr<SipMessage> regMessage = clientDum.makeRegistration(userAor);
115 NameAddr contact;
116
117 clientDum.send( regMessage );
118
119 int n = 0;
120 while ( !clientHandler.done )
121 {
122 FdSet fdset;
123
124 stack.buildFdSet(fdset);
125 int err = fdset.selectMilliSeconds(100);
126 assert ( err != -1 );
127
128 stack.process(fdset);
129 while(clientDum.process());
130
131 if (n == 1000) clientHandler.done = true;
132
133 if (!(n++ % 10)) cerr << "|/-\\"[(n/10)%4] << '\b';
134 }
135 return 0;
136 }
137
138 /* ====================================================================
139 * The Vovida Software License, Version 1.0
140 *
141 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
142 *
143 * Redistribution and use in source and binary forms, with or without
144 * modification, are permitted provided that the following conditions
145 * are met:
146 *
147 * 1. Redistributions of source code must retain the above copyright
148 * notice, this list of conditions and the following disclaimer.
149 *
150 * 2. Redistributions in binary form must reproduce the above copyright
151 * notice, this list of conditions and the following disclaimer in
152 * the documentation and/or other materials provided with the
153 * distribution.
154 *
155 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
156 * and "Vovida Open Communication Application Library (VOCAL)" must
157 * not be used to endorse or promote products derived from this
158 * software without prior written permission. For written
159 * permission, please contact vocal@vovida.org.
160 *
161 * 4. Products derived from this software may not be called "VOCAL", nor
162 * may "VOCAL" appear in their name, without prior written
163 * permission of Vovida Networks, Inc.
164 *
165 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
166 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
167 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
168 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
169 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
170 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
171 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
172 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
173 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
174 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
175 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
176 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
177 * DAMAGE.
178 *
179 * ====================================================================
180 *
181 * This software consists of voluntary contributions made by Vovida
182 * Networks, Inc. and many individuals on behalf of Vovida Networks,
183 * Inc. For more information on Vovida Networks, Inc., please see
184 * <http://www.vovida.org/>.
185 *
186 */

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