--- a/libpurple/protocols/facebook/api.c Fri Dec 18 22:29:26 2015 -0600
+++ b/libpurple/protocols/facebook/api.c Fri Dec 18 22:35:29 2015 -0600
@@ -844,6 +844,7 @@
FbApiPrivate *priv = api->priv;
static guint8 flags = FB_MQTT_CONNECT_FLAG_USER |
FB_MQTT_CONNECT_FLAG_PASS |
@@ -918,7 +919,12 @@
fb_thrift_write_stop(thft);
bytes = fb_thrift_get_bytes(thft);
- cytes = fb_util_zcompress(bytes);
+ cytes = fb_util_zcompress(bytes, &err); + FB_API_ERROR_EMIT(api, err, fb_util_debug_hexdump(FB_UTIL_DEBUG_INFO, bytes, "Writing connect");
fb_mqtt_connect(mqtt, flags, cytes);
@@ -1599,6 +1605,7 @@
@@ -1615,13 +1622,8 @@
comp = fb_util_zcompressed(pload);
- bytes = fb_util_zuncompress(pload);
- if (G_UNLIKELY(bytes == NULL)) {
- fb_api_error(api, FB_API_ERROR,
- _("Failed to decompress"));
+ bytes = fb_util_zuncompress(pload, &err); + FB_API_ERROR_EMIT(api, err, return); bytes = (GByteArray*) pload;
@@ -2112,6 +2114,7 @@
g_return_if_fail(FB_IS_API(api));
@@ -2124,7 +2127,12 @@
bytes = g_byte_array_new_take((guint8*) msg, strlen(msg));
- cytes = fb_util_zcompress(bytes);
+ cytes = fb_util_zcompress(bytes, &err); + FB_API_ERROR_EMIT(api, err, + g_byte_array_free(bytes, TRUE); fb_util_debug_hexdump(FB_UTIL_DEBUG_INFO, bytes,
"Writing message (topic: %s)",
--- a/libpurple/protocols/facebook/util.c Fri Dec 18 22:29:26 2015 -0600
+++ b/libpurple/protocols/facebook/util.c Fri Dec 18 22:35:29 2015 -0600
@@ -21,9 +21,9 @@
#include "blistnodetypes.h"
@@ -483,18 +483,6 @@
-fb_util_zalloc(voidpf opaque, uInt items, uInt size)
- return g_malloc(size * items);
-fb_util_zfree(voidpf opaque, voidpf address)
fb_util_zcompressed(const GByteArray *bytes)
@@ -510,90 +498,73 @@
- return ((((b0 << 8) | b1) % 31) == 0) && /* Check the header */
- ((b0 & 0x0F) == Z_DEFLATED); /* Check the method */
+ return ((((b0 << 8) | b1) % 31) == 0) && /* Check the header */ + ((b0 & 0x0F) == 8 /* Z_DEFLATED */); /* Check the method */ +fb_util_zconv(GConverter *conv, const GByteArray *bytes, GError **error) + ret = g_byte_array_new(); + res = g_converter_convert(conv, + G_CONVERTER_INPUT_AT_END, + case G_CONVERTER_CONVERTED: + g_byte_array_append(ret, data, wize); + case G_CONVERTER_ERROR: + g_byte_array_free(ret, TRUE); + case G_CONVERTER_FINISHED: + g_byte_array_append(ret, data, wize); -fb_util_zcompress(const GByteArray *bytes)
+fb_util_zcompress(const GByteArray *bytes, GError **error)
- g_return_val_if_fail(bytes != NULL, NULL);
- memset(&zs, 0, sizeof zs);
- zs.zalloc = fb_util_zalloc;
- zs.zfree = fb_util_zfree;
- zs.next_in = bytes->data;
- zs.avail_in = bytes->len;
- if (deflateInit(&zs, Z_BEST_COMPRESSION) != Z_OK) {
- size = compressBound(bytes->len);
- ret = g_byte_array_new();
- g_byte_array_set_size(ret, size);
- zs.next_out = ret->data;
- res = deflate(&zs, Z_FINISH);
- if (res != Z_STREAM_END) {
- g_byte_array_free(ret, TRUE);
- g_byte_array_remove_range(ret, size, ret->len - size);
+ conv = g_zlib_compressor_new(G_ZLIB_COMPRESSOR_FORMAT_ZLIB, -1); + ret = fb_util_zconv(G_CONVERTER(conv), bytes, error); -fb_util_zuncompress(const GByteArray *bytes)
+fb_util_zuncompress(const GByteArray *bytes, GError **error)
- g_return_val_if_fail(bytes != NULL, NULL);
- memset(&zs, 0, sizeof zs);
- zs.zalloc = fb_util_zalloc;
- zs.zfree = fb_util_zfree;
- zs.next_in = bytes->data;
- zs.avail_in = bytes->len;
- if (inflateInit(&zs) != Z_OK) {
+ GZlibDecompressor *conv; - ret = g_byte_array_new();
- zs.avail_out = sizeof out;
- res = inflate(&zs, Z_NO_FLUSH);
- if ((res != Z_OK) && (res != Z_STREAM_END)) {
- g_byte_array_free(ret, TRUE);
- g_byte_array_append(ret, out, sizeof out - zs.avail_out);
- } while (res != Z_STREAM_END);
+ conv = g_zlib_decompressor_new(G_ZLIB_COMPRESSOR_FORMAT_ZLIB); + ret = fb_util_zconv(G_CONVERTER(conv), bytes, error); --- a/libpurple/protocols/facebook/util.h Fri Dec 18 22:29:26 2015 -0600
+++ b/libpurple/protocols/facebook/util.h Fri Dec 18 22:35:29 2015 -0600
@@ -320,6 +320,7 @@
* @bytes: The #GByteArray.
+ * @error: The return location for the #GError, or #NULL. * Compresses a #GByteArray with zlib. The returned #GByteArray should
* be freed with #g_byte_array_free() when no longer needed.
@@ -327,11 +328,12 @@
* Returns: The compressed #GByteArray.
-fb_util_zcompress(const GByteArray *bytes);
+fb_util_zcompress(const GByteArray *bytes, GError **error); * @bytes: The #GByteArray.
+ * @error: The return location for the #GError, or #NULL. * Uncompresses a #GByteArray with zlib. The returned #GByteArray
* should be freed with #g_byte_array_free() when no longer needed.
@@ -339,6 +341,6 @@
* Returns: The uncompressed #GByteArray, or #NULL on error.
-fb_util_zuncompress(const GByteArray *bytes);
+fb_util_zuncompress(const GByteArray *bytes, GError **error); #endif /* _FACEBOOK_UTIL_H_ */