Skip to content

Commit 0ce84f8

Browse files
committed
Allow configuring compression level
Signed-off-by: Steffen Jaeckel <[email protected]>
1 parent fa92893 commit 0ce84f8

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

src/common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ struct _xmpp_conn_t {
278278

279279
struct {
280280
struct xmpp_compression *state;
281-
int allowed, supported, dont_reset;
281+
int allowed, dont_reset, level;
282+
int supported;
282283
} compression;
283284

284285
char *lang;

src/compression.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ int compression_init(xmpp_conn_t *conn)
228228

229229
comp->compression.stream.next_out = comp->compression.buffer;
230230
comp->compression.stream.avail_out = STROPHE_COMPRESSION_BUFFER_SIZE;
231-
int err = deflateInit(&comp->compression.stream, Z_DEFAULT_COMPRESSION);
231+
int err = deflateInit(&comp->compression.stream, conn->compression.level);
232232
if (err != Z_OK) {
233233
strophe_free_and_null(conn->ctx, comp->compression.buffer);
234234
conn->error = EBADFD;

src/conn.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t *ctx)
167167
tls_clear_password_cache(conn);
168168
conn->password_retries = 1;
169169

170+
conn->compression.level = -1;
171+
170172
conn->parser =
171173
parser_new(conn->ctx, _handle_stream_start, _handle_stream_end,
172174
_handle_stream_stanza, conn);
@@ -348,6 +350,10 @@ int xmpp_conn_release(xmpp_conn_t *conn)
348350
* In case the user enters the password manually it can be useful to
349351
* directly retry if the decryption of the key file failed.
350352
*
353+
* - \ref XMPP_SETTING_COMPRESSION_LEVEL
354+
* Set the compression level. \n
355+
* For zlib the valid range is `-1` to `9`.
356+
*
351357
* @param conn a Strophe connection object
352358
* @param setting The setting that shall be configured
353359
* @param value The value, the settings should get
@@ -365,6 +371,9 @@ void xmpp_conn_set_int(xmpp_conn_t *conn,
365371
else
366372
conn->password_retries = value;
367373
break;
374+
case XMPP_SETTING_COMPRESSION_LEVEL:
375+
conn->compression.level = value;
376+
break;
368377
default:
369378
strophe_warn(conn->ctx, "xmpp", "Invalid Int setting %d", setting);
370379
return;

strophe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ typedef enum xmpp_conn_setting_t {
389389
/* Int values */
390390
XMPP_SETTING_PASSWORD_RETRIES = 0x40, /**< Number of retry attempts to
391391
decrypt a private key file. */
392+
XMPP_SETTING_COMPRESSION_LEVEL, /**< Compression level. */
392393

393394
/* Pointer values */
394395
XMPP_SETTING_PASSWORD_CALLBACK_USERDATA = 0x80, /**< Userdata for password

0 commit comments

Comments
 (0)