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 |
// System includes
|
sl@0
|
17 |
#include <uri8.h>
|
sl@0
|
18 |
#include <uri16.h>
|
sl@0
|
19 |
#include "TUriCInternal.h"
|
sl@0
|
20 |
#include <uriutilscommon.h>
|
sl@0
|
21 |
#include <uriutils.h>
|
sl@0
|
22 |
#include "UriUtilsInternal.h"
|
sl@0
|
23 |
#include "TValidator.h"
|
sl@0
|
24 |
#include "TEquiv.h"
|
sl@0
|
25 |
#include <escapeutils.h>
|
sl@0
|
26 |
|
sl@0
|
27 |
|
sl@0
|
28 |
|
sl@0
|
29 |
// Panic category
|
sl@0
|
30 |
//
|
sl@0
|
31 |
_LIT(KUriPanicCategory,"URI-BASE");
|
sl@0
|
32 |
|
sl@0
|
33 |
//
|
sl@0
|
34 |
//
|
sl@0
|
35 |
// Implementation of TUriC8
|
sl@0
|
36 |
//
|
sl@0
|
37 |
//
|
sl@0
|
38 |
|
sl@0
|
39 |
/**
|
sl@0
|
40 |
Constructor.
|
sl@0
|
41 |
|
sl@0
|
42 |
@since 6.0
|
sl@0
|
43 |
*/
|
sl@0
|
44 |
EXPORT_C TUriC8::TUriC8()
|
sl@0
|
45 |
{
|
sl@0
|
46 |
// Reset the component table and the Uri
|
sl@0
|
47 |
Reset();
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
/**
|
sl@0
|
51 |
Retrieves the specified component in the uri.
|
sl@0
|
52 |
|
sl@0
|
53 |
@since 6.0
|
sl@0
|
54 |
@param aComponent The enum specifying the component.
|
sl@0
|
55 |
@return A constant reference to a descriptor pointer to the specified
|
sl@0
|
56 |
component.
|
sl@0
|
57 |
*/
|
sl@0
|
58 |
EXPORT_C const TDesC8& TUriC8::Extract(TUriComponent aComponent) const
|
sl@0
|
59 |
{
|
sl@0
|
60 |
__ASSERT_ALWAYS(aComponent<EUriMaxComponents && aComponent >EUriComplete, User::Panic(KUriPanicCategory, KUriUtilsErrBadComponentIndex));
|
sl@0
|
61 |
|
sl@0
|
62 |
return iComponent[aComponent];
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
/**
|
sl@0
|
66 |
Indicates whether the specified component is present in the uri.
|
sl@0
|
67 |
|
sl@0
|
68 |
@since 6.0
|
sl@0
|
69 |
@param aComponent The enum specifying the component.
|
sl@0
|
70 |
@return A boolean value of ETrue if the desired component is present,
|
sl@0
|
71 |
or EFalse if the desired component is not present.
|
sl@0
|
72 |
*/
|
sl@0
|
73 |
EXPORT_C TBool TUriC8::IsPresent(TUriComponent aComponent) const
|
sl@0
|
74 |
{
|
sl@0
|
75 |
__ASSERT_ALWAYS(aComponent<EUriMaxComponents && aComponent >EUriComplete, User::Panic(KUriPanicCategory, KUriUtilsErrBadComponentIndex));
|
sl@0
|
76 |
|
sl@0
|
77 |
return TBool(iComponent[aComponent].Ptr());
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
/**
|
sl@0
|
81 |
Checks the scheme to be valid. If there is no scheme then the return value
|
sl@0
|
82 |
indicates an invalid scheme.
|
sl@0
|
83 |
|
sl@0
|
84 |
@since 6.0
|
sl@0
|
85 |
@return A boolean value of ETrue if the scheme is valid, or EFalse if
|
sl@0
|
86 |
the scheme is not.
|
sl@0
|
87 |
*/
|
sl@0
|
88 |
EXPORT_C TBool TUriC8::IsSchemeValid() const
|
sl@0
|
89 |
{
|
sl@0
|
90 |
if( !IsPresent(EUriScheme) )
|
sl@0
|
91 |
{
|
sl@0
|
92 |
return EFalse;
|
sl@0
|
93 |
}
|
sl@0
|
94 |
return HasValidSchemeChars(iComponent[EUriScheme]);
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
/**
|
sl@0
|
98 |
Compares the specified component against the one in the uri passed in.
|
sl@0
|
99 |
|
sl@0
|
100 |
@since 6.0
|
sl@0
|
101 |
@param aUri The uri to compare components against.
|
sl@0
|
102 |
@param aComponent The enum specifying the component to compare.
|
sl@0
|
103 |
@return An integer value of zero if the components are the same,
|
sl@0
|
104 |
any other value if the components are not the same.
|
sl@0
|
105 |
*/
|
sl@0
|
106 |
EXPORT_C TInt TUriC8::Compare(const TUriC8& aUri, TUriComponent aComponent) const
|
sl@0
|
107 |
{
|
sl@0
|
108 |
__ASSERT_ALWAYS(aComponent<EUriMaxComponents && aComponent >EUriComplete, User::Panic(KUriPanicCategory, KUriUtilsErrBadComponentIndex));
|
sl@0
|
109 |
|
sl@0
|
110 |
// Does the component exist in both the Uri's
|
sl@0
|
111 |
if( IsPresent(aComponent) && aUri.IsPresent(aComponent) )
|
sl@0
|
112 |
{
|
sl@0
|
113 |
if( aComponent == EUriScheme || aComponent == EUriHost )
|
sl@0
|
114 |
{
|
sl@0
|
115 |
// Do case insensitive compare for scheme and host
|
sl@0
|
116 |
return (iComponent[aComponent].CompareF(aUri.iComponent[aComponent]));
|
sl@0
|
117 |
}
|
sl@0
|
118 |
else
|
sl@0
|
119 |
{
|
sl@0
|
120 |
// Do case sensitive compare for all other components
|
sl@0
|
121 |
return (iComponent[aComponent].Compare(aUri.iComponent[aComponent]));
|
sl@0
|
122 |
}
|
sl@0
|
123 |
}
|
sl@0
|
124 |
else
|
sl@0
|
125 |
return KErrNotFound;
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
/**
|
sl@0
|
129 |
Retrieves the descriptor for the entire uri.
|
sl@0
|
130 |
|
sl@0
|
131 |
@since 6.0
|
sl@0
|
132 |
@return A const reference to a descriptor pointer to the uri.
|
sl@0
|
133 |
*/
|
sl@0
|
134 |
EXPORT_C const TDesC8& TUriC8::UriDes() const
|
sl@0
|
135 |
{
|
sl@0
|
136 |
return iUriDes;
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
/**
|
sl@0
|
140 |
@publishedPartner
|
sl@0
|
141 |
@released
|
sl@0
|
142 |
Ensures that all components of the URI are valid. If the method returns
|
sl@0
|
143 |
KUriUtilsErrInvalidUri then one or more components are not valid. It is
|
sl@0
|
144 |
possible for URIs declared valid by this method to be, on detailed inspection,
|
sl@0
|
145 |
invalid.
|
sl@0
|
146 |
|
sl@0
|
147 |
@return KErrNone for vaild URIs, KUriUtilsErrInvalidUri for invalid URIs or KErrNotSupported.
|
sl@0
|
148 |
*/
|
sl@0
|
149 |
EXPORT_C TInt TUriC8::Validate() const
|
sl@0
|
150 |
{
|
sl@0
|
151 |
return DoValidate(*this);
|
sl@0
|
152 |
}
|
sl@0
|
153 |
|
sl@0
|
154 |
/**
|
sl@0
|
155 |
Compares the given URI to determine if it is equivalent to this URI. It is possible
|
sl@0
|
156 |
for URIs declared NOT equivalent by this method to be equvalent to a level not checked
|
sl@0
|
157 |
by this method.
|
sl@0
|
158 |
@publishedPartner
|
sl@0
|
159 |
@released
|
sl@0
|
160 |
@param aUri Contains URI to compare
|
sl@0
|
161 |
@return ETrue if the two URIs are equivalent otherwise EFalse
|
sl@0
|
162 |
*/
|
sl@0
|
163 |
EXPORT_C TInt TUriC8::Equivalent(const TUriC8& aUri) const
|
sl@0
|
164 |
{
|
sl@0
|
165 |
TInt result = EFalse;
|
sl@0
|
166 |
TRAPD(error, result = DoEquivalenceL(*this, aUri));
|
sl@0
|
167 |
if (error != KErrNone)
|
sl@0
|
168 |
{
|
sl@0
|
169 |
result = error;
|
sl@0
|
170 |
}
|
sl@0
|
171 |
return result;
|
sl@0
|
172 |
}
|
sl@0
|
173 |
|
sl@0
|
174 |
/**
|
sl@0
|
175 |
Retrieves the uri without the fragment component.
|
sl@0
|
176 |
|
sl@0
|
177 |
@since 6.0
|
sl@0
|
178 |
@param aUriNoFrag An output parameter which is set the non-reference
|
sl@0
|
179 |
version of the uri.
|
sl@0
|
180 |
*/
|
sl@0
|
181 |
EXPORT_C void TUriC8::UriWithoutFragment(TPtrC8& aUriNoFrag) const
|
sl@0
|
182 |
{
|
sl@0
|
183 |
if( IsPresent(EUriFragment) )
|
sl@0
|
184 |
{
|
sl@0
|
185 |
// There is a fragment, find where it starts
|
sl@0
|
186 |
TInt fragmentStartPos = iUriDes.Locate(KFragmentDelimiter);
|
sl@0
|
187 |
aUriNoFrag.Set(iUriDes.Left(fragmentStartPos));
|
sl@0
|
188 |
}
|
sl@0
|
189 |
else{
|
sl@0
|
190 |
aUriNoFrag.Set(iUriDes);
|
sl@0
|
191 |
}
|
sl@0
|
192 |
}
|
sl@0
|
193 |
|
sl@0
|
194 |
/**
|
sl@0
|
195 |
Create a new HBufC descriptor containing the desired component or the full URI.
|
sl@0
|
196 |
|
sl@0
|
197 |
@param aComponent The component to convert into Unicode (EUriScheme - EUriFragment), or
|
sl@0
|
198 |
the full URI (EUriComplete -- the default).
|
sl@0
|
199 |
@return The descriptor containing the desired component.
|
sl@0
|
200 |
*/
|
sl@0
|
201 |
EXPORT_C HBufC* TUriC8::DisplayFormL(TUriComponent aComponent) const
|
sl@0
|
202 |
{
|
sl@0
|
203 |
TPtrC8 component;
|
sl@0
|
204 |
|
sl@0
|
205 |
if (aComponent == EUriComplete)
|
sl@0
|
206 |
{
|
sl@0
|
207 |
component.Set(iUriDes);
|
sl@0
|
208 |
}
|
sl@0
|
209 |
else
|
sl@0
|
210 |
{ // extract the specified component, will Panic if invalid
|
sl@0
|
211 |
component.Set( Extract(aComponent) );
|
sl@0
|
212 |
}
|
sl@0
|
213 |
// convert descriptor from UTF-8 into Unicode
|
sl@0
|
214 |
return EscapeUtils::ConvertToUnicodeFromUtf8L(component);
|
sl@0
|
215 |
}
|
sl@0
|
216 |
|
sl@0
|
217 |
/**
|
sl@0
|
218 |
@internalComponent
|
sl@0
|
219 |
Resets the descriptor pointers for the uri components and the uri.
|
sl@0
|
220 |
|
sl@0
|
221 |
@since 6.0
|
sl@0
|
222 |
@post All uri component information is removed and the uri descriptor is
|
sl@0
|
223 |
set to NULL.
|
sl@0
|
224 |
*/
|
sl@0
|
225 |
void TUriC8::Reset()
|
sl@0
|
226 |
{
|
sl@0
|
227 |
// Set descriptor pointers to NULL and lengths to zero
|
sl@0
|
228 |
for( TInt i=0; i<EUriMaxComponents; ++i )
|
sl@0
|
229 |
{
|
sl@0
|
230 |
iComponent[i].Set(NULL,0);
|
sl@0
|
231 |
}
|
sl@0
|
232 |
iUriDes.Set(NULL,0);
|
sl@0
|
233 |
}
|
sl@0
|
234 |
|
sl@0
|
235 |
//
|
sl@0
|
236 |
//
|
sl@0
|
237 |
// Implementation of TUriC16
|
sl@0
|
238 |
//
|
sl@0
|
239 |
//
|
sl@0
|
240 |
/**
|
sl@0
|
241 |
Constructor.
|
sl@0
|
242 |
|
sl@0
|
243 |
@since 6.0
|
sl@0
|
244 |
@deprecated Deprecated in 9.1
|
sl@0
|
245 |
*/
|
sl@0
|
246 |
EXPORT_C TUriC16::TUriC16()
|
sl@0
|
247 |
{
|
sl@0
|
248 |
// Reset the component table and the Uri
|
sl@0
|
249 |
Reset();
|
sl@0
|
250 |
}
|
sl@0
|
251 |
|
sl@0
|
252 |
/**
|
sl@0
|
253 |
Retrieves the specified component in the uri.
|
sl@0
|
254 |
|
sl@0
|
255 |
@since 6.0
|
sl@0
|
256 |
@deprecated Deprecated in 9.1
|
sl@0
|
257 |
@param aComponent The enum specifying the component.
|
sl@0
|
258 |
@return A constant reference to a descriptor pointer to the specified component.
|
sl@0
|
259 |
*/
|
sl@0
|
260 |
EXPORT_C const TDesC16& TUriC16::Extract(TUriComponent aComponent) const
|
sl@0
|
261 |
{
|
sl@0
|
262 |
__ASSERT_ALWAYS(aComponent<EUriMaxComponents && aComponent >EUriComplete, User::Panic(KUriPanicCategory, KUriUtilsErrBadComponentIndex));
|
sl@0
|
263 |
|
sl@0
|
264 |
return iComponent[aComponent];
|
sl@0
|
265 |
}
|
sl@0
|
266 |
|
sl@0
|
267 |
/**
|
sl@0
|
268 |
Indicates whether the specified component is present in the uri.
|
sl@0
|
269 |
|
sl@0
|
270 |
@since 6.0
|
sl@0
|
271 |
@deprecated Deprecated in 9.1
|
sl@0
|
272 |
@param aComponent The enum specifying the component.
|
sl@0
|
273 |
@return A boolean value of ETrue if the desired component is present,
|
sl@0
|
274 |
or EFalse if the desired component is not present.
|
sl@0
|
275 |
*/
|
sl@0
|
276 |
EXPORT_C TBool TUriC16::IsPresent(TUriComponent aComponent) const
|
sl@0
|
277 |
{
|
sl@0
|
278 |
__ASSERT_ALWAYS(aComponent<EUriMaxComponents && aComponent >EUriComplete, User::Panic(KUriPanicCategory, KUriUtilsErrBadComponentIndex));
|
sl@0
|
279 |
|
sl@0
|
280 |
return TBool(iComponent[aComponent].Ptr());
|
sl@0
|
281 |
}
|
sl@0
|
282 |
|
sl@0
|
283 |
/**
|
sl@0
|
284 |
Checks to see if the scheme is valid. If there is no scheme then the return value
|
sl@0
|
285 |
indicates an invalid scheme (EFalse).
|
sl@0
|
286 |
|
sl@0
|
287 |
@since 6.0
|
sl@0
|
288 |
@deprecated Deprecated in 9.1
|
sl@0
|
289 |
@return A boolean value of ETrue if the scheme is valid, or EFalse if
|
sl@0
|
290 |
the scheme is not.
|
sl@0
|
291 |
*/
|
sl@0
|
292 |
EXPORT_C TBool TUriC16::IsSchemeValid() const
|
sl@0
|
293 |
{
|
sl@0
|
294 |
if( !IsPresent(EUriScheme) )
|
sl@0
|
295 |
{
|
sl@0
|
296 |
return EFalse;
|
sl@0
|
297 |
}
|
sl@0
|
298 |
return HasValidSchemeChars(iComponent[EUriScheme]);
|
sl@0
|
299 |
}
|
sl@0
|
300 |
|
sl@0
|
301 |
/**
|
sl@0
|
302 |
Compares the specified component against the one in the uri passed in.
|
sl@0
|
303 |
|
sl@0
|
304 |
@since 6.0
|
sl@0
|
305 |
@deprecated Deprecated in 9.1
|
sl@0
|
306 |
@param aUri The uri to compare components against.
|
sl@0
|
307 |
@param aComponent The enum specifying the component to compare.
|
sl@0
|
308 |
@return An integer value of zero if the components are the same, any other
|
sl@0
|
309 |
value if the components are not the same.
|
sl@0
|
310 |
*/
|
sl@0
|
311 |
EXPORT_C TBool TUriC16::Compare(const TUriC16& aUri, TUriComponent aComponent) const
|
sl@0
|
312 |
{
|
sl@0
|
313 |
__ASSERT_ALWAYS(aComponent<EUriMaxComponents && aComponent >EUriComplete, User::Panic(KUriPanicCategory, KUriUtilsErrBadComponentIndex));
|
sl@0
|
314 |
|
sl@0
|
315 |
// Does the component exist in both the Uri's
|
sl@0
|
316 |
if( IsPresent(aComponent) && aUri.IsPresent(aComponent) )
|
sl@0
|
317 |
{
|
sl@0
|
318 |
if( aComponent == EUriScheme || aComponent == EUriHost )
|
sl@0
|
319 |
{
|
sl@0
|
320 |
// Do case insensitive compare for scheme and host
|
sl@0
|
321 |
return (iComponent[aComponent].CompareF(aUri.iComponent[aComponent]));
|
sl@0
|
322 |
}
|
sl@0
|
323 |
else
|
sl@0
|
324 |
{
|
sl@0
|
325 |
// Do case sensitive compare for all other components
|
sl@0
|
326 |
return (iComponent[aComponent].Compare(aUri.iComponent[aComponent]));
|
sl@0
|
327 |
}
|
sl@0
|
328 |
}
|
sl@0
|
329 |
else
|
sl@0
|
330 |
return KErrNotFound;
|
sl@0
|
331 |
}
|
sl@0
|
332 |
|
sl@0
|
333 |
/**
|
sl@0
|
334 |
Retrieves the descriptor for the entire uri.
|
sl@0
|
335 |
|
sl@0
|
336 |
@since 6.0
|
sl@0
|
337 |
@deprecated Deprecated in 9.1
|
sl@0
|
338 |
@return A const reference to a descriptor pointer to the uri.
|
sl@0
|
339 |
*/
|
sl@0
|
340 |
EXPORT_C const TDesC16& TUriC16::UriDes() const
|
sl@0
|
341 |
{
|
sl@0
|
342 |
return iUriDes;
|
sl@0
|
343 |
}
|
sl@0
|
344 |
|
sl@0
|
345 |
/**
|
sl@0
|
346 |
@deprecated Deprecated in 9.1 -- provided for compatibility
|
sl@0
|
347 |
|
sl@0
|
348 |
Ensures that all components of the URI are valid. If the method returns
|
sl@0
|
349 |
KUriUtilsErrInvalidUri then one or more components are not valid. It is possible
|
sl@0
|
350 |
for URIs declared valid by this method to be, on detailed inspection, invalid.
|
sl@0
|
351 |
|
sl@0
|
352 |
@return KErrNone for vaild URIs, KUriUtilsErrInvalidUri for invalid URIs or KErrNotSupported.
|
sl@0
|
353 |
*/
|
sl@0
|
354 |
EXPORT_C TInt TUriC16::Validate() const
|
sl@0
|
355 |
{
|
sl@0
|
356 |
TInt result = KErrNone;
|
sl@0
|
357 |
TRAPD(error, result = ValidateL());
|
sl@0
|
358 |
if (error)
|
sl@0
|
359 |
{
|
sl@0
|
360 |
// problem allocating resourses
|
sl@0
|
361 |
return error;
|
sl@0
|
362 |
}
|
sl@0
|
363 |
return result;
|
sl@0
|
364 |
}
|
sl@0
|
365 |
|
sl@0
|
366 |
/**
|
sl@0
|
367 |
@deprecated Deprecated in 9.1 -- provided for compatibility
|
sl@0
|
368 |
|
sl@0
|
369 |
Compares the given URI to determine if it is equivalent to this URI. It is possible
|
sl@0
|
370 |
for URIs declared NOT equivalent by this method to be equvalent to a level not checked
|
sl@0
|
371 |
by this method.
|
sl@0
|
372 |
@param aUri Contains URI to compare
|
sl@0
|
373 |
@return ETrue if the two URIs are equivalent otherwise EFalse
|
sl@0
|
374 |
*/
|
sl@0
|
375 |
EXPORT_C TInt TUriC16::Equivalent(const TUriC16& aUri) const
|
sl@0
|
376 |
{
|
sl@0
|
377 |
TInt result = KErrNone;
|
sl@0
|
378 |
TRAPD(error, result = EquivalentL(aUri.UriDes()));
|
sl@0
|
379 |
if (error)
|
sl@0
|
380 |
{
|
sl@0
|
381 |
// problem allocating resourses
|
sl@0
|
382 |
return error;
|
sl@0
|
383 |
}
|
sl@0
|
384 |
return result;
|
sl@0
|
385 |
}
|
sl@0
|
386 |
/**
|
sl@0
|
387 |
Retrieves the uri without the fragment component.
|
sl@0
|
388 |
|
sl@0
|
389 |
@since 6.0
|
sl@0
|
390 |
@deprecated Deprecated in 9.1
|
sl@0
|
391 |
@param aUriNoFrag An output parameter which is set the non-reference
|
sl@0
|
392 |
version of the uri.
|
sl@0
|
393 |
*/
|
sl@0
|
394 |
|
sl@0
|
395 |
EXPORT_C void TUriC16::UriWithoutFragment(TPtrC16& aUriNoFrag) const
|
sl@0
|
396 |
{
|
sl@0
|
397 |
if( IsPresent(EUriFragment) )
|
sl@0
|
398 |
{
|
sl@0
|
399 |
// There is a fragment, find where it starts
|
sl@0
|
400 |
TInt fragmentStartPos = iUriDes.Locate(KFragmentDelimiter);
|
sl@0
|
401 |
aUriNoFrag.Set(iUriDes.Left(fragmentStartPos));
|
sl@0
|
402 |
}
|
sl@0
|
403 |
else{
|
sl@0
|
404 |
aUriNoFrag.Set(iUriDes);
|
sl@0
|
405 |
}
|
sl@0
|
406 |
}
|
sl@0
|
407 |
|
sl@0
|
408 |
/**
|
sl@0
|
409 |
Create a new HBufC descriptor containing the desired component or the full URI.
|
sl@0
|
410 |
@deprecated Deprecated in 9.1 - provided for compatibility
|
sl@0
|
411 |
|
sl@0
|
412 |
@param aComponent The component to convert into Unicode (EUriScheme - EUriFragment), or
|
sl@0
|
413 |
the full URI (EUriComplete -- the default).
|
sl@0
|
414 |
@return The descriptor containing the desired component.
|
sl@0
|
415 |
*/
|
sl@0
|
416 |
EXPORT_C HBufC* TUriC16::DisplayFormL(TUriComponent aComponent) const
|
sl@0
|
417 |
{
|
sl@0
|
418 |
if ( aComponent == EUriComplete) // extract the full URI
|
sl@0
|
419 |
{
|
sl@0
|
420 |
return iUriDes.AllocL();
|
sl@0
|
421 |
}
|
sl@0
|
422 |
return Extract(aComponent).AllocL();
|
sl@0
|
423 |
}
|
sl@0
|
424 |
|
sl@0
|
425 |
/**
|
sl@0
|
426 |
@internalComponent
|
sl@0
|
427 |
Resets the descriptor pointers for the uri components and the uri.
|
sl@0
|
428 |
|
sl@0
|
429 |
@since 6.0
|
sl@0
|
430 |
@post All uri component information is removed and the uri descriptor is
|
sl@0
|
431 |
set to NULL.
|
sl@0
|
432 |
*/
|
sl@0
|
433 |
void TUriC16::Reset()
|
sl@0
|
434 |
{
|
sl@0
|
435 |
// Set descriptor pointers to NULL and lengths to zero
|
sl@0
|
436 |
for( TInt i=0; i<EUriMaxComponents; ++i )
|
sl@0
|
437 |
{
|
sl@0
|
438 |
iComponent[i].Set(NULL,0);
|
sl@0
|
439 |
}
|
sl@0
|
440 |
iUriDes.Set(NULL,0);
|
sl@0
|
441 |
}
|
sl@0
|
442 |
|
sl@0
|
443 |
/**
|
sl@0
|
444 |
@deprecated Deprecated in 9.1
|
sl@0
|
445 |
|
sl@0
|
446 |
Ensures that all components of the URI are valid. If the method returns
|
sl@0
|
447 |
KUriUtilsErrInvalidUri then one or more components are not valid. It is possible
|
sl@0
|
448 |
for URIs declared valid by this method to be, on detailed inspection, invalid.
|
sl@0
|
449 |
|
sl@0
|
450 |
@return KErrNone for vaild URIs, KUriUtilsErrInvalidUri for invalid URIs or KErrNotSupported.
|
sl@0
|
451 |
*/
|
sl@0
|
452 |
TInt TUriC16::ValidateL() const
|
sl@0
|
453 |
{
|
sl@0
|
454 |
TInt result;
|
sl@0
|
455 |
|
sl@0
|
456 |
HBufC8* uri8 = CreateUri8LC(UriDes());
|
sl@0
|
457 |
TUriParser8 uriParser;
|
sl@0
|
458 |
if(uriParser.Parse(*uri8) != KErrNone)
|
sl@0
|
459 |
{
|
sl@0
|
460 |
result = KUriUtilsErrInvalidUri;
|
sl@0
|
461 |
}
|
sl@0
|
462 |
else
|
sl@0
|
463 |
{
|
sl@0
|
464 |
result = DoValidate(uriParser);
|
sl@0
|
465 |
}
|
sl@0
|
466 |
|
sl@0
|
467 |
CleanupStack::PopAndDestroy(uri8);
|
sl@0
|
468 |
return result;
|
sl@0
|
469 |
}
|
sl@0
|
470 |
|
sl@0
|
471 |
/**
|
sl@0
|
472 |
@deprecated Deprecated in 9.1
|
sl@0
|
473 |
|
sl@0
|
474 |
Compares the given URI to determine if it is equivalent to this URI. It is possible
|
sl@0
|
475 |
for URIs declared NOT equivalent by this method to be equvalent to a level not checked
|
sl@0
|
476 |
by this method.
|
sl@0
|
477 |
@param aUri Contains URI to compare
|
sl@0
|
478 |
@return ETrue if the two URIs are equivalent otherwise EFalse
|
sl@0
|
479 |
*/
|
sl@0
|
480 |
TBool TUriC16::EquivalentL(const TDesC16& aUri) const
|
sl@0
|
481 |
{
|
sl@0
|
482 |
HBufC8* lhs = CreateUri8LC(UriDes());
|
sl@0
|
483 |
HBufC8* rhs = CreateUri8LC(aUri);
|
sl@0
|
484 |
|
sl@0
|
485 |
TUriParser8 lhsParser;
|
sl@0
|
486 |
if(lhsParser.Parse(*lhs) != KErrNone)
|
sl@0
|
487 |
{
|
sl@0
|
488 |
User::Leave(KUriUtilsErrInvalidUri);
|
sl@0
|
489 |
}
|
sl@0
|
490 |
|
sl@0
|
491 |
TUriParser8 rhsParser;
|
sl@0
|
492 |
if(rhsParser.Parse(*rhs) != KErrNone)
|
sl@0
|
493 |
{
|
sl@0
|
494 |
User::Leave(KUriUtilsErrInvalidUri);
|
sl@0
|
495 |
}
|
sl@0
|
496 |
|
sl@0
|
497 |
TBool result = DoEquivalenceL(lhsParser, rhsParser);
|
sl@0
|
498 |
|
sl@0
|
499 |
CleanupStack::PopAndDestroy(2);
|
sl@0
|
500 |
return result;
|
sl@0
|
501 |
}
|
sl@0
|
502 |
|
sl@0
|
503 |
//
|
sl@0
|
504 |
//
|
sl@0
|
505 |
// Implementation of LOCAL functions
|
sl@0
|
506 |
//
|
sl@0
|
507 |
//
|
sl@0
|
508 |
|
sl@0
|
509 |
/**
|
sl@0
|
510 |
Checks the scheme for invalid characters. The scheme is invalid if it is empty.
|
sl@0
|
511 |
|
sl@0
|
512 |
@since 6.0
|
sl@0
|
513 |
@param aScheme The descriptor with the scheme.
|
sl@0
|
514 |
@return A boolean value of ETrue if all the characters in the scheme
|
sl@0
|
515 |
are valid, otherwise EFalse.
|
sl@0
|
516 |
*/
|
sl@0
|
517 |
template<class TPtrCType>
|
sl@0
|
518 |
LOCAL_C TBool HasValidSchemeChars(const TPtrCType& aScheme)
|
sl@0
|
519 |
{
|
sl@0
|
520 |
TInt length = aScheme.Length();
|
sl@0
|
521 |
TBool valid = ( length && TChar(aScheme[0]).IsAlpha() );
|
sl@0
|
522 |
|
sl@0
|
523 |
// Start checking from the second character
|
sl@0
|
524 |
TInt i=1;
|
sl@0
|
525 |
while( valid && i<length )
|
sl@0
|
526 |
{
|
sl@0
|
527 |
TChar c = aScheme[i];
|
sl@0
|
528 |
valid = c.IsAlphaDigit() || c==KPlusChar || c==KMinusChar || c==KPeriodChar;
|
sl@0
|
529 |
++i;
|
sl@0
|
530 |
}
|
sl@0
|
531 |
return valid;
|
sl@0
|
532 |
}
|
sl@0
|
533 |
|
sl@0
|
534 |
|
sl@0
|
535 |
//
|
sl@0
|
536 |
//
|
sl@0
|
537 |
// File URI Implementation - CUri8
|
sl@0
|
538 |
//
|
sl@0
|
539 |
//
|
sl@0
|
540 |
#ifdef __SECURE_DATA__
|
sl@0
|
541 |
/**
|
sl@0
|
542 |
Generates a fully-qualified filename from a file URI object.
|
sl@0
|
543 |
|
sl@0
|
544 |
The form of the returned filename depends on the file location, as follows:
|
sl@0
|
545 |
- public file on a fixed drive:
|
sl@0
|
546 |
@code
|
sl@0
|
547 |
file://c/path/to/file/name.ext -> c:\path\to\file\name.ext
|
sl@0
|
548 |
@endcode
|
sl@0
|
549 |
|
sl@0
|
550 |
- public file on removable media drive:
|
sl@0
|
551 |
The fully-qualified filename is resolved by finding the first drive on which the file exists.
|
sl@0
|
552 |
If the file does not exist, this will Leave with KErrNotFound
|
sl@0
|
553 |
@code
|
sl@0
|
554 |
file://ext-media/path/to/file/name.ext -> f:\path\to\file\name.ext
|
sl@0
|
555 |
@endcode
|
sl@0
|
556 |
(where f: is the first drive found containing "\path\to\file\name.ext")
|
sl@0
|
557 |
|
sl@0
|
558 |
- private file on fixed drive:
|
sl@0
|
559 |
@code
|
sl@0
|
560 |
file://private/c/path/to/file/name.ext -> c:\private\0x1001234f\path\to\file\name.ext
|
sl@0
|
561 |
@endcode
|
sl@0
|
562 |
(where 0x1001234f is the SID of the current application)
|
sl@0
|
563 |
|
sl@0
|
564 |
- private file on removable media drive:
|
sl@0
|
565 |
@code
|
sl@0
|
566 |
file://private/ext-media/path/to/file/name.ext -> h:\private\0x1001234f\path\to\file\name.ext
|
sl@0
|
567 |
@endcode
|
sl@0
|
568 |
(where h: is the first drive found containing "\private\0x1001234f\path\to\file\name.ext")
|
sl@0
|
569 |
|
sl@0
|
570 |
The returned file name is not guaranteed to exist except where specified above.
|
sl@0
|
571 |
|
sl@0
|
572 |
Be warned that this method may be slow when resolving special paths (like "/ext-media")
|
sl@0
|
573 |
|
sl@0
|
574 |
@leave KErrNotSupported URI does not specify a local file
|
sl@0
|
575 |
@leave KErrNotFound If the URI indicates the file is on removable media and the file does not exist on any.
|
sl@0
|
576 |
@since 9.1
|
sl@0
|
577 |
@return A descriptor containing the fully-qualified filename.
|
sl@0
|
578 |
@pre Object is fully constructed.
|
sl@0
|
579 |
*/
|
sl@0
|
580 |
#else
|
sl@0
|
581 |
/**
|
sl@0
|
582 |
Generates a fully-qualified filename from a file URI object.
|
sl@0
|
583 |
|
sl@0
|
584 |
The form of the returned filename depends on the file location, as follows:
|
sl@0
|
585 |
- public file on a fixed drive:
|
sl@0
|
586 |
@code
|
sl@0
|
587 |
file://c/path/to/file/name.ext -> c:\path\to\file\name.ext
|
sl@0
|
588 |
@endcode
|
sl@0
|
589 |
|
sl@0
|
590 |
- public file on removable media drive:
|
sl@0
|
591 |
The fully-qualified filename is resolved by finding the first drive on which the file exists.
|
sl@0
|
592 |
If the file does not exist, this will Leave with KErrNotFound
|
sl@0
|
593 |
@code
|
sl@0
|
594 |
file://ext-media/path/to/file/name.ext -> f:\path\to\file\name.ext
|
sl@0
|
595 |
@endcode
|
sl@0
|
596 |
(where f: is the first drive found containing "\path\to\file\name.ext")
|
sl@0
|
597 |
|
sl@0
|
598 |
The returned file name is not guaranteed to exist except where specified above.
|
sl@0
|
599 |
|
sl@0
|
600 |
Be warned that this method may be slow when resolving special paths (like "/ext-media")
|
sl@0
|
601 |
|
sl@0
|
602 |
@leave KErrNotSupported URI does not specify a local file
|
sl@0
|
603 |
@leave KErrNotFound If the URI indicates the file is on removable media and the file does not exist on any.
|
sl@0
|
604 |
@since 9.1
|
sl@0
|
605 |
@return A descriptor containing the fully-qualified filename.
|
sl@0
|
606 |
@pre Object is fully constructed.
|
sl@0
|
607 |
*/
|
sl@0
|
608 |
#endif
|
sl@0
|
609 |
EXPORT_C HBufC* TUriC8::GetFileNameL() const
|
sl@0
|
610 |
{
|
sl@0
|
611 |
return GetFileNameL(EUriFileNameFull);
|
sl@0
|
612 |
}
|
sl@0
|
613 |
|
sl@0
|
614 |
|
sl@0
|
615 |
/**
|
sl@0
|
616 |
This creates a file name from the URI, changing the network path separator (/) to the
|
sl@0
|
617 |
local file system path separator (\\).
|
sl@0
|
618 |
|
sl@0
|
619 |
If called with EUriFileNamePath, this will generate a file name containing the path relative to the drive.
|
sl@0
|
620 |
Any parameters in the URI are stripped off:
|
sl@0
|
621 |
@code
|
sl@0
|
622 |
http://www.foo.com/dir/file/name.ext;param1;param2 -> \dir\file\name.ext
|
sl@0
|
623 |
@endcode
|
sl@0
|
624 |
|
sl@0
|
625 |
If called with EUriFileNameTail, this will generate a just the name, with no directories or drive.
|
sl@0
|
626 |
Any parameters in the URI are stripped off:
|
sl@0
|
627 |
@code
|
sl@0
|
628 |
http://www.foo.com/dir/file/name.ext;param1;param2 -> name.ext
|
sl@0
|
629 |
@endcode
|
sl@0
|
630 |
|
sl@0
|
631 |
EUriFileNamePath and EUriFileNameTail can be used for any hierarchical URI (http, ftp, file, etc)
|
sl@0
|
632 |
and may have unexpected behaviour when called on any other type of URI.
|
sl@0
|
633 |
|
sl@0
|
634 |
If called with EUriFileNameFull, this will convert the URI into a fully-qualified filename. this is only valid
|
sl@0
|
635 |
for file URIs and will Leave if called on any other type of URI. The form of the returned filename is described in
|
sl@0
|
636 |
GetFileNameL with no arguments.
|
sl@0
|
637 |
|
sl@0
|
638 |
@leave KErrNotSupported The URI scheme cannot be converted into the desired type
|
sl@0
|
639 |
@since 9.1
|
sl@0
|
640 |
@pre Object is fully constructed.
|
sl@0
|
641 |
@param aType specifies what part of the filename is to be converted. The default is EUriFileNameFull).
|
sl@0
|
642 |
@return A descriptor containing the desired filename components.
|
sl@0
|
643 |
*/
|
sl@0
|
644 |
EXPORT_C HBufC* TUriC8::GetFileNameL(TUriFileName aType) const
|
sl@0
|
645 |
{
|
sl@0
|
646 |
TBool isFileUri = Extract(EUriScheme).Compare(KFileUriScheme8) == 0;
|
sl@0
|
647 |
if(aType == EUriFileNameFull && !isFileUri)
|
sl@0
|
648 |
{
|
sl@0
|
649 |
User::Leave(KErrNotSupported);
|
sl@0
|
650 |
}
|
sl@0
|
651 |
return ResolveFileNameL(Extract(EUriPath), aType, isFileUri);
|
sl@0
|
652 |
}
|
sl@0
|
653 |
|
sl@0
|
654 |
|
sl@0
|
655 |
//
|
sl@0
|
656 |
//
|
sl@0
|
657 |
// File URI Implementation - CUri16
|
sl@0
|
658 |
//
|
sl@0
|
659 |
//
|
sl@0
|
660 |
|
sl@0
|
661 |
#ifdef __SECURE_DATA__
|
sl@0
|
662 |
/**
|
sl@0
|
663 |
Generates a fully-qualified filename from a file URI object.
|
sl@0
|
664 |
|
sl@0
|
665 |
The form of the returned filename depends on the file location, as follows:
|
sl@0
|
666 |
- public file on a fixed drive:
|
sl@0
|
667 |
@code
|
sl@0
|
668 |
file://c/path/to/file/name.ext -> c:\path\to\file\name.ext
|
sl@0
|
669 |
@endcode
|
sl@0
|
670 |
|
sl@0
|
671 |
- public file on removable media drive:
|
sl@0
|
672 |
The fully-qualified filename is resolved by finding the first drive on which the file exists.
|
sl@0
|
673 |
If the file does not exist, this will Leave with KErrNotFound
|
sl@0
|
674 |
@code
|
sl@0
|
675 |
file://ext-media/path/to/file/name.ext -> f:\path\to\file\name.ext
|
sl@0
|
676 |
@endcode
|
sl@0
|
677 |
(where f: is the first drive found containing "\path\to\file\name.ext")
|
sl@0
|
678 |
|
sl@0
|
679 |
- private file on fixed drive:
|
sl@0
|
680 |
@code
|
sl@0
|
681 |
file://private/c/path/to/file/name.ext -> c:\private\0x1001234f\path\to\file\name.ext
|
sl@0
|
682 |
@endcode
|
sl@0
|
683 |
(where 0x1001234f is the SID of the current application)
|
sl@0
|
684 |
|
sl@0
|
685 |
- private file on removable media drive:
|
sl@0
|
686 |
@code
|
sl@0
|
687 |
file://private/ext-media/path/to/file/name.ext -> h:\private\0x1001234f\path\to\file\name.ext
|
sl@0
|
688 |
@endcode
|
sl@0
|
689 |
(where h: is the first drive found containing "\private\0x1001234f\path\to\file\name.ext")
|
sl@0
|
690 |
|
sl@0
|
691 |
The returned file name is not guaranteed to exist except where specified above.
|
sl@0
|
692 |
|
sl@0
|
693 |
Be warned that this method may be slow when resolving special paths (like "/ext-media")
|
sl@0
|
694 |
|
sl@0
|
695 |
@leave KErrNotSupported URI does not specify a local file
|
sl@0
|
696 |
@leave KErrNotFound If the URI indicates the file is on removable media and the file does not exist on any.
|
sl@0
|
697 |
@since 9.1
|
sl@0
|
698 |
@return A descriptor containing the fully-qualified filename.
|
sl@0
|
699 |
@pre Object is fully constructed.
|
sl@0
|
700 |
|
sl@0
|
701 |
*/
|
sl@0
|
702 |
#else
|
sl@0
|
703 |
/**
|
sl@0
|
704 |
Generates a fully-qualified filename from a file URI object.
|
sl@0
|
705 |
|
sl@0
|
706 |
The form of the returned filename depends on the file location, as follows:
|
sl@0
|
707 |
- public file on a fixed drive:
|
sl@0
|
708 |
@code
|
sl@0
|
709 |
file://c/path/to/file/name.ext -> c:\path\to\file\name.ext
|
sl@0
|
710 |
@endcode
|
sl@0
|
711 |
|
sl@0
|
712 |
- public file on removable media drive:
|
sl@0
|
713 |
The fully-qualified filename is resolved by finding the first drive on which the file exists.
|
sl@0
|
714 |
If the file does not exist, this will Leave with KErrNotFound
|
sl@0
|
715 |
@code
|
sl@0
|
716 |
file://ext-media/path/to/file/name.ext -> f:\path\to\file\name.ext
|
sl@0
|
717 |
@endcode
|
sl@0
|
718 |
(where f: is the first drive found containing "\path\to\file\name.ext")
|
sl@0
|
719 |
|
sl@0
|
720 |
The returned file name is not guaranteed to exist except where specified above.
|
sl@0
|
721 |
|
sl@0
|
722 |
Be warned that this method may be slow when resolving special paths (like "/ext-media")
|
sl@0
|
723 |
|
sl@0
|
724 |
@leave KErrNotSupported URI does not specify a local file
|
sl@0
|
725 |
@leave KErrNotFound If the URI indicates the file is on removable media and the file does not exist on any.
|
sl@0
|
726 |
@since 9.1
|
sl@0
|
727 |
@return A descriptor containing the fully-qualified filename.
|
sl@0
|
728 |
@pre Object is fully constructed.
|
sl@0
|
729 |
|
sl@0
|
730 |
*/
|
sl@0
|
731 |
#endif
|
sl@0
|
732 |
EXPORT_C HBufC* TUriC16::GetFileNameL() const
|
sl@0
|
733 |
{
|
sl@0
|
734 |
return GetFileNameL(EUriFileNameFull);
|
sl@0
|
735 |
}
|
sl@0
|
736 |
|
sl@0
|
737 |
|
sl@0
|
738 |
/**
|
sl@0
|
739 |
This creates a file name from the URI, changing the network path separator (/) to the
|
sl@0
|
740 |
local file system path separator (\\).
|
sl@0
|
741 |
|
sl@0
|
742 |
If called with EUriFileNamePath, this will generate a file name containing the path relative to the drive.
|
sl@0
|
743 |
Any parameters in the URI are stripped off:
|
sl@0
|
744 |
@code
|
sl@0
|
745 |
http://www.foo.com/dir/file/name.ext;param1;param2 -> \dir\file\name.ext
|
sl@0
|
746 |
@endcode
|
sl@0
|
747 |
|
sl@0
|
748 |
If called with EUriFileNameTail, this will generate a just the name, with no directories or drive.
|
sl@0
|
749 |
Any parameters in the URI are stripped off:
|
sl@0
|
750 |
@code
|
sl@0
|
751 |
http://www.foo.com/dir/file/name.ext;param1;param2 -> name.ext
|
sl@0
|
752 |
@endcode
|
sl@0
|
753 |
|
sl@0
|
754 |
EUriFileNamePath and EUriFileNameTail can be used for any hierarchical URI (http, ftp, file)
|
sl@0
|
755 |
and may have unexpected behaviour when called on any other type of URI.
|
sl@0
|
756 |
|
sl@0
|
757 |
If called with EUriFileNameFull, this will convert the URI into a fully-qualified filename. this is only valid
|
sl@0
|
758 |
for file URIs and will Leave if called on any other type of URI. The form of the returned filename is described in
|
sl@0
|
759 |
GetFileNameL with no arguments.
|
sl@0
|
760 |
|
sl@0
|
761 |
@leave KErrNotSupported The URI scheme cannot be converted into the desired type
|
sl@0
|
762 |
@since 9.1
|
sl@0
|
763 |
@pre Object is fully constructed.
|
sl@0
|
764 |
@param aType specifies what part of the filename is to be converted. The default is (EUriFileNameFull).
|
sl@0
|
765 |
@return A descriptor containing the desired filename components.
|
sl@0
|
766 |
*/
|
sl@0
|
767 |
EXPORT_C HBufC* TUriC16::GetFileNameL(TUriFileName aType) const
|
sl@0
|
768 |
{
|
sl@0
|
769 |
TBool isFileUri = Extract(EUriScheme).Compare(KFileUriScheme16) == 0;
|
sl@0
|
770 |
|
sl@0
|
771 |
if(aType == EUriFileNameFull && !isFileUri )
|
sl@0
|
772 |
{
|
sl@0
|
773 |
User::Leave(KErrNotSupported);
|
sl@0
|
774 |
}
|
sl@0
|
775 |
|
sl@0
|
776 |
HBufC8* fileUriPath8 = HBufC8::NewLC(Extract(EUriPath).Length());
|
sl@0
|
777 |
fileUriPath8->Des().Copy(Extract(EUriPath));
|
sl@0
|
778 |
HBufC* absFileName = ResolveFileNameL(*fileUriPath8, aType, isFileUri);
|
sl@0
|
779 |
CleanupStack::PopAndDestroy(fileUriPath8);
|
sl@0
|
780 |
return absFileName;
|
sl@0
|
781 |
}
|
sl@0
|
782 |
|
sl@0
|
783 |
|
sl@0
|
784 |
//
|
sl@0
|
785 |
//
|
sl@0
|
786 |
// Implementation of LOCAL functions
|
sl@0
|
787 |
//
|
sl@0
|
788 |
//
|
sl@0
|
789 |
|
sl@0
|
790 |
/**
|
sl@0
|
791 |
Function used to convert '\' to '/' and vice versa.
|
sl@0
|
792 |
|
sl@0
|
793 |
@since 9.1
|
sl@0
|
794 |
@param aDesPtr A descriptor reference to the string.
|
sl@0
|
795 |
@param aPathSeperatorFrom A path seperator to be converted (from)
|
sl@0
|
796 |
@param aPathSeperatorTo A path seperator to converte (To).
|
sl@0
|
797 |
*/
|
sl@0
|
798 |
void ChangePathSeparator(TDes& aDesPtr, TUint aPathSeperatorFrom, TUint aPathSeperatorTo)
|
sl@0
|
799 |
{
|
sl@0
|
800 |
for(TInt offset = aDesPtr.Length() - 1;offset >= 0;offset--)
|
sl@0
|
801 |
{
|
sl@0
|
802 |
if (aDesPtr[offset] == aPathSeperatorFrom)
|
sl@0
|
803 |
{
|
sl@0
|
804 |
aDesPtr[offset] = TUint16(aPathSeperatorTo);
|
sl@0
|
805 |
}
|
sl@0
|
806 |
}
|
sl@0
|
807 |
}
|
sl@0
|
808 |
|
sl@0
|
809 |
/**
|
sl@0
|
810 |
Function used to generate a fully qualified file name for a public or private file
|
sl@0
|
811 |
stored on a fix drive or a removable media drive from File URI path (parameter aFileUriPath).
|
sl@0
|
812 |
|
sl@0
|
813 |
This will be called by API GetFileName() to generate and return a filename.
|
sl@0
|
814 |
|
sl@0
|
815 |
@leave KErrBadName if the path doesn't contain valid drivename.
|
sl@0
|
816 |
@since 9.1
|
sl@0
|
817 |
@param aFileUriPath A descriptor reference to the File URI's path component.
|
sl@0
|
818 |
@return A pointer to a buffer containing the resolved fully qualified filename
|
sl@0
|
819 |
if the file uri path is not empty or a top level dir on main drive (C:\\)
|
sl@0
|
820 |
*/
|
sl@0
|
821 |
HBufC* GetFullFileNameFromFileUriPathL(const TDesC& aFileUriPath)
|
sl@0
|
822 |
{
|
sl@0
|
823 |
TFileName filename(KDefaultPath);
|
sl@0
|
824 |
|
sl@0
|
825 |
TInt origLength = aFileUriPath.Length();
|
sl@0
|
826 |
if(origLength == 0)
|
sl@0
|
827 |
{
|
sl@0
|
828 |
return filename.AllocL();
|
sl@0
|
829 |
}
|
sl@0
|
830 |
|
sl@0
|
831 |
TInt index = 0;
|
sl@0
|
832 |
TPtrC fileUriPath(aFileUriPath);
|
sl@0
|
833 |
|
sl@0
|
834 |
//skip KUriPathSeparator (/) from the Uri path
|
sl@0
|
835 |
if (fileUriPath[0] == KUriPathSeparator)
|
sl@0
|
836 |
{
|
sl@0
|
837 |
index++;
|
sl@0
|
838 |
}
|
sl@0
|
839 |
|
sl@0
|
840 |
fileUriPath.Set(aFileUriPath.Right(origLength - index));
|
sl@0
|
841 |
|
sl@0
|
842 |
RFs fs;
|
sl@0
|
843 |
TBool fsOpen = EFalse;
|
sl@0
|
844 |
|
sl@0
|
845 |
#ifdef __SECURE_DATA__
|
sl@0
|
846 |
if (fileUriPath.Left(KPrivate().Length()).Compare(KPrivate) == 0)
|
sl@0
|
847 |
{
|
sl@0
|
848 |
index += KPrivate().Length();
|
sl@0
|
849 |
User::LeaveIfError(fs.Connect());
|
sl@0
|
850 |
CleanupClosePushL(fs);
|
sl@0
|
851 |
fsOpen = ETrue;
|
sl@0
|
852 |
User::LeaveIfError(fs.PrivatePath(filename));
|
sl@0
|
853 |
filename.Insert(0, KDefaultPath().Left((KDefaultPath().Length() - 1) )); //Insert <drive>:
|
sl@0
|
854 |
fileUriPath.Set(aFileUriPath.Right(origLength - index));
|
sl@0
|
855 |
}
|
sl@0
|
856 |
#endif
|
sl@0
|
857 |
|
sl@0
|
858 |
TBool isExtMedia = (fileUriPath.Left(KExtMedia().Length()).Compare(KExtMedia) == 0);
|
sl@0
|
859 |
if (!isExtMedia )
|
sl@0
|
860 |
{
|
sl@0
|
861 |
TUint driveLetter = fileUriPath[0];
|
sl@0
|
862 |
//Checking for valid driveletter (should between A to Z or a to z) and followed by Uri path seperator "/"
|
sl@0
|
863 |
if ( fileUriPath[1] != KUriPathSeparator ||
|
sl@0
|
864 |
( (driveLetter < 'A' || driveLetter > 'Z') &&
|
sl@0
|
865 |
(driveLetter < 'a' || driveLetter > 'z') ) )
|
sl@0
|
866 |
{
|
sl@0
|
867 |
User::Leave(KErrBadName);
|
sl@0
|
868 |
}
|
sl@0
|
869 |
index += (KDefaultPath().Length() - 1); //skip <driveLetter>/
|
sl@0
|
870 |
filename[0] = TUint16(driveLetter);
|
sl@0
|
871 |
}
|
sl@0
|
872 |
else
|
sl@0
|
873 |
{
|
sl@0
|
874 |
index += KExtMedia().Length();
|
sl@0
|
875 |
}
|
sl@0
|
876 |
|
sl@0
|
877 |
filename.Append(aFileUriPath.Right(origLength - index));
|
sl@0
|
878 |
|
sl@0
|
879 |
//Convert "/" to "\"
|
sl@0
|
880 |
ChangePathSeparator(filename, KUriPathSeparator, KFilePathSeparator);
|
sl@0
|
881 |
|
sl@0
|
882 |
if (isExtMedia )
|
sl@0
|
883 |
{
|
sl@0
|
884 |
if (fsOpen == EFalse)
|
sl@0
|
885 |
{
|
sl@0
|
886 |
User::LeaveIfError(fs.Connect());
|
sl@0
|
887 |
CleanupClosePushL(fs);
|
sl@0
|
888 |
fsOpen = ETrue;
|
sl@0
|
889 |
}
|
sl@0
|
890 |
|
sl@0
|
891 |
TDriveInfo driveInfo;
|
sl@0
|
892 |
TInt err = KErrNotFound;
|
sl@0
|
893 |
|
sl@0
|
894 |
for (TInt driveNum = EDriveA; driveNum <= EDriveZ && err!=KErrNone; driveNum++)
|
sl@0
|
895 |
{
|
sl@0
|
896 |
if (fs.Drive(driveInfo, driveNum ) == KErrNone
|
sl@0
|
897 |
&& (driveInfo.iDriveAtt & KDriveAttRemovable))
|
sl@0
|
898 |
{
|
sl@0
|
899 |
filename[0]= TInt16('A' + driveNum);
|
sl@0
|
900 |
TUint attValue;
|
sl@0
|
901 |
err = fs.Att(filename, attValue);
|
sl@0
|
902 |
}
|
sl@0
|
903 |
}
|
sl@0
|
904 |
User::LeaveIfError(err);
|
sl@0
|
905 |
}
|
sl@0
|
906 |
|
sl@0
|
907 |
if (fsOpen)
|
sl@0
|
908 |
{
|
sl@0
|
909 |
CleanupStack::PopAndDestroy(&fs);
|
sl@0
|
910 |
}
|
sl@0
|
911 |
|
sl@0
|
912 |
return filename.AllocL();
|
sl@0
|
913 |
}
|
sl@0
|
914 |
|
sl@0
|
915 |
/**
|
sl@0
|
916 |
Creates an 8 bit URI descriptor from an 16 bit one
|
sl@0
|
917 |
|
sl@0
|
918 |
@param aBuf16 The full 16 bit URI descriptor
|
sl@0
|
919 |
@return Pointer to the newly created 8 bit URI descriptor
|
sl@0
|
920 |
are valid, otherwise EFalse.
|
sl@0
|
921 |
*/
|
sl@0
|
922 |
HBufC8* CreateUri8LC(const TDesC16& aBuf16)
|
sl@0
|
923 |
{
|
sl@0
|
924 |
TInt length = aBuf16.Length();
|
sl@0
|
925 |
HBufC8* newBuf = HBufC8::NewMaxLC(length);
|
sl@0
|
926 |
TPtr8 des8Ptr = newBuf->Des();
|
sl@0
|
927 |
for (TInt i = 0; i < length; ++i)
|
sl@0
|
928 |
{
|
sl@0
|
929 |
des8Ptr[i] = static_cast<TText8>(aBuf16[i]);
|
sl@0
|
930 |
}
|
sl@0
|
931 |
return newBuf;
|
sl@0
|
932 |
}
|
sl@0
|
933 |
|
sl@0
|
934 |
/**
|
sl@0
|
935 |
Check the components of a URI to ensure they are all valid
|
sl@0
|
936 |
|
sl@0
|
937 |
@since 8.1
|
sl@0
|
938 |
@param aUri The URI to check
|
sl@0
|
939 |
@return KErrNone if all components are valid, otherwise one of the 'invalid' error codes
|
sl@0
|
940 |
*/
|
sl@0
|
941 |
TInt DoValidate(const TUriC8& aUri)
|
sl@0
|
942 |
{
|
sl@0
|
943 |
TInt result;
|
sl@0
|
944 |
TPtrC8 subComponent(aUri.Extract(EUriScheme));
|
sl@0
|
945 |
if (!HasValidSchemeChars(subComponent))
|
sl@0
|
946 |
{
|
sl@0
|
947 |
result = KUriUtilsErrInvalidScheme;
|
sl@0
|
948 |
}
|
sl@0
|
949 |
else if(SchemeType(subComponent) == ESchemeTypeSip)
|
sl@0
|
950 |
//To validate Sip uri
|
sl@0
|
951 |
{
|
sl@0
|
952 |
TValidatorSip validator(aUri);
|
sl@0
|
953 |
result = validator.Validate();
|
sl@0
|
954 |
}
|
sl@0
|
955 |
else if(SchemeType(subComponent) == ESchemeTypeTel)
|
sl@0
|
956 |
//To validate Tel uri
|
sl@0
|
957 |
{
|
sl@0
|
958 |
TValidatorTel validator(aUri);
|
sl@0
|
959 |
result = validator.Validate();
|
sl@0
|
960 |
}
|
sl@0
|
961 |
else
|
sl@0
|
962 |
{
|
sl@0
|
963 |
result = KErrNotSupported;
|
sl@0
|
964 |
}
|
sl@0
|
965 |
|
sl@0
|
966 |
return result;
|
sl@0
|
967 |
}
|
sl@0
|
968 |
|
sl@0
|
969 |
/**
|
sl@0
|
970 |
Compare the components of two URIs to see if they identify the same resource
|
sl@0
|
971 |
|
sl@0
|
972 |
@since 8.1
|
sl@0
|
973 |
@param aLhs The left hand side URI to compare
|
sl@0
|
974 |
@param aRhs The right hand side URI to compare
|
sl@0
|
975 |
@return ETrue if they point to the same resource, EFalse otherwise.
|
sl@0
|
976 |
*/
|
sl@0
|
977 |
TInt DoEquivalenceL(const TUriC8& aLhs, const TUriC8& aRhs)
|
sl@0
|
978 |
{
|
sl@0
|
979 |
TInt result;
|
sl@0
|
980 |
if (SchemeType(aLhs.Extract(EUriScheme)) == ESchemeTypeSip)
|
sl@0
|
981 |
{
|
sl@0
|
982 |
TEquivSip equiv(aLhs, aRhs);
|
sl@0
|
983 |
result = equiv.EquivalentL();
|
sl@0
|
984 |
}
|
sl@0
|
985 |
else
|
sl@0
|
986 |
{
|
sl@0
|
987 |
// unknown scheme so assume network scheme
|
sl@0
|
988 |
TEquiv equiv(aLhs, aRhs);
|
sl@0
|
989 |
result = equiv.EquivalentL();
|
sl@0
|
990 |
}
|
sl@0
|
991 |
|
sl@0
|
992 |
return result;
|
sl@0
|
993 |
}
|
sl@0
|
994 |
|
sl@0
|
995 |
|
sl@0
|
996 |
/**
|
sl@0
|
997 |
Get the desired part of the filename from the URI path
|
sl@0
|
998 |
|
sl@0
|
999 |
@param aPath A descriptor reference to the File URI's path component.
|
sl@0
|
1000 |
@param aType enum value of TUriFileName.
|
sl@0
|
1001 |
@param aIsFileUri Specifies the whether it is FileUri or not.
|
sl@0
|
1002 |
@return Pointer to the newly created URI descriptor which contains the
|
sl@0
|
1003 |
desired part of the filename from the URI path.
|
sl@0
|
1004 |
*/
|
sl@0
|
1005 |
HBufC* ResolveFileNameL(const TDesC8& aPath, TUriFileName aType, TBool aIsFileUri)
|
sl@0
|
1006 |
{
|
sl@0
|
1007 |
// replace % codes
|
sl@0
|
1008 |
HBufC8* fileUriPath8 = EscapeUtils::EscapeDecodeL(aPath);
|
sl@0
|
1009 |
CleanupStack::PushL(fileUriPath8);
|
sl@0
|
1010 |
|
sl@0
|
1011 |
// convert to unicode
|
sl@0
|
1012 |
HBufC* fileUriPath = EscapeUtils::ConvertToUnicodeFromUtf8L(*fileUriPath8);
|
sl@0
|
1013 |
CleanupStack::PopAndDestroy(fileUriPath8);
|
sl@0
|
1014 |
CleanupStack::PushL(fileUriPath);
|
sl@0
|
1015 |
|
sl@0
|
1016 |
HBufC* absFileName = NULL; // setting to NULL makes compiler happy
|
sl@0
|
1017 |
if ( aIsFileUri )
|
sl@0
|
1018 |
{
|
sl@0
|
1019 |
/* awlays do full conversion for file URIs
|
sl@0
|
1020 |
It's not optimal time-wise, but it uses the least code and is
|
sl@0
|
1021 |
forward-compatible. */
|
sl@0
|
1022 |
absFileName = GetFullFileNameFromFileUriPathL(*fileUriPath);
|
sl@0
|
1023 |
CleanupStack::PopAndDestroy(fileUriPath);
|
sl@0
|
1024 |
if ( aType == EUriFileNameFull )
|
sl@0
|
1025 |
{
|
sl@0
|
1026 |
return absFileName;
|
sl@0
|
1027 |
}
|
sl@0
|
1028 |
fileUriPath = absFileName; // code below uses fileUriPath
|
sl@0
|
1029 |
CleanupStack::PushL(fileUriPath);
|
sl@0
|
1030 |
TPtr path(fileUriPath->Des());
|
sl@0
|
1031 |
path.Delete(0,2); // delete drive and ':' (always begins with drive letter and :)
|
sl@0
|
1032 |
}
|
sl@0
|
1033 |
else // not a file URI
|
sl@0
|
1034 |
{ // convert '/' to '\' for all other URIs
|
sl@0
|
1035 |
TPtr path(fileUriPath->Des());
|
sl@0
|
1036 |
ChangePathSeparator(path, KUriPathSeparator, KFilePathSeparator);
|
sl@0
|
1037 |
}
|
sl@0
|
1038 |
|
sl@0
|
1039 |
// EUriFileNameFull must only ever be used with a file URI. Failures should be caught by the caller
|
sl@0
|
1040 |
__ASSERT_DEBUG(aType != EUriFileNameFull,
|
sl@0
|
1041 |
User::Panic(KUriPanicCategory, KUriUtilsErrBadComponentIndex));
|
sl@0
|
1042 |
|
sl@0
|
1043 |
TPtrC name;
|
sl@0
|
1044 |
GetFileComponent(name, *fileUriPath, aType ); // get path or tail
|
sl@0
|
1045 |
if (name.Length() == fileUriPath->Length())
|
sl@0
|
1046 |
{ // no changes, just return fileUriPath
|
sl@0
|
1047 |
absFileName = fileUriPath;
|
sl@0
|
1048 |
CleanupStack::Pop(fileUriPath);
|
sl@0
|
1049 |
}
|
sl@0
|
1050 |
else
|
sl@0
|
1051 |
{
|
sl@0
|
1052 |
absFileName = name.AllocL();
|
sl@0
|
1053 |
CleanupStack::PopAndDestroy(fileUriPath);
|
sl@0
|
1054 |
}
|
sl@0
|
1055 |
|
sl@0
|
1056 |
return absFileName;
|
sl@0
|
1057 |
}
|
sl@0
|
1058 |
|
sl@0
|
1059 |
/**
|
sl@0
|
1060 |
Gets the desired file path or tail.
|
sl@0
|
1061 |
|
sl@0
|
1062 |
@param aNewName An outparameter, reference to descriptor .
|
sl@0
|
1063 |
@param aOldName An inparameter descriptor reference.
|
sl@0
|
1064 |
@param aType enum value of TUriFileName.
|
sl@0
|
1065 |
*/
|
sl@0
|
1066 |
void GetFileComponent(TPtrC& aNewName, const TDesC& aOldName, TUriFileName aType )
|
sl@0
|
1067 |
{
|
sl@0
|
1068 |
__ASSERT_ALWAYS(aType != EUriFileNameFull, User::Panic(KUriPanicCategory, KUriUtilsErrBadComponentIndex));
|
sl@0
|
1069 |
|
sl@0
|
1070 |
aNewName.Set(aOldName);
|
sl@0
|
1071 |
// chop off everything after the first ;
|
sl@0
|
1072 |
TInt pos = aNewName.Locate(KParamDelimiter);
|
sl@0
|
1073 |
if( pos == 0 ) // the ; is at the start
|
sl@0
|
1074 |
{
|
sl@0
|
1075 |
aNewName.Set(KNullDesC);
|
sl@0
|
1076 |
}
|
sl@0
|
1077 |
else if (pos > 0)
|
sl@0
|
1078 |
{ // set to the text untilt he ;
|
sl@0
|
1079 |
aNewName.Set(aNewName.Left(pos));
|
sl@0
|
1080 |
}
|
sl@0
|
1081 |
if( aType == EUriFileNameTail)
|
sl@0
|
1082 |
{
|
sl@0
|
1083 |
// chop off everything before the last /
|
sl@0
|
1084 |
TInt pos = aNewName.LocateReverse(KFilePathSeparator);
|
sl@0
|
1085 |
if( pos >=0 ) // there is a /
|
sl@0
|
1086 |
{
|
sl@0
|
1087 |
if( pos >= aNewName.Length() - 1 ) // the / is at the end
|
sl@0
|
1088 |
{
|
sl@0
|
1089 |
aNewName.Set(KNullDesC);
|
sl@0
|
1090 |
}
|
sl@0
|
1091 |
else
|
sl@0
|
1092 |
{ // set to the text following the last /
|
sl@0
|
1093 |
aNewName.Set(aNewName.Right(aNewName.Length()-1-pos));
|
sl@0
|
1094 |
}
|
sl@0
|
1095 |
}
|
sl@0
|
1096 |
}
|
sl@0
|
1097 |
}
|
sl@0
|
1098 |
|
sl@0
|
1099 |
|
sl@0
|
1100 |
|
sl@0
|
1101 |
|