[libgadu-commit] r741 - in branches/new-api: include src

Libgadu commit list libgadu-commit at lists.ziew.org
Thu Jun 11 13:38:18 CEST 2009


Author: wojtekka
Date: 2009-06-11 13:38:17 +0200 (Thu, 11 Jun 2009)
New Revision: 741

Added:
   branches/new-api/src/debug.c
Modified:
   branches/new-api/include/libgadu.h.in
   branches/new-api/src/Makefile.am
   branches/new-api/src/common.c
   branches/new-api/src/events.c
   branches/new-api/src/libgadu.c
   branches/new-api/src/session.c
Log:
Wydzielenie funkcji odpluskwiania do osobnego pliku.
Dodanie obsługi zdarzeń do session.c.
Nie usuwamy gg_session->client_version po połączeniu.


Modified: branches/new-api/include/libgadu.h.in
===================================================================
--- branches/new-api/include/libgadu.h.in	2009-06-10 11:12:37 UTC (rev 740)
+++ branches/new-api/include/libgadu.h.in	2009-06-11 11:38:17 UTC (rev 741)
@@ -282,6 +282,9 @@
 	unsigned int ping_period;	/**< Okres wysyłania pakietu utrzymania połączenia */
 	unsigned int max_image_chunk_length;	/**< Maksymalna długość fragmentu obrazka */
 	unsigned int max_notify_chunk_size;	/**< Maksymalny rozmiar bloku kontaktów */
+
+	struct gg_event *event_queue_head;	/**< Początek kolejki zdarzeń */
+	struct gg_event *event_queue_tail;	/**< Koniec kolejki zdarzeń */
 };
 
 /**
@@ -667,6 +670,9 @@
 int gg_session_import_contacts(struct gg_session *gs);
 int gg_session_image_request(struct gg_session *gs, uin_t recipient, size_t size, uint32_t crc32);
 int gg_session_image_reply(struct gg_session *gs, uin_t recipient, const char *image, size_t size, uint32_t crc32);
+int gg_session_handle_io(struct gg_session *gs, int condition);
+struct gg_event *gg_session_get_event(struct gg_session *gs);
+const struct gg_event *gg_session_peek_event(struct gg_session *gs);
 void gg_session_free(struct gg_session *gs);
 
 gg_message_t *gg_message_new(void);
@@ -1024,6 +1030,7 @@
 struct gg_event {
 	int type;			/**< Rodzaj zdarzenia */
 	union gg_event_union event;	/**< Informacja o zdarzeniu */
+	struct gg_event *next;		/**< Kolejne zdarzenie w kolejce */
 };
 
 struct gg_event *gg_watch_fd(struct gg_session *sess);

Modified: branches/new-api/src/Makefile.am
===================================================================
--- branches/new-api/src/Makefile.am	2009-06-10 11:12:37 UTC (rev 740)
+++ branches/new-api/src/Makefile.am	2009-06-11 11:38:17 UTC (rev 741)
@@ -1,4 +1,4 @@
 lib_LTLIBRARIES = libgadu.la
-libgadu_la_SOURCES = common.c dcc.c dcc7.c events.c http.c obsolete.c pubdir.c pubdir50.c libgadu.c sha1.c resolver.c session.c encoding.c message.c
+libgadu_la_SOURCES = common.c dcc.c dcc7.c events.c http.c obsolete.c pubdir.c pubdir50.c libgadu.c sha1.c resolver.c session.c encoding.c message.c debug.c
 libgadu_la_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/include
 libgadu_la_LDFLAGS = -version-number 3:10

