Fix the boiler plate codes
[platform/framework/native/appfw.git] / inc / FBaseUtilUri.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                FBaseUtilUri.h
19  * @brief               This is the header file for the %Uri class.
20  *
21  * This header file contains the declarations of the %Uri class.
22  */
23 #ifndef _FBASE_UTIL_URI_H_
24 #define _FBASE_UTIL_URI_H_
25
26 #include <FBaseObject.h>
27 #include <FBaseString.h>
28 #include <FBaseBuffer.h>
29
30
31 namespace Tizen { namespace Base { namespace Utility
32 {
33
34 /**
35  * @class       Uri
36  * @brief       This class provides useful methods for URI.
37  *
38  * @since 2.0
39  *
40  * The %Uri class represents a Uniform Resource Identifier (URI) as defined by RFC2396 and provides accessors
41  * which access the URI component.
42  * It also provides methods for creating, accessing, normalizing, resolving, and relativizing %Uri instances.
43  *
44  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/uri.htm">URI</a>.
45  *
46  * The following example demonstrates how to use the %Uri class.
47  *
48  * @code
49  *
50  * #include <FBase.h>
51  *
52  * using namespace Tizen::Base;
53  * using namespace Tizen::Base::Utility;
54  *
55  * void
56  * MyClass::UriSample(void)
57  * {
58  *              String base(L"http://www.samsung.com");
59  *              String against(L"/osp/framework/index.html");
60  *              String resolveString(L"http://www.samsung.com/osp/framework/index.html");
61  *
62  *              Uri baseUri;
63  *              baseUri.SetUri(base);
64  *
65  *              Uri againstUri;
66  *              againstUri.SetUri(against);
67  *
68  *              Uri resultUri;
69  *              baseUri.Resolve(againstUri, resultUri);
70  *
71  *              String resultString = resultUri.ToString();
72  *              if (resultString.Equals(resolveString))
73  *              {
74  *                      // ...
75  *              }
76  *
77  * }
78  * @endcode
79  */
80 class _OSP_EXPORT_ Uri
81         : public Tizen::Base::Object
82 {
83 public:
84         /**
85          * This is the default constructor for this class.
86          *
87          * @since 2.0
88          */
89         Uri(void);
90
91         /**
92          * Copying of objects using this copy constructor is allowed.
93          *
94          * @since 2.0
95          *
96          *  @param[in]  uri             An instance of %Uri to copy
97          */
98         Uri(const Uri& uri);
99
100         /**
101          * This destructor overrides Tizen::Base::Object::~Object().
102          *
103          * @since 2.0
104          */
105         virtual ~Uri(void);
106
107         /**
108          * Sets the current %Uri instance to the value of the specified instance of %Uri.
109          *
110          * @since 2.0
111          *
112          * @param[in]   uri             An instance of %Uri
113          */
114         void SetUri(const Uri& uri);
115
116         /**
117          * Sets the current %Uri instance by parsing a given string.
118          *
119          * @since 2.0
120          *
121          * @return              An error code
122          * @param[in]   str             A string to parse into a URI
123          * @exception   E_SUCCESS                               The method is successful.
124          * @exception   E_INVALID_ARG                   The specified @c str is an empty string.
125          * @exception   E_INVALID_FORMAT                The specified @c str violates the URI syntax (RFC 2396).
126          */
127         result SetUri(const Tizen::Base::String& str);
128
129         /**
130          * Sets an absolute %Uri instance with given components.
131          *
132          * @since 2.0
133          *
134          * @return              An error code
135          * @param[in]   scheme                  The scheme
136          * @param[in]   ssp                             The scheme-specific-part
137          * @param[in]   fragment                The fragment
138          * @exception   E_SUCCESS                               The method is successful.
139          * @exception   E_INVALID_FORMAT                A component violates the URI syntax(RFC 2396).
140          */
141         result SetUri(const Tizen::Base::String& scheme, const Tizen::Base::String& ssp, const Tizen::Base::String& fragment);
142
143         /**
144          * Sets an absolute and hierarchical %Uri instance with the given components.
145          *
146          * @since 2.0
147          *
148          * @return              An error code
149          * @param[in]   scheme                  The scheme
150          * @param[in]   userInfo                The user name and authorization
151          * @param[in]   host                    The host name
152          * @param[in]   port                    The port number
153          * @param[in]   path                    The path
154          * @param[in]   query                   The query
155          * @param[in]   fragment                The fragment
156          * @exception   E_SUCCESS                               The method is successful.
157          * @exception   E_INVALID_FORMAT                A component violates the URI syntax(RFC 2396).
158          */
159         result SetUri(const Tizen::Base::String& scheme, const Tizen::Base::String& userInfo, const Tizen::Base::String& host, int port, const Tizen::Base::String& path, const Tizen::Base::String& query, const Tizen::Base::String& fragment);
160
161         /**
162          * Sets an absolute and hierarchical %Uri instance with the given components.
163          *
164          * @since 2.0
165          *
166          * @return              An error code
167          * @param[in]   scheme                  The scheme
168          * @param[in]   host                    The host name
169          * @param[in]   path                    The path
170          * @param[in]   fragment                The fragment
171          * @exception   E_SUCCESS                               The method is successful.
172          * @exception   E_INVALID_FORMAT                A component violates the URI syntax(RFC 2396).
173          * @remarks     The authority and query component are left empty, and the port is set to @c -1.
174          */
175         result SetUri(const Tizen::Base::String& scheme, const Tizen::Base::String& host, const Tizen::Base::String& path, const Tizen::Base::String& fragment);
176
177         /**
178          * Sets an absolute and hierarchical %Uri instance with the given components.
179          *
180          * @since 2.0
181          *
182          * @return              An error code
183          * @param[in]   scheme                  The scheme
184          * @param[in]   authority               The authority
185          * @param[in]   path                    The path
186          * @param[in]   query                   The query
187          * @param[in]   fragment                The fragment
188          * @exception   E_SUCCESS                               The method is successful.
189          * @exception   E_INVALID_FORMAT                A component violates the URI syntax(RFC 2396).
190          */
191         result SetUri(const Tizen::Base::String& scheme, const Tizen::Base::String& authority, const Tizen::Base::String& path, const Tizen::Base::String& query, const Tizen::Base::String& fragment);
192
193         /**
194          * Copying of objects using this copy assignment operator is allowed.
195          *
196          * @since 2.0
197          *
198          * @return              A reference to the calling instance
199          * @param[in]   rhs             An instance of %Uri
200          */
201         Uri& operator =(const Uri& rhs);
202
203         /**
204          * Gets the value of the authority component.
205          *
206          * @since 2.0
207          *
208          * @return              The value of the authority component, @n
209          *                              else an empty string if the authority component is undefined
210          * @remarks             The string returned by this method is equal to the string returned by GetEncodedAuthority(),
211          *                              except that all sequences of the escaped octets are decoded.
212          */
213         Tizen::Base::String GetAuthority(void) const;
214
215         /**
216          * Gets the value of the fragment component.
217          *
218          * @since 2.0
219          *
220          * @return              The value of the fragment component, @n
221          *                              else an empty string if the fragment component is undefined
222          * @remarks             The string returned by this method is equal to the string returned by GetEncodedFragment(),
223          *                              except that all sequences of the escaped octets are decoded.
224          */
225         Tizen::Base::String GetFragment(void) const;
226
227         /**
228          * Gets the value of the host component.
229          *
230          * @since 2.0
231          *
232          * @return              The value of the host component, @n
233          *                              else an empty string if the host component is undefined
234          */
235         Tizen::Base::String GetHost(void) const;
236
237         /**
238          * Gets the value of the path component.
239          *
240          * @since 2.0
241          *
242          * @return              The value of the path component, @n
243          *                              else an empty string if the path component is undefined
244          * @remarks             The string returned by this method is equal to the string returned by GetEncodedPath(),
245          *                              except that all sequences of the escaped octets are decoded.
246          */
247         Tizen::Base::String GetPath(void) const;
248
249
250         /**
251          * Gets the value of the port component.
252          *
253          * @since 2.0
254          *
255          * @return              The value of the port component, @n
256          *                              else @c -1 if the port component is undefined
257          */
258         int GetPort(void) const;
259
260
261         /**
262          * Gets the value of the query component.
263          *
264          * @since 2.0
265          *
266          * @return              The value of the query component, @n
267          *                              else an empty string if the query component is undefined
268          * @remarks             The string returned by this method is equal to the string returned by GetEncodedQuery(),
269          *                              except that all sequences of the escaped octets are decoded.
270          */
271         Tizen::Base::String GetQuery(void) const;
272
273
274         /**
275          * Gets the value of the scheme component.
276          *
277          * @since 2.0
278          *
279          * @return              The value of the query scheme, @n
280          *                              else an empty string if the query scheme is undefined
281          */
282         Tizen::Base::String GetScheme(void) const;
283
284
285         /**
286          * Gets the value of the scheme-specific-part component.
287          *
288          * @since 2.0
289          *
290          * @return              The value of the scheme-specific-part component, @n
291          *                              else an empty string if the scheme-specific-part component is undefined
292          * @remarks             The string returned by this method is equal to the string returned by GetEncodedSchemeSpecificPart(),
293          *                              except that all sequences of the escaped octets are decoded.
294          */
295         Tizen::Base::String GetSchemeSpecificPart(void) const;
296
297
298         /**
299          * Gets the value of the user-info component.
300          *
301          * @since 2.0
302          *
303          * @return              The value of the user-info component, @n
304          *                              else an empty string if the user-info component is undefined
305          * @remarks             The string returned by this method is equal to the string returned by GetEncodedUserInfo(),
306          *                              except that all sequences of the escaped octets are decoded.
307          */
308         Tizen::Base::String GetUserInfo(void) const;
309
310
311         /**
312          * Gets the encoded value of the authority component. @n
313          * The non-US-ASCII characters in the authority component are encoded to escaped octets.
314          *
315          * @since 2.0
316          *
317          * @return              The encoded value of the authority component, @n
318          *                              else an empty string if the authority component is undefined
319          */
320         Tizen::Base::String GetEncodedAuthority(void) const;
321
322
323         /**
324          * Gets the encoded value of the fragment component. @n
325          * The non-US-ASCII characters in the fragment component are encoded to escaped octets.
326          *
327          * @since 2.0
328          *
329          * @return              The encoded value of the fragment component, @n
330          *                              else an empty string if the fragment component is undefined
331          */
332         Tizen::Base::String GetEncodedFragment(void) const;
333
334
335         /**
336          * Gets the encoded value of the path component. @n
337          * The non-US-ASCII characters in the path component are encoded to escaped octets.
338          *
339          * @since 2.0
340          *
341          * @return              The encoded value of the path component, @n
342          *                              else an empty string if the path component is undefined
343          */
344         Tizen::Base::String GetEncodedPath(void) const;
345
346
347         /**
348          * Gets the encoded value of the query component. @n
349          * The non-US-ASCII characters in the query component are encoded to escaped octets.
350          *
351          * @since 2.0
352          *
353          * @return              The encoded value of the query component, @n
354          *                              else an empty string if the query component is undefined
355          */
356         Tizen::Base::String GetEncodedQuery(void) const;
357
358
359         /**
360          * Gets the encoded value of the scheme-specific-part component. @n
361          * The non-US-ASCII characters in the scheme-specific-part component are encoded to escaped octets.
362          *
363          * @since 2.0
364          *
365          * @return              The encoded value of the scheme-specific-part component, @n
366          *                              else an empty string if the scheme-specific-part component is undefined
367          */
368         Tizen::Base::String GetEncodedSchemeSpecificPart(void) const;
369
370         /**
371         * Gets the encoded value of a user-info component,
372         * or returns an empty string if the user-info component is undefined. @n
373         * The non-US-ASCII characters in the user-info component are encoded to escaped octets.
374         *
375         * @since 2.0
376         *
377         * @return               The encoded value of user-info, @n
378         *                               else an empty string if the user-info component is undefined
379         */
380         Tizen::Base::String GetEncodedUserInfo(void) const;
381
382
383         /**
384          * Checks whether the current %Uri instance is an absolute URI.
385          *
386          * @since 2.0
387          *
388          * @return              @c true if the current %Uri instance is an absolute URI, @n
389          *                              else @c false
390          */
391         bool IsAbsolute(void) const;
392
393
394         /**
395          * Checks whether the calling %Uri instance is an opaque URI.
396          *
397          * @since 2.0
398          *
399          * @return              @c true if the current %Uri instance is an opaque URI, @n
400          *                              else @c false
401          */
402         bool IsOpaque(void) const;
403
404
405         /**
406          * Gets the encoded US-ASCII string.
407          *
408          * @since 2.0
409          *
410          * @return              The encoded US-ASCII string
411          * @remarks             If this URI does not contain any non US_ASCII characters,
412          *                              then the string returned by this method is equal to the string returned by ToString().
413          *
414          * The following example demonstrates how to use the %GetEncodedString() method.
415          *
416          * @code
417          * String str(L"http://www.sec.com/osp?currency==\u20ac");
418          *
419          *       Uri uri;
420          *       uri.SetUri(str);
421          *
422          *       String encode = uri.GetEncodedString();        // encode == L"http://www.sec.com/osp?currency==%E2%82%AC"
423          *
424          * @endcode
425          */
426         Tizen::Base::String GetEncodedString(void) const;
427
428         /**
429          * Compares the calling URI instance to the specified %Uri instance. @n
430          * When comparing corresponding components of two URIs, if one component in the current instance is undefined
431          * but the other is defined, then the current instance is considered to be less than the given object.
432          *
433          * @since 2.0
434          *
435          * @return              The result of the comparison
436          * @code
437          * < 0  if the current instance is less than the given object
438          * = 0  if the current instance is equal to the given object
439          * > 0  if the current instance is greater than the given object
440          * @endcode
441          * @param[in]   uri                     An instance of %Uri
442          * @remarks
443          *
444          * Ordering of URIs
445          * 1. Scheme
446          *    Two URIs are ordered according to the ordering of schemes, without regard to case.
447          * 2. Hierarchical URI vs. Opaque URI
448          *    A hierarchical URI is less than an opaque URI if they have an identical scheme.
449          * 3. Scheme-specific-part
450          *    If two opaque URIs have an identical scheme, they are ordered according to
451          *    the scheme-specific-part, without regard to %case.
452          * 4. Fragment
453          *    If two opaque URIs have identical schemes and scheme-specific-parts, they are ordered according
454          *    to the ordering of fragments, without regard to case.
455          * 5. Authority
456          *    If two hierarchical URIs have identical schemes, they are ordered according to the authority,
457          *    without regard to the case.
458          *       5-1. Server-based authority
459          *             If two URIs are server-based, they are ordered according to their user-information,
460          *             without regard to case.
461          *             If the hosts are identical, then the URIs are ordered according to the ordering of ports.
462          * 6. Path
463          *    If two hierarchical URIs have identical schemas and authority components, they are ordered according to the
464          *    ordering of paths, without regard to the case.
465          *    If their paths are identical, their queries are compared. And if the queries are the same, then their fragments
466          *    are compared.
467          *
468          */
469         int CompareTo(const Uri& uri) const;
470
471
472         /**
473          *      Compares the specified instance to the current instance.
474          *
475          *  @since 2.0
476          *
477          *      @return         @c true if the two instances are equal, @n
478          *                              else @c false
479          *      @param[in]      obj     The object to compare with the current instance
480          *      @remarks        Two equal instances must return the same hash value. The default
481          *                              implementation of this method returns @c true if two instances
482          *                              have the same address. @n
483          *                              The method can be overridden to support value equality. Furthermore, the Equals()
484          *                              method must return the same results as the equality operator.
485          */
486         virtual bool Equals(const Tizen::Base::Object& obj) const;
487
488
489         /**
490          *      Gets the hash value of the current instance.
491          *
492          *  @since 2.0
493          *
494          *      @return         The hash value of the current instance
495          *      @remarks        Two equal instances must return the same hash value. For better performance,
496          *                              the used hash function must generate a random distribution for all inputs.
497          */
498         virtual int GetHashCode(void) const;
499
500
501         /**
502          * Normalizes the current URI.
503          *
504          * @since 2.0
505          *
506          * @return              The normalized URI, @n
507          *                              else the current URI in case any error occurs
508          * @remarks     Normalization is the process of removing unnecessary "." and ".." segments from the path component of the
509          *                      hierarchical URI. All "." segments are removed and If a ".." segment is preceded by a non-".." segment,
510          *                      both of these segments are removed. If a URI is opaque, the normalization has no effect.
511          *
512          * The following example demonstrates how to use the %Normalize() method.
513          *
514          * @code
515          *       Uri uri1;
516          *       uri1.SetUri(L"http://www.example.com/a/b/../c/./d.html");
517          *
518          *       Uri uriNormalized = uri1.Normalize();
519          *       String uriStr = uriNormalized.ToString();              // uriStr == L"http://www.example.com/a/c/d.html"
520          *
521          * @endcode
522          */
523         Uri Normalize(void);
524
525
526         /**
527          * Parses the server-based authority component, if defined.
528          *
529          * @since 2.0
530          *
531          * @return              An error code
532          * @param[out]  uri                                     The parsed URI
533          * @exception   E_SUCCESS                       The method is successful.
534          * @exception   E_INVALID_FORMAT        The authority component is defined but cannot be parsed as a server-based authority.
535          * @remarks             This method is provided because the generic URI syntax cannot always distinguish a malformed server-based authority from a legitimate registry-based authority.
536          *                              For example, the authority component in the URI string "//foo:bar/" is not a legal
537          *                              server-based authority but it is legal as a registry-based authority.
538          */
539         result ParseAuthority(Uri& uri);
540
541
542         /**
543          * Relativizes the specified %Uri instance against the calling %Uri instance.
544          *
545          * @since 2.0
546          *
547          * @return              An error code
548          * @param[in]   uri                                     The %Uri to relativize against the calling %Uri
549          * @param[out]  resultUri                       The relativized URI
550          * @exception   E_SUCCESS                       The method is successful.
551          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
552          * @remarks             Relativization is the opposite of Resolution. It is used
553          *                              to divide a URI into the base URI and the relative URI.
554          */
555         result Relativize(const Uri& uri, Uri& resultUri);
556
557
558         /**
559          * Resolves the specified %Uri instance against the calling %Uri instance.
560          *
561          * @since 2.0
562          *
563          * @return              An error code
564          * @param[in]   uri                                     The URI to resolve against this URI
565          * @param[out]  resultUri                       The resolved URI
566          * @exception   E_SUCCESS                       The method is successful.
567          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
568          * @remarks             Resolution is the process of resolving a URI against another, base URI. For hierarchical URI,
569          *                              the path of the original is resolved against the path of the base URI and then normalized. @n
570          *
571          *                              For example, to resolve the URI "/osp/framework/index.html" against the base URI "http://www.samsung.com" ,
572          *                              the resultant URI is "http://www.samsung.com/osp/framework/index.html".
573          *
574          */
575         result Resolve(const Uri& uri, Uri& resultUri);
576
577
578         /**
579          * Sets the authority component to the specified String instance.
580          *
581          * @since 2.0
582          *
583          * @return              An error code
584          * @param[in]   authority                       The authority
585          * @exception   E_SUCCESS                       The method is successful.
586          * @exception   E_INVALID_FORMAT        The specified string is invalid.
587          */
588         result SetAuthority(const Tizen::Base::String& authority);
589
590
591         /**
592          * Sets the fragment component to the specified String instance.
593          *
594          * @since 2.0
595          *
596          * @return              An error code
597          * @param[in]   fragment                        The new fragment
598          * @exception   E_SUCCESS                       The method is successful.
599          * @exception   E_INVALID_FORMAT        The specified string is invalid.
600          */
601         result SetFragment(const Tizen::Base::String& fragment);
602
603
604         /**
605          * Sets the host component to the specified String instance.
606          *
607          * @since 2.0
608          *
609          * @return              An error code
610          * @param[in]   host                            The new host
611          * @exception   E_SUCCESS                       The method is successful.
612          * @exception   E_INVALID_FORMAT        The specified string is invalid.
613          */
614         result SetHost(const Tizen::Base::String& host);
615
616
617         /**
618          * Sets the path component to the specified String instance.
619          *
620          * @since 2.0
621          *
622          * @return              An error code
623          * @param[in]   path                            The new path component
624          * @exception   E_SUCCESS                       The method is successful.
625          * @exception   E_INVALID_FORMAT        The specified string is invalid.
626          */
627         result SetPath(const Tizen::Base::String& path);
628
629
630         /**
631          * Sets the port component to a given integer.
632          *
633          * @since 2.0
634          *
635          * @return              An error code
636          * @param[in]   port                            The new port component
637          * @exception   E_SUCCESS                       The method is successful.
638          * @exception   E_INVALID_ARG           The specified @c port is negative.
639          */
640         result SetPort(int port);
641
642
643         /**
644          * Sets the query component to the specified String instance.
645          *
646          * @since 2.0
647          *
648          * @return              An error code
649          * @param[in]   query                           The new query string
650          * @exception   E_SUCCESS                       The method is successful.
651          * @exception   E_INVALID_FORMAT        The specified string is invalid.
652          */
653         result SetQuery(const Tizen::Base::String& query);
654
655
656         /**
657          * Sets the scheme component to the specified String instance.
658          *
659          * @since 2.0
660          *
661          * @return              An error code
662          * @param[in]   scheme                          The new scheme
663          * @exception   E_SUCCESS                       The method is successful.
664          * @exception   E_INVALID_FORMAT        The specified string is invalid.
665          */
666         result SetScheme(const Tizen::Base::String& scheme);
667
668
669         /**
670          * Sets the scheme-specific-part component to the specified String instance.
671          *
672          * @since 2.0
673          *
674          * @return              An error code
675          * @param[in]   ssp                                     The new scheme-specific-part component
676          * @exception   E_SUCCESS                       The method is successful.
677          * @exception   E_INVALID_FORMAT        The specified string is invalid.
678          */
679         result SetSchemeSpecificPart(const Tizen::Base::String& ssp);
680
681
682         /**
683          * Sets the user-info component to the specified String instance.
684          *
685          * @since 2.0
686          *
687          * @return              An error code
688          * @param[in]   userInfo                        The new user-info string
689          * @exception   E_SUCCESS                       The method is successful.
690          * @exception   E_INVALID_FORMAT        The specified string is invalid.
691          */
692         result SetUserInfo(const Tizen::Base::String& userInfo);
693
694
695         /**
696          * Gets the content of the calling %Uri instance as a string containing escaped octets.
697          *
698          * @since 2.0
699          *
700          * @return              The content of this URI as a string containing escaped octets
701          */
702         Tizen::Base::String ToString(void) const;
703
704 private:
705         //
706         // Constructs an Uri instance with the given components.
707         // scheme, ssp(opaquePart), authority, user-info, host, port, path, query, fragment
708         //
709         result SetUri(const Tizen::Base::String& scheme, const Tizen::Base::String& opaque,
710                 const Tizen::Base::String& authority, const Tizen::Base::String& userInfo,
711                 const Tizen::Base::String& host, int port, const Tizen::Base::String& path,
712                 const Tizen::Base::String& query, const Tizen::Base::String& fragment);
713
714         //
715         // Appends a given scheme-specific-part to a String.
716         //
717         result AppendSchemeSpecificPart(Tizen::Base::String& strbuf, const Tizen::Base::String& opaque,
718                 const Tizen::Base::String& authority, const Tizen::Base::String& userInfo,
719                 const Tizen::Base::String& host, int port, const Tizen::Base::String& path,
720                 const Tizen::Base::String& query) const;
721
722         //
723         // Appends a given fragment to a String.
724         //
725         result AppendFragment(Tizen::Base::String& strbuf, const Tizen::Base::String& fragment) const;
726
727         //
728         // Appends a given authority component to a String.
729         //
730         result AppendAuthority(Tizen::Base::String& strbuf, const Tizen::Base::String& authority,
731                 const Tizen::Base::String& userInfo, const Tizen::Base::String& host, int port) const;
732
733         //
734         // Parses a given URI string.
735         //
736         result ParseUri(const Tizen::Base::String& str);
737
738         //
739         // Copies a given URI.
740         //
741         result CopyUri(const Uri& uri);
742
743         //
744         // Encodes all components - authority, fragment, path, query, and ssp.
745         //
746         void EncodeAllComponent(void);
747
748         //
749         // Parses a hierarchical URI string.
750         // @return              The start index of the fragment. If the operation fails, @c -1 is returned.
751         // @param[in]   startSsp                        The start index of scheme-specific-part
752         // @param[in] lengthOfUri               The length of the URI string
753         // @param[out] authority        A parsed authority component
754         // @param[out] path                     A parsed path component
755         // @param[out] query                    A parsed query component
756         //
757         result ParseHierarchicalUri(const Tizen::Base::String& str, int startSsp, Tizen::Base::String& authority,
758                 Tizen::Base::String& path, Tizen::Base::String& query, int& index);
759
760
761         //
762         // Parses a server_based authority component.
763         // server_based authority: [user-info@]<host>[:port]
764         //
765         result ParseAuthority(const Tizen::Base::String& str, int curIndex, Tizen::Base::String& newAuth,
766                 Tizen::Base::String& userInfo, Tizen::Base::String& host, int& port);
767
768         void SetAndEncodeAuthority(const Tizen::Base::String& authority,
769                 const Tizen::Base::String& path, const Tizen::Base::String& query);
770
771         //
772         // Parses a server_based authority component.
773         // Assigns user-info, host and port to their member variable.
774         //
775         result ParseServerAuthority(const Tizen::Base::String& str, Tizen::Base::String& user, Tizen::Base::String& host, int& port);
776
777         //
778         // Parses an IPv4 address.
779         //
780         result ParseIpv4(const Tizen::Base::String& str, int index, int& count);
781
782         //
783         // Parses an IPv6 address.
784         // It will be implemented.
785         //
786         result ParseIpv6(const Tizen::Base::String& ip6, Tizen::Base::String& outIpv6);
787
788         //
789         // Parses a host name and returns a host name as an out-param.
790         //
791         result ParseHostName(const Tizen::Base::String& str, int index, Tizen::Base::String& host);
792
793         //
794         // These methods verify components.
795         // If a given component is valid, return @c true, else, @c false.
796         // @param[in]   str             A component
797         //
798         bool VerifyScheme(const Tizen::Base::String& str) const;
799         bool VerifyAuthority(const Tizen::Base::String& str) const;
800         bool VerifyHost(const Tizen::Base::String& str) const;
801         bool VerifyPath(const Tizen::Base::String& str) const;
802         bool VerifyUserInfo(const Tizen::Base::String& str) const;
803         bool VerifyUriChar(const Tizen::Base::String& str) const;
804
805         //
806         // Checks that a given string only consists of server_based characters.
807         // @return              @c true if a string consists of only server_based characters, @n
808         //                      else @c false
809         //
810         bool VerifyServerAuthority(const Tizen::Base::String& str) const;
811
812         //
813         //  Checks that a given string only consists of registry_based characters.
814         // @return              @c true if a string consists of only registry_based characters, @n
815         //                              else @c false
816         //
817         bool VerifyRegistryAuthority(const Tizen::Base::String& str) const;
818
819         //
820         // Checks whether a given char is a user-info character or not.
821         // user-info char: alphabet, digit, -_.!~*'(), ;:&=+$,
822         //
823         bool IsUserInfo(wchar_t mch) const;
824
825         //
826         // Returns true if a given wchar_t is a mark character.
827         // mark char : -_.!~*'()
828         //
829         bool IsMark(wchar_t mch) const;
830
831         //
832         // Returns true if two given wchar_ts are hexadecimals.
833         //
834         bool IsEscapedChar(wchar_t ch1, wchar_t ch2) const;
835
836         //
837         // Returns true if a given string is already encoded.
838         //
839         bool IsEncoded(const Tizen::Base::String& str) const;
840
841         //
842         // Returns true if a given wchar_t is an ISO control character.
843         //
844         bool IsControlChar(wchar_t ch) const;
845
846         //
847         // Compares @c pStr1 with @c pStr2. @n
848         // If @c pStr1 is greater than @c pStr2, returns @c 1.
849         // If two strings are the same, return @c 0.
850         // If @c pStr1 is less than @c pStr2, returns @c -1.
851         //
852         int Compare(const Tizen::Base::String& pStr1, const Tizen::Base::String& pStr2) const;
853
854         //
855         // Adds leading dots.
856         // If the normalized path is relative, and if the first segment could be parsed as a scheme name,
857         // then prepend a '.' segment
858         //
859         void AddLeadingDot(Tizen::Base::WcharBuffer& path, int* segments, int numSegments);
860
861         //
862         // Finds the first character in stopString.
863         // If there is not a character in stopString, the last index is returned.
864         //
865         int Scan(const Tizen::Base::String& str, int start, const Tizen::Base::String& stopString);
866
867         //
868         // Normalizes a given string and removes unnecessary dots.
869         //
870         Tizen::Base::String InternalNormalize(const Tizen::Base::String& path);
871
872         //
873         // Returns the number of segments from a given path.
874         //
875         int GetNumberOfSegments(const Tizen::Base::String& path) const;
876
877         // Join the segments in the given path according to the given segment-index array,
878         // ignoring those segments whose index entries have been set to @c -1, and inserting slashes as needed.
879         // Return the length of the resulting path.
880         //
881         // Preconditions:
882         //   segs[i] == @c -1 implies segment i is to be ignored
883         //   path computed by split, as above, with '\0' having replaced '/'
884         //
885         // Postconditions:
886         //  path[0] .. path[return value] == Resulting path
887         //
888         int Join(Tizen::Base::WcharBuffer& path, int* segments, int segCount);
889
890         //
891         // Removes unnecessary dots and segment pairs consisting of a non-".." segment
892         // followed by a ".." segment
893         //
894         void RemoveDots(const Tizen::Base::WcharBuffer& mb, int* segments, int segCount, int length);
895
896         //
897         // Splits a path component into segments.
898         //
899         void SplitIntoSegments(Tizen::Base::WcharBuffer& mb, int* segments, int segCount);
900
901         //
902         // Implements Uri resolution in RFC2396 5.2
903         //
904         result Resolve(const Uri& baseUri, const Uri& childUri, Uri& resultUri);
905
906         //
907         // Resolves the path of the base and child URI.
908         //
909         Tizen::Base::String ResolvePath(const Tizen::Base::String& path, const Tizen::Base::String& resolve, bool isAbsolute);
910
911         bool EqualsComponent(const Tizen::Base::String& comp1, const Tizen::Base::String& comp2);
912         result Relativize(const Uri& baseUri, const Uri& childUri, Uri& resultUri);
913
914         //
915         // Converts a component represented by UTF8 to a component represented by Unicode.
916         //
917         Tizen::Base::String Decode(const Tizen::Base::String& str);
918
919         //
920         // Converts a component represented by Unicode to a component represented by UTF8.
921         //
922         Tizen::Base::String Encode(const Tizen::Base::String& str) const;
923
924         static result AppendEscape(Tizen::Base::String& strbuf, byte b);
925
926         //
927         // Clears the current instance.
928         //
929         void Clear(void);
930
931         // Component
932         Tizen::Base::String __scheme;
933         Tizen::Base::String __ssp;
934         Tizen::Base::String __authority;
935         Tizen::Base::String __host;
936         Tizen::Base::String __fragment;
937         Tizen::Base::String __path;
938         Tizen::Base::String __userInfo;
939         Tizen::Base::String __query;
940         Tizen::Base::String __ipv4;
941         Tizen::Base::String __ipv6;
942
943         // Encoded Component
944         Tizen::Base::String __encodedAuth;
945         Tizen::Base::String __encodedFragment;
946         Tizen::Base::String __encodedPath;
947         Tizen::Base::String __encodedQuery;
948         Tizen::Base::String __encodedSsp;
949         Tizen::Base::String __encodedUserInfo;
950
951         int __port;
952         bool __hasScheme;
953         int __ipv6ByteCount;
954
955         friend class _UriImpl;
956         class _UriImpl* __pUriImpl;
957
958 }; // Uri
959
960 }}} // Tizen::Base::Utility
961
962 #endif //_FBASE_UTIL_URI_H_