ReactOS  0.4.15-dev-1392-g3014417
uri.h File Reference
#include <libxml/xmlversion.h>
#include <libxml/tree.h>
Include dependency graph for uri.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _xmlURI
 

Typedefs

typedef struct _xmlURI xmlURI
 
typedef xmlURIxmlURIPtr
 

Functions

XMLPUBFUN xmlURIPtr XMLCALL xmlCreateURI (void)
 
XMLPUBFUN xmlChar *XMLCALL xmlBuildURI (const xmlChar *URI, const xmlChar *base)
 
XMLPUBFUN xmlChar *XMLCALL xmlBuildRelativeURI (const xmlChar *URI, const xmlChar *base)
 
XMLPUBFUN xmlURIPtr XMLCALL xmlParseURI (const char *str)
 
XMLPUBFUN xmlURIPtr XMLCALL xmlParseURIRaw (const char *str, int raw)
 
XMLPUBFUN int XMLCALL xmlParseURIReference (xmlURIPtr uri, const char *str)
 
XMLPUBFUN xmlChar *XMLCALL xmlSaveUri (xmlURIPtr uri)
 
XMLPUBFUN void XMLCALL xmlPrintURI (FILE *stream, xmlURIPtr uri)
 
XMLPUBFUN xmlChar *XMLCALL xmlURIEscapeStr (const xmlChar *str, const xmlChar *list)
 
XMLPUBFUN char *XMLCALL xmlURIUnescapeString (const char *str, int len, char *target)
 
XMLPUBFUN int XMLCALL xmlNormalizeURIPath (char *path)
 
XMLPUBFUN xmlChar *XMLCALL xmlURIEscape (const xmlChar *str)
 
XMLPUBFUN void XMLCALL xmlFreeURI (xmlURIPtr uri)
 
XMLPUBFUN xmlChar *XMLCALL xmlCanonicPath (const xmlChar *path)
 
XMLPUBFUN xmlChar *XMLCALL xmlPathToURI (const xmlChar *path)
 

Typedef Documentation

◆ xmlURI

Summary: library of generic URI related routines Description: library of generic URI related routines Implements RFC 2396

Copy: See Copyright for the status of this software.

Author: Daniel VeillardxmlURI:

A parsed URI reference. This is a struct containing the various fields as described in RFC 2396 but separated for further processing.

Note: query is a deprecated field which is incorrectly unescaped. query_raw takes precedence over query if the former is set. See: http://mail.gnome.org/archives/xml/2007-April/thread.html#00127

Definition at line 31 of file uri.h.

◆ xmlURIPtr

typedef xmlURI* xmlURIPtr

Definition at line 32 of file uri.h.

Function Documentation

◆ xmlBuildRelativeURI()

XMLPUBFUN xmlChar* XMLCALL xmlBuildRelativeURI ( const xmlChar URI,
const xmlChar base 
)

xmlBuildRelativeURI: @URI: the URI reference under consideration @base: the base value

Expresses the URI of the reference in terms relative to the base. Some examples of this operation include: base = "http://site1.com/docs/book1.html" URI input URI returned docs/pic1.gif pic1.gif docs/img/pic1.gif img/pic1.gif img/pic1.gif ../img/pic1.gif http://site1.com/docs/pic1.gif pic1.gif http://site2.com/docs/pic1.gif http://site2.com/docs/pic1.gif

base = "docs/book1.html" URI input URI returned docs/pic1.gif pic1.gif docs/img/pic1.gif img/pic1.gif img/pic1.gif ../img/pic1.gif http://site1.com/docs/pic1.gif http://site1.com/docs/pic1.gif

Note: if the URI reference is really weird or complicated, it may be worthwhile to first convert it into a "nice" one by calling xmlBuildURI (using 'base') before calling this routine, since this routine (for reasonable efficiency) assumes URI has already been through some validation.

Returns a new URI string (to be freed by the caller) or NULL in case error.

Definition at line 2165 of file uri.c.

