/[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 7259 - (show annotations) (download)
Mon Sep 24 19:53:38 2007 UTC (12 years, 2 months ago) by bcampen
File MIME type: text/plain
File size: 13594 byte(s)
More work on getting limpc to do what I want.

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
162 void
163 UserAgent::onNewSession(ServerInviteSessionHandle h, InviteSession::OfferAnswerType oat, const SipMessage& msg)
164 {
165 InfoLog(<< h->myAddr().uri().user() << " INVITE from " << h->peerAddr().uri().user());
166
167 h->provisional(180);
168 // .bwc. Er, this doesn't look right. We should provide an answer when we get
169 // the onOffer() callback, not the onNewSession() callback.
170 // SdpContents* sdp = dynamic_cast<SdpContents*>(msg.getContents());
171 // h->provideAnswer(*sdp);
172 // h->accept();
173
174 // might update presence here
175 }
176
177 void
178 UserAgent::onFailure(ClientInviteSessionHandle h, const SipMessage& msg)
179 {
180 InfoLog(<< h->myAddr().uri().user()
181 << " outgoing call failed "
182 << h->peerAddr().uri().user()
183 << " status=" << msg.header(h_StatusLine).statusCode());
184 }
185
186 void
187 UserAgent::onEarlyMedia(ClientInviteSessionHandle, const SipMessage&, const SdpContents&)
188 {
189 }
190
191 void
192 UserAgent::onProvisional(ClientInviteSessionHandle, const SipMessage& msg)
193 {
194 }
195
196 void
197 UserAgent::onConnected(ClientInviteSessionHandle h, const SipMessage& msg)
198 {
199 InfoLog(<< h->myAddr().uri().user() << " in INVITE session with " << h->peerAddr().uri().user());
200 }
201
202 void
203 UserAgent::onConnected(InviteSessionHandle, const SipMessage& msg)
204 {
205 }
206
207 void
208 UserAgent::onStaleCallTimeout(ClientInviteSessionHandle)
209 {
210 WarningLog(<< "onStaleCallTimeout");
211 }
212
213 void
214 UserAgent::onTerminated(InviteSessionHandle h, InviteSessionHandler::TerminatedReason reason, const SipMessage* msg)
215 {
216 if (reason != InviteSessionHandler::PeerEnded)
217 {
218 WarningLog(<< h->myAddr().uri().user() << " call terminated with " << h->peerAddr().uri().user());
219 }
220 else
221 {
222 WarningLog(<< h->myAddr().uri().user() << " ended call with " << h->peerAddr().uri().user());
223 }
224 }
225
226 void
227 UserAgent::onRedirected(ClientInviteSessionHandle, const SipMessage& msg)
228 {
229 assert(false);
230 }
231
232 void
233 UserAgent::onAnswer(InviteSessionHandle, const SipMessage& msg, const SdpContents&)
234 {
235 }
236
237 void
238 UserAgent::onOffer(InviteSessionHandle h, const SipMessage& msg, const SdpContents& offer)
239 {
240 InfoLog(<< h->myAddr().uri().user() << " offer from " << h->peerAddr().uri().user());
241
242 SdpContents* sdp = dynamic_cast<SdpContents*>(msg.getContents());
243 h->provideAnswer(*sdp);
244 if(msg.isRequest() && msg.method()==INVITE && !h->isConnected())
245 {
246 h->accept();
247 }
248 }
249
250 void
251 UserAgent::onOfferRequired(InviteSessionHandle h, const SipMessage& msg)
252 {
253 InfoLog(<< h->myAddr().uri().user() << " offer requested by "
254 << h->peerAddr().uri().user());
255
256 SdpContents* sdp = dynamic_cast<SdpContents*>(msg.getContents());
257 h->provideOffer(*sdp);
258 }
259
260 void
261 UserAgent::onOfferRejected(InviteSessionHandle h, const SipMessage* msg)
262 {
263 InfoLog(<< h->myAddr().uri().user() << " offer rejected by "
264 << h->peerAddr().uri().user());
265 }
266
267 void
268 UserAgent::onDialogModified(InviteSessionHandle h, InviteSession::OfferAnswerType oat, const SipMessage& msg)
269 {
270 InfoLog(<< h->myAddr().uri().user() << " dialog modified "
271 << h->peerAddr().uri().user());
272 }
273
274 void
275 UserAgent::onInfo(InviteSessionHandle h, const SipMessage& msg)
276 {
277 InfoLog(<< h->myAddr().uri().user() << " INFO "
278 << h->peerAddr().uri().user());
279 h->acceptNIT();
280 }
281
282 void
283 UserAgent::onInfoSuccess(InviteSessionHandle, const SipMessage& msg)
284 {
285 }
286
287 void
288 UserAgent::onInfoFailure(InviteSessionHandle, const SipMessage& msg)
289 {
290 }
291
292 void
293 UserAgent::onRefer(InviteSessionHandle, ServerSubscriptionHandle, const SipMessage& msg)
294 {
295 assert(0);
296 }
297
298 void
299 UserAgent::onReferAccepted(InviteSessionHandle, ClientSubscriptionHandle, const SipMessage& msg)
300 {
301 assert(false);
302 }
303
304 void
305 UserAgent::onReferRejected(InviteSessionHandle, const SipMessage& msg)
306 {
307 assert(0);
308 }
309
310 void
311 UserAgent::onReferNoSub(InviteSessionHandle, const SipMessage& msg)
312 {
313 assert(0);
314 }
315
316 void
317 UserAgent::onMessage(InviteSessionHandle h, const SipMessage& msg)
318 {
319 InfoLog(<< h->myAddr().uri().user() << " MESSAGE "
320 << h->peerAddr().uri().user());
321 h->acceptNIT();
322 }
323
324 void
325 UserAgent::onMessageSuccess(InviteSessionHandle, const SipMessage& msg)
326 {
327 }
328
329 void
330 UserAgent::onMessageFailure(InviteSessionHandle, const SipMessage& msg)
331 {
332 }
333
334
335 ////////////////////////////////////////////////////////////////////////////////
336 // Registration Handler ////////////////////////////////////////////////////////
337 ////////////////////////////////////////////////////////////////////////////////
338 void
339 UserAgent::onSuccess(ClientRegistrationHandle h, const SipMessage& response)
340 {
341 }
342
343 void
344 UserAgent::onFailure(ClientRegistrationHandle h, const SipMessage& response)
345 {
346 }
347
348 void
349 UserAgent::onRemoved(ClientRegistrationHandle h, const SipMessage&)
350 {
351 }
352
353 int
354 UserAgent::onRequestRetry(ClientRegistrationHandle h, int retryMinimum, const SipMessage& msg)
355 {
356 //assert(false);
357 return -1;
358 }
359
360 ////////////////////////////////////////////////////////////////////////////////
361 // ClientSubscriptionHandler ///////////////////////////////////////////////////
362 ////////////////////////////////////////////////////////////////////////////////
363 void
364 UserAgent::onUpdatePending(ClientSubscriptionHandle h, const SipMessage& notify, bool outOfOrder)
365 {
366 }
367
368 void
369 UserAgent::onUpdateActive(ClientSubscriptionHandle h, const SipMessage& notify, bool outOfOrder)
370 {
371 }
372
373 void
374 UserAgent::onUpdateExtension(ClientSubscriptionHandle, const SipMessage& notify, bool outOfOrder)
375 {
376 }
377
378 void
379 UserAgent::onTerminated(ClientSubscriptionHandle h, const SipMessage& notify)
380 {
381 }
382
383 void
384 UserAgent::onNewSubscription(ClientSubscriptionHandle h, const SipMessage& notify)
385 {
386 }
387
388 int
389 UserAgent::onRequestRetry(ClientSubscriptionHandle h, int retryMinimum, const SipMessage& notify)
390 {
391 return -1;
392 }
393
394 ////////////////////////////////////////////////////////////////////////////////
395 // ClientPublicationHandler ////////////////////////////////////////////////////
396 ////////////////////////////////////////////////////////////////////////////////
397 void
398 UserAgent::onSuccess(ClientPublicationHandle h, const SipMessage& status)
399 {
400 }
401
402 void
403 UserAgent::onRemove(ClientPublicationHandle h, const SipMessage& status)
404 {
405 }
406
407 void
408 UserAgent::onFailure(ClientPublicationHandle h, const SipMessage& response)
409 {
410 }
411
412 int
413 UserAgent::onRequestRetry(ClientPublicationHandle h, int retryMinimum, const SipMessage& response)
414 {
415 return -1;
416 }
417
418 ////////////////////////////////////////////////////////////////////////////////
419 // OutOfDialogHandler //////////////////////////////////////////////////////////
420 ////////////////////////////////////////////////////////////////////////////////
421 void
422 UserAgent::onSuccess(ClientOutOfDialogReqHandle, const SipMessage& response)
423 {
424 InfoLog(<< response.header(h_CSeq).method() << "::OK: " << response );
425 }
426
427 void
428 UserAgent::onFailure(ClientOutOfDialogReqHandle, const SipMessage& response)
429 {
430 ErrLog(<< response.header(h_CSeq).method() << "::failure: " << response );
431 if (response.exists(h_Warnings)) ErrLog (<< response.header(h_Warnings).front());
432 }
433
434 void
435 UserAgent::onReceivedRequest(ServerOutOfDialogReqHandle h, const SipMessage& request)
436 {
437 InfoLog(<< request.method() << ": Just respond.");
438 h->send(h->accept());
439 }
440
441 void
442 UserAgent::onForkDestroyed(ClientInviteSessionHandle)
443 {
444 }
445
446 /* ====================================================================
447 * The Vovida Software License, Version 1.0
448 *
449 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
450 *
451 * Redistribution and use in source and binary forms, with or without
452 * modification, are permitted provided that the following conditions
453 * are met:
454 *
455 * 1. Redistributions of source code must retain the above copyright
456 * notice, this list of conditions and the following disclaimer.
457 *
458 * 2. Redistributions in binary form must reproduce the above copyright
459 * notice, this list of conditions and the following disclaimer in
460 * the documentation and/or other materials provided with the
461 * distribution.
462 *
463 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
464 * and "Vovida Open Communication Application Library (VOCAL)" must
465 * not be used to endorse or promote products derived from this
466 * software without prior written permission. For written
467 * permission, please contact vocal@vovida.org.
468 *
469 * 4. Products derived from this software may not be called "VOCAL", nor
470 * may "VOCAL" appear in their name, without prior written
471 * permission of Vovida Networks, Inc.
472 *
473 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
474 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
475 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
476 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
477 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
478 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
479 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
480 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
481 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
482 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
483 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
484 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
485 * DAMAGE.
486 *
487 * ====================================================================
488 *
489 * This software consists of voluntary contributions made by Vovida
490 * Networks, Inc. and many individuals on behalf of Vovida Networks,
491 * Inc. For more information on Vovida Networks, Inc., please see
492 * <http://www.vovida.org/>.
493 *
494 */

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