From 8a58dab4113bbcccd1d85b8b6209d77077dcd9e8 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 14 Apr 2020 22:39:26 +0200 Subject: String handling fixes --- plugins/webbox/webbox.cpp | 48 ++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) (limited to 'plugins/webbox') diff --git a/plugins/webbox/webbox.cpp b/plugins/webbox/webbox.cpp index 142345a..d07e90b 100644 --- a/plugins/webbox/webbox.cpp +++ b/plugins/webbox/webbox.cpp @@ -272,14 +272,14 @@ protected: for (auto& dir_entry: dir) { if (dir_entry.is_regular_file() || dir_entry.is_directory()) { - entry.put_value(dir_entry.path().filename()); + entry.put_value(dir_entry.path().filename().string()); entry.put(".type", dir_entry.is_directory() ? "dir" : "file"); list.push_back(pt::ptree::value_type("listentry", entry)); } } tree.push_back(pt::ptree::value_type("list", list)); - std::stringstream ss; + std::ostringstream ss; pt::xml_parser::write_xml(ss, tree /*, pt::xml_parser::xml_writer_make_settings(' ', 1)*/); @@ -307,7 +307,7 @@ protected: pt::ptree tree; tree.put("serverinfo.title", p.webboxName); tree.put("serverinfo.readonly", p.webboxReadOnly ? "1" : "0"); - std::stringstream ss; + std::ostringstream ss; pt::xml_parser::write_xml(ss, tree); return ss.str(); } @@ -347,7 +347,8 @@ protected: p.m_SetResponseHeader("content_type", "text/plain"); pt::ptree tree; - pt::read_xml(m_content, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); + std::istringstream ss{m_content}; + pt::read_xml(ss, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); std::string dirname = tree.get("dirname"); @@ -381,7 +382,8 @@ protected: p.m_SetResponseHeader("content_type", "text/plain"); pt::ptree tree; - pt::read_xml(m_content, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); + std::istringstream ss{m_content}; + pt::read_xml(ss, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); try { auto elements {tree.get_child("files")}; @@ -433,7 +435,8 @@ protected: readContent(p); pt::ptree tree; - pt::read_xml(m_content, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); + std::istringstream ss{m_content}; + pt::read_xml(ss, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); try { auto elements {tree.get_child("files")}; @@ -495,7 +498,8 @@ protected: readContent(p); pt::ptree tree; - pt::read_xml(m_content, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); + std::istringstream ss{m_content}; + pt::read_xml(ss, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); try { auto elements {tree.get_child("files")}; @@ -554,7 +558,8 @@ protected: readContent(p); pt::ptree tree; - pt::read_xml(m_content, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); + std::istringstream ss{m_content}; + pt::read_xml(ss, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); try { auto elements {tree.get_child("request")}; @@ -604,7 +609,8 @@ protected: readContent(p); pt::ptree tree; - pt::read_xml(m_content, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); + std::istringstream ss{m_content}; + pt::read_xml(ss, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); std::string oldname{tree.get("request.oldname")}; std::string newname{tree.get("request.newname")}; @@ -766,21 +772,21 @@ std::string webbox_plugin::generate_page( { CommandParameters commandParameters(GetServerParam, GetRequestParam, SetResponseHeader); + std::string commandName; + auto it {commandParameters.paramHash.find("command")}; - if (it != commandParameters.paramHash.end()) { - std::string& commandName{it->second}; + if (it != commandParameters.paramHash.end()) + commandName = it->second; - auto commands_it{m_commands.find(commandName)}; - if (commands_it != m_commands.end()) { - try { - return commands_it->second->execute(commandParameters); - } catch (const std::exception& ex) { - return HttpStatus("500", "Processing command: "s + commandName, commandParameters); - } - } else - return HttpStatus("400", "Bad command: "s + commandName, commandParameters); + auto commands_it{m_commands.find(commandName)}; + if (commands_it != m_commands.end()) { + try { + return commands_it->second->execute(commandParameters); + } catch (const std::exception& ex) { + return HttpStatus("500", "Processing command: "s + commandName + ", "s + ex.what(), commandParameters); + } } else - return HttpStatus("400", "No command specified"s, commandParameters); + return HttpStatus("400", "Bad command: "s + commandName, commandParameters); } void webbox_plugin::registerCommand(std::shared_ptr command) -- cgit v1.2.3