libssh 0.5.2
include/libssh/callbacks.h
00001 /*
00002  * This file is part of the SSH Library
00003  *
00004  * Copyright (c) 2009 Aris Adamantiadis <aris@0xbadc0de.be>
00005  *
00006  * The SSH Library is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 2.1 of the License, or (at your
00009  * option) any later version.
00010  *
00011  * The SSH Library is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00013  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00014  * License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with the SSH Library; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00019  * MA 02111-1307, USA.
00020  */
00021 
00022 /* callback.h
00023  * This file includes the public declarations for the libssh callback mechanism
00024  */
00025 
00026 #ifndef _SSH_CALLBACK_H
00027 #define _SSH_CALLBACK_H
00028 
00029 #include <libssh/libssh.h>
00030 #include <string.h>
00031 
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif
00035 
00050 typedef void (*ssh_callback_int) (int code, void *user);
00051 
00060 typedef int (*ssh_callback_data) (const void *data, size_t len, void *user);
00061 
00062 typedef void (*ssh_callback_int_int) (int code, int errno_code, void *user);
00063 
00064 typedef int (*ssh_message_callback) (ssh_session, ssh_message message, void *user);
00065 typedef int (*ssh_channel_callback_int) (ssh_channel channel, int code, void *user);
00066 typedef int (*ssh_channel_callback_data) (ssh_channel channel, int code, void *data, size_t len, void *user);
00081 typedef int (*ssh_auth_callback) (const char *prompt, char *buf, size_t len,
00082     int echo, int verify, void *userdata);
00090 typedef void (*ssh_log_callback) (ssh_session session, int priority,
00091     const char *message, void *userdata);
00092 
00100 typedef void (*ssh_status_callback) (ssh_session session, float status,
00101     void *userdata);
00102 
00110 typedef void (*ssh_global_request_callback) (ssh_session session,
00111                                         ssh_message message, void *userdata);
00112 
00116 struct ssh_callbacks_struct {
00118   size_t size;
00122   void *userdata;
00126   ssh_auth_callback auth_function;
00130   ssh_log_callback log_function;
00135   void (*connect_status_function)(void *userdata, float status);
00139   ssh_global_request_callback global_request_function;
00140 };
00141 typedef struct ssh_callbacks_struct *ssh_callbacks;
00142 
00147 struct ssh_socket_callbacks_struct {
00151   void *userdata;
00156   ssh_callback_data data;
00160   ssh_callback_int controlflow;
00164   ssh_callback_int_int exception;
00168   ssh_callback_int_int connected;
00169 };
00170 typedef struct ssh_socket_callbacks_struct *ssh_socket_callbacks;
00171 
00172 #define SSH_SOCKET_FLOW_WRITEWILLBLOCK 1
00173 #define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
00174 
00175 #define SSH_SOCKET_EXCEPTION_EOF       1
00176 #define SSH_SOCKET_EXCEPTION_ERROR     2
00177 
00178 #define SSH_SOCKET_CONNECTED_OK       1
00179 #define SSH_SOCKET_CONNECTED_ERROR    2
00180 #define SSH_SOCKET_CONNECTED_TIMEOUT  3
00181 
00189 #define ssh_callbacks_init(p) do {\
00190   (p)->size=sizeof(*(p)); \
00191 } while(0);
00192 
00202 #define ssh_callbacks_exists(p,c) (\
00203   (p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
00204   ((p)-> c != NULL) \
00205   )
00206 
00216 typedef int (*ssh_packet_callback) (ssh_session session, uint8_t type, ssh_buffer packet, void *user);
00217 
00220 #define SSH_PACKET_USED 1
00221 
00223 #define SSH_PACKET_NOT_USED 2
00224 
00225 
00233 #define SSH_PACKET_CALLBACK(name) \
00234   int name (ssh_session session, uint8_t type, ssh_buffer packet, void *user)
00235 
00236 struct ssh_packet_callbacks_struct {
00238   uint8_t start;
00240   uint8_t n_callbacks;
00242   ssh_packet_callback *callbacks;
00246   void *user;
00247 };
00248 
00249 typedef struct ssh_packet_callbacks_struct *ssh_packet_callbacks;
00250 
00272 LIBSSH_API int ssh_set_callbacks(ssh_session session, ssh_callbacks cb);
00273 
00283 typedef int (*ssh_channel_data_callback) (ssh_session session,
00284                                            ssh_channel channel,
00285                                            void *data,
00286                                            uint32_t len,
00287                                            int is_stderr,
00288                                            void *userdata);
00289 
00296 typedef void (*ssh_channel_eof_callback) (ssh_session session,
00297                                            ssh_channel channel,
00298                                            void *userdata);
00299 
00306 typedef void (*ssh_channel_close_callback) (ssh_session session,
00307                                             ssh_channel channel,
00308                                             void *userdata);
00309 
00317 typedef void (*ssh_channel_signal_callback) (ssh_session session,
00318                                             ssh_channel channel,
00319                                             const char *signal,
00320                                             void *userdata);
00321 
00328 typedef void (*ssh_channel_exit_status_callback) (ssh_session session,
00329                                             ssh_channel channel,
00330                                             int exit_status,
00331                                             void *userdata);
00332 
00343 typedef void (*ssh_channel_exit_signal_callback) (ssh_session session,
00344                                             ssh_channel channel,
00345                                             const char *signal,
00346                                             int core,
00347                                             const char *errmsg,
00348                                             const char *lang,
00349                                             void *userdata);
00350 
00351 struct ssh_channel_callbacks_struct {
00353   size_t size;
00357   void *userdata;
00361   ssh_channel_data_callback channel_data_function;
00365   ssh_channel_eof_callback channel_eof_function;
00369   ssh_channel_close_callback channel_close_function;
00373   ssh_channel_signal_callback channel_signal_function;
00377   ssh_channel_exit_status_callback channel_exit_status_function;
00381   ssh_channel_exit_signal_callback channel_exit_signal_function;
00382 };
00383 typedef struct ssh_channel_callbacks_struct *ssh_channel_callbacks;
00384 
00406 LIBSSH_API int ssh_set_channel_callbacks(ssh_channel channel,
00407                                          ssh_channel_callbacks cb);
00408 
00415 typedef int (*ssh_thread_callback) (void **lock);
00416 
00417 typedef unsigned long (*ssh_thread_id_callback) (void);
00418 struct ssh_threads_callbacks_struct {
00419   const char *type;
00420   ssh_thread_callback mutex_init;
00421   ssh_thread_callback mutex_destroy;
00422   ssh_thread_callback mutex_lock;
00423   ssh_thread_callback mutex_unlock;
00424   ssh_thread_id_callback thread_id;
00425 };
00426 
00437 LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct
00438     *cb);
00439 
00446 LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_pthread(void);
00447 
00454 LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_noop(void);
00455 
00457 #ifdef __cplusplus
00458 }
00459 #endif
00460 
00461 #endif /*_SSH_CALLBACK_H */
00462 
00463 /* @} */