libshevek
telnet.hh
1 /* telnet.hh - implementation of the telnet protocol
2  * Copyright 2003 Bas Wijnen <wijnen@debian.org>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef SHEVEK_TELNET_HH
19 #define SHEVEK_TELNET_HH
20 
21 #include "socket.hh"
22 
23 namespace shevek
24 {
26  class telnet : public socket
27  {
28  // These are ideal for an enum, in a sense, but the values are really char constants, and C++ doesn't allow that for enums. So the choice is to cast the enum value to a char, or to not use an enum. I don't like casts.
29  // Command constants
30  static char const SE = '\xf0';
31  static char const NOP = '\xf1';
32  static char const MARK = '\xf2';
33  static char const BREAK = '\xf3';
34  static char const IP = '\xf4';
35  static char const AO = '\xf5';
36  static char const AYT = '\xf6';
37  static char const EC = '\xf7';
38  static char const EL = '\xf8';
39  static char const GA = '\xf9';
40  static char const SB = '\xfa';
41  static char const WILL = '\xfb';
42  static char const WONT = '\xfc';
43  static char const DO = '\xfd';
44  static char const DONT = '\xfe';
45  static char const IAC = '\xff';
46  // Option constants.
47  static char const BINARY = '\x00';
48  static char const ECHO = '\x01';
49  static char const SUPPRESS_GA = '\x03';
50  static char const STATUS = '\x05';
51  static char const TIMING_MARK = '\x06';
52  static char const EXOPL = '\xff';
53  enum option_idx {
54  BINARY_IDX = 0,
55  ECHO_IDX = 1,
56  SUPPRESS_GA_IDX = 2,
57  STATUS_IDX = 3,
58  TIMING_MARK_IDX = 4,
59  EXOPL_IDX = 5
60  };
61  struct option_t;
62  typedef void (telnet::*action)(option_t *opt);
63  struct option_t
64  {
65  char type;
66  action will, wont, doo, dont;
67  bool here, there, not_both;
68  };
69  static option_t options[6];
70  option_t nop_option;
71  option_t *s_find (char opt);
72  void nop (option_t *);
73  void nopwill (option_t *opt);
74  void nopdo (option_t *opt);
75  void l_will (option_t *opt);
76  void l_wont (option_t *opt);
77  void l_do (option_t *opt);
78  void l_dont (option_t *opt);
79  void will_check (option_t *opt);
80  void do_check (option_t *opt);
81  void wont_check (option_t *opt);
82  void dont_check (option_t *opt);
83  void l_do_sub (std::string const &data, std::string::size_type &pos);
84  bool m_ignore;
85  void l_in_filter (std::string &data);
86  void l_out_filter (std::string &data);
87  std::string m_am_here, m_inbuffer;
88  protected:
90  telnet (Glib::RefPtr <Glib::MainContext> main);
91  public:
93  static Glib::RefPtr <telnet> create (Glib::RefPtr <Glib::MainContext> main = Glib::MainContext::get_default () );
95 
97  std::string &you_there ();
98  };
99 }
100 
101 #endif
telnet(Glib::RefPtr< Glib::MainContext > main)
Derived classes have their own create function and may call the constructor.
Definition: args.hh:52
Input and output filters for shevek::socket to make them telnet sockets.
Definition: telnet.hh:26
Use a unix-domain, tcp or avahi network connection with shevek::fd.
Definition: socket.hh:36
std::string & you_there()
Return the string that is used in reply to ARE_YOU_THERE requests.
static Glib::RefPtr< telnet > create(Glib::RefPtr< Glib::MainContext > main=Glib::MainContext::get_default())
Create a new telnet socket.