Building the libssh2 and including a script to build it as UB
[printdrop.git] / libssh2 / include / libssh2.h
1 /* Copyright (c) 2004-2007, Sara Golemon <sarag@libssh2.org>
2 * All rights reserved.
3 *
4 * Redistribution and use in source and binary forms,
5 * with or without modification, are permitted provided
6 * that the following conditions are met:
7 *
8 * Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the
10 * following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 *
17 * Neither the name of the copyright holder nor the names
18 * of any other contributors may be used to endorse or
19 * promote products derived from this software without
20 * specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
34 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
35 * OF SUCH DAMAGE.
36 */
37
38 #ifndef LIBSSH2_H
39 #define LIBSSH2_H 1
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 #include <stddef.h>
46 #include <string.h>
47 #include <sys/stat.h>
48 #include <sys/types.h>
49
50 /* Allow alternate API prefix from CFLAGS or calling app */
51 #ifndef LIBSSH2_API
52 # ifdef LIBSSH2_WIN32
53 # ifdef LIBSSH2_LIBRARY
54 # define LIBSSH2_API __declspec(dllexport)
55 # else
56 # define LIBSSH2_API __declspec(dllimport)
57 # endif /* LIBSSH2_LIBRARY */
58 # else /* !LIBSSH2_WIN32 */
59 # define LIBSSH2_API
60 # endif /* LIBSSH2_WIN32 */
61 #endif /* LIBSSH2_API */
62
63 #if defined(LIBSSH2_DARWIN) || (defined(LIBSSH2_WIN32) && !defined(_MSC_VER) && !defined(__MINGW32__))
64 # include <sys/uio.h>
65 #endif
66
67 #if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
68 # include <sys/bsdskt.h>
69 typedef unsigned int uint32_t;
70 #endif
71
72 #if defined(LIBSSH2_WIN32) && defined(_MSC_VER) && (_MSC_VER <= 1400)
73 typedef unsigned __int64 libssh2_uint64_t;
74 typedef __int64 libssh2_int64_t;
75 typedef unsigned int uint32_t;
76 #ifndef _SSIZE_T_DEFINED
77 typedef int ssize_t;
78 #define _SSIZE_T_DEFINED
79 #endif
80 #else
81 typedef unsigned long long libssh2_uint64_t;
82 typedef long long libssh2_int64_t;
83 #endif
84
85 #define LIBSSH2_VERSION "0.18"
86
87 /* The numeric version number is also available "in parts" by using these
88 defines: */
89 #define LIBSSH2_VERSION_MAJOR 0
90 #define LIBSSH2_VERSION_MINOR 18
91 #define LIBSSH2_VERSION_PATCH
92
93 /* This is the numeric version of the libssh2 version number, meant for easier
94 parsing and comparions by programs. The LIBSSH2_VERSION_NUM define will
95 always follow this syntax:
96
97 0xXXYYZZ
98
99 Where XX, YY and ZZ are the main version, release and patch numbers in
100 hexadecimal (using 8 bits each). All three numbers are always represented
101 using two digits. 1.2 would appear as "0x010200" while version 9.11.7
102 appears as "0x090b07".
103
104 This 6-digit (24 bits) hexadecimal number does not show pre-release number,
105 and it is always a greater number in a more recent release. It makes
106 comparisons with greater than and less than work.
107 */
108 #define LIBSSH2_VERSION_NUM 0x001200
109
110 /*
111 * This is the date and time when the full source package was created. The
112 * timestamp is not stored in CVS, as the timestamp is properly set in the
113 * tarballs by the maketgz script.
114 *
115 * The format of the date should follow this template:
116 *
117 * "Mon Feb 12 11:35:33 UTC 2007"
118 */
119 #define LIBSSH2_TIMESTAMP "Sun Nov 11 10:41:38 UTC 2007"
120
121 /* Part of every banner, user specified or not */
122 #define LIBSSH2_SSH_BANNER "SSH-2.0-libssh2_" LIBSSH2_VERSION
123
124 /* We *could* add a comment here if we so chose */
125 #define LIBSSH2_SSH_DEFAULT_BANNER LIBSSH2_SSH_BANNER
126 #define LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF LIBSSH2_SSH_DEFAULT_BANNER "\r\n"
127
128 /* Default generate and safe prime sizes for diffie-hellman-group-exchange-sha1 */
129 #define LIBSSH2_DH_GEX_MINGROUP 1024
130 #define LIBSSH2_DH_GEX_OPTGROUP 1536
131 #define LIBSSH2_DH_GEX_MAXGROUP 2048
132
133 /* Defaults for pty requests */
134 #define LIBSSH2_TERM_WIDTH 80
135 #define LIBSSH2_TERM_HEIGHT 24
136 #define LIBSSH2_TERM_WIDTH_PX 0
137 #define LIBSSH2_TERM_HEIGHT_PX 0
138
139 /* 1/4 second */
140 #define LIBSSH2_SOCKET_POLL_UDELAY 250000
141 /* 0.25 * 120 == 30 seconds */
142 #define LIBSSH2_SOCKET_POLL_MAXLOOPS 120
143
144 /* Maximum size to allow a payload to compress to, plays it safe by falling short of spec limits */
145 #define LIBSSH2_PACKET_MAXCOMP 32000
146
147 /* Maximum size to allow a payload to deccompress to, plays it safe by allowing more than spec requires */
148 #define LIBSSH2_PACKET_MAXDECOMP 40000
149
150 /* Maximum size for an inbound compressed payload, plays it safe by overshooting spec limits */
151 #define LIBSSH2_PACKET_MAXPAYLOAD 40000
152
153 /* Malloc callbacks */
154 #define LIBSSH2_ALLOC_FUNC(name) void *name(size_t count, void **abstract)
155 #define LIBSSH2_REALLOC_FUNC(name) void *name(void *ptr, size_t count, void **abstract)
156 #define LIBSSH2_FREE_FUNC(name) void name(void *ptr, void **abstract)
157
158 typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT
159 {
160 char* text;
161 unsigned int length;
162 unsigned char echo;
163 } LIBSSH2_USERAUTH_KBDINT_PROMPT;
164
165 typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE
166 {
167 char* text;
168 unsigned int length;
169 } LIBSSH2_USERAUTH_KBDINT_RESPONSE;
170
171 /* 'keyboard-interactive' authentication callback */
172 #define LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(name_) void name_(const char* name, int name_len, const char* instruction, int instruction_len, int num_prompts, const LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts, LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses, void **abstract)
173
174 /* Callbacks for special SSH packets */
175 #define LIBSSH2_IGNORE_FUNC(name) void name(LIBSSH2_SESSION *session, const char *message, int message_len, void **abstract)
176 #define LIBSSH2_DEBUG_FUNC(name) void name(LIBSSH2_SESSION *session, int always_display, const char *message, int message_len, const char *language, int language_len,void **abstract)
177 #define LIBSSH2_DISCONNECT_FUNC(name) void name(LIBSSH2_SESSION *session, int reason, const char *message, int message_len, const char *language, int language_len, void **abstract)
178 #define LIBSSH2_PASSWD_CHANGEREQ_FUNC(name) void name(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, void **abstract)
179 #define LIBSSH2_MACERROR_FUNC(name) int name(LIBSSH2_SESSION *session, const char *packet, int packet_len, void **abstract)
180 #define LIBSSH2_X11_OPEN_FUNC(name) void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, const char *shost, int sport, void **abstract)
181
182 #define LIBSSH2_CHANNEL_CLOSE_FUNC(name) void name(LIBSSH2_SESSION *session, void **session_abstract, LIBSSH2_CHANNEL *channel, void **channel_abstract)
183
184 /* libssh2_session_callback_set() constants */
185 #define LIBSSH2_CALLBACK_IGNORE 0
186 #define LIBSSH2_CALLBACK_DEBUG 1
187 #define LIBSSH2_CALLBACK_DISCONNECT 2
188 #define LIBSSH2_CALLBACK_MACERROR 3
189 #define LIBSSH2_CALLBACK_X11 4
190
191 /* libssh2_session_method_pref() constants */
192 #define LIBSSH2_METHOD_KEX 0
193 #define LIBSSH2_METHOD_HOSTKEY 1
194 #define LIBSSH2_METHOD_CRYPT_CS 2
195 #define LIBSSH2_METHOD_CRYPT_SC 3
196 #define LIBSSH2_METHOD_MAC_CS 4
197 #define LIBSSH2_METHOD_MAC_SC 5
198 #define LIBSSH2_METHOD_COMP_CS 6
199 #define LIBSSH2_METHOD_COMP_SC 7
200 #define LIBSSH2_METHOD_LANG_CS 8
201 #define LIBSSH2_METHOD_LANG_SC 9
202
203 /* session.flags bits */
204 #define LIBSSH2_FLAG_SIGPIPE 0x00000001
205
206 typedef struct _LIBSSH2_SESSION LIBSSH2_SESSION;
207 typedef struct _LIBSSH2_CHANNEL LIBSSH2_CHANNEL;
208 typedef struct _LIBSSH2_LISTENER LIBSSH2_LISTENER;
209
210 typedef struct _LIBSSH2_POLLFD {
211 unsigned char type; /* LIBSSH2_POLLFD_* below */
212
213 union {
214 int socket; /* File descriptors -- examined with system select() call */
215 LIBSSH2_CHANNEL *channel; /* Examined by checking internal state */
216 LIBSSH2_LISTENER *listener; /* Read polls only -- are inbound connections waiting to be accepted? */
217 } fd;
218
219 unsigned long events; /* Requested Events */
220 unsigned long revents; /* Returned Events */
221 } LIBSSH2_POLLFD;
222
223 /* Poll FD Descriptor Types */
224 #define LIBSSH2_POLLFD_SOCKET 1
225 #define LIBSSH2_POLLFD_CHANNEL 2
226 #define LIBSSH2_POLLFD_LISTENER 3
227
228 /* Note: Win32 Doesn't actually have a poll() implementation, so some of these values are faked with select() data */
229 /* Poll FD events/revents -- Match sys/poll.h where possible */
230 #define LIBSSH2_POLLFD_POLLIN 0x0001 /* Data available to be read or connection available -- All */
231 #define LIBSSH2_POLLFD_POLLPRI 0x0002 /* Priority data available to be read -- Socket only */
232 #define LIBSSH2_POLLFD_POLLEXT 0x0002 /* Extended data available to be read -- Channel only */
233 #define LIBSSH2_POLLFD_POLLOUT 0x0004 /* Can may be written -- Socket/Channel */
234 /* revents only */
235 #define LIBSSH2_POLLFD_POLLERR 0x0008 /* Error Condition -- Socket */
236 #define LIBSSH2_POLLFD_POLLHUP 0x0010 /* HangUp/EOF -- Socket */
237 #define LIBSSH2_POLLFD_SESSION_CLOSED 0x0010 /* Session Disconnect */
238 #define LIBSSH2_POLLFD_POLLNVAL 0x0020 /* Invalid request -- Socket Only */
239 #define LIBSSH2_POLLFD_POLLEX 0x0040 /* Exception Condition -- Socket/Win32 */
240 #define LIBSSH2_POLLFD_CHANNEL_CLOSED 0x0080 /* Channel Disconnect */
241 #define LIBSSH2_POLLFD_LISTENER_CLOSED 0x0080 /* Listener Disconnect */
242
243 /* Hash Types */
244 #define LIBSSH2_HOSTKEY_HASH_MD5 1
245 #define LIBSSH2_HOSTKEY_HASH_SHA1 2
246
247 /* Disconnect Codes (defined by SSH protocol) */
248 #define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1
249 #define SSH_DISCONNECT_PROTOCOL_ERROR 2
250 #define SSH_DISCONNECT_KEY_EXCHANGE_FAILED 3
251 #define SSH_DISCONNECT_RESERVED 4
252 #define SSH_DISCONNECT_MAC_ERROR 5
253 #define SSH_DISCONNECT_COMPRESSION_ERROR 6
254 #define SSH_DISCONNECT_SERVICE_NOT_AVAILABLE 7
255 #define SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8
256 #define SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE 9
257 #define SSH_DISCONNECT_CONNECTION_LOST 10
258 #define SSH_DISCONNECT_BY_APPLICATION 11
259 #define SSH_DISCONNECT_TOO_MANY_CONNECTIONS 12
260 #define SSH_DISCONNECT_AUTH_CANCELLED_BY_USER 13
261 #define SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE 14
262 #define SSH_DISCONNECT_ILLEGAL_USER_NAME 15
263
264 /* Error Codes (defined by libssh2) */
265 #define LIBSSH2_ERROR_NONE 0
266 #define LIBSSH2_ERROR_SOCKET_NONE -1
267 #define LIBSSH2_ERROR_BANNER_NONE -2
268 #define LIBSSH2_ERROR_BANNER_SEND -3
269 #define LIBSSH2_ERROR_INVALID_MAC -4
270 #define LIBSSH2_ERROR_KEX_FAILURE -5
271 #define LIBSSH2_ERROR_ALLOC -6
272 #define LIBSSH2_ERROR_SOCKET_SEND -7
273 #define LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE -8
274 #define LIBSSH2_ERROR_TIMEOUT -9
275 #define LIBSSH2_ERROR_HOSTKEY_INIT -10
276 #define LIBSSH2_ERROR_HOSTKEY_SIGN -11
277 #define LIBSSH2_ERROR_DECRYPT -12
278 #define LIBSSH2_ERROR_SOCKET_DISCONNECT -13
279 #define LIBSSH2_ERROR_PROTO -14
280 #define LIBSSH2_ERROR_PASSWORD_EXPIRED -15
281 #define LIBSSH2_ERROR_FILE -16
282 #define LIBSSH2_ERROR_METHOD_NONE -17
283 #define LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED -18
284 #define LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED -19
285 #define LIBSSH2_ERROR_CHANNEL_OUTOFORDER -20
286 #define LIBSSH2_ERROR_CHANNEL_FAILURE -21
287 #define LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED -22
288 #define LIBSSH2_ERROR_CHANNEL_UNKNOWN -23
289 #define LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED -24
290 #define LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED -25
291 #define LIBSSH2_ERROR_CHANNEL_CLOSED -26
292 #define LIBSSH2_ERROR_CHANNEL_EOF_SENT -27
293 #define LIBSSH2_ERROR_SCP_PROTOCOL -28
294 #define LIBSSH2_ERROR_ZLIB -29
295 #define LIBSSH2_ERROR_SOCKET_TIMEOUT -30
296 #define LIBSSH2_ERROR_SFTP_PROTOCOL -31
297 #define LIBSSH2_ERROR_REQUEST_DENIED -32
298 #define LIBSSH2_ERROR_METHOD_NOT_SUPPORTED -33
299 #define LIBSSH2_ERROR_INVAL -34
300 #define LIBSSH2_ERROR_INVALID_POLL_TYPE -35
301 #define LIBSSH2_ERROR_PUBLICKEY_PROTOCOL -36
302 #define LIBSSH2_ERROR_EAGAIN -37
303
304 /* Session API */
305 LIBSSH2_API LIBSSH2_SESSION *libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)), LIBSSH2_FREE_FUNC((*my_free)), LIBSSH2_REALLOC_FUNC((*my_realloc)), void *abstract);
306 #define libssh2_session_init() libssh2_session_init_ex(NULL, NULL, NULL, NULL)
307 LIBSSH2_API void **libssh2_session_abstract(LIBSSH2_SESSION *session);
308
309 LIBSSH2_API void *libssh2_session_callback_set(LIBSSH2_SESSION *session, int cbtype, void *callback);
310 LIBSSH2_API int libssh2_banner_set(LIBSSH2_SESSION *session, const char *banner);
311
312 LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int sock);
313 LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reason, const char *description, const char *lang);
314 #define libssh2_session_disconnect(session, description) libssh2_session_disconnect_ex((session), SSH_DISCONNECT_BY_APPLICATION, (description), "")
315 LIBSSH2_API int libssh2_session_free(LIBSSH2_SESSION *session);
316
317 LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session, int hash_type);
318
319 LIBSSH2_API int libssh2_session_method_pref(LIBSSH2_SESSION *session, int method_type, const char *prefs);
320 LIBSSH2_API const char *libssh2_session_methods(LIBSSH2_SESSION *session, int method_type);
321 LIBSSH2_API int libssh2_session_last_error(LIBSSH2_SESSION *session, char **errmsg, int *errmsg_len, int want_buf);
322 LIBSSH2_API int libssh2_session_last_errno(LIBSSH2_SESSION *session);
323
324 LIBSSH2_API int libssh2_session_flag(LIBSSH2_SESSION *session, int flag, int value);
325
326 /* Userauth API */
327 LIBSSH2_API char *libssh2_userauth_list(LIBSSH2_SESSION *session, const char *username, unsigned int username_len);
328 LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION *session);
329 LIBSSH2_API int libssh2_userauth_password_ex(LIBSSH2_SESSION *session, const char *username, unsigned int username_len, const char *password, unsigned int password_len, LIBSSH2_PASSWD_CHANGEREQ_FUNC((*passwd_change_cb)));
330 #define libssh2_userauth_password(session, username, password) libssh2_userauth_password_ex((session), (username), strlen(username), (password), strlen(password), NULL)
331
332 LIBSSH2_API int libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session, const char *username, unsigned int username_len,
333 const char *publickey, const char *privatekey,
334 const char *passphrase);
335 #define libssh2_userauth_publickey_fromfile(session, username, publickey, privatekey, passphrase) \
336 libssh2_userauth_publickey_fromfile_ex((session), (username), strlen(username), (publickey), (privatekey), (passphrase))
337 LIBSSH2_API int libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session, const char *username, unsigned int username_len,
338 const char *publickey, const char *privatekey,
339 const char *passphrase,
340 const char *hostname, unsigned int hostname_len,
341 const char *local_username, unsigned int local_username_len);
342 #define libssh2_userauth_hostbased_fromfile(session, username, publickey, privatekey, passphrase, hostname) \
343 libssh2_userauth_hostbased_fromfile_ex((session), (username), strlen(username), (publickey), (privatekey), (passphrase), (hostname), strlen(hostname), (username), strlen(username))
344
345 /*
346 * response_callback is provided with filled by library prompts array,
347 * but client must allocate and fill individual responses. Responses
348 * array is already allocated. Responses data will be freed by libssh2
349 * after callback return, but before subsequent callback invokation.
350 */
351 LIBSSH2_API int libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION* session, const char *username, unsigned int username_len,
352 LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC((*response_callback)));
353 #define libssh2_userauth_keyboard_interactive(session, username, response_callback) \
354 libssh2_userauth_keyboard_interactive_ex((session), (username), strlen(username), (response_callback))
355
356 LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds, long timeout);
357
358 /* Channel API */
359 #define LIBSSH2_CHANNEL_WINDOW_DEFAULT 65536
360 #define LIBSSH2_CHANNEL_PACKET_DEFAULT 16384
361 #define LIBSSH2_CHANNEL_MINADJUST 1024
362
363 /* Extended Data Handling */
364 #define LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL 0
365 #define LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE 1
366 #define LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE 2
367
368 #define SSH_EXTENDED_DATA_STDERR 1
369
370 /* Returned by any function that would block during a read/write opperation */
371 #define LIBSSH2CHANNEL_EAGAIN LIBSSH2_ERROR_EAGAIN
372
373 LIBSSH2_API LIBSSH2_CHANNEL *libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *channel_type, unsigned int channel_type_len, unsigned int window_size, unsigned int packet_size, const char *message, unsigned int message_len);
374 #define libssh2_channel_open_session(session) libssh2_channel_open_ex((session), "session", sizeof("session") - 1, LIBSSH2_CHANNEL_WINDOW_DEFAULT, LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0)
375
376 LIBSSH2_API LIBSSH2_CHANNEL *libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host, int port, const char *shost, int sport);
377 #define libssh2_channel_direct_tcpip(session, host, port) libssh2_channel_direct_tcpip_ex((session), (host), (port), "127.0.0.1", 22)
378
379 LIBSSH2_API LIBSSH2_LISTENER *libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host, int port, int *bound_port, int queue_maxsize);
380 #define libssh2_channel_forward_listen(session, port) libssh2_channel_forward_listen_ex((session), NULL, (port), NULL, 16)
381
382 LIBSSH2_API int libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener);
383
384 LIBSSH2_API LIBSSH2_CHANNEL *libssh2_channel_forward_accept(LIBSSH2_LISTENER *listener);
385
386 LIBSSH2_API int libssh2_channel_setenv_ex(LIBSSH2_CHANNEL *channel, const char *varname, unsigned int varname_len, const char *value, unsigned int value_len);
387 #define libssh2_channel_setenv(channel, varname, value) libssh2_channel_setenv_ex((channel), (varname), strlen(varname), (value), strlen(value))
388
389 LIBSSH2_API int libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL *channel, const char *term, unsigned int term_len, const char *modes, unsigned int modes_len, int width, int height, int width_px, int height_px);
390 #define libssh2_channel_request_pty(channel, term) libssh2_channel_request_pty_ex((channel), (term), strlen(term), NULL, 0, LIBSSH2_TERM_WIDTH, LIBSSH2_TERM_HEIGHT, LIBSSH2_TERM_WIDTH_PX, LIBSSH2_TERM_HEIGHT_PX)
391
392 LIBSSH2_API int libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel, int single_connection, const char *auth_proto, const char *auth_cookie, int screen_number);
393 #define libssh2_channel_x11_req(channel, screen_number) libssh2_channel_x11_req_ex((channel), 0, NULL, NULL, (screen_number))
394
395 LIBSSH2_API int libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, const char *request, unsigned int request_len, const char *message, unsigned int message_len);
396 #define libssh2_channel_shell(channel) libssh2_channel_process_startup((channel), "shell", sizeof("shell") - 1, NULL, 0)
397 #define libssh2_channel_exec(channel, command) libssh2_channel_process_startup((channel), "exec", sizeof("exec") - 1, (command), strlen(command))
398 #define libssh2_channel_subsystem(channel, subsystem) libssh2_channel_process_startup((channel), "subsystem", sizeof("subsystem") - 1, (subsystem), strlen(subsystem))
399
400 LIBSSH2_API ssize_t libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel, int stream_id, char *buf, size_t buflen);
401 #define libssh2_channel_read(channel, buf, buflen) \
402 libssh2_channel_read_ex((channel), 0, (buf), (buflen))
403 #define libssh2_channel_read_stderr(channel, buf, buflen) \
404 libssh2_channel_read_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
405
406 LIBSSH2_API int libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel, int extended);
407
408 LIBSSH2_API unsigned long libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel, unsigned long *read_avail, unsigned long *window_size_initial);
409 #define libssh2_channel_window_read(channel) \
410 libssh2_channel_window_read_ex((channel), NULL, NULL)
411
412 LIBSSH2_API unsigned long libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel, unsigned long adjustment, unsigned char force);
413
414 LIBSSH2_API ssize_t libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel, int stream_id, const char *buf, size_t buflen);
415
416 #define libssh2_channel_write(channel, buf, buflen) \
417 libssh2_channel_write_ex((channel), 0, (buf), (buflen))
418 #define libssh2_channel_write_stderr(channel, buf, buflen) \
419 libssh2_channel_write_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
420
421 LIBSSH2_API unsigned long libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel, unsigned long *window_size_initial);
422 #define libssh2_channel_window_write(channel) libssh2_channel_window_write_ex((channel), NULL)
423
424 LIBSSH2_API void libssh2_session_set_blocking(LIBSSH2_SESSION* session, int blocking);
425 LIBSSH2_API int libssh2_session_get_blocking(LIBSSH2_SESSION* session);
426
427 LIBSSH2_API void libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel, int blocking);
428
429 LIBSSH2_API void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode);
430 LIBSSH2_API int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel, int ignore_mode);
431 /* libssh2_channel_ignore_extended_data() is defined below for BC with version 0.1
432 * Future uses should use libssh2_channel_handle_extended_data() directly
433 * if LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE is passed, extended data will be read (FIFO) from the standard data channel
434 */
435 /* DEPRECATED */
436 #define libssh2_channel_ignore_extended_data(channel, ignore) libssh2_channel_handle_extended_data((channel), (ignore) ? LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE : LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL )
437
438 #define LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA -1
439 #define LIBSSH2_CHANNEL_FLUSH_ALL -2
440 LIBSSH2_API int libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel, int streamid);
441 #define libssh2_channel_flush(channel) libssh2_channel_flush_ex((channel), 0)
442 #define libssh2_channel_flush_stderr(channel) libssh2_channel_flush_ex((channel), SSH_EXTENDED_DATA_STDERR)
443 LIBSSH2_API int libssh2_channel_get_exit_status(LIBSSH2_CHANNEL* channel);
444
445 LIBSSH2_API int libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel);
446 LIBSSH2_API int libssh2_channel_eof(LIBSSH2_CHANNEL *channel);
447 LIBSSH2_API int libssh2_channel_wait_eof(LIBSSH2_CHANNEL *channel);
448 LIBSSH2_API int libssh2_channel_close(LIBSSH2_CHANNEL *channel);
449 LIBSSH2_API int libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel);
450 LIBSSH2_API int libssh2_channel_free(LIBSSH2_CHANNEL *channel);
451
452 LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const char *path, struct stat *sb);
453 LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, size_t size, long mtime, long atime);
454 #define libssh2_scp_send(session, path, mode, size) libssh2_scp_send_ex((session), (path), (mode), (size), 0, 0)
455
456 LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest, unsigned int *dest_len, const char *src, unsigned int src_len);
457
458 /* NOTE NOTE NOTE
459 libssh2_trace() has no function in builds that aren't built with debug
460 enabled
461 */
462 LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask);
463 #define LIBSSH2_TRACE_TRANS (1<<1)
464 #define LIBSSH2_TRACE_KEX (1<<2)
465 #define LIBSSH2_TRACE_AUTH (1<<3)
466 #define LIBSSH2_TRACE_CONN (1<<4)
467 #define LIBSSH2_TRACE_SCP (1<<5)
468 #define LIBSSH2_TRACE_SFTP (1<<6)
469 #define LIBSSH2_TRACE_ERROR (1<<7)
470 #define LIBSSH2_TRACE_PUBLICKEY (1<<8)
471
472 #ifdef __cplusplus
473 } /* extern "C" */
474 #endif
475
476 #endif /* LIBSSH2_H */