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 <uriutilscommon.h>
|
sl@0
|
19 |
#include <escapeutils.h>
|
sl@0
|
20 |
|
sl@0
|
21 |
// Panic category
|
sl@0
|
22 |
//
|
sl@0
|
23 |
_LIT(KAuthorityPanicCategory,"AUTHORITY");
|
sl@0
|
24 |
|
sl@0
|
25 |
//
|
sl@0
|
26 |
//
|
sl@0
|
27 |
// Implementation of TAuthorityC8
|
sl@0
|
28 |
//
|
sl@0
|
29 |
//
|
sl@0
|
30 |
|
sl@0
|
31 |
/**
|
sl@0
|
32 |
Constructor.
|
sl@0
|
33 |
|
sl@0
|
34 |
@since 6.0
|
sl@0
|
35 |
*/
|
sl@0
|
36 |
EXPORT_C TAuthorityC8::TAuthorityC8()
|
sl@0
|
37 |
{
|
sl@0
|
38 |
// Reset the component table and the Authority
|
sl@0
|
39 |
Reset();
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
/**
|
sl@0
|
43 |
Retrieves the specified component in the authority.
|
sl@0
|
44 |
|
sl@0
|
45 |
@since 6.0
|
sl@0
|
46 |
@param aComponent The enum specifying the component.
|
sl@0
|
47 |
@return A constant reference to a descriptor pointer to the specified component.
|
sl@0
|
48 |
*/
|
sl@0
|
49 |
EXPORT_C const TDesC8& TAuthorityC8::Extract(TAuthorityComponent aComponent) const
|
sl@0
|
50 |
{
|
sl@0
|
51 |
__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
|
sl@0
|
52 |
|
sl@0
|
53 |
return iComponent[aComponent];
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
/**
|
sl@0
|
57 |
Indicates whether the specified component is present in the authority.
|
sl@0
|
58 |
|
sl@0
|
59 |
@since 6.0
|
sl@0
|
60 |
@param aComponent The enum specifying the component.
|
sl@0
|
61 |
@return A boolean value of ETrue if the desired component is present,
|
sl@0
|
62 |
or EFalse if the desired component is not present.
|
sl@0
|
63 |
*/
|
sl@0
|
64 |
EXPORT_C TBool TAuthorityC8::IsPresent(TAuthorityComponent aComponent) const
|
sl@0
|
65 |
{
|
sl@0
|
66 |
__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
|
sl@0
|
67 |
|
sl@0
|
68 |
TBool present = TBool(iComponent[aComponent].Ptr());
|
sl@0
|
69 |
return present;
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
/**
|
sl@0
|
73 |
Compares the specified component against the one in the authority passed in.
|
sl@0
|
74 |
|
sl@0
|
75 |
@since 6.0
|
sl@0
|
76 |
@param aAuthority The authority to compare components against.
|
sl@0
|
77 |
@param aComponent The enum specifying the component to compare.
|
sl@0
|
78 |
@return An integer value of zero if the components are the same, any other
|
sl@0
|
79 |
value if the components are not the same.
|
sl@0
|
80 |
*/
|
sl@0
|
81 |
EXPORT_C TInt TAuthorityC8::Compare(const TAuthorityC8& aAuthority, TAuthorityComponent aComponent) const
|
sl@0
|
82 |
{
|
sl@0
|
83 |
__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
|
sl@0
|
84 |
|
sl@0
|
85 |
// Does the component exist in both the Authoritys
|
sl@0
|
86 |
if( IsPresent(aComponent) && aAuthority.IsPresent(aComponent) )
|
sl@0
|
87 |
{
|
sl@0
|
88 |
if( aComponent == EAuthorityHost )
|
sl@0
|
89 |
{
|
sl@0
|
90 |
// Do case insensitive compare for host
|
sl@0
|
91 |
return (iComponent[aComponent].CompareF(aAuthority.iComponent[aComponent]));
|
sl@0
|
92 |
}
|
sl@0
|
93 |
else
|
sl@0
|
94 |
{
|
sl@0
|
95 |
// Do case sensitive compare for all other components
|
sl@0
|
96 |
return (iComponent[aComponent].Compare(aAuthority.iComponent[aComponent]));
|
sl@0
|
97 |
}
|
sl@0
|
98 |
}
|
sl@0
|
99 |
else
|
sl@0
|
100 |
return KErrNotFound;
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
/**
|
sl@0
|
104 |
Retrieves the descriptor for the entire authority.
|
sl@0
|
105 |
|
sl@0
|
106 |
@since 6.0
|
sl@0
|
107 |
@return A const reference to a descriptor pointer to the authority.
|
sl@0
|
108 |
*/
|
sl@0
|
109 |
EXPORT_C const TDesC8& TAuthorityC8::AuthorityDes() const
|
sl@0
|
110 |
{
|
sl@0
|
111 |
return iAuthorityDes;
|
sl@0
|
112 |
}
|
sl@0
|
113 |
|
sl@0
|
114 |
/**
|
sl@0
|
115 |
Create a new HBufC descriptor containing the desired component or the full Authority.
|
sl@0
|
116 |
|
sl@0
|
117 |
@param aComponent The component to convert into Unicode (EAuthorityScheme - EAuthorityFragment)
|
sl@0
|
118 |
or the full authority (EAuthorityComplete -- the default)).
|
sl@0
|
119 |
@return the descriptor containing the desired component.
|
sl@0
|
120 |
*/
|
sl@0
|
121 |
EXPORT_C HBufC* TAuthorityC8::DisplayFormL(TAuthorityComponent aComponent ) const
|
sl@0
|
122 |
{
|
sl@0
|
123 |
TPtrC8 component;
|
sl@0
|
124 |
|
sl@0
|
125 |
if ( aComponent == EAuthorityComplete) // extract the full authority
|
sl@0
|
126 |
{
|
sl@0
|
127 |
component.Set(iAuthorityDes);
|
sl@0
|
128 |
}
|
sl@0
|
129 |
else
|
sl@0
|
130 |
{ // extract the specified component, will Panic if invalid
|
sl@0
|
131 |
component.Set( Extract(aComponent) );
|
sl@0
|
132 |
}
|
sl@0
|
133 |
// convert descriptor from UTF-8 into Unicode
|
sl@0
|
134 |
return EscapeUtils::ConvertToUnicodeFromUtf8L(component);
|
sl@0
|
135 |
}
|
sl@0
|
136 |
|
sl@0
|
137 |
|
sl@0
|
138 |
/**
|
sl@0
|
139 |
@internalComponent
|
sl@0
|
140 |
Resets the descriptor pointers for the authority components and the authority.
|
sl@0
|
141 |
|
sl@0
|
142 |
@since 6.0
|
sl@0
|
143 |
@post All authority component information is removed and the authority
|
sl@0
|
144 |
descriptor is set to NULL.
|
sl@0
|
145 |
*/
|
sl@0
|
146 |
void TAuthorityC8::Reset()
|
sl@0
|
147 |
{
|
sl@0
|
148 |
// Set descriptor pointers to NULL and lengths to zero
|
sl@0
|
149 |
for( TInt i=0; i<EAuthorityMaxComponents; ++i )
|
sl@0
|
150 |
{
|
sl@0
|
151 |
iComponent[i].Set(NULL,0);
|
sl@0
|
152 |
}
|
sl@0
|
153 |
iAuthorityDes.Set(NULL,0);
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
//
|
sl@0
|
157 |
//
|
sl@0
|
158 |
// Implementation of TAuthorityC16
|
sl@0
|
159 |
//
|
sl@0
|
160 |
//
|
sl@0
|
161 |
|
sl@0
|
162 |
/**
|
sl@0
|
163 |
Constructor.
|
sl@0
|
164 |
|
sl@0
|
165 |
@since 6.0
|
sl@0
|
166 |
@deprecated Deprecated in 9.1
|
sl@0
|
167 |
*/
|
sl@0
|
168 |
EXPORT_C TAuthorityC16::TAuthorityC16()
|
sl@0
|
169 |
{
|
sl@0
|
170 |
// Reset the component table and the Authority
|
sl@0
|
171 |
Reset();
|
sl@0
|
172 |
}
|
sl@0
|
173 |
|
sl@0
|
174 |
/**
|
sl@0
|
175 |
Retrieves the specified component in the authority.
|
sl@0
|
176 |
|
sl@0
|
177 |
@since 6.0
|
sl@0
|
178 |
@deprecated Deprecated in 9.1
|
sl@0
|
179 |
@param aComponent The enum specifying the component.
|
sl@0
|
180 |
@return A constant reference to a descriptor pointer to the specified component.
|
sl@0
|
181 |
*/
|
sl@0
|
182 |
EXPORT_C const TDesC16& TAuthorityC16::Extract(TAuthorityComponent aComponent) const
|
sl@0
|
183 |
{
|
sl@0
|
184 |
__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
|
sl@0
|
185 |
|
sl@0
|
186 |
return iComponent[aComponent];
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
/**
|
sl@0
|
190 |
Indicates whether the specified component is present in the authority.
|
sl@0
|
191 |
|
sl@0
|
192 |
@since 6.0
|
sl@0
|
193 |
@deprecated Deprecated in 9.1
|
sl@0
|
194 |
@param aComponent The enum specifying the component.
|
sl@0
|
195 |
@return A boolean value of ETrue if the desired component is present,
|
sl@0
|
196 |
or EFalse if the desired component is not present.
|
sl@0
|
197 |
*/
|
sl@0
|
198 |
EXPORT_C TBool TAuthorityC16::IsPresent(TAuthorityComponent aComponent) const
|
sl@0
|
199 |
{
|
sl@0
|
200 |
__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
|
sl@0
|
201 |
|
sl@0
|
202 |
TBool present = iComponent[aComponent].Ptr() ? ETrue : EFalse;
|
sl@0
|
203 |
return present;
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
/**
|
sl@0
|
207 |
Compares the specified component against the one in the authority passed in.
|
sl@0
|
208 |
|
sl@0
|
209 |
@since 6.0
|
sl@0
|
210 |
@deprecated Deprecated in 9.1
|
sl@0
|
211 |
@param aAuthority The authority to compare components against.
|
sl@0
|
212 |
@param aComponent The enum specifying the component to compare.
|
sl@0
|
213 |
@return An integer value of zero if the components are the same, any other
|
sl@0
|
214 |
value if the components are not the same.
|
sl@0
|
215 |
*/
|
sl@0
|
216 |
EXPORT_C TInt TAuthorityC16::Compare(const TAuthorityC16& aAuthority, TAuthorityComponent aComponent) const
|
sl@0
|
217 |
{
|
sl@0
|
218 |
__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
|
sl@0
|
219 |
|
sl@0
|
220 |
// Does the component exist in both the Authoritys
|
sl@0
|
221 |
if( IsPresent(aComponent) && aAuthority.IsPresent(aComponent) )
|
sl@0
|
222 |
{
|
sl@0
|
223 |
if( aComponent == EAuthorityHost )
|
sl@0
|
224 |
{
|
sl@0
|
225 |
// Do case insensitive compare for host
|
sl@0
|
226 |
return (iComponent[aComponent].CompareF(aAuthority.iComponent[aComponent]));
|
sl@0
|
227 |
}
|
sl@0
|
228 |
else
|
sl@0
|
229 |
{
|
sl@0
|
230 |
// Do case sensitive compare for all other components
|
sl@0
|
231 |
return (iComponent[aComponent].Compare(aAuthority.iComponent[aComponent]));
|
sl@0
|
232 |
}
|
sl@0
|
233 |
}
|
sl@0
|
234 |
else
|
sl@0
|
235 |
return KErrNotFound;
|
sl@0
|
236 |
}
|
sl@0
|
237 |
|
sl@0
|
238 |
/**
|
sl@0
|
239 |
Retrieves the descriptor for the entire authority.
|
sl@0
|
240 |
|
sl@0
|
241 |
@since 6.0
|
sl@0
|
242 |
@deprecated Deprecated in 9.1
|
sl@0
|
243 |
@return A const reference to a descriptor pointer to the authority.
|
sl@0
|
244 |
*/
|
sl@0
|
245 |
EXPORT_C const TDesC16& TAuthorityC16::AuthorityDes() const
|
sl@0
|
246 |
{
|
sl@0
|
247 |
return iAuthorityDes;
|
sl@0
|
248 |
}
|
sl@0
|
249 |
|
sl@0
|
250 |
/**
|
sl@0
|
251 |
Create a new HBufC descriptor containing the desired component or the full authority.
|
sl@0
|
252 |
|
sl@0
|
253 |
@param aComponent The component to convert into Unicode (EAuthorityScheme - EAuthorityFragment),
|
sl@0
|
254 |
the full authority (EAuthorityComplete -- the default), or the final segment of the path (EAuthorityTail).
|
sl@0
|
255 |
@return the descriptor containing the desired component.
|
sl@0
|
256 |
@deprecated Deprecated in 9.1. Provided for compatibility.
|
sl@0
|
257 |
*/
|
sl@0
|
258 |
EXPORT_C HBufC* TAuthorityC16::DisplayFormL(TAuthorityComponent aComponent) const
|
sl@0
|
259 |
{
|
sl@0
|
260 |
TPtrC component;
|
sl@0
|
261 |
if ( aComponent == EAuthorityComplete) // extract the full authority
|
sl@0
|
262 |
{
|
sl@0
|
263 |
component.Set(iAuthorityDes);
|
sl@0
|
264 |
}
|
sl@0
|
265 |
else
|
sl@0
|
266 |
{ // extract the specified component, will Panic if invalid
|
sl@0
|
267 |
component.Set( Extract(aComponent) );
|
sl@0
|
268 |
}
|
sl@0
|
269 |
|
sl@0
|
270 |
return component.AllocL();
|
sl@0
|
271 |
}
|
sl@0
|
272 |
|
sl@0
|
273 |
/**
|
sl@0
|
274 |
@internalComponent
|
sl@0
|
275 |
Resets the descriptor pointers for the authority components and the authority.
|
sl@0
|
276 |
|
sl@0
|
277 |
@since 6.0
|
sl@0
|
278 |
@deprecated Deprecated in 9.1
|
sl@0
|
279 |
@post All authority component information is removed and the authority
|
sl@0
|
280 |
descriptor is set to NULL.
|
sl@0
|
281 |
*/
|
sl@0
|
282 |
void TAuthorityC16::Reset()
|
sl@0
|
283 |
{
|
sl@0
|
284 |
// Set descriptor pointers to NULL and lengths to zero
|
sl@0
|
285 |
for( TInt i=0; i<EAuthorityMaxComponents; ++i )
|
sl@0
|
286 |
{
|
sl@0
|
287 |
iComponent[i].Set(NULL,0);
|
sl@0
|
288 |
}
|
sl@0
|
289 |
iAuthorityDes.Set(NULL,0);
|
sl@0
|
290 |
}
|
sl@0
|
291 |
|