1/*
2 * This file is part of the SSH Library
3 *
4 * Copyright (c) 2009 by Aris Adamantiadis
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef CHANNELS_H_
22#define CHANNELS_H_
23#include "libssh/priv.h"
24
25/** @internal
26 * Describes the different possible states in a
27 * outgoing (client) channel request
28 */
29enum ssh_channel_request_state_e {
30 /** No request has been made */
31 SSH_CHANNEL_REQ_STATE_NONE = 0,
32 /** A request has been made and answer is pending */
33 SSH_CHANNEL_REQ_STATE_PENDING,
34 /** A request has been replied and accepted */
35 SSH_CHANNEL_REQ_STATE_ACCEPTED,
36 /** A request has been replied and refused */
37 SSH_CHANNEL_REQ_STATE_DENIED,
38 /** A request has been replied and an error happend */
39 SSH_CHANNEL_REQ_STATE_ERROR
40};
41
42enum ssh_channel_state_e {
43 SSH_CHANNEL_STATE_NOT_OPEN = 0,
44 SSH_CHANNEL_STATE_OPENING,
45 SSH_CHANNEL_STATE_OPEN_DENIED,
46 SSH_CHANNEL_STATE_OPEN,
47 SSH_CHANNEL_STATE_CLOSED
48};
49
50/* The channel has been closed by the remote side */
51#define SSH_CHANNEL_FLAG_CLOSED_REMOTE 0x1
52/* The channel has been freed by the calling program */
53#define SSH_CHANNEL_FLAG_FREED_LOCAL 0x2
54/* the channel has not yet been bound to a remote one */
55#define SSH_CHANNEL_FLAG_NOT_BOUND 0x4
56
57struct ssh_channel_struct {
58 ssh_session session; /* SSH_SESSION pointer */
59 uint32_t local_channel;
60 uint32_t local_window;
61 int local_eof;
62 uint32_t local_maxpacket;
63
64 uint32_t remote_channel;
65 uint32_t remote_window;
66 int remote_eof; /* end of file received */
67 uint32_t remote_maxpacket;
68 enum ssh_channel_state_e state;
69 int delayed_close;
70 int flags;
71 ssh_buffer stdout_buffer;
72 ssh_buffer stderr_buffer;
73 void *userarg;
74 int version;
75 int exit_status;
76 enum ssh_channel_request_state_e request_state;
77 ssh_channel_callbacks callbacks;
78 /* counters */
79 ssh_counter counter;
80};
81
82SSH_PACKET_CALLBACK(ssh_packet_channel_open_conf);
83SSH_PACKET_CALLBACK(ssh_packet_channel_open_fail);
84SSH_PACKET_CALLBACK(ssh_packet_channel_success);
85SSH_PACKET_CALLBACK(ssh_packet_channel_failure);
86SSH_PACKET_CALLBACK(ssh_request_success);
87SSH_PACKET_CALLBACK(ssh_request_denied);
88
89SSH_PACKET_CALLBACK(channel_rcv_change_window);
90SSH_PACKET_CALLBACK(channel_rcv_eof);
91SSH_PACKET_CALLBACK(channel_rcv_close);
92SSH_PACKET_CALLBACK(channel_rcv_request);
93SSH_PACKET_CALLBACK(channel_rcv_data);
94
95ssh_channel ssh_channel_new(ssh_session session);
96int channel_default_bufferize(ssh_channel channel, void *data, int len,
97 int is_stderr);
98int ssh_channel_flush(ssh_channel channel);
99uint32_t ssh_channel_new_id(ssh_session session);
100ssh_channel ssh_channel_from_local(ssh_session session, uint32_t id);
101void ssh_channel_do_free(ssh_channel channel);
102#ifdef WITH_SSH1
103SSH_PACKET_CALLBACK(ssh_packet_data1);
104SSH_PACKET_CALLBACK(ssh_packet_close1);
105SSH_PACKET_CALLBACK(ssh_packet_exist_status1);
106
107/* channels1.c */
108int channel_open_session1(ssh_channel channel);
109int channel_request_pty_size1(ssh_channel channel, const char *terminal,
110 int cols, int rows);
111int channel_change_pty_size1(ssh_channel channel, int cols, int rows);
112int channel_request_shell1(ssh_channel channel);
113int channel_request_exec1(ssh_channel channel, const char *cmd);
114int channel_write1(ssh_channel channel, const void *data, int len);
115ssh_channel ssh_get_channel1(ssh_session session);
116#endif
117
118#endif /* CHANNELS_H_ */
119