2166 {
2167  xmlChar *val = NULL;
2168  int ret;
2169  int ix;
2170  int nbslash = 0;
2171  int len;
2172  xmlURIPtr ref = NULL;
2173  xmlURIPtr bas = NULL;
2174  xmlChar *bptr, *uptr, *vptr;
2175  int remove_path = 0;
2176 
2177  if ((URI == NULL) || (*URI == 0))
2178  return NULL;
2179 
2180  /*
2181  * First parse URI into a standard form
2182  */
2183  ref = xmlCreateURI ();
2184  if (ref == NULL)
2185  return NULL;
2186  /* If URI not already in "relative" form */
2187  if (URI[0] != '.') {
2188  ret = xmlParseURIReference (ref, (const char *) URI);
2189  if (ret != 0)
2190  goto done; /* Error in URI, return NULL */
2191  } else
2192  ref->path = (char *)xmlStrdup(URI);
2193 
2194  /*
2195  * Next parse base into the same standard form
2196  */
2197  if ((base == NULL) || (*base == 0)) {
2198  val = xmlStrdup (URI);
2199  goto done;
2200  }
2201  bas = xmlCreateURI ();
2202  if (bas == NULL)
2203  goto done;
2204  if (base[0] != '.') {
2205  ret = xmlParseURIReference (bas, (const char *) base);
2206  if (ret != 0)
2207  goto done; /* Error in base, return NULL */
2208  } else
2209  bas->path = (char *)xmlStrdup(base);
2210 
2211  /*
2212  * If the scheme / server on the URI differs from the base,
2213  * just return the URI
2214  */
2215  if ((ref->scheme != NULL) &&
2216  ((bas->scheme == NULL) ||
2217  (xmlStrcmp ((xmlChar *)bas->scheme, (xmlChar *)ref->scheme)) ||
2218  (xmlStrcmp ((xmlChar *)bas->server, (xmlChar *)ref->server)))) {
2219  val = xmlStrdup (URI);
2220  goto done;
2221  }
2222  if (xmlStrEqual((xmlChar *)bas->path, (xmlChar *)ref->path)) {
2223  val = xmlStrdup(BAD_CAST "");
2224  goto done;
2225  }
2226  if (bas->path == NULL) {
2227  val = xmlStrdup((xmlChar *)ref->path);
2228  goto done;
2229  }
2230  if (ref->path == NULL) {
2231  ref->path = (char *) "/";
2232  remove_path = 1;
2233  }
2234 
2235  /*
2236  * At this point (at last!) we can compare the two paths
2237  *
2238  * First we take care of the special case where either of the
2239  * two path components may be missing (bug 316224)
2240  */
2241  bptr = (xmlChar *)bas->path;
2242  {
2243  xmlChar *rptr = (xmlChar *) ref->path;
2244  int pos = 0;
2245 
2246  /*
2247  * Next we compare the two strings and find where they first differ
2248  */
2249  if ((*rptr == '.') && (rptr[1] == '/'))
2250  rptr += 2;
2251  if ((*bptr == '.') && (bptr[1] == '/'))
2252  bptr += 2;
2253  else if ((*bptr == '/') && (*rptr != '/'))
2254  bptr++;
2255  while ((bptr[pos] == rptr[pos]) && (bptr[pos] != 0))
2256  pos++;
2257 
2258  if (bptr[pos] == rptr[pos]) {
2259  val = xmlStrdup(BAD_CAST "");
2260  goto done; /* (I can't imagine why anyone would do this) */
2261  }
2262 
2263  /*
2264  * In URI, "back up" to the last '/' encountered. This will be the
2265  * beginning of the "unique" suffix of URI
2266  */
2267  ix = pos;
2268  for (; ix > 0; ix--) {
2269  if (rptr[ix - 1] == '/')
2270  break;
2271  }
2272  uptr = (xmlChar *)&rptr[ix];
2273 
2274  /*
2275  * In base, count the number of '/' from the differing point
2276  */
2277  for (; bptr[ix] != 0; ix++) {
2278  if (bptr[ix] == '/')
2279  nbslash++;
2280  }
2281 
2282  /*
2283  * e.g: URI="foo/" base="foo/bar" -> "./"
2284  */
2285  if (nbslash == 0 && !uptr[0]) {
2286  val = xmlStrdup(BAD_CAST "./");
2287  goto done;
2288  }
2289 
2290  len = xmlStrlen (uptr) + 1;
2291  }
2292 
2293  if (nbslash == 0) {
2294  if (uptr != NULL)
2295  /* exception characters from xmlSaveUri */
2296  val = xmlURIEscapeStr(uptr, BAD_CAST "/;&=+$,");
2297  goto done;
2298  }
2299 
2300  /*
2301  * Allocate just enough space for the returned string -
2302  * length of the remainder of the URI, plus enough space
2303  * for the "../" groups, plus one for the terminator
2304  */
2305  val = (xmlChar *) xmlMalloc (len + 3 * nbslash);
2306  if (val == NULL) {
2307  xmlURIErrMemory("building relative URI\n");
2308  goto done;
2309  }
2310  vptr = val;
2311  /*
2312  * Put in as many "../" as needed
2313  */
2314  for (; nbslash>0; nbslash--) {
2315  *vptr++ = '.';
2316  *vptr++ = '.';
2317  *vptr++ = '/';
2318  }
2319  /*
2320  * Finish up with the end of the URI
2321  */
2322  if (uptr != NULL) {
2323  if ((vptr > val) && (len > 0) &&
2324  (uptr[0] == '/') && (vptr[-1] == '/')) {
2325  memcpy (vptr, uptr + 1, len - 1);
2326  vptr[len - 2] = 0;
2327  } else {
2328  memcpy (vptr, uptr, len);
2329  vptr[len - 1] = 0;
2330  }
2331  } else {
2332  vptr[len - 1] = 0;
2333  }
2334 
2335  /* escape the freshly-built path */
2336  vptr = val;
2337  /* exception characters from xmlSaveUri */
2338  val = xmlURIEscapeStr(vptr, BAD_CAST "/;&=+$,");
2339  xmlFree(vptr);
2340 
2341 done:
2342  /*
2343  * Free the working variables
2344  */
2345  if (remove_path != 0)
2346  ref->path = NULL;
2347  if (ref != NULL)
2348  xmlFreeURI (ref);
2349  if (bas != NULL)
2350  xmlFreeURI (bas);
2351 
2352  return val;
2353 }
xmlChar * xmlURIEscapeStr(const xmlChar *str, const xmlChar *list)
Definition: uri.c:1672
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:422
Definition: send.c:48
char * server
Definition: uri.h:37
#define BAD_CAST
Definition: xmlstring.h:35
GLuint GLfloat * val
Definition: glext.h:7180
xmlURIPtr xmlCreateURI(void)
Definition: uri.c:1014
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
int ret
unsigned char xmlChar
Definition: xmlstring.h:28
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
int xmlParseURIReference(xmlURIPtr uri, const char *str)
Definition: uri.c:964
char * path
Definition: uri.h:40
Definition: uri.h:33
char * scheme
Definition: uri.h:34
void xmlFreeURI(xmlURIPtr uri)
Definition: uri.c:1381
static void xmlURIErrMemory(const char *extra)
Definition: uri.c:36
#define NULL
Definition: types.h:112
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: globals.h:247
XMLPUBFUN int XMLCALL xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:157
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:66
XMLPUBFUN int XMLCALL xmlStrcmp(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:132

◆ xmlBuildURI()

XMLPUBFUN xmlChar* XMLCALL xmlBuildURI ( const xmlChar URI,
const xmlChar base 
)

xmlBuildURI: @URI: the URI instance found in the document @base: the base value

Computes he final URI of the reference done by checking that the given URI is valid, and building the final URI using the base URI. This is processed according to section 5.2 of the RFC 2396

5.2. Resolving Relative References to Absolute Form

Returns a new URI string (to be freed by the caller) or NULL in case of error.

Definition at line 1884 of file uri.c.

1884  {
1885  xmlChar *val = NULL;
1886  int ret, len, indx, cur, out;
1887  xmlURIPtr ref = NULL;
1888  xmlURIPtr bas = NULL;
1889  xmlURIPtr res = NULL;
1890 
1891  /*
1892  * 1) The URI reference is parsed into the potential four components and
1893  * fragment identifier, as described in Section 4.3.
1894  *
1895  * NOTE that a completely empty URI is treated by modern browsers
1896  * as a reference to "." rather than as a synonym for the current
1897  * URI. Should we do that here?
1898  */
1899  if (URI == NULL)
1900  ret = -1;
1901  else {
1902  if (*URI) {
1903  ref = xmlCreateURI();
1904  if (ref == NULL)
1905  goto done;
1906  ret = xmlParseURIReference(ref, (const char *) URI);
1907  }
1908  else
1909  ret = 0;
1910  }
1911  if (ret != 0)
1912  goto done;
1913  if ((ref != NULL) && (ref->scheme != NULL)) {
1914  /*
1915  * The URI is absolute don't modify.
1916  */
1917  val = xmlStrdup(URI);
1918  goto done;
1919  }
1920  if (base == NULL)
1921  ret = -1;
1922  else {
1923  bas = xmlCreateURI();
1924  if (bas == NULL)
1925  goto done;
1926  ret = xmlParseURIReference(bas, (const char *) base);
1927  }
1928  if (ret != 0) {
1929  if (ref)
1930  val = xmlSaveUri(ref);
1931  goto done;
1932  }
1933  if (ref == NULL) {
1934  /*
1935  * the base fragment must be ignored
1936  */
1937  if (bas->fragment != NULL) {
1938  xmlFree(bas->fragment);
1939  bas->fragment = NULL;
1940  }
1941  val = xmlSaveUri(bas);
1942  goto done;
1943  }
1944 
1945  /*
1946  * 2) If the path component is empty and the scheme, authority, and
1947  * query components are undefined, then it is a reference to the
1948  * current document and we are done. Otherwise, the reference URI's
1949  * query and fragment components are defined as found (or not found)
1950  * within the URI reference and not inherited from the base URI.
1951  *
1952  * NOTE that in modern browsers, the parsing differs from the above
1953  * in the following aspect: the query component is allowed to be
1954  * defined while still treating this as a reference to the current
1955  * document.
1956  */
1957  res = xmlCreateURI();
1958  if (res == NULL)
1959  goto done;
1960  if ((ref->scheme == NULL) && (ref->path == NULL) &&
1961  ((ref->authority == NULL) && (ref->server == NULL))) {
1962  if (bas->scheme != NULL)
1963  res->scheme = xmlMemStrdup(bas->scheme);
1964  if (bas->authority != NULL)
1965  res->authority = xmlMemStrdup(bas->authority);
1966  else if ((bas->server != NULL) || (bas->port == -1)) {
1967  if (bas->server != NULL)
1968  res->server = xmlMemStrdup(bas->server);
1969  if (bas->user != NULL)
1970  res->user = xmlMemStrdup(bas->user);
1971  res->port = bas->port;
1972  }
1973  if (bas->path != NULL)
1974  res->path = xmlMemStrdup(bas->path);
1975  if (ref->query_raw != NULL)
1976  res->query_raw = xmlMemStrdup (ref->query_raw);
1977  else if (ref->query != NULL)
1978  res->query = xmlMemStrdup(ref->query);
1979  else if (bas->query_raw != NULL)
1980  res->query_raw = xmlMemStrdup(bas->query_raw);
1981  else if (bas->query != NULL)
1982  res->query = xmlMemStrdup(bas->query);
1983  if (ref->fragment != NULL)
1984  res->fragment = xmlMemStrdup(ref->fragment);
1985  goto step_7;
1986  }
1987 
1988  /*
1989  * 3) If the scheme component is defined, indicating that the reference
1990  * starts with a scheme name, then the reference is interpreted as an
1991  * absolute URI and we are done. Otherwise, the reference URI's
1992  * scheme is inherited from the base URI's scheme component.
1993  */
1994  if (ref->scheme != NULL) {
1995  val = xmlSaveUri(ref);
1996  goto done;
1997  }
1998  if (bas->scheme != NULL)
1999  res->scheme = xmlMemStrdup(bas->scheme);
2000 
2001  if (ref->query_raw != NULL)
2002  res->query_raw = xmlMemStrdup(ref->query_raw);
2003  else if (ref->query != NULL)
2004  res->query = xmlMemStrdup(ref->query);
2005  if (ref->fragment != NULL)
2006  res->fragment = xmlMemStrdup(ref->fragment);
2007 
2008  /*
2009  * 4) If the authority component is defined, then the reference is a
2010  * network-path and we skip to step 7. Otherwise, the reference
2011  * URI's authority is inherited from the base URI's authority
2012  * component, which will also be undefined if the URI scheme does not
2013  * use an authority component.
2014  */
2015  if ((ref->authority != NULL) || (ref->server != NULL)) {
2016  if (ref->authority != NULL)
2017  res->authority = xmlMemStrdup(ref->authority);
2018  else {
2019  res->server = xmlMemStrdup(ref->server);
2020  if (ref->user != NULL)
2021  res->user = xmlMemStrdup(ref->user);
2022  res->port = ref->port;
2023  }
2024  if (ref->path != NULL)
2025  res->path = xmlMemStrdup(ref->path);
2026  goto step_7;
2027  }
2028  if (bas->authority != NULL)
2029  res->authority = xmlMemStrdup(bas->authority);
2030  else if ((bas->server != NULL) || (bas->port == -1)) {
2031  if (bas->server != NULL)
2032  res->server = xmlMemStrdup(bas->server);
2033  if (bas->user != NULL)
2034  res->user = xmlMemStrdup(bas->user);
2035  res->port = bas->port;
2036  }
2037 
2038  /*
2039  * 5) If the path component begins with a slash character ("/"), then
2040  * the reference is an absolute-path and we skip to step 7.
2041  */
2042  if ((ref->path != NULL) && (ref->path[0] == '/')) {
2043  res->path = xmlMemStrdup(ref->path);
2044  goto step_7;
2045  }
2046 
2047 
2048  /*
2049  * 6) If this step is reached, then we are resolving a relative-path
2050  * reference. The relative path needs to be merged with the base
2051  * URI's path. Although there are many ways to do this, we will
2052  * describe a simple method using a separate string buffer.
2053  *
2054  * Allocate a buffer large enough for the result string.
2055  */
2056  len = 2; /* extra / and 0 */
2057  if (ref->path != NULL)
2058  len += strlen(ref->path);
2059  if (bas->path != NULL)
2060  len += strlen(bas->path);
2061  res->path = (char *) xmlMallocAtomic(len);
2062  if (res->path == NULL) {
2063  xmlURIErrMemory("resolving URI against base\n");
2064  goto done;
2065  }
2066  res->path[0] = 0;
2067 
2068  /*
2069  * a) All but the last segment of the base URI's path component is
2070  * copied to the buffer. In other words, any characters after the
2071  * last (right-most) slash character, if any, are excluded.
2072  */
2073  cur = 0;
2074  out = 0;
2075  if (bas->path != NULL) {
2076  while (bas->path[cur] != 0) {
2077  while ((bas->path[cur] != 0) && (bas->path[cur] != '/'))
2078  cur++;
2079  if (bas->path[cur] == 0)
2080  break;
2081 
2082  cur++;
2083  while (out < cur) {
2084  res->path[out] = bas->path[out];
2085  out++;
2086  }
2087  }
2088  }
2089  res->path[out] = 0;
2090 
2091  /*
2092  * b) The reference's path component is appended to the buffer
2093  * string.
2094  */
2095  if (ref->path != NULL && ref->path[0] != 0) {
2096  indx = 0;
2097  /*
2098  * Ensure the path includes a '/'
2099  */
2100  if ((out == 0) && (bas->server != NULL))
2101  res->path[out++] = '/';
2102  while (ref->path[indx] != 0) {
2103  res->path[out++] = ref->path[indx++];
2104  }
2105  }
2106  res->path[out] = 0;
2107 
2108  /*
2109  * Steps c) to h) are really path normalization steps
2110  */
2111  xmlNormalizeURIPath(res->path);
2112 
2113 step_7:
2114 
2115  /*
2116  * 7) The resulting URI components, including any inherited from the
2117  * base URI, are recombined to give the absolute form of the URI
2118  * reference.
2119  */
2120  val = xmlSaveUri(res);
2121 
2122 done:
2123  if (ref != NULL)
2124  xmlFreeURI(ref);
2125  if (bas != NULL)
2126  xmlFreeURI(bas);
2127  if (res != NULL)
2128  xmlFreeURI(res);
2129  return(val);
2130 }
XMLPUBVAR xmlMallocFunc xmlMallocAtomic
Definition: globals.h:248
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
xmlChar * xmlSaveUri(xmlURIPtr uri)
Definition: uri.c:1060
int port
Definition: uri.h:39
Definition: send.c:48
char * server
Definition: uri.h:37
char * query
Definition: uri.h:41
char * authority
Definition: uri.h:36
char * query_raw
Definition: uri.h:44
int xmlNormalizeURIPath(char *path)
Definition: uri.c:1414
GLuint GLfloat * val
Definition: glext.h:7180
xmlURIPtr xmlCreateURI(void)
Definition: uri.c:1014
static FILE * out
Definition: regtests2xml.c:44
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
int ret
unsigned char xmlChar
Definition: xmlstring.h:28
GLenum GLsizei len
Definition: glext.h:6722
int xmlParseURIReference(xmlURIPtr uri, const char *str)
Definition: uri.c:964
FxCollectionEntry * cur
char * path
Definition: uri.h:40
XMLPUBVAR xmlStrdupFunc xmlMemStrdup
Definition: globals.h:251
Definition: uri.h:33
char * scheme
Definition: uri.h:34
char * user
Definition: uri.h:38
void xmlFreeURI(xmlURIPtr uri)
Definition: uri.c:1381
static void xmlURIErrMemory(const char *extra)
Definition: uri.c:36
#define NULL
Definition: types.h:112
GLuint res
Definition: glext.h:9613
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:66
char * fragment
Definition: uri.h:42

Referenced by xmlCreateEntityParserCtxtInternal(), xmlSAX2EntityDecl(), xmlSAX2ResolveEntity(), xmlSAX2UnparsedEntityDecl(), xsltDocumentElem(), xsltDocumentFunction(), xsltLoadStylesheetPI(), xsltParseStylesheetImport(), and xsltParseStylesheetInclude().

◆ xmlCanonicPath()

XMLPUBFUN xmlChar* XMLCALL xmlCanonicPath ( const xmlChar path)

Definition at line 2372 of file uri.c.

2373 {
2374 /*
2375  * For Windows implementations, additional work needs to be done to
2376  * replace backslashes in pathnames with "forward slashes"
2377  */
2378 #if defined(_WIN32) && !defined(__CYGWIN__)
2379  int len = 0;
2380  char *p = NULL;
2381 #endif
2382  xmlURIPtr uri;
2383  xmlChar *ret;
2384  const xmlChar *absuri;
2385 
2386  if (path == NULL)
2387  return(NULL);
2388 
2389 #if defined(_WIN32)
2390  /*
2391  * We must not change the backslashes to slashes if the the path
2392  * starts with \\?\
2393  * Those paths can be up to 32k characters long.
2394  * Was added specifically for OpenOffice, those paths can't be converted
2395  * to URIs anyway.
2396  */
2397  if ((path[0] == '\\') && (path[1] == '\\') && (path[2] == '?') &&
2398  (path[3] == '\\') )
2399  return xmlStrdup((const xmlChar *) path);
2400 #endif
2401 
2402  /* sanitize filename starting with // so it can be used as URI */
2403  if ((path[0] == '/') && (path[1] == '/') && (path[2] != '/'))
2404  path++;
2405 
2406  if ((uri = xmlParseURI((const char *) path)) != NULL) {
2407  xmlFreeURI(uri);
2408  return xmlStrdup(path);
2409  }
2410 
2411  /* Check if this is an "absolute uri" */
2412  absuri = xmlStrstr(path, BAD_CAST "://");
2413  if (absuri != NULL) {
2414  int l, j;
2415  unsigned char c;
2416  xmlChar *escURI;
2417 
2418  /*
2419  * this looks like an URI where some parts have not been
2420  * escaped leading to a parsing problem. Check that the first
2421  * part matches a protocol.
2422  */
2423  l = absuri - path;
2424  /* Bypass if first part (part before the '://') is > 20 chars */
2425  if ((l <= 0) || (l > 20))
2426  goto path_processing;
2427  /* Bypass if any non-alpha characters are present in first part */
2428  for (j = 0;j < l;j++) {
2429  c = path[j];
2430  if (!(((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'))))
2431  goto path_processing;
2432  }
2433 
2434  /* Escape all except the characters specified in the supplied path */
2435  escURI = xmlURIEscapeStr(path, BAD_CAST ":/?_.#&;=");
2436  if (escURI != NULL) {
2437  /* Try parsing the escaped path */
2438  uri = xmlParseURI((const char *) escURI);
2439  /* If successful, return the escaped string */
2440  if (uri != NULL) {
2441  xmlFreeURI(uri);
2442  return escURI;
2443  }
2444  xmlFree(escURI);
2445  }
2446  }
2447 
2448 path_processing:
2449 /* For Windows implementations, replace backslashes with 'forward slashes' */
2450 #if defined(_WIN32) && !defined(__CYGWIN__)
2451  /*
2452  * Create a URI structure
2453  */
2454  uri = xmlCreateURI();
2455  if (uri == NULL) { /* Guard against 'out of memory' */
2456  return(NULL);
2457  }
2458 
2459  len = xmlStrlen(path);
2460  if ((len > 2) && IS_WINDOWS_PATH(path)) {
2461  /* make the scheme 'file' */
2462  uri->scheme = (char *) xmlStrdup(BAD_CAST "file");
2463  /* allocate space for leading '/' + path + string terminator */
2464  uri->path = xmlMallocAtomic(len + 2);
2465  if (uri->path == NULL) {
2466  xmlFreeURI(uri); /* Guard against 'out of memory' */
2467  return(NULL);
2468  }
2469  /* Put in leading '/' plus path */
2470  uri->path[0] = '/';
2471  p = uri->path + 1;
2472  strncpy(p, (char *) path, len + 1);
2473  } else {
2474  uri->path = (char *) xmlStrdup(path);
2475  if (uri->path == NULL) {
2476  xmlFreeURI(uri);
2477  return(NULL);
2478  }
2479  p = uri->path;
2480  }
2481  /* Now change all occurrences of '\' to '/' */
2482  while (*p != '\0') {
2483  if (*p == '\\')
2484  *p = '/';
2485  p++;
2486  }
2487 
2488  if (uri->scheme == NULL) {
2489  ret = xmlStrdup((const xmlChar *) uri->path);
2490  } else {
2491  ret = xmlSaveUri(uri);
2492  }
2493 
2494  xmlFreeURI(uri);
2495 #else
2496  ret = xmlStrdup((const xmlChar *) path);
2497 #endif
2498  return(ret);
2499 }
xmlChar * xmlURIEscapeStr(const xmlChar *str, const xmlChar *list)
Definition: uri.c:1672
XMLPUBVAR xmlMallocFunc xmlMallocAtomic
Definition: globals.h:248
XMLPUBFUN const xmlChar *XMLCALL xmlStrstr(const xmlChar *str, const xmlChar *val)
Definition: xmlstring.c:341
xmlChar * xmlSaveUri(xmlURIPtr uri)
Definition: uri.c:1060
GLsizei const GLchar ** path
Definition: glext.h:7234
const char * uri
Definition: sec_mgr.c:1588
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:422
#define IS_WINDOWS_PATH(p)
Definition: uri.c:2366
#define BAD_CAST
Definition: xmlstring.h:35
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
r l[0]
Definition: byte_order.h:167
xmlURIPtr xmlCreateURI(void)
Definition: uri.c:1014
const GLubyte * c
Definition: glext.h:8905
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
int ret
unsigned char xmlChar
Definition: xmlstring.h:28
GLenum GLsizei len
Definition: glext.h:6722
Definition: uri.h:33
xmlURIPtr xmlParseURI(const char *str)
Definition: uri.c:934
void xmlFreeURI(xmlURIPtr uri)
Definition: uri.c:1381
#define NULL
Definition: types.h:112
#define c
Definition: ke_i.h:80
GLfloat GLfloat p
Definition: glext.h:8902
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:66

Referenced by xmlCtxtResetPush(), xmlNewInputFromFile(), xmlPathToURI(), and xmlSAX2ExternalSubset().

◆ xmlCreateURI()

XMLPUBFUN xmlURIPtr XMLCALL xmlCreateURI ( void  )

xmlCreateURI:

Simply creates an empty xmlURI

Returns the new structure or NULL in case of error

Definition at line 1014 of file uri.c.

1014  {
1015  xmlURIPtr ret;
1016 
1017  ret = (xmlURIPtr) xmlMalloc(sizeof(xmlURI));
1018  if (ret == NULL) {
1019  xmlURIErrMemory("creating URI structure\n");
1020  return(NULL);
1021  }
1022  memset(ret, 0, sizeof(xmlURI));
1023  return(ret);
1024 }
int ret
Definition: uri.h:33
static void xmlURIErrMemory(const char *extra)
Definition: uri.c:36
#define NULL
Definition: types.h:112
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: globals.h:247
xmlURI * xmlURIPtr
Definition: uri.h:32
#define memset(x, y, z)
Definition: compat.h:39

Referenced by xmlBuildRelativeURI(), xmlBuildURI(), xmlCanonicPath(), xmlParseURI(), xmlParseURIRaw(), xmlURIEscape(), and xsltCheckWrite().

◆ xmlFreeURI()

XMLPUBFUN void XMLCALL xmlFreeURI ( xmlURIPtr  uri)

xmlFreeURI: @uri: pointer to an xmlURI

Free up the xmlURI struct

Definition at line 1381 of file uri.c.

1381  {
1382  if (uri == NULL) return;
1383 
1384  if (uri->scheme != NULL) xmlFree(uri->scheme);
1385  if (uri->server != NULL) xmlFree(uri->server);
1386  if (uri->user != NULL) xmlFree(uri->user);
1387  if (uri->path != NULL) xmlFree(uri->path);
1388  if (uri->fragment != NULL) xmlFree(uri->fragment);
1389  if (uri->opaque != NULL) xmlFree(uri->opaque);
1390  if (uri->authority != NULL) xmlFree(uri->authority);
1391  if (uri->query != NULL) xmlFree(uri->query);
1392  if (uri->query_raw != NULL) xmlFree(uri->query_raw);
1393  xmlFree(uri);
1394 }
const char * uri
Definition: sec_mgr.c:1588
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
#define NULL
Definition: types.h:112

Referenced by xmlBuildURI(), xmlCanonicPath(), xmlParseEntityDecl(), xmlParseStartTag2(), xmlParseURI(), xmlParseURIRaw(), xmlPathToURI(), xmlURIEscape(), xsltCheckRead(), xsltCheckWrite(), xsltDocumentFunctionLoadDocument(), and xsltLoadStylesheetPI().

◆ xmlNormalizeURIPath()

XMLPUBFUN int XMLCALL xmlNormalizeURIPath ( char path)

xmlNormalizeURIPath: @path: pointer to the path string

Applies the 5 normalization steps to a path string–that is, RFC 2396 Section 5.2, steps 6.c through 6.g.

Normalization occurs directly on the string, no new allocation is done

Returns 0 or an error code

Definition at line 1414 of file uri.c.

1414  {
1415  char *cur, *out;
1416 
1417  if (path == NULL)
1418  return(-1);
1419 
1420  /* Skip all initial "/" chars. We want to get to the beginning of the
1421  * first non-empty segment.
1422  */
1423  cur = path;
1424  while (cur[0] == '/')
1425  ++cur;
1426  if (cur[0] == '\0')
1427  return(0);
1428 
1429  /* Keep everything we've seen so far. */
1430  out = cur;
1431 
1432  /*
1433  * Analyze each segment in sequence for cases (c) and (d).
1434  */
1435  while (cur[0] != '\0') {
1436  /*
1437  * c) All occurrences of "./", where "." is a complete path segment,
1438  * are removed from the buffer string.
1439  */
1440  if ((cur[0] == '.') && (cur[1] == '/')) {
1441  cur += 2;
1442  /* '//' normalization should be done at this point too */
1443  while (cur[0] == '/')
1444  cur++;
1445  continue;
1446  }
1447 
1448  /*
1449  * d) If the buffer string ends with "." as a complete path segment,
1450  * that "." is removed.
1451  */
1452  if ((cur[0] == '.') && (cur[1] == '\0'))
1453  break;
1454 
1455  /* Otherwise keep the segment. */
1456  while (cur[0] != '/') {
1457  if (cur[0] == '\0')
1458  goto done_cd;
1459  (out++)[0] = (cur++)[0];
1460  }
1461  /* normalize // */
1462  while ((cur[0] == '/') && (cur[1] == '/'))
1463  cur++;
1464 
1465  (out++)[0] = (cur++)[0];
1466  }
1467  done_cd:
1468  out[0] = '\0';
1469 
1470  /* Reset to the beginning of the first segment for the next sequence. */
1471  cur = path;
1472  while (cur[0] == '/')
1473  ++cur;
1474  if (cur[0] == '\0')
1475  return(0);
1476 
1477  /*
1478  * Analyze each segment in sequence for cases (e) and (f).
1479  *
1480  * e) All occurrences of "<segment>/../", where <segment> is a
1481  * complete path segment not equal to "..", are removed from the
1482  * buffer string. Removal of these path segments is performed
1483  * iteratively, removing the leftmost matching pattern on each
1484  * iteration, until no matching pattern remains.
1485  *
1486  * f) If the buffer string ends with "<segment>/..", where <segment>
1487  * is a complete path segment not equal to "..", that
1488  * "<segment>/.." is removed.
1489  *
1490  * To satisfy the "iterative" clause in (e), we need to collapse the
1491  * string every time we find something that needs to be removed. Thus,
1492  * we don't need to keep two pointers into the string: we only need a
1493  * "current position" pointer.
1494  */
1495  while (1) {
1496  char *segp, *tmp;
1497 
1498  /* At the beginning of each iteration of this loop, "cur" points to
1499  * the first character of the segment we want to examine.
1500  */
1501 
1502  /* Find the end of the current segment. */
1503  segp = cur;
1504  while ((segp[0] != '/') && (segp[0] != '\0'))
1505  ++segp;
1506 
1507  /* If this is the last segment, we're done (we need at least two
1508  * segments to meet the criteria for the (e) and (f) cases).
1509  */
1510  if (segp[0] == '\0')
1511  break;
1512 
1513  /* If the first segment is "..", or if the next segment _isn't_ "..",
1514  * keep this segment and try the next one.
1515  */
1516  ++segp;
1517  if (((cur[0] == '.') && (cur[1] == '.') && (segp == cur+3))
1518  || ((segp[0] != '.') || (segp[1] != '.')
1519  || ((segp[2] != '/') && (segp[2] != '\0')))) {
1520  cur = segp;
1521  continue;
1522  }
1523 
1524  /* If we get here, remove this segment and the next one and back up
1525  * to the previous segment (if there is one), to implement the
1526  * "iteratively" clause. It's pretty much impossible to back up
1527  * while maintaining two pointers into the buffer, so just compact
1528  * the whole buffer now.
1529  */
1530 
1531  /* If this is the end of the buffer, we're done. */
1532  if (segp[2] == '\0') {
1533  cur[0] = '\0';
1534  break;
1535  }
1536  /* Valgrind complained, strcpy(cur, segp + 3); */
1537  /* string will overlap, do not use strcpy */
1538  tmp = cur;
1539  segp += 3;
1540  while ((*tmp++ = *segp++) != 0)
1541  ;
1542 
1543  /* If there are no previous segments, then keep going from here. */
1544  segp = cur;
1545  while ((segp > path) && ((--segp)[0] == '/'))
1546  ;
1547  if (segp == path)
1548  continue;
1549 
1550  /* "segp" is pointing to the end of a previous segment; find it's
1551  * start. We need to back up to the previous segment and start
1552  * over with that to handle things like "foo/bar/../..". If we
1553  * don't do this, then on the first pass we'll remove the "bar/..",
1554  * but be pointing at the second ".." so we won't realize we can also
1555  * remove the "foo/..".
1556  */
1557  cur = segp;
1558  while ((cur > path) && (cur[-1] != '/'))
1559  --cur;
1560  }
1561  out[0] = '\0';
1562 
1563  /*
1564  * g) If the resulting buffer string still begins with one or more
1565  * complete path segments of "..", then the reference is
1566  * considered to be in error. Implementations may handle this
1567  * error by retaining these components in the resolved path (i.e.,
1568  * treating them as part of the final URI), by removing them from
1569  * the resolved path (i.e., discarding relative levels above the
1570  * root), or by avoiding traversal of the reference.
1571  *
1572  * We discard them from the final path.
1573  */
1574  if (path[0] == '/') {
1575  cur = path;
1576  while ((cur[0] == '/') && (cur[1] == '.') && (cur[2] == '.')
1577  && ((cur[3] == '/') || (cur[3] == '\0')))
1578  cur += 3;
1579 
1580  if (cur != path) {
1581  out = path;
1582  while (cur[0] != '\0')
1583  (out++)[0] = (cur++)[0];
1584  out[0] = 0;
1585  }
1586  }
1587 
1588  return(0);
1589 }
GLsizei const GLchar ** path
Definition: glext.h:7234
static FILE * out
Definition: regtests2xml.c:44
FxCollectionEntry * cur
#define NULL
Definition: types.h:112

Referenced by xmlBuildURI().

◆ xmlParseURI()

XMLPUBFUN xmlURIPtr XMLCALL xmlParseURI ( const char str)

xmlParseURI: @str: the URI string to analyze

Parse an URI based on RFC 3986

URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]

Returns a newly built xmlURIPtr or NULL in case of error

Definition at line 934 of file uri.c.

934  {
935  xmlURIPtr uri;
936  int ret;
937 
938  if (str == NULL)
939  return(NULL);
940  uri = xmlCreateURI();
941  if (uri != NULL) {
943  if (ret) {
944  xmlFreeURI(uri);
945  return(NULL);
946  }
947  }
948  return(uri);
949 }
const char * uri
Definition: sec_mgr.c:1588
const WCHAR * str
xmlURIPtr xmlCreateURI(void)
Definition: uri.c:1014
int ret
Definition: uri.h:33
void xmlFreeURI(xmlURIPtr uri)
Definition: uri.c:1381
#define NULL
Definition: types.h:112
static int xmlParse3986URIReference(xmlURIPtr uri, const char *str)
Definition: uri.c:900

Referenced by xmlCanonicPath(), xmlParseEntityDecl(), xmlParseStartTag2(), xmlPathToURI(), xsltCheckRead(), xsltCheckWrite(), xsltDocumentFunctionLoadDocument(), and xsltLoadStylesheetPI().

◆ xmlParseURIRaw()

XMLPUBFUN xmlURIPtr XMLCALL xmlParseURIRaw ( const char str,
int  raw 
)

xmlParseURIRaw: @str: the URI string to analyze @raw: if 1 unescaping of URI pieces are disabled

Parse an URI but allows to keep intact the original fragments.

URI-reference = URI / relative-ref

Returns a newly built xmlURIPtr or NULL in case of error

Definition at line 980 of file uri.c.

980  {
981  xmlURIPtr uri;
982  int ret;
983 
984  if (str == NULL)
985  return(NULL);
986  uri = xmlCreateURI();
987  if (uri != NULL) {
988  if (raw) {
989  uri->cleanup |= 2;
990  }
992  if (ret) {
993  xmlFreeURI(uri);
994  return(NULL);
995  }
996  }
997  return(uri);
998 }
const char * uri
Definition: sec_mgr.c:1588
const WCHAR * str
xmlURIPtr xmlCreateURI(void)
Definition: uri.c:1014
int ret
int xmlParseURIReference(xmlURIPtr uri, const char *str)
Definition: uri.c:964
Definition: uri.h:33
void xmlFreeURI(xmlURIPtr uri)
Definition: uri.c:1381
#define NULL
Definition: types.h:112

◆ xmlParseURIReference()

XMLPUBFUN int XMLCALL xmlParseURIReference ( xmlURIPtr  uri,
const char str 
)

xmlParseURIReference: @uri: pointer to an URI structure @str: the string to analyze

Parse an URI reference string based on RFC 3986 and fills in the appropriate fields of the @uri structure

URI-reference = URI / relative-ref

Returns 0 or the error code

Definition at line 964 of file uri.c.

964  {
965  return(xmlParse3986URIReference(uri, str));
966 }
const char * uri
Definition: sec_mgr.c:1588
const WCHAR * str
static int xmlParse3986URIReference(xmlURIPtr uri, const char *str)
Definition: uri.c:900

Referenced by xmlBuildRelativeURI(), xmlBuildURI(), xmlParseURIRaw(), and xmlURIEscape().

◆ xmlPathToURI()

XMLPUBFUN xmlChar* XMLCALL xmlPathToURI ( const xmlChar path)

xmlPathToURI: @path: the resource locator in a filesystem notation

Constructs an URI expressing the existing path

Returns a new URI, or a duplicate of the path parameter if the construction fails. The caller is responsible for freeing the memory occupied by the returned string. If there is insufficient memory available, or the argument is NULL, the function returns NULL.

Definition at line 2513 of file uri.c.

2514 {
2515  xmlURIPtr uri;
2516  xmlURI temp;
2517  xmlChar *ret, *cal;
2518 
2519  if (path == NULL)
2520  return(NULL);
2521 
2522  if ((uri = xmlParseURI((const char *) path)) != NULL) {
2523  xmlFreeURI(uri);
2524  return xmlStrdup(path);
2525  }
2526  cal = xmlCanonicPath(path);
2527  if (cal == NULL)
2528  return(NULL);
2529 #if defined(_WIN32) && !defined(__CYGWIN__)
2530  /* xmlCanonicPath can return an URI on Windows (is that the intended behaviour?)
2531  If 'cal' is a valid URI already then we are done here, as continuing would make
2532  it invalid. */
2533  if ((uri = xmlParseURI((const char *) cal)) != NULL) {
2534  xmlFreeURI(uri);
2535  return cal;
2536  }
2537  /* 'cal' can contain a relative path with backslashes. If that is processed
2538  by xmlSaveURI, they will be escaped and the external entity loader machinery
2539  will fail. So convert them to slashes. Misuse 'ret' for walking. */
2540  ret = cal;
2541  while (*ret != '\0') {
2542  if (*ret == '\\')
2543  *ret = '/';
2544  ret++;
2545  }
2546 #endif
2547  memset(&temp, 0, sizeof(temp));
2548  temp.path = (char *) cal;
2549  ret = xmlSaveUri(&temp);
2550  xmlFree(cal);
2551  return(ret);
2552 }
xmlChar * xmlSaveUri(xmlURIPtr uri)
Definition: uri.c:1060
const char * uri
Definition: sec_mgr.c:1588
xmlChar * xmlCanonicPath(const xmlChar *path)
Definition: uri.c:2372
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
int ret
unsigned char xmlChar
Definition: xmlstring.h:28
Definition: uri.h:33
xmlURIPtr xmlParseURI(const char *str)
Definition: uri.c:934
static calc_node_t temp
Definition: rpn_ieee.c:38
void xmlFreeURI(xmlURIPtr uri)
Definition: uri.c:1381
#define NULL
Definition: types.h:112
#define memset(x, y, z)
Definition: compat.h:39
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:66

Referenced by xmlSAX2StartDocument().

◆ xmlPrintURI()

XMLPUBFUN void XMLCALL xmlPrintURI ( FILE stream,
xmlURIPtr  uri 
)

xmlPrintURI: @stream: a FILE* for the output @uri: pointer to an xmlURI

Prints the URI in the stream @stream.

Definition at line 1334 of file uri.c.

1334  {
1335  xmlChar *out;
1336 
1337  out = xmlSaveUri(uri);
1338  if (out != NULL) {
1339  fprintf(stream, "%s", (char *) out);
1340  xmlFree(out);
1341  }
1342 }
xmlChar * xmlSaveUri(xmlURIPtr uri)
Definition: uri.c:1060
const char * uri
Definition: sec_mgr.c:1588
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
static FILE * out
Definition: regtests2xml.c:44
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
Definition: parse.h:22
unsigned char xmlChar
Definition: xmlstring.h:28
#define NULL
Definition: types.h:112

◆ xmlSaveUri()

XMLPUBFUN xmlChar* XMLCALL xmlSaveUri ( xmlURIPtr  uri)

xmlSaveUri: @uri: pointer to an xmlURI

Save the URI as an escaped string

Returns a new string (to be deallocated by caller)

Definition at line 1060 of file uri.c.

1060  {
1061  xmlChar *ret = NULL;
1062  xmlChar *temp;
1063  const char *p;
1064  int len;
1065  int max;
1066 
1067  if (uri == NULL) return(NULL);
1068 
1069 
1070  max = 80;
1071  ret = (xmlChar *) xmlMallocAtomic((max + 1) * sizeof(xmlChar));
1072  if (ret == NULL) {
1073  xmlURIErrMemory("saving URI\n");
1074  return(NULL);
1075  }
1076  len = 0;
1077 
1078  if (uri->scheme != NULL) {
1079  p = uri->scheme;
1080  while (*p != 0) {
1081  if (len >= max) {
1083  if (temp == NULL) goto mem_error;
1084  ret = temp;
1085  }
1086  ret[len++] = *p++;
1087  }
1088  if (len >= max) {
1090  if (temp == NULL) goto mem_error;
1091  ret = temp;
1092  }
1093  ret[len++] = ':';
1094  }
1095  if (uri->opaque != NULL) {
1096  p = uri->opaque;
1097  while (*p != 0) {
1098  if (len + 3 >= max) {
1100  if (temp == NULL) goto mem_error;
1101  ret = temp;
1102  }
1103  if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p)))
1104  ret[len++] = *p++;
1105  else {
1106  int val = *(unsigned char *)p++;
1107  int hi = val / 0x10, lo = val % 0x10;
1108  ret[len++] = '%';
1109  ret[len++] = hi + (hi > 9? 'A'-10 : '0');
1110  ret[len++] = lo + (lo > 9? 'A'-10 : '0');
1111  }
1112  }
1113  } else {
1114  if ((uri->server != NULL) || (uri->port == -1)) {
1115  if (len + 3 >= max) {
1117  if (temp == NULL) goto mem_error;
1118  ret = temp;
1119  }
1120  ret[len++] = '/';
1121  ret[len++] = '/';
1122  if (uri->user != NULL) {
1123  p = uri->user;
1124  while (*p != 0) {
1125  if (len + 3 >= max) {
1127  if (temp == NULL) goto mem_error;
1128  ret = temp;
1129  }
1130  if ((IS_UNRESERVED(*(p))) ||
1131  ((*(p) == ';')) || ((*(p) == ':')) ||
1132  ((*(p) == '&')) || ((*(p) == '=')) ||
1133  ((*(p) == '+')) || ((*(p) == '$')) ||
1134  ((*(p) == ',')))
1135  ret[len++] = *p++;
1136  else {
1137  int val = *(unsigned char *)p++;
1138  int hi = val / 0x10, lo = val % 0x10;
1139  ret[len++] = '%';
1140  ret[len++] = hi + (hi > 9? 'A'-10 : '0');
1141  ret[len++] = lo + (lo > 9? 'A'-10 : '0');
1142  }
1143  }
1144  if (len + 3 >= max) {
1146  if (temp == NULL) goto mem_error;
1147  ret = temp;
1148  }
1149  ret[len++] = '@';
1150  }
1151  if (uri->server != NULL) {
1152  p = uri->server;
1153  while (*p != 0) {
1154  if (len >= max) {
1156  if (temp == NULL) goto mem_error;
1157  ret = temp;
1158  }
1159  ret[len++] = *p++;
1160  }
1161  if (uri->port > 0) {
1162  if (len + 10 >= max) {
1164  if (temp == NULL) goto mem_error;
1165  ret = temp;
1166  }
1167  len += snprintf((char *) &ret[len], max - len, ":%d", uri->port);
1168  }
1169  }
1170  } else if (uri->authority != NULL) {
1171  if (len + 3 >= max) {
1173  if (temp == NULL) goto mem_error;
1174  ret = temp;
1175  }
1176  ret[len++] = '/';
1177  ret[len++] = '/';
1178  p = uri->authority;
1179  while (*p != 0) {
1180  if (len + 3 >= max) {
1182  if (temp == NULL) goto mem_error;
1183  ret = temp;
1184  }
1185  if ((IS_UNRESERVED(*(p))) ||
1186  ((*(p) == '$')) || ((*(p) == ',')) || ((*(p) == ';')) ||
1187  ((*(p) == ':')) || ((*(p) == '@')) || ((*(p) == '&')) ||
1188  ((*(p) == '=')) || ((*(p) == '+')))
1189  ret[len++] = *p++;
1190  else {
1191  int val = *(unsigned char *)p++;
1192  int hi = val / 0x10, lo = val % 0x10;
1193  ret[len++] = '%';
1194  ret[len++] = hi + (hi > 9? 'A'-10 : '0');
1195  ret[len++] = lo + (lo > 9? 'A'-10 : '0');
1196  }
1197  }
1198  } else if (uri->scheme != NULL) {
1199  if (len + 3 >= max) {
1201  if (temp == NULL) goto mem_error;
1202  ret = temp;
1203  }
1204  }
1205  if (uri->path != NULL) {
1206  p = uri->path;
1207  /*
1208  * the colon in file:///d: should not be escaped or
1209  * Windows accesses fail later.
1210  */
1211  if ((uri->scheme != NULL) &&
1212  (p[0] == '/') &&
1213  (((p[1] >= 'a') && (p[1] <= 'z')) ||
1214  ((p[1] >= 'A') && (p[1] <= 'Z'))) &&
1215  (p[2] == ':') &&
1216  (xmlStrEqual(BAD_CAST uri->scheme, BAD_CAST "file"))) {
1217  if (len + 3 >= max) {
1219  if (temp == NULL) goto mem_error;
1220  ret = temp;
1221  }
1222  ret[len++] = *p++;
1223  ret[len++] = *p++;
1224  ret[len++] = *p++;
1225  }
1226  while (*p != 0) {
1227  if (len + 3 >= max) {
1229  if (temp == NULL) goto mem_error;
1230  ret = temp;
1231  }
1232  if ((IS_UNRESERVED(*(p))) || ((*(p) == '/')) ||
1233  ((*(p) == ';')) || ((*(p) == '@')) || ((*(p) == '&')) ||
1234  ((*(p) == '=')) || ((*(p) == '+')) || ((*(p) == '$')) ||
1235  ((*(p) == ',')))
1236  ret[len++] = *p++;
1237  else {
1238  int val = *(unsigned char *)p++;
1239  int hi = val / 0x10, lo = val % 0x10;
1240  ret[len++] = '%';
1241  ret[len++] = hi + (hi > 9? 'A'-10 : '0');
1242  ret[len++] = lo + (lo > 9? 'A'-10 : '0');
1243  }
1244  }
1245  }
1246  if (uri->query_raw != NULL) {
1247  if (len + 1 >= max) {
1249  if (temp == NULL) goto mem_error;
1250  ret = temp;
1251  }
1252  ret[len++] = '?';
1253  p = uri->query_raw;
1254  while (*p != 0) {
1255  if (len + 1 >= max) {
1257  if (temp == NULL) goto mem_error;
1258  ret = temp;
1259  }
1260  ret[len++] = *p++;
1261  }
1262  } else if (uri->query != NULL) {
1263  if (len + 3 >= max) {
1265  if (temp == NULL) goto mem_error;
1266  ret = temp;
1267  }
1268  ret[len++] = '?';
1269  p = uri->query;
1270  while (*p != 0) {
1271  if (len + 3 >= max) {
1273  if (temp == NULL) goto mem_error;
1274  ret = temp;
1275  }
1276  if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))
1277  ret[len++] = *p++;
1278  else {
1279  int val = *(unsigned char *)p++;
1280  int hi = val / 0x10, lo = val % 0x10;
1281  ret[len++] = '%';
1282  ret[len++] = hi + (hi > 9? 'A'-10 : '0');
1283  ret[len++] = lo + (lo > 9? 'A'-10 : '0');
1284  }
1285  }
1286  }
1287  }
1288  if (uri->fragment != NULL) {
1289  if (len + 3 >= max) {
1291  if (temp == NULL) goto mem_error;
1292  ret = temp;
1293  }
1294  ret[len++] = '#';
1295  p = uri->fragment;
1296  while (*p != 0) {
1297  if (len + 3 >= max) {
1299  if (temp == NULL) goto mem_error;
1300  ret = temp;
1301  }
1302  if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))
1303  ret[len++] = *p++;
1304  else {
1305  int val = *(unsigned char *)p++;
1306  int hi = val / 0x10, lo = val % 0x10;
1307  ret[len++] = '%';
1308  ret[len++] = hi + (hi > 9? 'A'-10 : '0');
1309  ret[len++] = lo + (lo > 9? 'A'-10 : '0');
1310  }
1311  }
1312  }
1313  if (len >= max) {
1315  if (temp == NULL) goto mem_error;
1316  ret = temp;
1317  }
1318  ret[len] = 0;
1319  return(ret);
1320 
1321 mem_error:
1322  xmlFree(ret);
1323  return(NULL);
1324 }
XMLPUBVAR xmlMallocFunc xmlMallocAtomic
Definition: globals.h:248
#define max(a, b)
Definition: svc.c:63
const char * uri
Definition: sec_mgr.c:1588
#define snprintf
Definition: wintirpc.h:48
#define BAD_CAST
Definition: xmlstring.h:35
GLuint GLfloat * val
Definition: glext.h:7180
#define IS_UNRESERVED(x)
Definition: uri.c:120
#define IS_RESERVED(x)
Definition: uri.c:111
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
int ret
static xmlChar * xmlSaveUriRealloc(xmlChar *ret, int *max)
Definition: uri.c:1033
unsigned char xmlChar
Definition: xmlstring.h:28
GLenum GLsizei len
Definition: glext.h:6722
static calc_node_t temp
Definition: rpn_ieee.c:38
static void xmlURIErrMemory(const char *extra)
Definition: uri.c:36
#define NULL
Definition: types.h:112
XMLPUBFUN int XMLCALL xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:157
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by xmlBuildURI(), xmlCanonicPath(), xmlPathToURI(), xmlPrintURI(), and xsltDocumentFunctionLoadDocument().

