/cpw/tomkiewicz/gg11: 89441dbabc83: Gadu-Gadu: initial GG11 conf...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Tue Sep 11 06:56:16 EDT 2012


Changeset: 89441dbabc83e32a8820b5d1bc88186d3fb1096e
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2012-09-11 12:56 +0200
Branch:	 default
URL: http://hg.pidgin.im/cpw/tomkiewicz/gg11/rev/89441dbabc83

Description:

Gadu-Gadu: initial GG11 conferences support

diffstat:

 libpurple/protocols/gg/Makefile.am |   72 +++---
 libpurple/protocols/gg/avatar.c    |    2 +-
 libpurple/protocols/gg/chat.c      |  365 +++++++++++++++++++++++++++++++++++++
 libpurple/protocols/gg/chat.h      |   26 ++
 libpurple/protocols/gg/confer.c    |  170 -----------------
 libpurple/protocols/gg/confer.h    |   93 ---------
 libpurple/protocols/gg/gg.c        |  257 ++-----------------------
 libpurple/protocols/gg/gg.h        |   13 +-
 libpurple/protocols/gg/servconn.c  |    6 +-
 9 files changed, 462 insertions(+), 542 deletions(-)

diffs (truncated from 1215 to 300 lines):

diff --git a/libpurple/protocols/gg/Makefile.am b/libpurple/protocols/gg/Makefile.am
--- a/libpurple/protocols/gg/Makefile.am
+++ b/libpurple/protocols/gg/Makefile.am
@@ -1,5 +1,5 @@
 #V=0
-#GADU_EXTRA_WARNINGS = -Wall -Wextra -Werror
+GADU_EXTRA = -Wall -Wextra -Werror -fno-inline
 
 pkgdir = $(libdir)/purple-$(PURPLE_MAJOR_VERSION)
 
@@ -51,44 +51,44 @@ endif
 
 GGSOURCES = \
 	$(INTGGSOURCES) \
+	account.c \
+	account.h \
+	avatar.c \
+	avatar.h \
+	buddylist.c \
+	buddylist.h \
+	chat.c \
+	chat.h \
+	deprecated.c \
+	deprecated.h \
+	gg.c \
+	gg.h \
+	image.h \
+	image.c \
+	libgadu-events.h \
+	libgadu-events.c \
+	libgaduw.h \
+	libgaduw.c \
+	multilogon.c \
+	multilogon.h \
+	pubdir-prpl.c \
+	pubdir-prpl.h \
+	purplew.h \
+	purplew.c \
+	resolver-purple.h \
+	resolver-purple.c \
+	roster.c \
+	roster.h \
+	servconn.c \
+	servconn.h \
+	status.c \
+	status.h \
 	utils.h \
 	utils.c \
-	confer.h \
-	confer.c \
-	buddylist.h \
-	buddylist.c \
-	gg.h \
-	gg.c \
-	resolver-purple.h \
-	resolver-purple.c \
-	image.h \
-	image.c \
-	account.h \
-	account.c \
-	deprecated.h \
-	deprecated.c \
-	purplew.h \
-	purplew.c \
-	libgaduw.h \
-	libgaduw.c \
-	avatar.h \
-	avatar.c \
-	libgadu-events.h \
-	libgadu-events.c \
-	roster.c \
-	roster.h \
 	validator.c \
 	validator.h \
 	xml.c \
 	xml.h \
-	multilogon.c \
-	multilogon.h \
-	status.c \
-	status.h \
-	servconn.c \
-	servconn.h \
-	pubdir-prpl.c \
-	pubdir-prpl.h \
 	oauth/oauth.c \
 	oauth/oauth.h \
 	oauth/oauth-parameter.c \
