/[resiprocate]/main/resip/dum/test/UserAgent.cxx
ViewVC logotype

Annotation of /main/resip/dum/test/UserAgent.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7258 - (hide annotations) (download)
Mon Sep 24 17:45:36 2007 UTC (12 years, 2 months ago) by bcampen
File MIME type: text/plain
File size: 13370 byte(s)
Make limpc a better UAS.

1 jason 5276 #include "rutil/Log.hxx"
2     #include "rutil/Logger.hxx"
3 derek 5283 #include "resip/stack/Pidf.hxx"
4 jason 5276 #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 jason 4076
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 sgodin 4781 mProfile(new MasterProfile),
24 jason 4076 #if defined(USE_SSL)
25     mSecurity(new Security(mCertPath)),
26 jason 4383 mStack(mSecurity),
27 jason 4076 #else
28     mSecurity(0),
29 jason 4383 mStack(mSecurity),
30 jason 4076 #endif
31 jason 4383 mDum(mStack),
32     mStackThread(mStack)
33 jason 4076 {
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 jason 4383 #if defined(USE_SSL)
46 jason 4076 addTransport(TLS, mTlsPort);
47 jason 4383 #endif
48     #if defined(USED_DTLS)
49 jason 4076 addTransport(DTLS, mDtlsPort);
50 jason 4383 #endif
51 jason 4076
52 sgodin 4781 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 jason 4383
60 jason 4076 if (!mContact.host().empty())
61     {
62 sgodin 4781 mProfile->setOverrideHostAndPort(mContact);
63 jason 4076 }
64     if (!mOutboundProxy.host().empty())
65     {
66 sgodin 4781 mProfile->setOutboundProxy(Uri(mOutboundProxy));
67 jason 4076 }
68 sgodin 4781 mProfile->setUserAgent("limpc/1.0");
69 jason 4076
70 sgodin 4781 mDum.setMasterProfile(mProfile);
71 jason 4076 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 jason 4383 mStackThread.run();
79 jason 4076 }
80    
81     UserAgent::~UserAgent()
82     {
83 jason 4383 mStackThread.shutdown();
84     mStackThread.join();
85 jason 4076 }
86    
87     void
88     UserAgent::startup()
89     {
90     if (mRegisterDuration)
91     {
92 jason 4383 InfoLog (<< "register for " << mAor);
93 jason 4078 mDum.send(mDum.makeRegistration(NameAddr(mAor)));
94 jason 4076 }
95    
96 jason 4078 //for (std::vector<Uri> i = mBuddies.begin(); i != mBuddies.end(); ++i)
97 jason 4076 {
98     }
99    
100 jason 4078 #if 0
101 jason 4076 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 jason 4078 #endif
110     }
111 jason 4076
112 jason 4078 void
113     UserAgent::shutdown()
114     {
115 jason 4076 }
116    
117     void
118     UserAgent::process()
119     {
120 jason 4383 while (mDum.process());
121 jason 4076 }
122    
123     void
124     UserAgent::addTransport(TransportType type, int port)
125     {
126 jason 4383 for (; port < port+10; ++port)
127 jason 4076 {
128 jason 4383 try
129 jason 4076 {
130 jason 4383 if (port)
131 jason 4076 {
132 jason 4383 if (!mNoV4)
133     {
134     mDum.addTransport(type, port, V4, Data::Empty, mTlsDomain);
135     return;
136     }
137 jason 4076
138 jason 4383 if (!mNoV6)
139     {
140     mDum.addTransport(type, port, V6, Data::Empty, mTlsDomain);
141     return;
142     }
143 jason 4076 }
144     }
145 jason 4383 catch (BaseException& e)
146     {
147     InfoLog (<< "Caught: " << e);
148     WarningLog (<< "Failed to add " << Tuple::toData(type) << " transport on " << port);
149     }
150 jason 4076 }
151 jason 4383 throw Transport::Exception("Port already in use", __FILE__, __LINE__);
152 jason 4076 }
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 bcampen 7258 // .bwc. Er, this doesn't look right. We should provide an answer when we get
168     // the onOffer() callback, not the onNewSession() callback.
169     // SdpContents* sdp = dynamic_cast<SdpContents*>(msg.getContents());
170     // h->provideAnswer(*sdp);
171     // h->accept();
172 jason 4076
173     // might update presence here
174     }
175    
176     void
177     UserAgent::onFailure(ClientInviteSessionHandle h, const SipMessage& msg)
178     {
179     InfoLog(<< h->myAddr().uri().user()
180     << " outgoing call failed "
181     << h->peerAddr().uri().user()
182     << " status=" << msg.header(h_StatusLine).statusCode());
183     }
184    
185     void
186     UserAgent::onEarlyMedia(ClientInviteSessionHandle, const SipMessage&, const SdpContents&)
187     {
188     }
189    
190     void
191     UserAgent::onProvisional(ClientInviteSessionHandle, const SipMessage& msg)
192     {
193     }
194    
195     void
196     UserAgent::onConnected(ClientInviteSessionHandle h, const SipMessage& msg)
197     {
198     InfoLog(<< h->myAddr().uri().user() << " in INVITE session with " << h->peerAddr().uri().user());
199     }
200    
201     void
202     UserAgent::onConnected(InviteSessionHandle, const SipMessage& msg)
203     {
204     }
205    
206     void
207     UserAgent::onStaleCallTimeout(ClientInviteSessionHandle)
208     {
209     WarningLog(<< "onStaleCallTimeout");
210     }
211    
212     void
213     UserAgent::onTerminated(InviteSessionHandle h, InviteSessionHandler::TerminatedReason reason, const SipMessage* msg)
214     {
215     if (reason != InviteSessionHandler::PeerEnded)
216     {
217     WarningLog(<< h->myAddr().uri().user() << " call terminated with " << h->peerAddr().uri().user());
218     }
219     else
220     {
221     WarningLog(<< h->myAddr().uri().user() << " ended call with " << h->peerAddr().uri().user());
222     }
223     }
224    
225     void
226     UserAgent::onRedirected(ClientInviteSessionHandle, const SipMessage& msg)
227     {
228     assert(false);
229     }
230    
231     void
232 bcampen 7081 UserAgent::onAnswer(InviteSessionHandle, const SipMessage& msg, const SdpContents&)
233 jason 4076 {
234     }
235    
236     void
237 bcampen 7258 UserAgent::onOffer(InviteSessionHandle h, const SipMessage& msg, const SdpContents& offer)
238     {
239     InfoLog(<< h->myAddr().uri().user() << " offer from " << h->peerAddr().uri().user());
240    
241     SdpContents* sdp = dynamic_cast<SdpContents*>(msg.getContents());
242     h->provideAnswer(*sdp);
243 jason 4076 }
244    
245     void
246 bcampen 7258 UserAgent::onOfferRequired(InviteSessionHandle h, const SipMessage& msg)
247 jason 4076 {
248 bcampen 7258 InfoLog(<< h->myAddr().uri().user() << " offer requested by "
249     << h->peerAddr().uri().user());
250    
251     SdpContents* sdp = dynamic_cast<SdpContents*>(msg.getContents());
252     h->provideOffer(*sdp);
253 jason 4076 }
254    
255     void
256 bcampen 7258 UserAgent::onOfferRejected(InviteSessionHandle h, const SipMessage* msg)
257 jason 4076 {
258 bcampen 7258 InfoLog(<< h->myAddr().uri().user() << " offer rejected by "
259     << h->peerAddr().uri().user());
260 jason 4076 }
261    
262     void
263 bcampen 7258 UserAgent::onDialogModified(InviteSessionHandle h, InviteSession::OfferAnswerType oat, const SipMessage& msg)
264 jason 4076 {
265 bcampen 7258 InfoLog(<< h->myAddr().uri().user() << " dialog modified "
266     << h->peerAddr().uri().user());
267 jason 4076 }
268    
269     void
270 bcampen 7258 UserAgent::onInfo(InviteSessionHandle h, const SipMessage& msg)
271 jason 4076 {
272 bcampen 7258 InfoLog(<< h->myAddr().uri().user() << " INFO "
273     << h->peerAddr().uri().user());
274     h->acceptNIT();
275 jason 4076 }
276    
277     void
278     UserAgent::onInfoSuccess(InviteSessionHandle, const SipMessage& msg)
279     {
280     }
281    
282     void
283     UserAgent::onInfoFailure(InviteSessionHandle, const SipMessage& msg)
284     {
285     }
286    
287     void
288     UserAgent::onRefer(InviteSessionHandle, ServerSubscriptionHandle, const SipMessage& msg)
289     {
290     assert(0);
291     }
292    
293     void
294     UserAgent::onReferAccepted(InviteSessionHandle, ClientSubscriptionHandle, const SipMessage& msg)
295     {
296     assert(false);
297     }
298    
299     void
300     UserAgent::onReferRejected(InviteSessionHandle, const SipMessage& msg)
301     {
302     assert(0);
303     }
304    
305 greg 5308 void
306 jozsef 5888 UserAgent::onReferNoSub(InviteSessionHandle, const SipMessage& msg)
307     {
308     assert(0);
309     }
310    
311     void
312 bcampen 7258 UserAgent::onMessage(InviteSessionHandle h, const SipMessage& msg)
313 greg 5308 {
314 bcampen 7258 InfoLog(<< h->myAddr().uri().user() << " MESSAGE "
315     << h->peerAddr().uri().user());
316     h->acceptNIT();
317 greg 5308 }
318    
319     void
320     UserAgent::onMessageSuccess(InviteSessionHandle, const SipMessage& msg)
321     {
322     }
323    
324     void
325     UserAgent::onMessageFailure(InviteSessionHandle, const SipMessage& msg)
326     {
327     }
328    
329    
330 jason 4076 ////////////////////////////////////////////////////////////////////////////////
331     // Registration Handler ////////////////////////////////////////////////////////
332     ////////////////////////////////////////////////////////////////////////////////
333     void
334     UserAgent::onSuccess(ClientRegistrationHandle h, const SipMessage& response)
335     {
336     }
337    
338     void
339     UserAgent::onFailure(ClientRegistrationHandle h, const SipMessage& response)
340     {
341     }
342    
343     void
344 daniel 5759 UserAgent::onRemoved(ClientRegistrationHandle h, const SipMessage&)
345 jason 4076 {
346     }
347    
348     int
349     UserAgent::onRequestRetry(ClientRegistrationHandle h, int retryMinimum, const SipMessage& msg)
350     {
351 jason 4383 //assert(false);
352 jason 4076 return -1;
353     }
354    
355     ////////////////////////////////////////////////////////////////////////////////
356     // ClientSubscriptionHandler ///////////////////////////////////////////////////
357     ////////////////////////////////////////////////////////////////////////////////
358     void
359 jozsef 5888 UserAgent::onUpdatePending(ClientSubscriptionHandle h, const SipMessage& notify, bool outOfOrder)
360 jason 4076 {
361     }
362    
363     void
364 jozsef 5888 UserAgent::onUpdateActive(ClientSubscriptionHandle h, const SipMessage& notify, bool outOfOrder)
365 jason 4076 {
366     }
367    
368     void
369 jozsef 5888 UserAgent::onUpdateExtension(ClientSubscriptionHandle, const SipMessage& notify, bool outOfOrder)
370 jason 4076 {
371     }
372    
373     void
374     UserAgent::onTerminated(ClientSubscriptionHandle h, const SipMessage& notify)
375     {
376     }
377    
378     void
379     UserAgent::onNewSubscription(ClientSubscriptionHandle h, const SipMessage& notify)
380     {
381     }
382    
383     int
384     UserAgent::onRequestRetry(ClientSubscriptionHandle h, int retryMinimum, const SipMessage& notify)
385     {
386     return -1;
387     }
388    
389     ////////////////////////////////////////////////////////////////////////////////
390     // ClientPublicationHandler ////////////////////////////////////////////////////
391     ////////////////////////////////////////////////////////////////////////////////
392     void
393     UserAgent::onSuccess(ClientPublicationHandle h, const SipMessage& status)
394     {
395     }
396    
397     void
398     UserAgent::onRemove(ClientPublicationHandle h, const SipMessage& status)
399     {
400     }
401    
402     void
403     UserAgent::onFailure(ClientPublicationHandle h, const SipMessage& response)
404     {
405     }
406    
407     int
408     UserAgent::onRequestRetry(ClientPublicationHandle h, int retryMinimum, const SipMessage& response)
409     {
410     return -1;
411     }
412    
413     ////////////////////////////////////////////////////////////////////////////////
414     // OutOfDialogHandler //////////////////////////////////////////////////////////
415     ////////////////////////////////////////////////////////////////////////////////
416     void
417     UserAgent::onSuccess(ClientOutOfDialogReqHandle, const SipMessage& response)
418     {
419     InfoLog(<< response.header(h_CSeq).method() << "::OK: " << response );
420     }
421    
422     void
423     UserAgent::onFailure(ClientOutOfDialogReqHandle, const SipMessage& response)
424     {
425     ErrLog(<< response.header(h_CSeq).method() << "::failure: " << response );
426     if (response.exists(h_Warnings)) ErrLog (<< response.header(h_Warnings).front());
427     }
428    
429     void
430     UserAgent::onReceivedRequest(ServerOutOfDialogReqHandle, const SipMessage& request)
431     {
432     }
433    
434     void
435     UserAgent::onForkDestroyed(ClientInviteSessionHandle)
436     {
437     }
438 derek 4602
439     /* ====================================================================
440     * The Vovida Software License, Version 1.0
441     *
442     * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
443     *
444     * Redistribution and use in source and binary forms, with or without
445     * modification, are permitted provided that the following conditions
446     * are met:
447     *
448     * 1. Redistributions of source code must retain the above copyright
449     * notice, this list of conditions and the following disclaimer.
450     *
451     * 2. Redistributions in binary form must reproduce the above copyright
452     * notice, this list of conditions and the following disclaimer in
453     * the documentation and/or other materials provided with the
454     * distribution.
455     *
456     * 3. The names "VOCAL", "Vovida Open Communication Application Library",
457     * and "Vovida Open Communication Application Library (VOCAL)" must
458     * not be used to endorse or promote products derived from this
459     * software without prior written permission. For written
460     * permission, please contact vocal@vovida.org.
461     *
462     * 4. Products derived from this software may not be called "VOCAL", nor
463     * may "VOCAL" appear in their name, without prior written
464     * permission of Vovida Networks, Inc.
465     *
466     * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
467     * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
468     * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
469     * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
470     * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
471     * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
472     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
473     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
474     * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
475     * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
476     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
477     * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
478     * DAMAGE.
479     *
480     * ====================================================================
481     *
482     * This software consists of voluntary contributions made by Vovida
483     * Networks, Inc. and many individuals on behalf of Vovida Networks,
484     * Inc. For more information on Vovida Networks, Inc., please see
485     * <http://www.vovida.org/>.
486     *
487     */

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