mirror of
https://github.com/LibreOffice/online.git
synced 2025-08-10 01:34:37 +00:00
Revert "wsd: create a static function "parse""
This reverts commit fcfc257162
.
This commit is contained in:
@ -683,13 +683,37 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::
|
||||
documentSigningDiv = "<div id=\"document-signing-bar\"></div>";
|
||||
}
|
||||
|
||||
std::string lang;
|
||||
std::locale locale;
|
||||
std::ostringstream ostr;
|
||||
std::istringstream istr(preprocess);
|
||||
enum class ParseState
|
||||
{
|
||||
None,
|
||||
Subs,
|
||||
L10n
|
||||
};
|
||||
|
||||
parse(locale, istr, ostr, [&](const std::string& var) {
|
||||
bool result = true;
|
||||
std::string token;
|
||||
std::ostringstream ostr;
|
||||
std::stringstream varSubs, varL10n;
|
||||
std::istringstream istr(preprocess);
|
||||
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::Subs)
|
||||
{
|
||||
std::string var = varSubs.str();
|
||||
if (var == "ACCESS_TOKEN")
|
||||
{
|
||||
ostr << escapedAccessToken;
|
||||
@ -742,15 +766,41 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::
|
||||
{
|
||||
ostr << brandJS;
|
||||
}
|
||||
else if (var == "LANG")
|
||||
{
|
||||
if (lang != "en")
|
||||
ostr << "?lang=" << lang;
|
||||
}
|
||||
else result = false;
|
||||
else ostr << var;
|
||||
|
||||
return result;
|
||||
});
|
||||
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();
|
||||
}
|
||||
|
||||
const std::string mimeType = "text/html";
|
||||
|
||||
@ -937,92 +987,4 @@ 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: */
|
||||
|
@ -21,7 +21,6 @@ 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:
|
||||
|
Reference in New Issue
Block a user