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 "TAuthorityParserInternal.h"
|
sl@0
|
19 |
#include <uriutilscommon.h>
|
sl@0
|
20 |
|
sl@0
|
21 |
|
sl@0
|
22 |
//
|
sl@0
|
23 |
//
|
sl@0
|
24 |
// Implementation of TAuthorityParser8
|
sl@0
|
25 |
//
|
sl@0
|
26 |
//
|
sl@0
|
27 |
|
sl@0
|
28 |
/**
|
sl@0
|
29 |
Constructor.
|
sl@0
|
30 |
|
sl@0
|
31 |
@since 6.0
|
sl@0
|
32 |
*/
|
sl@0
|
33 |
EXPORT_C TAuthorityParser8::TAuthorityParser8()
|
sl@0
|
34 |
: TAuthorityC8()
|
sl@0
|
35 |
{
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
/**
|
sl@0
|
39 |
Parses the descriptor aAuthority into authority components.
|
sl@0
|
40 |
|
sl@0
|
41 |
@since 6.0
|
sl@0
|
42 |
@param aAuthority A reference to a descriptor pointer to be parsed.
|
sl@0
|
43 |
@return KErrNone if the descriptor has been parsed into its authority components.
|
sl@0
|
44 |
@post The object references the input descriptor.
|
sl@0
|
45 |
*/
|
sl@0
|
46 |
EXPORT_C TInt TAuthorityParser8::Parse(const TDesC8& aAuthority)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
// Reset the Authority information and then set the authority
|
sl@0
|
49 |
if( iAuthorityDes.Ptr() )
|
sl@0
|
50 |
Reset();
|
sl@0
|
51 |
iAuthorityDes.Set(aAuthority);
|
sl@0
|
52 |
|
sl@0
|
53 |
// Parse the authority
|
sl@0
|
54 |
DoParseAuthority(iAuthorityDes, iComponent);
|
sl@0
|
55 |
return KErrNone;
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
//
|
sl@0
|
59 |
//
|
sl@0
|
60 |
// Implementation of TAuthorityParser16
|
sl@0
|
61 |
//
|
sl@0
|
62 |
//
|
sl@0
|
63 |
|
sl@0
|
64 |
/**
|
sl@0
|
65 |
Constructor.
|
sl@0
|
66 |
|
sl@0
|
67 |
@since 6.0
|
sl@0
|
68 |
@deprecated Deprecated in 9.1
|
sl@0
|
69 |
*/
|
sl@0
|
70 |
EXPORT_C TAuthorityParser16::TAuthorityParser16()
|
sl@0
|
71 |
: TAuthorityC16()
|
sl@0
|
72 |
{
|
sl@0
|
73 |
}
|
sl@0
|
74 |
|
sl@0
|
75 |
/**
|
sl@0
|
76 |
Parses the descriptor aAuthority into authority components.
|
sl@0
|
77 |
|
sl@0
|
78 |
@since 6.0
|
sl@0
|
79 |
@deprecated Deprecated in 9.1
|
sl@0
|
80 |
@param aAuthority A reference to a descriptor pointer to be parsed.
|
sl@0
|
81 |
@return KErrNone if the descriptor has been parsed into its authority components.
|
sl@0
|
82 |
@post The object references the input descriptor.
|
sl@0
|
83 |
*/
|
sl@0
|
84 |
EXPORT_C TInt TAuthorityParser16::Parse(const TDesC16& aAuthority)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
// Reset the Authority information and then set the authority
|
sl@0
|
87 |
if( iAuthorityDes.Ptr() )
|
sl@0
|
88 |
Reset();
|
sl@0
|
89 |
iAuthorityDes.Set(aAuthority);
|
sl@0
|
90 |
|
sl@0
|
91 |
// Parse the authority
|
sl@0
|
92 |
DoParseAuthority(iAuthorityDes, iComponent);
|
sl@0
|
93 |
return KErrNone;
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
//
|
sl@0
|
97 |
//
|
sl@0
|
98 |
// Implementation of templated LOCAL functions
|
sl@0
|
99 |
//
|
sl@0
|
100 |
//
|
sl@0
|
101 |
|
sl@0
|
102 |
/**
|
sl@0
|
103 |
Templated function to parse an authority. The input argument aAuthority points to a
|
sl@0
|
104 |
descriptor with the authority. The parsed authority component information is set in
|
sl@0
|
105 |
the output argument aComponent.
|
sl@0
|
106 |
|
sl@0
|
107 |
@since 6.0
|
sl@0
|
108 |
@param aAuthority The descriptor pointer to the authority.
|
sl@0
|
109 |
@param aComponent The array of descriptor pointers to be updated.
|
sl@0
|
110 |
@pre The array of descriptor pointers in the output argument aComponent must
|
sl@0
|
111 |
be set to NULL.
|
sl@0
|
112 |
@post The parsed authority components will be refered to by the descriptor
|
sl@0
|
113 |
pointers in aComponent. If any components did not exist then the appropriate pointer
|
sl@0
|
114 |
will remain unchanged, i.e. still be NULL.
|
sl@0
|
115 |
*/
|
sl@0
|
116 |
template<class TPtrCType>
|
sl@0
|
117 |
void DoParseAuthority(const TPtrCType& aAuthority, TPtrCType aComponent[])
|
sl@0
|
118 |
{
|
sl@0
|
119 |
// Parse the components
|
sl@0
|
120 |
TPtrCType authority = aAuthority;
|
sl@0
|
121 |
TInt consumed = 0;
|
sl@0
|
122 |
if( (consumed = ParseUserinfo(authority, aComponent[EAuthorityUserinfo])) > 0 )
|
sl@0
|
123 |
{
|
sl@0
|
124 |
authority.Set(authority.Mid(consumed));
|
sl@0
|
125 |
}
|
sl@0
|
126 |
if( (consumed = ParseHost(authority, aComponent[EAuthorityHost])) > 0 )
|
sl@0
|
127 |
{
|
sl@0
|
128 |
authority.Set(authority.Mid(consumed));
|
sl@0
|
129 |
}
|
sl@0
|
130 |
if( (consumed = ParsePort(authority, aComponent[EAuthorityPort])) > 0 )
|
sl@0
|
131 |
{
|
sl@0
|
132 |
authority.Set(authority.Mid(consumed));
|
sl@0
|
133 |
}
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
/**
|
sl@0
|
137 |
Templated function that parses the descriptor for the userinfo component. The input argument
|
sl@0
|
138 |
aAuthority must be set to the beginning of the userinfo component (ie the start of the authority)
|
sl@0
|
139 |
for the userinfo to be correctly parsed. If the userinfo component is found, the output argument
|
sl@0
|
140 |
aComponent will be set to refer to it. The number of characters consumed (ie the number of characters
|
sl@0
|
141 |
to move to the end of this component, including any delimiters) is returned.
|
sl@0
|
142 |
|
sl@0
|
143 |
@since 6.0
|
sl@0
|
144 |
@param aAuthority The descriptor set to the beginning of the userinfo component.
|
sl@0
|
145 |
@param aComponent The output descriptor pointer to refer to the parsed component.
|
sl@0
|
146 |
@return The number of characters consumed in parsing the component.
|
sl@0
|
147 |
@pre The input argument descriptor is set at the beginning of the userinfo component
|
sl@0
|
148 |
to correctly parse it. The output descriptor aComponent is set to NULL.
|
sl@0
|
149 |
@post If the component exists, the output descriptor will refer to it. If
|
sl@0
|
150 |
the component does not exist, then the output decriptor will remain set to NULL.
|
sl@0
|
151 |
*/
|
sl@0
|
152 |
template<class TPtrCType>
|
sl@0
|
153 |
TInt ParseUserinfo(const TPtrCType& aAuthority, TPtrCType& aComponent)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
TInt consumed =0;
|
sl@0
|
156 |
TInt userinfoEndPos = aAuthority.Locate(KUserinfoDelimiter);
|
sl@0
|
157 |
|
sl@0
|
158 |
// Check that the delimiter is there
|
sl@0
|
159 |
if( userinfoEndPos != KErrNotFound )
|
sl@0
|
160 |
{
|
sl@0
|
161 |
// Got a host - store information
|
sl@0
|
162 |
aComponent.Set(aAuthority.Left(userinfoEndPos));
|
sl@0
|
163 |
|
sl@0
|
164 |
// Set consumed amount - include the trailing '@' delimiter
|
sl@0
|
165 |
consumed = userinfoEndPos + 1;
|
sl@0
|
166 |
}
|
sl@0
|
167 |
return consumed;
|
sl@0
|
168 |
}
|
sl@0
|
169 |
|
sl@0
|
170 |
/**
|
sl@0
|
171 |
Templated function that parses the descriptor for the host component. The input argument aAuthority
|
sl@0
|
172 |
must be set to beginning of the host component (ie the end of the userinfo component) for the host
|
sl@0
|
173 |
to be correctly parsed. If the host component is found, the output argument aComponent will be set
|
sl@0
|
174 |
to refer to it. The number of characters consumed (ie the number of characters to move to the end of
|
sl@0
|
175 |
this component, including any delimiters) is returned.
|
sl@0
|
176 |
|
sl@0
|
177 |
@since 6.0
|
sl@0
|
178 |
@param aAuthority The descriptor set to the beginning of the host component.
|
sl@0
|
179 |
@param aComponent The output descriptor pointer to refer to the parsed component.
|
sl@0
|
180 |
@return The number of characters consumed in parsing the component.
|
sl@0
|
181 |
@pre The input argument descriptor is set at the beginning of the host component
|
sl@0
|
182 |
to correctly parse it. The output descriptor aComponent is set to NULL.
|
sl@0
|
183 |
@post If the component exists, the output descriptor will refer to it. If
|
sl@0
|
184 |
the component does not exist, then the output decriptor will remain set to NULL.
|
sl@0
|
185 |
*/
|
sl@0
|
186 |
template<class TPtrCType>
|
sl@0
|
187 |
TInt ParseHost(const TPtrCType& aAuthority, TPtrCType& aComponent)
|
sl@0
|
188 |
{
|
sl@0
|
189 |
// Get the descriptor and look for the host delimiter
|
sl@0
|
190 |
TInt consumed =0;
|
sl@0
|
191 |
|
sl@0
|
192 |
// is this an IPv6 host?
|
sl@0
|
193 |
TInt startIPv6Host = aAuthority.Locate(KIPv6UriOpenBrace);
|
sl@0
|
194 |
|
sl@0
|
195 |
if (startIPv6Host==KErrNotFound)
|
sl@0
|
196 |
{
|
sl@0
|
197 |
// it's an IPv4 address then....
|
sl@0
|
198 |
TInt hostEndPos = aAuthority.Locate(KPortDelimiter);
|
sl@0
|
199 |
|
sl@0
|
200 |
// Check that the delimiter is there
|
sl@0
|
201 |
if( hostEndPos == KErrNotFound )
|
sl@0
|
202 |
hostEndPos = aAuthority.Length();
|
sl@0
|
203 |
|
sl@0
|
204 |
if( hostEndPos > 0 )
|
sl@0
|
205 |
{
|
sl@0
|
206 |
// Got a host - store information
|
sl@0
|
207 |
aComponent.Set(aAuthority.Left(hostEndPos));
|
sl@0
|
208 |
|
sl@0
|
209 |
// Set consumed amount
|
sl@0
|
210 |
consumed = hostEndPos;
|
sl@0
|
211 |
}
|
sl@0
|
212 |
}
|
sl@0
|
213 |
else
|
sl@0
|
214 |
{
|
sl@0
|
215 |
// This is an IPv6 address, so it MUST have the closing brace too....
|
sl@0
|
216 |
TInt endIPv6Host = aAuthority.Locate(KIPv6UriCloseBrace);
|
sl@0
|
217 |
|
sl@0
|
218 |
// Return an error if the closing IPv6 delimiter isn't there.
|
sl@0
|
219 |
if (endIPv6Host==KErrNotFound)
|
sl@0
|
220 |
return KUriUtilsErrInvalidUri;
|
sl@0
|
221 |
|
sl@0
|
222 |
// The host shouldnt include the '[' and ']'
|
sl@0
|
223 |
aComponent.Set(aAuthority.Mid(startIPv6Host+1, endIPv6Host - (startIPv6Host + 1) ));
|
sl@0
|
224 |
|
sl@0
|
225 |
// set the consumed amount to include the closing brace
|
sl@0
|
226 |
consumed = endIPv6Host+1;
|
sl@0
|
227 |
}
|
sl@0
|
228 |
|
sl@0
|
229 |
return consumed;
|
sl@0
|
230 |
}
|
sl@0
|
231 |
|
sl@0
|
232 |
/**
|
sl@0
|
233 |
Templated function that parses the descriptor for the port component. The input argument aAuthority
|
sl@0
|
234 |
must be set to beginning of the port component (ie the end of the host component) for the port to be
|
sl@0
|
235 |
correctly parsed. If the port component is found, the output argument aComponent will be set to refer
|
sl@0
|
236 |
to it. The number of characters consumed (ie the number of characters to move to the end of this component,
|
sl@0
|
237 |
including any delimiters) is returned.
|
sl@0
|
238 |
|
sl@0
|
239 |
@since 6.0
|
sl@0
|
240 |
@param aAuthority The descriptor set to the beginning of the port component.
|
sl@0
|
241 |
@param aComponent The output descriptor pointer to refer to the parsed component.
|
sl@0
|
242 |
@return The number of characters consumed in parsing the component.
|
sl@0
|
243 |
@pre The input argument descriptor is set at the beginning of the port component
|
sl@0
|
244 |
to correctly parse it. The output descriptor aComponent is set to NULL.
|
sl@0
|
245 |
@post If the component exists, the output descriptor will refer to it. If
|
sl@0
|
246 |
the component does not exist, then the output decriptor will remain set to NULL.
|
sl@0
|
247 |
*/
|
sl@0
|
248 |
template<class TPtrCType>
|
sl@0
|
249 |
TInt ParsePort(const TPtrCType& aAuthority, TPtrCType& aComponent)
|
sl@0
|
250 |
{
|
sl@0
|
251 |
// Get the descriptor and look for the port delimiter
|
sl@0
|
252 |
TInt consumed =0;
|
sl@0
|
253 |
TInt portEndPos = aAuthority.Length();
|
sl@0
|
254 |
|
sl@0
|
255 |
// We have a port
|
sl@0
|
256 |
if( portEndPos > 0 )
|
sl@0
|
257 |
{
|
sl@0
|
258 |
// Got a host - store information; need to exclude the leading ':'
|
sl@0
|
259 |
aComponent.Set(aAuthority.Mid(1, portEndPos - 1));
|
sl@0
|
260 |
|
sl@0
|
261 |
// Set consumed amount - this includes the leading ':' delimiter
|
sl@0
|
262 |
consumed = portEndPos;
|
sl@0
|
263 |
}
|
sl@0
|
264 |
return consumed;
|
sl@0
|
265 |
}
|