ReactOS  0.4.15-dev-3299-gbe8e5fc
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 2172 of file uri.c.

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

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

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

1020  {
1021  xmlURIPtr ret;
1022 
1023  ret = (xmlURIPtr) xmlMalloc(sizeof(xmlURI));
1024  if (ret == NULL) {
1025  xmlURIErrMemory("creating URI structure\n");
1026  return(NULL);
1027  }
1028  memset(ret, 0, sizeof(xmlURI));
1029  return(ret);
1030 }
int ret
Definition: uri.h:33
static void xmlURIErrMemory(const char *extra)
Definition: uri.c:37
#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 1387 of file uri.c.

1387  {
1388  if (uri == NULL) return;
1389 
1390  if (uri->scheme != NULL) xmlFree(uri->scheme);
1391  if (uri->server != NULL) xmlFree(uri->server);
1392  if (uri->user != NULL) xmlFree(uri->user);
1393  if (uri->path != NULL) xmlFree(uri->path);
1394  if (uri->fragment != NULL) xmlFree(uri->fragment);
1395  if (uri->opaque != NULL) xmlFree(uri->opaque);
1396  if (uri->authority != NULL) xmlFree(uri->authority);
1397  if (uri->query != NULL) xmlFree(uri->query);
1398  if (uri->query_raw != NULL) xmlFree(uri->query_raw);
1399  xmlFree(uri);
1400 }
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 1420 of file uri.c.

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

940  {
941  xmlURIPtr uri;
942  int ret;
943 
944  if (str == NULL)
945  return(NULL);
946  uri = xmlCreateURI();
947  if (uri != NULL) {
949  if (ret) {
950  xmlFreeURI(uri);
951  return(NULL);
952  }
953  }
954  return(uri);
955 }
const char * uri
Definition: sec_mgr.c:1588
const WCHAR * str
xmlURIPtr xmlCreateURI(void)
Definition: uri.c:1020
int ret
Definition: uri.h:33
void xmlFreeURI(xmlURIPtr uri)
Definition: uri.c:1387
#define NULL
Definition: types.h:112
static int xmlParse3986URIReference(xmlURIPtr uri, const char *str)
Definition: uri.c:906

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 986 of file uri.c.

986  {
987  xmlURIPtr uri;
988  int ret;
989 
990  if (str == NULL)
991  return(NULL);
992  uri = xmlCreateURI();
993  if (uri != NULL) {
994  if (raw) {
995  uri->cleanup |= 2;
996  }
998  if (ret) {
999  xmlFreeURI(uri);
1000  return(NULL);
1001  }
1002  }
1003  return(uri);
1004 }
const char * uri
Definition: sec_mgr.c:1588
const WCHAR * str
xmlURIPtr xmlCreateURI(void)
Definition: uri.c:1020
int ret
int xmlParseURIReference(xmlURIPtr uri, const char *str)
Definition: uri.c:970
Definition: uri.h:33
void xmlFreeURI(xmlURIPtr uri)
Definition: uri.c:1387
#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 970 of file uri.c.

970  {
971  return(xmlParse3986URIReference(uri, str));
972 }
const char * uri
Definition: sec_mgr.c:1588
const WCHAR * str
static int xmlParse3986URIReference(xmlURIPtr uri, const char *str)
Definition: uri.c:906

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 2520 of file uri.c.

