|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : CSipHeaderStrategyBase.cpp |
|
15 // Part of : SIP Client Resolver |
|
16 // Version : 1.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "CSipHeaderStrategyBase.h" |
|
22 #include "MSipClient.h" |
|
23 #include "MSipClients.h" |
|
24 #include "siprequest.h" |
|
25 #include "sipstrings.h" |
|
26 #include "sipstrconsts.h" |
|
27 #include "sipcontenttypeheader.h" |
|
28 #include "CSIPClientResolver2.h" |
|
29 #include "uricontainer.h" |
|
30 #include "SIPCRLogs.h" |
|
31 #include "TSipClient.h" |
|
32 |
|
33 // ---------------------------------------------------------------------------- |
|
34 // CSipHeaderStrategyBase::~CSipHeaderStrategyBase |
|
35 // ---------------------------------------------------------------------------- |
|
36 // |
|
37 CSipHeaderStrategyBase::~CSipHeaderStrategyBase() |
|
38 { |
|
39 } |
|
40 |
|
41 // ---------------------------------------------------------------------------- |
|
42 // CSipHeaderStrategyBase::CSipHeaderStrategyBase |
|
43 // ---------------------------------------------------------------------------- |
|
44 // |
|
45 CSipHeaderStrategyBase::CSipHeaderStrategyBase( |
|
46 MSipClients& aSipClients, |
|
47 CSipHeaderStrategyBase* aNextStrategy, |
|
48 CSipHeaderStrategyBase* aNextStrategy2 ) |
|
49 : iSipClients( aSipClients ), |
|
50 iNextStrategy( aNextStrategy ), |
|
51 iNextStrategy2( aNextStrategy2 ) |
|
52 { |
|
53 } |
|
54 |
|
55 // ---------------------------------------------------------------------------- |
|
56 // CSipHeaderStrategyBase::MatchClientsL |
|
57 // ---------------------------------------------------------------------------- |
|
58 // |
|
59 CSIPResponse* CSipHeaderStrategyBase::MatchClientsL( |
|
60 CSIPRequest& aRequest, |
|
61 RArray<TUid>& aUids ) |
|
62 { |
|
63 SIP_CR_LOG("CSipHeaderStrategyBase::MatchClientsL") |
|
64 EliminateClientsL( aRequest,aUids ); |
|
65 if ( aUids.Count() == 0 ) |
|
66 { |
|
67 return CreateResponseL(); |
|
68 } |
|
69 return NULL; |
|
70 } |
|
71 |
|
72 // ---------------------------------------------------------------------------- |
|
73 // CSipHeaderStrategyBase::MatchClients2L |
|
74 // ---------------------------------------------------------------------------- |
|
75 // |
|
76 CSIPResponse* CSipHeaderStrategyBase::MatchClients2L( |
|
77 CSIPRequest& aRequest, |
|
78 RArray<TUid>& aUids, |
|
79 TBool& aContinueSearch, |
|
80 CSIPClientResolver2& aClientResolver2 ) |
|
81 { |
|
82 SIP_CR_LOG("CSipHeaderStrategyBase::MatchClients2L") |
|
83 CSIPResponse* response = NULL; |
|
84 aClientResolver2.FetchMatchingUidsL( aRequest, *this ); |
|
85 response = NoMatchL( aRequest,aUids,aContinueSearch,aClientResolver2 ); |
|
86 if ( !response ) |
|
87 { |
|
88 response = MoreThanOneMatchL( aRequest,aUids,aContinueSearch, |
|
89 aClientResolver2 ); |
|
90 } |
|
91 return response; |
|
92 } |
|
93 |
|
94 // ---------------------------------------------------------------------------- |
|
95 // CSipHeaderStrategyBase::MatchL |
|
96 // ---------------------------------------------------------------------------- |
|
97 // |
|
98 TBool CSipHeaderStrategyBase::MatchL( CSIPResolvedClient2& aClient, |
|
99 CSIPRequest& aRequest, |
|
100 TUid& aUid ) |
|
101 { |
|
102 CUri8* uri8 = ConvertRequestUriL( aRequest ); |
|
103 CleanupStack::PushL( uri8 ); |
|
104 TBool match( EFalse ); |
|
105 match = MatchResolvedClientL( aClient,aRequest,aUid,*uri8 ); |
|
106 CleanupStack::PopAndDestroy( uri8 ); |
|
107 return match; |
|
108 } |
|
109 |
|
110 // ---------------------------------------------------------------------------- |
|
111 // CSipHeaderStrategyBase::ConvertRequestUriL |
|
112 // ---------------------------------------------------------------------------- |
|
113 // |
|
114 CUri8* CSipHeaderStrategyBase::ConvertRequestUriL( CSIPRequest& aRequest ) |
|
115 { |
|
116 CUri8* uri8 = NULL; |
|
117 __ASSERT_ALWAYS(aRequest.RequestURI(), User::Leave(KErrCorrupt)); |
|
118 HBufC8* temp = aRequest.RequestURI()->ToTextL(); |
|
119 CleanupStack::PushL( temp ); |
|
120 TUriParser8 parser; |
|
121 User::LeaveIfError( parser.Parse( *temp) ); |
|
122 uri8 = CUri8::NewL( parser ); |
|
123 CleanupStack::PopAndDestroy( temp ); |
|
124 return uri8; |
|
125 } |
|
126 |
|
127 // ---------------------------------------------------------------------------- |
|
128 // CSipHeaderStrategyBase::NextStrategyL |
|
129 // ---------------------------------------------------------------------------- |
|
130 // |
|
131 CSIPResponse* CSipHeaderStrategyBase::NextStrategyL( CSIPRequest& aRequest, |
|
132 RArray<TUid>& aUids, |
|
133 TBool& aContinueSearch, |
|
134 CSIPClientResolver2& aClientResolver2 ) |
|
135 { |
|
136 SIP_CR_LOG("CSipHeaderStrategyBase::NextStrategyL") |
|
137 CSIPResponse* response = NULL; |
|
138 if ( iNextStrategy ) |
|
139 { |
|
140 response = iNextStrategy->ApplyL( aRequest,aUids,aContinueSearch, |
|
141 aClientResolver2 ); |
|
142 } |
|
143 return response; |
|
144 } |
|
145 |
|
146 // ---------------------------------------------------------------------------- |
|
147 // CSipHeaderStrategyBase::NextStrategy2L |
|
148 // ---------------------------------------------------------------------------- |
|
149 // |
|
150 CSIPResponse* CSipHeaderStrategyBase::NextStrategy2L( |
|
151 CSIPRequest& aRequest, |
|
152 RArray<TUid>& aUids, |
|
153 TBool& aContinueSearch, |
|
154 CSIPClientResolver2& aClientResolver2 ) |
|
155 { |
|
156 SIP_CR_LOG("CSipHeaderStrategyBase::NextStrategy2L") |
|
157 CSIPResponse* response = NULL; |
|
158 if ( iNextStrategy2 ) |
|
159 { |
|
160 response = iNextStrategy2->ApplyL( aRequest,aUids,aContinueSearch, |
|
161 aClientResolver2 ); |
|
162 } |
|
163 return response; |
|
164 } |
|
165 |
|
166 // ---------------------------------------------------------------------------- |
|
167 // CSipHeaderStrategyBase::NoMatchL |
|
168 // ---------------------------------------------------------------------------- |
|
169 // |
|
170 CSIPResponse* CSipHeaderStrategyBase::NoMatchL( |
|
171 CSIPRequest& aRequest, |
|
172 RArray<TUid>& aUids, |
|
173 TBool& aContinueSearch, |
|
174 CSIPClientResolver2& aClientResolver2 ) |
|
175 { |
|
176 SIP_CR_LOG("CSipHeaderStrategyBase::NoMatchL") |
|
177 CSIPResponse* response = NULL; |
|
178 if ( !aClientResolver2.ClientsData().Count() ) |
|
179 { |
|
180 response = NextStrategy2L( aRequest,aUids,aContinueSearch, |
|
181 aClientResolver2 ); |
|
182 } |
|
183 return response; |
|
184 } |
|
185 |
|
186 // ---------------------------------------------------------------------------- |
|
187 // CSipHeaderStrategyBase::MoreThanOneMatchL |
|
188 // ---------------------------------------------------------------------------- |
|
189 // |
|
190 CSIPResponse* CSipHeaderStrategyBase::MoreThanOneMatchL( CSIPRequest& aRequest, |
|
191 RArray<TUid>& aUids, |
|
192 TBool& aContinueSearch, |
|
193 CSIPClientResolver2& aClientResolver2 ) |
|
194 { |
|
195 SIP_CR_LOG("CSipHeaderStrategyBase::MoreThanOneMatchL") |
|
196 CSIPResponse* response = NULL; |
|
197 if ( iNextStrategy && aClientResolver2.ClientsData().Count() > 1 ) |
|
198 { |
|
199 response = NextStrategyL( aRequest,aUids,aContinueSearch, |
|
200 aClientResolver2 ); |
|
201 } |
|
202 return response; |
|
203 } |
|
204 |
|
205 // ---------------------------------------------------------------------------- |
|
206 // CSipHeaderStrategyBase::MatchResolvedClientsL |
|
207 // ---------------------------------------------------------------------------- |
|
208 // |
|
209 TBool CSipHeaderStrategyBase::MatchResolvedClientL( |
|
210 CSIPResolvedClient2& /*aClient*/, |
|
211 CSIPRequest& /*aRequest*/, |
|
212 TUid& /*aUids*/, |
|
213 const CUri8& /*aUri8*/ ) |
|
214 { |
|
215 return EFalse; |
|
216 } |
|
217 |
|
218 // ---------------------------------------------------------------------------- |
|
219 // CSipHeaderStrategyBase::EliminateClientsL |
|
220 // ---------------------------------------------------------------------------- |
|
221 // |
|
222 void CSipHeaderStrategyBase::EliminateClientsL( |
|
223 CSIPRequest& aRequest, |
|
224 RArray<TUid>& aUids ) |
|
225 { |
|
226 for ( TInt i=0; i < aUids.Count();i++ ) |
|
227 { |
|
228 MSipClient* client = iSipClients.GetByUID( aUids[i] ); |
|
229 if ( client && !CompareHeaders( aRequest,*client) ) |
|
230 { |
|
231 aUids.Remove( i ); |
|
232 i--; |
|
233 } |
|
234 } |
|
235 } |
|
236 |
|
237 // ---------------------------------------------------------------------------- |
|
238 // CSipHeaderStrategyBase::CreateResponseL |
|
239 // ---------------------------------------------------------------------------- |
|
240 // |
|
241 CSIPResponse* CSipHeaderStrategyBase::CreateResponseL() |
|
242 { |
|
243 return NULL; |
|
244 } |
|
245 |
|
246 // ---------------------------------------------------------------------------- |
|
247 // CSipHeaderStrategyBase::CompareHeaders |
|
248 // ---------------------------------------------------------------------------- |
|
249 // |
|
250 TBool CSipHeaderStrategyBase::CompareHeaders( |
|
251 CSIPRequest& /*aRequest*/, |
|
252 MSipClient& /*aClient*/) |
|
253 { |
|
254 // Not implemented for this sub-class |
|
255 return EFalse; |
|
256 } |
|
257 |
|
258 // ---------------------------------------------------------------------------- |
|
259 // CSipHeaderStrategyBase::ContentType |
|
260 // ---------------------------------------------------------------------------- |
|
261 // |
|
262 CSIPContentTypeHeader* CSipHeaderStrategyBase::ContentType( |
|
263 CSIPRequest& aRequest ) |
|
264 { |
|
265 CSIPContentTypeHeader* contentType = NULL; |
|
266 CSIPHeaderBase* header = aRequest.Header( |
|
267 SIPStrings::StringF( SipStrConsts::EContentTypeHeader ),0 ); |
|
268 if ( header ) |
|
269 { |
|
270 contentType = static_cast<CSIPContentTypeHeader*>( header ); |
|
271 } |
|
272 return contentType; |
|
273 } |