aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Uhrig <[email protected]>2005-03-28 17:16:46 +0000
committerStefan Uhrig <[email protected]>2005-03-28 17:16:46 +0000
commit0b37c6d09cd7c3f0b5bb9649531c0ef7b3850f73 (patch)
tree0decc2a6aed69cbad85d8d659222812b4726d17f
parentAdded toUpper() function (diff)
downloadvmime-0b37c6d09cd7c3f0b5bb9649531c0ef7b3850f73.tar.gz
vmime-0b37c6d09cd7c3f0b5bb9649531c0ef7b3850f73.zip
Modified isValidPathComponent() to accept drives as first component.
-rw-r--r--src/platforms/windows/windowsFile.cpp36
-rw-r--r--vmime/platforms/windows/windowsFile.hpp2
2 files changed, 28 insertions, 10 deletions
diff --git a/src/platforms/windows/windowsFile.cpp b/src/platforms/windows/windowsFile.cpp
index f90b7ea1..2cc7c289 100644
--- a/src/platforms/windows/windowsFile.cpp
+++ b/src/platforms/windows/windowsFile.cpp
@@ -23,6 +23,7 @@
#include <string.h>
#include "vmime/exception.hpp"
+#include "vmime/utility/stringUtils.hpp"
#if VMIME_HAVE_FILESYSTEM_FEATURES
@@ -89,11 +90,25 @@ const vmime::string windowsFileSystemFactory::pathToStringImpl(const vmime::util
return (native);
}
-
const bool windowsFileSystemFactory::isValidPathComponent(const vmime::utility::file::path::component& comp) const
{
+ return isValidPathComponent(comp, false);
+}
+
+const bool windowsFileSystemFactory::isValidPathComponent(
+ const vmime::utility::file::path::component& comp,
+ bool firstComponent) const
+{
const string& buffer = comp.getBuffer();
+ // If first component, check if component is a drive
+ if (firstComponent && (buffer.length() == 2) && (buffer[1] == ':'))
+ {
+ char drive = tolower(buffer[0]);
+ if ((drive >= 'a') && (drive <= 'z'))
+ return true;
+ }
+
// Check for invalid characters
for (string::size_type i = 0 ; i < buffer.length() ; ++i)
{
@@ -115,26 +130,27 @@ const bool windowsFileSystemFactory::isValidPathComponent(const vmime::utility::
}
}
+ string upperBuffer = vmime::utility::stringUtils::toUpper(buffer);
+
// Check for reserved names
- if (buffer.length() == 3)
+ if (upperBuffer.length() == 3)
{
- if (buffer == "CON" || buffer == "PRN" || buffer == "AUX" || buffer == "NUL")
+ if (upperBuffer == "CON" || buffer == "PRN" || buffer == "AUX" || buffer == "NUL")
return false;
}
- else if (buffer.length() == 4)
+ else if (upperBuffer.length() == 4)
{
- if (buffer[0] == 'C' && buffer[1] == 'O' && // COM1-COM9
- buffer[2] == 'M' && (buffer[3] >= '0' && buffer[3] <= '9'))
+ if ((upperBuffer.substr(0, 3) == "COM") && // COM0 to COM9
+ (upperBuffer[3] >= '0') && (upperBuffer[3] <= '9'))
{
return false;
}
- else if (buffer[0] == 'L' && buffer[1] == 'P' && // LPT1-LPT9
- buffer[2] == 'T' && (buffer[3] >= '0' && buffer[3] <= '9'))
+ else if ((upperBuffer.substr(0, 3) == "LPT") && // LPT0 to LPT9
+ (upperBuffer[3] >= '0') && (upperBuffer[3] <= '9'))
{
return false;
}
}
-
return true;
}
@@ -143,7 +159,7 @@ const bool windowsFileSystemFactory::isValidPath(const vmime::utility::file::pat
{
for (int i = 0 ; i < path.getSize() ; ++i)
{
- if (!isValidPathComponent(path[i]))
+ if (!isValidPathComponent(path[i], (i==0)))
return false;
}
diff --git a/vmime/platforms/windows/windowsFile.hpp b/vmime/platforms/windows/windowsFile.hpp
index 885a954b..15465198 100644
--- a/vmime/platforms/windows/windowsFile.hpp
+++ b/vmime/platforms/windows/windowsFile.hpp
@@ -46,6 +46,8 @@ public:
static const vmime::string pathToStringImpl(const vmime::utility::file::path& path);
const bool isValidPathComponent(const vmime::utility::file::path::component& comp) const;
+ const bool isValidPathComponent(const vmime::utility::file::path::component& comp,
+ bool firstComponent) const;
const bool isValidPath(const vmime::utility::file::path& path) const;
static void reportError(const vmime::utility::path& path, const int err);