/[resiprocate]/branches/b-directory-reorg/resip/resiprocate/dum/test/testIdentity.cxx
ViewVC logotype

Contents of /branches/b-directory-reorg/resip/resiprocate/dum/test/testIdentity.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
Original Path: main/sip/resiprocate/dum/test/testIdentity.cxx
File size: 8951 byte(s)
modified to work with new ShartPtr management of Master/UserProfiles
1 #include "resiprocate/dum/ClientAuthManager.hxx"
2 #include "resiprocate/dum/ClientRegistration.hxx"
3 #include "resiprocate/dum/DialogUsageManager.hxx"
4 #include "resiprocate/dum/MasterProfile.hxx"
5 #include "resiprocate/dum/Profile.hxx"
6 #include "resiprocate/dum/UserProfile.hxx"
7 #include "resiprocate/dum/RegistrationHandler.hxx"
8 #include "resiprocate/dum/ClientPagerMessage.hxx"
9 #include "resiprocate/dum/ServerPagerMessage.hxx"
10
11 #include "resiprocate/dum/DialogUsageManager.hxx"
12 #include "resiprocate/dum/AppDialogSet.hxx"
13 #include "resiprocate/dum/AppDialog.hxx"
14 #include "resiprocate/dum/RegistrationHandler.hxx"
15 #include "resiprocate/dum/PagerMessageHandler.hxx"
16 #include "resiprocate/PlainContents.hxx"
17
18 #include "resiprocate/external/HttpGetMessage.hxx"
19 #include "curlHttp/CurlHttpProvider.hxx"
20
21 #include "resiprocate/os/Log.hxx"
22 #include "resiprocate/os/Logger.hxx"
23 #include "resiprocate/os/Subsystem.hxx"
24
25 #ifdef WIN32
26 #include "resiprocate/WinSecurity.hxx"
27 #endif
28
29 #include <iostream>
30 #include <string>
31 #include <sstream>
32
33 using namespace std;
34 using namespace resip;
35
36 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
37
38 class TestIdentityHandler : public ClientPagerMessageHandler,
39 public ServerPagerMessageHandler,
40 public ClientRegistrationHandler
41 {
42 public:
43 TestIdentityHandler() : _registered(false), _ended(false), _rcvd(false)
44 {};
45
46 bool isRegistered()
47 {
48 return _registered;
49 };
50
51 bool isEnded()
52 {
53 return _ended;
54 };
55
56 bool isRcvd()
57 {
58 return _rcvd;
59 };
60
61 virtual void onMessageArrived(ServerPagerMessageHandle handle,
62 const SipMessage& message)
63 {
64
65 SipMessage ok = handle->accept();
66 handle->send(ok);
67
68 Contents *body = message.getContents();
69
70 InfoLog( << "ServerPagerMessageHandler::onMessageArrived: "
71 << *body << "\n" );
72
73 const SecurityAttributes *attr = message.getSecurityAttributes();
74 InfoLog( << *attr );
75
76 _rcvd = true;
77 }
78
79 virtual void onSuccess(ClientPagerMessageHandle,
80 const SipMessage& status)
81 {
82 InfoLog( << "ClientMessageHandler::onSuccess\n" );
83 _ended = true;
84 }
85
86 virtual void onFailure(ClientPagerMessageHandle,
87 const SipMessage& status,
88 std::auto_ptr<Contents> contents)
89 {
90 InfoLog( << "ClientMessageHandler::onFailure\n" );
91 _ended = true;
92 }
93
94 virtual void onSuccess(ClientRegistrationHandle,
95 const SipMessage& response)
96 {
97 InfoLog( << "ClientRegistrationHandler::onSuccess\n" );
98 _registered = true;
99 }
100
101 virtual void onRemoved(ClientRegistrationHandle)
102 {
103 InfoLog( << "ClientRegistrationHander::onRemoved\n" );
104 exit(-1);
105 }
106
107 virtual void onFailure(ClientRegistrationHandle,
108 const SipMessage& response)
109 {
110 InfoLog( << "ClientRegistrationHandler::onFailure\n" );
111 exit(-1);
112 }
113
114 virtual int onRequestRetry(ClientRegistrationHandle,
115 int retrySeconds, const SipMessage& response)
116 {
117 InfoLog( << "ClientRegistrationHandler::onRequestRetry\n" );
118 exit(-1);
119 }
120
121 protected:
122 bool _registered;
123 bool _ended;
124 bool _rcvd;
125
126 };
127
128
129 /*****************************************************************************/
130
131 int main(int argc, char *argv[])
132 {
133
134 if ( argc < 3 ) {
135 cout << "usage: " << argv[0] << " sip:user passwd\n";
136 return 0;
137 }
138
139 Log::initialize(Log::Cout, Log::Debug, argv[0]);
140
141 HttpProvider::setFactory(
142 std::auto_ptr<HttpProviderFactory>(new CurlHttpProviderFactory()));
143
144 bool first = true;
145 NameAddr userAor(argv[1]);
146 Data passwd(argv[2]);
147
148 InfoLog(<< "user: " << userAor << ", passwd: " << passwd << "\n");
149
150 #ifdef WIN32
151 WinSecurity* security = new WinSecurity;
152 #else
153 Security* security = new Security;
154 #endif
155
156 assert( security );
157
158 SipStack clientStack(security);
159 DialogUsageManager clientDum(clientStack);
160 clientDum.addTransport(UDP, 10000 + rand()&0x7fff, V4);
161 clientDum.addTransport(TCP, 10000 + rand()&0x7fff, V4);
162 clientDum.addTransport(TLS, 10000 + rand()&0x7fff, V4);
163 // clientDum.addTransport(UDP, 10000 + rand()&0x7fff, V6);
164 // clientDum.addTransport(TCP, 10000 + rand()&0x7fff, V6);
165 // clientDum.addTransport(TLS, 10000 + rand()&0x7fff, V6);
166
167 SharedPtr<MasterProfile> clientProfile(new MasterProfile);
168 auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager());
169 TestIdentityHandler clientHandler;
170
171 clientDum.setMasterProfile(clientProfile);
172 clientDum.setClientAuthManager(clientAuth);
173 clientDum.setClientRegistrationHandler(&clientHandler);
174 clientDum.setClientPagerMessageHandler(&clientHandler);
175 clientDum.setServerPagerMessageHandler(&clientHandler);
176 clientDum.getMasterProfile()->setDefaultRegistrationTime(70);
177 clientDum.getMasterProfile()->addSupportedMethod(MESSAGE);
178 clientDum.getMasterProfile()->addSupportedMimeType(MESSAGE, Mime("text", "plain"));
179
180 clientProfile->setDefaultFrom(userAor);
181
182 InfoLog( << userAor.uri().host() << " " << userAor.uri().user()
183 << " " << passwd );
184
185 clientProfile->setDigestCredential(userAor.uri().host(),
186 userAor.uri().user(),
187 passwd);
188
189 SipMessage & regMessage = clientDum.makeRegistration(userAor);
190
191 InfoLog( << regMessage << "Generated register: " << endl << regMessage );
192 clientDum.send( regMessage );
193
194 while (!clientHandler.isEnded() || !clientHandler.isRcvd() )
195 {
196 FdSet fdset;
197
198 // Should these be buildFdSet on the DUM?
199 clientStack.buildFdSet(fdset);
200 int err = fdset.selectMilliSeconds(100);
201 assert ( err != -1 );
202
203 clientStack.process(fdset);
204 while(clientDum.process());
205 //if (!(n++ % 10)) cerr << "|/-\\"[(n/10)%4] << '\b';
206
207 if (first && clientHandler.isRegistered()) {
208 first = false;
209 InfoLog( << "client registered!!\n" );
210 InfoLog( << "Sending MESSAGE\n" );
211 ClientPagerMessageHandle cpmh = clientDum.makePagerMessage(userAor);
212 auto_ptr<Contents> content(new PlainContents(Data("message")));
213 cpmh.get()->page(content);
214 }
215 }
216
217 return 0;
218 }
219
220 /* ====================================================================
221 * The Vovida Software License, Version 1.0
222 *
223 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
224 *
225 * Redistribution and use in source and binary forms, with or without
226 * modification, are permitted provided that the following conditions
227 * are met:
228 *
229 * 1. Redistributions of source code must retain the above copyright
230 * notice, this list of conditions and the following disclaimer.
231 *
232 * 2. Redistributions in binary form must reproduce the above copyright
233 * notice, this list of conditions and the following disclaimer in
234 * the documentation and/or other materials provided with the
235 * distribution.
236 *
237 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
238 * and "Vovida Open Communication Application Library (VOCAL)" must
239 * not be used to endorse or promote products derived from this
240 * software without prior written permission. For written
241 * permission, please contact vocal@vovida.org.
242 *
243 * 4. Products derived from this software may not be called "VOCAL", nor
244 * may "VOCAL" appear in their name, without prior written
245 * permission of Vovida Networks, Inc.
246 *
247 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
248 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
249 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
250 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
251 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
252 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
253 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
254 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
255 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
256 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
257 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
258 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
259 * DAMAGE.
260 *
261 * ====================================================================
262 *
263 * This software consists of voluntary contributions made by Vovida
264 * Networks, Inc. and many individuals on behalf of Vovida Networks,
265 * Inc. For more information on Vovida Networks, Inc., please see
266 * <http://www.vovida.org/>.
267 *
268 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27