diff options
| author | Roland Reichwein <mail@reichwein.it> | 2020-04-14 22:39:26 +0200 | 
|---|---|---|
| committer | Roland Reichwein <mail@reichwein.it> | 2020-04-14 22:39:26 +0200 | 
| commit | 8a58dab4113bbcccd1d85b8b6209d77077dcd9e8 (patch) | |
| tree | bd051d5d3d0f479e1c003dbd009df62a58ae6fdd /plugins | |
| parent | 1e82f7b36ff6d708cd285310eb090d58f9da855c (diff) | |
String handling fixes
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/webbox/webbox.cpp | 48 | 
1 files changed, 27 insertions, 21 deletions
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("<xmlattr>.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<std::string>(' ', 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<std::string>("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<std::string>("request.oldname")};    std::string newname{tree.get<std::string>("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> command)  | 
