diff --git a/README b/README index 2b3ac27..dffe5e7 100644 --- a/README +++ b/README @@ -20,6 +20,8 @@ Version 0.2 LIBSSH2_CHANNEL_FLUSH_ALL Flush all streams LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA Flush all streams EXCEPT the standard data stream + Added libssh2_session_callback_set() for setting ignore/debug/disconnect/macerror callbacks + Version 0.1 ----------- diff --git a/include/libssh2.h b/include/libssh2.h index 392fb48..6faab1a 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -43,7 +43,7 @@ #include #define LIBSSH2_VERSION "0.1" -#define LIBSSH2_APINO 200412080954 +#define LIBSSH2_APINO 200412091007 /* Part of every banner, user specified or not */ #define LIBSSH2_SSH_BANNER "SSH-2.0-libssh2_" LIBSSH2_VERSION @@ -89,6 +89,12 @@ #define LIBSSH2_PASSWD_CHANGEREQ_FUNC(name) void name(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, void **abstract) #define LIBSSH2_MACERROR_FUNC(name) int name(LIBSSH2_SESSION *session, const char *packet, int packet_len, void **abstract) +/* libssh2_session_callback_set() constants */ +#define LIBSSH2_CALLBACK_IGNORE 0 +#define LIBSSH2_CALLBACK_DEBUG 1 +#define LIBSSH2_CALLBACK_DISCONNECT 2 +#define LIBSSH2_CALLBACK_MACERROR 3 + typedef struct _LIBSSH2_SESSION LIBSSH2_SESSION; typedef struct _LIBSSH2_CHANNEL LIBSSH2_CHANNEL; @@ -154,6 +160,8 @@ typedef struct _LIBSSH2_CHANNEL LIBSSH2_CHANNEL; 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); #define libssh2_session_init() libssh2_session_init_ex(NULL, NULL, NULL, NULL) +LIBSSH2_API void *libssh2_session_callback_set(LIBSSH2_SESSION *session, int cbtype, void *callback); + LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int socket); LIBSSH2_API void libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reason, char *description, char *lang); #define libssh2_session_disconnect(session, description) libssh2_session_disconnect_ex((session), SSH_DISCONNECT_BY_APPLICATION, (description), "") diff --git a/src/session.c b/src/session.c index 0be6a79..d4fc505 100644 --- a/src/session.c +++ b/src/session.c @@ -160,6 +160,41 @@ LIBSSH2_API LIBSSH2_SESSION *libssh2_session_init_ex( } /* }}} */ +/* {{{ libssh2_session_callback_set + * Set (or reset) a callback function + * Returns the prior address + */ +LIBSSH2_API void* libssh2_session_callback_set(LIBSSH2_SESSION *session, int cbtype, void *callback) +{ + void *oldcb; + + switch (cbtype) { + case LIBSSH2_CALLBACK_IGNORE: + oldcb = session->ssh_msg_ignore; + session->ssh_msg_ignore = callback; + return oldcb; + break; + case LIBSSH2_CALLBACK_DEBUG: + oldcb = session->ssh_msg_debug; + session->ssh_msg_debug = callback; + return oldcb; + break; + case LIBSSH2_CALLBACK_DISCONNECT: + oldcb = session->ssh_msg_disconnect; + session->ssh_msg_disconnect = callback; + return oldcb; + break; + case LIBSSH2_CALLBACK_MACERROR: + oldcb = session->macerror; + session->macerror = callback; + return oldcb; + break; + } + + return NULL; +} +/* }}} */ + /* {{{ proto libssh2_session_startup * session: LIBSSH2_SESSION struct allocated and owned by the calling program * Returns: 0 on success, or non-zero on failure