/[resiprocate]/main/sip/resiprocate/dum/DialogUsageManager.hxx
ViewVC logotype

Contents of /main/sip/resiprocate/dum/DialogUsageManager.hxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4601 - (show annotations) (download)
Thu May 12 01:10:49 2005 UTC (14 years, 6 months ago) by derek
File size: 18392 byte(s)
merged identity branch(4598) into main--removing identity branch after this
1 #if !defined(RESIP_DIALOGUSAGEMANAGER_HXX)
2 #define RESIP_DIALOGUSAGEMANAGER_HXX
3
4 #include <vector>
5 #include <set>
6 #include <map>
7
8 #include "resiprocate/Headers.hxx"
9 #include "resiprocate/dum/DialogSet.hxx"
10 #include "resiprocate/dum/DumTimeout.hxx"
11 #include "resiprocate/dum/HandleManager.hxx"
12 #include "resiprocate/dum/Handles.hxx"
13 #include "resiprocate/dum/MergedRequestKey.hxx"
14 #include "resiprocate/dum/RegistrationPersistenceManager.hxx"
15 #include "resiprocate/os/BaseException.hxx"
16 #include "resiprocate/SipStack.hxx"
17 #include "resiprocate/TransactionUser.hxx"
18
19 namespace resip
20 {
21
22 class Security;
23 class SipStack;
24 class FdSet;
25 class MasterProfile;
26 class RedirectManager;
27 class ClientAuthManager;
28 class ServerAuthManager;
29 class Uri;
30 class SdpContents;
31
32 class ClientRegistrationHandler;
33 class ServerRegistrationHandler;
34 class InviteSessionHandler;
35 class ClientSubscriptionHandler;
36 class ServerSubscriptionHandler;
37 class ClientPublicationHandler;
38 class ServerPublicationHandler;
39 class ClientPagerMessageHandler;
40 class ServerPagerMessageHandler;
41 class OutOfDialogHandler;
42 class RedirectHandler;
43 class DialogSetHandler;
44
45 class Dialog;
46 class InviteSessionCreator;
47
48 class AppDialogSetFactory;
49 class DumShutdownHandler;
50
51 class KeepAliveManager;
52 class HttpGetMessage;
53
54 class DialogUsageManager : public HandleManager, public TransactionUser
55 {
56 public:
57 class Exception : public BaseException
58 {
59 public:
60 Exception(const Data& msg,
61 const Data& file,
62 int line)
63 : BaseException(msg, file, line)
64 {}
65
66 virtual const char* name() const {return "DialogUsageManager::Exception";}
67 };
68
69 DialogUsageManager(SipStack& stack);
70 virtual ~DialogUsageManager();
71
72 void shutdown(DumShutdownHandler*, unsigned long giveUpSeconds=0);
73 void shutdownIfNoUsages(DumShutdownHandler*, unsigned long giveUpSeconds=0);
74 void forceShutdown(DumShutdownHandler*);
75
76 void addTransport( TransportType protocol,
77 int port=0,
78 IpVersion version=V4,
79 const Data& ipInterface = Data::Empty,
80 const Data& sipDomainname = Data::Empty, // only used
81 // for TLS
82 // based stuff
83 const Data& privateKeyPassPhrase = Data::Empty,
84 SecurityTypes::SSLType sslType = SecurityTypes::TLSv1 );
85
86 SipStack& getSipStack();
87 Security* getSecurity();
88
89 Data getHostAddress();
90
91 void setAppDialogSetFactory(std::auto_ptr<AppDialogSetFactory>);
92
93 void setMasterProfile(MasterProfile* masterProfile);
94 MasterProfile* getMasterProfile();
95
96 //optional handler to track the progress of DialogSets
97 void setDialogSetHandler(DialogSetHandler* handler);
98
99 void setKeepAliveManager(std::auto_ptr<KeepAliveManager> keepAlive);
100
101 //There is a default RedirectManager. Setting one may cause the old one
102 //to be deleted.
103 void setRedirectManager(std::auto_ptr<RedirectManager> redirect);
104
105 //informational, so a RedirectHandler is not required
106 void setRedirectHandler(RedirectHandler* handler);
107 RedirectHandler* getRedirectHandler();
108
109 /// If there is no ClientAuthManager, when the client receives a 401/407,
110 /// pass it up through the normal BaseUsageHandler
111 void setClientAuthManager(std::auto_ptr<ClientAuthManager> client);
112
113 /// If there is no ServerAuthManager, the server does not authenticate requests
114 void setServerAuthManager(std::auto_ptr<ServerAuthManager> server);
115
116 /// If there is no such handler, calling makeInviteSession will throw and
117 /// receiving an INVITE as a UAS will respond with 405 Method Not Allowed
118 void setInviteSessionHandler(InviteSessionHandler*);
119
120 /// If there is no such handler, calling makeRegistration will throw
121 void setClientRegistrationHandler(ClientRegistrationHandler*);
122
123 /// If no such handler, UAS will respond to REGISTER with 405 Method Not Allowed
124 void setServerRegistrationHandler(ServerRegistrationHandler*);
125
126 /// If there is no such handler, calling makeSubscription will throw
127 void addClientSubscriptionHandler(const Data& eventType, ClientSubscriptionHandler*);
128
129 /// If there is no such handler, calling makePublication will throw
130 void addClientPublicationHandler(const Data& eventType, ClientPublicationHandler*);
131
132 void addServerSubscriptionHandler(const Data& eventType, ServerSubscriptionHandler*);
133 void addServerPublicationHandler(const Data& eventType, ServerPublicationHandler*);
134
135 void addOutOfDialogHandler(MethodTypes, OutOfDialogHandler*);
136
137 void setClientPagerMessageHandler(ClientPagerMessageHandler*);
138 void setServerPagerMessageHandler(ServerPagerMessageHandler*);
139
140 /// Sets a manager to handle storage of registration state
141 void setRegistrationPersistenceManager(RegistrationPersistenceManager*);
142
143 // The message is owned by the underlying datastructure and may go away in
144 // the future. If the caller wants to keep it, it should make a copy. The
145 // memory will exist at least up until the point where the application
146 // calls DialogUsageManager::send(msg);
147 SipMessage& makeInviteSession(const NameAddr& target, UserProfile& userProfile, const SdpContents* initialOffer, AppDialogSet* = 0);
148 SipMessage& makeInviteSession(const NameAddr& target, const SdpContents* initialOffer, AppDialogSet* = 0);
149
150 //will send a Notify(100)...currently can be decorated through the
151 //OnReadyToSend callback. Probably will change it's own callback/handler soon
152 SipMessage& makeInviteSessionFromRefer(const SipMessage& refer, ServerSubscriptionHandle,
153 const SdpContents* initialOffer, AppDialogSet* = 0);
154
155 SipMessage& makeSubscription(const NameAddr& target, UserProfile& userProfile, const Data& eventType, AppDialogSet* = 0);
156 SipMessage& makeSubscription(const NameAddr& target, UserProfile& userProfile, const Data& eventType, int subscriptionTime, AppDialogSet* = 0);
157 SipMessage& makeSubscription(const NameAddr& target, UserProfile& userProfile, const Data& eventType,
158 int subscriptionTime, int refreshInterval, AppDialogSet* = 0);
159 SipMessage& makeSubscription(const NameAddr& target, const Data& eventType, AppDialogSet* = 0);
160 SipMessage& makeSubscription(const NameAddr& target, const Data& eventType, int subscriptionTime, AppDialogSet* = 0);
161 SipMessage& makeSubscription(const NameAddr& target, const Data& eventType,
162 int subscriptionTime, int refreshInterval, AppDialogSet* = 0);
163
164 //unsolicited refer
165 SipMessage& makeRefer(const NameAddr& target, UserProfile& userProfile, const H_ReferTo::Type& referTo, AppDialogSet* = 0);
166 SipMessage& makeRefer(const NameAddr& target, const H_ReferTo::Type& referTo, AppDialogSet* = 0);
167
168 SipMessage& makePublication(const NameAddr& target,
169 UserProfile& userProfile,
170 const Contents& body,
171 const Data& eventType,
172 unsigned expiresSeconds,
173 AppDialogSet* = 0);
174 SipMessage& makePublication(const NameAddr& target,
175 const Contents& body,
176 const Data& eventType,
177 unsigned expiresSeconds,
178 AppDialogSet* = 0);
179
180 SipMessage& makeRegistration(const NameAddr& target, UserProfile& userProfile, AppDialogSet* = 0);
181 SipMessage& makeRegistration(const NameAddr& target, UserProfile& userProfile, int registrationTime, AppDialogSet* = 0);
182 SipMessage& makeRegistration(const NameAddr& target, AppDialogSet* = 0);
183 SipMessage& makeRegistration(const NameAddr& target, int registrationTime, AppDialogSet* = 0);
184
185 SipMessage& makeOutOfDialogRequest(const NameAddr& target, UserProfile& userProfile, const MethodTypes meth, AppDialogSet* = 0);
186 SipMessage& makeOutOfDialogRequest(const NameAddr& target, const MethodTypes meth, AppDialogSet* = 0);
187
188 ClientPagerMessageHandle makePagerMessage(const NameAddr& target, UserProfile& userProfile, AppDialogSet* = 0);
189 ClientPagerMessageHandle makePagerMessage(const NameAddr& target, AppDialogSet* = 0);
190
191 void end(DialogSetId invSessionId);
192 void send(SipMessage& request);
193
194 // give dum an opportunity to handle its events. If process() returns true
195 // there are more events to process.
196 bool process();
197
198 //void buildFdSet(FdSet& fdset);
199 // Call this version of process if you want to run the stack in the
200 // application's thread
201 //void process(FdSet& fdset);
202
203 /// returns time in milliseconds when process next needs to be called
204 //int getTimeTillNextProcessMS();
205
206 InviteSessionHandle findInviteSession(DialogId id);
207 //if the handle is inValid, int represents the errorcode
208 std::pair<InviteSessionHandle, int> findInviteSession(CallId replaces);
209
210 std::vector<ClientSubscriptionHandle> findClientSubscriptions(DialogId id);
211 std::vector<ClientSubscriptionHandle> findClientSubscriptions(DialogSetId id);
212 std::vector<ClientSubscriptionHandle> findClientSubscriptions(DialogSetId id, const Data& eventType, const Data& subId);
213 ServerSubscriptionHandle findServerSubscription(DialogId id);
214 ClientPublicationHandle findClientPublication(DialogId id);
215 ServerPublicationHandle findServerPublication(DialogId id);
216 std::vector<ClientOutOfDialogReqHandle> findClientOutOfDialog(DialogId id);
217 ServerOutOfDialogReqHandle findServerOutOfDialog(DialogId id);
218
219 ClientPublicationHandler* getClientPublicationHandler(const Data& eventType);
220 ServerPublicationHandler* getServerPublicationHandler(const Data& eventType);
221
222 ClientSubscriptionHandler* getClientSubscriptionHandler(const Data& eventType);
223 ServerSubscriptionHandler* getServerSubscriptionHandler(const Data& eventType);
224
225 protected:
226 virtual void onAllHandlesDestroyed();
227 //TransactionUser virtuals
228 virtual const Data& name() const;
229 void internalProcess(std::auto_ptr<Message> msg);
230 friend class DumThread;
231
232 private:
233 friend class Dialog;
234 friend class DialogSet;
235
236 friend class ClientInviteSession;
237 friend class ClientOutOfDialogReq;
238 friend class ClientPublication;
239 friend class ClientRegistration;
240 friend class ClientSubscription;
241 friend class InviteSession;
242 friend class ServerInviteSession;
243 friend class ServerOutOfDialogReq;
244 friend class ServerPublication;
245 friend class ServerRegistration;
246 friend class ServerSubscription;
247 friend class BaseUsage;
248 friend class ClientPagerMessage;
249 friend class ServerPagerMessage;
250 friend class KeepAliveAssociation;
251 friend class NetworkAssociation;
252
253 DialogSet* makeUacDialogSet(BaseCreator* creator, AppDialogSet* appDs);
254 SipMessage& makeNewSession(BaseCreator* creator, AppDialogSet* appDs);
255
256 // makes a proto response to a request
257 void makeResponse(SipMessage& response,
258 const SipMessage& request,
259 int responseCode,
260 const Data& reason = Data::Empty) const;
261 // May call a callback to let the app adorn
262 void sendResponse(SipMessage& response);
263
264 void sendUsingOutboundIfAppropriate(UserProfile& userProfile, SipMessage& msg);
265
266 void addTimer(DumTimeout::Type type,
267 unsigned long durationSeconds,
268 BaseUsageHandle target,
269 int seq,
270 int altseq=-1);
271
272 void addTimerMs(DumTimeout::Type type,
273 unsigned long duration,
274 BaseUsageHandle target,
275 int seq,
276 int altseq=-1);
277
278 Dialog& findOrCreateDialog(const SipMessage* msg);
279 Dialog* findDialog(const DialogId& id);
280 DialogSet* findDialogSet(const DialogSetId& id);
281
282 // return 0, if no matching BaseCreator
283 BaseCreator* findCreator(const DialogId& id);
284
285 void processRequest(const SipMessage& request);
286 void processResponse(const SipMessage& response);
287 bool validateRequestURI(const SipMessage& request);
288 bool validateRequiredOptions(const SipMessage& request);
289 bool validateContent(const SipMessage& request);
290 bool validateAccept(const SipMessage& request);
291 bool validateTo(const SipMessage& request);
292 bool mergeRequest(const SipMessage& request);
293
294 void processPublish(const SipMessage& publish);
295
296 void removeDialogSet(const DialogSetId& );
297
298 bool checkEventPackage(const SipMessage& request);
299
300 bool queueForIdentityCheck(SipMessage* msg);
301 void processIdentityCheckResponse(const HttpGetMessage& msg);
302
303 // For delayed delete of a Usage
304 void destroy(const BaseUsage* usage);
305 void destroy(DialogSet*);
306 void destroy(Dialog*);
307
308 typedef std::set<MergedRequestKey> MergedRequests;
309 MergedRequests mMergedRequests;
310
311 typedef std::map<Data, DialogSet*> CancelMap;
312 CancelMap mCancelMap;
313
314 typedef HashMap<DialogSetId, DialogSet*> DialogSetMap;
315 DialogSetMap mDialogSetMap;
316
317 MasterProfile* mMasterProfile;
318 std::auto_ptr<RedirectManager> mRedirectManager;
319 std::auto_ptr<ClientAuthManager> mClientAuthManager;
320 std::auto_ptr<ServerAuthManager> mServerAuthManager;
321
322 InviteSessionHandler* mInviteSessionHandler;
323 ClientRegistrationHandler* mClientRegistrationHandler;
324 ServerRegistrationHandler* mServerRegistrationHandler;
325 RedirectHandler* mRedirectHandler;
326 DialogSetHandler* mDialogSetHandler;
327
328 RegistrationPersistenceManager *mRegistrationPersistenceManager;
329
330 OutOfDialogHandler* getOutOfDialogHandler(const MethodTypes type);
331
332 std::map<Data, ClientSubscriptionHandler*> mClientSubscriptionHandlers;
333 std::map<Data, ServerSubscriptionHandler*> mServerSubscriptionHandlers;
334 std::map<Data, ClientPublicationHandler*> mClientPublicationHandlers;
335 std::map<Data, ServerPublicationHandler*> mServerPublicationHandlers;
336 std::map<MethodTypes, OutOfDialogHandler*> mOutOfDialogHandlers;
337 std::auto_ptr<KeepAliveManager> mKeepAliveManager;
338
339 ClientPagerMessageHandler* mClientPagerMessageHandler;
340 ServerPagerMessageHandler* mServerPagerMessageHandler;
341
342 std::auto_ptr<AppDialogSetFactory> mAppDialogSetFactory;
343
344 SipStack& mStack;
345 DumShutdownHandler* mDumShutdownHandler;
346 typedef enum
347 {
348 Running,
349 ShutdownRequested, // while ending usages
350 RemovingTransactionUser, // while removing TU from stack
351 Shutdown, // after TU has been removed from stack
352 Destroying // while calling destructor
353 } ShutdownState;
354 ShutdownState mShutdownState;
355
356 // from ETag -> ServerPublication
357 typedef std::map<Data, ServerPublication*> ServerPublications;
358 ServerPublications mServerPublications;
359 typedef std::map<Data, SipMessage*> RequiresCerts;
360 RequiresCerts mRequiresCerts;
361 // from Event-Type+document-aor -> ServerSubscription
362 // Managed by ServerSubscription
363 typedef std::multimap<Data, ServerSubscription*> ServerSubscriptions;
364 ServerSubscriptions mServerSubscriptions;
365 };
366
367 }
368
369 #endif
370
371 /* ====================================================================
372 * The Vovida Software License, Version 1.0
373 *
374 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
375 *
376 * Redistribution and use in source and binary forms, with or without
377 * modification, are permitted provided that the following conditions
378 * are met:
379 *
380 * 1. Redistributions of source code must retain the above copyright
381 * notice, this list of conditions and the following disclaimer.
382 *
383 * 2. Redistributions in binary form must reproduce the above copyright
384 * notice, this list of conditions and the following disclaimer in
385 * the documentation and/or other materials provided with the
386 * distribution.
387 *
388 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
389 * and "Vovida Open Communication Application Library (VOCAL)" must
390 * not be used to endorse or promote products derived from this
391 * software without prior written permission. For written
392 * permission, please contact vocal@vovida.org.
393 *
394 * 4. Products derived from this software may not be called "VOCAL", nor
395 * may "VOCAL" appear in their name, without prior written
396 * permission of Vovida Networks, Inc.
397 *
398 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
399 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
400 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
401 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
402 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
403 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
404 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
405 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
406 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
407 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
408 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
409 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
410 * DAMAGE.
411 *
412 * ====================================================================
413 *
414 * This software consists of voluntary contributions made by Vovida
415 * Networks, Inc. and many individuals on behalf of Vovida Networks,
416 * Inc. For more information on Vovida Networks, Inc., please see
417 * <http://www.vovida.org/>.
418 *
419 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27