From b4111c5c187cf9212eba0ae459edb630dbddb656 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 28 Jul 2009 14:13:22 +0200 Subject: Add functions to get the extension count, name and data. --- include/libssh/sftp.h | 34 ++++++++++++++++++++++++++++++++++ libssh/sftp.c | 32 ++++++++++++++++++++++++++++++++ sample.c | 12 +++++++++++- 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/include/libssh/sftp.h b/include/libssh/sftp.h index 4b23c1e..a41681b 100644 --- a/include/libssh/sftp.h +++ b/include/libssh/sftp.h @@ -201,6 +201,40 @@ int sftp_init(SFTP_SESSION *sftp); */ int sftp_get_error(SFTP_SESSION *sftp); +/** + * @brief Get the count of extensions provided by the server. + * + * @param sftp The sftp session to use. + * + * @return The count of extensions provided by the server, 0 on error or + * not available. + */ +unsigned int sftp_extensions_get_count(SFTP_SESSION *sftp); + +/** + * @brief Get the name of the extension provided by the server. + * + * @param sftp The sftp session to use. + * + * @param index The index number of the extension name you want. + * + * @return The name of the extension. + */ +const char *sftp_extensions_get_name(SFTP_SESSION *sftp, unsigned int index); + +/** + * @brief Get the data of the extension provided by the server. + * + * This is normally the version number of the extension. + * + * @param sftp The sftp session to use. + * + * @param index The index number of the extension data you want. + * + * @return The data of the extension. + */ +const char *sftp_extensions_get_data(SFTP_SESSION *sftp, unsigned int index); + /** * @brief Open a directory used to obtain directory entries. * diff --git a/libssh/sftp.c b/libssh/sftp.c index 9363955..d8c4690 100644 --- a/libssh/sftp.c +++ b/libssh/sftp.c @@ -587,6 +587,38 @@ int sftp_init(SFTP_SESSION *sftp) { return 0; } +unsigned int sftp_extensions_get_count(SFTP_SESSION *sftp) { + if (sftp == NULL || sftp->ext == NULL) { + return 0; + } + + return sftp->ext->count; +} + +const char *sftp_extensions_get_name(SFTP_SESSION *sftp, unsigned int index) { + if (sftp == NULL || sftp->ext == NULL || sftp->ext->name == NULL) { + return NULL; + } + + if (index > sftp->ext->count) { + return NULL; + } + + return sftp->ext->name[index]; +} + +const char *sftp_extensions_get_data(SFTP_SESSION *sftp, unsigned int index) { + if (sftp == NULL || sftp->ext == NULL || sftp->ext->data == NULL) { + return NULL; + } + + if (index > sftp->ext->count) { + return NULL; + } + + return sftp->ext->data[index]; +} + static REQUEST_QUEUE *request_queue_new(SFTP_MESSAGE *msg) { REQUEST_QUEUE *queue = NULL; diff --git a/sample.c b/sample.c index 3a7acfa..1a8b058 100644 --- a/sample.c +++ b/sample.c @@ -283,10 +283,12 @@ void do_sftp(SSH_SESSION *session){ SFTP_FILE *fichier; SFTP_FILE *to; int len=1; - int i; + unsigned int i; char data[8000]={0}; char *link; + unsigned int count; + if(!sftp_session){ fprintf(stderr, "sftp error initialising channel: %s\n", ssh_get_error(session)); @@ -298,6 +300,14 @@ void do_sftp(SSH_SESSION *session){ return; } + printf("Additional SFTP extensions provided by the server:\n"); + count = sftp_extensions_get_count(sftp_session); + for (i = 0; i < count; i++) { + printf("\t%s, version: %s\n", + sftp_extensions_get_name(sftp_session, i), + sftp_extensions_get_data(sftp_session, i)); + } + /* test symlink and readlink */ if (sftp_symlink(sftp_session, "/tmp/this_is_the_link", "/tmp/sftp_symlink_test") < 0) { -- cgit