From: Martin Vidner Date: Fri, 1 Nov 2019 16:08:45 +0000 (+0100) Subject: Parse headers X-Git-Tag: v0.8.7^2~30 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7d28f634702c6fb0c73247ff03247caa07543996;p=thirdparty%2Fsnapper.git Parse headers --- diff --git a/zypp-plugin/snapper_zypp_plugin.cc b/zypp-plugin/snapper_zypp_plugin.cc index 6e363a56..1865efef 100644 --- a/zypp-plugin/snapper_zypp_plugin.cc +++ b/zypp-plugin/snapper_zypp_plugin.cc @@ -169,6 +169,7 @@ set SnapperZyppPlugin::get_solvables(const Message& msg, bool todo) { rapidjson::Document doc; const char * c_body = msg.body.c_str(); + y2deb("parsing zypp JSON: " << c_body); if (doc.Parse(c_body).HasParseError()) { y2err("parsing zypp JSON failed"); return result; diff --git a/zypp-plugin/zypp_plugin.cc b/zypp-plugin/zypp_plugin.cc index 3fc9b36a..a933129a 100644 --- a/zypp-plugin/zypp_plugin.cc +++ b/zypp-plugin/zypp_plugin.cc @@ -40,7 +40,7 @@ int ZyppPlugin::main() { state = State::Headers; } else { - throw "FIXME: expected a command"; + throw runtime_error("Plugin protocol error: expected a command. Got '" + line + "'"); } } else if (state == State::Headers) { @@ -53,9 +53,16 @@ int ZyppPlugin::main() { state = State::Start; } else { - //string key, value; - // TODO: parse the header - //msg.headers[key] = value; + static const boost::regex rx_header("([A-Za-z0-9_]+):[ \t]*(.+)"); + boost::smatch what; + if (boost::regex_match(line, what, rx_header)) { + string key = what[1]; + string value = what[2]; + msg.headers[key] = value; + } + else { + throw runtime_error("Plugin protocol error: expected a header or new line. Got '" + line + "'"); + } } } }