/[resiprocate]/main/sip/resiprocate/dum/test/testIdentity.cxx
ViewVC logotype

Contents of /main/sip/resiprocate/dum/test/testIdentity.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4633 - (show annotations) (download)
Fri May 13 19:31:17 2005 UTC (14 years, 6 months ago) by greg
File size: 8650 byte(s)
Log the security attributes.

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

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27