diff options
Diffstat (limited to 'src/configreader.cpp')
-rw-r--r-- | src/configreader.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp index bd8320137..905eb786a 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -773,14 +773,31 @@ bool ServerConfig::FileExists(const char* file) if ((sb.st_mode & S_IFDIR) > 0) return false; - FILE *input = fopen(file, "r"); - if (input == NULL) - return false; - else + return !access(file, F_OK); +} + +std::string ServerConfig::Escape(const std::string& str, bool xml) +{ + std::string escaped; + for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) { - fclose(input); - return true; + switch (*it) + { + case '"': + escaped += xml ? """ : "\""; + break; + case '&': + escaped += xml ? "&" : "&"; + break; + case '\\': + escaped += xml ? "\\" : "\\\\"; + break; + default: + escaped += *it; + break; + } } + return escaped; } const char* ServerConfig::CleanFilename(const char* name) |