Modified: branches/new-api/src/common.c
===================================================================
--- branches/new-api/src/common.c	2009-06-10 11:12:37 UTC (rev 740)
+++ branches/new-api/src/common.c	2009-06-11 11:38:17 UTC (rev 741)
@@ -45,127 +45,6 @@
 #include "libgadu.h"
 
 /**
- * Plik, do którego będą przekazywane informacje odpluskwiania.
- *
- * Funkcja \c gg_debug() i pochodne mogą być przechwytywane przez aplikację
- * korzystającą z biblioteki, by wyświetlić je na żądanie użytkownika lub
- * zapisać do późniejszej analizy. Jeśli nie określono pliku, wybrane
- * informacje będą wysyłane do standardowego wyjścia błędu (\c stderr).
- *
- * \ingroup debug
- */
-FILE *gg_debug_file = NULL;
-
-#ifndef GG_DEBUG_DISABLE
-
-/**
- * \internal Przekazuje informacje odpluskwiania do odpowiedniej funkcji.
- *
- * Jeśli aplikacja ustawiła odpowiednią funkcję obsługi w
- * \c gg_debug_handler_session lub \c gg_debug_handler, jest ona wywoływana.
- * W przeciwnym wypadku wynik jest wysyłany do standardowego wyjścia błędu.
- *
- * \param sess Struktura sesji (może być \c NULL)
- * \param level Poziom informacji
- * \param format Format wiadomości (zgodny z \c printf)
- * \param ap Lista argumentów (zgodna z \c printf)
- */
-void gg_debug_common(struct gg_session *sess, int level, const char *format, va_list ap)
-{
-	if (gg_debug_handler_session)
-		(*gg_debug_handler_session)(sess, level, format, ap);
-	else if (gg_debug_handler)
-		(*gg_debug_handler)(level, format, ap);
-	else if (gg_debug_level & level)
-		vfprintf(gg_debug_file ? gg_debug_file : stderr, format, ap);
-}
-
-
-/**
- * Przekazuje informację odpluskawiania.
- *
- * \param level Poziom wiadomości
- * \param format Format wiadomości (zgodny z \c printf)
- *
- * \ingroup debug
- */
-void gg_debug(int level, const char *format, ...)
-{
-	va_list ap;
-	int old_errno = errno;
-	va_start(ap, format);
-	gg_debug_common(NULL, level, format, ap);
-	va_end(ap);
-	errno = old_errno;
-}
-
-/**
- * Przekazuje informację odpluskwiania związaną z sesją.
- *
- * \param sess Struktura sesji
- * \param level Poziom wiadomości
- * \param format Format wiadomości (zgodny z \c printf)
- *
- * \ingroup debug
- */
-void gg_debug_session(struct gg_session *sess, int level, const char *format, ...)
-{
-	va_list ap;
-	int old_errno = errno;
-	va_start(ap, format);
-	gg_debug_common(sess, level, format, ap);
-	va_end(ap);
-	errno = old_errno;
-}
-
-/**
- * Przekazuje zrzut bufora do odpluskwiania.
- *
- * \param sess Struktura sesji
- * \param level Poziom wiadomości
- * \param buf Bufor danych
- * \param len Długość bufora danych
- *
- * \ingroup debug
- */
-void gg_debug_dump(struct gg_session *sess, int level, const char *buf, int len)
-{
-	int i, j;
-
-	for (i = 0; i < len; i += 16) {
-		gg_debug_session(sess, level, "%.4x: ", i);
-
-		for (j = 0; j < 16; j++) {
-			if (i + j < len)
-				gg_debug_session(sess, level, " %02x", (unsigned char) buf[i + j]);
-			else
-				gg_debug_session(sess, level, "   ");
-		}
-
-		gg_debug_session(sess, level, "  ");
-
-		for (j = 0; j < 16; j++) {
-			unsigned char ch;
-
-			if (i + j < len) {
-				ch = buf[i + j];
-
-				if (ch < 32 || ch > 126)
-					ch = '.';
-
-				gg_debug_session(sess, level, "%c", ch);
-			} else {
-				gg_debug_session(sess, level, " ");
-			}
-		}
-
-		gg_debug_session(sess, level, "\n");
-	}
-}
-
-#endif
-
-/**
  * Odpowiednik funkcji \c vsprintf alokujący miejsce na wynik.
  *
  * Funkcja korzysta z funkcji \c vsnprintf, sprawdzając czy dostępna funkcja

Added: branches/new-api/src/debug.c
===================================================================
--- branches/new-api/src/debug.c	                        (rev 0)
+++ branches/new-api/src/debug.c	2009-06-11 11:38:17 UTC (rev 741)
@@ -0,0 +1,233 @@
+/* $Id$ */
+
+/*
+ *  (C) Copyright 2001-2006 Wojtek Kaniewski <wojtekka at irc.pl>
+ *                          Robert J. Woźny <speedy at ziew.org>
+ *                          Arkadiusz Miśkiewicz <arekm at pld-linux.org>
+ *                          Tomasz Chiliński <chilek at chilan.com>
+ *                          Adam Wysocki <gophi at ekg.chmurka.net>
+ *
+ *  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 debug.c
+ *
+ * \brief Funkcje odpluskwiania
+ */
+#include <sys/types.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "libgadu.h"
+
+/**
+ * Poziom rejestracji informacji odpluskwiających. Zmienna jest maską bitową
+ * składającą się ze stałych \c GG_DEBUG_...
+ *
+ * \ingroup debug
+ */
+int gg_debug_level = 0;
+
+/**
+ * Funkcja, do której są przekazywane informacje odpluskwiające. Jeśli zarówno
+ * ten \c gg_debug_handler, jak i \c gg_debug_handler_session, są równe
+ * \c NULL, informacje są wysyłane do standardowego wyjścia błędu (\c stderr).
+ *
+ * \param level Poziom rejestracji
+ * \param format Format wiadomości (zgodny z \c printf)
+ * \param ap Lista argumentów (zgodna z \c printf)
+ *
+ * \note Funkcja jest przesłaniana przez \c gg_debug_handler_session.
+ *
+ * \ingroup debug
+ */
+void (*gg_debug_handler)(int level, const char *format, va_list ap) = NULL;
+
+/**
+ * Funkcja, do której są przekazywane informacje odpluskwiające. Jeśli zarówno
+ * ten \c gg_debug_handler, jak i \c gg_debug_handler_session, są równe
+ * \c NULL, informacje są wysyłane do standardowego wyjścia błędu.
+ *
+ * \param sess Sesja której dotyczy informacja lub \c NULL
+ * \param level Poziom rejestracji
+ * \param format Format wiadomości (zgodny z \c printf)
+ * \param ap Lista argumentów (zgodna z \c printf)
+ *
+ * \note Funkcja przesłania przez \c gg_debug_handler_session.
+ *
+ * \ingroup debug
+ */
+void (*gg_debug_handler_session)(struct gg_session *sess, int level, const char *format, va_list ap) = NULL;
+
+/**
+ * Plik, do którego będą przekazywane informacje odpluskwiania.
+ *
+ * Funkcja \c gg_debug() i pochodne mogą być przechwytywane przez aplikację
+ * korzystającą z biblioteki, by wyświetlić je na żądanie użytkownika lub
+ * zapisać do późniejszej analizy. Jeśli nie określono pliku, wybrane
+ * informacje będą wysyłane do standardowego wyjścia błędu (\c stderr).
+ *
+ * \ingroup debug
+ */
+FILE *gg_debug_file = NULL;
+
+#ifndef GG_DEBUG_DISABLE
+
+/**
+ * \internal Przekazuje informacje odpluskwiania do odpowiedniej funkcji.
+ *
+ * Jeśli aplikacja ustawiła odpowiednią funkcję obsługi w
+ * \c gg_debug_handler_session lub \c gg_debug_handler, jest ona wywoływana.
+ * W przeciwnym wypadku wynik jest wysyłany do standardowego wyjścia błędu.
+ *
+ * \param sess Struktura sesji (może być \c NULL)
+ * \param level Poziom informacji
+ * \param format Format wiadomości (zgodny z \c printf)
+ * \param ap Lista argumentów (zgodna z \c printf)
+ */
+void gg_debug_common(struct gg_session *sess, int level, const char *format, va_list ap)
+{
+	if (gg_debug_handler_session)
+		(*gg_debug_handler_session)(sess, level, format, ap);
+	else if (gg_debug_handler)
+		(*gg_debug_handler)(level, format, ap);
+	else if (gg_debug_level & level)
+		vfprintf((gg_debug_file) ? gg_debug_file : stderr, format, ap);
+}
+
+
+/**
+ * Przekazuje informację odpluskawiania.
+ *
+ * \param level Poziom wiadomości
+ * \param format Format wiadomości (zgodny z \c printf)
+ *
+ * \ingroup debug
+ */
+void gg_debug(int level, const char *format, ...)
+{
+	va_list ap;
+	int old_errno = errno;
+	va_start(ap, format);
+	gg_debug_common(NULL, level, format, ap);
+	va_end(ap);
+	errno = old_errno;
+}
+
+/**
+ * Przekazuje informację odpluskwiania związaną z sesją.
+ *
+ * \param sess Struktura sesji
+ * \param level Poziom wiadomości
+ * \param format Format wiadomości (zgodny z \c printf)
+ *
+ * \ingroup debug
+ */
+void gg_debug_session(struct gg_session *gs, int level, const char *format, ...)
+{
+	va_list ap;
+	int old_errno = errno;
+	va_start(ap, format);
+	gg_debug_common(gs, level, format, ap);
+	va_end(ap);
+	errno = old_errno;
+}
+
+/**
+ * Przekazuje zrzut bufora do odpluskwiania.
+ *
+ * \param sess Struktura sesji
+ * \param level Poziom wiadomości
+ * \param buf Bufor danych
+ * \param len Długość bufora danych
+ *
+ * \ingroup debug
+ */
+void gg_debug_dump(struct gg_session *gs, int level, const char *buf, int len)
+{
+	char line[80];
+	int i, j;
+
+	for (i = 0; i < len; i += 16) {
+		int ofs;
+
+		sprintf(line, "%.4x: ", i);
+		ofs = 6;
+//		gg_debug_session(sess, level, "%.4x: ", i);
+
+		for (j = 0; j < 16; j++) {
+			if (i + j < len)
+				sprintf(line + ofs, " %02x", (unsigned char) buf[i + j]);
+//				gg_debug_session(sess, level, " %02x", (unsigned char) buf[i + j]);
+			else
+				sprintf(line + ofs, "   ");
+//				gg_debug_session(sess, level, "   ");
+
+			ofs += 3;
+		}
+
+		sprintf(line + ofs, "  ");
+//		gg_debug_session(sess, level, "  ");
+		ofs += 2;
+
+		for (j = 0; j < 16; j++) {
+			unsigned char ch;
+
+			if (i + j < len) {
+				ch = buf[i + j];
+
+				if (ch < 32 || ch > 126)
+					ch = '.';
+			} else {
+				ch = ' ';
+			}
+
+			line[ofs++] = ch;
+//			gg_debug_session(sess, level, "%c", ch);
+		}
+
+		line[ofs++] = '\n';
+		line[ofs++] = 0;
+
+		gg_debug_session(gs, level, "%s", line);
+	}
+}
+
+#else
+
+#undef gg_debug_common
+void gg_debug_common(struct gg_session *sess, int level, const char *format, va_list ap)
+{
+}
+
+#undef gg_debug
+void gg_debug(int level, const char *format, ...)
+{
+}
+
+#undef gg_debug_session
+void gg_debug_session(struct gg_session *gs, int level, const char *format, ...)
+{
+}
+
+#undef gg_debug_dump
+void gg_debug_dump(struct gg_session *gs, int level, const char *buf, int len)
+{
+}
+
+#endif