◆ xmlURIEscape()

XMLPUBFUN xmlChar* XMLCALL xmlURIEscape ( const xmlChar str)

xmlURIEscape: @str: the string of the URI to escape

Escaping routine, does not do validity checks ! It will try to escape the chars needing this, but this is heuristic based it's impossible to be sure.

Returns an copy of the string, but escaped

25 May 2001 Uses xmlParseURI and xmlURIEscapeStr to try to escape correctly according to RFC2396.

  • Carl Douglas

Definition at line 1745 of file uri.c.

1746 {
1747  xmlChar *ret, *segment = NULL;
1748  xmlURIPtr uri;
1749  int ret2;
1750 
1751 #define NULLCHK(p) if(!p) { \
1752  xmlURIErrMemory("escaping URI value\n"); \
1753  xmlFreeURI(uri); \
1754  return NULL; } \
1755 
1756  if (str == NULL)
1757  return (NULL);
1758 
1759  uri = xmlCreateURI();
1760  if (uri != NULL) {
1761  /*
1762  * Allow escaping errors in the unescaped form
1763  */
1764  uri->cleanup = 1;
1765  ret2 = xmlParseURIReference(uri, (const char *)str);
1766  if (ret2) {
1767  xmlFreeURI(uri);
1768  return (NULL);
1769  }
1770  }
1771 
1772  if (!uri)
1773  return NULL;
1774 
1775  ret = NULL;
1776 
1777  if (uri->scheme) {
1778  segment = xmlURIEscapeStr(BAD_CAST uri->scheme, BAD_CAST "+-.");
1779  NULLCHK(segment)
1780  ret = xmlStrcat(ret, segment);
1781  ret = xmlStrcat(ret, BAD_CAST ":");
1782  xmlFree(segment);
1783  }
1784 
1785  if (uri->authority) {
1786  segment =
1787  xmlURIEscapeStr(BAD_CAST uri->authority, BAD_CAST "/?;:@");
1788  NULLCHK(segment)
1789  ret = xmlStrcat(ret, BAD_CAST "//");
1790  ret = xmlStrcat(ret, segment);
1791  xmlFree(segment);
1792  }
1793 
1794  if (uri->user) {
1795  segment = xmlURIEscapeStr(BAD_CAST uri->user, BAD_CAST ";:&=+$,");
1796  NULLCHK(segment)
1797  ret = xmlStrcat(ret,BAD_CAST "//");
1798  ret = xmlStrcat(ret, segment);
1799  ret = xmlStrcat(ret, BAD_CAST "@");
1800  xmlFree(segment);
1801  }
1802 
1803  if (uri->server) {
1804  segment = xmlURIEscapeStr(BAD_CAST uri->server, BAD_CAST "/?;:@");
1805  NULLCHK(segment)
1806  if (uri->user == NULL)
1807  ret = xmlStrcat(ret, BAD_CAST "//");
1808  ret = xmlStrcat(ret, segment);
1809  xmlFree(segment);
1810  }
1811 
1812  if (uri->port) {
1813  xmlChar port[10];
1814 
1815  snprintf((char *) port, 10, "%d", uri->port);
1816  ret = xmlStrcat(ret, BAD_CAST ":");
1817  ret = xmlStrcat(ret, port);
1818  }
1819 
1820  if (uri->path) {
1821  segment =
1822  xmlURIEscapeStr(BAD_CAST uri->path, BAD_CAST ":@&=+$,/?;");
1823  NULLCHK(segment)
1824  ret = xmlStrcat(ret, segment);
1825  xmlFree(segment);
1826  }
1827 
1828  if (uri->query_raw) {
1829  ret = xmlStrcat(ret, BAD_CAST "?");
1830  ret = xmlStrcat(ret, BAD_CAST uri->query_raw);
1831  }
1832  else if (uri->query) {
1833  segment =
1834  xmlURIEscapeStr(BAD_CAST uri->query, BAD_CAST ";/?:@&=+,$");
1835  NULLCHK(segment)
1836  ret = xmlStrcat(ret, BAD_CAST "?");
1837  ret = xmlStrcat(ret, segment);
1838  xmlFree(segment);
1839  }
1840 
1841  if (uri->opaque) {
1842  segment = xmlURIEscapeStr(BAD_CAST uri->opaque, BAD_CAST "");
1843  NULLCHK(segment)
1844  ret = xmlStrcat(ret, segment);
1845  xmlFree(segment);
1846  }
1847 
1848  if (uri->fragment) {
1849  segment = xmlURIEscapeStr(BAD_CAST uri->fragment, BAD_CAST "#");
1850  NULLCHK(segment)
1851  ret = xmlStrcat(ret, BAD_CAST "#");
1852  ret = xmlStrcat(ret, segment);
1853  xmlFree(segment);
1854  }
1855 
1856  xmlFreeURI(uri);
1857 #undef NULLCHK
1858 
1859  return (ret);
1860 }
xmlChar * xmlURIEscapeStr(const xmlChar *str, const xmlChar *list)
Definition: uri.c:1672
const char * uri
Definition: sec_mgr.c:1588
#define snprintf
Definition: wintirpc.h:48
XMLPUBFUN xmlChar *XMLCALL xmlStrcat(xmlChar *cur, const xmlChar *add)
Definition: xmlstring.c:526
const WCHAR * str
#define BAD_CAST
Definition: xmlstring.h:35
xmlURIPtr xmlCreateURI(void)
Definition: uri.c:1014
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
int ret
unsigned char xmlChar
Definition: xmlstring.h:28
int xmlParseURIReference(xmlURIPtr uri, const char *str)
Definition: uri.c:964
Definition: uri.h:33
void xmlFreeURI(xmlURIPtr uri)
Definition: uri.c:1381
#define NULL
Definition: types.h:112
USHORT port
Definition: uri.c:228
#define NULLCHK(p)

