static String _xmlreader_get_valid_file_path(const char *source) { int isFileUri = 0; xmlURI *uri = xmlCreateURI(); xmlChar *escsource = xmlURIEscapeStr((xmlChar*)source, (xmlChar*)":"); xmlParseURIReference(uri, (char*)escsource); xmlFree(escsource); if (uri->scheme != NULL) { /* absolute file uris - libxml only supports localhost or empty host */ if (strncasecmp(source, "file:///",8) == 0) { isFileUri = 1; source += 7; } else if (strncasecmp(source, "file://localhost/",17) == 0) { isFileUri = 1; source += 16; } } String file_dest = String(source, CopyString); if ((uri->scheme == NULL || isFileUri)) { file_dest = File::TranslatePath(file_dest); } xmlFreeURI(uri); return file_dest; }
std::string XdmfSystemUtils::getRealPath(const std::string & path) { xmlURIPtr ref = NULL; ref = xmlCreateURI(); xmlParseURIReference(ref, path.c_str()); #ifdef WIN32 char realPath[_MAX_PATH]; _fullpath(realPath, path.c_str(), _MAX_PATH); xmlFreeURI(ref); return realPath; #else char realPath[PATH_MAX]; char *rp = realpath(ref->path, realPath); if (rp == 0) { //indicates a failure that we are silently ignoring //TODO: realPath is now undefined but in practice //ends up path.c_str() rp = realPath; } xmlFreeURI(ref); return std::string(rp); #endif }
std::string XdmfSystemUtils::getRealPath(const std::string & path) { xmlURIPtr ref = NULL; ref = xmlCreateURI(); xmlParseURIReference(ref, path.c_str()); char realPath[PATH_MAX]; char *rp = realpath(ref->path, realPath); xmlFreeURI(ref); return path; }
static void handleURI(const char *str) { int ret; xmlURIPtr uri; xmlChar *res = NULL, *parsed = NULL; uri = xmlCreateURI(); if (base == NULL) { ret = xmlParseURIReference(uri, str); if (ret != 0) printf("%s : error %d\n", str, ret); else { if (debug) { if (uri->scheme) printf("scheme: %s\n", uri->scheme); if (uri->opaque) printf("opaque: %s\n", uri->opaque); if (uri->authority) printf("authority: %s\n", uri->authority); if (uri->server) printf("server: %s\n", uri->server); if (uri->user) printf("user: %s\n", uri->user); if (uri->port != 0) printf("port: %d\n", uri->port); if (uri->path) printf("path: %s\n", uri->path); if (uri->query) printf("query: %s\n", uri->query); if (uri->fragment) printf("fragment: %s\n", uri->fragment); if (uri->query_raw) printf("query_raw: %s\n", uri->query_raw); if (uri->cleanup != 0) printf("cleanup\n"); } xmlNormalizeURIPath(uri->path); if (escape != 0) { parsed = xmlSaveUri(uri); res = xmlURIEscape(parsed); printf("%s\n", (char *) res); } else { xmlPrintURI(stdout, uri); printf("\n"); } } } else { res = xmlBuildURI((xmlChar *)str, (xmlChar *) base); if (res != NULL) { printf("%s\n", (char *) res); } else printf("::ERROR::\n"); } if (res != NULL) xmlFree(res); if (parsed != NULL) xmlFree(parsed); xmlFreeURI(uri); }
/* _xmlreader_get_valid_file_path and _xmlreader_get_relaxNG should be made a common function in libxml extension as code is common to a few xml extensions */ char *_xmlreader_get_valid_file_path(char *source, char *resolved_path, int resolved_path_len ) { xmlURI *uri; xmlChar *escsource; char *file_dest; int isFileUri = 0; uri = xmlCreateURI(); escsource = xmlURIEscapeStr((xmlChar *)source, (xmlChar *)":"); xmlParseURIReference(uri, (const char *)escsource); xmlFree(escsource); if (uri->scheme != NULL) { /* absolute file uris - libxml only supports localhost or empty host */ if (strncasecmp(source, "file:///",8) == 0) { isFileUri = 1; #ifdef PHP_WIN32 source += 8; #else source += 7; #endif } else if (strncasecmp(source, "file://localhost/",17) == 0) { isFileUri = 1; #ifdef PHP_WIN32 source += 17; #else source += 16; #endif } } file_dest = source; if ((uri->scheme == NULL || isFileUri)) { if (!VCWD_REALPATH(source, resolved_path) && !expand_filepath(source, resolved_path)) { xmlFreeURI(uri); return NULL; } file_dest = resolved_path; } xmlFreeURI(uri); return file_dest; }