Modified: branches/new-api/src/events.c
===================================================================
--- branches/new-api/src/events.c	2009-06-10 11:12:37 UTC (rev 740)
+++ branches/new-api/src/events.c	2009-06-11 11:38:17 UTC (rev 741)
@@ -1404,10 +1404,6 @@
 			free(auth);
 			free(client);
 
-			/* zwolnij pamięć po wersji klienta. */
-			free(sess->client_version);
-			sess->client_version = NULL;
-
 			gg_debug_session(sess, GG_DEBUG_MISC, "=> -----BEGIN-HTTP-QUERY-----\n%s\n=> -----END-HTTP-QUERY-----\n", buf);
 
 			/* zapytanie jest krótkie, więc zawsze zmieści się

Modified: branches/new-api/src/libgadu.c
===================================================================
--- branches/new-api/src/libgadu.c	2009-06-10 11:12:37 UTC (rev 740)
+++ branches/new-api/src/libgadu.c	2009-06-11 11:38:17 UTC (rev 741)
@@ -56,45 +56,6 @@
 #endif
 
 /**
- * Poziom rejestracji informacji odpluskwiających. Zmienna jest maską bitową
- * składającą się ze stałych \c GG_DEBUG_...
- *
- * \ingroup debug
- */
-int gg_debug_level = 0;
-
-/**
- * Funkcja, do której są przekazywane informacje odpluskwiające. Jeśli zarówno
- * ten \c gg_debug_handler, jak i \c gg_debug_handler_session, są równe
- * \c NULL, informacje są wysyłane do standardowego wyjścia błędu (\c stderr).
- *
- * \param level Poziom rejestracji
- * \param format Format wiadomości (zgodny z \c printf)
- * \param ap Lista argumentów (zgodna z \c printf)
- *
- * \note Funkcja jest przesłaniana przez \c gg_debug_handler_session.
- *
- * \ingroup debug
- */
-void (*gg_debug_handler)(int level, const char *format, va_list ap) = NULL;
-
-/**
- * Funkcja, do której są przekazywane informacje odpluskwiające. Jeśli zarówno
- * ten \c gg_debug_handler, jak i \c gg_debug_handler_session, są równe
- * \c NULL, informacje są wysyłane do standardowego wyjścia błędu.
- *
- * \param sess Sesja której dotyczy informacja lub \c NULL
- * \param level Poziom rejestracji
- * \param format Format wiadomości (zgodny z \c printf)
- * \param ap Lista argumentów (zgodna z \c printf)
- *
- * \note Funkcja przesłania przez \c gg_debug_handler_session.
- *
- * \ingroup debug
- */
-void (*gg_debug_handler_session)(struct gg_session *sess, int level, const char *format, va_list ap) = NULL;
-
-/**
  * Port gniazda nasłuchującego dla połączeń bezpośrednich.
  * 
  * \ingroup ip
@@ -538,70 +499,92 @@
 int gg_send_packet(struct gg_session *sess, int type, ...)
 {
 	struct gg_header *h;
-	char *tmp;
-	unsigned int tmp_length;
-	void *payload;
-	unsigned int payload_length;
+	char *packet;
+	unsigned int packet_ofs;
+	unsigned int packet_len;
+	void *chunk;
+	unsigned int chunk_len;
 	va_list ap;
 	int res;
 
 	gg_debug_session(sess, GG_DEBUG_FUNCTION, "** gg_send_packet(%p, 0x%.2x, ...);\n", sess, type);
 
-	tmp_length = sizeof(struct gg_header);
+	/* Policz długość pakietu */
 