◆ xmlURIEscapeStr()

XMLPUBFUN xmlChar* XMLCALL xmlURIEscapeStr ( const xmlChar str,
const xmlChar list 
)

xmlURIEscapeStr: @str: string to escape @list: exception list string of chars not to escape

This routine escapes a string to hex, ignoring reserved characters (a-z) and the characters in the exception list.

Returns a new escaped string or NULL in case of error.

Definition at line 1672 of file uri.c.

1672  {
1673  xmlChar *ret, ch;
1674  xmlChar *temp;
1675  const xmlChar *in;
1676  int len, out;
1677 
1678  if (str == NULL)
1679  return(NULL);
1680  if (str[0] == 0)
1681  return(xmlStrdup(str));
1682  len = xmlStrlen(str);
1683  if (!(len > 0)) return(NULL);
1684 
1685  len += 20;
1686  ret = (xmlChar *) xmlMallocAtomic(len);
1687  if (ret == NULL) {
1688  xmlURIErrMemory("escaping URI value\n");
1689  return(NULL);
1690  }
1691  in = (const xmlChar *) str;
1692  out = 0;
1693  while(*in != 0) {
1694  if (len - out <= 3) {
1696  if (temp == NULL) {
1697  xmlURIErrMemory("escaping URI value\n");
1698  xmlFree(ret);
1699  return(NULL);
1700  }
1701  ret = temp;
1702  }
1703 
1704  ch = *in;
1705 
1706  if ((ch != '@') && (!IS_UNRESERVED(ch)) && (!xmlStrchr(list, ch))) {
1707  unsigned char val;
1708  ret[out++] = '%';
1709  val = ch >> 4;
1710  if (val <= 9)
1711  ret[out++] = '0' + val;
1712  else
1713  ret[out++] = 'A' + val - 0xA;
1714  val = ch & 0xF;
1715  if (val <= 9)
1716  ret[out++] = '0' + val;
1717  else
1718  ret[out++] = 'A' + val - 0xA;
1719  in++;
1720  } else {
1721  ret[out++] = *in++;
1722  }
1723 
1724  }
1725  ret[out] = 0;
1726  return(ret);
1727 }
XMLPUBVAR xmlMallocFunc xmlMallocAtomic
Definition: globals.h:248
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:422
XMLPUBFUN const xmlChar *XMLCALL xmlStrchr(const xmlChar *str, xmlChar val)
Definition: xmlstring.c:321
const WCHAR * str
GLuint GLfloat * val
Definition: glext.h:7180
#define IS_UNRESERVED(x)
Definition: uri.c:120
static FILE * out
Definition: regtests2xml.c:44
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
int ret
static xmlChar * xmlSaveUriRealloc(xmlChar *ret, int *max)
Definition: uri.c:1033
unsigned char xmlChar
Definition: xmlstring.h:28
GLenum GLsizei len
Definition: glext.h:6722
Definition: _list.h:228
GLuint in
Definition: glext.h:9616
static calc_node_t temp
Definition: rpn_ieee.c:38
static void xmlURIErrMemory(const char *extra)
Definition: uri.c:36
#define NULL
Definition: types.h:112
XMLPUBFUN xmlChar *XMLCALL xmlStrdup(const xmlChar *cur)
Definition: xmlstring.c:66

