monotone

monotone Mtn Source Tree

Root/proto_machine.hh

1#ifndef __PROTO_MACHINE_HH__
2#define __PROTO_MACHINE_HH__
3
4// copyright (C) 2002, 2003 graydon hoare <graydon@pobox.com>
5// all rights reserved.
6// licensed to the public under the terms of the GNU GPL (>= 2)
7// see the file COPYING for details
8
9#include <vector>
10#include <string>
11#include <map>
12#include <iosfwd>
13
14// this file describes the interface to netnews in terms
15// of NNTP / SMTP protocol state machines.
16
17using namespace std;
18
19class proto_state;
20struct proto_edge
21{
22 proto_state * targ;
23 int code;
24 string msg;
25 vector<string> lines;
26 explicit proto_edge(proto_state * next_state,
27 int code,
28 string const & message,
29 vector<string> const & lines);
30};
31
32class proto_state
33{
34private:
35 int res_code;
36 static bool debug;
37 map< int, pair<bool, proto_state *> > codes;
38 proto_edge handle_response(istream & net);
39
40protected:
41 proto_edge step_lines(iostream & net,
42vector<string> const & send_lines);
43
44 proto_edge step_cmd(iostream & net,
45 string const & cmd,
46 vector<string> const & args);
47
48public:
49 int get_res_code() { return res_code; }
50 static void set_debug(bool b);
51 void add_edge(int code, proto_state * targ, bool read_lines = false);
52 virtual ~proto_state();
53 virtual proto_edge drive(iostream & net, proto_edge const & e) = 0;
54};
55
56
57class cmd_state : public proto_state
58{
59 string cmd;
60 vector<string> args;
61public:
62 cmd_state(string const & c);
63 cmd_state(string const & c, string const & arg1);
64 cmd_state(string const & c, string const & arg1, string const & arg2);
65 virtual ~cmd_state();
66 virtual proto_edge drive(iostream & net, proto_edge const & e);
67};
68
69void run_proto_state_machine(proto_state * machine,
70 iostream & link);
71
72#endif // __PROTO_MACHINE_HH__

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status