/[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 7081 - (show annotations) (download)
Tue Apr 17 14:46:38 2007 UTC (12 years, 8 months ago) by bcampen
File MIME type: text/plain
File size: 12566 byte(s)
Reverting rev 7077 until it can get some review.
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::onReferNoSub(InviteSessionHandle, const SipMessage& msg)
295 {
296 assert(0);
297 }
298
299 void
300 UserAgent::onMessage(InviteSessionHandle, const SipMessage& msg)
301 {
302 }
303
304 void
305 UserAgent::onMessageSuccess(InviteSessionHandle, const SipMessage& msg)
306 {
307 }
308
309 void
310 UserAgent::onMessageFailure(InviteSessionHandle, const SipMessage& msg)
311 {
312 }
313
314
315 ////////////////////////////////////////////////////////////////////////////////
316 // Registration Handler ////////////////////////////////////////////////////////
317 ////////////////////////////////////////////////////////////////////////////////
318 void
319 UserAgent::onSuccess(ClientRegistrationHandle h, const SipMessage& response)
320 {
321 }
322
323 void
324 UserAgent::onFailure(ClientRegistrationHandle h, const SipMessage& response)
325 {
326 }
327
328 void
329 UserAgent::onRemoved(ClientRegistrationHandle h, const SipMessage&)
330 {
331 }
332
333 int
334 UserAgent::onRequestRetry(ClientRegistrationHandle h, int retryMinimum, const SipMessage& msg)
335 {
336 //assert(false);
337 return -1;
338 }
339
340 ////////////////////////////////////////////////////////////////////////////////
341 // ClientSubscriptionHandler ///////////////////////////////////////////////////
342 ////////////////////////////////////////////////////////////////////////////////
343 void
344 UserAgent::onRefreshRejected(ClientSubscriptionHandle h, const SipMessage& rejection)
345 {
346 }
347
348 void
349 UserAgent::onUpdatePending(ClientSubscriptionHandle h, const SipMessage& notify, bool outOfOrder)
350 {
351 }
352
353 void
354 UserAgent::onUpdateActive(ClientSubscriptionHandle h, const SipMessage& notify, bool outOfOrder)
355 {
356 }
357
358 void
359 UserAgent::onUpdateExtension(ClientSubscriptionHandle, const SipMessage& notify, bool outOfOrder)
360 {
361 }
362
363 void
364 UserAgent::onTerminated(ClientSubscriptionHandle h, const SipMessage& notify)
365 {
366 }
367
368 void
369 UserAgent::onNewSubscription(ClientSubscriptionHandle h, const SipMessage& notify)
370 {
371 }
372
373 int
374 UserAgent::onRequestRetry(ClientSubscriptionHandle h, int retryMinimum, const SipMessage& notify)
375 {
376 return -1;
377 }
378
379 ////////////////////////////////////////////////////////////////////////////////
380 // ClientPublicationHandler ////////////////////////////////////////////////////
381 ////////////////////////////////////////////////////////////////////////////////
382 void
383 UserAgent::onSuccess(ClientPublicationHandle h, const SipMessage& status)
384 {
385 }
386
387 void
388 UserAgent::onRemove(ClientPublicationHandle h, const SipMessage& status)
389 {
390 }
391
392 void
393 UserAgent::onFailure(ClientPublicationHandle h, const SipMessage& response)
394 {
395 }
396
397 int
398 UserAgent::onRequestRetry(ClientPublicationHandle h, int retryMinimum, const SipMessage& response)
399 {
400 return -1;
401 }
402
403 ////////////////////////////////////////////////////////////////////////////////
404 // OutOfDialogHandler //////////////////////////////////////////////////////////
405 ////////////////////////////////////////////////////////////////////////////////
406 void
407 UserAgent::onSuccess(ClientOutOfDialogReqHandle, const SipMessage& response)
408 {
409 InfoLog(<< response.header(h_CSeq).method() << "::OK: " << response );
410 }
411
412 void
413 UserAgent::onFailure(ClientOutOfDialogReqHandle, const SipMessage& response)
414 {
415 ErrLog(<< response.header(h_CSeq).method() << "::failure: " << response );
416 if (response.exists(h_Warnings)) ErrLog (<< response.header(h_Warnings).front());
417 }
418
419 void
420 UserAgent::onReceivedRequest(ServerOutOfDialogReqHandle, const SipMessage& request)
421 {
422 }
423
424 void
425 UserAgent::onForkDestroyed(ClientInviteSessionHandle)
426 {
427 }
428
429 /* ====================================================================
430 * The Vovida Software License, Version 1.0
431 *
432 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
433 *
434 * Redistribution and use in source and binary forms, with or without
435 * modification, are permitted provided that the following conditions
436 * are met:
437 *
438 * 1. Redistributions of source code must retain the above copyright
439 * notice, this list of conditions and the following disclaimer.
440 *
441 * 2. Redistributions in binary form must reproduce the above copyright
442 * notice, this list of conditions and the following disclaimer in
443 * the documentation and/or other materials provided with the
444 * distribution.
445 *
446 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
447 * and "Vovida Open Communication Application Library (VOCAL)" must
448 * not be used to endorse or promote products derived from this
449 * software without prior written permission. For written
450 * permission, please contact vocal@vovida.org.
451 *
452 * 4. Products derived from this software may not be called "VOCAL", nor
453 * may "VOCAL" appear in their name, without prior written
454 * permission of Vovida Networks, Inc.
455 *
456 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
457 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
458 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
459 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
460 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
461 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
462 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
463 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
464 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
465 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
466 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
467 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
468 * DAMAGE.
469 *
470 * ====================================================================
471 *
472 * This software consists of voluntary contributions made by Vovida
473 * Networks, Inc. and many individuals on behalf of Vovida Networks,
474 * Inc. For more information on Vovida Networks, Inc., please see
475 * <http://www.vovida.org/>.
476 *
477 */

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