compress: faster check, better return codes
In the transport functions we avoid a strcmp() now and just check a boolean instead. The compress/decompress function's return code is now acknowledged and used as actual return code in case of failures.
Этот коммит содержится в:
родитель
0d58af6aec
Коммит
59636cc11e
@ -77,6 +77,7 @@ comp_method_none_comp(LIBSSH2_SESSION * session,
|
||||
|
||||
static const LIBSSH2_COMP_METHOD comp_method_none = {
|
||||
"none",
|
||||
0, /* not really compressing */
|
||||
NULL,
|
||||
comp_method_none_comp,
|
||||
NULL
|
||||
@ -318,6 +319,7 @@ comp_method_zlib_dtor(LIBSSH2_SESSION * session, int compress,
|
||||
|
||||
static const LIBSSH2_COMP_METHOD comp_method_zlib = {
|
||||
"zlib",
|
||||
1, /* yes, this compresses */
|
||||
comp_method_zlib_init,
|
||||
comp_method_zlib_comp,
|
||||
comp_method_zlib_dtor,
|
||||
|
@ -998,7 +998,7 @@ struct _LIBSSH2_CRYPT_METHOD
|
||||
struct _LIBSSH2_COMP_METHOD
|
||||
{
|
||||
const char *name;
|
||||
|
||||
int compress; /* 1 if it does compress, 0 if it doesn't */
|
||||
int (*init) (LIBSSH2_SESSION * session, int compress, void **abstract);
|
||||
int (*comp) (LIBSSH2_SESSION * session, int compress, unsigned char **dest,
|
||||
size_t *dest_len, size_t payload_limit,
|
||||
|
@ -195,21 +195,21 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ )
|
||||
session->fullpacket_payload_len -= p->padding_length;
|
||||
|
||||
/* Check for and deal with decompression */
|
||||
if (session->remote.comp &&
|
||||
strcmp(session->remote.comp->name, "none")) {
|
||||
if (session->remote.comp && session->remote.comp->compress) {
|
||||
unsigned char *data;
|
||||
size_t data_len;
|
||||
int free_payload = 1;
|
||||
|
||||
if (session->remote.comp->comp(session, 0,
|
||||
&data, &data_len,
|
||||
LIBSSH2_PACKET_MAXDECOMP,
|
||||
&free_payload,
|
||||
p->payload,
|
||||
session->fullpacket_payload_len,
|
||||
&session->remote.comp_abstract)) {
|
||||
rc = session->remote.comp->comp(session, 0,
|
||||
&data, &data_len,
|
||||
LIBSSH2_PACKET_MAXDECOMP,
|
||||
&free_payload,
|
||||
p->payload,
|
||||
session->fullpacket_payload_len,
|
||||
&session->remote.comp_abstract);
|
||||
if(rc) {
|
||||
LIBSSH2_FREE(session, p->payload);
|
||||
return LIBSSH2_ERROR_COMPRESS;
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (free_payload) {
|
||||
@ -718,13 +718,13 @@ _libssh2_transport_write(LIBSSH2_SESSION * session, unsigned char *data,
|
||||
encrypted = (session->state & LIBSSH2_STATE_NEWKEYS) ? 1 : 0;
|
||||
|
||||
/* check if we should compress */
|
||||
if (encrypted && strcmp(session->local.comp->name, "none")) {
|
||||
if (session->local.comp->comp(session, 1, &data, &data_len,
|
||||
LIBSSH2_PACKET_MAXCOMP,
|
||||
&free_data, data, data_len,
|
||||
&session->local.comp_abstract)) {
|
||||
return LIBSSH2_ERROR_COMPRESS; /* compression failure */
|
||||
}
|
||||
if (encrypted && session->local.comp->compress) {
|
||||
rc = session->local.comp->comp(session, 1, &data, &data_len,
|
||||
LIBSSH2_PACKET_MAXCOMP,
|
||||
&free_data, data, data_len,
|
||||
&session->local.comp_abstract);
|
||||
if(rc)
|
||||
return rc; /* compression failure */
|
||||
}
|
||||
|
||||
/* RFC4253 says: Note that the length of the concatenation of
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user