diff --git a/CHANGELOG b/CHANGELOG index ea37a49f9..cda327f14 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,7 +6,9 @@ o Reduced memory consumption for some longer running scans by removing line on how long we wait and hence keep this information in memory. See http://seclists.org/nmap-dev/2008/q3/0902.html for more. [Kris] -o XML output now contains the full path to nmap.xml on Windows. [Jah] +o XML output now contains the full path to nmap.xml on Windows. The + path is converted to a file:// URL to provide better compatibility + across browsers. [Jah] o Zenmap no longer outputs XML elements and attributes that are not in the Nmap XML DTD. This was done mostly by removing things from diff --git a/NmapOps.cc b/NmapOps.cc index dd36481a2..4fca8af30 100644 --- a/NmapOps.cc +++ b/NmapOps.cc @@ -175,6 +175,21 @@ int NmapOps::TimeSinceStartMS(struct timeval *now) { return TIMEVAL_MSEC_SUBTRACT(tv, start_time); } +// Convert a filename to a file:// URL. The return value must be freed. +char *filename_to_url(const char *filename) { + std::string url(filename); + +#if WIN32 + for (std::string::iterator p = url.begin(); p != url.end(); p++) { + if (*p == '\\') + *p = '/'; + } +#endif + url = "file://" + url; + + return strdup(url.c_str()); +} + void NmapOps::Initialize() { char tmpxsl[MAXPATHLEN]; @@ -247,15 +262,20 @@ void NmapOps::Initialize() { reason = false; if (datadir) free(datadir); datadir = NULL; - if (nmap_fetchfile(tmpxsl, sizeof(tmpxsl), "nmap.xsl") != 1) { + if (xsl_stylesheet) free(xsl_stylesheet); + if (nmap_fetchfile(tmpxsl, sizeof(tmpxsl), "nmap.xsl") == 1) { + xsl_stylesheet = filename_to_url(tmpxsl); + } else { #if WIN32 - Strncpy(tmpxsl, "nmap.xsl", sizeof(tmpxsl)); + /* Use a relative URL on Windows if nmap_fetchfile failed. It won't work, + but it gives a clue that there is an nmap.xsl somewhere. */ + Strncpy(tmpxsl, "nmap.xsl", sizeof(tmpxsl)); + xsl_stylesheet = strdup(tmpxsl); #else - Snprintf(tmpxsl, sizeof(tmpxsl), "%s/nmap.xsl", NMAPDATADIR); + Snprintf(tmpxsl, sizeof(tmpxsl), "%s/nmap.xsl", NMAPDATADIR); + xsl_stylesheet = filename_to_url(tmpxsl); #endif } - if (xsl_stylesheet) free(xsl_stylesheet); - xsl_stylesheet = strdup(tmpxsl); spoof_mac_set = false; mass_dns = true; log_errors = false;