libssh  0.5.4
Data Structures | Macros | Typedefs | Functions
The libssh callbacks

Callback which can be replaced in libssh. More...

Data Structures

struct  ssh_callbacks
 The structure to replace libssh functions with appropriate callbacks. More...
 
struct  ssh_socket_callbacks
 These are the callbacks exported by the socket structure They are called by the socket module when a socket event appears. More...
 

Macros

#define ssh_callbacks_init(p)
 Initializes an ssh_callbacks_struct A call to this macro is mandatory when you have set a new ssh_callback_struct structure. More...
 
#define SSH_PACKET_CALLBACK(name)   int name (ssh_session session, uint8_t type, ssh_buffer packet, void *user)
 This macro declares a packet callback handler. More...
 
#define SSH_PACKET_NOT_USED   2
 Packet was not used and should be passed to any other callback available.
 
#define SSH_PACKET_USED   1
 return values for a ssh_packet_callback More...
 

Typedefs

typedef int(* ssh_auth_callback )(const char *prompt, char *buf, size_t len, int echo, int verify, void *userdata)
 SSH authentication callback. More...
 
typedef void(* ssh_channel_close_callback )(ssh_session session, ssh_channel channel, void *userdata)
 SSH channel close callback. More...
 
typedef int(* ssh_channel_data_callback )(ssh_session session, ssh_channel channel, void *data, uint32_t len, int is_stderr, void *userdata)
 SSH channel data callback. More...
 
typedef void(* ssh_channel_eof_callback )(ssh_session session, ssh_channel channel, void *userdata)
 SSH channel eof callback. More...
 
typedef void(* ssh_channel_exit_signal_callback )(ssh_session session, ssh_channel channel, const char *signal, int core, const char *errmsg, const char *lang, void *userdata)
 SSH channel exit signal callback. More...
 
typedef void(* ssh_channel_exit_status_callback )(ssh_session session, ssh_channel channel, int exit_status, void *userdata)
 SSH channel exit status callback. More...
 
typedef void(* ssh_channel_signal_callback )(ssh_session session, ssh_channel channel, const char *signal, void *userdata)
 SSH channel signal callback. More...
 
typedef void(* ssh_global_request_callback )(ssh_session session, ssh_message message, void *userdata)
 SSH global request callback. More...
 
typedef void(* ssh_log_callback )(ssh_session session, int priority, const char *message, void *userdata)
 SSH log callback. More...
 
typedef int(* ssh_packet_callback )(ssh_session session, uint8_t type, ssh_buffer packet, void *user)
 Prototype for a packet callback, to be called when a new packet arrives. More...
 
typedef void(* ssh_status_callback )(ssh_session session, float status, void *userdata)
 SSH Connection status callback. More...
 

Functions

LIBSSH_API int ssh_set_callbacks (ssh_session session, ssh_callbacks cb)
 Set the session callback functions. More...
 
LIBSSH_API int ssh_set_channel_callbacks (ssh_channel channel, ssh_channel_callbacks cb)
 Set the channel callback functions. More...
 

Detailed Description

Callback which can be replaced in libssh.

Macro Definition Documentation

#define ssh_callbacks_init (   p)
Value:
do {\
(p)->size=sizeof(*(p)); \
} while(0);

Initializes an ssh_callbacks_struct A call to this macro is mandatory when you have set a new ssh_callback_struct structure.

Its goal is to maintain the binary compatibility with future versions of libssh as the structure evolves with time.

#define SSH_PACKET_CALLBACK (   name)    int name (ssh_session session, uint8_t type, ssh_buffer packet, void *user)

This macro declares a packet callback handler.

SSH_PACKET_CALLBACK(mycallback){
...
}
#define SSH_PACKET_USED   1

return values for a ssh_packet_callback

Packet was used and should not be parsed by another callback

Typedef Documentation

typedef int(* ssh_auth_callback)(const char *prompt, char *buf, size_t len, int echo, int verify, void *userdata)

SSH authentication callback.

Parameters
promptPrompt to be displayed.
bufBuffer to save the password. You should null-terminate it.
lenLength of the buffer.
echoEnable or disable the echo of what you type.
verifyShould the password be verified?
userdataUserdata to be passed to the callback function. Useful for GUI applications.
Returns
0 on success, < 0 on error.
typedef void(* ssh_channel_close_callback)(ssh_session session, ssh_channel channel, void *userdata)

