From 5bd38a5f376772cc4be5d59d8cfa9a6ff9a517cf Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Wed, 23 Sep 2009 21:30:56 +0200 Subject: Changed the current callback sys to be scalable --- include/libssh/callback.h | 42 ++++++++++++++++++++++++++++++++---------- include/libssh/libssh.h | 25 ------------------------- include/libssh/priv.h | 10 +++------- 3 files changed, 35 insertions(+), 42 deletions(-) (limited to 'include') diff --git a/include/libssh/callback.h b/include/libssh/callback.h index 759db0e..3e1a1fa 100644 --- a/include/libssh/callback.h +++ b/include/libssh/callback.h @@ -23,21 +23,43 @@ * This file includes the declarations for the libssh callback mechanism */ +#ifndef _SSH_CALLBACK_H +#define _SSH_CALLBACK_H + #include "libssh.h" -typedef int (*ssh_callback_int) (ssh_session session, void *user, int code); -typedef int (*ssh_message_callback) (ssh_session, void *user, ssh_message message); -typedef int (*ssh_channel_callback_int) (ssh_channel channel, void *user, int code); -typedef int (*ssh_channel_callback_data) (ssh_channel channel, void *user, int code, void *data, int len); +/** + * @brief SSH authentication callback. + * + * @param prompt Prompt to be displayed. + * @param buf Buffer to save the password. You should null-terminate it. + * @param len Length of the buffer. + * @param echo Enable or disable the echo of what you type. + * @param verify Should the password be verified? + * @param userdata Userdata to be passed to the callback function. Useful + * for GUI applications. + * + * @return 0 on success, < 0 on error. + */ +typedef int (*ssh_auth_callback) (const char *prompt, char *buf, size_t len, + int echo, int verify, void *userdata); +typedef void (*ssh_log_callback) (ssh_session session, int priority, + const char *message, void *userdata); struct ssh_callbacks_struct { - ssh_callback_int connection_progress; - void *connection_progress_user; - ssh_channel_callback_int channel_write_confirm; - void *channel_write_confirm_user; - ssh_channel_callback_data channel_read_available; - void *channel_read_available_user; + size_t size; /* size of this structure */ + void *userdata; /* User-provided data */ + ssh_auth_callback auth_function; /* this functions will be called if e.g. a keyphrase is needed. */ + ssh_log_callback log_function; //log callback + void (*connect_status_function)(void *arg, float status); /* status callback function */ }; typedef struct ssh_callbacks_struct * ssh_callbacks; +LIBSSH_API int ssh_options_set_auth_callback(SSH_OPTIONS *opt, ssh_auth_callback cb, + void *userdata); +LIBSSH_API int ssh_options_set_log_function(SSH_OPTIONS *opt, + ssh_log_callback cb, void *userdata); +LIBSSH_API int ssh_options_set_status_callback(SSH_OPTIONS *opt, void (*callback) + (void *arg, float status), void *arg); +#endif /*_SSH_CALLBACK_H */ diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h index 0b1bf49..10103e5 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h @@ -292,25 +292,6 @@ enum ssh_scp_request_types { SSH_SCP_REQUEST_WARNING }; -/** - * @brief SSH authentication callback. - * - * @param prompt Prompt to be displayed. - * @param buf Buffer to save the password. You should null-terminate it. - * @param len Length of the buffer. - * @param echo Enable or disable the echo of what you type. - * @param verify Should the password be verified? - * @param userdata Userdata to be passed to the callback function. Useful - * for GUI applications. - * - * @return 0 on success, < 0 on error. - */ -typedef int (*ssh_auth_callback) (const char *prompt, char *buf, size_t len, - int echo, int verify, void *userdata); -typedef void (*ssh_log_callback) (ssh_session session, int priority, - const char *message, void *userdata); - - LIBSSH_API void buffer_free(ssh_buffer buffer); LIBSSH_API void *buffer_get(ssh_buffer buffer); LIBSSH_API uint32_t buffer_get_len(ssh_buffer buffer); @@ -406,23 +387,17 @@ LIBSSH_API int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **arg LIBSSH_API int ssh_options_parse_config(SSH_OPTIONS *opt, const char *filename); LIBSSH_API int ssh_options_set(ssh_options opt, enum ssh_options_e type, const void *value); -LIBSSH_API int ssh_options_set_auth_callback(SSH_OPTIONS *opt, ssh_auth_callback cb, - void *userdata); LIBSSH_API int ssh_options_set_banner(SSH_OPTIONS *opt, const char *banner); LIBSSH_API int ssh_options_set_bind(SSH_OPTIONS *opt, const char *bindaddr, int port); LIBSSH_API int ssh_options_set_dsa_server_key(SSH_OPTIONS *opt, const char *dsakey); LIBSSH_API int ssh_options_set_fd(SSH_OPTIONS *opt, socket_t fd); LIBSSH_API int ssh_options_set_host(SSH_OPTIONS *opt, const char *host); LIBSSH_API int ssh_options_set_identity(SSH_OPTIONS *opt, const char *identity); -LIBSSH_API int ssh_options_set_log_function(SSH_OPTIONS *opt, - ssh_log_callback cb, void *userdata); LIBSSH_API int ssh_options_set_log_verbosity(SSH_OPTIONS *opt, int verbosity); LIBSSH_API int ssh_options_set_known_hosts_file(SSH_OPTIONS *opt, const char *dir); LIBSSH_API int ssh_options_set_port(SSH_OPTIONS *opt, unsigned int port); LIBSSH_API int ssh_options_set_rsa_server_key(SSH_OPTIONS *opt, const char *rsakey); LIBSSH_API int ssh_options_set_ssh_dir(SSH_OPTIONS *opt, const char *dir); -LIBSSH_API int ssh_options_set_status_callback(SSH_OPTIONS *opt, void (*callback) - (void *arg, float status), void *arg); LIBSSH_API int ssh_options_set_timeout(SSH_OPTIONS *opt, long seconds, long usec); LIBSSH_API int ssh_options_set_username(SSH_OPTIONS *opt, const char *username); LIBSSH_API int ssh_options_set_wanted_algos(SSH_OPTIONS *opt, int algo, const char *list); diff --git a/include/libssh/priv.h b/include/libssh/priv.h index 1d5414b..87bf1bf 100644 --- a/include/libssh/priv.h +++ b/include/libssh/priv.h @@ -45,7 +45,7 @@ #include "config.h" #include "libssh/libssh.h" - +#include "libssh/callback.h" /* some constants */ #define MAX_PACKET_LEN 262144 #define ERROR_BUFFERLEN 1024 @@ -285,10 +285,7 @@ struct ssh_options_struct { int use_nonexisting_algo; /* if user sets a not supported algorithm for kex, don't complain */ char *wanted_methods[10]; /* the kex methods can be choosed. better use the kex fonctions to do that */ void *wanted_cookie; /* wants a specific cookie to be sent ? if null, generate a new one */ - ssh_auth_callback auth_function; /* this functions will be called if e.g. a keyphrase is needed. */ - void *auth_userdata; - void (*connect_status_function)(void *arg, float status); /* status callback function */ - void *connect_status_arg; /* arbitrary argument */ + ssh_callbacks callbacks; /* Callbacks to user functions */ long timeout; /* seconds */ long timeout_usec; int ssh2allowed; @@ -296,8 +293,7 @@ struct ssh_options_struct { char *dsakey; char *rsakey; /* host key for server implementation */ int log_verbosity; - ssh_log_callback log_function; //log callback - void *log_userdata; + }; typedef struct ssh_crypto_struct { -- cgit v1.2.3