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

« back to all changes in this revision

Viewing changes to src/protocol/internal/fqterm_ssh_channel.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_SSH_CHANNEL_H
 
22
#define FQTERM_SSH_CHANNEL_H
 
23
 
 
24
#include "fqterm_ssh_types.h"
 
25
 
 
26
#include <QObject>
 
27
 
 
28
namespace FQTerm {
 
29
 
 
30
class FQTermSSHPacketReceiver;
 
31
class FQTermSSHPacketSender;
 
32
 
 
33
class FQTermSSHChannel: public QObject {
 
34
  Q_OBJECT;
 
35
protected:
 
36
  bool is_closed_;
 
37
 
 
38
  FQTermSSHPacketReceiver *packet_receiver_;
 
39
  FQTermSSHPacketSender *packet_sender_;
 
40
 
 
41
public:
 
42
  FQTermSSHChannel(){}
 
43
  virtual ~FQTermSSHChannel(){}
 
44
  virtual void initChannel(FQTermSSHPacketReceiver *packet,
 
45
                           FQTermSSHPacketSender *output) = 0;
 
46
  virtual void closeConnection(char *reason) = 0;
 
47
 
 
48
  // TODO: it seems this function isn't used.
 
49
  virtual void changeTermSize(int col, int row) = 0;
 
50
  
 
51
  virtual void sendData(const char *data, int len) = 0;
 
52
 
 
53
public slots:
 
54
  virtual void handlePacket(int type) = 0;
 
55
signals:
 
56
  void channelOK();
 
57
  void channelReadyRead(const char *data, int len);
 
58
  void channelError(const char *reason);
 
59
};
 
60
 
 
61
class FQTermSSH1Channel: public FQTermSSHChannel {
 
62
  Q_OBJECT;
 
63
private:
 
64
  enum FQTermSSH1ChannelState {
 
65
    BEGIN_SERVICE, REQPTY_SENT, 
 
66
    //REQCMD_SENT,
 
67
    SERVICE_OK
 
68
  }     service_state_;
 
69
 
 
70
public:
 
71
  FQTermSSH1Channel();
 
72
  virtual void initChannel(FQTermSSHPacketReceiver *packet, FQTermSSHPacketSender *output);
 
73
  virtual void closeConnection(char *reason);
 
74
  virtual void changeTermSize(int col, int row);
 
75
  virtual void sendData(const char *data, int len);
 
76
 
 
77
public slots:
 
78
  virtual void handlePacket(int type);
 
79
signals:
 
80
  void channelReadyRead(const char *data, int len);
 
81
};
 
82
 
 
83
 
 
84
class FQTermSSH2Channel: public FQTermSSHChannel {
 
85
  Q_OBJECT;
 
86
private:
 
87
  static u_int32_t generateChannelID();
 
88
 
 
89
private:
 
90
  enum FQTermSSH2ChannelState {
 
91
    BEGIN_CHANNEL, REQUEST_PTY_SENT, REQUEST_SHELL_SENT, CHANNEL_OK
 
92
  }     channel_state_;
 
93
 
 
94
  u_int32_t channel_id_;
 
95
 
 
96
  enum {MAX_LOCAL_WINDOW_SIZE = 0x100000, MAX_LOCAL_PACKET_SIZE = 0x4000};
 
97
  
 
98
  u_int32_t local_window_size_;
 
99
 
 
100
  u_int32_t server_channel_id_;
 
101
  u_int32_t server_window_size_; // connection packet window size;
 
102
  u_int32_t server_max_packet_size_; // max size of each packet sent to server.
 
103
 
 
104
  void requestPty();
 
105
  void requestShell();
 
106
  void processChannelPacket();
 
107
  void checkLocalWindowSize();
 
108
 
 
109
public:
 
110
  FQTermSSH2Channel();
 
111
  virtual void initChannel(FQTermSSHPacketReceiver *packet, FQTermSSHPacketSender *output);
 
112
  virtual void closeConnection(char *reason);
 
113
  virtual void changeTermSize(int col, int row);
 
114
  virtual void sendData(const char *data, int len);
 
115
 
 
116
public slots:
 
117
  virtual void handlePacket(int type);
 
118
signals:
 
119
  void channelReadyRead(const char *data, int len);
 
120
};
 
121
 
 
122
}  // namespace FQTerm
 
123
 
 
124
#endif  // FQTERM_SSH_CHANNEL_H