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

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