sl@0
|
1 |
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <authority8.h>
|
sl@0
|
17 |
#include <authority16.h>
|
sl@0
|
18 |
#include "CAuthorityInternal.h"
|
sl@0
|
19 |
#include <uriutilscommon.h>
|
sl@0
|
20 |
#include <escapeutils.h>
|
sl@0
|
21 |
#include <uriutils.h>
|
sl@0
|
22 |
|
sl@0
|
23 |
|
sl@0
|
24 |
//
|
sl@0
|
25 |
//
|
sl@0
|
26 |
// Implementation of CAuthority8
|
sl@0
|
27 |
//
|
sl@0
|
28 |
//
|
sl@0
|
29 |
|
sl@0
|
30 |
/**
|
sl@0
|
31 |
Static factory constructor. Uses two phase construction and leaves nothing on the
|
sl@0
|
32 |
CleanupStack. Creates an authority object which is a copy of the input parameter
|
sl@0
|
33 |
aAuthority.
|
sl@0
|
34 |
|
sl@0
|
35 |
@since 6.0
|
sl@0
|
36 |
@param aAuthority A reference to a parsed authority object.
|
sl@0
|
37 |
@return A pointer to the newly created CAuthority8 object.
|
sl@0
|
38 |
@post A fully constructed and initialized CAuthority8 object.
|
sl@0
|
39 |
*/
|
sl@0
|
40 |
EXPORT_C CAuthority8* CAuthority8::NewL(const TAuthorityC8& aAuthority)
|
sl@0
|
41 |
{
|
sl@0
|
42 |
CAuthority8* self = CAuthority8::NewLC(aAuthority);
|
sl@0
|
43 |
CleanupStack::Pop(self);
|
sl@0
|
44 |
return self;
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
/**
|
sl@0
|
48 |
Static factory constructor. Uses two phase construction and leaves a pointer to created
|
sl@0
|
49 |
object on the CleanupStack. Creates an authority object which is a copy of the input
|
sl@0
|
50 |
parameter aAuthority.
|
sl@0
|
51 |
|
sl@0
|
52 |
@since 6.0
|
sl@0
|
53 |
@param aAuthority A reference to a parsed authority object.
|
sl@0
|
54 |
@return A pointer to the newly created CAuthority8 object.
|
sl@0
|
55 |
@post A fully constructed and initialized CAuthority8 object.
|
sl@0
|
56 |
*/
|
sl@0
|
57 |
EXPORT_C CAuthority8* CAuthority8::NewLC(const TAuthorityC8& aAuthority)
|
sl@0
|
58 |
{
|
sl@0
|
59 |
CAuthority8* self = new (ELeave) CAuthority8(aAuthority);
|
sl@0
|
60 |
CleanupStack::PushL(self);
|
sl@0
|
61 |
self->ConstructL();
|
sl@0
|
62 |
return self;
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
/**
|
sl@0
|
66 |
Static factory constructor. Uses two phase construction and leaves nothing on the CleanupStack.
|
sl@0
|
67 |
Creates an authority object which is empty.
|
sl@0
|
68 |
|
sl@0
|
69 |
@since 6.0
|
sl@0
|
70 |
@return A pointer to the newly created CAuthority8 object.
|
sl@0
|
71 |
@post A fully constructed and initialized CAuthority8 object.
|
sl@0
|
72 |
*/
|
sl@0
|
73 |
EXPORT_C CAuthority8* CAuthority8::NewL()
|
sl@0
|
74 |
{
|
sl@0
|
75 |
CAuthority8* self = CAuthority8::NewLC();
|
sl@0
|
76 |
CleanupStack::Pop(self);
|
sl@0
|
77 |
return self;
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
/**
|
sl@0
|
81 |
Static factory constructor. Uses two phase construction and leaves a pointer to created object on
|
sl@0
|
82 |
the CleanupStack. Creates an authority object which is empty.
|
sl@0
|
83 |
|
sl@0
|
84 |
@since 6.0
|
sl@0
|
85 |
@return A pointer to the newly created CAuthority8 object.
|
sl@0
|
86 |
@post A fully constructed and initialized CAuthority8 object.
|
sl@0
|
87 |
*/
|
sl@0
|
88 |
EXPORT_C CAuthority8* CAuthority8::NewLC()
|
sl@0
|
89 |
{
|
sl@0
|
90 |
CAuthority8* self = new (ELeave) CAuthority8(TAuthorityC8());
|
sl@0
|
91 |
CleanupStack::PushL(self);
|
sl@0
|
92 |
self->ConstructL();
|
sl@0
|
93 |
return self;
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
/**
|
sl@0
|
97 |
Destructor.
|
sl@0
|
98 |
|
sl@0
|
99 |
@since 6.0
|
sl@0
|
100 |
*/
|
sl@0
|
101 |
EXPORT_C CAuthority8::~CAuthority8()
|
sl@0
|
102 |
{
|
sl@0
|
103 |
delete iAuthorityBuf;
|
sl@0
|
104 |
}
|
sl@0
|
105 |
|
sl@0
|
106 |
/**
|
sl@0
|
107 |
Provides a reference to the parsed authority. Allows access to the non-modifying API for TAuthorityC8.
|
sl@0
|
108 |
|
sl@0
|
109 |
@since 6.0
|
sl@0
|
110 |
@return A const reference to the parsed authority object.
|
sl@0
|
111 |
*/
|
sl@0
|
112 |
EXPORT_C const TAuthorityC8& CAuthority8::Authority() const
|
sl@0
|
113 |
{
|
sl@0
|
114 |
return iAuthority;
|
sl@0
|
115 |
}
|
sl@0
|
116 |
|
sl@0
|
117 |
/**
|
sl@0
|
118 |
Sets the specified component in the authority. The component is set to the value given in the argument
|
sl@0
|
119 |
aData. If the specified component already exists then it is replaced with the new value.
|
sl@0
|
120 |
|
sl@0
|
121 |
@since 6.0
|
sl@0
|
122 |
@param aData A descriptor pointer to the new value for the authority component.
|
sl@0
|
123 |
@param aComponent An enum specifying the component to be set.
|
sl@0
|
124 |
@pre Object is fully constructed.
|
sl@0
|
125 |
@post The authority has the specified component set to the new value.
|
sl@0
|
126 |
@Leave KErrArgument If aComponent goes out of range.
|
sl@0
|
127 |
*/
|
sl@0
|
128 |
EXPORT_C void CAuthority8::SetComponentL(const TDesC8& aData, TAuthorityComponent aComponent)
|
sl@0
|
129 |
{
|
sl@0
|
130 |
// Update the appropriate component table entry
|
sl@0
|
131 |
iAuthority.iComponent[aComponent].Set(aData);
|
sl@0
|
132 |
|
sl@0
|
133 |
// Copy to the buffer by forming the Authority
|
sl@0
|
134 |
FormAuthorityL();
|
sl@0
|
135 |
}
|
sl@0
|
136 |
|
sl@0
|
137 |
/**
|
sl@0
|
138 |
Escape encodes the component then sets the specified component in the authority. The component is set to the
|
sl@0
|
139 |
value given in the argument aData. If the specified component already exists then it is replaced with the new
|
sl@0
|
140 |
value.
|
sl@0
|
141 |
|
sl@0
|
142 |
@since 6.0
|
sl@0
|
143 |
@param aData A descriptor pointer to the new value for the authority component.
|
sl@0
|
144 |
@param aComponent An enum specifying the component to be set.
|
sl@0
|
145 |
@pre Object is fully constructed.
|
sl@0
|
146 |
@post The authority has the specified component set to the new value.
|
sl@0
|
147 |
*/
|
sl@0
|
148 |
EXPORT_C void CAuthority8::SetAndEscapeComponentL(const TDesC8& aData, TAuthorityComponent aComponent)
|
sl@0
|
149 |
{
|
sl@0
|
150 |
// Create escaped version of component
|
sl@0
|
151 |
HBufC8* escaped = EscapeUtils::EscapeEncodeL(aData, EscapeUtils::EEscapeAuth);
|
sl@0
|
152 |
CleanupStack::PushL(escaped);
|
sl@0
|
153 |
|
sl@0
|
154 |
// Set the component
|
sl@0
|
155 |
if(aComponent<EAuthorityMaxComponents && aComponent >=EAuthorityUserinfo )
|
sl@0
|
156 |
{
|
sl@0
|
157 |
SetComponentL(*escaped, aComponent);
|
sl@0
|
158 |
}
|
sl@0
|
159 |
else
|
sl@0
|
160 |
{
|
sl@0
|
161 |
User::Leave(KErrArgument);
|
sl@0
|
162 |
}
|
sl@0
|
163 |
|
sl@0
|
164 |
// Cleanup
|
sl@0
|
165 |
CleanupStack::PopAndDestroy(escaped);
|
sl@0
|
166 |
}
|
sl@0
|
167 |
|
sl@0
|
168 |
/**
|
sl@0
|
169 |
Removes the specified component from the authority. If the component does not exist then this function does
|
sl@0
|
170 |
nothing.
|
sl@0
|
171 |
|
sl@0
|
172 |
@since 6.0
|
sl@0
|
173 |
@param aComponent An enum specifying the component to be removed.
|
sl@0
|
174 |
@pre Object is fully constructed.
|
sl@0
|
175 |
@post The authority is updated to exclude the specified component.
|
sl@0
|
176 |
*/
|
sl@0
|
177 |
EXPORT_C void CAuthority8::RemoveComponentL(TAuthorityComponent aComponent)
|
sl@0
|
178 |
{
|
sl@0
|
179 |
if( iAuthority.IsPresent(aComponent) )
|
sl@0
|
180 |
{
|
sl@0
|
181 |
// Remove the component - set pointer to NULL and length to zero
|
sl@0
|
182 |
iAuthority.iComponent[aComponent].Set(NULL,0);
|
sl@0
|
183 |
|
sl@0
|
184 |
// Re-form buffer and component table
|
sl@0
|
185 |
FormAuthorityL();
|
sl@0
|
186 |
}
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
/**
|
sl@0
|
190 |
Constructor. First phase of two-phase construction method. Does non-allocating construction.
|
sl@0
|
191 |
|
sl@0
|
192 |
@param aNewAuthority The parsed authority component information from which
|
sl@0
|
193 |
to create the authority.
|
sl@0
|
194 |
@since 6.0
|
sl@0
|
195 |
*/
|
sl@0
|
196 |
CAuthority8::CAuthority8(const TAuthorityC8& aNewAuthority)
|
sl@0
|
197 |
: CBase(), iAuthority(aNewAuthority)
|
sl@0
|
198 |
{
|
sl@0
|
199 |
}
|
sl@0
|
200 |
|
sl@0
|
201 |
/**
|
sl@0
|
202 |
Second phase of two-phase construction method. Does any allocations required to fully construct
|
sl@0
|
203 |
the object.
|
sl@0
|
204 |
|
sl@0
|
205 |
@since 6.0
|
sl@0
|
206 |
@pre First phase of construction is complete.
|
sl@0
|
207 |
@post The object is fully constructed and initialized.
|
sl@0
|
208 |
*/
|
sl@0
|
209 |
void CAuthority8::ConstructL()
|
sl@0
|
210 |
{
|
sl@0
|
211 |
// Create the HBufC8
|
sl@0
|
212 |
FormAuthorityL();
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
/**
|
sl@0
|
216 |
Forms the authority from the parsed authority information. A copy of the parsed authority is created.
|
sl@0
|
217 |
The parsed authority is changed to refer to the copy.
|
sl@0
|
218 |
|
sl@0
|
219 |
@since 6.0
|
sl@0
|
220 |
@pre The parsed authority information is set.
|
sl@0
|
221 |
@post The authority buffer is a copy of the parsed authority, and the
|
sl@0
|
222 |
parsed authority now refers to the copy.
|
sl@0
|
223 |
*/
|
sl@0
|
224 |
void CAuthority8::FormAuthorityL()
|
sl@0
|
225 |
{
|
sl@0
|
226 |
TBool isIPv6Host;
|
sl@0
|
227 |
|
sl@0
|
228 |
// Calculate length of of the Authority
|
sl@0
|
229 |
TInt length = CalculateAuthorityLength(iAuthority.iComponent, isIPv6Host);
|
sl@0
|
230 |
|
sl@0
|
231 |
// Create a temporary buffer and descriptor pointer to it
|
sl@0
|
232 |
HBufC8* buf = HBufC8::NewL(length);
|
sl@0
|
233 |
TPtr8 authority = buf->Des();
|
sl@0
|
234 |
|
sl@0
|
235 |
// Create the authority, updating the internal authority object
|
sl@0
|
236 |
DoFormAuthority(authority, iAuthority.iComponent, isIPv6Host);
|
sl@0
|
237 |
|
sl@0
|
238 |
// Update the internal buffer and descriptor pointer for the authority object
|
sl@0
|
239 |
delete iAuthorityBuf;
|
sl@0
|
240 |
iAuthorityBuf = buf;
|
sl@0
|
241 |
iAuthority.iAuthorityDes.Set(iAuthorityBuf->Des());
|
sl@0
|
242 |
}
|
sl@0
|
243 |
|
sl@0
|
244 |
//
|
sl@0
|
245 |
//
|
sl@0
|
246 |
// Implementation of CAuthority16
|
sl@0
|
247 |
//
|
sl@0
|
248 |
//
|
sl@0
|
249 |
|
sl@0
|
250 |
/**
|
sl@0
|
251 |
Static factory constructor. Uses two phase construction and leaves nothing on the CleanupStack.
|
sl@0
|
252 |
Creates an authority object which is a copy of the input parameter aAuthority.
|
sl@0
|
253 |
|
sl@0
|
254 |
@since 6.0
|
sl@0
|
255 |
@deprecated Deprecated in 9.1
|
sl@0
|
256 |
@param aAuthority A reference to a parsed authority object.
|
sl@0
|
257 |
@return A pointer to the newly created CAuthority16 object.
|
sl@0
|
258 |
@post A fully constructed and initialized CAuthority16 object.
|
sl@0
|
259 |
*/
|
sl@0
|
260 |
EXPORT_C CAuthority16* CAuthority16::NewL(const TAuthorityC16& aAuthority)
|
sl@0
|
261 |
{
|
sl@0
|
262 |
CAuthority16* self = CAuthority16::NewLC(aAuthority);
|
sl@0
|
263 |
CleanupStack::Pop(self);
|
sl@0
|
264 |
return self;
|
sl@0
|
265 |
}
|
sl@0
|
266 |
|
sl@0
|
267 |
/**
|
sl@0
|
268 |
Static factory constructor. Uses two phase construction and leaves a pointer to created object on
|
sl@0
|
269 |
the CleanupStack. Creates an authority object which is a copy of the input parameter aAuthority.
|
sl@0
|
270 |
|
sl@0
|
271 |
@since 6.0
|
sl@0
|
272 |
@deprecated Deprecated in 9.1
|
sl@0
|
273 |
@param aAuthority A reference to a parsed authority object.
|
sl@0
|
274 |
@return A pointer to the newly created CAuthority16 object.
|
sl@0
|
275 |
@post A fully constructed and initialized CAuthority16 object.
|
sl@0
|
276 |
*/
|
sl@0
|
277 |
EXPORT_C CAuthority16* CAuthority16::NewLC(const TAuthorityC16& aAuthority)
|
sl@0
|
278 |
{
|
sl@0
|
279 |
CAuthority16* self = new (ELeave) CAuthority16(aAuthority);
|
sl@0
|
280 |
CleanupStack::PushL(self);
|
sl@0
|
281 |
self->ConstructL();
|
sl@0
|
282 |
return self;
|
sl@0
|
283 |
}
|
sl@0
|
284 |
|
sl@0
|
285 |
/**
|
sl@0
|
286 |
Static factory constructor. Uses two phase construction and leaves nothing on the CleanupStack.
|
sl@0
|
287 |
Creates an authority object which is empty.
|
sl@0
|
288 |
|
sl@0
|
289 |
@since 6.0
|
sl@0
|
290 |
@deprecated Deprecated in 9.1
|
sl@0
|
291 |
@return A pointer to the newly created CAuthority16 object.
|
sl@0
|
292 |
@post A fully constructed and initialized CAuthority16 object.
|
sl@0
|
293 |
*/
|
sl@0
|
294 |
EXPORT_C CAuthority16* CAuthority16::NewL()
|
sl@0
|
295 |
{
|
sl@0
|
296 |
CAuthority16* self = CAuthority16::NewLC();
|
sl@0
|
297 |
CleanupStack::Pop(self);
|
sl@0
|
298 |
return self;
|
sl@0
|
299 |
}
|
sl@0
|
300 |
|
sl@0
|
301 |
/**
|
sl@0
|
302 |
Static factory constructor. Uses two phase construction and leaves a pointer to created object on the
|
sl@0
|
303 |
CleanupStack. Creates an authority object which is empty.
|
sl@0
|
304 |
|
sl@0
|
305 |
@since 6.0
|
sl@0
|
306 |
@deprecated Deprecated in 9.1
|
sl@0
|
307 |
@return A pointer to the newly created CAuthority16 object.
|
sl@0
|
308 |
@post A fully constructed and initialized CAuthority16 object.
|
sl@0
|
309 |
*/
|
sl@0
|
310 |
EXPORT_C CAuthority16* CAuthority16::NewLC()
|
sl@0
|
311 |
{
|
sl@0
|
312 |
CAuthority16* self = new (ELeave) CAuthority16(TAuthorityC16());
|
sl@0
|
313 |
CleanupStack::PushL(self);
|
sl@0
|
314 |
self->ConstructL();
|
sl@0
|
315 |
return self;
|
sl@0
|
316 |
}
|
sl@0
|
317 |
|
sl@0
|
318 |
/**
|
sl@0
|
319 |
Destructor.
|
sl@0
|
320 |
|
sl@0
|
321 |
@since 6.0
|
sl@0
|
322 |
@deprecated Deprecated in 9.1
|
sl@0
|
323 |
*/
|
sl@0
|
324 |
EXPORT_C CAuthority16::~CAuthority16()
|
sl@0
|
325 |
{
|
sl@0
|
326 |
delete iAuthorityBuf;
|
sl@0
|
327 |
}
|
sl@0
|
328 |
|
sl@0
|
329 |
/**
|
sl@0
|
330 |
Provides a reference to the parsed authority. Allows access to the non-modifying API for TAuthorityC.
|
sl@0
|
331 |
|
sl@0
|
332 |
@since 6.0
|
sl@0
|
333 |
@deprecated Deprecated in 9.1
|
sl@0
|
334 |
@return A const reference to the parsed authority object.
|
sl@0
|
335 |
*/
|
sl@0
|
336 |
EXPORT_C const TAuthorityC16& CAuthority16::Authority() const
|
sl@0
|
337 |
{
|
sl@0
|
338 |
return iAuthority;
|
sl@0
|
339 |
}
|
sl@0
|
340 |
|
sl@0
|
341 |
/**
|
sl@0
|
342 |
Sets the specified component in the authority. The component is set to the value given in the argument aData.
|
sl@0
|
343 |
If the specified component already exists then it is replaced with the new value.
|
sl@0
|
344 |
|
sl@0
|
345 |
@since 6.0
|
sl@0
|
346 |
@deprecated Deprecated in 9.1
|
sl@0
|
347 |
@param aData A descriptor pointer to the new value for the authority component.
|
sl@0
|
348 |
@param aComponent An enum specifying the component to be set.
|
sl@0
|
349 |
@pre Object is fully constructed.
|
sl@0
|
350 |
@post The authority has the specified component set to the new value.
|
sl@0
|
351 |
@Leave KErrArgument If aComponent goes out of range.
|
sl@0
|
352 |
*/
|
sl@0
|
353 |
EXPORT_C void CAuthority16::SetComponentL(const TDesC16& aData, TAuthorityComponent aComponent)
|
sl@0
|
354 |
{
|
sl@0
|
355 |
// Update the appropriate component table entry
|
sl@0
|
356 |
iAuthority.iComponent[aComponent].Set(aData);
|
sl@0
|
357 |
|
sl@0
|
358 |
// Copy to the buffer by forming the Authority
|
sl@0
|
359 |
FormAuthorityL();
|
sl@0
|
360 |
}
|
sl@0
|
361 |
|
sl@0
|
362 |
/**
|
sl@0
|
363 |
Escape encodes the component then sets the specified component in the authority. The component is set to the
|
sl@0
|
364 |
value given in the argument aData. If the specified component already exists then it is replaced with the new
|
sl@0
|
365 |
value.
|
sl@0
|
366 |
|
sl@0
|
367 |
@since 6.0
|
sl@0
|
368 |
@deprecated Deprecated in 9.1
|
sl@0
|
369 |
@param aData A descriptor pointer to the new value for the authority component.
|
sl@0
|
370 |
@param aComponent An enum specifying the component to be set.
|
sl@0
|
371 |
@pre Object is fully constructed.
|
sl@0
|
372 |
@post The authority has the specified component set to the new value.
|
sl@0
|
373 |
*/
|
sl@0
|
374 |
EXPORT_C void CAuthority16::SetAndEscapeComponentL(const TDesC16& aData, TAuthorityComponent aComponent)
|
sl@0
|
375 |
{
|
sl@0
|
376 |
// Need to convert to utf8 first
|
sl@0
|
377 |
HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aData);
|
sl@0
|
378 |
CleanupStack::PushL(utf8);
|
sl@0
|
379 |
|
sl@0
|
380 |
// Create escaped version of component
|
sl@0
|
381 |
HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapeAuth);
|
sl@0
|
382 |
CleanupStack::PushL(escaped);
|
sl@0
|
383 |
|
sl@0
|
384 |
// Convert back to 16-bits
|
sl@0
|
385 |
HBufC16* converted = HBufC16::NewLC(escaped->Length());
|
sl@0
|
386 |
converted->Des().Copy(*escaped);
|
sl@0
|
387 |
|
sl@0
|
388 |
// Set the component
|
sl@0
|
389 |
if(aComponent<EAuthorityMaxComponents && aComponent >=EAuthorityUserinfo )
|
sl@0
|
390 |
{
|
sl@0
|
391 |
SetComponentL(*converted, aComponent);
|
sl@0
|
392 |
}
|
sl@0
|
393 |
else
|
sl@0
|
394 |
{
|
sl@0
|
395 |
User::Leave(KErrArgument);
|
sl@0
|
396 |
}
|
sl@0
|
397 |
|
sl@0
|
398 |
// Cleanup
|
sl@0
|
399 |
CleanupStack::PopAndDestroy(3, utf8); // utf8, escaped, converted
|
sl@0
|
400 |
}
|
sl@0
|
401 |
|
sl@0
|
402 |
/**
|
sl@0
|
403 |
Removes the specified component from the authority. If the component does not exist then this
|
sl@0
|
404 |
function does nothing.
|
sl@0
|
405 |
|
sl@0
|
406 |
@since 6.0
|
sl@0
|
407 |
@deprecated Deprecated in 9.1
|
sl@0
|
408 |
@param aComponent An enum specifying the component to be removed.
|
sl@0
|
409 |
@pre Object is fully constructed.
|
sl@0
|
410 |
@post The authority is updated to exclude the specified component.
|
sl@0
|
411 |
*/
|
sl@0
|
412 |
EXPORT_C void CAuthority16::RemoveComponentL(TAuthorityComponent aComponent)
|
sl@0
|
413 |
{
|
sl@0
|
414 |
if( iAuthority.IsPresent(aComponent) )
|
sl@0
|
415 |
{
|
sl@0
|
416 |
// Remove the component - set pointer to NULL and length to zero
|
sl@0
|
417 |
iAuthority.iComponent[aComponent].Set(NULL,0);
|
sl@0
|
418 |
|
sl@0
|
419 |
// Re-form buffer and component table
|
sl@0
|
420 |
FormAuthorityL();
|
sl@0
|
421 |
}
|
sl@0
|
422 |
}
|
sl@0
|
423 |
|
sl@0
|
424 |
/**
|
sl@0
|
425 |
Constructor. First phase of two-phase construction method. Does non-allocating construction.
|
sl@0
|
426 |
|
sl@0
|
427 |
@since 6.0
|
sl@0
|
428 |
@param aNewAuthority The parsed authority component information from which
|
sl@0
|
429 |
to create the authority.
|
sl@0
|
430 |
*/
|
sl@0
|
431 |
CAuthority16::CAuthority16(const TAuthorityC16& aNewAuthority)
|
sl@0
|
432 |
: CBase(), iAuthority(aNewAuthority)
|
sl@0
|
433 |
{
|
sl@0
|
434 |
}
|
sl@0
|
435 |
|
sl@0
|
436 |
/**
|
sl@0
|
437 |
Second phase of two-phase construction method. Does any allocations required to fully construct
|
sl@0
|
438 |
the object.
|
sl@0
|
439 |
|
sl@0
|
440 |
@since 6.0
|
sl@0
|
441 |
@pre First phase of construction is complete.
|
sl@0
|
442 |
@post The object is fully constructed and initialized.
|
sl@0
|
443 |
*/
|
sl@0
|
444 |
void CAuthority16::ConstructL()
|
sl@0
|
445 |
{
|
sl@0
|
446 |
// Create the HBufC16
|
sl@0
|
447 |
FormAuthorityL();
|
sl@0
|
448 |
}
|
sl@0
|
449 |
|
sl@0
|
450 |
/**
|
sl@0
|
451 |
Forms the authority from the parsed authority information. A copy of the parsed authority is created.
|
sl@0
|
452 |
The parsed authority is changed to refer to the copy.
|
sl@0
|
453 |
|
sl@0
|
454 |
@since 6.0
|
sl@0
|
455 |
@pre The parsed authority information is set.
|
sl@0
|
456 |
@post The authority buffer is a copy of the parsed authority, and the
|
sl@0
|
457 |
parsed authority now refers to the copy.
|
sl@0
|
458 |
*/
|
sl@0
|
459 |
void CAuthority16::FormAuthorityL()
|
sl@0
|
460 |
{
|
sl@0
|
461 |
TBool isIPv6Host;
|
sl@0
|
462 |
|
sl@0
|
463 |
// Calculate length of of the Authority
|
sl@0
|
464 |
TInt length = CalculateAuthorityLength(iAuthority.iComponent, isIPv6Host);
|
sl@0
|
465 |
|
sl@0
|
466 |
// Create a temporary buffer and descriptor pointer to it
|
sl@0
|
467 |
HBufC16* buf = HBufC16::NewL(length);
|
sl@0
|
468 |
TPtr16 authority = buf->Des();
|
sl@0
|
469 |
|
sl@0
|
470 |
// Create the authority, updating the internal authority object
|
sl@0
|
471 |
DoFormAuthority(authority, iAuthority.iComponent, isIPv6Host);
|
sl@0
|
472 |
|
sl@0
|
473 |
// Update the internal buffer and descriptor pointer for the authority object
|
sl@0
|
474 |
delete iAuthorityBuf;
|
sl@0
|
475 |
iAuthorityBuf = buf;
|
sl@0
|
476 |
iAuthority.iAuthorityDes.Set(iAuthorityBuf->Des());
|
sl@0
|
477 |
}
|
sl@0
|
478 |
|
sl@0
|
479 |
//
|
sl@0
|
480 |
//
|
sl@0
|
481 |
// Implementation of templated LOCAL functions
|
sl@0
|
482 |
//
|
sl@0
|
483 |
//
|
sl@0
|
484 |
|
sl@0
|
485 |
/**
|
sl@0
|
486 |
Calculates the length of the authority from a list of the components.
|
sl@0
|
487 |
|
sl@0
|
488 |
@since 6.0
|
sl@0
|
489 |
@param aComponent The array of descriptor pointers to the authority
|
sl@0
|
490 |
components.
|
sl@0
|
491 |
@param aIsIPv6Host Specifies ETrue or EFalse.
|
sl@0
|
492 |
@return The length of the authority including the required delimiters.
|
sl@0
|
493 |
*/
|
sl@0
|
494 |
template<class TPtrCType>
|
sl@0
|
495 |
TInt CalculateAuthorityLength(const TPtrCType aComponent[], TBool& aIsIPv6Host)
|
sl@0
|
496 |
{
|
sl@0
|
497 |
aIsIPv6Host = EFalse;
|
sl@0
|
498 |
TInt length=0;
|
sl@0
|
499 |
for( TInt i=0; i<EAuthorityMaxComponents; ++i )
|
sl@0
|
500 |
{
|
sl@0
|
501 |
if( aComponent[i].Ptr() )
|
sl@0
|
502 |
{
|
sl@0
|
503 |
length += aComponent[i].Length();
|
sl@0
|
504 |
// Need to make space for a delimiter if not a host
|
sl@0
|
505 |
if( i != EAuthorityHost )
|
sl@0
|
506 |
++length;
|
sl@0
|
507 |
else
|
sl@0
|
508 |
// Check the host type
|
sl@0
|
509 |
if (UriUtils::HostType(aComponent[i]) == UriUtils::EIPv6Host)
|
sl@0
|
510 |
{
|
sl@0
|
511 |
// If its an IPv6 format host, need to increase the length for the []
|
sl@0
|
512 |
aIsIPv6Host = ETrue;
|
sl@0
|
513 |
length+=2;
|
sl@0
|
514 |
}
|
sl@0
|
515 |
}
|
sl@0
|
516 |
}
|
sl@0
|
517 |
return length;
|
sl@0
|
518 |
}
|
sl@0
|
519 |
|
sl@0
|
520 |
/**
|
sl@0
|
521 |
Templated function to form an authority. The new authority component information is given by
|
sl@0
|
522 |
the input/output argument aComponent. For each authority component that exists in aComponent,
|
sl@0
|
523 |
that component and its appropriate delimiters are appended to aAuthority. Then the components
|
sl@0
|
524 |
in aComponent are updated to refer to the copied versions in aUri.
|
sl@0
|
525 |
|
sl@0
|
526 |
@since 6.0
|
sl@0
|
527 |
@param aAuthority The descriptor pointer to buffer to be appended.
|
sl@0
|
528 |
@param aComponent The array of descriptor pointers to be copied and
|
sl@0
|
529 |
then updated.
|
sl@0
|
530 |
@param aIsIPv6Host Specifies ETrue or EFalse.
|
sl@0
|
531 |
@pre The buffer pointed to by aAuthority should be large enough
|
sl@0
|
532 |
to have the authority components given in aNewComponent copied into it, as well as
|
sl@0
|
533 |
the required delimiters.
|
sl@0
|
534 |
@post The authority buffer will have a copy of the authority defined in
|
sl@0
|
535 |
aNewComponent, and aOldComponent will refer to copies of these components in aAuthority.
|
sl@0
|
536 |
*/
|
sl@0
|
537 |
template<class TPtrType, class TPtrCType>
|
sl@0
|
538 |
void DoFormAuthority(TPtrType& aAuthority, TPtrCType aComponent[], const TBool& aIsIPv6Host)
|
sl@0
|
539 |
{
|
sl@0
|
540 |
if( aComponent[EAuthorityUserinfo].Ptr() )
|
sl@0
|
541 |
{
|
sl@0
|
542 |
// Update the userinfo
|
sl@0
|
543 |
SetUserinfo(aAuthority, aComponent[EAuthorityUserinfo]);
|
sl@0
|
544 |
}
|
sl@0
|
545 |
if( aComponent[EAuthorityHost].Ptr() )
|
sl@0
|
546 |
{
|
sl@0
|
547 |
// Update the host
|
sl@0
|
548 |
SetHost(aAuthority, aComponent[EAuthorityHost], aIsIPv6Host);
|
sl@0
|
549 |
}
|
sl@0
|
550 |
if( aComponent[EAuthorityPort].Ptr() )
|
sl@0
|
551 |
{
|
sl@0
|
552 |
// Update the port
|
sl@0
|
553 |
SetPort(aAuthority, aComponent[EAuthorityPort]);
|
sl@0
|
554 |
}
|
sl@0
|
555 |
}
|
sl@0
|
556 |
|
sl@0
|
557 |
/**
|
sl@0
|
558 |
Templated function to set the userinfo in an authority. The output argument aAuthority points to
|
sl@0
|
559 |
the descriptor buffer into which aNewUserInfo will be copied. The argument aOldUserInfo is updated
|
sl@0
|
560 |
to point to the copied version of aNewUserInfo in aAuthority.
|
sl@0
|
561 |
|
sl@0
|
562 |
@warning This function will panic with KAuthorityErrBufferOverflow if there is not
|
sl@0
|
563 |
enough space in the descriptor to append the component and any required delimiters.
|
sl@0
|
564 |
@since 6.0
|
sl@0
|
565 |
@param aAuthority The descriptor pointer to buffer to be appended.
|
sl@0
|
566 |
@param aUserinfo The descriptor pointer to the userinfo component to be copied
|
sl@0
|
567 |
and then updated.
|
sl@0
|
568 |
@pre The buffer pointed to by aAuthority should be large enough to have
|
sl@0
|
569 |
aNewUserInfo appended to it with the required delimiter.
|
sl@0
|
570 |
@post The authority buffer now includes aNewUserInfo and aOldUserInfo points
|
sl@0
|
571 |
to the copy of the userinfo component in aAuthority.
|
sl@0
|
572 |
*/
|
sl@0
|
573 |
template<class TPtrType, class TPtrCType>
|
sl@0
|
574 |
void SetUserinfo(TPtrType& aAuthority, TPtrCType& aUserinfo)
|
sl@0
|
575 |
{
|
sl@0
|
576 |
// Append the userinfo and delimiter
|
sl@0
|
577 |
aAuthority.Append(aUserinfo);
|
sl@0
|
578 |
aAuthority.Append(KUserinfoDelimiter);
|
sl@0
|
579 |
|
sl@0
|
580 |
// Update the component table
|
sl@0
|
581 |
aUserinfo.Set(aAuthority.Left(aUserinfo.Length()));
|
sl@0
|
582 |
}
|
sl@0
|
583 |
|
sl@0
|
584 |
/**
|
sl@0
|
585 |
Templated function to set the host in an authority. The output argument aAuthority points to the
|
sl@0
|
586 |
descriptor buffer into which aNewHost will be copied. The argument aOldHost is updated to point to
|
sl@0
|
587 |
the copied version of aNewHost in aAuthority.
|
sl@0
|
588 |
|
sl@0
|
589 |
@warning This function will panic with KAuthorityErrBufferOverflow if there is not
|
sl@0
|
590 |
enough space in the descriptor to append the component and any required delimiters.
|
sl@0
|
591 |
@since 6.0
|
sl@0
|
592 |
@param aAuthority The descriptor pointer to buffer to appended.
|
sl@0
|
593 |
@param aHost The descriptor pointer to the host component to be copied
|
sl@0
|
594 |
and then updated.
|
sl@0
|
595 |
@param aIsIPv6Host Specifies ETrue or EFalse.
|
sl@0
|
596 |
@pre The buffer pointed to by aAuthority should be large enough to have
|
sl@0
|
597 |
aNewHost appended to it with the required delimiter.
|
sl@0
|
598 |
@post The authority buffer now includes aNewHost and aOldHost points to the
|
sl@0
|
599 |
copy of the host component in aAuthority.
|
sl@0
|
600 |
*/
|
sl@0
|
601 |
template<class TPtrType, class TPtrCType>
|
sl@0
|
602 |
void SetHost(TPtrType& aAuthority, TPtrCType& aHost, const TBool& aIsIPv6Host)
|
sl@0
|
603 |
{
|
sl@0
|
604 |
if (aIsIPv6Host)
|
sl@0
|
605 |
{
|
sl@0
|
606 |
aAuthority.Append(KIPv6UriOpenBrace);
|
sl@0
|
607 |
aAuthority.Append(aHost);
|
sl@0
|
608 |
aAuthority.Append(KIPv6UriCloseBrace);
|
sl@0
|
609 |
|
sl@0
|
610 |
// Position = (length of uri - length of host) - length of end brace
|
sl@0
|
611 |
aHost.Set( aAuthority.Mid((aAuthority.Length()-aHost.Length())-1, aHost.Length()) );
|
sl@0
|
612 |
}
|
sl@0
|
613 |
else
|
sl@0
|
614 |
{
|
sl@0
|
615 |
// Append the host
|
sl@0
|
616 |
aAuthority.Append(aHost);
|
sl@0
|
617 |
|
sl@0
|
618 |
// Update the component table
|
sl@0
|
619 |
aHost.Set(aAuthority.Right(aHost.Length()));
|
sl@0
|
620 |
}
|
sl@0
|
621 |
}
|
sl@0
|
622 |
|
sl@0
|
623 |
/**
|
sl@0
|
624 |
Templated function to set the port in an authority. The output argument aAuthority points to the
|
sl@0
|
625 |
descriptor buffer into which aNewPort will be copied. The argument aOldPort is updated to point to
|
sl@0
|
626 |
the copied version of aNewPort in aAuthority.
|
sl@0
|
627 |
|
sl@0
|
628 |
@warning This function will panic with KAuthorityErrBufferOverflow if there is not
|
sl@0
|
629 |
enough space in the descriptor to append the component and any required delimiters.
|
sl@0
|
630 |
@since 6.0
|
sl@0
|
631 |
@param aAuthority The descriptor pointer to buffer to appended.
|
sl@0
|
632 |
@param aPort The descriptor pointer to the port component to be copied
|
sl@0
|
633 |
and then updated.
|
sl@0
|
634 |
@pre The buffer pointed to by aAuthority should be large enough to have aNewPort
|
sl@0
|
635 |
appended to it with the required delimiter.
|
sl@0
|
636 |
@post The authority buffer now includes aNewPort and aOldPort points to the
|
sl@0
|
637 |
copy of the port component in aAuthority.
|
sl@0
|
638 |
*/
|
sl@0
|
639 |
template<class TPtrType, class TPtrCType>
|
sl@0
|
640 |
void SetPort(TPtrType& aAuthority, TPtrCType& aPort)
|
sl@0
|
641 |
{
|
sl@0
|
642 |
// Append delimiter and the port
|
sl@0
|
643 |
aAuthority.Append(KPortDelimiter);
|
sl@0
|
644 |
aAuthority.Append(aPort);
|
sl@0
|
645 |
|
sl@0
|
646 |
// Update the component table
|
sl@0
|
647 |
aPort.Set(aAuthority.Right(aPort.Length()));
|
sl@0
|
648 |
}
|