pidgin: 0c4a4fbc: Forgot two files for the gg 1.11.0 updat...

elb at pidgin.im elb at pidgin.im
Sun Jun 5 10:21:08 EDT 2011


----------------------------------------------------------------------
Revision: 0c4a4fbccfea023172fc827e56f244e1fa0dbe7c
Parent:   0cfe18da7cbd8d3462741378584340a8fb6e08ba
Author:   elb at pidgin.im
Date:     06/05/11 10:15:04
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/0c4a4fbccfea023172fc827e56f244e1fa0dbe7c

Changelog: 

Forgot two files for the gg 1.11.0 update

Changes against parent 0cfe18da7cbd8d3462741378584340a8fb6e08ba

  added    libpurple/protocols/gg/lib/deflate.c
  added    libpurple/protocols/gg/lib/deflate.h

-------------- next part --------------
============================================================
--- /dev/null	
+++ libpurple/protocols/gg/lib/deflate.c	0532a45e14b8276183254173c98543f5890da67f
@@ -0,0 +1,219 @@
+/* $Id$ */
+
+/*
+ *  (C) Copyright 2011 Bartosz Brachaczek <b.brachaczek at gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License Version
+ *  2.1 as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
+ *  USA.
+ */
+
+/**
+ * \file deflate.c
+ *
+ * \brief Funkcje kompresji Deflate
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "libgadu.h"
+#include "deflate.h"
+
+#ifdef GG_CONFIG_HAVE_ZLIB
+#include <zlib.h>
+#endif
+
+/**
+ * \internal Kompresuje dane wej?ciowe algorytmem Deflate z najwy?szym
+ * stopniem kompresji, tak samo jak oryginalny klient.
+ * 
+ * Wynik funkcji nale?y zwolni? za pomoc? \c free.
+ *
+ * \param in Ci?g znak?w do skompresowania, zako?czony \c \\0
+ * \param out_lenp Wska?nik na zmienn?, do kt?rej zostanie zapisana
+ *                 d?ugo?? bufora wynikowego
+ *
+ * \return Skompresowany ci?g znak?w lub \c NULL w przypadku niepowodzenia.
+ */
+unsigned char *gg_deflate(const char *in, size_t *out_lenp)
+{
+#ifdef GG_CONFIG_HAVE_ZLIB
+	int ret;
+	z_stream strm;
+	unsigned char *out, *out2;
+	size_t out_len;
+
+	if (in == NULL || out_lenp == NULL)
+		return NULL;
+
+	strm.zalloc = Z_NULL;
+	strm.zfree = Z_NULL;
+	strm.opaque = Z_NULL;
+	strm.avail_in = strlen(in);
+	strm.next_in = (unsigned char*) in;
+
+	ret = deflateInit(&strm, Z_BEST_COMPRESSION);
+	if (ret != Z_OK) {
+		gg_debug(GG_DEBUG_MISC, "// gg_deflate() deflateInit() failed (%d)\n", ret);
+		return NULL;
+	}
+
+	out_len = deflateBound(&strm, strm.avail_in);
+	out = malloc(out_len);
+
+	if (out == NULL) {
+		gg_debug(GG_DEBUG_MISC, "// gg_deflate() not enough memory for output data (%d)\n", out_len);
+		goto fail;
+	}
+
+	strm.avail_out = out_len;
+	strm.next_out = out;
+
+	for (;;) {
+		ret = deflate(&strm, Z_FINISH);
+		
+		if (ret == Z_STREAM_END)
+			break;
+		
+		/* raczej nie powinno si? zdarzy? przy Z_FINISH i out_len == deflateBound(),
+		 * ale dokumentacja zlib nie wyklucza takiej mo?liwo?ci */
+		if (ret == Z_OK) {
+			out_len *= 2;
+			out2 = realloc(out, out_len);
+			
+			if (out2 == NULL) {
+				gg_debug(GG_DEBUG_MISC, "// gg_deflate() not enough memory for output data (%d)\n", out_len);
+				goto fail;
+			}
+			
+			out = out2;
+			
+			strm.avail_out = out_len / 2;
+			strm.next_out = out + out_len / 2;
+		} else {
+			gg_debug(GG_DEBUG_MISC, "// gg_deflate() deflate() failed (ret=%d, msg=%s)\n", ret, strm.msg != NULL ? strm.msg : "no error message provided");
+			goto fail;
+		}
+	}
+
+	out_len = strm.total_out;
+	out2 = realloc(out, out_len);
+
+	if (out2 == NULL) {
+		gg_debug(GG_DEBUG_MISC, "// gg_deflate() not enough memory for output data (%d)\n", out_len);
+		goto fail;
+	}
+
+	*out_lenp = out_len;
+	deflateEnd(&strm);
+
+	return out2;
+
+fail:
+	*out_lenp = 0;
+	deflateEnd(&strm);
+	free(out);
+#endif
+	return NULL;
+}
+
+/**
+ * \internal Dekompresuje dane wej?ciowe w formacie Deflate.
+ *
+ * Wynik funkcji nale?y zwolni? za pomoc? \c free.
+ *
+ * \param in Bufor danych skompresowanych algorytmem Deflate
+ * \param length D?ugo?? bufora wej?ciowego
+ *
+ * \note Dokleja \c \\0 na ko?cu bufora wynikowego.
+ *
+ * \return Zdekompresowany ci?g znak?w, zako?czony \c \\0,
+ *         lub \c NULL w przypadku niepowodzenia.
+ */
+char *gg_inflate(const unsigned char *in, size_t length)
+{
+#ifdef GG_CONFIG_HAVE_ZLIB
+	int ret;
+	z_stream strm;
+	char *out = NULL, *out2;
+	size_t out_len = 1024;
+	int first = 1;
+
+	if (in == NULL)
+		return NULL;
+
+	strm.zalloc = Z_NULL;
+	strm.zfree = Z_NULL;
+	strm.opaque = Z_NULL;
+	strm.avail_in = length;
+	strm.next_in = (unsigned char*) in;
+
+	ret = inflateInit(&strm);
+	if (ret != Z_OK) {
+		gg_debug(GG_DEBUG_MISC, "// gg_inflate() inflateInit() failed (%d)\n", ret);
+		return NULL;
+	}
+
+	do {
+		out_len *= 2;
+		out2 = realloc(out, out_len);
+		
+		if (out2 == NULL) {
+			gg_debug(GG_DEBUG_MISC, "// gg_inflate() not enough memory for output data (%d)\n", out_len);
+			goto fail;
+		}
+		
+		out = out2;
+		
+		if (first) {
+			strm.avail_out = out_len;
+			strm.next_out = (unsigned char*) out;
+		} else {
+			strm.avail_out = out_len / 2;
+			strm.next_out = (unsigned char*) out + out_len / 2;
+		}
+		
+		ret = inflate(&strm, Z_NO_FLUSH);
+		
+		if (ret != Z_OK && ret != Z_STREAM_END) {
+			gg_debug(GG_DEBUG_MISC, "// gg_inflate() inflate() failed (ret=%d, msg=%s)\n", ret, strm.msg != NULL ? strm.msg : "no error message provided");
+			goto fail;
+		}
+		
+		first = 0;
+	} while (ret != Z_STREAM_END);
+
+	/* rezerwujemy ostatni znak na NULL-a */
+	out_len = strm.total_out + 1;
+	out2 = realloc(out, out_len);
+
+	if (out2 == NULL) {
+		gg_debug(GG_DEBUG_MISC, "// gg_inflate() not enough memory for output data (%d)\n", out_len);
+		goto fail;
+	}
+
+	out = out2;
+	out[out_len - 1] = '\0';
+
+	inflateEnd(&strm);
+
+	return out;
+
+fail:
+	inflateEnd(&strm);
+	free(out);
+#endif
+	return NULL;
+}
+
============================================================
--- /dev/null	
+++ libpurple/protocols/gg/lib/deflate.h	392439e640bfde845d8ee0b31687905f3da1dc5b
@@ -0,0 +1,29 @@
+/* $Id$ */
+
+/*
+ *  (C) Copyright 2009 Jakub Zawadzki <darkjames at darkjames.ath.cx>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License Version
+ *  2.1 as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
+ *  USA.
+ */
+
+#ifndef LIBGADU_DEFLATE_H
+#define LIBGADU_DEFLATE_H
+
+#include "libgadu.h"
+
+unsigned char *gg_deflate(const char *in, size_t *out_lenp);
+char *gg_inflate(const unsigned char *in, size_t length);
+
+#endif /* LIBGADU_DEFLATE_H */


More information about the Commits mailing list