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

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