diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2010-06-25 16:19:19 +0200 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2010-06-25 16:19:19 +0200 |
commit | 94b00cc7625bf139a72c3c8d5f8c30243319f5b4 (patch) | |
tree | f2fb01507002a4163e0ced9fbc340faed649ca16 /include | |
parent | e4701e7c86aecc7bd201ea2ed54282f2d4737092 (diff) | |
download | libssh-94b00cc7625bf139a72c3c8d5f8c30243319f5b4.tar.gz libssh-94b00cc7625bf139a72c3c8d5f8c30243319f5b4.tar.xz libssh-94b00cc7625bf139a72c3c8d5f8c30243319f5b4.zip |
Add ssh_callbacks_exists internal macro + unittest
(first commit with eclipse helios, crossing fingers ...)
Diffstat (limited to 'include')
-rw-r--r-- | include/libssh/callbacks.h | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/include/libssh/callbacks.h b/include/libssh/callbacks.h index d5a3745f..3ceb3857 100644 --- a/include/libssh/callbacks.h +++ b/include/libssh/callbacks.h @@ -156,7 +156,8 @@ typedef struct ssh_socket_callbacks_struct *ssh_socket_callbacks; #define SSH_SOCKET_CONNECTED_ERROR 2 #define SSH_SOCKET_CONNECTED_TIMEOUT 3 -/** Initializes an ssh_callbacks_struct +/** + * @brief 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 @@ -166,6 +167,20 @@ typedef struct ssh_socket_callbacks_struct *ssh_socket_callbacks; (p)->size=sizeof(*(p)); \ } while(0); +/** + * @internal + * @brief tests if a callback can be called without crash + * verifies that the struct size if big enough + * verifies that the callback pointer exists + * @param p callback pointer + * @param c callback name + * @returns nonzero if callback can be called + */ +#define ssh_callbacks_exists(p,c) (\ + ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \ + ((p)-> c != NULL) \ + ) + /** @brief Prototype for a packet callback, to be called when a new packet arrives * @param session The current session of the packet * @param type packet type (see ssh2.h) @@ -217,11 +232,10 @@ typedef struct ssh_packet_callbacks_struct *ssh_packet_callbacks; * functions for auth, logging and status. * * @code - * struct ssh_callbacks_struct cb; - * memset(&cb, 0, sizeof(struct ssh_callbacks_struct)); - * cb.userdata = data; - * cb.auth_function = my_auth_function; - * + * struct ssh_callbacks_struct cb = { + * .userdata = data, + * .auth_function = my_auth_function + * }; * ssh_callbacks_init(&cb); * ssh_set_callbacks(session, &cb); * @endcode |