2521 {
2522  xmlURIPtr uri;
2523  xmlURI temp;
2524  xmlChar *ret, *cal;
2525 
2526  if (path == NULL)
2527  return(NULL);
2528 
2529  if ((uri = xmlParseURI((const char *) path)) != NULL) {
2530  xmlFreeURI(uri);
2531  return xmlStrdup(path);
2532  }
2533  cal = xmlCanonicPath(path);
2534  if (cal == NULL)
2535  return(NULL);
2536 #if defined(_WIN32) && !defined(__CYGWIN__)
2537  /* xmlCanonicPath can return an URI on Windows (is that the intended behaviour?)
2538  If 'cal' is a valid URI already then we are done here, as continuing would make
2539  it invalid. */
2540  if ((uri = xmlParseURI((const char *) cal)) != NULL) {
2541  xmlFreeURI(uri);
2542  return cal;
2543  }
2544  /* 'cal' can contain a relative path with backslashes. If that is processed
2545  by xmlSaveURI, they will be escaped and the external entity loader machinery
2546  will fail. So convert them to slashes. Misuse 'ret' for walking. */
2547  ret = cal;
2548  while (*ret != '\0') {
2549  if (*ret == '\\')
2550  *ret = '/';
2551  ret++;
2552  }
2553 #endif
2554  memset(&temp, 0, sizeof(temp));
2555  temp.path = (char *) cal;
2556  ret = xmlSaveUri(&temp);
2557  xmlFree(cal);
2558  return(ret);
2559 }
xmlChar * xmlSaveUri(xmlURIPtr uri)
Definition: uri.c:1066
const char * uri
Definition: sec_mgr.c:1588
xmlChar * xmlCanonicPath(const xmlChar *path)
Definition: uri.c:2379
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:940
static calc_node_t temp
Definition: rpn_ieee.c:38
void xmlFreeURI(xmlURIPtr uri)
Definition: uri.c:1387
#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 1340 of file uri.c.

1340  {
1341  xmlChar *out;
1342 
1343  out = xmlSaveUri(uri);
1344  if (out != NULL) {
1345  fprintf(stream, "%s", (char *) out);
1346  xmlFree(out);
1347  }
1348 }
xmlChar * xmlSaveUri(xmlURIPtr uri)
Definition: uri.c:1066
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 1066 of file uri.c.

