ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/communicator/command_parser/msg.h
Revision: 1.4
Committed: Mon Oct 25 12:06:57 2010 UTC (15 years, 11 months ago) by sf-pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +2 -0 lines
Log Message:
be more strict about the protocol

File Contents

# Content
1 #include <json/json.h>
2
3 void
4 command_parser::on_msg (std::istream &args)
5 {
6 if (args.peek () == '[')
7 {
8 Json::Reader reader;
9 Json::Value msg;
10 if (!reader.parse (args, msg, false))
11 throw std::runtime_error ("error parsing input: " + reader.getFormatedErrorMessages ());
12 PARSE_END;
13
14 assert (msg.type () == Json::arrayValue);
15 emit msg (msg[0u].asUInt (), msg[1u].asString (), msg[2u].asString ());
16 }
17 else
18 {
19 int level;
20 std::string channel;
21 std::string msg;
22
23 args >> level >> channel;
24 while (args.peek () == ' ')
25 args.ignore ();
26 std::getline (args, msg);
27 PARSE_END;
28
29 emit msg (level, channel, msg);
30 }
31 }