SSH channel close callback.

Called when a channel is closed by remote peer

Parameters
sessionCurrent session handler
channelthe actual channel
userdataUserdata to be passed to the callback function.
typedef int(* ssh_channel_data_callback)(ssh_session session, ssh_channel channel, void *data, uint32_t len, int is_stderr, void *userdata)

SSH channel data callback.

Called when data is available on a channel

Parameters
sessionCurrent session handler
channelthe actual channel
datathe data that has been read on the channel
lenthe length of the data
is_stderris 0 for stdout or 1 for stderr
userdataUserdata to be passed to the callback function.
typedef void(* ssh_channel_eof_callback)(ssh_session session, ssh_channel channel, void *userdata)

SSH channel eof callback.

Called when a channel receives EOF

Parameters
sessionCurrent session handler
channelthe actual channel
userdataUserdata to be passed to the callback function.
typedef void(* ssh_channel_exit_signal_callback)(ssh_session session, ssh_channel channel, const char *signal, int core, const char *errmsg, const char *lang, void *userdata)

SSH channel exit signal callback.

Called when a channel has received an exit signal

Parameters
sessionCurrent session handler
channelthe actual channel
signalthe signal name (without the SIG prefix)
corea boolean telling wether a core has been dumped or not
errmsgthe description of the exception
langthe language of the description (format: RFC 3066)
userdataUserdata to be passed to the callback function.
typedef void(* ssh_channel_exit_status_callback)(ssh_session session, ssh_channel channel, int exit_status, void *userdata)

SSH channel exit status callback.

Called when a channel has received an exit status

Parameters
sessionCurrent session handler
channelthe actual channel
userdataUserdata to be passed to the callback function.
typedef void(* ssh_channel_signal_callback)(ssh_session session, ssh_channel channel, const char *signal, void *userdata)

SSH channel signal callback.

Called when a channel has received a signal

Parameters
sessionCurrent session handler
channelthe actual channel
signalthe signal name (without the SIG prefix)
userdataUserdata to be passed to the callback function.
typedef void(* ssh_global_request_callback)(ssh_session session, ssh_message message, void *userdata)

SSH global request callback.

All global request will go through this callback.

Parameters
sessionCurrent session handler
messagethe actual message
userdataUserdata to be passed to the callback function.
typedef void(* ssh_log_callback)(ssh_session session, int priority, const char *message, void *userdata)

SSH log callback.

All logging messages will go through this callback

Parameters
sessionCurrent session handler
priorityPriority of the log, the smaller being the more important
messagethe actual message
userdataUserdata to be passed to the callback function.
typedef int(* ssh_packet_callback)(ssh_session session, uint8_t type, ssh_buffer packet, void *user)

Prototype for a packet callback, to be called when a new packet arrives.

Parameters
sessionThe current session of the packet
typepacket type (see ssh2.h)
packetbuffer containing the packet, excluding size, type and padding fields
useruser argument to the callback and are called each time a packet shows up
Returns
SSH_PACKET_USED Packet was parsed and used
SSH_PACKET_NOT_USED Packet was not used or understood, processing must continue
typedef void(* ssh_status_callback)(ssh_session session, float status, void *userdata)

SSH Connection status callback.

Parameters
sessionCurrent session handler
statusPercentage of connection status, going from 0.0 to 1.0 once connection is done.
userdataUserdata to be passed to the callback function.

Function Documentation

LIBSSH_API int ssh_set_callbacks ( ssh_session  session,
ssh_callbacks  cb 
)

Set the session callback functions.

This functions sets the callback structure to use your own callback functions for auth, logging and status.

struct ssh_callbacks_struct cb = {
.userdata = data,
.auth_function = my_auth_function
};
ssh_set_callbacks(session, &cb);
Parameters
sessionThe session to set the callback structure.
cbThe callback structure itself.
Returns
SSH_OK on success, SSH_ERROR on error.
LIBSSH_API int ssh_set_channel_callbacks ( ssh_channel  channel,
ssh_channel_callbacks  cb 
)

Set the channel callback functions.

This functions sets the callback structure to use your own callback functions for channel data and exceptions

struct ssh_channel_callbacks_struct cb = {
.userdata = data,
.channel_data = my_channel_data_function
};
Parameters
channelThe channel to set the callback structure.
cbThe callback structure itself.
Returns
SSH_OK on success, SSH_ERROR on error.