@@ -118,9 +118,11 @@ libgg_la_LIBADD  = $(GLIB_LIBS) $(GADU_L
 endif
 
 AM_CPPFLAGS = \
-	$(GADU_EXTRA_WARNINGS) \
 	-I$(top_srcdir)/libpurple \
 	-I$(top_builddir)/libpurple \
 	$(INTGG_CFLAGS) \
 	$(GLIB_CFLAGS) \
-	$(DEBUG_CFLAGS)
+	$(DEBUG_CFLAGS) \
+	$(GADU_EXTRA)
+
+CFLAGS = -g -O0
diff --git a/libpurple/protocols/gg/avatar.c b/libpurple/protocols/gg/avatar.c
--- a/libpurple/protocols/gg/avatar.c
+++ b/libpurple/protocols/gg/avatar.c
@@ -152,7 +152,7 @@ void ggp_avatar_buddy_update(PurpleConne
 {
 	ggp_avatar_session_data *avdata = ggp_avatar_get_avdata(gc);
 	ggp_avatar_buddy_update_req *pending_update =
-		g_new(ggp_avatar_buddy_update_req, 1);
+		g_new(ggp_avatar_buddy_update_req, 1); //TODO: leak?
 
 	purple_debug_misc("gg", "ggp_avatar_buddy_update(%p, %u, %lu)\n", gc,
 		uin, timestamp);
diff --git a/libpurple/protocols/gg/chat.c b/libpurple/protocols/gg/chat.c
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/gg/chat.c
@@ -0,0 +1,365 @@
+#include "chat.h"
+
+#include <debug.h>
+
+#include "gg.h"
+#include "utils.h"
+
+typedef struct _ggp_chat_local_info ggp_chat_local_info;
+
+struct _ggp_chat_session_data
+{
+	ggp_chat_local_info *chats;
+	int chats_count;
+};
+
+struct _ggp_chat_local_info
+{
+	int local_id;
+	uint64_t id;
+	
+	PurpleConversation *conv;
+	PurpleConnection *gc;
+	
+	gboolean previously_joined;
+};
+
+static ggp_chat_local_info * ggp_chat_new(PurpleConnection *gc, uint64_t id);
+static ggp_chat_local_info * ggp_chat_get(PurpleConnection *gc, uint64_t id);
+static ggp_chat_local_info * ggp_chat_get_local(PurpleConnection *gc,
+	int local_id);
+static void ggp_chat_joined(ggp_chat_local_info *chat, uin_t uin,
+	gboolean new_arrival);
+static void ggp_chat_left(ggp_chat_local_info *chat, uin_t uin);
+static const gchar * ggp_chat_get_name_from_id(uint64_t id);
+/*static uint64_t ggp_chat_get_id_from_name(const gchar * name);*/
+
+static inline ggp_chat_session_data *
+ggp_chat_get_sdata(PurpleConnection *gc)
+{
+	GGPInfo *accdata = purple_connection_get_protocol_data(gc);
+	return accdata->chat_data;
+}
+
+void ggp_chat_setup(PurpleConnection *gc)
+{
+	GGPInfo *accdata = purple_connection_get_protocol_data(gc);
+	ggp_chat_session_data *sdata = g_new0(ggp_chat_session_data, 1);
+
+	accdata->chat_data = sdata;
+
+	sdata->chats = NULL;
+	sdata->chats_count = 0;
+}
+
+void ggp_chat_cleanup(PurpleConnection *gc)
+{
+	ggp_chat_session_data *sdata = ggp_chat_get_sdata(gc);
+
+	g_free(sdata->chats);
+	g_free(sdata);
+}
+
+static ggp_chat_local_info * ggp_chat_new(PurpleConnection *gc, uint64_t id)
+{
+	ggp_chat_session_data *sdata = ggp_chat_get_sdata(gc);
+	int local_id;
+	ggp_chat_local_info *chat;
+
+	if (NULL == (chat = ggp_chat_get(gc, id)))
+	{
+		local_id = sdata->chats_count++;
+		sdata->chats = realloc(sdata->chats,
+			sdata->chats_count * sizeof(ggp_chat_local_info));
+		chat = &sdata->chats[local_id];
+
+		chat->local_id = local_id;
+		chat->id = id;
+		chat->conv = NULL;
+		chat->gc = gc;
+		chat->previously_joined = FALSE;
+	}
+
+	if (chat->conv != NULL)
+	{
+		purple_debug_warning("gg", "ggp_chat_new: "
+			"chat %llu already exists\n", id);
+		return chat;
+	}
+
+	chat->conv = serv_got_joined_chat(gc, local_id,
+		ggp_chat_get_name_from_id(id));
+	if (chat->previously_joined)
+	{
+		purple_conversation_write(chat->conv, NULL,
+			_("You have re-joined the chat"), PURPLE_MESSAGE_SYSTEM,
+			time(NULL));
+	}
+	chat->previously_joined = TRUE;
+
+	return chat;
+}
+
+static ggp_chat_local_info * ggp_chat_get(PurpleConnection *gc, uint64_t id)
+{
+	ggp_chat_session_data *sdata = ggp_chat_get_sdata(gc);
+	int i;
+
+	for (i = 0; i < sdata->chats_count; i++)
+		if (sdata->chats[i].id == id)
+			return &sdata->chats[i];
+
+	return NULL;
+}
+
+static ggp_chat_local_info * ggp_chat_get_local(PurpleConnection *gc,
+	int local_id)
+{
+	ggp_chat_session_data *sdata = ggp_chat_get_sdata(gc);
+	int i;
+
+	for (i = 0; i < sdata->chats_count; i++)
+		if (sdata->chats[i].local_id == local_id)
+			return &sdata->chats[i];
+
+	return NULL;
+}
+
+void ggp_chat_got_event(PurpleConnection *gc, const struct gg_event *ev)
+{
+	ggp_chat_local_info *chat;
+	int i;
+
+	if (ev->type == GG_EVENT_CHAT_INFO)
+	{
+		const struct gg_event_chat_info *eci = &ev->event.chat_info;
+		chat = ggp_chat_new(gc, eci->id);
+		for (i = 0; i < eci->participants_count; i++)
+			ggp_chat_joined(chat, eci->participants[i], FALSE);
+	}
+	else if (ev->type == GG_EVENT_CHAT_INFO_UPDATE)
+	{
+		const struct gg_event_chat_info_update *eciu =
+			&ev->event.chat_info_update;
+		chat = ggp_chat_get(gc, eciu->id);
+		if (!chat)
+		{
+			purple_debug_error("gg", "ggp_chat_got_event: "
+				"chat %llu not found\n", eciu->id);
+			return;
+		}
+		if (eciu->type == GG_CHAT_INFO_UPDATE_ENTERED)
+			ggp_chat_joined(chat, eciu->participant, TRUE);
+		else if (eciu->type == GG_CHAT_INFO_UPDATE_EXITED)
+			ggp_chat_left(chat, eciu->participant);
+		else
+			purple_debug_warning("gg", "ggp_chat_got_event: "
+				"unknown update type - %d", eciu->type);
+	}
+	else if (ev->type == GG_EVENT_CHAT_CREATED)
+	{
+		const struct gg_event_chat_created *ecc =
+			&ev->event.chat_created;
+		uin_t me = ggp_str_to_uin(purple_account_get_username(
+			purple_connection_get_account(gc)));
+		chat = ggp_chat_new(gc, ecc->id);
+		ggp_chat_joined(chat, me, FALSE);
+	}
+	else if (ev->type == GG_EVENT_CHAT_INVITE_ACK ||
+		ev->type == GG_EVENT_CHAT_SEND_MSG_ACK)
+	{
+		/* ignore */
+	}
+	else
+	{
+		purple_debug_fatal("gg", "ggp_chat_got_event: unexpected event "
+			"- %d\n", ev->type);
+	}
+}
+
+static void ggp_chat_joined(ggp_chat_local_info *chat, uin_t uin,
+	gboolean new_arrival)
+{



More information about the Commits mailing list