/[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 4078 - (show annotations) (download)
Wed Mar 30 18:00:53 2005 UTC (14 years, 8 months ago) by jason
Original Path: main/sip/resiprocate/dum/test/UserAgent.cxx
File size: 9464 byte(s)


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 #if defined(USE_SSL)
24 mSecurity(new Security(mCertPath)),
25 mDum(mSecurity)
26 #else
27 mSecurity(0),
28 mDum(mSecurity)
29 #endif
30 {
31 Log::initialize(mLogType, mLogLevel, argv[0]);
32
33 #if defined(USE_SSL)
34 if (mGenUserCert)
35 {
36 mSecurity->generateUserCert(mAor.getAor());
37 }
38 #endif
39
40 addTransport(UDP, mUdpPort);
41 addTransport(TCP, mTcpPort);
42 addTransport(TLS, mTlsPort);
43 addTransport(DTLS, mDtlsPort);
44
45 mProfile.setDefaultRegistrationTime(mRegisterDuration);
46 mProfile.addSupportedMethod(NOTIFY);
47 mProfile.validateAcceptEnabled() = false;
48 mProfile.validateContentEnabled() = false;
49 mProfile.addSupportedMimeType(NOTIFY, Pidf::getStaticType());
50 mProfile.setDefaultFrom(NameAddr(mAor));
51 if (!mContact.host().empty())
52 {
53 mProfile.setOverrideHostAndPort(mContact);
54 }
55 if (!mOutboundProxy.host().empty())
56 {
57 mProfile.setOutboundProxy(Uri(mOutboundProxy));
58 }
59 mProfile.setUserAgent("limpc/0.3");
60
61 mDum.setMasterProfile(&mProfile);
62 mDum.setClientRegistrationHandler(this);
63 mDum.addClientSubscriptionHandler(Symbols::Presence, this);
64 mDum.addClientPublicationHandler(Symbols::Presence, this);
65 mDum.addOutOfDialogHandler(OPTIONS, this);
66 mDum.setClientAuthManager(std::auto_ptr<ClientAuthManager>(new ClientAuthManager));
67 mDum.setInviteSessionHandler(this);
68
69 mDum.run(); // starts a StackThread
70 }
71
72 UserAgent::~UserAgent()
73 {
74 shutdown();
75 join();
76 }
77
78 void
79 UserAgent::startup()
80 {
81 if (mRegisterDuration)
82 {
83 mDum.send(mDum.makeRegistration(NameAddr(mAor)));
84 }
85
86 //for (std::vector<Uri> i = mBuddies.begin(); i != mBuddies.end(); ++i)
87 {
88 }
89
90 #if 0
91 mDum.send(mDum.makePublish);
92
93 auto_ptr<SipMessage> msg( sa.dialog->makeInitialPublish(NameAddr(sa.uri),NameAddr(mAor)) );
94 Pidf* pidf = new Pidf( *mPidf );
95 msg->header(h_Event).value() = "presence";
96 msg->setContents( pidf );
97 setOutbound( *msg );
98 mStack->send( *msg );
99 #endif
100 }
101
102 void
103 UserAgent::shutdown()
104 {
105 }
106
107 void
108 UserAgent::process()
109 {
110 mDum.process();
111 }
112
113 void
114 UserAgent::thread()
115 {
116 while(!waitForShutdown(1000))
117 {
118 process();
119 }
120 }
121
122
123 void
124 UserAgent::addTransport(TransportType type, int port)
125 {
126 try
127 {
128 if (port)
129 {
130 if (!mNoV4)
131 {
132 mDum.addTransport(type, port, V4, Data::Empty, mTlsDomain);
133 }
134
135 if (!mNoV6)
136 {
137 mDum.addTransport(type, port, V6, Data::Empty, mTlsDomain);
138 }
139 }
140 }
141 catch (BaseException& e)
142 {
143 InfoLog (<< "Caught: " << e);
144 WarningLog (<< "Failed to add " << Tuple::toData(type) << " transport on " << port);
145 throw;
146 }
147
148 }
149
150
151 void
152 UserAgent::onNewSession(ClientInviteSessionHandle h, InviteSession::OfferAnswerType oat, const SipMessage& msg)
153 {
154 InfoLog(<< h->myAddr().uri().user() << " 180 from " << h->peerAddr().uri().user());
155 }
156
157 void
158 UserAgent::onNewSession(ServerInviteSessionHandle h, InviteSession::OfferAnswerType oat, const SipMessage& msg)
159 {
160 InfoLog(<< h->myAddr().uri().user() << " INVITE from " << h->peerAddr().uri().user());
161
162 h->provisional(180);
163 SdpContents* sdp = dynamic_cast<SdpContents*>(msg.getContents());
164 h->provideAnswer(*sdp);
165 h->accept();
166
167 // might update presence here
168 }
169
170 void
171 UserAgent::onFailure(ClientInviteSessionHandle h, const SipMessage& msg)
172 {
173 InfoLog(<< h->myAddr().uri().user()
174 << " outgoing call failed "
175 << h->peerAddr().uri().user()
176 << " status=" << msg.header(h_StatusLine).statusCode());
177 }
178
179 void
180 UserAgent::onEarlyMedia(ClientInviteSessionHandle, const SipMessage&, const SdpContents&)
181 {
182 }
183
184 void
185 UserAgent::onProvisional(ClientInviteSessionHandle, const SipMessage& msg)
186 {
187 }
188
189 void
190 UserAgent::onConnected(ClientInviteSessionHandle h, const SipMessage& msg)
191 {
192 InfoLog(<< h->myAddr().uri().user() << " in INVITE session with " << h->peerAddr().uri().user());
193 }
194
195 void
196 UserAgent::onConnected(InviteSessionHandle, const SipMessage& msg)
197 {
198 }
199
200 void
201 UserAgent::onStaleCallTimeout(ClientInviteSessionHandle)
202 {
203 WarningLog(<< "onStaleCallTimeout");
204 }
205
206 void
207 UserAgent::onTerminated(InviteSessionHandle h, InviteSessionHandler::TerminatedReason reason, const SipMessage* msg)
208 {
209 if (reason != InviteSessionHandler::PeerEnded)
210 {
211 WarningLog(<< h->myAddr().uri().user() << " call terminated with " << h->peerAddr().uri().user());
212 }
213 else
214 {
215 WarningLog(<< h->myAddr().uri().user() << " ended call with " << h->peerAddr().uri().user());
216 }
217 }
218
219 void
220 UserAgent::onRedirected(ClientInviteSessionHandle, const SipMessage& msg)
221 {
222 assert(false);
223 }
224
225 void
226 UserAgent::onAnswer(InviteSessionHandle, const SipMessage& msg, const SdpContents&)
227 {
228 }
229
230 void
231 UserAgent::onOffer(InviteSessionHandle handle, const SipMessage& msg, const SdpContents& offer)
232 {
233 }
234
235 void
236 UserAgent::onOfferRequired(InviteSessionHandle, const SipMessage& msg)
237 {
238 assert(false);
239 }
240
241 void
242 UserAgent::onOfferRejected(InviteSessionHandle, const SipMessage& msg)
243 {
244 assert(0);
245 }
246
247 void
248 UserAgent::onDialogModified(InviteSessionHandle, InviteSession::OfferAnswerType oat, const SipMessage& msg)
249 {
250 assert(0);
251 }
252
253 void
254 UserAgent::onInfo(InviteSessionHandle, const SipMessage& msg)
255 {
256 assert(0);
257 }
258
259 void
260 UserAgent::onInfoSuccess(InviteSessionHandle, const SipMessage& msg)
261 {
262 assert(0);
263 }
264
265 void
266 UserAgent::onInfoFailure(InviteSessionHandle, const SipMessage& msg)
267 {
268 assert(0);
269 }
270
271 void
272 UserAgent::onRefer(InviteSessionHandle, ServerSubscriptionHandle, const SipMessage& msg)
273 {
274 assert(0);
275 }
276
277 void
278 UserAgent::onReferAccepted(InviteSessionHandle, ClientSubscriptionHandle, const SipMessage& msg)
279 {
280 assert(false);
281 }
282
283 void
284 UserAgent::onReferRejected(InviteSessionHandle, const SipMessage& msg)
285 {
286 assert(0);
287 }
288
289 ////////////////////////////////////////////////////////////////////////////////
290 // Registration Handler ////////////////////////////////////////////////////////
291 ////////////////////////////////////////////////////////////////////////////////
292 void
293 UserAgent::onSuccess(ClientRegistrationHandle h, const SipMessage& response)
294 {
295 }
296
297 void
298 UserAgent::onFailure(ClientRegistrationHandle h, const SipMessage& response)
299 {
300 }
301
302 void
303 UserAgent::onRemoved(ClientRegistrationHandle h)
304 {
305 }
306
307 int
308 UserAgent::onRequestRetry(ClientRegistrationHandle h, int retryMinimum, const SipMessage& msg)
309 {
310 assert(false);
311 return -1;
312 }
313
314 ////////////////////////////////////////////////////////////////////////////////
315 // ClientSubscriptionHandler ///////////////////////////////////////////////////
316 ////////////////////////////////////////////////////////////////////////////////
317 void
318 UserAgent::onRefreshRejected(ClientSubscriptionHandle h, const SipMessage& rejection)
319 {
320 }
321
322 void
323 UserAgent::onUpdatePending(ClientSubscriptionHandle h, const SipMessage& notify)
324 {
325 }
326
327 void
328 UserAgent::onUpdateActive(ClientSubscriptionHandle h, const SipMessage& notify)
329 {
330 }
331
332 void
333 UserAgent::onUpdateExtension(ClientSubscriptionHandle, const SipMessage& notify)
334 {
335 }
336
337 void
338 UserAgent::onTerminated(ClientSubscriptionHandle h, const SipMessage& notify)
339 {
340 }
341
342 void
343 UserAgent::onNewSubscription(ClientSubscriptionHandle h, const SipMessage& notify)
344 {
345 }
346
347 int
348 UserAgent::onRequestRetry(ClientSubscriptionHandle h, int retryMinimum, const SipMessage& notify)
349 {
350 return -1;
351 }
352
353 ////////////////////////////////////////////////////////////////////////////////
354 // ClientPublicationHandler ////////////////////////////////////////////////////
355 ////////////////////////////////////////////////////////////////////////////////
356 void
357 UserAgent::onSuccess(ClientPublicationHandle h, const SipMessage& status)
358 {
359 }
360
361 void
362 UserAgent::onRemove(ClientPublicationHandle h, const SipMessage& status)
363 {
364 }
365
366 void
367 UserAgent::onFailure(ClientPublicationHandle h, const SipMessage& response)
368 {
369 }
370
371 int
372 UserAgent::onRequestRetry(ClientPublicationHandle h, int retryMinimum, const SipMessage& response)
373 {
374 return -1;
375 }
376
377 ////////////////////////////////////////////////////////////////////////////////
378 // OutOfDialogHandler //////////////////////////////////////////////////////////
379 ////////////////////////////////////////////////////////////////////////////////
380 void
381 UserAgent::onSuccess(ClientOutOfDialogReqHandle, const SipMessage& response)
382 {
383 InfoLog(<< response.header(h_CSeq).method() << "::OK: " << response );
384 }
385
386 void
387 UserAgent::onFailure(ClientOutOfDialogReqHandle, const SipMessage& response)
388 {
389 ErrLog(<< response.header(h_CSeq).method() << "::failure: " << response );
390 if (response.exists(h_Warnings)) ErrLog (<< response.header(h_Warnings).front());
391 }
392
393 void
394 UserAgent::onReceivedRequest(ServerOutOfDialogReqHandle, const SipMessage& request)
395 {
396 }
397
398 void
399 UserAgent::onForkDestroyed(ClientInviteSessionHandle)
400 {
401 }

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27