libssh  0.5.4
callbacks.h
1 /*
2  * This file is part of the SSH Library
3  *
4  * Copyright (c) 2009 Aris Adamantiadis <aris@0xbadc0de.be>
5  *
6  * The SSH Library is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or (at your
9  * option) any later version.
10  *
11  * The SSH Library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with the SSH Library; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19  * MA 02111-1307, USA.
20  */
21 
22 /* callback.h
23  * This file includes the public declarations for the libssh callback mechanism
24  */
25 
26 #ifndef _SSH_CALLBACK_H
27 #define _SSH_CALLBACK_H
28 
29 #include <libssh/libssh.h>
30 #include <string.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
50 typedef void (*ssh_callback_int) (int code, void *user);
51 
60 typedef int (*ssh_callback_data) (const void *data, size_t len, void *user);
61 
62 typedef void (*ssh_callback_int_int) (int code, int errno_code, void *user);
63 
64 typedef int (*ssh_message_callback) (ssh_session, ssh_message message, void *user);
65 typedef int (*ssh_channel_callback_int) (ssh_channel channel, int code, void *user);
66 typedef int (*ssh_channel_callback_data) (ssh_channel channel, int code, void *data, size_t len, void *user);
81 typedef int (*ssh_auth_callback) (const char *prompt, char *buf, size_t len,
82  int echo, int verify, void *userdata);
90 typedef void (*ssh_log_callback) (ssh_session session, int priority,
91  const char *message, void *userdata);
92 
100 typedef void (*ssh_status_callback) (ssh_session session, float status,
101  void *userdata);
102 
110 typedef void (*ssh_global_request_callback) (ssh_session session,
111  ssh_message message, void *userdata);
112 
118  size_t size;
122  void *userdata;
135  void (*connect_status_function)(void *userdata, float status);
140 };
141 typedef struct ssh_callbacks_struct *ssh_callbacks;
142 
151  void *userdata;
156  ssh_callback_data data;
160  ssh_callback_int controlflow;
164  ssh_callback_int_int exception;
168  ssh_callback_int_int connected;
169 };
170 typedef struct ssh_socket_callbacks_struct *ssh_socket_callbacks;
171 
172 #define SSH_SOCKET_FLOW_WRITEWILLBLOCK 1
173 #define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
174 
175 #define SSH_SOCKET_EXCEPTION_EOF 1
176 #define SSH_SOCKET_EXCEPTION_ERROR 2
177 
178 #define SSH_SOCKET_CONNECTED_OK 1
179 #define SSH_SOCKET_CONNECTED_ERROR 2
180 #define SSH_SOCKET_CONNECTED_TIMEOUT 3
181 
189 #define ssh_callbacks_init(p) do {\
190  (p)->size=sizeof(*(p)); \
191 } while(0);
192 
202 #define ssh_callbacks_exists(p,c) (\
203  (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
204  ((p)-> c != NULL) \
205  )
206 
216 typedef int (*ssh_packet_callback) (ssh_session session, uint8_t type, ssh_buffer packet, void *user);
217 
220 #define SSH_PACKET_USED 1
221 
223 #define SSH_PACKET_NOT_USED 2
224 
225 
233 #define SSH_PACKET_CALLBACK(name) \
234  int name (ssh_session session, uint8_t type, ssh_buffer packet, void *user)
235 
236 struct ssh_packet_callbacks_struct {
238  uint8_t start;
240  uint8_t n_callbacks;
242  ssh_packet_callback *callbacks;
246  void *user;
247 };
248 
249 typedef struct ssh_packet_callbacks_struct *ssh_packet_callbacks;
250 
272 LIBSSH_API int ssh_set_callbacks(ssh_session session, ssh_callbacks cb);
273 
283 typedef int (*ssh_channel_data_callback) (ssh_session session,
284  ssh_channel channel,
285  void *data,
286  uint32_t len,
287  int is_stderr,
288  void *userdata);
289 
296 typedef void (*ssh_channel_eof_callback) (ssh_session session,
297  ssh_channel channel,
298  void *userdata);
299 
306 typedef void (*ssh_channel_close_callback) (ssh_session session,
307  ssh_channel channel,
308  void *userdata);
309 
317 typedef void (*ssh_channel_signal_callback) (ssh_session session,
318  ssh_channel channel,
319  const char *signal,
320  void *userdata);
321 
328 typedef void (*ssh_channel_exit_status_callback) (ssh_session session,
329  ssh_channel channel,
330  int exit_status,
331  void *userdata);
332 
343 typedef void (*ssh_channel_exit_signal_callback) (ssh_session session,
344  ssh_channel channel,
345  const char *signal,
346  int core,
347  const char *errmsg,
348  const char *lang,
349  void *userdata);
350 
351 struct ssh_channel_callbacks_struct {
353  size_t size;
357  void *userdata;
361  ssh_channel_data_callback channel_data_function;
365  ssh_channel_eof_callback channel_eof_function;
369  ssh_channel_close_callback channel_close_function;
373  ssh_channel_signal_callback channel_signal_function;
377  ssh_channel_exit_status_callback channel_exit_status_function;
381  ssh_channel_exit_signal_callback channel_exit_signal_function;
382 };
383 typedef struct ssh_channel_callbacks_struct *ssh_channel_callbacks;
384 
406 LIBSSH_API int ssh_set_channel_callbacks(ssh_channel channel,
407  ssh_channel_callbacks cb);
408 
415 typedef int (*ssh_thread_callback) (void **lock);
416 
417 typedef unsigned long (*ssh_thread_id_callback) (void);
418 struct ssh_threads_callbacks_struct {
419  const char *type;
420  ssh_thread_callback mutex_init;
421  ssh_thread_callback mutex_destroy;
422  ssh_thread_callback mutex_lock;
423  ssh_thread_callback mutex_unlock;
424  ssh_thread_id_callback thread_id;
425 };
426 
437 LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct
438  *cb);
439 
446 LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_pthread(void);
447 
454 LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_noop(void);
455 
457 #ifdef __cplusplus
458 }
459 #endif
460 
461 #endif /*_SSH_CALLBACK_H */
462 
463 /* @} */