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;
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) {
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 + "'");
+ }
}
}
}