]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
Parse headers
authorMartin Vidner <mvidner@suse.cz>
Fri, 1 Nov 2019 16:08:45 +0000 (17:08 +0100)
committerMartin Vidner <mvidner@suse.cz>
Fri, 13 Dec 2019 15:31:47 +0000 (16:31 +0100)
zypp-plugin/snapper_zypp_plugin.cc
zypp-plugin/zypp_plugin.cc

index 6e363a56178da87c9cc3485448b92333fa758cb5..1865efef62ca3315b13a23663d6d23a80a30d76a 100644 (file)
@@ -169,6 +169,7 @@ set<string> 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;
index 3fc9b36ac55e61d1f5d456bcd900f896213cd4ae..a933129a83e4e2515d1eeb35c5422fdb56c37dc1 100644 (file)
@@ -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 + "'");
+               }
            }
        }
     }