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

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27