mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-08 19:02:06 +03:00
Added compression options and allow "yes/no" setting
SSH_OPTION_COMPRESSION and SSH_OPTION_COMPRESSION_LEVEL options have been added. Now, end-level apps may simply choose to enable compression without knowing the relevant algorithms behind it.
This commit is contained in:
@@ -296,7 +296,9 @@ enum ssh_options_e {
|
||||
SSH_OPTIONS_COMPRESSION_S_C,
|
||||
SSH_OPTIONS_PROXYCOMMAND,
|
||||
SSH_OPTIONS_BINDADDR,
|
||||
SSH_OPTIONS_STRICTHOSTKEYCHECK
|
||||
SSH_OPTIONS_STRICTHOSTKEYCHECK,
|
||||
SSH_OPTIONS_COMPRESSION,
|
||||
SSH_OPTIONS_COMPRESSION_LEVEL
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@@ -138,6 +138,7 @@ struct ssh_session_struct {
|
||||
char *sshdir;
|
||||
char *knownhosts;
|
||||
char *wanted_methods[10];
|
||||
char compressionlevel;
|
||||
unsigned long timeout; /* seconds */
|
||||
unsigned long timeout_usec;
|
||||
unsigned int port;
|
||||
|
@@ -239,11 +239,9 @@ static int ssh_config_parse_line(ssh_session session, const char *line,
|
||||
i = ssh_config_get_yesno(&s, -1);
|
||||
if (i >= 0 && *parsing) {
|
||||
if (i) {
|
||||
ssh_options_set(session, SSH_OPTIONS_COMPRESSION_C_S, "zlib@openssh.com,zlib,none");
|
||||
ssh_options_set(session, SSH_OPTIONS_COMPRESSION_S_C, "zlib@openssh.com,zlib,none");
|
||||
ssh_options_set(session, SSH_OPTIONS_COMPRESSION, "yes");
|
||||
} else {
|
||||
ssh_options_set(session, SSH_OPTIONS_COMPRESSION_C_S, "none");
|
||||
ssh_options_set(session, SSH_OPTIONS_COMPRESSION_S_C, "none");
|
||||
ssh_options_set(session, SSH_OPTIONS_COMPRESSION, "no");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@@ -103,7 +103,7 @@ static ssh_buffer gzip_compress(ssh_session session,ssh_buffer source,int level)
|
||||
int compress_buffer(ssh_session session, ssh_buffer buf) {
|
||||
ssh_buffer dest = NULL;
|
||||
|
||||
dest = gzip_compress(session, buf, 9);
|
||||
dest = gzip_compress(session, buf, session->compressionlevel);
|
||||
if (dest == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@@ -145,6 +145,7 @@ int ssh_options_copy(ssh_session src, ssh_session *dest) {
|
||||
new->ssh2 = src->ssh2;
|
||||
new->ssh1 = src->ssh1;
|
||||
new->log_verbosity = src->log_verbosity;
|
||||
new->compressionlevel = src->compressionlevel;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -272,23 +273,23 @@ int ssh_options_set_algo(ssh_session session, int algo,
|
||||
* \n
|
||||
* See the corresponding numbers in libssh.h.
|
||||
*
|
||||
* - SSH_OPTTIONS_AUTH_CALLBACK:
|
||||
* - SSH_OPTIONS_AUTH_CALLBACK:
|
||||
* Set a callback to use your own authentication function
|
||||
* (function pointer).
|
||||
*
|
||||
* - SSH_OPTTIONS_AUTH_USERDATA:
|
||||
* - SSH_OPTIONS_AUTH_USERDATA:
|
||||
* Set the user data passed to the authentication
|
||||
* function (generic pointer).
|
||||
*
|
||||
* - SSH_OPTTIONS_LOG_CALLBACK:
|
||||
* - SSH_OPTIONS_LOG_CALLBACK:
|
||||
* Set a callback to use your own logging function
|
||||
* (function pointer).
|
||||
*
|
||||
* - SSH_OPTTIONS_LOG_USERDATA:
|
||||
* - SSH_OPTIONS_LOG_USERDATA:
|
||||
* Set the user data passed to the logging function
|
||||
* (generic pointer).
|
||||
*
|
||||
* - SSH_OPTTIONS_STATUS_CALLBACK:
|
||||
* - SSH_OPTIONS_STATUS_CALLBACK:
|
||||
* Set a callback to show connection status in realtime
|
||||
* (function pointer).\n
|
||||
* \n
|
||||
@@ -299,7 +300,7 @@ int ssh_options_set_algo(ssh_session session, int algo,
|
||||
* During ssh_connect(), libssh will call the callback
|
||||
* with status from 0.0 to 1.0.
|
||||
*
|
||||
* - SSH_OPTTIONS_STATUS_ARG:
|
||||
* - SSH_OPTIONS_STATUS_ARG:
|
||||
* Set the status argument which should be passed to the
|
||||
* status callback (generic pointer).
|
||||
*
|
||||
@@ -313,11 +314,22 @@ int ssh_options_set_algo(ssh_session session, int algo,
|
||||
*
|
||||
* - SSH_OPTIONS_COMPRESSION_C_S:
|
||||
* Set the compression to use for client to server
|
||||
* communication (const char *, "none" or "zlib").
|
||||
* communication (const char *, "yes", "no" or a specific
|
||||
* algorithm name if needed ("zlib","zlib@openssh.com","none").
|
||||
*
|
||||
* - SSH_OPTIONS_COMPRESSION_S_C:
|
||||
* Set the compression to use for server to client
|
||||
* communication (const char *, "none" or "zlib").
|
||||
* communication (const char *, "yes", "no" or a specific
|
||||
* algorithm name if needed ("zlib","zlib@openssh.com","none").
|
||||
*
|
||||
* - SSH_OPTIONS_COMPRESSION:
|
||||
* Set the compression to use for both directions
|
||||
* communication (const char *, "yes", "no" or a specific
|
||||
* algorithm name if needed ("zlib","zlib@openssh.com","none").
|
||||
*
|
||||
* - SSH_OPTIONS_COMPRESSION_LEVEL:
|
||||
* Set the compression level to use for zlib functions. (int,
|
||||
* value from 1 to 9, 9 being the most efficient but slower).
|
||||
*
|
||||
* - SSH_OPTIONS_STRICTHOSTKEYCHECK:
|
||||
* Set the parameter StrictHostKeyChecking to avoid
|
||||
@@ -576,8 +588,16 @@ int ssh_options_set(ssh_session session, enum ssh_options_e type,
|
||||
ssh_set_error_invalid(session, __FUNCTION__);
|
||||
return -1;
|
||||
} else {
|
||||
if (ssh_options_set_algo(session, SSH_COMP_C_S, value) < 0)
|
||||
return -1;
|
||||
if (strcasecmp(value,"yes")==0){
|
||||
if(ssh_options_set_algo(session,SSH_COMP_C_S,"zlib@openssh.com,zlib") < 0)
|
||||
return -1;
|
||||
} else if (strcasecmp(value,"no")==0){
|
||||
if(ssh_options_set_algo(session,SSH_COMP_C_S,"none") < 0)
|
||||
return -1;
|
||||
} else {
|
||||
if (ssh_options_set_algo(session, SSH_COMP_C_S, value) < 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SSH_OPTIONS_COMPRESSION_S_C:
|
||||
@@ -585,8 +605,40 @@ int ssh_options_set(ssh_session session, enum ssh_options_e type,
|
||||
ssh_set_error_invalid(session, __FUNCTION__);
|
||||
return -1;
|
||||
} else {
|
||||
if (ssh_options_set_algo(session, SSH_COMP_S_C, value) < 0)
|
||||
if (strcasecmp(value,"yes")==0){
|
||||
if(ssh_options_set_algo(session,SSH_COMP_S_C,"zlib@openssh.com,zlib") < 0)
|
||||
return -1;
|
||||
} else if (strcasecmp(value,"no")==0){
|
||||
if(ssh_options_set_algo(session,SSH_COMP_S_C,"none") < 0)
|
||||
return -1;
|
||||
} else {
|
||||
if (ssh_options_set_algo(session, SSH_COMP_S_C, value) < 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SSH_OPTIONS_COMPRESSION:
|
||||
if (value==NULL) {
|
||||
ssh_set_error_invalid(session, __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
if(ssh_options_set(session,SSH_OPTIONS_COMPRESSION_C_S,value) < 0)
|
||||
return -1;
|
||||
if(ssh_options_set(session,SSH_OPTIONS_COMPRESSION_S_C,value) < 0)
|
||||
return -1;
|
||||
break;
|
||||
case SSH_OPTIONS_COMPRESSION_LEVEL:
|
||||
if (value==NULL) {
|
||||
ssh_set_error_invalid(session, __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
int *x=(int *)value;
|
||||
if(*x < 1 || *x > 9){
|
||||
ssh_set_error_invalid(session, __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
session->compressionlevel=*x & 0xff;
|
||||
}
|
||||
break;
|
||||
case SSH_OPTIONS_STRICTHOSTKEYCHECK:
|
||||
@@ -760,10 +812,7 @@ int ssh_options_getopt(ssh_session session, int *argcptr, char **argv) {
|
||||
|
||||
/* set a new option struct */
|
||||
if (compress) {
|
||||
if (ssh_options_set(session, SSH_OPTIONS_COMPRESSION_C_S, "zlib,zlib@openssh.com,none") < 0) {
|
||||
cont = 0;
|
||||
}
|
||||
if (ssh_options_set(session, SSH_OPTIONS_COMPRESSION_S_C, "zlib,zlib@openssh.com,none") < 0) {
|
||||
if (ssh_options_set(session, SSH_OPTIONS_COMPRESSION, "yes") < 0) {
|
||||
cont = 0;
|
||||
}
|
||||
}
|
||||
|
@@ -94,6 +94,7 @@ ssh_session ssh_new(void) {
|
||||
session->port = 22;
|
||||
session->fd = -1;
|
||||
session->ssh2 = 1;
|
||||
session->compressionlevel=7;
|
||||
#ifdef WITH_SSH1
|
||||
session->ssh1 = 1;
|
||||
#else
|
||||
|
Reference in New Issue
Block a user