[Libreoffice-commits] online.git: wsd/FileServer.cpp wsd/FileServer.hpp
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Mar 5 22:53:50 UTC 2019
wsd/FileServer.cpp | 254 ++++++++++++++++++++++++++++++-----------------------
wsd/FileServer.hpp | 1
2 files changed, 147 insertions(+), 108 deletions(-)
New commits:
commit fcfc257162e106f48b2864820c435fd836588a41
Author: Henry Castro <hcastro at collabora.com>
AuthorDate: Sun Feb 10 15:19:03 2019 -0400
Commit: Henry Castro <hcastro at collabora.com>
CommitDate: Tue Mar 5 18:53:20 2019 -0400
wsd: create a static function "parse"
Change-Id: Ifffae9a0d38bf64c41863a98395a2f41a6470441
diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index 61259ac05..409a9c540 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -683,124 +683,74 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::
documentSigningDiv = "<div id=\"document-signing-bar\"></div>";
}
- enum class ParseState
- {
- None,
- Subs,
- L10n
- };
-
- std::string token;
+ std::string lang;
+ std::locale locale;
std::ostringstream ostr;
- std::stringstream varSubs, varL10n;
std::istringstream istr(preprocess);
- ParseState state = ParseState::None;
- getToken(istr, token);
- while (!token.empty())
- {
- if (token == "<%")
+ parse(locale, istr, ostr, [&](const std::string& var) {
+ bool result = true;
+ if (var == "ACCESS_TOKEN")
{
- if (state == ParseState::None)
- {
- state = ParseState::Subs;
- varSubs.str("");
- varSubs.clear();
- }
- else ostr << token;
+ ostr << escapedAccessToken;
}
- else if (token == "%>")
+ else if (var == "ACCESS_TOKEN_TTL")
{
- if (state == ParseState::Subs)
- {
- std::string var = varSubs.str();
- if (var == "ACCESS_TOKEN")
- {
- ostr << escapedAccessToken;
- }
- else if (var == "ACCESS_TOKEN_TTL")
- {
- ostr << tokenTtl;
- }
- else if (var == "ACCESS_HEADER")
- {
- ostr << escapedAccessHeader;
- }
- else if (var == "HOST")
- {
- ostr << host;
- }
- else if (var == "VERSION")
- {
- ostr << LOOLWSD_VERSION_HASH;
- }
- else if (var == "SERVICE_ROOT")
- {
- ostr << LOOLWSD::ServiceRoot;
- }
- else if (var == "LOLEAFLET_LOGGING")
- {
- ostr << config.getString("loleaflet_logging", "false");
- }
- else if (var == "OUT_OF_FOCUS_TIMEOUT_SECS")
- {
- ostr << config.getString("per_view.out_of_focus_timeout_secs", "60");
- }
- else if (var == "IDLE_TIMEOUT_SECS")
- {
- ostr << config.getString("per_view.idle_timeout_secs", "900");
- }
- else if (var == "DOCUMENT_SIGNING_DIV")
- {
- ostr << documentSigningDiv;
- }
- else if (var == "DOCUMENT_SIGNING_URL")
- {
- ostr << documentSigningURL;
- }
- else if (var == "BRANDING_CSS")
- {
- ostr << brandCSS;
- }
- else if (var == "BRANDING_JS")
- {
- ostr << brandJS;
- }
- else ostr << var;
-
- state = ParseState::None;
- }
- else ostr << token;
+ ostr << tokenTtl;
}
- else
+ else if (var == "ACCESS_HEADER")
{
- switch (state)
- {
- case ParseState::None:
- ostr << token;
- break;
-
- case ParseState::Subs:
- varSubs << token;
- break;
-
- case ParseState::L10n:
- varL10n << token;
- break;
- }
+ ostr << escapedAccessHeader;
}
+ else if (var == "HOST")
+ {
+ ostr << host;
+ }
+ else if (var == "VERSION")
+ {
+ ostr << LOOLWSD_VERSION_HASH;
+ }
+ else if (var == "SERVICE_ROOT")
+ {
+ ostr << LOOLWSD::ServiceRoot;
+ }
+ else if (var == "LOLEAFLET_LOGGING")
+ {
+ ostr << config.getString("loleaflet_logging", "false");
+ }
+ else if (var == "OUT_OF_FOCUS_TIMEOUT_SECS")
+ {
+ ostr << config.getString("per_view.out_of_focus_timeout_secs", "60");
+ }
+ else if (var == "IDLE_TIMEOUT_SECS")
+ {
+ ostr << config.getString("per_view.idle_timeout_secs", "900");
+ }
+ else if (var == "DOCUMENT_SIGNING_DIV")
+ {
+ ostr << documentSigningDiv;
+ }
+ else if (var == "DOCUMENT_SIGNING_URL")
+ {
+ ostr << documentSigningURL;
+ }
+ else if (var == "BRANDING_CSS")
+ {
+ ostr << brandCSS;
+ }
+ else if (var == "BRANDING_JS")
+ {
+ ostr << brandJS;
+ }
+ else if (var == "LANG")
+ {
+ if (lang != "en")
+ ostr << "?lang=" << lang;
+ }
+ else result = false;
- getToken(istr, token);
- }
-
- if (state == ParseState::Subs)
- {
- ostr << varSubs.str();
- }
- else if (state == ParseState::L10n)
- {
- ostr << varL10n.str();
- }
+ return result;
+ });
const std::string mimeType = "text/html";
@@ -987,4 +937,92 @@ void FileServerRequestHandler::preprocessAdminFile(const HTTPRequest& request,co
socket->send(oss.str());
}
+void FileServerRequestHandler::parse(const std::locale& locale, std::istringstream& istr, std::ostringstream& ostr, const std::function<bool(const std::string&)>& funcSubs)
+{
+ enum class ParseState
+ {
+ None,
+ Subs,
+ L10n
+ };
+
+ std::string token;
+ std::stringstream varSubs, varL10n;
+ ParseState state = ParseState::None;
+
+ getToken(istr, token);
+ while (!token.empty())
+ {
+ if (token == "<%")
+ {
+ if (state == ParseState::None)
+ {
+ state = ParseState::Subs;
+ varSubs.str("");
+ varSubs.clear();
+ }
+ else ostr << token;
+ }
+ else if (token == "_(\'")
+ {
+ if (state == ParseState::None)
+ {
+ state = ParseState::L10n;
+ varL10n.str("");
+ varL10n.clear();
+ }
+ else ostr << token;
+ }
+ else if (token == "\')")
+ {
+ if (state == ParseState::L10n)
+ {
+ LOG_INF(locale.name());
+ //ostr << '\'' << boost::locale::gettext(varL10n.str().c_str(), locale) << '\'';
+ state = ParseState::None;
+ }
+ else ostr << token;
+ }
+ else if (token == "%>")
+ {
+ if (state == ParseState::Subs)
+ {
+ std::string var = varSubs.str();
+ if (!funcSubs(var))
+ ostr << var;
+
+ state = ParseState::None;
+ }
+ else ostr << token;
+ }
+ else
+ {
+ switch (state)
+ {
+ case ParseState::None:
+ ostr << token;
+ break;
+
+ case ParseState::Subs:
+ varSubs << token;
+ break;
+
+ case ParseState::L10n:
+ varL10n << token;
+ break;
+ }
+ }
+
+ getToken(istr, token);
+ }
+
+ if (state == ParseState::Subs)
+ {
+ ostr << varSubs.str();
+ }
+ else if (state == ParseState::L10n)
+ {
+ ostr << varL10n.str();
+ }
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/FileServer.hpp b/wsd/FileServer.hpp
index 45cf7538b..c5a5133cd 100644
--- a/wsd/FileServer.hpp
+++ b/wsd/FileServer.hpp
@@ -21,6 +21,7 @@ class FileServerRequestHandler
static std::string getRequestPathname(const Poco::Net::HTTPRequest& request);
static void getToken(std::istringstream&, std::string&);
+ static void parse(const std::locale&, std::istringstream&, std::ostringstream&, const std::function<bool(const std::string&)>&);
static void preprocessFile(const Poco::Net::HTTPRequest& request, Poco::MemoryInputStream& message, const std::shared_ptr<StreamSocket>& socket);
static void preprocessAdminFile(const Poco::Net::HTTPRequest& request, const std::shared_ptr<StreamSocket>& socket);
public:
More information about the Libreoffice-commits
mailing list