1
/***************************************************************************
2
* fqterm, a terminal emulator for both BBS and *nix. *
3
* Copyright (C) 2008 fqterm development group. *
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. *
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. *
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
***************************************************************************/
21
#ifndef FQTERM_TELNET_H
22
#define FQTERM_TELNET_H
24
#include <QAbstractSocket>
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
39
// actionFunc is a pointer, point to a FQTermTelnet's func
40
typedef int(FQTermTelnet:: *ptrActionFunc)(int c);
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
51
/*------------------------------------------------------------------------------
52
* FQTermTelnet class definition
53
*-------------------------------------------------------------------------------
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 {
64
FQTermTelnet(const QString &termtype, int rows, int numColumns, bool isSSH, const
65
char *sshuser = NULL, const char *sshpasswd = NULL);
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);
75
int read(char *data, uint maxlen);
77
// Write data raw data
78
int write(const char *data, uint len);
80
void close(); // User close the connection
83
int read_raw(char *data, uint maxlen);
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);
92
void windowSizeChanged(int, int);
95
// Retrieve data from socket, translate NVT data to ansi data,
96
// then notify data ready.
97
void socketReadyRead();
100
void showError(QAbstractSocket::SocketError);
102
void delayCloseFinished();
108
void fsminit(u_char fsm[][NCHRS], struct fsm_trans ttab[], int nstates);
117
int do_txbinary(int);
118
int will_notsup(int);
119
int will_txbinary(int);
120
int will_termtype(int);
123
int subtermtype(int);
132
void putc_down(u_char);
137
char synching, doecho, sndbinary, rcvbinary;
140
u_char option_cmd; // has value WILL, WONT, DO, or DONT
142
char termtype; // non-zero if received "DO TERMTYPE"
143
char *term; // terminal name
145
/* // TODO: BBS don't need control signals
146
// Special keys - Terminal control characters
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)
156
static struct fsm_trans ttstab[];
158
u_char ttfsm[NTSTATES][NCHRS];
160
static struct fsm_trans substab[];
162
u_char subfsm[NSSTATES][NCHRS];
165
FQTermSocket *socket;
167
//Pointers to internal buffers
169
// |-->from_socket-->process-->to_ansi-->|
170
// socket<---> <---> ansi decode
171
// |<---to_socket<--process<--from_ansi--|
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
185
} // namespace FQTerm
187
#endif // FQTERM_TELNET_H