~ubuntu-branches/ubuntu/jaunty/fqterm/jaunty

« back to all changes in this revision

Viewing changes to src/terminal/internal/fqterm_telnet.h

  • Committer: Bazaar Package Importer
  • Author(s): LI Daobing
  • Date: 2009-02-14 09:32:53 UTC
  • Revision ID: james.westby@ubuntu.com-20090214093253-s2e6544ox2aj79rj
Tags: upstream-0.9.3+svn632
ImportĀ upstreamĀ versionĀ 0.9.3+svn632

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   fqterm, a terminal emulator for both BBS and *nix.                    *
 
3
 *   Copyright (C) 2008 fqterm development group.                          *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 *   This program is distributed in the hope that it will be useful,       *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
 *   GNU General Public License for more details.                          *
 
14
 *                                                                         *
 
15
 *   You should have received a copy of the GNU General Public License     *
 
16
 *   along with this program; if not, write to the                         *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.               *
 
19
 ***************************************************************************/
 
20
 
 
21
#ifndef FQTERM_TELNET_H
 
22
#define FQTERM_TELNET_H
 
23
 
 
24
#include <QAbstractSocket>
 
25
#include <QByteArray>
 
26
 
 
27
namespace FQTerm {
 
28
 
 
29
#ifndef u_char
 
30
#define u_char uchar
 
31
#endif
 
32
 
 
33
#define NTSTATES         6          // # of Telnet Socket-Input FSM States
 
34
#define NSSTATES        3               // # of Telnet Option Subnegotiation FSM States
 
35
#define NCHRS           256             // # of valid characters
 
36
 
 
37
//  decleration
 
38
class FQTermTelnet;
 
39
// actionFunc is a pointer, point to a FQTermTelnet's func
 
40
typedef int(FQTermTelnet:: *ptrActionFunc)(int c);
 
41
 
 
42
//fsm struct
 
43
struct fsm_trans {
 
44
  u_char ft_state; // current state
 
45
  short ft_char; // input character
 
46
  u_char ft_next; // next state
 
47
  ptrActionFunc ft_action; // action to take
 
48
};
 
49
 
 
50
 
 
51
/*------------------------------------------------------------------------------
 
52
 *      FQTermTelnet class definition
 
53
 *-------------------------------------------------------------------------------
 
54
 */
 
55
class FQTermSocket;
 
56
 
 
57
// Telnet connection, a wrapper of socket.
 
58
// It will translate raw NVT data from low level socket to ansi data,
 
59
// and then upper level application can read it.
 
60
// It also can send ascii data (0~127).
 
61
class FQTermTelnet: public QObject {
 
62
  Q_OBJECT;
 
63
 public:
 
64
  FQTermTelnet(const QString &termtype, int rows, int numColumns, bool isSSH, const
 
65
              char *sshuser = NULL, const char *sshpasswd = NULL);
 
66
  ~FQTermTelnet();
 
67
 
 
68
  void setProxy(int nProxyType,  //0-no proxy; 1-wingate; 2-sock4; 3-socks5
 
69
                bool bAuth,  // if authentation needed
 
70
                const QString &strProxyHost, quint16 uProxyPort, const QString &strProxyUsr,
 
71
                const QString &strProxyPwd);
 
72
  void connectHost(const QString &hostname, quint16 portnumber);
 
73
 
 
74
  // Read ansi data.
 
75
  int read(char *data, uint maxlen);
 
76
 
 
77
  // Write data raw data
 
78
  int write(const char *data, uint len);
 
79
 
 
80
  void close(); // User close the connection
 
81
 
 
82
  int raw_len();
 
83
  int read_raw(char *data, uint maxlen);
 
84
 
 
85
 signals:
 
86
  void readyRead(int, int); // There are datas to be read out
 
87
  void TelnetState(int); // The  state telnet, defined as TSXXXX in fqterm.h
 
88
  void requestUserPwd(QString *user, QString *pwd, bool *isOK);
 
89
  void errorMessage(const char *reason);
 
90
 
 
91
 public slots:
 
92
  void windowSizeChanged(int, int);
 
93
 
 
94
 private slots:
 
95
  // Retrieve data from socket, translate NVT data to ansi data,
 
96
  // then notify data ready.
 
97
  void socketReadyRead();
 
98
 
 
99
  void connected();
 
100
  void showError(QAbstractSocket::SocketError);
 
101
  void hostFound();
 
102
  void delayCloseFinished();
 
103
  void closed();
 
104
 protected:
 
105
  //init structure fsm
 
106
  void init_telnet();
 
107
  void fsmbuild();
 
108
  void fsminit(u_char fsm[][NCHRS], struct fsm_trans ttab[], int nstates);
 
109
 
 
110
  //actions
 
111
  int tcdm(int);
 
112
  int recopt(int);
 
113
  int no_op(int);
 
114
  int do_echo(int);
 
115
  int do_notsup(int);
 
116
  int do_noga(int);
 
117
  int do_txbinary(int);
 
118
  int will_notsup(int);
 
119
  int will_txbinary(int);
 
120
  int will_termtype(int);
 
121
  int will_naws(int);
 
122
  int subopt(int);
 
123
  int subtermtype(int);
 
124
  int subend(int);
 
125
  int soputc(int);
 
126
  int ttputc(int);
 
127
  int tnabort(int);
 
128
 
 
129
  //utility functions
 
130
  int xputc_up(char);
 
131
  int xputs_up(char*);
 
132
  void putc_down(u_char);
 
133
 
 
134
 
 
135
 private:
 
136
  // Boolean Flags
 
137
  char synching, doecho, sndbinary, rcvbinary;
 
138
  char noga;
 
139
  char naws;
 
140
  u_char option_cmd; // has value WILL, WONT, DO, or DONT
 
141
 
 
142
  char termtype; // non-zero if received "DO TERMTYPE"
 
143
  char *term; // terminal name
 
144
 
 
145
  /* // TODO: BBS don't need control signals
 
146
  // Special keys - Terminal control characters
 
147
  // need work...
 
148
  static const char t_flushc=FQTERM_CTRL('S'); // Abort Output          i.e:(^S)
 
149
  static const char t_intrc=FQTERM_CTRL('C');  // Interrupt             i.e:(^C)
 
150
  static const char t_quitc=FQTERM_CTRL('\\'); // Quit                  i.e:(^\)
 
151
  static const char sg_erase=FQTERM_CTRL('?'); // Erase a character     i.e:(^?)
 
152
  static const char sg_kill=FQTERM_CTRL('U');  // Kill a line           i.e:(^U)
 
153
  */
 
154
 
 
155
  // FSM stuffs
 
156
  static struct fsm_trans ttstab[];
 
157
  int ttstate;
 
158
  u_char ttfsm[NTSTATES][NCHRS];
 
159
 
 
160
  static struct fsm_trans substab[];
 
161
  int substate;
 
162
  u_char subfsm[NSSTATES][NCHRS];
 
163
 
 
164
  // socket stuffs
 
165
  FQTermSocket *socket;
 
166
 
 
167
  //Pointers to internal buffers
 
168
  //
 
169
  //             |-->from_socket-->process-->to_ansi-->|
 
170
  //  socket<--->                                      <---> ansi decode
 
171
  //             |<---to_socket<--process<--from_ansi--|
 
172
  //
 
173
  QByteArray from_socket, to_ansi, from_ansi, to_socket;
 
174
  uint rsize; // size of to_ansi buffer
 
175
  uint wsize; // size of to_socket buffer
 
176
 
 
177
  // for test
 
178
  int wx, wy;
 
179
  int done_naws;
 
180
  bool d_isSSH;
 
181
  bool bConnected;
 
182
  int raw_size;
 
183
};
 
184
 
 
185
}  // namespace FQTerm
 
186
 
 
187
#endif  // FQTERM_TELNET_H