* xmlBuildURISafe: * @URI: the URI instance found in the document * @base: the base value * @valPtr: pointer to result URI * * 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 * * A
| 2009 | * code if URI or base are invalid. |
| 2010 | */ |
| 2011 | int |
| 2012 | xmlBuildURISafe(const xmlChar *URI, const xmlChar *base, xmlChar **valPtr) { |
| 2013 | xmlChar *val = NULL; |
| 2014 | int ret, len, indx, cur, out; |
| 2015 | xmlURIPtr ref = NULL; |
| 2016 | xmlURIPtr bas = NULL; |
| 2017 | xmlURIPtr res = NULL; |
| 2018 | |
| 2019 | if (valPtr == NULL) |
| 2020 | return(1); |
| 2021 | *valPtr = NULL; |
| 2022 | |
| 2023 | if (URI == NULL) |
| 2024 | return(1); |
| 2025 | |
| 2026 | if (base == NULL) { |
| 2027 | val = xmlStrdup(URI); |
| 2028 | if (val == NULL) |
| 2029 | return(-1); |
| 2030 | *valPtr = val; |
| 2031 | return(0); |
| 2032 | } |
| 2033 | |
| 2034 | /* |
| 2035 | * 1) The URI reference is parsed into the potential four components and |
| 2036 | * fragment identifier, as described in Section 4.3. |
| 2037 | * |
| 2038 | * NOTE that a completely empty URI is treated by modern browsers |
| 2039 | * as a reference to "." rather than as a synonym for the current |
| 2040 | * URI. Should we do that here? |
| 2041 | */ |
| 2042 | if (URI[0] != 0) |
| 2043 | ret = xmlParseURISafe((const char *) URI, &ref); |
| 2044 | else |
| 2045 | ret = 0; |
| 2046 | if (ret != 0) |
| 2047 | goto done; |
| 2048 | if ((ref != NULL) && (ref->scheme != NULL)) { |
| 2049 | /* |
| 2050 | * The URI is absolute don't modify. |
| 2051 | */ |
| 2052 | val = xmlStrdup(URI); |
| 2053 | if (val == NULL) |
| 2054 | ret = -1; |
| 2055 | goto done; |
| 2056 | } |
| 2057 | |
| 2058 | /* |
| 2059 | * If base has no scheme or authority, it is assumed to be a |
| 2060 | * filesystem path. |
| 2061 | */ |
| 2062 | if (xmlStrstr(base, BAD_CAST "://") == NULL) { |
| 2063 | xmlFreeURI(ref); |
| 2064 | return(xmlResolvePath(URI, base, valPtr)); |
| 2065 | } |
| 2066 | |
| 2067 | ret = xmlParseURISafe((const char *) base, &bas); |
| 2068 | if (ret < 0) |
no test coverage detected