pidgin/pidgin

Merging default back in
use-gresolver
2015-12-18, Gary Kramlich
cffa32ee55d8
Merging default back in
--- 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;
FbThrift *thft;
GByteArray *cytes;
+ GError *err = NULL;
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,
+ g_object_unref(thft);
+ return;
+ );
fb_util_debug_hexdump(FB_UTIL_DEBUG_INFO, bytes, "Writing connect");
fb_mqtt_connect(mqtt, flags, cytes);
@@ -1599,6 +1605,7 @@
FbApi *api = data;
gboolean comp;
GByteArray *bytes;
+ GError *err = NULL;
guint i;
static const struct {
@@ -1615,13 +1622,8 @@
comp = fb_util_zcompressed(pload);
if (G_LIKELY(comp)) {
- bytes = fb_util_zuncompress(pload);
-
- if (G_UNLIKELY(bytes == NULL)) {
- fb_api_error(api, FB_API_ERROR,
- _("Failed to decompress"));
- return;
- }
+ bytes = fb_util_zuncompress(pload, &err);
+ FB_API_ERROR_EMIT(api, err, return);
} else {
bytes = (GByteArray*) pload;
}
@@ -2112,6 +2114,7 @@
GByteArray *bytes;
GByteArray *cytes;
gchar *msg;
+ GError *err = NULL;
va_list ap;
g_return_if_fail(FB_IS_API(api));
@@ -2124,7 +2127,12 @@
va_end(ap);
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);
+ return;
+ );
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 "internal.h"
+#include <gio/gio.h>
#include <stdarg.h>
#include <string.h>
-#include <zlib.h>
#include "blistnodetypes.h"
#include "buddylist.h"
@@ -483,18 +483,6 @@
return TRUE;
}
-static voidpf
-fb_util_zalloc(voidpf opaque, uInt items, uInt size)
-{
- return g_malloc(size * items);
-}
-
-static void
-fb_util_zfree(voidpf opaque, voidpf address)
-{
- g_free(address);
-}
-
gboolean
fb_util_zcompressed(const GByteArray *bytes)
{
@@ -510,90 +498,73 @@
b0 = *(bytes->data + 0);
b1 = *(bytes->data + 1);
- 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 */
+}
+
+static GByteArray *
+fb_util_zconv(GConverter *conv, const GByteArray *bytes, GError **error)
+{
+ GByteArray *ret;
+ GConverterResult res;
+ gsize cize = 0;
+ gsize rize;
+ gsize wize;
+ guint8 data[1024];
+
+ ret = g_byte_array_new();
+
+ while (TRUE) {
+ rize = 0;
+ wize = 0;
+
+ res = g_converter_convert(conv,
+ bytes->data + cize,
+ bytes->len - cize,
+ data, sizeof data,
+ G_CONVERTER_INPUT_AT_END,
+ &rize, &wize, error);
+
+ switch (res) {
+ case G_CONVERTER_CONVERTED:
+ g_byte_array_append(ret, data, wize);
+ cize += rize;
+ break;
+
+ case G_CONVERTER_ERROR:
+ g_byte_array_free(ret, TRUE);
+ return NULL;
+
+ case G_CONVERTER_FINISHED:
+ g_byte_array_append(ret, data, wize);
+ return ret;
+
+ default:
+ break;
+ }
+ }
}
GByteArray *
-fb_util_zcompress(const GByteArray *bytes)
+fb_util_zcompress(const GByteArray *bytes, GError **error)
{
GByteArray *ret;
- gint res;
- gsize size;
- z_stream zs;
-
- 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) {
- return NULL;
- }
+ GZlibCompressor *conv;
- size = compressBound(bytes->len);
- ret = g_byte_array_new();
-
- g_byte_array_set_size(ret, size);
-
- zs.next_out = ret->data;
- zs.avail_out = size;
-
- res = deflate(&zs, Z_FINISH);
-
- if (res != Z_STREAM_END) {
- deflateEnd(&zs);
- g_byte_array_free(ret, TRUE);
- return NULL;
- }
-
- size -= zs.avail_out;
- g_byte_array_remove_range(ret, size, ret->len - size);
-
- deflateEnd(&zs);
+ conv = g_zlib_compressor_new(G_ZLIB_COMPRESSOR_FORMAT_ZLIB, -1);
+ ret = fb_util_zconv(G_CONVERTER(conv), bytes, error);
+ g_object_unref(conv);
return ret;
}
GByteArray *
-fb_util_zuncompress(const GByteArray *bytes)
+fb_util_zuncompress(const GByteArray *bytes, GError **error)
{
GByteArray *ret;
- gint res;
- guint8 out[1024];
- z_stream zs;
-
- 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) {
- return NULL;
- }
+ GZlibDecompressor *conv;
- ret = g_byte_array_new();
-
- do {
- zs.next_out = out;
- zs.avail_out = sizeof out;
-
- res = inflate(&zs, Z_NO_FLUSH);
-
- if ((res != Z_OK) && (res != Z_STREAM_END)) {
- inflateEnd(&zs);
- g_byte_array_free(ret, TRUE);
- return NULL;
- }
-
- g_byte_array_append(ret, out, sizeof out - zs.avail_out);
- } while (res != Z_STREAM_END);
-
- inflateEnd(&zs);
+ conv = g_zlib_decompressor_new(G_ZLIB_COMPRESSOR_FORMAT_ZLIB);
+ ret = fb_util_zconv(G_CONVERTER(conv), bytes, error);
+ g_object_unref(conv);
return ret;
}
--- 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 @@
/**
* fb_util_zcompress:
* @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.
*/
GByteArray *
-fb_util_zcompress(const GByteArray *bytes);
+fb_util_zcompress(const GByteArray *bytes, GError **error);
/**
* fb_util_zuncompress:
* @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.
*/
GByteArray *
-fb_util_zuncompress(const GByteArray *bytes);
+fb_util_zuncompress(const GByteArray *bytes, GError **error);
#endif /* _FACEBOOK_UTIL_H_ */