-	if (!(tmp = malloc(tmp_length))) {
-		gg_debug_session(sess, GG_DEBUG_MISC, "// gg_send_packet() not enough memory for packet header\n");
-		return -1;
-	}
+	packet_len = sizeof(struct gg_header);
 
 	va_start(ap, type);
 
-	payload = va_arg(ap, void *);
+	for (;;) {
+		chunk = va_arg(ap, void *);
+		if (chunk == NULL)
+			break;
+		chunk_len = va_arg(ap, unsigned int);
 
-	while (payload) {
-		char *tmp2;
+		packet_len += chunk_len;
+	}
 
-		payload_length = va_arg(ap, unsigned int);
+	va_end(ap);
 
-		if (!(tmp2 = realloc(tmp, tmp_length + payload_length))) {
-			gg_debug_session(sess, GG_DEBUG_MISC, "// gg_send_packet() not enough memory for payload\n");
-			free(tmp);
-			va_end(ap);
-			return -1;
-		}
+	/* Zaalokuj pamięć */
 
-		tmp = tmp2;
+	packet = malloc(packet_len);
 
-		memcpy(tmp + tmp_length, payload, payload_length);
-		tmp_length += payload_length;
+	if (packet == NULL) {
+		gg_debug_session(sess, GG_DEBUG_MISC, "// gg_send_packet() not enough memory for packet (%d bytes)\n", packet_len);
+		return -1;
+	}
 
-		payload = va_arg(ap, void *);
+	/* Wypełnij nagłówek */
+
+	h = (struct gg_header*) packet;
+	h->type = gg_fix32(type);
+	h->length = gg_fix32(packet_len - sizeof(struct gg_header));
+
+	/* Sklej wszystkie kawałki w jedną całość */
+
+	packet_ofs = sizeof(struct gg_header);
+
+	va_start(ap, type);
+
+	for (;;) {
+		chunk = va_arg(ap, void *);
+		if (chunk == NULL)
+			break;
+		chunk_len = va_arg(ap, unsigned int);
+
+		memcpy(packet + packet_ofs, chunk, chunk_len);
+		packet_ofs += chunk_len;
 	}
 
 	va_end(ap);
 
-	h = (struct gg_header*) tmp;
-	h->type = gg_fix32(type);
-	h->length = gg_fix32(tmp_length - sizeof(struct gg_header));
+	/* Zaloguj */
 
 	if ((gg_debug_level & GG_DEBUG_DUMP)) {
 		gg_debug_session(sess, GG_DEBUG_DUMP, "// gg_send_packet() packet dump:\n");
-		gg_debug_dump(sess, GG_DEBUG_DUMP, tmp, tmp_length);
+		gg_debug_dump(sess, GG_DEBUG_DUMP, packet, packet_len);
 	}
 
-	res = gg_write(sess, tmp, tmp_length);
+	/* Wyślij */
 
-	free(tmp);
+	res = gg_write(sess, packet, packet_len);
 
+	free(packet);
+
 	if (res == -1) {
 		gg_debug_session(sess, GG_DEBUG_MISC, "// gg_send_packet() write() failed. res = %d, errno = %d (%s)\n", res, errno, strerror(errno));
 		return -1;
 	}
 
-	if (sess->async)
-		gg_debug_session(sess, GG_DEBUG_MISC, "// gg_send_packet() partial write(), %d sent, %d left, %d total left\n", res, tmp_length - res, sess->send_left);
+	if (sess->async) {
+		if (res != packet_len)
+			gg_debug_session(sess, GG_DEBUG_MISC, "// gg_send_packet() partial write: %d sent, %d left, %d total left\n", res, packet_len - res, sess->send_left);
+		else
+			gg_debug_session(sess, GG_DEBUG_MISC, "// gg_send_packet() written %d bytes\n", res);
+	}
 
-	if (sess->send_buf)
+	if (sess->send_buf != NULL)
 		sess->check |= GG_CHECK_WRITE;
 
 	return 0;

Modified: branches/new-api/src/session.c
===================================================================
--- branches/new-api/src/session.c	2009-06-10 11:12:37 UTC (rev 740)
+++ branches/new-api/src/session.c	2009-06-11 11:38:17 UTC (rev 741)
@@ -71,8 +71,8 @@
 	memset(gs, 0, sizeof(struct gg_session));
 
 	gs->type = GG_SESSION_GG;
-	gs->callback = gg_session_callback;
-	gs->destroy = gg_session_free;
+	gs->callback = gg_session_callback;	// XXX do usunięcia
+	gs->destroy = gg_session_free;		// XXX do usunięcia
 	gs->pid = -1;
 	gs->encoding = GG_ENCODING_UTF8;
 	gs->hash_type = GG_LOGIN_HASH_SHA1;
@@ -1420,6 +1420,53 @@
 	return gg_send_packet(gs, GG_ADD_NOTIFY, &a, sizeof(a), NULL);
 }
 
