channel.h 7.19 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1
2
3
4
5
6
7
8
/* channel.h
 *
 * Information about one ssh channel.
 */

#ifndef LSH_CHANNEL_H_INCLUDED
#define LSH_CHANNEL_H_INCLUDED

Niels Möller's avatar
Niels Möller committed
9
10
11
#include "alist.h"
#include "connection.h"
#include "parse.h"
Niels Möller's avatar
Niels Möller committed
12

13
14
15
16
#define CLASS_DECLARE
#include "channel.h.x"
#undef CLASS_DECLARE

Niels Möller's avatar
Niels Möller committed
17
18
19
20
21
22
23
24
/* Channels are indexed by local channel number in some array. This
 * index is not stored in the channel struct. When sending messages on
 * the channel, it is identified by the *remote* sides index number,
 * and this number must be stored. */

#define CHANNEL_DATA 0
#define CHANNEL_STDERR_DATA 1

25
26
27
28
29
#define CHANNEL_SENT_CLOSE 1
#define CHANNEL_RECIEVED_CLOSE 2
#define CHANNEL_SENT_EOF 4
#define CHANNEL_RECIEVED_EOF 8

30
/* Means that we should send close immediately after sending eof. */
31
#define CHANNEL_CLOSE_AT_EOF 0x10
32

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* CLASS:
   (class
     (name ssh_channel)
     (vars
       ; Remote channel number 
       (channel_number simple UINT32)

       ; We try to keep the rec_window_size ; between max_window / 2
       ; and max_window.
       (max_window simple UINT32)       

       (rec_window_size simple UINT32)
       (rec_max_packet simple UINT32)

       (send_window_size simple UINT32)
       (send_max_packet simple UINT32)

       ; FIXME: Perhaps this should be moved to the channel_table, and
       ; a pointer to that table be stored here instead?
       (write object abstract_write)
  
       (request_types object alist)

       (flags simple int)

       ; Number of files connected to this channel. For instance,
       ; stdout and stderr can be multiplexed on the same channel. We
       ; should not close the channel until we have got an EOF on both
       ; sources.
       (sources simple int)

       ; FIXME: What about return values from these functions? A
       ; channel may fail to process it's data. Is there some way to
       ; propagate a channel broken message to the other end? 

       ; Type is CHANNEL_DATA or CHANNEL_STDERR_DATA
       (recieve method int "int type" "struct lsh_string *data")

       ; Called when we are allowed to send data on the channel. 
       (send method int)

Niels Möller's avatar
Niels Möller committed
74
75
       ; Called when the channel is closed
       ; FIXME: Is this needed for anything?
76
77
78
79
80
81
82
83
84
85
86
87
88
89
       (close method void)

       ; Called when eof is recieved on the channel (or when it is
       ; closed, whatever happens first).
 
       (eof method int)
  
       ; Reply from SSH_MSG_CHANNEL_OPEN_REQUEST
       (open_confirm method int)
       (open_failure method int)

       ; Reply from SSH_MSG_CHANNEL_REQUEST 
       (channel_success method int)
       (channel_failure method int)))
90
*/
91

92
93
#define CHANNEL_RECIEVE(s, t, d) \
((s)->recieve((s), (t), (d)))
Niels Möller's avatar
Niels Möller committed
94

95
96
97
98
#define CHANNEL_SEND(s) ((s)->send((s)))
     
#define CHANNEL_CLOSE(s) \
((s)->close((s)))
Niels Möller's avatar
Niels Möller committed
99

100
101
#define CHANNEL_EOF(s) \
((s)->eof((s)))
Niels Möller's avatar
Niels Möller committed
102

103
104
#define CHANNEL_OPEN_CONFIRM(s) \
((s)->open_confirm((s)))
105

106
107
#define CHANNEL_OPEN_FAILURE(s) \
((s)->open_failure((s)))
Niels Möller's avatar
Niels Möller committed
108

109
110
#define CHANNEL_SUCCESS(s) \
((s)->channel_success((s)))
Niels Möller's avatar
Niels Möller committed
111

112
113
#define CHANNEL_FAILURE(s) \
((s)->channel_failure((s)))
114
     
Niels Möller's avatar
Niels Möller committed
115
/* FIXME: Perhaps, this information is better kept in the connection
116
 * object? */
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

/* CLASS:
   (class
     (name channel_table)
     (vars
       ; FIXME: This is relevant only for the server side. It's
       ; probably better to store this in the connection struct.

       ;; uid_t user;  ; Authenticated user 

       ; Channels are indexed by local number
       (channels pointer (object ssh_channel) used_channels)

       ; Allocation of local channel numbers is managed using the same
       ; method as is traditionally used for allocation of unix file 
       ; descriptors.

       (allocated_channels simple UINT32)
       (next_channel simple UINT32)
     
       (used_channels simple UINT32)
       (max_channels simple UINT32) ; Max number of channels allowed 

       ; If non-zero, close connection after all active channels have
       ; died.
       (pending_close simple int)

       ; FIXME: Perhaps we should use an flag to indicate whether or
       ; not new channels can be opened?
       ))
*/
Niels Möller's avatar
Niels Möller committed
148
149

