From a9ff529d83ad5e4293095448bd2f18641754be01 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sun, 17 Mar 2013 16:14:20 +0100 Subject: [PATCH] relay: rename compression "gzip" to "zlib" (compression is zlib, not gzip) (thanks to Dominik Honnef) --- ChangeLog | 1 + doc/en/weechat_relay_protocol.en.txt | 16 ++-- src/plugins/relay/weechat/relay-weechat-msg.c | 74 ++++++++++--------- .../relay/weechat/relay-weechat-protocol.c | 2 +- src/plugins/relay/weechat/relay-weechat.c | 4 +- src/plugins/relay/weechat/relay-weechat.h | 4 +- 6 files changed, 56 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7dc4ec044..c6a06fe75 100644 --- a/ChangeLog +++ b/ChangeLog @@ -58,6 +58,7 @@ Version 0.4.1 (under dev!) * lua: fix crash on stack overflow: call lua_pop() for values returned by lua functions (bug #38510) * perl: simplify code to load scripts +* relay: rename compression "gzip" to "zlib" (compression is zlib, not gzip) * relay: add message "_nicklist_diff" (differences between old and current nicklist) * relay: add support of multiple servers on same port for irc protocol (the diff --git a/doc/en/weechat_relay_protocol.en.txt b/doc/en/weechat_relay_protocol.en.txt index 696bdae3b..acc1e3f8d 100644 --- a/doc/en/weechat_relay_protocol.en.txt +++ b/doc/en/weechat_relay_protocol.en.txt @@ -116,16 +116,20 @@ Arguments: ** 'password' (required): password used to authenticate on 'relay' (option 'relay.network.password' in WeeChat) ** 'compression' (optional): compression type: -*** 'gzip': enable gzip compression for messages sent by 'relay' +*** 'zlib': enable zlib compression for messages sent by 'relay' *** 'off': disable compression [NOTE] -Compression 'gzip' is enabled by default if 'relay' supports gzip compression. +Compression 'zlib' is enabled by default if 'relay' supports zlib compression. -Example: +Examples: ---------------------------------------- -init password=mypass,compression=gzip +# initialize and use zlib compression by default (if WeeChat supports it) +init password=mypass + +# initialize and disable compression +init password=mypass,compression=off ---------------------------------------- [[command_hdata]] @@ -473,7 +477,7 @@ Messages are sent as binary data, using following format (with size in bytes): this length) * 'compression' (byte): flag: ** '0x00': following data is not compressed -** '0x01': following data is gzip-compressed +** '0x01': following data is zlib-compressed * 'id' (string): identifier sent by client (before command name); it can be empty (string with zero length and no content) if no identifier was given in command @@ -485,7 +489,7 @@ Compression ~~~~~~~~~~~ If flag 'compression' is equal to 0x01, then *all* data after is compressed -with gzip, and therefore must be uncompressed before being processed. +with zlib, and therefore must be uncompressed before being processed. [[message_identifier]] Identifier diff --git a/src/plugins/relay/weechat/relay-weechat-msg.c b/src/plugins/relay/weechat/relay-weechat-msg.c index 5e1595530..0c4afb4c2 100644 --- a/src/plugins/relay/weechat/relay-weechat-msg.c +++ b/src/plugins/relay/weechat/relay-weechat-msg.c @@ -999,52 +999,58 @@ relay_weechat_msg_send (struct t_relay_client *client, struct timeval tv1, tv2; long time_diff; - if (RELAY_WEECHAT_DATA(client, compression) - && (weechat_config_integer (relay_config_network_compression_level) > 0)) + if (weechat_config_integer (relay_config_network_compression_level) > 0) { - dest_size = compressBound (msg->data_size - 5); - dest = malloc (dest_size + 5); - if (dest) + switch (RELAY_WEECHAT_DATA(client, compression)) { - gettimeofday (&tv1, NULL); - rc = compress2 (dest + 5, &dest_size, - (Bytef *)(msg->data + 5), msg->data_size - 5, - weechat_config_integer (relay_config_network_compression_level)); - gettimeofday (&tv2, NULL); - time_diff = weechat_util_timeval_diff (&tv1, &tv2); - if ((rc == Z_OK) && ((int)dest_size + 5 < msg->data_size)) - { - /* set size and compression flag */ - size32 = htonl ((uint32_t)(dest_size + 5)); - memcpy (dest, &size32, 4); - dest[4] = 1; + case RELAY_WEECHAT_COMPRESSION_ZLIB: + dest_size = compressBound (msg->data_size - 5); + dest = malloc (dest_size + 5); + if (dest) + { + gettimeofday (&tv1, NULL); + rc = compress2 (dest + 5, &dest_size, + (Bytef *)(msg->data + 5), msg->data_size - 5, + weechat_config_integer (relay_config_network_compression_level)); + gettimeofday (&tv2, NULL); + time_diff = weechat_util_timeval_diff (&tv1, &tv2); + if ((rc == Z_OK) && ((int)dest_size + 5 < msg->data_size)) + { + /* set size and compression flag */ + size32 = htonl ((uint32_t)(dest_size + 5)); + memcpy (dest, &size32, 4); + dest[4] = RELAY_WEECHAT_COMPRESSION_ZLIB; - /* display message in raw buffer */ - snprintf (raw_message, sizeof (raw_message), - "obj: %d/%d bytes (%d%%, %ldms), id: %s", - (int)dest_size + 5, - msg->data_size, - 100 - ((((int)dest_size + 5) * 100) / msg->data_size), - time_diff, - msg->id); + /* display message in raw buffer */ + snprintf (raw_message, sizeof (raw_message), + "obj: %d/%d bytes (%d%%, %ldms), id: %s", + (int)dest_size + 5, + msg->data_size, + 100 - ((((int)dest_size + 5) * 100) / msg->data_size), + time_diff, + msg->id); - /* send compressed data */ - relay_client_send (client, (const char *)dest, dest_size + 5, - raw_message); + /* send compressed data */ + relay_client_send (client, (const char *)dest, dest_size + 5, + raw_message); - free (dest); - return; - } - free (dest); + free (dest); + return; + } + free (dest); + } + break; + default: + break; } } - /* compression with zlib failed (or not asked), send uncompressed message */ + /* compression failed (or not asked), send uncompressed message */ /* set size and compression flag */ size32 = htonl ((uint32_t)msg->data_size); relay_weechat_msg_set_bytes (msg, 0, &size32, 4); - compression = 0; + compression = RELAY_WEECHAT_COMPRESSION_OFF; relay_weechat_msg_set_bytes (msg, 4, &compression, 1); /* send uncompressed data */ diff --git a/src/plugins/relay/weechat/relay-weechat-protocol.c b/src/plugins/relay/weechat/relay-weechat-protocol.c index a2cf81dd1..d8b4e3cae 100644 --- a/src/plugins/relay/weechat/relay-weechat-protocol.c +++ b/src/plugins/relay/weechat/relay-weechat-protocol.c @@ -159,7 +159,7 @@ relay_weechat_protocol_is_sync (struct t_relay_client *ptr_client, * * Message looks like: * init password=mypass - * init password=mypass,compression=gzip + * init password=mypass,compression=zlib * init password=mypass,compression=off */ diff --git a/src/plugins/relay/weechat/relay-weechat.c b/src/plugins/relay/weechat/relay-weechat.c index 9136849a8..714aee387 100644 --- a/src/plugins/relay/weechat/relay-weechat.c +++ b/src/plugins/relay/weechat/relay-weechat.c @@ -41,7 +41,7 @@ char *relay_weechat_compression_string[] = /* strings for compressions */ -{ "off", "gzip" }; +{ "off", "zlib" }; /* @@ -175,7 +175,7 @@ relay_weechat_alloc (struct t_relay_client *client) if (client->protocol_data) { RELAY_WEECHAT_DATA(client, password_ok) = (password && password[0]) ? 0 : 1; - RELAY_WEECHAT_DATA(client, compression) = 1; + RELAY_WEECHAT_DATA(client, compression) = RELAY_WEECHAT_COMPRESSION_ZLIB; RELAY_WEECHAT_DATA(client, nicklist_diff) = 0; RELAY_WEECHAT_DATA(client, buffers_sync) = weechat_hashtable_new (32, diff --git a/src/plugins/relay/weechat/relay-weechat.h b/src/plugins/relay/weechat/relay-weechat.h index 2e0719775..dc3486eae 100644 --- a/src/plugins/relay/weechat/relay-weechat.h +++ b/src/plugins/relay/weechat/relay-weechat.h @@ -28,7 +28,7 @@ struct t_relay_client; enum t_relay_weechat_compression { RELAY_WEECHAT_COMPRESSION_OFF = 0, /* no compression of binary objects */ - RELAY_WEECHAT_COMPRESSION_GZIP, /* gzip compression */ + RELAY_WEECHAT_COMPRESSION_ZLIB, /* zlib compression */ /* number of compressions */ RELAY_WEECHAT_NUM_COMPRESSIONS, }; @@ -36,7 +36,7 @@ enum t_relay_weechat_compression struct t_relay_weechat_data { int password_ok; /* password received and OK? */ - int compression; /* compression type */ + enum t_relay_weechat_compression compression; /* compression type */ int nicklist_diff; /* (TEMPORARY) nicklist diff enabled?*/ /* sync of buffers */