1066  {
1067  xmlChar *ret = NULL;
1068  xmlChar *temp;
1069  const char *p;
1070  int len;
1071  int max;
1072 
1073  if (uri == NULL) return(NULL);
1074 
1075 
1076  max = 80;
1077  ret = (xmlChar *) xmlMallocAtomic((max + 1) * sizeof(xmlChar));
1078  if (ret == NULL) {
1079  xmlURIErrMemory("saving URI\n");
1080  return(NULL);
1081  }
1082  len = 0;
1083 
1084  if (uri->scheme != NULL) {
1085  p = uri->scheme;
1086  while (*p != 0) {
1087  if (len >= max) {
1089  if (temp == NULL) goto mem_error;
1090  ret = temp;
1091  }
1092  ret[len++] = *p++;
1093  }
1094  if (len >= max) {
1096  if (temp == NULL) goto mem_error;
1097  ret = temp;
1098  }
1099  ret[len++] = ':';
1100  }
1101  if (uri->opaque != NULL) {
1102  p = uri->opaque;
1103  while (*p != 0) {
1104  if (len + 3 >= max) {
1106  if (temp == NULL) goto mem_error;
1107  ret = temp;
1108  }
1109  if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p)))
1110  ret[len++] = *p++;
1111  else {
1112  int val = *(unsigned char *)p++;
1113  int hi = val / 0x10, lo = val % 0x10;
1114  ret[len++] = '%';
1115  ret[len++] = hi + (hi > 9? 'A'-10 : '0');
1116  ret[len++] = lo + (lo > 9? 'A'-10 : '0');
1117  }
1118  }
1119  } else {
1120  if ((uri->server != NULL) || (uri->port == -1)) {
1121  if (len + 3 >= max) {
1123  if (temp == NULL) goto mem_error;
1124  ret = temp;
1125  }
1126  ret[len++] = '/';
1127  ret[len++] = '/';
1128  if (uri->user != NULL) {
1129  p = uri->user;
1130  while (*p != 0) {
1131  if (len + 3 >= max) {
1133  if (temp == NULL) goto mem_error;
1134  ret = temp;
1135  }
1136  if ((IS_UNRESERVED(*(p))) ||
1137  ((*(p) == ';')) || ((*(p) == ':')) ||
1138  ((*(p) == '&')) || ((*(p) == '=')) ||
1139  ((*(p) == '+')) || ((*(p) == '$')) ||
1140  ((*(p) == ',')))
1141  ret[len++] = *p++;
1142  else {
1143  int val = *(unsigned char *)p++;
1144  int hi = val / 0x10, lo = val % 0x10;
1145  ret[len++] = '%';
1146  ret[len++] = hi + (hi > 9? 'A'-10 : '0');
1147  ret[len++] = lo + (lo > 9? 'A'-10 : '0');
1148  }
1149  }
1150  if (len + 3 >= max) {
1152  if (temp == NULL) goto mem_error;
1153  ret = temp;
1154  }
1155  ret[len++] = '@';
1156  }
1157  if (uri->server != NULL) {
1158  p = uri->server;
1159  while (*p != 0) {
1160  if (len >= max) {
1162  if (temp == NULL) goto mem_error;
1163  ret = temp;
1164  }
1165  ret[len++] = *p++;
1166  }
1167  if (uri->port > 0) {
1168  if (len + 10 >= max) {
1170  if (temp == NULL) goto mem_error;
1171  ret = temp;
1172  }
1173  len += snprintf((char *) &ret[len], max - len, ":%d", uri->port);
1174  }
1175  }
1176  } else if (uri->authority != NULL) {
1177  if (len + 3 >= max) {
1179  if (temp == NULL) goto mem_error;
1180  ret = temp;
1181  }
1182  ret[len++] = '/';
1183  ret[len++] = '/';
1184  p = uri->authority;
1185  while (*p != 0) {
1186  if (len + 3 >= max) {
1188  if (temp == NULL) goto mem_error;
1189  ret = temp;
1190  }
1191  if ((IS_UNRESERVED(*(p))) ||
1192  ((*(p) == '$')) || ((*(p) == ',')) || ((*(p) == ';')) ||
1193  ((*(p) == ':')) || ((*(p) == '@')) || ((*(p) == '&')) ||
1194  ((*(p) == '=')) || ((*(p) == '+')))
1195  ret[len++] = *p++;
1196  else {
1197  int val = *(unsigned char *)p++;
1198  int hi = val / 0x10, lo = val % 0x10;
1199  ret[len++] = '%';
1200  ret[len++] = hi + (hi > 9? 'A'-10 : '0');
1201  ret[len++] = lo + (lo > 9? 'A'-10 : '0');
1202  }
1203  }
1204  } else if (uri->scheme != NULL) {
1205  if (len + 3 >= max) {
1207  if (temp == NULL) goto mem_error;
1208  ret = temp;
1209  }
1210  }
1211  if (uri->path != NULL) {
1212  p = uri->path;
1213  /*
1214  * the colon in file:///d: should not be escaped or
1215  * Windows accesses fail later.
1216  */
1217  if ((uri->scheme != NULL) &&
1218  (p[0] == '/') &&
1219  (((p[1] >= 'a') && (p[1] <= 'z')) ||
1220  ((p[1] >= 'A') && (p[1] <= 'Z'))) &&
1221  (p[2] == ':') &&
1222  (xmlStrEqual(BAD_CAST uri->scheme, BAD_CAST "file"))) {
1223  if (len + 3 >= max) {
1225  if (temp == NULL) goto mem_error;
1226  ret = temp;
1227  }
1228  ret[len++] = *p++;
1229  ret[len++] = *p++;
1230  ret[len++] = *p++;
1231  }
1232  while (*p != 0) {
1233  if (len + 3 >= max) {
1235  if (temp == NULL) goto mem_error;
1236  ret = temp;
1237  }
1238  if ((IS_UNRESERVED(*(p))) || ((*(p) == '/')) ||
1239  ((*(p) == ';')) || ((*(p) == '@')) || ((*(p) == '&')) ||
1240  ((*(p) == '=')) || ((*(p) == '+')) || ((*(p) == '$')) ||
1241  ((*(p) == ',')))
1242  ret[len++] = *p++;
1243  else {
1244  int val = *(unsigned char *)p++;
1245  int hi = val / 0x10, lo = val % 0x10;
1246  ret[len++] = '%';
1247  ret[len++] = hi + (hi > 9? 'A'-10 : '0');
1248  ret[len++] = lo + (lo > 9? 'A'-10 : '0');
1249  }
1250  }
1251  }
1252  if (uri->query_raw != NULL) {
1253  if (len + 1 >= max) {
1255  if (temp == NULL) goto mem_error;
1256  ret = temp;
1257  }
1258  ret[len++] = '?';
1259  p = uri->query_raw;
1260  while (*p != 0) {
1261  if (len + 1 >= max) {
1263  if (temp == NULL) goto mem_error;
1264  ret = temp;
1265  }
1266  ret[len++] = *p++;
1267  }
1268  } else if (uri->query != NULL) {
1269  if (len + 3 >= max) {
1271  if (temp == NULL) goto mem_error;
1272  ret = temp;
1273  }
1274  ret[len++] = '?';
1275  p = uri->query;
1276  while (*p != 0) {
1277  if (len + 3 >= max) {
1279  if (temp == NULL) goto mem_error;
1280  ret = temp;
1281  }
1282  if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))
1283  ret[len++] = *p++;
1284  else {
1285  int val = *(unsigned char *)p++;
1286  int hi = val / 0x10, lo = val % 0x10;
1287  ret[len++] = '%';
1288  ret[len++] = hi + (hi > 9? 'A'-10 : '0');
1289  ret[len++] = lo + (lo > 9? 'A'-10 : '0');
1290  }
1291  }
1292  }
1293  }
1294  if (uri->fragment != NULL) {
1295  if (len + 3 >= max) {
1297  if (temp == NULL) goto mem_error;
1298  ret = temp;
1299  }
1300  ret[len++] = '#';
1301  p = uri->fragment;
1302  while (*p != 0) {
1303  if (len + 3 >= max) {
1305  if (temp == NULL) goto mem_error;
1306  ret = temp;
1307  }
1308  if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))
1309  ret[len++] = *p++;
1310  else {
1311  int val = *(unsigned char *)p++;
1312  int hi = val / 0x10, lo = val % 0x10;
1313  ret[len++] = '%';
1314  ret[len++] = hi + (hi > 9? 'A'-10 : '0');
1315  ret[len++] = lo + (lo > 9? 'A'-10 : '0');
1316  }
1317  }
1318  }
1319  if (len >= max) {
1321  if (temp == NULL) goto mem_error;
1322  ret = temp;
1323  }
1324  ret[len] = 0;
1325  return(ret);
1326 
1327 mem_error:
1328  xmlFree(ret);
1329  return(NULL);
1330 }
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:121
#define IS_RESERVED(x)
Definition: uri.c:112
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
int ret
static xmlChar * xmlSaveUriRealloc(xmlChar *ret, int *max)
Definition: uri.c:1039
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:37
#define NULL
Definition: types.h:112
XMLPUBFUN int XMLCALL xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:159
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 1751 of file uri.c.

