mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-31 14:39:53 +01:00
Merge branch 'poco-1.8.2' of https://github.com/pocoproject/poco into poco-1.8.2
This commit is contained in:
commit
260aee9b04
@ -282,16 +282,44 @@ public:
|
||||
/// On Unix systems, this is the colon ':'. On Windows systems,
|
||||
/// this is the semicolon ';'. On OpenVMS systems, this is the
|
||||
/// comma ','.
|
||||
|
||||
|
||||
static std::string current();
|
||||
/// Returns the current working directory.
|
||||
|
||||
static std::string home();
|
||||
/// Returns the user's home directory.
|
||||
|
||||
|
||||
static std::string configHome();
|
||||
/// Returns the user's config directory.
|
||||
///
|
||||
/// On Unix systems, this is the '~/.config/'. On Windows systems,
|
||||
/// this is '%APPDATA%'.
|
||||
|
||||
static std::string dataHome();
|
||||
/// Returns the user's data directory.
|
||||
///
|
||||
/// On Unix systems, this is the '~/.local/share/'. On Windows systems,
|
||||
/// this is '%APPDATA%'.
|
||||
|
||||
static std::string tempHome();
|
||||
/// Returns the user's temp directory.
|
||||
///
|
||||
/// On Unix systems, this is the '~/.local/temp/'.
|
||||
|
||||
static std::string cacheHome();
|
||||
/// Returns the user's cache directory.
|
||||
///
|
||||
/// On Unix systems, this is the '~/.cache/'. On Windows systems,
|
||||
/// this is '%APPDATA%'.
|
||||
|
||||
static std::string temp();
|
||||
/// Returns the temporary directory.
|
||||
|
||||
static std::string config();
|
||||
/// Returns the systemwide config directory.
|
||||
///
|
||||
/// On Unix systems, this is the '/etc/'.
|
||||
|
||||
static std::string null();
|
||||
/// Returns the name of the null device.
|
||||
|
||||
|
@ -30,7 +30,12 @@ class PathImpl
|
||||
public:
|
||||
static std::string currentImpl();
|
||||
static std::string homeImpl();
|
||||
static std::string configHomeImpl();
|
||||
static std::string dataHomeImpl();
|
||||
static std::string tempHomeImpl();
|
||||
static std::string cacheHomeImpl();
|
||||
static std::string tempImpl();
|
||||
static std::string configImpl();
|
||||
static std::string nullImpl();
|
||||
static std::string expandImpl(const std::string& path);
|
||||
static void listRootsImpl(std::vector<std::string>& roots);
|
||||
|
@ -30,7 +30,12 @@ class Foundation_API PathImpl
|
||||
public:
|
||||
static std::string currentImpl();
|
||||
static std::string homeImpl();
|
||||
static std::string configHomeImpl();
|
||||
static std::string dataHomeImpl();
|
||||
static std::string cacheHomeImpl();
|
||||
static std::string tempHomeImpl();
|
||||
static std::string tempImpl();
|
||||
static std::string configImpl();
|
||||
static std::string nullImpl();
|
||||
static std::string systemImpl();
|
||||
static std::string expandImpl(const std::string& path);
|
||||
|
@ -30,7 +30,12 @@ class Foundation_API PathImpl
|
||||
public:
|
||||
static std::string currentImpl();
|
||||
static std::string homeImpl();
|
||||
static std::string configHomeImpl();
|
||||
static std::string dataHomeImpl();
|
||||
static std::string cacheHomeImpl();
|
||||
static std::string tempHomeImpl();
|
||||
static std::string tempImpl();
|
||||
static std::string configImpl();
|
||||
static std::string nullImpl();
|
||||
static std::string systemImpl();
|
||||
static std::string expandImpl(const std::string& path);
|
||||
|
@ -33,7 +33,6 @@ public:
|
||||
static std::string configHomeImpl();
|
||||
static std::string dataHomeImpl();
|
||||
static std::string cacheHomeImpl();
|
||||
static std::string tempHomeImpl();
|
||||
static std::string tempImpl();
|
||||
static std::string configImpl();
|
||||
static std::string nullImpl();
|
||||
|
@ -57,13 +57,17 @@ struct Foundation_API UTF8
|
||||
/// Remove the UTF-8 Byte Order Mark sequence (0xEF, 0xBB, 0xBF)
|
||||
/// from the beginning of the string, if it's there.
|
||||
|
||||
static std::string escape(const std::string& s);
|
||||
static std::string escape(const std::string& s, bool strictJSON = false);
|
||||
/// Escapes a string. Special characters like tab, backslash, ... are
|
||||
/// escaped. Unicode characters are escaped to \uxxxx.
|
||||
/// If strictJSON is true, \a and \v will be escaped to \\u0007 and \\u000B
|
||||
/// instead of \\a and \\v for strict JSON conformance.
|
||||
|
||||
static std::string escape(const std::string::const_iterator& begin, const std::string::const_iterator& end);
|
||||
static std::string escape(const std::string::const_iterator& begin, const std::string::const_iterator& end, bool strictJSON = false);
|
||||
/// Escapes a string. Special characters like tab, backslash, ... are
|
||||
/// escaped. Unicode characters are escaped to \uxxxx.
|
||||
/// If strictJSON is true, \a and \v will be escaped to \\u0007 and \\u000B
|
||||
/// instead of \\a and \\v for strict JSON conformance.
|
||||
|
||||
static std::string unescape(const std::string& s);
|
||||
/// Creates an UTF8 string from a string that contains escaped characters.
|
||||
|
@ -42,7 +42,7 @@ void writeString(const std::string &value, T& obj, typename WriteFunc<T, S>::Typ
|
||||
if(wrap) (obj.*write)("\"", 1);
|
||||
if(escapeAllUnicode)
|
||||
{
|
||||
std::string str = Poco::UTF8::escape(value.begin(), value.end());
|
||||
std::string str = Poco::UTF8::escape(value.begin(), value.end(), true);
|
||||
(obj.*write)(str.c_str(), str.size());
|
||||
}
|
||||
else
|
||||
@ -52,7 +52,7 @@ void writeString(const std::string &value, T& obj, typename WriteFunc<T, S>::Typ
|
||||
// Forward slash isn't strictly required by JSON spec, but some parsers expect it
|
||||
if((*it >= 0 && *it <= 31) || (*it == '"') || (*it == '\\') || (*it == '/'))
|
||||
{
|
||||
std::string str = Poco::UTF8::escape(it, it + 1);
|
||||
std::string str = Poco::UTF8::escape(it, it + 1, true);
|
||||
(obj.*write)(str.c_str(), str.size());
|
||||
}else (obj.*write)(&(*it), 1);
|
||||
}
|
||||
|
@ -569,12 +569,61 @@ std::string Path::home()
|
||||
}
|
||||
|
||||
|
||||
std::string Path::configHome()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_WINDOWS)
|
||||
return PathImpl::configHomeImpl();
|
||||
#else
|
||||
return PathImpl::homeImpl();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string Path::dataHome()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_WINDOWS)
|
||||
return PathImpl::dataHomeImpl();
|
||||
#else
|
||||
return PathImpl::homeImpl();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string Path::tempHome()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_WINDOWS)
|
||||
return PathImpl::tempHomeImpl();
|
||||
#else
|
||||
return PathImpl::tempImpl();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string Path::cacheHome()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_WINDOWS)
|
||||
return PathImpl::cacheHomeImpl();
|
||||
#else
|
||||
return PathImpl::homeImpl();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string Path::temp()
|
||||
{
|
||||
return PathImpl::tempImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string Path::config()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_WINDOWS)
|
||||
return PathImpl::configImpl();
|
||||
#else
|
||||
return PathImpl::currentImpl();
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string Path::null()
|
||||
{
|
||||
return PathImpl::nullImpl();
|
||||
|
@ -74,6 +74,82 @@ std::string PathImpl::homeImpl()
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::configHomeImpl()
|
||||
{
|
||||
#if defined(POCO_VXWORKS)
|
||||
return PathImpl::homeImpl();
|
||||
#else
|
||||
std::string path = PathImpl::homeImpl();
|
||||
std::string::size_type n = path.size();
|
||||
if (n > 0 && path[n - 1] == '/')
|
||||
#if POCO_OS == POCO_OS_MAC_OS_X
|
||||
path.append("Library/Preferences/");
|
||||
#else
|
||||
path.append(".config/");
|
||||
#endif
|
||||
|
||||
return path;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::dataHomeImpl()
|
||||
{
|
||||
#if defined(POCO_VXWORKS)
|
||||
return PathImpl::homeImpl();
|
||||
#else
|
||||
std::string path = PathImpl::homeImpl();
|
||||
std::string::size_type n = path.size();
|
||||
if (n > 0 && path[n - 1] == '/')
|
||||
#if POCO_OS == POCO_OS_MAC_OS_X
|
||||
path.append("Library/Application Support/");
|
||||
#else
|
||||
path.append(".local/share/");
|
||||
#endif
|
||||
|
||||
return path;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::cacheHomeImpl()
|
||||
{
|
||||
#if defined(POCO_VXWORKS)
|
||||
return PathImpl::tempImpl();
|
||||
#else
|
||||
std::string path = PathImpl::homeImpl();
|
||||
std::string::size_type n = path.size();
|
||||
if (n > 0 && path[n - 1] == '/')
|
||||
#if POCO_OS == POCO_OS_MAC_OS_X
|
||||
path.append("Library/Caches/");
|
||||
#else
|
||||
path.append(".cache/");
|
||||
#endif
|
||||
|
||||
return path;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::tempHomeImpl()
|
||||
{
|
||||
#if defined(POCO_VXWORKS)
|
||||
return PathImpl::tempImpl();
|
||||
#else
|
||||
std::string path = PathImpl::homeImpl();
|
||||
std::string::size_type n = path.size();
|
||||
if (n > 0 && path[n - 1] == '/')
|
||||
#if POCO_OS == POCO_OS_MAC_OS_X
|
||||
path.append("Library/Caches/");
|
||||
#else
|
||||
path.append(".local/tmp/");
|
||||
#endif
|
||||
|
||||
return path;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::tempImpl()
|
||||
{
|
||||
std::string path;
|
||||
@ -92,6 +168,19 @@ std::string PathImpl::tempImpl()
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::configImpl()
|
||||
{
|
||||
std::string path;
|
||||
|
||||
#if POCO_OS == POCO_OS_MAC_OS_X
|
||||
path = "/Library/Preferences/";
|
||||
#else
|
||||
path = "/etc/";
|
||||
#endif
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::nullImpl()
|
||||
{
|
||||
#if defined(POCO_VXWORKS)
|
||||
|
@ -74,6 +74,60 @@ std::string PathImpl::homeImpl()
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::configHomeImpl()
|
||||
{
|
||||
std::string result;
|
||||
|
||||
// if APPDATA environment variable not exist, return home directory instead
|
||||
try
|
||||
{
|
||||
result = EnvironmentImpl::getImpl("APPDATA");
|
||||
}
|
||||
catch (NotFoundException&)
|
||||
{
|
||||
result = homeImpl();
|
||||
}
|
||||
|
||||
std::string::size_type n = result.size();
|
||||
if (n > 0 && result[n - 1] != '\\')
|
||||
result.append("\\");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::dataHomeImpl()
|
||||
{
|
||||
std::string result;
|
||||
|
||||
// if LOCALAPPDATA environment variable not exist, return config home instead
|
||||
try
|
||||
{
|
||||
result = EnvironmentImpl::getImpl("LOCALAPPDATA");
|
||||
}
|
||||
catch (NotFoundException&)
|
||||
{
|
||||
result = configHomeImpl();
|
||||
}
|
||||
|
||||
std::string::size_type n = result.size();
|
||||
if (n > 0 && result[n - 1] != '\\')
|
||||
result.append("\\");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::cacheHomeImpl()
|
||||
{
|
||||
return tempImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::tempHomeImpl()
|
||||
{
|
||||
return tempImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::tempImpl()
|
||||
{
|
||||
char buffer[MAX_PATH];
|
||||
@ -91,6 +145,26 @@ std::string PathImpl::tempImpl()
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::configImpl()
|
||||
{
|
||||
std::string result;
|
||||
|
||||
// if PROGRAMDATA environment variable not exist, return system directory instead
|
||||
try
|
||||
{
|
||||
result = EnvironmentImpl::getImpl("PROGRAMDATA");
|
||||
}
|
||||
catch (NotFoundException&)
|
||||
{
|
||||
result = systemImpl();
|
||||
}
|
||||
|
||||
std::string::size_type n = result.size();
|
||||
if (n > 0 && result[n - 1] != '\\')
|
||||
result.append("\\");
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string PathImpl::nullImpl()
|
||||
{
|
||||
return "NUL:";
|
||||
|
@ -84,6 +84,62 @@ std::string PathImpl::homeImpl()
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::configHomeImpl()
|
||||
{
|
||||
std::string result;
|
||||
|
||||
// if APPDATA environment variable no exist, return home directory instead
|
||||
try
|
||||
{
|
||||
result = EnvironmentImpl::getImpl("APPDATA");
|
||||
}
|
||||
catch (NotFoundException&)
|
||||
{
|
||||
result = homeImpl();
|
||||
}
|
||||
|
||||
std::string::size_type n = result.size();
|
||||
if (n > 0 && result[n - 1] != '\\')
|
||||
result.append("\\");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::dataHomeImpl()
|
||||
{
|
||||
std::string result;
|
||||
|
||||
// if LOCALAPPDATA environment variable no exist, return config home instead
|
||||
try
|
||||
{
|
||||
result = EnvironmentImpl::getImpl("LOCALAPPDATA");
|
||||
}
|
||||
catch (NotFoundException&)
|
||||
{
|
||||
result = configHomeImpl();
|
||||
}
|
||||
|
||||
std::string::size_type n = result.size();
|
||||
if (n > 0 && result[n - 1] != '\\')
|
||||
result.append("\\");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::cacheHomeImpl()
|
||||
{
|
||||
return tempImpl();
|
||||
}
|
||||
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
std::string PathImpl::tempHomeImpl()
|
||||
{
|
||||
return tempImpl();
|
||||
}
|
||||
|
||||
>>>>>>> 06e59cb... add Windows compliant implementation of XDG Base Directory Specification
|
||||
std::string PathImpl::tempImpl()
|
||||
{
|
||||
Buffer<wchar_t> buffer(MAX_PATH_LEN);
|
||||
@ -102,6 +158,26 @@ std::string PathImpl::tempImpl()
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::configImpl()
|
||||
{
|
||||
std::string result;
|
||||
|
||||
// if PROGRAMDATA environment variable not exist, return system directory instead
|
||||
try
|
||||
{
|
||||
result = EnvironmentImpl::getImpl("PROGRAMDATA");
|
||||
}
|
||||
catch (NotFoundException&)
|
||||
{
|
||||
result = systemImpl();
|
||||
}
|
||||
|
||||
std::string::size_type n = result.size();
|
||||
if (n > 0 && result[n - 1] != '\\')
|
||||
result.append("\\");
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string PathImpl::nullImpl()
|
||||
{
|
||||
return "NUL:";
|
||||
|
@ -49,11 +49,13 @@ std::string PathImpl::cacheHomeImpl()
|
||||
return homeImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::tempHomeImpl()
|
||||
{
|
||||
return tempImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::configImpl()
|
||||
{
|
||||
return("\\");
|
||||
|
@ -172,13 +172,13 @@ void UTF8::removeBOM(std::string& str)
|
||||
}
|
||||
|
||||
|
||||
std::string UTF8::escape(const std::string &s)
|
||||
std::string UTF8::escape(const std::string &s, bool strictJSON)
|
||||
{
|
||||
return escape(s.begin(), s.end());
|
||||
return escape(s.begin(), s.end(), strictJSON);
|
||||
}
|
||||
|
||||
|
||||
std::string UTF8::escape(const std::string::const_iterator& begin, const std::string::const_iterator& end)
|
||||
std::string UTF8::escape(const std::string::const_iterator& begin, const std::string::const_iterator& end, bool strictJSON)
|
||||
{
|
||||
static Poco::UInt32 offsetsFromUTF8[6] = {
|
||||
0x00000000UL, 0x00003080UL, 0x000E2080UL,
|
||||
@ -208,8 +208,8 @@ std::string UTF8::escape(const std::string::const_iterator& begin, const std::st
|
||||
else if (ch == '\r') result += "\\r";
|
||||
else if (ch == '\b') result += "\\b";
|
||||
else if (ch == '\f') result += "\\f";
|
||||
else if (ch == '\v') result += "\\v";
|
||||
else if (ch == '\a') result += "\\a";
|
||||
else if (ch == '\v') result += (strictJSON ? "\\u000B" : "\\v");
|
||||
else if (ch == '\a') result += (strictJSON ? "\\u0007" : "\\a");
|
||||
else if (ch == '\\') result += "\\\\";
|
||||
else if (ch == '\"') result += "\\\"";
|
||||
else if (ch == '/') result += "\\/";
|
||||
|
@ -1086,13 +1086,13 @@ void StringTest::testJSONString()
|
||||
assert (toJSON("\\", false) == "\\\\");
|
||||
assert (toJSON("\"", false) == "\\\"");
|
||||
assert (toJSON("/", false) == "\\/");
|
||||
assert (toJSON("\a", false) == "\\a");
|
||||
assert (toJSON("\a", false) == "\\u0007");
|
||||
assert (toJSON("\b", false) == "\\b");
|
||||
assert (toJSON("\f", false) == "\\f");
|
||||
assert (toJSON("\n", false) == "\\n");
|
||||
assert (toJSON("\r", false) == "\\r");
|
||||
assert (toJSON("\t", false) == "\\t");
|
||||
assert (toJSON("\v", false) == "\\v");
|
||||
assert (toJSON("\v", false) == "\\u000B");
|
||||
assert (toJSON("a", false) == "a");
|
||||
assert (toJSON("\xD0\x82", 0) == "\xD0\x82");
|
||||
assert (toJSON("\xD0\x82", Poco::JSON_ESCAPE_UNICODE) == "\\u0402");
|
||||
|
@ -83,6 +83,25 @@ void UTF8StringTest::testTransform()
|
||||
}
|
||||
|
||||
|
||||
void UTF8StringTest::testEscape()
|
||||
{
|
||||
std::string s1("A \t, a \v, and an \a walk into a |, and the barman says \xD0\x82");
|
||||
|
||||
assert (UTF8::escape(s1) == "A \\t, a \\v, and an \\a walk into a |, and the barman says \\u0402");
|
||||
assert (UTF8::escape(s1, true) == "A \\t, a \\u000B, and an \\u0007 walk into a |, and the barman says \\u0402");
|
||||
}
|
||||
|
||||
|
||||
void UTF8StringTest::testUnescape()
|
||||
{
|
||||
std::string s1("A \\t, a \\u000B, and an \\u0007 walk into a |, and the barman says \\u0402");
|
||||
std::string s2("A \\t, a \\v, and an \\a walk into a |, and the barman says \\u0402");
|
||||
|
||||
assert (UTF8::unescape(s1) == "A \t, a \v, and an \a walk into a |, and the barman says \xD0\x82");
|
||||
assert (UTF8::unescape(s2) == "A \t, a \v, and an \a walk into a |, and the barman says \xD0\x82");
|
||||
}
|
||||
|
||||
|
||||
void UTF8StringTest::setUp()
|
||||
{
|
||||
}
|
||||
@ -99,6 +118,8 @@ CppUnit::Test* UTF8StringTest::suite()
|
||||
|
||||
CppUnit_addTest(pSuite, UTF8StringTest, testCompare);
|
||||
CppUnit_addTest(pSuite, UTF8StringTest, testTransform);
|
||||
CppUnit_addTest(pSuite, UTF8StringTest, testEscape);
|
||||
CppUnit_addTest(pSuite, UTF8StringTest, testUnescape);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@ -27,6 +27,9 @@ public:
|
||||
void testCompare();
|
||||
void testTransform();
|
||||
|
||||
void testEscape();
|
||||
void testUnescape();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
|
@ -1938,7 +1938,6 @@ void JSONTest::testEscape0()
|
||||
|
||||
void JSONTest::testNonEscapeUnicode()
|
||||
{
|
||||
Poco::JSON::Object::Ptr json = new Poco::JSON::Object();
|
||||
std::string chinese("{ \"name\" : \"\\u4e2d\" }");
|
||||
Poco::JSON::Parser parser(new Poco::JSON::ParseHandler());
|
||||
Var result = parser.parse(chinese);
|
||||
@ -1959,6 +1958,27 @@ void JSONTest::testNonEscapeUnicode()
|
||||
object = result.extract<Object::Ptr>();
|
||||
ss.str(""); object->stringify(ss);
|
||||
assert (ss.str() == "{\"name\":\"g\xC3\xBCnter\"}");
|
||||
|
||||
Poco::JSON::Object obj1;
|
||||
std::string shortEscapeStr("String with \t");
|
||||
std::string longEscapeStr("String with \a and \v plus \t for good measure");
|
||||
obj1.set("shortEscape", shortEscapeStr);
|
||||
obj1.set("longEscape", longEscapeStr);
|
||||
|
||||
ss.str("");
|
||||
obj1.stringify(ss);
|
||||
|
||||
parser.reset();
|
||||
parser.parse(ss.str());
|
||||
result = parser.asVar();
|
||||
|
||||
assert(result.type() == typeid(Object::Ptr));
|
||||
|
||||
object = result.extract<Object::Ptr>();
|
||||
Var shortEscape = object->get("shortEscape");
|
||||
Var longEscape = object->get("longEscape");
|
||||
assert(shortEscape.convert<std::string>() == shortEscapeStr);
|
||||
assert(longEscape.convert<std::string>() == longEscapeStr);
|
||||
}
|
||||
|
||||
|
||||
|
@ -74,7 +74,10 @@ class Util_API Application: public Subsystem
|
||||
/// - application.name: the file name of the application executable
|
||||
/// - application.baseName: the file name (excluding extension) of the application executable
|
||||
/// - application.dir: the path to the directory where the application executable resides
|
||||
/// - application.configDir: the path to the directory where the last configuration file loaded with loadConfiguration() was found.
|
||||
/// - application.configDir: the path to the directory where user specific configuration files of the application should be stored.
|
||||
/// - application.cacheDir: the path to the directory where user specific non-essential data files of the application should be stored.
|
||||
/// - application.dataDir: the path to the directory where user specific data files of the application should be stored.
|
||||
/// - application.tempDir: the path to the directory where user specific temporary files and other file objects of the application should be stored.
|
||||
///
|
||||
/// If loadConfiguration() has never been called, application.configDir will be equal to application.dir.
|
||||
///
|
||||
@ -369,6 +372,7 @@ private:
|
||||
void getApplicationPath(Poco::Path& path) const;
|
||||
void processOptions();
|
||||
bool findAppConfigFile(const std::string& appName, const std::string& extension, Poco::Path& path) const;
|
||||
bool findAppConfigFile(const Path& basePath, const std::string& appName, const std::string& extension, Poco::Path& path) const;
|
||||
|
||||
typedef Poco::AutoPtr<LayeredConfiguration> ConfigPtr;
|
||||
|
||||
|
@ -39,7 +39,12 @@ class Util_API SystemConfiguration: public AbstractConfiguration
|
||||
/// of the first Ethernet adapter found on the system.
|
||||
/// - system.currentDir: the current working directory
|
||||
/// - system.homeDir: the user's home directory
|
||||
/// - system.configHomeDir: the base directory relative to which user specific configuration files should be stored
|
||||
/// - system.cacheHomeDir: the base directory relative to which user specific non-essential data files should be stored
|
||||
/// - system.dataHomeDir: the base directory relative to which user specific data files should be stored
|
||||
/// - system.tempHomeDir: the base directory relative to which user-specific temporary files and other file objects should be placed
|
||||
/// - system.tempDir: the system's temporary directory
|
||||
/// - system.configDir: the system's configuration directory
|
||||
/// - system.dateTime: the current UTC date and time, formatted in ISO 8601 format.
|
||||
/// - system.pid: the current process ID.
|
||||
/// - system.env.<NAME>: the environment variable with the given <NAME>.
|
||||
@ -74,7 +79,12 @@ private:
|
||||
static const std::string NODEID;
|
||||
static const std::string CURRENTDIR;
|
||||
static const std::string HOMEDIR;
|
||||
static const std::string CONFIGHOMEDIR;
|
||||
static const std::string CACHEHOMEDIR;
|
||||
static const std::string DATAHOMEDIR;
|
||||
static const std::string TEMPHOMEDIR;
|
||||
static const std::string TEMPDIR;
|
||||
static const std::string CONFIGDIR;
|
||||
static const std::string DATETIME;
|
||||
#if !defined(POCO_VXWORKS)
|
||||
static const std::string PID;
|
||||
|
@ -164,7 +164,10 @@ void Application::init()
|
||||
_pConfig->setString("application.name", appPath.getFileName());
|
||||
_pConfig->setString("application.baseName", appPath.getBaseName());
|
||||
_pConfig->setString("application.dir", appPath.parent().toString());
|
||||
_pConfig->setString("application.configDir", appPath.parent().toString());
|
||||
_pConfig->setString("application.configDir", Path::configHome() + appPath.getBaseName() + Path::separator());
|
||||
_pConfig->setString("application.cacheDir", Path::cacheHome() + appPath.getBaseName() + Path::separator());
|
||||
_pConfig->setString("application.tempDir", Path::tempHome() + appPath.getBaseName() + Path::separator());
|
||||
_pConfig->setString("application.dataDir", Path::dataHome() + appPath.getBaseName() + Path::separator());
|
||||
processOptions();
|
||||
}
|
||||
|
||||
@ -504,6 +507,29 @@ bool Application::findAppConfigFile(const std::string& appName, const std::strin
|
||||
}
|
||||
|
||||
|
||||
bool Application::findAppConfigFile(const Path& basePath, const std::string& appName, const std::string& extension, Path& path) const
|
||||
{
|
||||
poco_assert (!appName.empty());
|
||||
|
||||
Path p(basePath,appName);
|
||||
p.setExtension(extension);
|
||||
bool found = findFile(p);
|
||||
if (!found)
|
||||
{
|
||||
#if defined(_DEBUG)
|
||||
if (appName[appName.length() - 1] == 'd')
|
||||
{
|
||||
p.setBaseName(appName.substr(0, appName.length() - 1));
|
||||
found = findFile(p);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (found)
|
||||
path = p;
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
void Application::defineOptions(OptionSet& options)
|
||||
{
|
||||
for (SubsystemVec::iterator it = _subsystems.begin(); it != _subsystems.end(); ++it)
|
||||
|
@ -41,7 +41,12 @@ const std::string SystemConfiguration::NODENAME = "system.nodeName";
|
||||
const std::string SystemConfiguration::NODEID = "system.nodeId";
|
||||
const std::string SystemConfiguration::CURRENTDIR = "system.currentDir";
|
||||
const std::string SystemConfiguration::HOMEDIR = "system.homeDir";
|
||||
const std::string SystemConfiguration::CONFIGHOMEDIR = "system.configHomeDir";
|
||||
const std::string SystemConfiguration::CACHEHOMEDIR = "system.cacheHomeDir";
|
||||
const std::string SystemConfiguration::DATAHOMEDIR = "system.dataHomeDir";
|
||||
const std::string SystemConfiguration::TEMPHOMEDIR = "system.tempHomeDir";
|
||||
const std::string SystemConfiguration::TEMPDIR = "system.tempDir";
|
||||
const std::string SystemConfiguration::CONFIGDIR = "system.configDir";
|
||||
const std::string SystemConfiguration::DATETIME = "system.dateTime";
|
||||
#if !defined(POCO_VXWORKS)
|
||||
const std::string SystemConfiguration::PID = "system.pid";
|
||||
@ -106,10 +111,31 @@ bool SystemConfiguration::getRaw(const std::string& key, std::string& value) con
|
||||
{
|
||||
value = Path::home();
|
||||
}
|
||||
else if (key == CONFIGHOMEDIR)
|
||||
{
|
||||
value = Path::configHome();
|
||||
}
|
||||
else if (key == CACHEHOMEDIR)
|
||||
{
|
||||
value = Path::cacheHome();
|
||||
}
|
||||
else if (key == DATAHOMEDIR)
|
||||
{
|
||||
value = Path::dataHome();
|
||||
}
|
||||
|
||||
else if (key == TEMPHOMEDIR)
|
||||
{
|
||||
value = Path::tempHome();
|
||||
}
|
||||
else if (key == TEMPDIR)
|
||||
{
|
||||
value = Path::temp();
|
||||
}
|
||||
else if (key == CONFIGDIR)
|
||||
{
|
||||
value = Path::config();
|
||||
}
|
||||
else if (key == DATETIME)
|
||||
{
|
||||
value = Poco::DateTimeFormatter::format(Poco::DateTime(), Poco::DateTimeFormat::ISO8601_FORMAT);
|
||||
@ -151,7 +177,12 @@ void SystemConfiguration::enumerate(const std::string& key, Keys& range) const
|
||||
range.push_back("nodeId");
|
||||
range.push_back("currentDir");
|
||||
range.push_back("homeDir");
|
||||
range.push_back("configHomeDir");
|
||||
range.push_back("cacheHomeDir");
|
||||
range.push_back("dataHomeDir");
|
||||
range.push_back("tempHomeDir");
|
||||
range.push_back("tempDir");
|
||||
range.push_back("configDir");
|
||||
range.push_back("dateTime");
|
||||
#if !defined(POCO_VXWORKS)
|
||||
range.push_back("pid");
|
||||
|
@ -84,7 +84,7 @@ void SystemConfigurationTest::testKeys()
|
||||
#if defined(POCO_VXWORKS)
|
||||
assert (keys.size() == 10);
|
||||
#else
|
||||
assert (keys.size() == 11);
|
||||
assert (keys.size() == 16);
|
||||
#endif
|
||||
assert (std::find(keys.begin(), keys.end(), "osName") != keys.end());
|
||||
assert (std::find(keys.begin(), keys.end(), "osVersion") != keys.end());
|
||||
@ -93,6 +93,9 @@ void SystemConfigurationTest::testKeys()
|
||||
assert (std::find(keys.begin(), keys.end(), "nodeId") != keys.end());
|
||||
assert (std::find(keys.begin(), keys.end(), "currentDir") != keys.end());
|
||||
assert (std::find(keys.begin(), keys.end(), "homeDir") != keys.end());
|
||||
assert (std::find(keys.begin(), keys.end(), "configHomeDir") != keys.end());
|
||||
assert (std::find(keys.begin(), keys.end(), "cacheHomeDir") != keys.end());
|
||||
assert (std::find(keys.begin(), keys.end(), "dataHomeDir") != keys.end());
|
||||
assert (std::find(keys.begin(), keys.end(), "tempDir") != keys.end());
|
||||
assert (std::find(keys.begin(), keys.end(), "dateTime") != keys.end());
|
||||
#if !defined(POCO_VXWORKS)
|
||||
|
2
openssl
2
openssl
@ -1 +1 @@
|
||||
Subproject commit b42dcf2175f30e0c21dc9a684f0b9670f4ed09c8
|
||||
Subproject commit 26b1673caad94a702b6d694f48f917a283b30777
|
Loading…
x
Reference in New Issue
Block a user