Skip to content

Commit 320edcf

Browse files
committed
Allow configuring compression level
Signed-off-by: Steffen Jaeckel <[email protected]>
1 parent 91ea95f commit 320edcf

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
@@ -273,7 +273,8 @@ struct _xmpp_conn_t {
273273

274274
struct {
275275
struct xmpp_compression *state;
276-
int allowed, supported, dont_reset;
276+
int allowed, dont_reset, level;
277+
int supported;
277278
} compression;
278279

279280
char *lang;

src/compression.c

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

9292
comp->compression.stream.next_out = comp->compression.buffer;
9393
comp->compression.stream.avail_out = STROPHE_COMPRESSION_BUFFER_SIZE;
94-
int err = deflateInit(&comp->compression.stream, Z_DEFAULT_COMPRESSION);
94+
int err = deflateInit(&comp->compression.stream, conn->compression.level);
9595
if (err != Z_OK) {
9696
strophe_free_and_null(conn->ctx, comp->compression.buffer);
9797
conn->error = EBADFD;

src/conn.c

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

173+
conn->compression.level = -1;
174+
173175
conn->parser =
174176
parser_new(conn->ctx, _handle_stream_start, _handle_stream_end,
175177
_handle_stream_stanza, conn);
@@ -351,6 +353,10 @@ int xmpp_conn_release(xmpp_conn_t *conn)
351353
* In case the user enters the password manually it can be useful to
352354
* directly retry if the decryption of the key file failed.
353355
*
356+
* - \ref XMPP_SETTING_COMPRESSION_LEVEL
357+
* Set the compression level. \n
358+
* For zlib the valid range is `-1` to `9`.
359+
*
354360
* @param conn a Strophe connection object
355361
* @param setting The setting that shall be configured
356362
* @param value The value, the settings should get
@@ -368,6 +374,9 @@ void xmpp_conn_set_int(xmpp_conn_t *conn,
368374
else
369375
conn->password_retries = value;
370376
break;
377+
case XMPP_SETTING_COMPRESSION_LEVEL:
378+
conn->compression.level = value;
379+
break;
371380
default:
372381
strophe_warn(conn->ctx, "xmpp", "Invalid Int setting %d", setting);
373382
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)