From 4b363928f6a29e9cf2f2f33b86cb860ef0ab4dec Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Sun, 6 Sep 2009 19:43:23 +0300 Subject: [PATCH] SCP warning request --- examples/scp_download.c | 5 +++-- include/libssh/libssh.h | 1 + include/libssh/priv.h | 1 + libssh/scp.c | 11 +++++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/examples/scp_download.c b/examples/scp_download.c index 9da3aafd..52587b57 100644 --- a/examples/scp_download.c +++ b/examples/scp_download.c @@ -111,8 +111,9 @@ static int fetch_files(ssh_session session){ break; case SSH_ERROR: fprintf(stderr,"Error: %s\n",ssh_get_error(session)); - if(ssh_get_error_code(session)!=SSH_REQUEST_DENIED) - return -1; + return -1; + case SSH_SCP_REQUEST_WARNING: + fprintf(stderr,"Warning: %s\n",ssh_scp_request_get_warning(scp)); break; case SSH_SCP_REQUEST_NEWDIR: filename=strdup(ssh_scp_request_get_filename(scp)); diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h index ade69d38..3ab9b494 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h @@ -499,6 +499,7 @@ LIBSSH_API int ssh_scp_read(ssh_scp scp, void *buffer, size_t size); LIBSSH_API const char *ssh_scp_request_get_filename(ssh_scp scp); LIBSSH_API int ssh_scp_request_get_permissions(ssh_scp scp); LIBSSH_API size_t ssh_scp_request_get_size(ssh_scp scp); +LIBSSH_API const char *ssh_scp_request_get_warning(ssh_scp scp); #ifdef __cplusplus diff --git a/include/libssh/priv.h b/include/libssh/priv.h index d05f3a60..1318cb08 100644 --- a/include/libssh/priv.h +++ b/include/libssh/priv.h @@ -373,6 +373,7 @@ struct ssh_scp_struct { size_t processed; enum ssh_scp_request_types request_type; char *request_name; + char *warning; int request_mode; }; diff --git a/libssh/scp.c b/libssh/scp.c index 4f74dc10..2f800efa 100644 --- a/libssh/scp.c +++ b/libssh/scp.c @@ -132,6 +132,7 @@ void ssh_scp_free(ssh_scp scp){ channel_free(scp->channel); SAFE_FREE(scp->location); SAFE_FREE(scp->request_name); + SAFE_FREE(scp->warning); SAFE_FREE(scp); } @@ -429,6 +430,8 @@ int ssh_scp_pull_request(ssh_scp scp){ case 0x1: ssh_set_error(scp->session,SSH_REQUEST_DENIED,"SCP: Warning: %s",&buffer[1]); scp->request_type=SSH_SCP_REQUEST_WARNING; + SAFE_FREE(scp->warning); + scp->warning=strdup(&buffer[1]); return scp->request_type; case 0x2: ssh_set_error(scp->session,SSH_FATAL,"SCP: Error: %s",&buffer[1]); @@ -589,3 +592,11 @@ char *ssh_scp_string_mode(int mode){ snprintf(buffer,sizeof(buffer),"%.4o",mode); return strdup(buffer); } + +/** @brief Gets the warning string + * @returns Warning string. Should not be freed. + */ + +const char *ssh_scp_request_get_warning(ssh_scp scp){ + return scp->warning; +}