|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Name : CSIPRegEventHandler.h |
|
16 * Part of : SIP Profile Agent |
|
17 * Interface : |
|
18 * Version : 1.0 |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 /** |
|
26 @internalComponent |
|
27 */ |
|
28 |
|
29 #ifndef CSIPREGEVENTHANDLER_H |
|
30 #define CSIPREGEVENTHANDLER_H |
|
31 |
|
32 // INCLUDES |
|
33 #include <e32base.h> |
|
34 #include <uri8.h> |
|
35 #include <stringpool.h> |
|
36 #include "sipregeventsubscriberobserver.h" |
|
37 #include "sipregeventobserver.h" |
|
38 #include "sipdialog.h" |
|
39 #include "sipclienttransaction.h" |
|
40 #include "sipservertransaction.h" |
|
41 #include "_sipcodecdefs.h" |
|
42 #include <sipprofileagentextensionparams.h> |
|
43 // FORWARD DECLARATIONS |
|
44 class CSIPConnection; |
|
45 class MSIPRegistrationContext; |
|
46 class CSIPNotifyXmlBodyParser; |
|
47 class CSIPRegEventSubscriber; |
|
48 class CSIPRegistrationElement; |
|
49 class CSIPContactElement; |
|
50 |
|
51 // CLASS DECLARATION |
|
52 // |
|
53 class CSIPRegEventHandler : public CBase, |
|
54 public MSIPRegEventSubscriberObserver |
|
55 { |
|
56 public: // Constructors and destructor |
|
57 |
|
58 /** |
|
59 * Creates a new instance of CSIPRegEventHandler. |
|
60 * |
|
61 * @pre aConnection::State() == CSIPConnection::EActive |
|
62 * @pre aContext.IsContextActive() == ETrue |
|
63 * |
|
64 * @param aXMLParser a XML parser for NOTIFY bodies |
|
65 * @param aLocalIP the local IP address of the related CSIPConnection |
|
66 * @param aDeltaTimer an object used for ordering timer events |
|
67 * @param aConnection an active SIP connection |
|
68 * @param aContext an active context |
|
69 * @param aUserIdentity a URI received in the topmost |
|
70 * P-Associated-URI-header in the 200 OK for the registration. |
|
71 * @param a observer for the network initiated re-/de-registration. |
|
72 * @return a new instance of CSIPRegEventHandler. |
|
73 * The ownership is transferred. |
|
74 */ |
|
75 static CSIPRegEventHandler* NewL(CSIPNotifyXmlBodyParser& aXMLParser, |
|
76 const TDesC8& aLocalIP, |
|
77 CDeltaTimer& aDeltaTimer, |
|
78 CSIPConnection& aConnection, |
|
79 MSIPRegistrationContext& aContext, |
|
80 CUri8& aUserIdentity, |
|
81 MSIPRegEventObserver& aObserver, |
|
82 CSipProfileAgentConfigExtension& aConfigExtension); |
|
83 |
|
84 /** |
|
85 * Creates a new instance of CSIPRegEventHandler and |
|
86 * puts it to CleanupStack. |
|
87 * |
|
88 * @pre aConnection::State() == CSIPConnection::EActive |
|
89 * @pre aContext.IsContextActive() == ETrue |
|
90 * |
|
91 * @param aXMLParser a XML parser for NOTIFY bodies |
|
92 * @param aLocalIP the local IP address of the related CSIPConnection |
|
93 * @param aDeltaTimer an object used for ordering timer events |
|
94 * @param aConnection an active SIP connection |
|
95 * @param aContext an active context |
|
96 * @param aUserIdentity a URI received in the topmost |
|
97 * P-Associated-URI-header in the 200 OK for the registration. |
|
98 * @param a observer for the network initiated re-/de-registration. |
|
99 * @return a new instance of CSIPRegEventHandler. |
|
100 * The ownership is transferred. |
|
101 */ |
|
102 static CSIPRegEventHandler* NewLC(CSIPNotifyXmlBodyParser& aXMLParser, |
|
103 const TDesC8& aLocalIP, |
|
104 CDeltaTimer& aDeltaTimer, |
|
105 CSIPConnection& aConnection, |
|
106 MSIPRegistrationContext& aContext, |
|
107 CUri8& aUserIdentity, |
|
108 MSIPRegEventObserver& aObserver, |
|
109 CSipProfileAgentConfigExtension& aConfigExtension); |
|
110 |
|
111 /** |
|
112 * Destructor. |
|
113 */ |
|
114 ~CSIPRegEventHandler(); |
|
115 |
|
116 public: // New functions |
|
117 |
|
118 /** |
|
119 * Sends the SUBCRIBE for the registration state event to the network. |
|
120 */ |
|
121 void SubscribeL(); |
|
122 |
|
123 /** |
|
124 * Refreshes the subscription for the registration state event. |
|
125 * In other words send an immediate updated SUBSRIBE to the network. |
|
126 */ |
|
127 void RefreshL(); |
|
128 |
|
129 /** |
|
130 * Checks whether this handler owns the transaction given. |
|
131 * |
|
132 * @param aTransaction the transaction to be checked |
|
133 * @return ETrue if this handler owns the transaction. Otherwise EFalse. |
|
134 */ |
|
135 TBool HasTransaction(const CSIPTransactionBase& aTransaction) const; |
|
136 |
|
137 /** |
|
138 * Checks whether this handler owns the refresh given. |
|
139 * |
|
140 * @param aRefresh the refresh to be checked |
|
141 * @return ETrue if this handler owns the refresh. Otherwise EFalse. |
|
142 */ |
|
143 TBool HasRefresh(const CSIPRefresh& aRefresh) const; |
|
144 |
|
145 /** |
|
146 * Checks whether this handler has created the dialog given. |
|
147 * |
|
148 * @param aDialog the dialog to be checked |
|
149 * @return ETrue if this handler owns the dialog. Otherwise EFalse. |
|
150 */ |
|
151 TBool HasDialog(const CSIPDialog& aDialog) const; |
|
152 |
|
153 /** |
|
154 * A response has been received from the network. |
|
155 * In practice this should be a response for |
|
156 * the SUBSCRIBE that was sent for the registration state event. |
|
157 * |
|
158 * @pre HasTransaction(aTransaction) == ETrue |
|
159 * |
|
160 * @param aTransaction an existing transaction |
|
161 */ |
|
162 void ResponseReceivedL(CSIPClientTransaction& aTransaction); |
|
163 |
|
164 /** |
|
165 * A request within a dialog has been received from the network. |
|
166 * In practice this should be a NOTIFY for the registration state event. |
|
167 * |
|
168 * @pre HasDialog(aDialog) == ETrue |
|
169 * |
|
170 * @param aTransaction a new transaction. The ownership is transferred. |
|
171 * @param aDialog an existing dialog related to the transaction |
|
172 */ |
|
173 void RequestReceivedL(CSIPServerTransaction* aTransaction, |
|
174 CSIPDialog& aDialog); |
|
175 |
|
176 /** |
|
177 * An error has occured related to an existing transaction. |
|
178 * This can be an error related to a SUBSCRIBE send to network or |
|
179 * a response sent for a NOTIFY. |
|
180 * |
|
181 * @pre HasTransaction(aTransaction) == ETrue |
|
182 * |
|
183 * @param aError the error |
|
184 * @param aTransaction an existing transaction |
|
185 */ |
|
186 void ErrorOccured(TInt aError, |
|
187 CSIPTransactionBase& aTransaction); |
|
188 |
|
189 /** |
|
190 * An error has occured related to an existing transaction. |
|
191 * In practice this error is related |
|
192 * to a refreshed SUBSCRIBE send to network. |
|
193 * |
|
194 * @pre HasDialog(aDialog) == ETrue |
|
195 * |
|
196 * @param aError the error |
|
197 * @param aDialog an existing dialog |
|
198 */ |
|
199 void ErrorOccured(TInt aError, |
|
200 CSIPDialog& aDialog); |
|
201 |
|
202 |
|
203 public: // From MSIPRegEventSubscriberObserver |
|
204 |
|
205 void SubscriptionFailedL(); |
|
206 |
|
207 void SubscriptionFailedL(TInt aRetryAfter); |
|
208 |
|
209 void RegEventNotSupportedByNetworkL(); |
|
210 |
|
211 void ReRegister(); |
|
212 |
|
213 void NotifyReceivedL(CSIPRegInfoElement& aNotifyData); |
|
214 |
|
215 void TerminatedL(CSIPRegInfoElement& aNotifyData,TInt aRetryAfter); |
|
216 |
|
217 public: // A callback for CDeltaTimer |
|
218 |
|
219 static TInt ReSubscribeTimerExpired(TAny* aPtr); |
|
220 |
|
221 private: // New functions |
|
222 |
|
223 void ReSubscribeAfterL(TInt aRetryAfter); |
|
224 |
|
225 void ReSubscribeL(); |
|
226 |
|
227 void HandleRegInfoL(CSIPRegInfoElement& aElement, |
|
228 TBool& aTerminated); |
|
229 |
|
230 void HandleRegistrationElementL(CSIPRegistrationElement& aElement, |
|
231 TBool& aTerminated, |
|
232 TBool& aLocalIPFound); |
|
233 |
|
234 TBool AllLocalContactsTerminated(CSIPRegInfoElement& aNotifyData) const; |
|
235 |
|
236 TBool HasLocalIP(const CSIPContactElement& aContact) const; |
|
237 |
|
238 private: // Second phase constructors |
|
239 |
|
240 void ConstructL(const TDesC8& aLocalIP, |
|
241 CUri8& aUserIdentity, |
|
242 CSipProfileAgentConfigExtension& aConfigExtension); |
|
243 |
|
244 CSIPRegEventHandler(CSIPNotifyXmlBodyParser& aXMLParser, |
|
245 CDeltaTimer& aDeltaTimer, |
|
246 CSIPConnection& aConnection, |
|
247 MSIPRegistrationContext& aContext, |
|
248 MSIPRegEventObserver& aObserver); |
|
249 |
|
250 private: // Data |
|
251 |
|
252 CSIPNotifyXmlBodyParser& iXMLParser; |
|
253 CDeltaTimer& iDeltaTimer; |
|
254 CSIPConnection& iConnection; |
|
255 MSIPRegistrationContext& iRegistrationContext; |
|
256 MSIPRegEventObserver& iObserver; |
|
257 HBufC8* iLocalIP; |
|
258 CUri8* iUserId; |
|
259 CSIPRegEventSubscriber* iSubscriber; |
|
260 TCallBack iDeltaTimerCallBack; |
|
261 TDeltaTimerEntry iDeltaTimerEntry; |
|
262 TUint iRegEventVersion; |
|
263 TBool iFirstNotifyProcessed; |
|
264 // String constants |
|
265 RString iStrFull; |
|
266 RString iStrActive; |
|
267 RString iStrShortened; |
|
268 RString iStrRejected; |
|
269 RString iStrTerminated; |
|
270 RString iStrDeactivated; |
|
271 RString iStrUnregistered; |
|
272 RString iStrProbation; |
|
273 RString iStrExpired; |
|
274 |
|
275 private: // Unit test |
|
276 |
|
277 UNIT_TEST(CSIPRegEventHandlerTest) |
|
278 UNIT_TEST(CSIPIMSProfileContextTest) |
|
279 }; |
|
280 |
|
281 #endif // CSIPREGEVENTHANDLER_H |