Referenced by xmlCanonicPath(), xmlURIEscape(), and xsltDocumentElem().

◆ xmlURIUnescapeString()

XMLPUBFUN char* XMLCALL xmlURIUnescapeString ( const char str,
int  len,
char target 
)

xmlURIUnescapeString: @str: the string to unescape @len: the length in bytes to unescape (or <= 0 to indicate full string) @target: optional destination buffer

Unescaping routine, but does not check that the string is an URI. The output is a direct unsigned char translation of XX values (no encoding) Note that the length of the result can only be smaller or same size as the input string.

Returns a copy of the string, but unescaped, will return NULL only in case of error

Definition at line 1614 of file uri.c.

1614  {
1615  char *ret, *out;
1616  const char *in;
1617 
1618  if (str == NULL)
1619  return(NULL);
1620  if (len <= 0) len = strlen(str);
1621  if (len < 0) return(NULL);
1622 
1623  if (target == NULL) {
1624  ret = (char *) xmlMallocAtomic(len + 1);
1625  if (ret == NULL) {
1626  xmlURIErrMemory("unescaping URI value\n");
1627  return(NULL);
1628  }
1629  } else
1630  ret = target;
1631  in = str;
1632  out = ret;
1633  while(len > 0) {
1634  if ((len > 2) && (*in == '%') && (is_hex(in[1])) && (is_hex(in[2]))) {
1635  in++;
1636  if ((*in >= '0') && (*in <= '9'))
1637  *out = (*in - '0');
1638  else if ((*in >= 'a') && (*in <= 'f'))
1639  *out = (*in - 'a') + 10;
1640  else if ((*in >= 'A') && (*in <= 'F'))
1641  *out = (*in - 'A') + 10;
1642  in++;
1643  if ((*in >= '0') && (*in <= '9'))
1644  *out = *out * 16 + (*in - '0');
1645  else if ((*in >= 'a') && (*in <= 'f'))
1646  *out = *out * 16 + (*in - 'a') + 10;
1647  else if ((*in >= 'A') && (*in <= 'F'))
1648  *out = *out * 16 + (*in - 'A') + 10;
1649  in++;
1650  len -= 3;
1651  out++;
1652  } else {
1653  *out++ = *in++;
1654  len--;
1655  }
1656  }
1657  *out = 0;
1658  return(ret);
1659 }
XMLPUBVAR xmlMallocFunc xmlMallocAtomic
Definition: globals.h:248
static int is_hex(char c)
Definition: uri.c:1591
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
const WCHAR * str
static FILE * out
Definition: regtests2xml.c:44
int ret
GLenum GLsizei len
Definition: glext.h:6722
GLuint in
Definition: glext.h:9616
static void xmlURIErrMemory(const char *extra)
Definition: uri.c:36
#define NULL
Definition: types.h:112
GLenum target
Definition: glext.h:7315

Referenced by xmlParse3986Fragment(), xmlParse3986Host(), xmlParse3986PathAbEmpty(), xmlParse3986PathAbsolute(), xmlParse3986PathNoScheme(), xmlParse3986PathRootless(), xmlParse3986Query(), and xmlParse3986Userinfo().