1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-28 05:46:38 +02:00

relay: rename compression "gzip" to "zlib" (compression is zlib, not gzip) (thanks to Dominik Honnef)

This commit is contained in:
Sebastien Helleu
2013-03-17 16:14:20 +01:00
parent fa2b1d6bf9
commit a9ff529d83
6 changed files with 56 additions and 45 deletions
+1
View File
@@ -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
+10 -6
View File
@@ -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
+40 -34
View File
@@ -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 */
@@ -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
*/
+2 -2
View File
@@ -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,
+2 -2
View File
@@ -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 */