|
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 : SIPCRSerializer.cpp |
|
15 // Part of : SIP Client Resolver |
|
16 // Version : 1.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include "SIPCRSerializer.h" |
|
23 #include "sipstrings.h" |
|
24 #include "siprequest.h" |
|
25 #include "sipresponse.h" |
|
26 #include "uricontainer.h" |
|
27 |
|
28 |
|
29 const TInt KBufExpandSize=100; |
|
30 |
|
31 // ---------------------------------------------------------------------------- |
|
32 // SIPCRSerializer::ExternalizeL |
|
33 // ---------------------------------------------------------------------------- |
|
34 // |
|
35 CBufFlat* SIPCRSerializer::ExternalizeL(CSIPRequest& aRequest) |
|
36 { |
|
37 CBufFlat* buf = CBufFlat::NewL(KBufExpandSize); |
|
38 CleanupStack::PushL(buf); |
|
39 RBufWriteStream writeStream(*buf,0); |
|
40 writeStream.PushL(); |
|
41 writeStream.WriteUint16L(aRequest.Method().DesC().Length()); |
|
42 writeStream.WriteL (aRequest.Method().DesC()); |
|
43 CURIContainer* uriContainer = aRequest.RequestURI(); |
|
44 if (uriContainer) |
|
45 { |
|
46 uriContainer->ExternalizeL(writeStream); |
|
47 } |
|
48 aRequest.ExternalizeHeadersL(writeStream); |
|
49 writeStream.Pop(); |
|
50 writeStream.Close(); |
|
51 CleanupStack::Pop(buf); |
|
52 return buf; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // SIPCRSerializer::InternalizeL |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 void SIPCRSerializer::InternalizeL(const TDesC8& aDes, CSIPRequest& aRequest) |
|
60 { |
|
61 RDesReadStream readStream(aDes); |
|
62 CleanupClosePushL (readStream); |
|
63 |
|
64 InternalizeMethodL (aRequest,readStream); |
|
65 |
|
66 CURIContainer* uriContainer = CURIContainer::InternalizeL(readStream); |
|
67 CleanupStack::PushL(uriContainer); |
|
68 aRequest.SetRequestURIL(uriContainer); |
|
69 CleanupStack::Pop(uriContainer); |
|
70 |
|
71 aRequest.InternalizeHeadersL(readStream); |
|
72 |
|
73 readStream.Pop(); |
|
74 readStream.Close(); |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // SIPCRSerializer::ExternalizeL |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 CBufFlat* SIPCRSerializer::ExternalizeL(CSIPResponse& aResponse) |
|
82 { |
|
83 CBufFlat* buf = CBufFlat::NewL(KBufExpandSize); |
|
84 CleanupStack::PushL(buf); |
|
85 RBufWriteStream writeStream(*buf,0); |
|
86 writeStream.PushL(); |
|
87 |
|
88 writeStream.WriteUint16L(aResponse.ResponseCode()); |
|
89 |
|
90 TPtrC8 des(aResponse.ReasonPhrase().DesC()); |
|
91 writeStream.WriteUint32L(des.Length()); |
|
92 writeStream.WriteL(des); |
|
93 |
|
94 aResponse.ExternalizeHeadersL(writeStream); |
|
95 |
|
96 writeStream.Pop(); |
|
97 writeStream.Close(); |
|
98 CleanupStack::Pop(buf); |
|
99 return buf; |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // SIPCRSerializer::InternalizeMethodL |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void SIPCRSerializer::InternalizeMethodL(CSIPRequest& aRequest, |
|
107 RReadStream& aReadStream) |
|
108 { |
|
109 RStringF method = ReadFromStreamL(aReadStream); |
|
110 CleanupClosePushL(method); |
|
111 aRequest.SetMethodL(method); |
|
112 CleanupStack::PopAndDestroy(1); // method |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // SIPCRSerializer::ReadFromStreamLC |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 RStringF SIPCRSerializer::ReadFromStreamL(RReadStream& aReadStream) |
|
120 { |
|
121 TUint16 bufLength = aReadStream.ReadUint16L(); |
|
122 HBufC8* buf = HBufC8::NewLC (bufLength); |
|
123 TPtr8 bufPtr(buf->Des()); |
|
124 if (bufLength > 0) |
|
125 { |
|
126 aReadStream.ReadL (bufPtr,bufLength); |
|
127 } |
|
128 else |
|
129 { |
|
130 } |
|
131 RStringF str = SIPStrings::Pool().OpenFStringL(bufPtr); |
|
132 CleanupStack::PopAndDestroy(buf); |
|
133 return str; |
|
134 } |
|
135 |
|
136 // End of File |