1 #ifndef __LIBSSH2_CHANNEL_H
2 #define __LIBSSH2_CHANNEL_H
3 /* Copyright (c) 2008-2010 by Daniel Stenberg
4  *
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms,
8  * with or without modification, are permitted provided
9  * that the following conditions are met:
10  *
11  *   Redistributions of source code must retain the above
12  *   copyright notice, this list of conditions and the
13  *   following disclaimer.
14  *
15  *   Redistributions in binary form must reproduce the above
16  *   copyright notice, this list of conditions and the following
17  *   disclaimer in the documentation and/or other materials
18  *   provided with the distribution.
19  *
20  *   Neither the name of the copyright holder nor the names
21  *   of any other contributors may be used to endorse or
22  *   promote products derived from this software without
23  *   specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
26  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
27  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
38  * OF SUCH DAMAGE.
39  */
40 
41 /*
42  * _libssh2_channel_receive_window_adjust
43  *
44  * Adjust the receive window for a channel by adjustment bytes. If the amount
45  * to be adjusted is less than LIBSSH2_CHANNEL_MINADJUST and force is 0 the
46  * adjustment amount will be queued for a later packet.
47  *
48  * Always non-blocking.
49  */
50 int _libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL * channel,
51                                            uint32_t adjustment,
52                                            unsigned char force,
53                                            unsigned int *store);
54 
55 /*
56  * _libssh2_channel_flush
57  *
58  * Flush data from one (or all) stream
59  * Returns number of bytes flushed, or negative on failure
60  */
61 int _libssh2_channel_flush(LIBSSH2_CHANNEL *channel, int streamid);
62 
63 /*
64  * _libssh2_channel_free
65  *
66  * Make sure a channel is closed, then remove the channel from the session
67  * and free its resource(s)
68  *
69  * Returns 0 on success, negative on failure
70  */
71 int _libssh2_channel_free(LIBSSH2_CHANNEL *channel);
72 
73 int
74 _libssh2_channel_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode);
75 
76 /*
77  * _libssh2_channel_write
78  *
79  * Send data to a channel
80  */
81 ssize_t
82 _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
83                        const unsigned char *buf, size_t buflen);
84 
85 /*
86  * _libssh2_channel_open
87  *
88  * Establish a generic session channel
89  */
90 LIBSSH2_CHANNEL *
91 _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
92                       uint32_t channel_type_len,
93                       uint32_t window_size,
94                       uint32_t packet_size,
95                       const unsigned char *message, size_t message_len);
96 
97 
98 /*
99  * _libssh2_channel_process_startup
100  *
101  * Primitive for libssh2_channel_(shell|exec|subsystem)
102  */
103 int
104 _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
105                                  const char *request, size_t request_len,
106                                  const char *message, size_t message_len);
107 
108 /*
109  * _libssh2_channel_read
110  *
111  * Read data from a channel
112  *
113  * It is important to not return 0 until the currently read channel is
114  * complete. If we read stuff from the wire but it was no payload data to fill
115  * in the buffer with, we MUST make sure to return PACKET_EAGAIN.
116  */
117 ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
118                               char *buf, size_t buflen);
119 
120 uint32_t _libssh2_channel_nextid(LIBSSH2_SESSION * session);
121 
122 LIBSSH2_CHANNEL *_libssh2_channel_locate(LIBSSH2_SESSION * session,
123                                          uint32_t channel_id);
124 
125 size_t _libssh2_channel_packet_data_len(LIBSSH2_CHANNEL * channel,
126                                         int stream_id);
127 
128 int _libssh2_channel_close(LIBSSH2_CHANNEL * channel);
129 
130 /*
131  * _libssh2_channel_forward_cancel
132  *
133  * Stop listening on a remote port and free the listener
134  * Toss out any pending (un-accept()ed) connections
135  *
136  * Return 0 on success, LIBSSH2_ERROR_EAGAIN if would block, -1 on error
137  */
138 int _libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener);
139 
140 #endif /* __LIBSSH2_CHANNEL_H */
141 
142