/[resiprocate]/main/resip/dum/test/UserAgent.cxx
ViewVC logotype

Contents of /main/resip/dum/test/UserAgent.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5759 - (show annotations) (download)
Fri Dec 16 18:07:05 2005 UTC (14 years ago) by daniel
File size: 12423 byte(s)
compiles with lastest ShardPtr change.
1 #include "rutil/Log.hxx"
2 #include "rutil/Logger.hxx"
3 #include "resip/stack/Pidf.hxx"
4 #include "resip/dum/ClientAuthManager.hxx"
5 #include "resip/dum/ClientInviteSession.hxx"
6 #include "resip/dum/ServerInviteSession.hxx"
7 #include "resip/dum/ClientSubscription.hxx"
8 #include "resip/dum/ServerSubscription.hxx"
9 #include "resip/dum/ClientRegistration.hxx"
10 #include "resip/dum/ServerRegistration.hxx"
11 #include "resip/dum/ClientPublication.hxx"
12 #include "resip/dum/ServerPublication.hxx"
13
14 #include "UserAgent.hxx"
15
16 using namespace resip;
17 using namespace std;
18
19 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
20
21 UserAgent::UserAgent(int argc, char** argv) :
22 CommandLineParser(argc, argv),
23 mProfile(new MasterProfile),
24 #if defined(USE_SSL)
25 mSecurity(new Security(mCertPath)),
26 mStack(mSecurity),
27 #else
28 mSecurity(0),
29 mStack(mSecurity),
30 #endif
31 mDum(mStack),
32 mStackThread(mStack)
33 {
34 Log::initialize(mLogType, mLogLevel, argv[0]);
35
36 #if defined(USE_SSL)
37 if (mGenUserCert)
38 {
39 mSecurity->generateUserCert(mAor.getAor());
40 }
41 #endif
42
43 addTransport(UDP, mUdpPort);
44 addTransport(TCP, mTcpPort);
45 #if defined(USE_SSL)
46 addTransport(TLS, mTlsPort);
47 #endif
48 #if defined(USED_DTLS)
49 addTransport(DTLS, mDtlsPort);
50 #endif
51
52 mProfile->setDefaultRegistrationTime(mRegisterDuration);
53 mProfile->addSupportedMethod(NOTIFY);
54 mProfile->validateAcceptEnabled() = false;
55 mProfile->validateContentEnabled() = false;
56 mProfile->addSupportedMimeType(NOTIFY, Pidf::getStaticType());
57 mProfile->setDefaultFrom(NameAddr(mAor));
58 mProfile->setDigestCredential(mAor.host(), mAor.user(), mPassword);
59
60 if (!mContact.host().empty())
61 {
62 mProfile->setOverrideHostAndPort(mContact);
63 }
64 if (!mOutboundProxy.host().empty())
65 {
66 mProfile->setOutboundProxy(Uri(mOutboundProxy));
67 }
68 mProfile->setUserAgent("limpc/1.0");
69
70 mDum.setMasterProfile(mProfile);
71 mDum.setClientRegistrationHandler(this);
72 mDum.addClientSubscriptionHandler(Symbols::Presence, this);
73 mDum.addClientPublicationHandler(Symbols::Presence, this);
74 mDum.addOutOfDialogHandler(OPTIONS, this);
75 mDum.setClientAuthManager(std::auto_ptr<ClientAuthManager>(new ClientAuthManager));
76 mDum.setInviteSessionHandler(this);
77
78 mStackThread.run();
79 }
80
81 UserAgent::~UserAgent()
82 {
83 mStackThread.shutdown();
84 mStackThread.join();
85 }
86
87 void
88 UserAgent::startup()
89 {
90 if (mRegisterDuration)
91 {
92 InfoLog (<< "register for " << mAor);
93 mDum.send(mDum.makeRegistration(NameAddr(mAor)));
94 }
95
96 //for (std::vector<Uri> i = mBuddies.begin(); i != mBuddies.end(); ++i)
97 {
98 }
99
100 #if 0
101 mDum.send(mDum.makePublish);
102
103 auto_ptr<SipMessage> msg( sa.dialog->makeInitialPublish(NameAddr(sa.uri),NameAddr(mAor)) );
104 Pidf* pidf = new Pidf( *mPidf );
105 msg->header(h_Event).value() = "presence";
106 msg->setContents( pidf );
107 setOutbound( *msg );
108 mStack->send( *msg );
109 #endif
110 }
111
112 void
113 UserAgent::shutdown()
114 {
115 }
116
117 void
118 UserAgent::process()
119 {
120 while (mDum.process());
121 }
122
123 void
124 UserAgent::addTransport(TransportType type, int port)
125 {
126 for (; port < port+10; ++port)
127 {
128 try
129 {
130 if (port)
131 {
132 if (!mNoV4)
133 {
134 mDum.addTransport(type, port, V4, Data::Empty, mTlsDomain);
135 return;
136 }
137
138 if (!mNoV6)
139 {
140 mDum.addTransport(type, port, V6, Data::Empty, mTlsDomain);
141 return;
142 }
143 }
144 }
145 catch (BaseException& e)
146 {
147 InfoLog (<< "Caught: " << e);
148 WarningLog (<< "Failed to add " << Tuple::toData(type) << " transport on " << port);
149 }
150 }
151 throw Transport::Exception("Port already in use", __FILE__, __LINE__);
152 }
153
154
155 void
156 UserAgent::onNewSession(ClientInviteSessionHandle h, InviteSession::OfferAnswerType oat, const SipMessage& msg)
157 {
158 InfoLog(<< h->myAddr().uri().user() << " 180 from " << h->peerAddr().uri().user());
159 }
160
161 void
162 UserAgent::onNewSession(ServerInviteSessionHandle h, InviteSession::OfferAnswerType oat, const SipMessage& msg)
163 {
164 InfoLog(<< h->myAddr().uri().user() << " INVITE from " << h->peerAddr().uri().user());
165
166 h->provisional(180);
167 SdpContents* sdp = dynamic_cast<SdpContents*>(msg.getContents());
168 h->provideAnswer(*sdp);
169 h->accept();
170
171 // might update presence here
172 }
173
174 void
175 UserAgent::onFailure(ClientInviteSessionHandle h, const SipMessage& msg)
176 {
177 InfoLog(<< h->myAddr().uri().user()
178 << " outgoing call failed "
179 << h->peerAddr().uri().user()
180 << " status=" << msg.header(h_StatusLine).statusCode());
181 }
182
183 void
184 UserAgent::onEarlyMedia(ClientInviteSessionHandle, const SipMessage&, const SdpContents&)
185 {
186 }
187
188 void
189 UserAgent::onProvisional(ClientInviteSessionHandle, const SipMessage& msg)
190 {
191 }
192
193 void
194 UserAgent::onConnected(ClientInviteSessionHandle h, const SipMessage& msg)
195 {
196 InfoLog(<< h->myAddr().uri().user() << " in INVITE session with " << h->peerAddr().uri().user());
197 }
198
199 void
200 UserAgent::onConnected(InviteSessionHandle, const SipMessage& msg)
201 {
202 }
203
204 void
205 UserAgent::onStaleCallTimeout(ClientInviteSessionHandle)
206 {
207 WarningLog(<< "onStaleCallTimeout");
208 }
209
210 void
211 UserAgent::onTerminated(InviteSessionHandle h, InviteSessionHandler::TerminatedReason reason, const SipMessage* msg)
212 {
213 if (reason != InviteSessionHandler::PeerEnded)
214 {
215 WarningLog(<< h->myAddr().uri().user() << " call terminated with " << h->peerAddr().uri().user());
216 }
217 else
218 {
219 WarningLog(<< h->myAddr().uri().user() << " ended call with " << h->peerAddr().uri().user());
220 }
221 }
222
223 void
224 UserAgent::onRedirected(ClientInviteSessionHandle, const SipMessage& msg)
225 {
226 assert(false);
227 }
228
229 void
230 UserAgent::onAnswer(InviteSessionHandle, const SipMessage& msg, const SdpContents&)
231 {
232 }
233
234 void
235 UserAgent::onOffer(InviteSessionHandle handle, const SipMessage& msg, const SdpContents& offer)
236 {
237 }
238
239 void
240 UserAgent::onOfferRequired(InviteSessionHandle, const SipMessage& msg)
241 {
242 assert(false);
243 }
244
245 void
246 UserAgent::onOfferRejected(InviteSessionHandle, const SipMessage* msg)
247 {
248 assert(0);
249 }
250
251 void
252 UserAgent::onDialogModified(InviteSessionHandle, InviteSession::OfferAnswerType oat, const SipMessage& msg)
253 {
254 assert(0);
255 }
256
257 void
258 UserAgent::onInfo(InviteSessionHandle, const SipMessage& msg)
259 {
260 assert(0);
261 }
262
263 void
264 UserAgent::onInfoSuccess(InviteSessionHandle, const SipMessage& msg)
265 {
266 assert(0);
267 }
268
269 void
270 UserAgent::onInfoFailure(InviteSessionHandle, const SipMessage& msg)
271 {
272 assert(0);
273 }
274
275 void
276 UserAgent::onRefer(InviteSessionHandle, ServerSubscriptionHandle, const SipMessage& msg)
277 {
278 assert(0);
279 }
280
281 void
282 UserAgent::onReferAccepted(InviteSessionHandle, ClientSubscriptionHandle, const SipMessage& msg)
283 {
284 assert(false);
285 }
286
287 void
288 UserAgent::onReferRejected(InviteSessionHandle, const SipMessage& msg)
289 {
290 assert(0);
291 }
292
293 void
294 UserAgent::onMessage(InviteSessionHandle, const SipMessage& msg)
295 {
296 }
297
298 void
299 UserAgent::onMessageSuccess(InviteSessionHandle, const SipMessage& msg)
300 {
301 }
302
303 void
304 UserAgent::onMessageFailure(InviteSessionHandle, const SipMessage& msg)
305 {
306 }
307
308
309 ////////////////////////////////////////////////////////////////////////////////
310 // Registration Handler ////////////////////////////////////////////////////////
311 ////////////////////////////////////////////////////////////////////////////////
312 void
313 UserAgent::onSuccess(ClientRegistrationHandle h, const SipMessage& response)
314 {
315 }
316
317 void
318 UserAgent::onFailure(ClientRegistrationHandle h, const SipMessage& response)
319 {
320 }
321
322 void
323 UserAgent::onRemoved(ClientRegistrationHandle h, const SipMessage&)
324 {
325 }
326
327 int
328 UserAgent::onRequestRetry(ClientRegistrationHandle h, int retryMinimum, const SipMessage& msg)
329 {
330 //assert(false);
331 return -1;
332 }
333
334 ////////////////////////////////////////////////////////////////////////////////
335 // ClientSubscriptionHandler ///////////////////////////////////////////////////
336 ////////////////////////////////////////////////////////////////////////////////
337 void
338 UserAgent::onRefreshRejected(ClientSubscriptionHandle h, const SipMessage& rejection)
339 {
340 }
341
342 void
343 UserAgent::onUpdatePending(ClientSubscriptionHandle h, const SipMessage& notify)
344 {
345 }
346
347 void
348 UserAgent::onUpdateActive(ClientSubscriptionHandle h, const SipMessage& notify)
349 {
350 }
351
352 void
353 UserAgent::onUpdateExtension(ClientSubscriptionHandle, const SipMessage& notify)
354 {
355 }
356
357 void
358 UserAgent::onTerminated(ClientSubscriptionHandle h, const SipMessage& notify)
359 {
360 }
361
362 void
363 UserAgent::onNewSubscription(ClientSubscriptionHandle h, const SipMessage& notify)
364 {
365 }
366
367 int
368 UserAgent::onRequestRetry(ClientSubscriptionHandle h, int retryMinimum, const SipMessage& notify)
369 {
370 return -1;
371 }
372
373 ////////////////////////////////////////////////////////////////////////////////
374 // ClientPublicationHandler ////////////////////////////////////////////////////
375 ////////////////////////////////////////////////////////////////////////////////
376 void
377 UserAgent::onSuccess(ClientPublicationHandle h, const SipMessage& status)
378 {
379 }
380
381 void
382 UserAgent::onRemove(ClientPublicationHandle h, const SipMessage& status)
383 {
384 }
385
386 void
387 UserAgent::onFailure(ClientPublicationHandle h, const SipMessage& response)
388 {
389 }
390
391 int
392 UserAgent::onRequestRetry(ClientPublicationHandle h, int retryMinimum, const SipMessage& response)
393 {
394 return -1;
395 }
396
397 ////////////////////////////////////////////////////////////////////////////////
398 // OutOfDialogHandler //////////////////////////////////////////////////////////
399 ////////////////////////////////////////////////////////////////////////////////
400 void
401 UserAgent::onSuccess(ClientOutOfDialogReqHandle, const SipMessage& response)
402 {
403 InfoLog(<< response.header(h_CSeq).method() << "::OK: " << response );
404 }
405
406 void
407 UserAgent::onFailure(ClientOutOfDialogReqHandle, const SipMessage& response)
408 {
409 ErrLog(<< response.header(h_CSeq).method() << "::failure: " << response );
410 if (response.exists(h_Warnings)) ErrLog (<< response.header(h_Warnings).front());
411 }
412
413 void
414 UserAgent::onReceivedRequest(ServerOutOfDialogReqHandle, const SipMessage& request)
415 {
416 }
417
418 void
419 UserAgent::onForkDestroyed(ClientInviteSessionHandle)
420 {
421 }
422
423 /* ====================================================================
424 * The Vovida Software License, Version 1.0
425 *
426 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
427 *
428 * Redistribution and use in source and binary forms, with or without
429 * modification, are permitted provided that the following conditions
430 * are met:
431 *
432 * 1. Redistributions of source code must retain the above copyright
433 * notice, this list of conditions and the following disclaimer.
434 *
435 * 2. Redistributions in binary form must reproduce the above copyright
436 * notice, this list of conditions and the following disclaimer in
437 * the documentation and/or other materials provided with the
438 * distribution.
439 *
440 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
441 * and "Vovida Open Communication Application Library (VOCAL)" must
442 * not be used to endorse or promote products derived from this
443 * software without prior written permission. For written
444 * permission, please contact vocal@vovida.org.
445 *
446 * 4. Products derived from this software may not be called "VOCAL", nor
447 * may "VOCAL" appear in their name, without prior written
448 * permission of Vovida Networks, Inc.
449 *
450 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
451 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
452 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
453 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
454 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
455 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
456 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
457 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
458 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
459 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
460 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
461 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
462 * DAMAGE.
463 *
464 * ====================================================================
465 *
466 * This software consists of voluntary contributions made by Vovida
467 * Networks, Inc. and many individuals on behalf of Vovida Networks,
468 * Inc. For more information on Vovida Networks, Inc., please see
469 * <http://www.vovida.org/>.
470 *
471 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27