|
1 // Copyright (c) 2004-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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include <obex/internal/obexinternalheader.h> |
|
22 #include <obexheaders.h> |
|
23 #include "obexheaderutil.h" |
|
24 |
|
25 /** |
|
26 This function wraps the potential leaving CreateAndSetUnicodeHeaderL function in a |
|
27 handy TRAP, because all the functions that call it are non-leavers. |
|
28 |
|
29 @param aHI is the Header Information byte for this new header (2 MSBits should indicate a Unicode header) |
|
30 @param aUnicode is the Header Value for this new header |
|
31 |
|
32 @return A pointer to a new CObexHeader, or NULL if the construction failed. |
|
33 */ |
|
34 CObexHeader* IrOBEXHeaderUtil::CreateAndSetUnicodeHeader(const TUint8 aHI, const TDesC16& aUnicode) |
|
35 { |
|
36 CObexHeader* header = NULL; |
|
37 TRAP_IGNORE(header = CreateAndSetUnicodeHeaderL(aHI, aUnicode)); |
|
38 return header; |
|
39 } |
|
40 |
|
41 /** |
|
42 Creates a new Unicode header, with value as specified by aHI and aUnicode. This function will |
|
43 leave if construction of the header fails. |
|
44 |
|
45 @param aHI is the Header Information byte for this new header (2 MSBits should indicate a Unicode header) |
|
46 @param aUnicode is the Header Value for this new header |
|
47 |
|
48 @return A pointer to a new CObexHeader. |
|
49 */ |
|
50 CObexHeader* IrOBEXHeaderUtil::CreateAndSetUnicodeHeaderL(const TUint8 aHI, const TDesC16& aUnicode) |
|
51 { |
|
52 CObexHeader* header = CObexHeader::NewL(); |
|
53 CleanupStack::PushL(header); |
|
54 header->SetUnicodeL(aHI, aUnicode); |
|
55 CleanupStack::Pop(header); |
|
56 return header; |
|
57 } |
|
58 |
|
59 /** |
|
60 This function wraps the potential leaving CreateAndSetByteSeqHeaderL function in a |
|
61 handy TRAP, because all the functions that call it are non-leavers. |
|
62 |
|
63 @param aHI is the Header Information byte for this new header (2 MSBits should indicate a Unicode header) |
|
64 @param aByteSeq is the Header Value for this new header |
|
65 |
|
66 @return A pointer to a new CObexHeader, or NULL if the construction failed. |
|
67 */ |
|
68 CObexHeader* IrOBEXHeaderUtil::CreateAndSetByteSeqHeader(const TUint8 aHI, const TDesC8& aByteSeq) |
|
69 { |
|
70 CObexHeader* header = NULL; |
|
71 TRAP_IGNORE(header = CreateAndSetByteSeqHeaderL(aHI, aByteSeq)); |
|
72 return header; |
|
73 } |
|
74 |
|
75 /** |
|
76 Creates a new Byte Sequence header, with value as specified by aHI and aByteSeq. This function will |
|
77 leave if construction of the header fails. |
|
78 |
|
79 @param aHI is the Header Information byte for this new header (2 MSBits should indicate a Unicode header) |
|
80 @param aByteSeq is the Header Value for this new header |
|
81 |
|
82 @return A pointer to a new CObexHeader. |
|
83 */ |
|
84 CObexHeader* IrOBEXHeaderUtil::CreateAndSetByteSeqHeaderL(const TUint8 aHI, const TDesC8& aByteSeq) |
|
85 { |
|
86 CObexHeader* header = CObexHeader::NewL(); |
|
87 CleanupStack::PushL(header); |
|
88 header->SetByteSeqL(aHI, aByteSeq); |
|
89 CleanupStack::Pop(header); |
|
90 return header; |
|
91 } |
|
92 |
|
93 TInt IrOBEXHeaderUtil::ParseHeader(TObexInternalHeader& aHeader, CObexHeaderSet& aHeaderSet) |
|
94 { |
|
95 TUint headerType = aHeader.HIType(); |
|
96 |
|
97 switch (headerType) |
|
98 { |
|
99 case (TObexInternalHeader::EUnicode) : |
|
100 { |
|
101 HBufC* newHeader = HBufC::New(aHeader.HVSize()); |
|
102 if (!newHeader) |
|
103 { |
|
104 return KErrNoMemory; |
|
105 } |
|
106 //else |
|
107 TPtr ptr(newHeader->Des()); |
|
108 |
|
109 if(aHeader.GetHVText(ptr) == KErrNone) |
|
110 { |
|
111 CObexHeader* unicodeHeader = NULL; |
|
112 |
|
113 unicodeHeader = IrOBEXHeaderUtil::CreateAndSetUnicodeHeader(aHeader.HI(), *newHeader); |
|
114 |
|
115 if (!unicodeHeader) |
|
116 { |
|
117 delete newHeader; |
|
118 newHeader = NULL; |
|
119 return KErrNoMemory; |
|
120 } |
|
121 |
|
122 //Transfer ownership of pointer to CObexHeaderSet |
|
123 if (aHeaderSet.AddHeader(unicodeHeader) != KErrNone) |
|
124 { |
|
125 delete newHeader; |
|
126 newHeader = NULL; |
|
127 delete unicodeHeader; |
|
128 unicodeHeader = NULL; |
|
129 return KErrNoMemory; |
|
130 } |
|
131 } |
|
132 delete newHeader; |
|
133 newHeader = NULL; |
|
134 |
|
135 break; |
|
136 } |
|
137 |
|
138 case (TObexInternalHeader::EByteSeq) : |
|
139 { |
|
140 TPtrC8 src(aHeader.HVByteSeq(), aHeader.HVSize()); |
|
141 |
|
142 CObexHeader* byteseqHeader = NULL; |
|
143 |
|
144 byteseqHeader = IrOBEXHeaderUtil::CreateAndSetByteSeqHeader(aHeader.HI(), src); |
|
145 if (!byteseqHeader) |
|
146 { |
|
147 return KErrNoMemory; |
|
148 } |
|
149 |
|
150 //Transfer ownership of pointer to CObexHeaderSet |
|
151 if (aHeaderSet.AddHeader(byteseqHeader) != KErrNone) |
|
152 { |
|
153 delete byteseqHeader; |
|
154 byteseqHeader = NULL; |
|
155 return KErrNoMemory; |
|
156 } |
|
157 |
|
158 break; |
|
159 } |
|
160 |
|
161 case (TObexInternalHeader::E1Byte) : |
|
162 { |
|
163 CObexHeader* byteHeader = NULL; |
|
164 TRAPD(err, byteHeader=CObexHeader::NewL()); |
|
165 if (err) |
|
166 { |
|
167 return err; |
|
168 } |
|
169 |
|
170 byteHeader->SetByte(aHeader.HI(), (static_cast<TUint8>(aHeader.HVInt()))); |
|
171 //Transfer ownership of pointer to CObexHeaderSet |
|
172 if(aHeaderSet.AddHeader(byteHeader) != KErrNone) |
|
173 { |
|
174 delete byteHeader; |
|
175 byteHeader = NULL; |
|
176 return KErrNoMemory; |
|
177 } |
|
178 break; |
|
179 } |
|
180 |
|
181 case (TObexInternalHeader::E4Byte) : |
|
182 { |
|
183 CObexHeader* fourByteHeader = NULL; |
|
184 TRAPD(err, fourByteHeader = CObexHeader::NewL()); |
|
185 if (err) |
|
186 { |
|
187 return err; |
|
188 } |
|
189 |
|
190 fourByteHeader->SetFourByte(aHeader.HI(), aHeader.HVInt()); |
|
191 //Transfer ownership of pointer to CObexHeaderSet |
|
192 if(aHeaderSet.AddHeader(fourByteHeader) != KErrNone) |
|
193 { |
|
194 delete fourByteHeader; |
|
195 fourByteHeader = NULL; |
|
196 return KErrNoMemory; |
|
197 } |
|
198 break; |
|
199 } |
|
200 |
|
201 default : |
|
202 { |
|
203 break; |
|
204 } |
|
205 |
|
206 } // End of switch |
|
207 |
|
208 return KErrNone; |
|
209 } |