|
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 : CSipCSServerITC.cpp |
|
15 // Part of : SIPServerCore |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include "CSipCSServerITC.h" |
|
23 #include "CSIPCSSerializer.h" |
|
24 #include "SipCSServer.pan" |
|
25 #include "siprequest.h" |
|
26 #include "sipresponse.h" |
|
27 #include "siprouteheader.h" |
|
28 #include "sipfromheader.h" |
|
29 #include "TSIPRemoteTargetAndProxy.h" |
|
30 #include "uricontainer.h" |
|
31 #include "SipLogs.h" |
|
32 |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CSipCSServerITC::NewL |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CSipCSServerITC* CSipCSServerITC::NewL () |
|
39 { |
|
40 CSipCSServerITC* self = CSipCSServerITC::NewLC (); |
|
41 CleanupStack::Pop(self); |
|
42 return self; |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CSipCSServerITC::NewLC |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CSipCSServerITC* CSipCSServerITC::NewLC () |
|
50 { |
|
51 CSipCSServerITC* self = new (ELeave) CSipCSServerITC; |
|
52 CleanupStack::PushL (self); |
|
53 self->ConstructL(); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CSipCSServerITC::CSipCSServerITC |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CSipCSServerITC::CSipCSServerITC () |
|
62 { |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CSipCSServerITC::ConstructL |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 void CSipCSServerITC::ConstructL () |
|
70 { |
|
71 iSerializer = CSIPCSSerializer::NewL(); |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CSipCSServerITC::~CSipCSServerITC |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 CSipCSServerITC::~CSipCSServerITC () |
|
79 { |
|
80 delete iSerializer; |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CSipCSServerITC::Serializer |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 CSIPCSSerializer& CSipCSServerITC::Serializer () |
|
88 { |
|
89 return *iSerializer; |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CSipCSServerITC::WriteL |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 void CSipCSServerITC::WriteL (const RMessage2& aMessage, |
|
97 CBufFlat& aSipHeaders) const |
|
98 { |
|
99 TPtr8 headerBufPtr = aSipHeaders.Ptr(0); |
|
100 WriteL(ESipItcArgMessageHeaders,aMessage,headerBufPtr); |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CSipCSServerITC::WriteL |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void CSipCSServerITC::WriteL (const RMessage2& aMessage, |
|
108 const TDesC8& aDes, |
|
109 TSipItcArguments aItcArgIndex) const |
|
110 { |
|
111 WriteL(aItcArgIndex,aMessage,aDes); |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CSipCSServerITC::WriteL |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CSipCSServerITC::WriteL (const RMessage2& aMessage, |
|
119 const TSIPIds& aIds) const |
|
120 { |
|
121 TPckgBuf<TSIPIds> sipIdsPckg(aIds); |
|
122 WriteL(ESipItcArgIds, aMessage, sipIdsPckg); |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CSipCSServerITC::WriteL |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 void CSipCSServerITC::WriteL (const RMessage2& aMessage, |
|
130 const TSIPMessageBufSizes aSizes) const |
|
131 { |
|
132 TPckgBuf<TSIPMessageBufSizes> bufSizesPckg(aSizes); |
|
133 WriteL(ESipItcArgBufSizes, aMessage, bufSizesPckg); |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CSipCSServerITC::WriteL |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 void CSipCSServerITC::WriteL (const RMessage2& aMessage, |
|
141 const CSIPHeaderBase& aHeader) const |
|
142 { |
|
143 CBufFlat* headerBuf = iSerializer->ExternalizeValueLC(aHeader); |
|
144 TPtr8 headerBufPtr(headerBuf->Ptr(0)); |
|
145 WriteL(ESipItcArgMessageHeaders,aMessage,headerBufPtr); |
|
146 CleanupStack::PopAndDestroy(headerBuf); |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CSipCSServerITC::WriteL |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 void CSipCSServerITC::WriteL (const RMessage2& aMessage, |
|
154 TInt aValue, |
|
155 TSipItcArguments aItcArgIndex) const |
|
156 { |
|
157 TPckg<TInt> handlePckg(aValue); |
|
158 WriteL(aItcArgIndex, aMessage, handlePckg); |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CSipCSServerITC::WriteL |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 void CSipCSServerITC::WriteL (const RMessage2& aMessage, |
|
166 CSIPConnection::TState aState) const |
|
167 { |
|
168 TPckg<CSIPConnection::TState> statePckg(aState); |
|
169 WriteL(ESipItcArgConnectionState, aMessage, statePckg); |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CSipCSServerITC::WriteL |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 void CSipCSServerITC::WriteL (const RMessage2& aMessage, |
|
177 MDesC8Array& aSecurityMechanisms) const |
|
178 { |
|
179 CBufFlat* buf = iSerializer->ExternalizeLC(aSecurityMechanisms); |
|
180 TPtr8 bufPtr = buf->Ptr(0); |
|
181 WriteL(ESipItcArgAuthenticationMechanism, aMessage, bufPtr); |
|
182 CleanupStack::PopAndDestroy(buf); |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CSipCSServerITC::WriteL |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 void CSipCSServerITC::WriteL (const RMessage2& aMessage, |
|
190 const TInetAddr& aInetAddr) const |
|
191 { |
|
192 TPckgBuf<TInetAddr> addrPckg(aInetAddr); |
|
193 WriteL(ESipItcArgLocalAddr, aMessage, addrPckg); |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CSipCSServerITC::ReadAppUidL |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 TUid CSipCSServerITC::ReadAppUidL (const RMessage2& aMessage) const |
|
201 { |
|
202 TPckgBuf<TUid> appUidPckg; |
|
203 aMessage.ReadL(ESipItcArgAppUid, appUidPckg); |
|
204 return appUidPckg(); |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CSipCSServerITC::ReadRequestL |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 void CSipCSServerITC::ReadRequestL (const RMessage2& aMessage, |
|
212 CSIPRequest& aRequest, |
|
213 TBool aMethodExpected) const |
|
214 { |
|
215 HBufC8* headers = ReadLC(aMessage,ESipItcArgMessageHeaders); |
|
216 if (headers->Length() > 0) |
|
217 { |
|
218 iSerializer->InternalizeL(*headers,aRequest,aMethodExpected); |
|
219 } |
|
220 CleanupStack::PopAndDestroy(headers); |
|
221 HBufC8* content = ReadL(aMessage,ESipItcArgMessageContent); |
|
222 aRequest.SetContent(content); |
|
223 __SIP_MESSAGE_LOG("ServerCore",aRequest) |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // CSipCSServerITC::ReadRequestL |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 void |
|
231 CSipCSServerITC::ReadRequestL (const RMessage2& aMessage, |
|
232 CSIPRequest& aRequest, |
|
233 TSIPRemoteTargetAndProxy& aRemoteTargetAndProxy, |
|
234 TBool aMethodExpected, |
|
235 TBool aProxyExpected) const |
|
236 { |
|
237 HBufC8* headers = ReadLC(aMessage,ESipItcArgMessageHeaders); |
|
238 if (headers->Length() == 0) |
|
239 { |
|
240 User::Leave(KErrArgument); |
|
241 } |
|
242 iSerializer->InternalizeL(*headers,aRequest,aRemoteTargetAndProxy, |
|
243 aMethodExpected,aProxyExpected); |
|
244 CleanupStack::PopAndDestroy(headers); |
|
245 CleanupStack::PushL(aRemoteTargetAndProxy.iRemoteTarget); |
|
246 CleanupStack::PushL(aRemoteTargetAndProxy.iProxy); |
|
247 HBufC8* content = ReadL(aMessage,ESipItcArgMessageContent); |
|
248 aRequest.SetContent(content); |
|
249 CleanupStack::Pop(aRemoteTargetAndProxy.iProxy); |
|
250 CleanupStack::Pop(aRemoteTargetAndProxy.iRemoteTarget); |
|
251 __SIP_MESSAGE_LOG("ServerCore",aRequest) |
|
252 } |
|
253 |
|
254 // ----------------------------------------------------------------------------- |
|
255 // CSipCSServerITC::ReadResponseLC |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 CSIPResponse* CSipCSServerITC::ReadResponseLC (const RMessage2& aMessage) const |
|
259 { |
|
260 HBufC8* headers = ReadLC(aMessage,ESipItcArgMessageHeaders); |
|
261 if (headers->Length() == 0) |
|
262 { |
|
263 User::Leave(KErrArgument); |
|
264 } |
|
265 CSIPResponse* response = iSerializer->InternalizeL(*headers); |
|
266 CleanupStack::PopAndDestroy(headers); |
|
267 CleanupStack::PushL(response); |
|
268 HBufC8* content = ReadL(aMessage,ESipItcArgMessageContent); |
|
269 response->SetContent(content); |
|
270 __SIP_MESSAGE_LOG("ServerCore",*response) |
|
271 return response; |
|
272 } |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // CSipCSServerITC::ReadProxyLC |
|
276 // ----------------------------------------------------------------------------- |
|
277 // |
|
278 CSIPRouteHeader* CSipCSServerITC::ReadProxyLC (const RMessage2& aMessage) const |
|
279 { |
|
280 HBufC8* proxyBuf = ReadLC(aMessage,ESipItcArgMessageHeaders); |
|
281 if (proxyBuf->Length() == 0) |
|
282 { |
|
283 User::Leave(KErrArgument); |
|
284 } |
|
285 CSIPRouteHeader* proxy = iSerializer->InternalizeProxyL(*proxyBuf); |
|
286 CleanupStack::PopAndDestroy(proxyBuf); |
|
287 CleanupStack::PushL(proxy); |
|
288 return proxy; |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CSipCSServerITC::ReadSipIdsL |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 TSIPIds CSipCSServerITC::ReadSipIdsL (const RMessage2& aMessage) const |
|
296 { |
|
297 TPckgBuf<TSIPIds> sipIdsPckg; |
|
298 aMessage.ReadL(ESipItcArgIds, sipIdsPckg); |
|
299 return sipIdsPckg(); |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CSipCSServerITC::ReadSIPSockOptL |
|
304 // ----------------------------------------------------------------------------- |
|
305 // |
|
306 TSIPSockOpt CSipCSServerITC::ReadSIPSockOptL (const RMessage2& aMessage) const |
|
307 { |
|
308 TPckgBuf<TSIPSockOpt> sipSockOptPckg; |
|
309 aMessage.ReadL(ESipItcArgSockOpt, sipSockOptPckg); |
|
310 return sipSockOptPckg(); |
|
311 } |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CSipCSServerITC::ReadL |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 void CSipCSServerITC::ReadL (const RMessage2& aMessage, |
|
318 TInt& aValue, |
|
319 TSipItcArguments aItcArgIndex) const |
|
320 { |
|
321 aValue = ITCArgInt(aItcArgIndex,aMessage); |
|
322 } |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CSipCSServerITC::ReadLC |
|
326 // ----------------------------------------------------------------------------- |
|
327 // |
|
328 HBufC8* CSipCSServerITC::ReadLC (const RMessage2& aMessage, |
|
329 TSipItcArguments aItcArgIndex) const |
|
330 { |
|
331 TInt length = aMessage.GetDesLength (aItcArgIndex); |
|
332 if (length < 0) |
|
333 { |
|
334 User::Leave (KErrBadDescriptor); |
|
335 } |
|
336 HBufC8* buf = HBufC8::NewLC (length); |
|
337 if (length > 0) |
|
338 { |
|
339 TPtr8 bufPtr(buf->Des()); |
|
340 aMessage.ReadL (aItcArgIndex, bufPtr); |
|
341 } |
|
342 return buf; |
|
343 } |
|
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // CSipCSServerITC::ReadCredentialsLC |
|
347 // ----------------------------------------------------------------------------- |
|
348 // |
|
349 CDesC8Array* |
|
350 CSipCSServerITC::ReadCredentialsLC (const RMessage2& aMessage) const |
|
351 { |
|
352 HBufC8* credentialsBuf = ReadLC(aMessage,ESipItcArgCredentials); |
|
353 CDesC8Array* credentials = |
|
354 iSerializer->InternalizeCredentialsL(*credentialsBuf); |
|
355 CleanupStack::Pop(credentialsBuf); |
|
356 CleanupStack::PushL(credentials); |
|
357 return credentials; |
|
358 } |
|
359 |
|
360 // ----------------------------------------------------------------------------- |
|
361 // CSipCSServerITC::Complete |
|
362 // ----------------------------------------------------------------------------- |
|
363 // |
|
364 void CSipCSServerITC::Complete (const RMessage2& aMessage, |
|
365 TInt aCompletionCode) const |
|
366 { |
|
367 aMessage.Complete (aCompletionCode); |
|
368 } |
|
369 |
|
370 // ----------------------------------------------------------------------------- |
|
371 // CSipCSServerITC::PanicClient |
|
372 // ----------------------------------------------------------------------------- |
|
373 // |
|
374 void CSipCSServerITC::PanicClient(const RMessage2& aMessage, TInt aPanic) const |
|
375 { |
|
376 RThread client; |
|
377 aMessage.Client(client); |
|
378 client.Panic(KSipCSServerPanic, aPanic); |
|
379 } |
|
380 |
|
381 // ----------------------------------------------------------------------------- |
|
382 // CSipCSServerITC::ITCArgPtr |
|
383 // ----------------------------------------------------------------------------- |
|
384 // |
|
385 const TAny* CSipCSServerITC::ITCArgPtr (TSipItcArguments aItcArgIndex, |
|
386 const RMessage2& aMessage) const |
|
387 { |
|
388 const TAny* ptr; |
|
389 switch (static_cast<TInt>(aItcArgIndex)) |
|
390 { |
|
391 case 0: ptr = aMessage.Ptr0(); break; |
|
392 case 1: ptr = aMessage.Ptr1(); break; |
|
393 case 2: ptr = aMessage.Ptr2(); break; |
|
394 case 3: ptr = aMessage.Ptr3(); break; |
|
395 default: ptr = 0; break; |
|
396 } |
|
397 return ptr; |
|
398 } |
|
399 |
|
400 // ----------------------------------------------------------------------------- |
|
401 // CSipCSServerITC::ITCArgInt |
|
402 // ----------------------------------------------------------------------------- |
|
403 // |
|
404 TInt CSipCSServerITC::ITCArgInt (TSipItcArguments aItcArgIndex, |
|
405 const RMessage2& aMessage) const |
|
406 { |
|
407 TInt integer; |
|
408 switch (static_cast<TInt>(aItcArgIndex)) |
|
409 { |
|
410 case 0: integer = aMessage.Int0(); break; |
|
411 case 1: integer = aMessage.Int1(); break; |
|
412 case 2: integer = aMessage.Int2(); break; |
|
413 case 3: integer = aMessage.Int3(); break; |
|
414 default: integer = KErrArgument; break; |
|
415 } |
|
416 return integer; |
|
417 } |
|
418 |
|
419 // ----------------------------------------------------------------------------- |
|
420 // CSipCSServerITC::WriteL |
|
421 // ----------------------------------------------------------------------------- |
|
422 // |
|
423 void CSipCSServerITC::WriteL (TSipItcArguments aItcArgIndex, |
|
424 const RMessage2& aMessage, |
|
425 const TDesC8& aDes) const |
|
426 { |
|
427 TInt length = aMessage.GetDesMaxLength(aItcArgIndex); |
|
428 if (length < 0) |
|
429 { |
|
430 User::Leave (KErrArgument); |
|
431 } |
|
432 if (length < aDes.Length()) |
|
433 { |
|
434 User::Leave (KErrOverflow); |
|
435 } |
|
436 aMessage.WriteL (aItcArgIndex, aDes); |
|
437 } |
|
438 |
|
439 // ----------------------------------------------------------------------------- |
|
440 // CSipCSServerITC::ReadL |
|
441 // ----------------------------------------------------------------------------- |
|
442 // |
|
443 HBufC8* CSipCSServerITC::ReadL (const RMessage2& aMessage, |
|
444 TSipItcArguments aItcArgIndex) const |
|
445 { |
|
446 HBufC8* buf = ReadLC(aMessage,aItcArgIndex); |
|
447 CleanupStack::Pop(buf); |
|
448 return buf; |
|
449 } |