1752 {
1753  xmlChar *ret, *segment = NULL;
1754  xmlURIPtr uri;
1755  int ret2;
1756 
1757  if (str == NULL)
1758  return (NULL);
1759 
1760  uri = xmlCreateURI();
1761  if (uri != NULL) {
1762  /*
1763  * Allow escaping errors in the unescaped form
1764  */
1765  uri->cleanup = 1;
1766  ret2 = xmlParseURIReference(uri, (const char *)str);
1767  if (ret2) {
1768  xmlFreeURI(uri);
1769  return (NULL);
1770  }
1771  }
1772 
1773  if (!uri)
1774  return NULL;
1775 
1776  ret = NULL;
1777 
1778 #define NULLCHK(p) if(!p) { \
1779  xmlURIErrMemory("escaping URI value\n"); \
1780  xmlFreeURI(uri); \
1781  xmlFree(ret); \
1782  return NULL; } \
1783 
1784  if (uri->scheme) {
1785  segment = xmlURIEscapeStr(BAD_CAST uri->scheme, BAD_CAST "+-.");
1786  NULLCHK(segment)
1787  ret = xmlStrcat(ret, segment);
1788  ret = xmlStrcat(ret, BAD_CAST ":");
1789  xmlFree(segment);
1790  }
1791 
1792  if (uri->authority) {
1793  segment =
1794  xmlURIEscapeStr(BAD_CAST uri->authority, BAD_CAST "/?;:@");
1795  NULLCHK(segment)
1796  ret = xmlStrcat(ret, BAD_CAST "//");
1797  ret = xmlStrcat(ret, segment);
1798  xmlFree(segment);
1799  }
1800 
1801  if (uri->user) {
1802  segment = xmlURIEscapeStr(BAD_CAST uri->user, BAD_CAST ";:&=+$,");
1803  NULLCHK(segment)
1804  ret = xmlStrcat(ret,BAD_CAST "//");
1805  ret = xmlStrcat(ret, segment);
1806  ret = xmlStrcat(ret, BAD_CAST "@");
1807  xmlFree(segment);
1808  }
1809 
1810  if (uri->server) {
1811  segment = xmlURIEscapeStr(BAD_CAST uri->server, BAD_CAST "/?;:@");
1812  NULLCHK(segment)
1813  if (uri->user == NULL)
1814  ret = xmlStrcat(ret, BAD_CAST "//");
1815  ret = xmlStrcat(ret, segment);
1816  xmlFree(segment);
1817  }
1818 
1819  if (uri->port) {
1820  xmlChar port[10];
1821 
1822  snprintf((char *) port, 10, "%d", uri->port);
1823  ret = xmlStrcat(ret, BAD_CAST ":");
1824  ret = xmlStrcat(ret, port);
1825  }
1826 
1827  if (uri->path) {
1828  segment =
1829  xmlURIEscapeStr(BAD_CAST uri->path, BAD_CAST ":@&=+$,/?;");
1830  NULLCHK(segment)
1831  ret = xmlStrcat(ret, segment);
1832  xmlFree(segment);
1833  }
1834 
1835  if (uri->query_raw) {
1836  ret = xmlStrcat(ret, BAD_CAST "?");
1837  ret = xmlStrcat(ret, BAD_CAST uri->query_raw);
1838  }
1839  else if (uri->query) {
1840  segment =
1841  xmlURIEscapeStr(BAD_CAST uri->query, BAD_CAST ";/?:@&=+,$");
1842  NULLCHK(segment)
1843  ret = xmlStrcat(ret, BAD_CAST "?");
1844  ret = xmlStrcat(ret, segment);
1845  xmlFree(segment);
1846  }
1847 
1848  if (uri->opaque) {
1849  segment = xmlURIEscapeStr(BAD_CAST uri->opaque, BAD_CAST "");
1850  NULLCHK(segment)
1851  ret = xmlStrcat(ret, segment);
1852  xmlFree(segment);
1853  }
1854 
1855  if (uri->fragment) {
1856  segment = xmlURIEscapeStr(BAD_CAST uri->fragment, BAD_CAST "#");
1857  NULLCHK(segment)
1858  ret = xmlStrcat(ret, BAD_CAST "#");
1859  ret = xmlStrcat(ret, segment);
1860  xmlFree(segment);
1861  }
1862 
1863  xmlFreeURI(uri);
1864 #undef NULLCHK
1865 
1866  return (ret);
1867 }
xmlChar * xmlURIEscapeStr(const xmlChar *str, const xmlChar *list)
Definition: uri.c:1678
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:529
const WCHAR * str
#define BAD_CAST
Definition: xmlstring.h:35
xmlURIPtr xmlCreateURI(void)
Definition: uri.c:1020
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:970
Definition: uri.h:33
void xmlFreeURI(xmlURIPtr uri)
Definition: uri.c:1387
#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 1678 of file uri.c.

