aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2010-12-27 23:28:39 +0100
committerAris Adamantiadis <aris@0xbadc0de.be>2010-12-27 23:28:39 +0100
commit4fa2e4dde159a62a0d15bc800a7480f29fd964b1 (patch)
tree3eb243519cb80f755a7a9d40fb417507bd16fdda
parent32c0e1c99a46f91bbec9b203894afdb99e2f5344 (diff)
downloadlibssh-4fa2e4dde159a62a0d15bc800a7480f29fd964b1.tar.gz
libssh-4fa2e4dde159a62a0d15bc800a7480f29fd964b1.tar.xz
libssh-4fa2e4dde159a62a0d15bc800a7480f29fd964b1.zip
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.
-rw-r--r--include/libssh/libssh.h4
-rw-r--r--include/libssh/session.h1
-rw-r--r--src/config.c6
-rw-r--r--src/gzip.c2
-rw-r--r--src/options.c79
-rw-r--r--src/session.c1
6 files changed, 72 insertions, 21 deletions
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index 21ab70e..d1c1b3b 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -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 {
diff --git a/include/libssh/session.h b/include/libssh/session.h
index 33ef879..a2cdfa0 100644
--- a/include/libssh/session.h
+++ b/include/libssh/session.h
@@ -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;
diff --git a/src/config.c b/src/config.c
index c651ed0..4b2c739 100644
--- a/src/config.c
+++ b/src/config.c
@@ -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;
diff --git a/src/gzip.c b/src/gzip.c
index c95bf9d..cfea1e3 100644
--- a/src/gzip.c
+++ b/src/gzip.c
@@ -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;
}
diff --git a/src/options.c b/src/options.c
index d8fcee8..534012d 100644
--- a/src/options.c
+++ b/src/options.c
@@ -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;
}
}
diff --git a/src/session.c b/src/session.c
index cda01db..a057b93 100644
--- a/src/session.c
+++ b/src/session.c
@@ -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