1 | /** @file
|
---|
2 | * IPRT - Uniform Resource Identifier handling.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2011 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___iprt_uri_h
|
---|
27 | #define ___iprt_uri_h
|
---|
28 |
|
---|
29 | #include <iprt/cdefs.h>
|
---|
30 | #include <iprt/types.h>
|
---|
31 |
|
---|
32 | RT_C_DECLS_BEGIN
|
---|
33 |
|
---|
34 | /** @defgroup grp_rt_uri RTUri - Uri parsing and creation
|
---|
35 | * URI parsing and creation based on RFC 3986.
|
---|
36 | * See http://datatracker.ietf.org/doc/rfc3986/ for the full specification.
|
---|
37 | * @note Currently it isn't the full specification implemented.
|
---|
38 | * @note Currently only some generic URI support and a minimum File(file:) URI
|
---|
39 | * support is implemented. Other specific scheme support, like html:, ldap:,
|
---|
40 | * data:, ..., is missing.
|
---|
41 | * @see grp_rt_uri_file
|
---|
42 | * @ingroup grp_rt
|
---|
43 | * @{
|
---|
44 | */
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Creates a generic URI. The returned pointer must be freed
|
---|
48 | * using RTStrFree().
|
---|
49 | *
|
---|
50 | * @returns the new URI on success, NULL otherwise.
|
---|
51 | * @param pszScheme The URI scheme.
|
---|
52 | * @param pszAuthority The authority part of the URI (optional).
|
---|
53 | * @param pszPath The path part of the URI (optional).
|
---|
54 | * @param pszQuery The query part of the URI (optional).
|
---|
55 | * @param pszFragment The fragment part of the URI (optional).
|
---|
56 | */
|
---|
57 | RTR3DECL(char *) RTUriCreate(const char *pszScheme, const char *pszAuthority, const char *pszPath, const char *pszQuery, const char *pszFragment);
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Check an string for a specific URI scheme.
|
---|
61 | *
|
---|
62 | * @returns true if the scheme match, false if not.
|
---|
63 | * @param pszUri The URI to check.
|
---|
64 | * @param pszScheme The scheme to compare with.
|
---|
65 | */
|
---|
66 | RTR3DECL(bool) RTUriHasScheme(const char *pszUri, const char *pszScheme);
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Extract the scheme out of an URI.
|
---|
70 | *
|
---|
71 | * @returns the scheme if the URI is valid, NULL otherwise.
|
---|
72 | * @param pszUri The URI to extract from.
|
---|
73 | */
|
---|
74 | RTR3DECL(char *) RTUriScheme(const char *pszUri);
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Extract the authority out of an URI.
|
---|
78 | *
|
---|
79 | * @returns the authority if the URI contains one, NULL otherwise.
|
---|
80 | * @param pszUri The URI to extract from.
|
---|
81 | */
|
---|
82 | RTR3DECL(char *) RTUriAuthority(const char *pszUri);
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Extract the path out of an URI.
|
---|
86 | *
|
---|
87 | * @returns the path if the URI contains one, NULL otherwise.
|
---|
88 | * @param pszUri The URI to extract from.
|
---|
89 | */
|
---|
90 | RTR3DECL(char *) RTUriPath(const char *pszUri);
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Extract the query out of an URI.
|
---|
94 | *
|
---|
95 | * @returns the query if the URI contains one, NULL otherwise.
|
---|
96 | * @param pszUri The URI to extract from.
|
---|
97 | */
|
---|
98 | RTR3DECL(char *) RTUriQuery(const char *pszUri);
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Extract the fragment out of an URI.
|
---|
102 | *
|
---|
103 | * @returns the fragment if the URI contains one, NULL otherwise.
|
---|
104 | * @param pszUri The URI to extract from.
|
---|
105 | */
|
---|
106 | RTR3DECL(char *) RTUriFragment(const char *pszUri);
|
---|
107 |
|
---|
108 | /** @defgroup grp_rt_uri_file RTUriFile - Uri file parsing and creation
|
---|
109 | * Adds file: scheme support to the generic RTUri interface. This is partly
|
---|
110 | * documented in http://datatracker.ietf.org/doc/rfc1738/.
|
---|
111 | * @ingroup grp_rt_uri
|
---|
112 | * @{
|
---|
113 | */
|
---|
114 |
|
---|
115 | /** Auto detect in which format a path is returned. */
|
---|
116 | #define URI_FILE_FORMAT_AUTO UINT32_C(0)
|
---|
117 | /** Return a path in UNIX format style. */
|
---|
118 | #define URI_FILE_FORMAT_UNIX UINT32_C(1)
|
---|
119 | /** Return a path in Windows format style. */
|
---|
120 | #define URI_FILE_FORMAT_WIN UINT32_C(2)
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * Creates a file URI. The returned pointer must be freed
|
---|
124 | * using RTStrFree().
|
---|
125 | *
|
---|
126 | * @see RTUriCreate
|
---|
127 | *
|
---|
128 | * @returns the new URI on success, NULL otherwise.
|
---|
129 | * @param pszPath The path of the URI.
|
---|
130 | */
|
---|
131 | RTR3DECL(char *) RTUriFileCreate(const char *pszPath);
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Returns the file path encoded in the URI.
|
---|
135 | *
|
---|
136 | * @returns the path if the URI contains one, NULL otherwise.
|
---|
137 | * @param pszUri The URI to extract from.
|
---|
138 | * @param uFormat In which format should the path returned.
|
---|
139 | */
|
---|
140 | RTR3DECL(char *) RTUriFilePath(const char *pszUri, uint32_t uFormat);
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Returns the file path encoded in the URI, given a max string length.
|
---|
144 | *
|
---|
145 | * @returns the path if the URI contains one, NULL otherwise.
|
---|
146 | * @param pszUri The URI to extract from.
|
---|
147 | * @param uFormat In which format should the path returned.
|
---|
148 | * @param cbMax The max string length to inspect.
|
---|
149 | */
|
---|
150 | RTR3DECL(char *) RTUriFileNPath(const char *pszUri, uint32_t uFormat, size_t cchMax);
|
---|
151 |
|
---|
152 | /** @} */
|
---|
153 |
|
---|
154 | /** @} */
|
---|
155 |
|
---|
156 | RT_C_DECLS_END
|
---|
157 |
|
---|
158 | #endif
|
---|
159 |
|
---|