1678  {
1679  xmlChar *ret, ch;
1680  xmlChar *temp;
1681  const xmlChar *in;
1682  int len, out;
1683 
1684  if (str == NULL)
1685  return(NULL);
1686  if (str[0] == 0)
1687  return(xmlStrdup(str));
1688  len = xmlStrlen(str);
1689  if (!(len > 0)) return(NULL);
1690 
1691  len += 20;
1692  ret = (xmlChar *) xmlMallocAtomic(len);
1693  if (ret == NULL) {
1694  xmlURIErrMemory("escaping URI value\n");
1695  return(NULL);
1696  }
1697  in = (const xmlChar *) str;
1698  out = 0;
1699  while(*in != 0) {
1700  if (len - out <= 3) {
1702  if (temp == NULL) {
1703  xmlURIErrMemory("escaping URI value\n");
1704  xmlFree(ret);
1705  return(NULL);
1706  }
1707  ret = temp;
1708  }
1709 
1710  ch = *in;
1711 
1712  if ((ch != '@') && (!IS_UNRESERVED(ch)) && (!xmlStrchr(list, ch))) {
1713  unsigned char val;
1714  ret[out++] = '%';
1715  val = ch >> 4;
1716  if (val <= 9)
1717  ret[out++] = '0' + val;
1718  else
1719  ret[out++] = 'A' + val - 0xA;
1720  val = ch & 0xF;
1721  if (val <= 9)
1722  ret[out++] = '0' + val;
1723  else
1724  ret[out++] = 'A' + val - 0xA;
1725  in++;
1726  } else {
1727  ret[out++] = *in++;
1728  }
1729 
1730  }
1731  ret[out] = 0;
1732  return(ret);
1733 }
XMLPUBVAR xmlMallocFunc xmlMallocAtomic
Definition: globals.h:248
XMLPUBFUN int XMLCALL xmlStrlen(const xmlChar *str)
Definition: xmlstring.c:425
XMLPUBFUN const xmlChar *XMLCALL xmlStrchr(const xmlChar *str, xmlChar val)
Definition: xmlstring.c:324
const WCHAR * str
GLuint GLfloat * val
Definition: glext.h:7180
#define IS_UNRESERVED(x)
Definition: uri.c:121
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:1039
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:37
#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 1620 of file uri.c.