/* SSH_MSG_GLOBAL_REQUEST */
150
151
152
153
154
155
156
/* CLASS:
   (class
     (name global_request)
     (vars
       (handler method int "int want_reply" "struct simple_buffer *args")))
*/

Niels Möller's avatar
Niels Möller committed
157
158
159
#define GLOBAL_REQUEST(c, w, a) ((c)->handler((c), (w), (a)))

/* SSH_MSG_CHANNEL_OPEN */
160
161
162
163
164
165
166
167
168
169
/* CLASS:
   (class
     (name channel_open)
     (vars
       (handler method (object ssh_channel)
               "struct simple_buffer *args"
	       "UINT32 *error" "char **error_msg"
	       "struct lsh_string **data")))
*/

170
171
#define CHANNEL_OPEN(c, a, e, m, d) \
((c)->handler((c), (a), (e), (m), (d)))
Niels Möller's avatar
Niels Möller committed
172
173

/* SSH_MSH_CHANNEL_REQUEST */
174
175
176
177
178
179
180
181
182
183
/* CLASS:
   (class
     (name channel_request)
     (vars
       (handler method int
		"struct ssh_channel *channel"
		"int want_reply"
		"struct simple_buffer *args")))
*/

Niels Möller's avatar
Niels Möller committed
184
185
186
#define CHANNEL_REQUEST(s, c, w, a) \
((s)->handler((s), (c), (w), (a)))

187
188
189
190
191
192
193
194
195
/* CLASS:
   (class
     (name connection_startup)
     (vars
       (start method int
	      "struct channel_table *table"
	      "struct abstract_write *write")))
*/

196
197
#define CONNECTION_START(c, s, w) ((c)->start((c), (s), (w)))

198
199
void init_channel(struct ssh_channel *channel);

200
201
202
203
204
struct channel_table *make_channel_table(void);
int alloc_channel(struct channel_table *table);
void dealloc_channel(struct channel_table *table, int i);
int register_channel(struct channel_table *table, struct ssh_channel *channel);
struct ssh_channel *lookup_channel(struct channel_table *table, UINT32 i);
Niels Möller's avatar
Niels Möller committed
205

206
207
208
209
210
211
212
struct abstract_write *make_channel_write(struct ssh_channel *channel);
struct abstract_write *make_channel_write_extended(struct ssh_channel *channel,
						   UINT32 type);

struct read_handler *make_channel_read_data(struct ssh_channel *channel);
struct read_handler *make_channel_read_stderr(struct ssh_channel *channel);

Niels Möller's avatar
Niels Möller committed
213
struct lsh_string *format_global_failure(void);
214

Niels Möller's avatar
Niels Möller committed
215
struct lsh_string *format_open_failure(UINT32 channel, UINT32 reason,
216
				       const char *msg, const char *language);
217
218
struct lsh_string *format_open_confirmation(struct ssh_channel *channel,
					    UINT32 channel_number,
219
					    const char *format, ...);
220
221

struct lsh_string *format_channel_success(UINT32 channel);
Niels Möller's avatar
Niels Möller committed
222
223
struct lsh_string *format_channel_failure(UINT32 channel);

Niels Möller's avatar
Niels Möller committed
224
225
226
struct lsh_string *prepare_window_adjust(struct ssh_channel *channel,
					 UINT32 add);

227
228
struct lsh_string *prepare_channel_open(struct channel_table *table,
					int type, struct ssh_channel *channel,
229
					const char *format, ...);
230
231

struct lsh_string *format_channel_request(int type, struct ssh_channel *channel,
232
233
					  int want_reply, const char *format, 
					  ...);
234

235
236
struct lsh_string *format_channel_close(struct ssh_channel *channel);
struct lsh_string *format_channel_eof(struct ssh_channel *channel);
237

238
239
int channel_close(struct ssh_channel *channel);
int channel_eof(struct ssh_channel *channel);
240

241
242
struct close_callback *make_channel_close(struct ssh_channel *channel);

243
244
struct lsh_string *channel_transmit_data(struct ssh_channel *channel,
					 struct lsh_string *data);
245

246
247
248
struct lsh_string *channel_transmit_extended(struct ssh_channel *channel,
					     UINT32 type,
					     struct lsh_string *data);
249

Niels Möller's avatar
Niels Möller committed
250
struct ssh_service *make_connection_service(struct alist *global_requests,
251
252
253
					    struct alist *channel_types,
					    struct connection_startup *start);

Niels Möller's avatar
Niels Möller committed
254

Niels Möller's avatar
Niels Möller committed
255
#endif /* LSH_CHANNEL_H_INCLUDED */