1 | /*
|
---|
2 | * The Apache Software License, Version 1.1
|
---|
3 | *
|
---|
4 | * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
|
---|
5 | * reserved.
|
---|
6 | *
|
---|
7 | * Redistribution and use in source and binary forms, with or without
|
---|
8 | * modification, are permitted provided that the following conditions
|
---|
9 | * are met:
|
---|
10 | *
|
---|
11 | * 1. Redistributions of source code must retain the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer.
|
---|
13 | *
|
---|
14 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
15 | * notice, this list of conditions and the following disclaimer in
|
---|
16 | * the documentation and/or other materials provided with the
|
---|
17 | * distribution.
|
---|
18 | *
|
---|
19 | * 3. The end-user documentation included with the redistribution,
|
---|
20 | * if any, must include the following acknowledgment:
|
---|
21 | * "This product includes software developed by the
|
---|
22 | * Apache Software Foundation (http://www.apache.org/)."
|
---|
23 | * Alternately, this acknowledgment may appear in the software itself,
|
---|
24 | * if and wherever such third-party acknowledgments normally appear.
|
---|
25 | *
|
---|
26 | * 4. The names "Xerces" and "Apache Software Foundation" must
|
---|
27 | * not be used to endorse or promote products derived from this
|
---|
28 | * software without prior written permission. For written
|
---|
29 | * permission, please contact apache\@apache.org.
|
---|
30 | *
|
---|
31 | * 5. Products derived from this software may not be called "Apache",
|
---|
32 | * nor may "Apache" appear in their name, without prior written
|
---|
33 | * permission of the Apache Software Foundation.
|
---|
34 | *
|
---|
35 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
---|
36 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
37 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
38 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
---|
39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
---|
42 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
44 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
---|
45 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
46 | * SUCH DAMAGE.
|
---|
47 | * ====================================================================
|
---|
48 | *
|
---|
49 | * This software consists of voluntary contributions made by many
|
---|
50 | * individuals on behalf of the Apache Software Foundation, and was
|
---|
51 | * originally based on software copyright (c) 1999, International
|
---|
52 | * Business Machines, Inc., http://www.ibm.com . For more information
|
---|
53 | * on the Apache Software Foundation, please see
|
---|
54 | * <http://www.apache.org/>.
|
---|
55 | */
|
---|
56 |
|
---|
57 | /*
|
---|
58 | * $Id: XMLUri.hpp,v 1.16 2004/01/12 22:01:02 cargilld Exp $
|
---|
59 | * $Log: XMLUri.hpp,v $
|
---|
60 | * Revision 1.16 2004/01/12 22:01:02 cargilld
|
---|
61 | * Minor performance change for handling reserved and unreserved characters.
|
---|
62 | *
|
---|
63 | * Revision 1.15 2003/12/17 00:18:35 cargilld
|
---|
64 | * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
|
---|
65 | *
|
---|
66 | * Revision 1.14 2003/12/11 22:21:25 neilg
|
---|
67 | * fixes for the URI implementation to take registry names into account; much thanks to Michael Glavassevich
|
---|
68 | *
|
---|
69 | * Revision 1.13 2003/12/02 17:50:21 neilg
|
---|
70 | * additional fix for bug 25118; once again, thanks to Jeroen Whitmond
|
---|
71 | *
|
---|
72 | * Revision 1.12 2003/10/01 00:20:41 knoaman
|
---|
73 | * Add a static method to check whether a given string is a valid URI.
|
---|
74 | *
|
---|
75 | * Revision 1.11 2003/09/25 22:23:25 peiyongz
|
---|
76 | * Implementation of Serialization/Deserialization
|
---|
77 | *
|
---|
78 | * Revision 1.10 2003/07/25 10:15:16 gareth
|
---|
79 | * Patch by Michael Glavassevich
|
---|
80 | *
|
---|
81 | * The patch fixes Bugzilla #19787, #20006, #20009, #20010 and #20287, and
|
---|
82 | * several other issues. A summary of the changes is listed below:
|
---|
83 | *
|
---|
84 | * 1. Added '[' and ']' to reserved characters as per RFC 2732.
|
---|
85 | * 2. '[' and ']' added in RFC 2732, are not allowed in path segments, but
|
---|
86 | * may appear in the opaque part.
|
---|
87 | * 3. No URI can begin with a ':'.
|
---|
88 | * 4. URI has no scheme if ':' occurs in a URI after '?' or '#', it's part of
|
---|
89 | * the query string or fragment.
|
---|
90 | * 5. Whitespace (even escaped as %20) is not permitted in the authority
|
---|
91 | * portion of a URI.
|
---|
92 | * 6. IPv4 addresses must match 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "."
|
---|
93 | * 1*3DIGIT. Since RFC 2732.
|
---|
94 | * 7. IPv4 addresses are 32-bit, therefore no segment may be larger than 255.
|
---|
95 | * This isn't expressed by the grammar.
|
---|
96 | * 8. Hostnames cannot end with a '-'.
|
---|
97 | * 9. Labels in a hostname must be 63 bytes or less [RFC 1034].
|
---|
98 | * 10. Hostnames may be no longer than 255 bytes [RFC 1034]. (That
|
---|
99 | * restriction was already there. I just moved it inwards.
|
---|
100 | * 11. Added support for IPv6 references added in RFC 2732. URIs such as
|
---|
101 | * http://[::ffff:1.2.3.4] are valid. The BNF in RFC 2373 isn't correct. IPv6
|
---|
102 | * addresses are read according to section 2.2 of RFC 2373.
|
---|
103 | *
|
---|
104 | * Revision 1.9 2003/05/16 06:01:53 knoaman
|
---|
105 | * Partial implementation of the configurable memory manager.
|
---|
106 | *
|
---|
107 | * Revision 1.8 2003/05/15 19:07:46 knoaman
|
---|
108 | * Partial implementation of the configurable memory manager.
|
---|
109 | *
|
---|
110 | * Revision 1.7 2003/01/06 19:43:18 tng
|
---|
111 | * New feature StandardUriConformant to force strict standard uri conformance.
|
---|
112 | *
|
---|
113 | * Revision 1.6 2002/11/21 15:42:39 gareth
|
---|
114 | * Implemented copy constructor and operator =. Patch by Jennifer Schachter.
|
---|
115 | *
|
---|
116 | * Revision 1.5 2002/11/04 15:22:05 tng
|
---|
117 | * C++ Namespace Support.
|
---|
118 | *
|
---|
119 | * Revision 1.4 2002/09/23 18:41:00 tng
|
---|
120 | * DOM L3: Support baseURI. Add fURIText to XMLUri. Added by Gareth Reakes and Thomas Ford.
|
---|
121 | *
|
---|
122 | * Revision 1.3 2002/08/23 20:45:24 tng
|
---|
123 | * .Memory leak fix: XMLUri data not deleted if constructor failed.
|
---|
124 | *
|
---|
125 | * Revision 1.2 2002/02/20 18:17:02 tng
|
---|
126 | * [Bug 5977] Warnings on generating apiDocs.
|
---|
127 | *
|
---|
128 | * Revision 1.1.1.1 2002/02/01 22:22:17 peiyongz
|
---|
129 | * sane_include
|
---|
130 | *
|
---|
131 | * Revision 1.3 2001/08/29 19:03:03 peiyongz
|
---|
132 | * Bugzilla# 2816:on AIX 4.2, xlC 3 r ev.1, Compilation error on inline method
|
---|
133 | *
|
---|
134 | * Revision 1.2 2001/08/16 14:09:44 peiyongz
|
---|
135 | * Removed unused ctors and methods
|
---|
136 | *
|
---|
137 | * Revision 1.1 2001/08/10 16:23:41 peiyongz
|
---|
138 | * XMLUri: creation
|
---|
139 | *
|
---|
140 | *
|
---|
141 | */
|
---|
142 |
|
---|
143 | #if !defined(XMLURI_HPP)
|
---|
144 | #define XMLURI_HPP
|
---|
145 |
|
---|
146 | #include <xercesc/util/XMemory.hpp>
|
---|
147 | #include <xercesc/util/XMLString.hpp>
|
---|
148 |
|
---|
149 | #include <xercesc/internal/XSerializable.hpp>
|
---|
150 |
|
---|
151 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
152 |
|
---|
153 | /*
|
---|
154 | * This class is a direct port of Java's URI class, to distinguish
|
---|
155 | * itself from the XMLURL, we use the name XMLUri instead of
|
---|
156 | * XMLURI.
|
---|
157 | *
|
---|
158 | * TODO: how to relate XMLUri and XMLURL since URL is part of URI.
|
---|
159 | *
|
---|
160 | */
|
---|
161 |
|
---|
162 | class XMLUTIL_EXPORT XMLUri : public XSerializable, public XMemory
|
---|
163 | {
|
---|
164 | public:
|
---|
165 |
|
---|
166 | // -----------------------------------------------------------------------
|
---|
167 | // Constructors and Destructor
|
---|
168 | // -----------------------------------------------------------------------
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * Construct a new URI from a URI specification string.
|
---|
172 | *
|
---|
173 | * If the specification follows the "generic URI" syntax, (two slashes
|
---|
174 | * following the first colon), the specification will be parsed
|
---|
175 | * accordingly - setting the
|
---|
176 | * scheme,
|
---|
177 | * userinfo,
|
---|
178 | * host,
|
---|
179 | * port,
|
---|
180 | * path,
|
---|
181 | * querystring and
|
---|
182 | * fragment
|
---|
183 | * fields as necessary.
|
---|
184 | *
|
---|
185 | * If the specification does not follow the "generic URI" syntax,
|
---|
186 | * the specification is parsed into a
|
---|
187 | * scheme and
|
---|
188 | * scheme-specific part (stored as the path) only.
|
---|
189 | *
|
---|
190 | * @param uriSpec the URI specification string (cannot be null or empty)
|
---|
191 | *
|
---|
192 | * @param manager Pointer to the memory manager to be used to
|
---|
193 | * allocate objects.
|
---|
194 | *
|
---|
195 | * ctor# 2
|
---|
196 | *
|
---|
197 | */
|
---|
198 | XMLUri(const XMLCh* const uriSpec,
|
---|
199 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
200 |
|
---|
201 | /**
|
---|
202 | * Construct a new URI from a base URI and a URI specification string.
|
---|
203 | * The URI specification string may be a relative URI.
|
---|
204 | *
|
---|
205 | * @param baseURI the base URI (cannot be null if uriSpec is null or
|
---|
206 | * empty)
|
---|
207 | *
|
---|
208 | * @param uriSpec the URI specification string (cannot be null or
|
---|
209 | * empty if base is null)
|
---|
210 | *
|
---|
211 | * @param manager Pointer to the memory manager to be used to
|
---|
212 | * allocate objects.
|
---|
213 | *
|
---|
214 | * ctor# 7 relative ctor
|
---|
215 | *
|
---|
216 | */
|
---|
217 | XMLUri(const XMLUri* const baseURI
|
---|
218 | , const XMLCh* const uriSpec
|
---|
219 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * Copy constructor
|
---|
223 | */
|
---|
224 | XMLUri(const XMLUri& toCopy);
|
---|
225 | XMLUri& operator=(const XMLUri& toAssign);
|
---|
226 |
|
---|
227 | virtual ~XMLUri();
|
---|
228 |
|
---|
229 | // -----------------------------------------------------------------------
|
---|
230 | // Getter methods
|
---|
231 | // -----------------------------------------------------------------------
|
---|
232 | /**
|
---|
233 | * Get the URI as a string specification. See RFC 2396 Section 5.2.
|
---|
234 | *
|
---|
235 | * @return the URI string specification
|
---|
236 | */
|
---|
237 | const XMLCh* getUriText() const;
|
---|
238 |
|
---|
239 | /**
|
---|
240 | * Get the scheme for this URI.
|
---|
241 | *
|
---|
242 | * @return the scheme for this URI
|
---|
243 | */
|
---|
244 | const XMLCh* getScheme() const;
|
---|
245 |
|
---|
246 | /**
|
---|
247 | * Get the userinfo for this URI.
|
---|
248 | *
|
---|
249 | * @return the userinfo for this URI (null if not specified).
|
---|
250 | */
|
---|
251 | const XMLCh* getUserInfo() const;
|
---|
252 |
|
---|
253 |
|
---|
254 | /**
|
---|
255 | * Get the host for this URI.
|
---|
256 | *
|
---|
257 | * @return the host for this URI (null if not specified).
|
---|
258 | */
|
---|
259 | const XMLCh* getHost() const;
|
---|
260 |
|
---|
261 | /**
|
---|
262 | * Get the port for this URI.
|
---|
263 | *
|
---|
264 | * @return the port for this URI (-1 if not specified).
|
---|
265 | */
|
---|
266 | int getPort() const;
|
---|
267 |
|
---|
268 | /**
|
---|
269 | * Get the registry based authority for this URI.
|
---|
270 | *
|
---|
271 | * @return the registry based authority (null if not specified).
|
---|
272 | */
|
---|
273 | const XMLCh* getRegBasedAuthority() const;
|
---|
274 |
|
---|
275 | /**
|
---|
276 | * Get the path for this URI. Note that the value returned is the path
|
---|
277 | * only and does not include the query string or fragment.
|
---|
278 | *
|
---|
279 | * @return the path for this URI.
|
---|
280 | */
|
---|
281 | const XMLCh* getPath() const;
|
---|
282 |
|
---|
283 | /**
|
---|
284 | * Get the query string for this URI.
|
---|
285 | *
|
---|
286 | * @return the query string for this URI. Null is returned if there
|
---|
287 | * was no "?" in the URI spec, empty string if there was a
|
---|
288 | * "?" but no query string following it.
|
---|
289 | */
|
---|
290 | const XMLCh* getQueryString() const;
|
---|
291 |
|
---|
292 | /**
|
---|
293 | * Get the fragment for this URI.
|
---|
294 | *
|
---|
295 | * @return the fragment for this URI. Null is returned if there
|
---|
296 | * was no "#" in the URI spec, empty string if there was a
|
---|
297 | * "#" but no fragment following it.
|
---|
298 | */
|
---|
299 | const XMLCh* getFragment() const;
|
---|
300 |
|
---|
301 | // -----------------------------------------------------------------------
|
---|
302 | // Setter methods
|
---|
303 | // -----------------------------------------------------------------------
|
---|
304 |
|
---|
305 | /**
|
---|
306 | * Set the scheme for this URI. The scheme is converted to lowercase
|
---|
307 | * before it is set.
|
---|
308 | *
|
---|
309 | * @param newScheme the scheme for this URI (cannot be null)
|
---|
310 | *
|
---|
311 | */
|
---|
312 | void setScheme(const XMLCh* const newScheme);
|
---|
313 |
|
---|
314 | /**
|
---|
315 | * Set the userinfo for this URI. If a non-null value is passed in and
|
---|
316 | * the host value is null, then an exception is thrown.
|
---|
317 | *
|
---|
318 | * @param newUserInfo the userinfo for this URI
|
---|
319 | *
|
---|
320 | */
|
---|
321 | void setUserInfo(const XMLCh* const newUserInfo);
|
---|
322 |
|
---|
323 | /**
|
---|
324 | * Set the host for this URI. If null is passed in, the userinfo
|
---|
325 | * field is also set to null and the port is set to -1.
|
---|
326 | *
|
---|
327 | * Note: This method overwrites registry based authority if it
|
---|
328 | * previously existed in this URI.
|
---|
329 | *
|
---|
330 | * @param newHost the host for this URI
|
---|
331 | *
|
---|
332 | */
|
---|
333 | void setHost(const XMLCh* const newHost);
|
---|
334 |
|
---|
335 | /**
|
---|
336 | * Set the port for this URI. -1 is used to indicate that the port is
|
---|
337 | * not specified, otherwise valid port numbers are between 0 and 65535.
|
---|
338 | * If a valid port number is passed in and the host field is null,
|
---|
339 | * an exception is thrown.
|
---|
340 | *
|
---|
341 | * @param newPort the port number for this URI
|
---|
342 | *
|
---|
343 | */
|
---|
344 | void setPort(int newPort);
|
---|
345 |
|
---|
346 | /**
|
---|
347 | * Sets the registry based authority for this URI.
|
---|
348 | *
|
---|
349 | * Note: This method overwrites server based authority
|
---|
350 | * if it previously existed in this URI.
|
---|
351 | *
|
---|
352 | * @param newRegAuth the registry based authority for this URI
|
---|
353 | */
|
---|
354 | void setRegBasedAuthority(const XMLCh* const newRegAuth);
|
---|
355 |
|
---|
356 | /**
|
---|
357 | * Set the path for this URI.
|
---|
358 | *
|
---|
359 | * If the supplied path is null, then the
|
---|
360 | * query string and fragment are set to null as well.
|
---|
361 | *
|
---|
362 | * If the supplied path includes a query string and/or fragment,
|
---|
363 | * these fields will be parsed and set as well.
|
---|
364 | *
|
---|
365 | * Note:
|
---|
366 | *
|
---|
367 | * For URIs following the "generic URI" syntax, the path
|
---|
368 | * specified should start with a slash.
|
---|
369 | *
|
---|
370 | * For URIs that do not follow the generic URI syntax, this method
|
---|
371 | * sets the scheme-specific part.
|
---|
372 | *
|
---|
373 | * @param newPath the path for this URI (may be null)
|
---|
374 | *
|
---|
375 | */
|
---|
376 | void setPath(const XMLCh* const newPath);
|
---|
377 |
|
---|
378 | /**
|
---|
379 | * Set the query string for this URI. A non-null value is valid only
|
---|
380 | * if this is an URI conforming to the generic URI syntax and
|
---|
381 | * the path value is not null.
|
---|
382 | *
|
---|
383 | * @param newQueryString the query string for this URI
|
---|
384 | *
|
---|
385 | */
|
---|
386 | void setQueryString(const XMLCh* const newQueryString);
|
---|
387 |
|
---|
388 | /**
|
---|
389 | * Set the fragment for this URI. A non-null value is valid only
|
---|
390 | * if this is a URI conforming to the generic URI syntax and
|
---|
391 | * the path value is not null.
|
---|
392 | *
|
---|
393 | * @param newFragment the fragment for this URI
|
---|
394 | *
|
---|
395 | */
|
---|
396 | void setFragment(const XMLCh* const newFragment);
|
---|
397 |
|
---|
398 | // -----------------------------------------------------------------------
|
---|
399 | // Miscellaneous methods
|
---|
400 | // -----------------------------------------------------------------------
|
---|
401 |
|
---|
402 | /**
|
---|
403 | * Determine whether a given string contains only URI characters (also
|
---|
404 | * called "uric" in RFC 2396). uric consist of all reserved
|
---|
405 | * characters, unreserved characters and escaped characters.
|
---|
406 | *
|
---|
407 | * @return true if the string is comprised of uric, false otherwise
|
---|
408 | */
|
---|
409 | static bool isURIString(const XMLCh* const uric);
|
---|
410 |
|
---|
411 | /**
|
---|
412 | * Determine whether a given string is a valid URI
|
---|
413 | */
|
---|
414 | static bool isValidURI( const XMLUri* const baseURI
|
---|
415 | , const XMLCh* const uriStr);
|
---|
416 | /**
|
---|
417 | * Determine whether a given string is a valid URI
|
---|
418 | */
|
---|
419 | static bool isValidURI( bool haveBaseURI
|
---|
420 | , const XMLCh* const uriStr);
|
---|
421 |
|
---|
422 | /***
|
---|
423 | * Support for Serialization/De-serialization
|
---|
424 | ***/
|
---|
425 | DECL_XSERIALIZABLE(XMLUri)
|
---|
426 |
|
---|
427 | XMLUri(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
428 |
|
---|
429 | private:
|
---|
430 |
|
---|
431 | static const XMLCh MARK_OR_RESERVED_CHARACTERS[];
|
---|
432 | static const XMLCh RESERVED_CHARACTERS[];
|
---|
433 | static const XMLCh MARK_CHARACTERS[];
|
---|
434 | static const XMLCh SCHEME_CHARACTERS[];
|
---|
435 | static const XMLCh USERINFO_CHARACTERS[];
|
---|
436 | static const XMLCh REG_NAME_CHARACTERS[];
|
---|
437 | static const XMLCh PATH_CHARACTERS[];
|
---|
438 |
|
---|
439 | //helper method for getUriText
|
---|
440 | void buildFullText();
|
---|
441 |
|
---|
442 | // -----------------------------------------------------------------------
|
---|
443 | // Private helper methods
|
---|
444 | // -----------------------------------------------------------------------
|
---|
445 |
|
---|
446 | /**
|
---|
447 | * Determine whether a character is a reserved character:
|
---|
448 | *
|
---|
449 | * @return true if the string contains any reserved characters
|
---|
450 | */
|
---|
451 | static bool isReservedCharacter(const XMLCh theChar);
|
---|
452 |
|
---|
453 | /**
|
---|
454 | * Determine whether a character is a path character:
|
---|
455 | *
|
---|
456 | * @return true if the character is path character
|
---|
457 | */
|
---|
458 | static bool isPathCharacter(const XMLCh theChar);
|
---|
459 |
|
---|
460 | /**
|
---|
461 | * Determine whether a char is an unreserved character.
|
---|
462 | *
|
---|
463 | * @return true if the char is unreserved, false otherwise
|
---|
464 | */
|
---|
465 | static bool isUnreservedCharacter(const XMLCh theChar);
|
---|
466 |
|
---|
467 | /**
|
---|
468 | * Determine whether a char is an reserved or unreserved character.
|
---|
469 | *
|
---|
470 | * @return true if the char is reserved or unreserved, false otherwise
|
---|
471 | */
|
---|
472 | static bool isReservedOrUnreservedCharacter(const XMLCh theChar);
|
---|
473 |
|
---|
474 | /**
|
---|
475 | * Determine whether a scheme conforms to the rules for a scheme name.
|
---|
476 | * A scheme is conformant if it starts with an alphanumeric, and
|
---|
477 | * contains only alphanumerics, '+','-' and '.'.
|
---|
478 | *
|
---|
479 | * @return true if the scheme is conformant, false otherwise
|
---|
480 | */
|
---|
481 | static bool isConformantSchemeName(const XMLCh* const scheme);
|
---|
482 |
|
---|
483 | /**
|
---|
484 | * Determine whether a userInfo conforms to the rules for a userinfo.
|
---|
485 | *
|
---|
486 | * @return true if the scheme is conformant, false otherwise
|
---|
487 | */
|
---|
488 | static void isConformantUserInfo(const XMLCh* const userInfo
|
---|
489 | , MemoryManager* const manager);
|
---|
490 |
|
---|
491 | /**
|
---|
492 | * Determines whether the components host, port, and user info
|
---|
493 | * are valid as a server authority.
|
---|
494 | *
|
---|
495 | * @return true if the given host, port, and userinfo compose
|
---|
496 | * a valid server authority
|
---|
497 | */
|
---|
498 | static bool isValidServerBasedAuthority(const XMLCh* const host
|
---|
499 | , const int hostLen
|
---|
500 | , const int port
|
---|
501 | , const XMLCh* const userinfo
|
---|
502 | , const int userLen);
|
---|
503 |
|
---|
504 | /**
|
---|
505 | * Determines whether the components host, port, and user info
|
---|
506 | * are valid as a server authority.
|
---|
507 | *
|
---|
508 | * @return true if the given host, port, and userinfo compose
|
---|
509 | * a valid server authority
|
---|
510 | */
|
---|
511 | static bool isValidServerBasedAuthority(const XMLCh* const host
|
---|
512 | , const int port
|
---|
513 | , const XMLCh* const userinfo
|
---|
514 | , MemoryManager* const manager);
|
---|
515 |
|
---|
516 | /**
|
---|
517 | * Determines whether the given string is a registry based authority.
|
---|
518 | *
|
---|
519 | * @param authority the authority component of a URI
|
---|
520 | *
|
---|
521 | * @return true if the given string is a registry based authority
|
---|
522 | */
|
---|
523 | static bool isValidRegistryBasedAuthority(const XMLCh* const authority
|
---|
524 | , const int authLen);
|
---|
525 |
|
---|
526 | /**
|
---|
527 | * Determines whether the given string is a registry based authority.
|
---|
528 | *
|
---|
529 | * @param authority the authority component of a URI
|
---|
530 | *
|
---|
531 | * @return true if the given string is a registry based authority
|
---|
532 | */
|
---|
533 | static bool isValidRegistryBasedAuthority(const XMLCh* const authority);
|
---|
534 |
|
---|
535 | /**
|
---|
536 | * Determine whether a string is syntactically capable of representing
|
---|
537 | * a valid IPv4 address, IPv6 reference or the domain name of a network host.
|
---|
538 | *
|
---|
539 | * A valid IPv4 address consists of four decimal digit groups
|
---|
540 | * separated by a '.'.
|
---|
541 | *
|
---|
542 | * See RFC 2732 Section 3, and RFC 2373 Section 2.2, for the
|
---|
543 | * definition of IPv6 references.
|
---|
544 | *
|
---|
545 | * A hostname consists of domain labels (each of which must begin and
|
---|
546 | * end with an alphanumeric but may contain '-') separated by a '.'.
|
---|
547 | * See RFC 2396 Section 3.2.2.
|
---|
548 | *
|
---|
549 | * @return true if the string is a syntactically valid IPv4 address
|
---|
550 | * or hostname
|
---|
551 | */
|
---|
552 | static bool isWellFormedAddress(const XMLCh* const addr
|
---|
553 | , MemoryManager* const manager);
|
---|
554 |
|
---|
555 | /**
|
---|
556 | * Determines whether a string is an IPv4 address as defined by
|
---|
557 | * RFC 2373, and under the further constraint that it must be a 32-bit
|
---|
558 | * address. Though not expressed in the grammar, in order to satisfy
|
---|
559 | * the 32-bit address constraint, each segment of the address cannot
|
---|
560 | * be greater than 255 (8 bits of information).
|
---|
561 | *
|
---|
562 | * @return true if the string is a syntactically valid IPv4 address
|
---|
563 | */
|
---|
564 | static bool isWellFormedIPv4Address(const XMLCh* const addr, const int length);
|
---|
565 |
|
---|
566 | /**
|
---|
567 | * Determines whether a string is an IPv6 reference as defined
|
---|
568 | * by RFC 2732, where IPv6address is defined in RFC 2373. The
|
---|
569 | * IPv6 address is parsed according to Section 2.2 of RFC 2373,
|
---|
570 | * with the additional constraint that the address be composed of
|
---|
571 | * 128 bits of information.
|
---|
572 | *
|
---|
573 | * Note: The BNF expressed in RFC 2373 Appendix B does not
|
---|
574 | * accurately describe section 2.2, and was in fact removed from
|
---|
575 | * RFC 3513, the successor of RFC 2373.
|
---|
576 | *
|
---|
577 | * @return true if the string is a syntactically valid IPv6 reference
|
---|
578 | */
|
---|
579 | static bool isWellFormedIPv6Reference(const XMLCh* const addr, const int length);
|
---|
580 |
|
---|
581 | /**
|
---|
582 | * Helper function for isWellFormedIPv6Reference which scans the
|
---|
583 | * hex sequences of an IPv6 address. It returns the index of the
|
---|
584 | * next character to scan in the address, or -1 if the string
|
---|
585 | * cannot match a valid IPv6 address.
|
---|
586 | *
|
---|
587 | * @param address the string to be scanned
|
---|
588 | * @param index the beginning index (inclusive)
|
---|
589 | * @param end the ending index (exclusive)
|
---|
590 | * @param counter a counter for the number of 16-bit sections read
|
---|
591 | * in the address
|
---|
592 | *
|
---|
593 | * @return the index of the next character to scan, or -1 if the
|
---|
594 | * string cannot match a valid IPv6 address
|
---|
595 | */
|
---|
596 | static int scanHexSequence (const XMLCh* const addr, int index, int end, int& counter);
|
---|
597 |
|
---|
598 | /**
|
---|
599 | * Get the indicator as to whether this URI uses the "generic URI"
|
---|
600 | * syntax.
|
---|
601 | *
|
---|
602 | * @return true if this URI uses the "generic URI" syntax, false
|
---|
603 | * otherwise
|
---|
604 | */
|
---|
605 | bool isGenericURI();
|
---|
606 |
|
---|
607 | // -----------------------------------------------------------------------
|
---|
608 | // Miscellaneous methods
|
---|
609 | // -----------------------------------------------------------------------
|
---|
610 |
|
---|
611 | /**
|
---|
612 | * Initialize all fields of this URI from another URI.
|
---|
613 | *
|
---|
614 | * @param toCopy the URI to copy (cannot be null)
|
---|
615 | */
|
---|
616 | void initialize(const XMLUri& toCopy);
|
---|
617 |
|
---|
618 | /**
|
---|
619 | * Initializes this URI from a base URI and a URI specification string.
|
---|
620 | * See RFC 2396 Section 4 and Appendix B for specifications on parsing
|
---|
621 | * the URI and Section 5 for specifications on resolving relative URIs
|
---|
622 | * and relative paths.
|
---|
623 | *
|
---|
624 | * @param baseURI the base URI (may be null if uriSpec is an absolute
|
---|
625 | * URI)
|
---|
626 | *
|
---|
627 | * @param uriSpec the URI spec string which may be an absolute or
|
---|
628 | * relative URI (can only be null/empty if base
|
---|
629 | * is not null)
|
---|
630 | *
|
---|
631 | */
|
---|
632 | void initialize(const XMLUri* const baseURI
|
---|
633 | , const XMLCh* const uriSpec);
|
---|
634 |
|
---|
635 | /**
|
---|
636 | * Initialize the scheme for this URI from a URI string spec.
|
---|
637 | *
|
---|
638 | * @param uriSpec the URI specification (cannot be null)
|
---|
639 | *
|
---|
640 | */
|
---|
641 | void initializeScheme(const XMLCh* const uriSpec);
|
---|
642 |
|
---|
643 | /**
|
---|
644 | * Initialize the authority (userinfo, host and port) for this
|
---|
645 | * URI from a URI string spec.
|
---|
646 | *
|
---|
647 | * @param uriSpec the URI specification (cannot be null)
|
---|
648 | *
|
---|
649 | */
|
---|
650 | void initializeAuthority(const XMLCh* const uriSpec);
|
---|
651 |
|
---|
652 | /**
|
---|
653 | * Initialize the path for this URI from a URI string spec.
|
---|
654 | *
|
---|
655 | * @param uriSpec the URI specification (cannot be null)
|
---|
656 | *
|
---|
657 | */
|
---|
658 | void initializePath(const XMLCh* const uriSpec);
|
---|
659 |
|
---|
660 | /**
|
---|
661 | * cleanup the data variables
|
---|
662 | *
|
---|
663 | */
|
---|
664 | void cleanUp();
|
---|
665 |
|
---|
666 | static bool isConformantSchemeName(const XMLCh* const scheme,
|
---|
667 | const int schemeLen);
|
---|
668 | static bool processScheme(const XMLCh* const uriStr, int& index);
|
---|
669 | static bool processAuthority(const XMLCh* const uriStr, const int authLen);
|
---|
670 | static bool isWellFormedAddress(const XMLCh* const addr, const int addrLen);
|
---|
671 | static bool processPath(const XMLCh* const pathStr, const int pathStrLen,
|
---|
672 | const bool isSchemePresent);
|
---|
673 |
|
---|
674 | // -----------------------------------------------------------------------
|
---|
675 | // Data members
|
---|
676 | //
|
---|
677 | // for all the data member, we own it,
|
---|
678 | // responsible for the creation and/or deletion for
|
---|
679 | // the memory allocated.
|
---|
680 | //
|
---|
681 | // -----------------------------------------------------------------------
|
---|
682 | XMLCh* fScheme;
|
---|
683 | XMLCh* fUserInfo;
|
---|
684 | XMLCh* fHost;
|
---|
685 | int fPort;
|
---|
686 | XMLCh* fRegAuth;
|
---|
687 | XMLCh* fPath;
|
---|
688 | XMLCh* fQueryString;
|
---|
689 | XMLCh* fFragment;
|
---|
690 | XMLCh* fURIText;
|
---|
691 | MemoryManager* fMemoryManager;
|
---|
692 | };
|
---|
693 |
|
---|
694 | // ---------------------------------------------------------------------------
|
---|
695 | // XMLUri: Getter methods
|
---|
696 | // ---------------------------------------------------------------------------
|
---|
697 | inline const XMLCh* XMLUri::getScheme() const
|
---|
698 | {
|
---|
699 | return fScheme;
|
---|
700 | }
|
---|
701 |
|
---|
702 | inline const XMLCh* XMLUri::getUserInfo() const
|
---|
703 | {
|
---|
704 | return fUserInfo;
|
---|
705 | }
|
---|
706 |
|
---|
707 | inline const XMLCh* XMLUri::getHost() const
|
---|
708 | {
|
---|
709 | return fHost;
|
---|
710 | }
|
---|
711 |
|
---|
712 | inline int XMLUri::getPort() const
|
---|
713 | {
|
---|
714 | return fPort;
|
---|
715 | }
|
---|
716 |
|
---|
717 | inline const XMLCh* XMLUri::getRegBasedAuthority() const
|
---|
718 | {
|
---|
719 | return fRegAuth;
|
---|
720 | }
|
---|
721 |
|
---|
722 | inline const XMLCh* XMLUri::getPath() const
|
---|
723 | {
|
---|
724 | return fPath;
|
---|
725 | }
|
---|
726 |
|
---|
727 | inline const XMLCh* XMLUri::getQueryString() const
|
---|
728 | {
|
---|
729 | return fQueryString;
|
---|
730 | }
|
---|
731 |
|
---|
732 | inline const XMLCh* XMLUri::getFragment() const
|
---|
733 | {
|
---|
734 | return fFragment;
|
---|
735 | }
|
---|
736 |
|
---|
737 | inline const XMLCh* XMLUri::getUriText() const
|
---|
738 | {
|
---|
739 | //
|
---|
740 | // Fault it in if not already. Since this is a const method and we
|
---|
741 | // can't use mutable members due the compilers we have to support,
|
---|
742 | // we have to cast off the constness.
|
---|
743 | //
|
---|
744 | if (!fURIText)
|
---|
745 | ((XMLUri*)this)->buildFullText();
|
---|
746 |
|
---|
747 | return fURIText;
|
---|
748 | }
|
---|
749 |
|
---|
750 | // ---------------------------------------------------------------------------
|
---|
751 | // XMLUri: Helper methods
|
---|
752 | // ---------------------------------------------------------------------------
|
---|
753 | inline bool XMLUri::isReservedOrUnreservedCharacter(const XMLCh theChar)
|
---|
754 | {
|
---|
755 | return (XMLString::isAlphaNum(theChar) ||
|
---|
756 | XMLString::indexOf(MARK_OR_RESERVED_CHARACTERS, theChar) != -1);
|
---|
757 | }
|
---|
758 |
|
---|
759 | inline bool XMLUri::isReservedCharacter(const XMLCh theChar)
|
---|
760 | {
|
---|
761 | return (XMLString::indexOf(RESERVED_CHARACTERS, theChar) != -1);
|
---|
762 | }
|
---|
763 |
|
---|
764 | inline bool XMLUri::isPathCharacter(const XMLCh theChar)
|
---|
765 | {
|
---|
766 | return (XMLString::indexOf(PATH_CHARACTERS, theChar) != -1);
|
---|
767 | }
|
---|
768 |
|
---|
769 | inline bool XMLUri::isUnreservedCharacter(const XMLCh theChar)
|
---|
770 | {
|
---|
771 | return (XMLString::isAlphaNum(theChar) ||
|
---|
772 | XMLString::indexOf(MARK_CHARACTERS, theChar) != -1);
|
---|
773 | }
|
---|
774 |
|
---|
775 | XERCES_CPP_NAMESPACE_END
|
---|
776 |
|
---|
777 | #endif
|
---|