1620  {
1621  char *ret, *out;
1622  const char *in;
1623 
1624  if (str == NULL)
1625  return(NULL);
1626  if (len <= 0) len = strlen(str);
1627  if (len < 0) return(NULL);
1628 
1629  if (target == NULL) {
1630  ret = (char *) xmlMallocAtomic(len + 1);
1631  if (ret == NULL) {
1632  xmlURIErrMemory("unescaping URI value\n");
1633  return(NULL);
1634  }
1635  } else
1636  ret = target;
1637  in = str;
1638  out = ret;
1639  while(len > 0) {
1640  if ((len > 2) && (*in == '%') && (is_hex(in[1])) && (is_hex(in[2]))) {
1641  in++;
1642  if ((*in >= '0') && (*in <= '9'))
1643  *out = (*in - '0');
1644  else if ((*in >= 'a') && (*in <= 'f'))
1645  *out = (*in - 'a') + 10;
1646  else if ((*in >= 'A') && (*in <= 'F'))
1647  *out = (*in - 'A') + 10;
1648  in++;
1649  if ((*in >= '0') && (*in <= '9'))
1650  *out = *out * 16 + (*in - '0');
1651  else if ((*in >= 'a') && (*in <= 'f'))
1652  *out = *out * 16 + (*in - 'a') + 10;
1653  else if ((*in >= 'A') && (*in <= 'F'))
1654  *out = *out * 16 + (*in - 'A') + 10;
1655  in++;
1656  len -= 3;
1657  out++;
1658  } else {
1659  *out++ = *in++;
1660  len--;
1661  }
1662  }
1663  *out = 0;
1664  return(ret);
1665 }
XMLPUBVAR xmlMallocFunc xmlMallocAtomic
Definition: globals.h:248
static int is_hex(char c)
Definition: uri.c:1597
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:37
#define NULL
Definition: types.h:112
GLenum target
Definition: glext.h:7315

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