wsd: new helper class UserRequestVars

Used to substitute user-request variables
in the files being served.

Change-Id: I7c0046328ec05f2feb7fcd9df9a21e415a1e2513
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
This commit is contained in:
Ashod Nakashian 2023-06-20 11:01:24 -04:00 committed by Michael Meeks
parent 9555f3228b
commit 2bb765c48f

View file

@ -990,6 +990,41 @@ constexpr char BRANDING[] = "branding";
constexpr char BRANDING_UNSUPPORTED[] = "branding-unsupported";
#endif
/// Per user request variables.
/// Holds access_token, css_variables, postmessage_origin, etc.
class UserRequestVars
{
std::string extractVariable(const HTMLForm& form, const std::string& field,
const std::string& var)
{
std::string value = form.get(field, "");
const std::string escaped = Util::encodeURIComponent(value, "'");
_vars[var] = escaped;
LOG_TRC("Field [" << field << "] for var [" << var << "] = [" << escaped << ']');
return value;
}
public:
UserRequestVars(const HTTPRequest& /*request*/, const Poco::Net::HTMLForm& /*form*/)
{
// We need to pass certain parameters from the cool html GET URI
// to the embedded document URI. Here we extract those params
// from the GET URI and set them in the generated html (see cool.html.m4).
}
const std::string& operator[](const std::string& key) const
{
const auto it = _vars.find(key);
return it != _vars.end() ? it->second : _blank;
}
private:
std::unordered_map<std::string, std::string> _vars;
const std::string _blank;
};
void FileServerRequestHandler::preprocessFile(const HTTPRequest& request,
const RequestDetails &requestDetails,
Poco::MemoryInputStream& message,