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

# User Rev Content
1 sf-pippijn 1.1 #include <json/json.h>
2    
3     void
4     command_parser::on_msg (std::istream &args)
5     {
6 sf-pippijn 1.2 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 sf-pippijn 1.4 PARSE_END;
13 sf-pippijn 1.1
14 sf-pippijn 1.2 assert (msg.type () == Json::arrayValue);
15     emit msg (msg[0u].asUInt (), msg[1u].asString (), msg[2u].asString ());
16     }
17     else
18     {
19 sf-pippijn 1.3 int level;
20 sf-pippijn 1.2 std::string channel;
21     std::string msg;
22    
23 sf-pippijn 1.3 args >> level >> channel;
24 sf-pippijn 1.2 while (args.peek () == ' ')
25     args.ignore ();
26 sf-pippijn 1.3 std::getline (args, msg);
27 sf-pippijn 1.4 PARSE_END;
28 sf-pippijn 1.2
29 sf-pippijn 1.3 emit msg (level, channel, msg);
30 sf-pippijn 1.2 }
31 sf-pippijn 1.1 }