Fri, 11 Aug 2017 00:43:27 +0000
Merged in CMaiku/pidgin (pull request #247)
Port to GZlibDecompressor
Approved-by: Eion Robb <eionrobb@gmail.com>
Approved-by: Gary Kramlich <grim@reaperworld.com>
| configure.ac | file | annotate | diff | comparison | revisions | |
| meson.build | file | annotate | diff | comparison | revisions |
--- a/configure.ac Wed Aug 09 01:09:35 2017 +0000 +++ b/configure.ac Fri Aug 11 00:43:27 2017 +0000 @@ -829,17 +829,6 @@ AC_SUBST(JSON_LIBS) dnl ####################################################################### -dnl # Check for zlib (required) -dnl ####################################################################### - -PKG_CHECK_MODULES(ZLIB, [zlib >= 1.2.0], , [ - AC_SEARCH_LIBS([deflate], [z], [], AC_MSG_ERROR([You must have zlib >= 1.2.0 development headers installed to build.]), []) -]) - -AC_SUBST(ZLIB_CFLAGS) -AC_SUBST(ZLIB_LIBS) - -dnl ####################################################################### dnl # Check for GStreamer dnl ####################################################################### AC_ARG_ENABLE(gstreamer,
--- a/doc/reference/libpurple/Makefile.am Wed Aug 09 01:09:35 2017 +0000 +++ b/doc/reference/libpurple/Makefile.am Fri Aug 11 00:43:27 2017 +0000 @@ -134,7 +134,6 @@ $(IDN_CFLAGS) \ $(NETWORKMANAGER_CFLAGS) \ $(JSON_CFLAGS) \ - $(ZLIB_CFLAGS) \ $(INTROSPECTION_CFLAGS) GTKDOC_LIBS = \ @@ -152,7 +151,6 @@ $(GSTINTERFACES_LIBS) \ $(IDN_LIBS) \ $(JSON_LIBS) \ - $(ZLIB_LIBS) \ $(INTROSPECTION_LIBS) \ -lm
--- a/doc/reference/protocols/facebook/Makefile.am Wed Aug 09 01:09:35 2017 +0000 +++ b/doc/reference/protocols/facebook/Makefile.am Fri Aug 11 00:43:27 2017 +0000 @@ -88,7 +88,6 @@ $(GPLUGIN_CFLAGS) \ $(DEBUG_CFLAGS) \ $(JSON_CFLAGS) \ - $(ZLIB_CFLAGS) \ $(INTROSPECTION_CFLAGS) GTKDOC_LIBS = \ @@ -98,7 +97,6 @@ $(GPLUGIN_LIBS) \ $(INTLLIBS) \ $(JSON_LIBS) \ - $(ZLIB_LIBS) \ $(INTROSPECTION_LIBS) # This includes the standard gtk-doc make rules, copied by gtkdocize.
--- a/libpurple/Makefile.am Wed Aug 09 01:09:35 2017 +0000 +++ b/libpurple/Makefile.am Fri Aug 11 00:43:27 2017 +0000 @@ -434,7 +434,6 @@ $(GSTINTERFACES_LIBS) \ $(IDN_LIBS) \ $(JSON_LIBS) \ - $(ZLIB_LIBS) \ $(INTROSPECTION_LIBS) \ -lm @@ -452,7 +451,6 @@ $(IDN_CFLAGS) \ $(NETWORKMANAGER_CFLAGS) \ $(JSON_CFLAGS) \ - $(ZLIB_CFLAGS) \ $(INTROSPECTION_CFLAGS) -include $(INTROSPECTION_MAKEFILE) @@ -492,7 +490,6 @@ $(IDN_CFLAGS) \ $(NETWORKMANAGER_CFLAGS) \ $(JSON_CFLAGS) \ - $(ZLIB_CFLAGS) \ $(INTROSPECTION_CFLAGS) Purple_3_0_gir_LIBS = $(builddir)/libpurple.la
--- a/libpurple/http.c Wed Aug 09 01:09:35 2017 +0000 +++ b/libpurple/http.c Fri Aug 11 00:43:27 2017 +0000 @@ -29,11 +29,6 @@ #include "proxy.h" #include "purple-gio.h" -#include <zlib.h> -#ifndef z_const -#define z_const -#endif - #define PURPLE_HTTP_URL_CREDENTIALS_CHARS "a-z0-9.,~_/*!&%?=+\\^-" #define PURPLE_HTTP_MAX_RECV_BUFFER_LEN 10240 #define PURPLE_HTTP_MAX_READ_BUFFER_LEN 10240 @@ -223,7 +218,7 @@ struct _PurpleHttpGzStream { gboolean failed; - z_stream zs; + GZlibDecompressor *decompressor; gsize max_output; gsize decompressed; GString *pending; @@ -371,19 +366,14 @@ purple_http_gz_new(gsize max_output, gboolean is_deflate) { PurpleHttpGzStream *gzs = g_new0(PurpleHttpGzStream, 1); - int windowBits; + GZlibCompressorFormat format; if (is_deflate) - windowBits = -MAX_WBITS; + format = G_ZLIB_COMPRESSOR_FORMAT_RAW; else /* is gzip */ - windowBits = MAX_WBITS + 32; - - if (inflateInit2(&gzs->zs, windowBits) != Z_OK) { - purple_debug_error("http", "Cannot initialize zlib stream\n"); - g_free(gzs); - return NULL; - } - + format = G_ZLIB_COMPRESSOR_FORMAT_GZIP; + + gzs->decompressor = g_zlib_decompressor_new(format); gzs->max_output = max_output; return gzs; @@ -395,7 +385,6 @@ const gchar *compressed_buff; gsize compressed_len; GString *ret; - z_stream *zs; g_return_val_if_fail(gzs != NULL, NULL); g_return_val_if_fail(buf != NULL, NULL); @@ -403,8 +392,6 @@ if (gzs->failed) return NULL; - zs = &gzs->zs; - if (gzs->pending) { g_string_append_len(gzs->pending, buf, len); compressed_buff = gzs->pending->str; @@ -414,22 +401,26 @@ compressed_len = len; } - zs->next_in = (z_const Bytef*)compressed_buff; - zs->avail_in = compressed_len; - ret = g_string_new(NULL); - while (zs->avail_in > 0) { - int gzres; + while (compressed_len > 0) { + GConverterResult gzres; gchar decompressed_buff[PURPLE_HTTP_GZ_BUFF_LEN]; - gsize decompressed_len; - - zs->next_out = (Bytef*)decompressed_buff; - zs->avail_out = sizeof(decompressed_buff); - decompressed_len = zs->avail_out = sizeof(decompressed_buff); - gzres = inflate(zs, Z_FULL_FLUSH); - decompressed_len -= zs->avail_out; - - if (gzres == Z_OK || gzres == Z_STREAM_END) { + gsize decompressed_len = 0; + gsize bytes_read = 0; + GError *error = NULL; + + gzres = g_converter_convert(G_CONVERTER(gzs->decompressor), + compressed_buff, compressed_len, + decompressed_buff, sizeof(decompressed_buff), + G_CONVERTER_NO_FLAGS, + &bytes_read, + &decompressed_len, + &error); + + compressed_buff += bytes_read; + compressed_len -= bytes_read; + + if (gzres == G_CONVERTER_CONVERTED || G_CONVERTER_FINISHED) { if (decompressed_len == 0) break; if (gzs->decompressed + decompressed_len >= @@ -439,17 +430,18 @@ " decompressed data is reached\n"); decompressed_len = gzs->max_output - gzs->decompressed; - gzres = Z_STREAM_END; + gzres = G_CONVERTER_FINISHED; } gzs->decompressed += decompressed_len; g_string_append_len(ret, decompressed_buff, decompressed_len); - if (gzres == Z_STREAM_END) + if (gzres == G_CONVERTER_FINISHED) break; } else { purple_debug_error("http", "Decompression failed (%d): %s\n", gzres, - zs->msg); + error->message); + g_clear_error(&error); gzs->failed = TRUE; return NULL; } @@ -460,9 +452,9 @@ gzs->pending = NULL; } - if (zs->avail_in > 0) { - gzs->pending = g_string_new_len((gchar*)zs->next_in, - zs->avail_in); + if (compressed_len > 0) { + gzs->pending = g_string_new_len(compressed_buff, + compressed_len); } return ret; @@ -473,7 +465,7 @@ { if (gzs == NULL) return; - inflateEnd(&gzs->zs); + g_object_unref(gzs->decompressor); if (gzs->pending) g_string_free(gzs->pending, TRUE); g_free(gzs);
--- a/libpurple/meson.build Wed Aug 09 01:09:35 2017 +0000 +++ b/libpurple/meson.build Fri Aug 11 00:43:27 2017 +0000 @@ -393,8 +393,7 @@ dependencies : # static_link_libs [dbus, dbus_glib, dnsapi, ws2_32, glib, gio, gplugin, libxml, farstream, gstreamer, gstreamer_video, - gstreamer_app, idn, json, - zlib, math]) + gstreamer_app, idn, json, math]) libpurple_dep = declare_dependency( sources : purple_builtheaders, # Ensure built before any dependencies. include_directories : [toplevel_inc, libpurple_inc],
--- a/libpurple/protocols/facebook/Makefile.am Wed Aug 09 01:09:35 2017 +0000 +++ b/libpurple/protocols/facebook/Makefile.am Fri Aug 11 00:43:27 2017 +0000 @@ -48,6 +48,5 @@ -I$(top_srcdir) \ $(GLIB_CFLAGS) \ $(JSON_CFLAGS) \ - $(ZLIB_CFLAGS) \ $(GPLUGIN_CFLAGS) \ $(DEBUG_CFLAGS)
--- a/meson.build Wed Aug 09 01:09:35 2017 +0000 +++ b/meson.build Fri Aug 11 00:43:27 2017 +0000 @@ -604,12 +604,6 @@ json = dependency('json-glib-1.0', version : '>= 0.14.0') ####################################################################### -# Check for zlib (required) -####################################################################### - -zlib = dependency('zlib', version : '>= 1.2.0') - -####################################################################### # Check for GStreamer #######################################################################
--- a/pidgin/win32/gtkwin32dep.c Wed Aug 09 01:09:35 2017 +0000 +++ b/pidgin/win32/gtkwin32dep.c Fri Aug 11 00:43:27 2017 +0000 @@ -36,7 +36,6 @@ #include "network.h" #include "resource.h" -#include "zlib.h" #include "untar.h" #include "gtkwin32dep.h" @@ -73,36 +72,59 @@ } int winpidgin_gz_decompress(const char* in, const char* out) { - gzFile fin; - FILE *fout; - char buf[1024]; - int ret; + GFile *fin; + GFile *fout; + GInputStream *input; + GOutputStream *output; + GOutputStream *conv_out; + GZlibDecompressor *decompressor; + gssize size; + GError *error = NULL; - if((fin = gzopen(in, "rb"))) { - if(!(fout = g_fopen(out, "wb"))) { - purple_debug_error("winpidgin_gz_decompress", "Error opening file: %s\n", out); - gzclose(fin); - return 0; - } - } - else { - purple_debug_error("winpidgin_gz_decompress", "gzopen failed to open: %s\n", in); + fin = g_file_new_for_path(in); + input = G_INPUT_STREAM(g_file_read(fin, NULL, &error)); + g_object_unref(fin); + + if (input == NULL) { + purple_debug_error("winpidgin_gz_decompress", + "Failed to open: %s: %s\n", + in, error->message); + g_clear_error(&error); return 0; } - while((ret = gzread(fin, buf, 1024))) { - if ((int)fwrite(buf, 1, ret, fout) < ret) { - purple_debug_error("wpurple_gz_decompress", "Error writing %d bytes to file\n", ret); - gzclose(fin); - fclose(fout); - return 0; - } + fout = g_file_new_for_path(out); + output = G_OUTPUT_STREAM(g_file_replace(fout, NULL, FALSE, + G_FILE_CREATE_NONE, NULL, &error)); + g_object_unref(fout); + + if (output == NULL) { + purple_debug_error("winpidgin_gz_decompress", + "Error opening file: %s: %s\n", + out, error->message); + g_clear_error(&error); + g_object_unref(input); + return 0; } - fclose(fout); - gzclose(fin); + + decompressor = g_zlib_decompressor_new(G_ZLIB_COMPRESSOR_FORMAT_GZIP); + conv_out = g_converter_output_stream_new(output, + G_CONVERTER(decompressor)); + g_object_unref(decompressor); + g_object_unref(output); - if(ret < 0) { - purple_debug_error("winpidgin_gz_decompress", "gzread failed while reading: %s\n", in); + size = g_output_stream_splice(conv_out, input, + G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | + G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, NULL, &error); + + g_object_unref(input); + g_object_unref(conv_out); + + if (size < 0) { + purple_debug_error("wpurple_gz_decompress", + "Error writing to file: %s\n", + error->message); + g_clear_error(&error); return 0; }