+int gg_session_handle_io(struct gg_session *gs, int condition)
+{
+	struct gg_event *ge;
+
+	GG_SESSION_CHECK(gs, -1);
+
+	ge = gg_watch_fd(gs);
+
+	if (ge == NULL)
+		return -1;
+
+	if (gs->event_queue_head == NULL) {
+		gs->event_queue_head = ge;
+		gs->event_queue_tail = ge;
+	} else {
+		// XXX gs->event_queue_tail != NULL
+		gs->event_queue_tail->next = ge;
+		gs->event_queue_tail = ge;
+	}
+
+	return 0;
+}
+
+struct gg_event *gg_session_get_event(struct gg_session *gs)
+{
+	struct gg_event *res = NULL;
+
+	GG_SESSION_CHECK(gs, NULL);
+	
+	if (gs->event_queue_head != NULL) {
+		res = gs->event_queue_head;
+		if (res == gs->event_queue_tail)
+			gs->event_queue_tail = NULL;
+		gs->event_queue_head = gs->event_queue_head->next;
+		res->next = NULL;
+	}
+
+	return res;
+}
+
+const struct gg_event *gg_session_peek_event(struct gg_session *gs)
+{
+	GG_SESSION_CHECK(gs, NULL);
+
+	return gs->event_queue_head;
+}
+
 /**
  * Zwalnia zasoby używane przez połączenie z serwerem. Funkcję należy wywołać
  * po zamknięciu połączenia z serwerem, by nie doprowadzić do wycieku zasobów
@@ -1432,6 +1479,7 @@
 void gg_session_free(struct gg_session *gs)
 {
 	struct gg_dcc7 *dcc;
+	struct gg_event *ge;
 
 	if (gs == NULL)
 		return;
@@ -1464,6 +1512,12 @@
 	for (dcc = gs->dcc7_list; dcc != NULL; dcc = dcc->next)
 		dcc->sess = NULL;
 
+	for (ge = gs->event_queue_head; ge != NULL; ) {
+		struct gg_event *next = ge->next;
+		gg_event_free(ge);
+		ge = next;
+	}
+
 	free(gs);
 }
 



More information about the libgadu-commit mailing list