mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-06 10:27:22 +09:00
Squashed commit of the following:
commit 43fad8dfd977637c31fade76ace2905f6528c3bc Author: Aris Adamantiadis <aris@0xbadc0de.be> Date: Fri Nov 27 18:39:06 2009 +0100 adaptation to the new ssh_poll_handle object name commit 1e5e6ac4605adf10d437d04f0fd4b7e66024853c Merge: 3fd92a0... 810adad... Author: Aris Adamantiadis <aris@0xbadc0de.be> Date: Fri Nov 27 18:33:06 2009 +0100 Merge branch 'master' into badcode/libssh_async commit 3fd92a08eb74b1447a9ff4ca4e1d137475c62cc6 Author: Aris Adamantiadis <aris@0xbadc0de.be> Date: Mon Nov 2 14:25:46 2009 +0100 Compiles again commit 8910d7b9692418c9ccea0234f6d49674d238dc16 Merge: e83f1b5... cce34a6... Author: Aris Adamantiadis <aris@0xbadc0de.be> Date: Mon Nov 2 12:47:34 2009 +0100 Merge branch 'master' into libssh_async Very big merge ! Conflicts: include/libssh/callbacks.h include/libssh/priv.h libssh/channels.c libssh/messages.c libssh/packet.c libssh/server.c libssh/session.c libssh/socket.c commit e83f1b593219e183082b015315f09bfe95a29cfc Author: Aris Adamantiadis <aris@0xbadc0de.be> Date: Mon Nov 2 12:07:01 2009 +0100 rename callback.h commit dffa7b730e8f39e2198de18ab69a8e57bef95e58 Merge: 5a8b748... de8808c... Author: Aris Adamantiadis <aris@0xbadc0de.be> Date: Tue Sep 15 10:50:07 2009 +0200 Merge branch 'master' of git://git.libssh.org/projects/libssh/libssh into libssh_async commit 5a8b7484f36599d28f2c0c14a23b76bfc7257638 Author: Aris Adamantiadis <aris@0xbadc0de.be> Date: Sun Sep 13 12:55:18 2009 +0200 More updates to callback system commit 18620c20d5e4e62107093f7fd330e553493253fa Author: Aris Adamantiadis <aris@0xbadc0de.be> Date: Sat Sep 12 22:26:52 2009 +0200 Same thing with channel_rcv_data commit fc4a56f6726e409a5866272923f1cbebfc821af3 Author: Aris Adamantiadis <aris@0xbadc0de.be> Date: Sat Sep 12 22:17:45 2009 +0200 added a few packet handlers for channels commit 4b6bb4fd00b10cf1321a764126f277ab204bffe3 Author: Aris Adamantiadis <aris@0xbadc0de.be> Date: Fri Sep 11 23:15:25 2009 +0300 sample packet handlers + bugfixes commit 2784d09d6dec0a8f868912d14f90d860233b3f82 Author: Aris Adamantiadis <aris@0xbadc0de.be> Date: Fri Sep 11 20:30:50 2009 +0300 Packet callbacks nearly finished Need tests and implementation of some packet callbacks commit cd3ea43f20c9ae2f54576ca98a0ea75c5d4299d3 Author: Aris Adamantiadis <aris@0xbadc0de.be> Date: Thu Sep 10 12:46:02 2009 +0300 First step of async packet handling The socket to packet handler is nearly done (needs testing) I still need to define the interface for callbacks. commit 487f4d2a900a5fe3b90ceda4460ab7d38d7ad722 Author: Aris Adamantiadis <aris@0xbadc0de.be> Date: Tue Sep 8 23:24:09 2009 +0300 Almost complete socket callback system Finished the callback function so it bufferizes data when callee does not use it. Flushes the buffer automaticaly after a ssh_socket_nonblocking_flush commit 23571f22fac9e40c855dfa99569bba181a39648b Author: Aris Adamantiadis <aris@0xbadc0de.be> Date: Tue Sep 8 22:22:32 2009 +0300 First draft of a callback system
This commit is contained in:
@@ -32,7 +32,21 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
typedef void (*ssh_callback_int) (void *user, int code);
|
||||
/** @internal
|
||||
* @brief callback for data received messages.
|
||||
* @param user user-supplied pointer sent along with all callback messages
|
||||
* @param data data retrieved from the socket or stream
|
||||
* @param len number of bytes available from this stream
|
||||
* @returns number of bytes processed by the callee. The remaining bytes will
|
||||
* be sent in the next callback message, when more data is available.
|
||||
*/
|
||||
typedef int (*ssh_callback_data) (void *user, const void *data, size_t len);
|
||||
typedef void (*ssh_callback_int_int) (void *user, int code, int errno_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, size_t len);
|
||||
/**
|
||||
* @brief SSH authentication callback.
|
||||
*
|
||||
@@ -68,9 +82,36 @@ struct ssh_callbacks_struct {
|
||||
* of connection steps completed.
|
||||
*/
|
||||
void (*connect_status_function)(void *userdata, float status);
|
||||
/* To be cleaned up */
|
||||
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;
|
||||
};
|
||||
typedef struct ssh_callbacks_struct *ssh_callbacks;
|
||||
|
||||
typedef struct ssh_callbacks_struct * ssh_callbacks;
|
||||
/* This are the callbacks exported by the socket structure
|
||||
* They are called by the socket module when a socket event appears
|
||||
*/
|
||||
struct ssh_socket_callbacks_struct {
|
||||
ssh_callback_data data;
|
||||
ssh_callback_int controlflow;
|
||||
ssh_callback_int_int exception;
|
||||
ssh_callback_int_int connected;
|
||||
void *user;
|
||||
};
|
||||
typedef struct ssh_socket_callbacks_struct *ssh_socket_callbacks;
|
||||
|
||||
#define SSH_SOCKET_FLOW_WRITEWILLBLOCK (1<<0)
|
||||
#define SSH_SOCKET_FLOW_WRITEWONTBLOCK (1<<1)
|
||||
#define SSH_SOCKET_EXCEPTION_EOF (1<<0)
|
||||
#define SSH_SOCKET_EXCEPTION_ERROR (1<<1)
|
||||
|
||||
#define SSH_SOCKET_CONNECTED_OK (1<<0)
|
||||
#define SSH_SOCKET_CONNECTED_ERROR (1<<1)
|
||||
#define SSH_SOCKET_CONNECTED_TIMEOUT (1<<2)
|
||||
|
||||
/** Initializes an ssh_callbacks_struct
|
||||
* A call to this macro is mandatory when you have set a new
|
||||
@@ -82,6 +123,21 @@ typedef struct ssh_callbacks_struct * ssh_callbacks;
|
||||
(p)->size=sizeof(*(p)); \
|
||||
} while(0);
|
||||
|
||||
/* These are the callback exported by the packet layer
|
||||
* and are called each time a packet shows up
|
||||
* */
|
||||
typedef int (*ssh_packet_callback) (ssh_session, void *user, uint8_t code, ssh_buffer packet);
|
||||
|
||||
struct ssh_packet_callbacks_struct {
|
||||
/** Index of the first packet type being handled */
|
||||
u_int8_t start;
|
||||
/** Number of packets being handled by this callback struct */
|
||||
u_int8_t n_callbacks;
|
||||
/** A pointer to n_callbacks packet callbacks */
|
||||
ssh_packet_callback *callbacks;
|
||||
void *user;
|
||||
};
|
||||
typedef struct ssh_packet_callbacks_struct *ssh_packet_callbacks;
|
||||
/**
|
||||
* @brief Set the callback functions.
|
||||
*
|
||||
@@ -106,6 +162,12 @@ typedef struct ssh_callbacks_struct * ssh_callbacks;
|
||||
*/
|
||||
LIBSSH_API int ssh_set_callbacks(ssh_session session, ssh_callbacks cb);
|
||||
|
||||
/** return values for a ssh_packet_callback */
|
||||
/** Packet was used and should not be parsed by another callback */
|
||||
#define SSH_PACKET_USED 1
|
||||
/** Packet was not used and should be passed to any other callback
|
||||
* available */
|
||||
#define SSH_PACKET_NOT_USED 2
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -78,7 +78,7 @@ struct ssh_message_struct {
|
||||
};
|
||||
|
||||
|
||||
void message_handle(ssh_session session, uint32_t type);
|
||||
//void message_handle(ssh_session session, uint32_t type);
|
||||
int ssh_execute_message_callbacks(ssh_session session);
|
||||
|
||||
#endif /* MESSAGES_H_ */
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "libssh/libssh.h"
|
||||
#include "libssh/callbacks.h"
|
||||
#include "libssh/crypto.h"
|
||||
|
||||
/* some constants */
|
||||
#define MAX_PACKET_LEN 262144
|
||||
#define ERROR_BUFFERLEN 1024
|
||||
@@ -90,7 +91,7 @@ struct ssh_keys_struct {
|
||||
};
|
||||
|
||||
struct ssh_message_struct;
|
||||
|
||||
struct ssh_poll_handle_struct;
|
||||
|
||||
/* server data */
|
||||
|
||||
@@ -113,6 +114,14 @@ struct ssh_bind_struct {
|
||||
int toaccept;
|
||||
};
|
||||
|
||||
struct socket;
|
||||
struct ssh_poll;
|
||||
void ssh_socket_set_callbacks(struct socket *s, ssh_socket_callbacks callbacks);
|
||||
int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, int fd, int revents, void *s);
|
||||
void ssh_socket_register_pollcallback(struct socket *s, struct ssh_poll_handle_struct *p);
|
||||
|
||||
int ssh_packet_disconnect_callback(ssh_session session, void *user, u_int8_t type, ssh_buffer packet);
|
||||
int ssh_packet_ignore_callback(ssh_session session, void *user, u_int8_t type, ssh_buffer packet);
|
||||
|
||||
/* client.c */
|
||||
|
||||
@@ -134,6 +143,11 @@ unsigned char *packet_encrypt(ssh_session session,void *packet,unsigned int len)
|
||||
/* it returns the hmac buffer if exists*/
|
||||
int packet_hmac_verify(ssh_session session,ssh_buffer buffer,unsigned char *mac);
|
||||
|
||||
int ssh_packet_socket_callback(void *user, const void *data, size_t len);
|
||||
void ssh_packet_register_socket_callback(ssh_session session, struct socket *s);
|
||||
void ssh_packet_set_callbacks(ssh_session session, ssh_packet_callbacks callbacks);
|
||||
void ssh_packet_set_default_callbacks(ssh_session session);
|
||||
void ssh_packet_process(ssh_session session, u_int8_t type);
|
||||
/* connect.c */
|
||||
int ssh_regex_init(void);
|
||||
void ssh_regex_finalize(void);
|
||||
@@ -152,6 +166,11 @@ char **space_tokenize(const char *chain);
|
||||
int ssh_get_kex1(ssh_session session);
|
||||
char *ssh_find_matching(const char *in_d, const char *what_d);
|
||||
|
||||
int channel_rcv_change_window(ssh_session session, void *user, uint8_t type, ssh_buffer packet);
|
||||
int channel_rcv_eof(ssh_session session, void *user, uint8_t type, ssh_buffer packet);
|
||||
int channel_rcv_close(ssh_session session, void *user, uint8_t type, ssh_buffer packet);
|
||||
int channel_rcv_request(ssh_session session, void *user, uint8_t type, ssh_buffer packet);
|
||||
int channel_rcv_data(ssh_session session, void *user, uint8_t type, ssh_buffer packet);
|
||||
/* in base64.c */
|
||||
ssh_buffer base64_to_bin(const char *source);
|
||||
unsigned char *bin_to_base64(const unsigned char *source, int len);
|
||||
@@ -183,6 +202,7 @@ int channel_write1(ssh_channel channel, const void *data, int len);
|
||||
/* match.c */
|
||||
int match_hostname(const char *host, const char *pattern, unsigned int len);
|
||||
|
||||
int message_handle(ssh_session session, void *user, uint8_t type, ssh_buffer packet);
|
||||
/* log.c */
|
||||
|
||||
#ifndef __FUNCTION__
|
||||
|
||||
@@ -95,7 +95,9 @@ struct ssh_session_struct {
|
||||
int log_indent; /* indentation level in enter_function logs */
|
||||
|
||||
ssh_callbacks callbacks; /* Callbacks to user functions */
|
||||
|
||||
struct ssh_packet_callbacks_struct default_packet_callbacks;
|
||||
struct ssh_list *packet_callbacks;
|
||||
struct ssh_socket_callbacks_struct socket_callbacks;
|
||||
/* options */
|
||||
#ifdef WITH_PCAP
|
||||
ssh_pcap_context pcap_ctx; /* pcap debugging context */
|
||||
@@ -114,6 +116,7 @@ struct ssh_session_struct {
|
||||
socket_t fd;
|
||||
int ssh2;
|
||||
int ssh1;
|
||||
|
||||
};
|
||||
|
||||
int ssh_handle_packets(ssh_session session);
|
||||
|
||||
Reference in New Issue
Block a user