changeset 8810:a7affa2e2986

[gaim-migrate @ 9572] Forgot these. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sun, 25 Apr 2004 23:40:13 +0000
parents fde4101fa183
children 7329d01bb770
files src/protocols/msn/cmdproc.c src/protocols/msn/cmdproc.h src/protocols/msn/command.c src/protocols/msn/command.h src/protocols/msn/history.c src/protocols/msn/history.h src/protocols/msn/table.c src/protocols/msn/table.h src/protocols/msn/transaction.c src/protocols/msn/transaction.h
diffstat 10 files changed, 1111 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/protocols/msn/cmdproc.c	Sun Apr 25 23:40:13 2004 +0000
@@ -0,0 +1,397 @@
+/**
+ * @file cmdproc.c MSN command processor functions
+ *
+ * gaim
+ *
+ * Copyright (C) 2003, Christian Hammond <chipx86@gnupdate.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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
+ */
+#include "msn.h"
+#include "cmdproc.h"
+
+typedef struct
+{
+	char *command;
+	MsnMessage *msg;
+
+} MsnQueueEntry;
+
+MsnCmdProc *
+msn_cmdproc_new(MsnSession *session)
+{
+	MsnCmdProc *cmdproc;
+
+	cmdproc = g_new0(MsnCmdProc, 1);
+
+	cmdproc->session = session;
+	cmdproc->txqueue = g_queue_new();
+	cmdproc->history = msn_history_new();
+
+	return cmdproc;
+}
+
+void
+msn_cmdproc_destroy(MsnCmdProc *cmdproc)
+{
+	MsnTransaction *trans;
+
+	if (cmdproc->last_trans != NULL)
+		g_free(cmdproc->last_trans);
+
+	while ((trans = g_queue_pop_head(cmdproc->txqueue)) != NULL)
+		msn_transaction_destroy(trans);
+
+	g_queue_free(cmdproc->txqueue);
+
+	while (cmdproc->msg_queue != NULL)
+	{
+		MsnQueueEntry *entry = cmdproc->msg_queue->data;
+
+		msn_cmdproc_unqueue_message(cmdproc, entry->msg);
+	}
+
+	msn_history_destroy(cmdproc->history);
+}
+
+void
+msn_cmdproc_process_queue(MsnCmdProc *cmdproc)
+{
+	MsnTransaction *trans;
+
+	while ((trans = g_queue_pop_head(cmdproc->txqueue)) != NULL &&
+		   cmdproc->error == 0)
+	{
+		msn_cmdproc_send_trans(cmdproc, trans);
+	}
+}
+
+void
+msn_cmdproc_queue_trans(MsnCmdProc *cmdproc, MsnTransaction *trans)
+{
+	g_return_if_fail(cmdproc != NULL);
+	g_return_if_fail(trans   != NULL);
+
+	gaim_debug_info("msn", "Appending command to queue.\n");
+	
+	g_queue_push_tail(cmdproc->txqueue, trans);
+}
+
+static void
+show_debug_cmd(MsnCmdProc *cmdproc, gboolean incoming, const char *command)
+{
+	MsnServConn *servconn;
+	const char *names[] = { "NS", "SB" };
+	char *show;
+	char tmp;
+	size_t len;
+
+	servconn = cmdproc->servconn;
+	len = strlen(command);
+	show = g_strdup(command);
+
+	tmp = (incoming) ? 'S' : 'C';
+
+	if ((show[len - 1] == '\n') && (show[len - 2] == '\r'))
+	{
+		show[len - 2] = '\0';
+	}
+
+	gaim_debug_misc("msn", "%c: %s %03d: %s\n", tmp,
+					names[servconn->type], servconn->num, show);
+
+	g_free(show);
+}
+
+void
+msn_cmdproc_send_trans(MsnCmdProc *cmdproc, MsnTransaction *trans)
+{
+	MsnServConn *servconn;
+	char *data;
+	size_t len;
+
+	g_return_if_fail(cmdproc != NULL);
+	g_return_if_fail(trans != NULL);
+
+	servconn = cmdproc->servconn;
+	msn_history_add(cmdproc->history, trans);
+
+	data = msn_transaction_to_string(trans);
+	
+	cmdproc->last_trans = g_strdup(data);
+
+	len = strlen(data);
+
+	show_debug_cmd(cmdproc, FALSE, data);
+
+	if (trans->callbacks == NULL)
+		trans->callbacks = g_hash_table_lookup(cmdproc->cbs_table->cmds,
+											   trans->command);
+
+	if (trans->payload != NULL)
+	{
+		data = g_realloc(data, len + trans->payload_len);
+		memcpy(data + len, trans->payload, trans->payload_len);
+		len += trans->payload_len;
+	}
+
+	msn_servconn_write(servconn, data, len);
+
+	g_free(data);
+}
+
+void
+msn_cmdproc_send_quick(MsnCmdProc *cmdproc, const char *command,
+					   const char *format, ...)
+{
+	MsnServConn *servconn;
+	char *data;
+	char *params;
+	va_list arg;
+	size_t len;
+
+	g_return_if_fail(cmdproc != NULL);
+	g_return_if_fail(command != NULL);
+
+	servconn = cmdproc->servconn;
+
+	va_start(arg, format);
+	params = g_strdup_vprintf(format, arg);
+	va_end(arg);
+
+	if (params != NULL)
+		data = g_strdup_printf("%s %s\r\n", command, params);
+	else
+		data = g_strdup_printf("%s\r\n", command);
+
+	g_free(params);
+
+	len = strlen(data);
+
+	show_debug_cmd(cmdproc, FALSE, data);
+
+	msn_servconn_write(servconn, data, len);
+
+	g_free(data);
+}
+
+void
+msn_cmdproc_send(MsnCmdProc *cmdproc, const char *command,
+				 const char *format, ...)
+{
+	MsnTransaction *trans;
+	va_list arg;
+
+	g_return_if_fail(cmdproc != NULL);
+	g_return_if_fail(command != NULL);
+
+	trans = g_new0(MsnTransaction, 1);
+
+	trans->command = g_strdup(command);
+
+	va_start(arg, format);
+	trans->params = g_strdup_vprintf(format, arg);
+	va_end(arg);
+
+	msn_cmdproc_send_trans(cmdproc, trans);
+}
+
+void
+msn_cmdproc_process_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
+{
+	MsnServConn *servconn;
+	MsnMsgCb cb;
+
+	servconn = cmdproc->servconn;
+
+	cb = g_hash_table_lookup(cmdproc->cbs_table->msgs,
+							 msn_message_get_content_type(msg));
+
+	if (cb == NULL)
+	{
+		gaim_debug_warning("msn", "Unhandled content-type '%s': %s\n",
+						   msn_message_get_content_type(msg),
+						   msn_message_get_body(msg));
+
+		return;
+	}
+
+	cb(cmdproc, msg);
+}
+
+void
+msn_cmdproc_process_payload(MsnCmdProc *cmdproc, char *payload, int payload_len)
+{
+	g_return_if_fail(cmdproc             != NULL);
+	g_return_if_fail(cmdproc->payload_cb != NULL);
+
+	cmdproc->payload_cb(cmdproc, payload, payload_len);
+}
+
+void
+msn_cmdproc_process_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
+{
+	MsnSession *session;
+	MsnServConn *servconn;
+	MsnTransaction *trans = NULL;
+	MsnTransCb cb = NULL;
+	GSList *l, *l_next = NULL;
+
+	session = cmdproc->session;
+	servconn = cmdproc->servconn;
+
+	if (cmd->trId)
+		trans = msn_history_find(cmdproc->history, cmd->trId);
+
+	if (g_ascii_isdigit(cmd->command[0]))
+	{
+		if (trans != NULL)
+		{
+			MsnErrorCb error_cb = NULL;
+			int error;
+
+			error = atoi(cmd->command);
+			if (cmdproc->cbs_table->errors != NULL)
+				error_cb = g_hash_table_lookup(cmdproc->cbs_table->errors, trans->command);
+
+			if (error_cb != NULL)
+				error_cb(cmdproc, trans, error);
+			else
+			{
+#if 1
+				msn_error_handle(cmdproc->session, error);
+#else
+				gaim_debug_warning("msn", "Unhandled error '%s'\n",
+								   cmd->command);
+#endif
+			}
+
+			return;
+		}
+	}
+
+	if (cmdproc->cbs_table->async != NULL)
+		cb = g_hash_table_lookup(cmdproc->cbs_table->async, cmd->command);
+
+	if (cb == NULL && cmd->trId)
+	{
+		if (trans != NULL)
+		{
+			cmd->trans = trans;
+
+			if (trans->callbacks)
+				cb = g_hash_table_lookup(trans->callbacks, cmd->command);
+		}
+	}
+
+	if (cb != NULL)
+		cb(cmdproc, cmd);
+	else
+	{
+		gaim_debug_warning("msn", "Unhandled command '%s'\n",
+							cmd->command);
+
+		return;
+	}
+
+	if (g_list_find(session->servconns, servconn) == NULL)
+		return;
+
+	/* Process all queued messages that are waiting on this command. */
+	for (l = cmdproc->msg_queue; l != NULL; l = l_next)
+	{
+		MsnQueueEntry *entry = l->data;
+		MsnMessage *msg;
+
+		l_next = l->next;
+
+		if (entry->command == NULL ||
+			!g_ascii_strcasecmp(entry->command, cmd->command))
+		{
+			msg = entry->msg;
+
+			msn_message_ref(msg);
+
+			msn_cmdproc_process_msg(cmdproc, msg);
+
+			msn_cmdproc_unqueue_message(cmdproc, entry->msg);
+
+			msn_message_destroy(msg);
+			entry->msg = NULL;
+		}
+	}
+}
+
+void
+msn_cmdproc_process_cmd_text(MsnCmdProc *cmdproc, const char *command)
+{
+	show_debug_cmd(cmdproc, TRUE, command);
+
+	if (cmdproc->last_cmd != NULL)
+		msn_command_destroy(cmdproc->last_cmd);
+
+	cmdproc->last_cmd = msn_command_from_string(command);
+
+	msn_cmdproc_process_cmd(cmdproc, cmdproc->last_cmd);
+}
+
+void
+msn_cmdproc_queue_message(MsnCmdProc *cmdproc, const char *command,
+						  MsnMessage *msg)
+{
+	MsnQueueEntry *entry;
+
+	g_return_if_fail(cmdproc != NULL);
+	g_return_if_fail(msg != NULL);
+
+	entry          = g_new0(MsnQueueEntry, 1);
+	entry->msg     = msg;
+	entry->command = (command == NULL ? NULL : g_strdup(command));
+
+	cmdproc->msg_queue = g_slist_append(cmdproc->msg_queue, entry);
+
+	msn_message_ref(msg);
+}
+
+void
+msn_cmdproc_unqueue_message(MsnCmdProc *cmdproc, MsnMessage *msg)
+{
+	MsnQueueEntry *entry = NULL;
+	GSList *l;
+
+	g_return_if_fail(cmdproc != NULL);
+	g_return_if_fail(msg != NULL);
+
+	for (l = cmdproc->msg_queue; l != NULL; l = l->next)
+	{
+		entry = l->data;
+
+		if (entry->msg == msg)
+			break;
+
+		entry = NULL;
+	}
+
+	g_return_if_fail(entry != NULL);
+
+	msn_message_unref(msg);
+
+	cmdproc->msg_queue = g_slist_remove(cmdproc->msg_queue, entry);
+
+	if (entry->command != NULL)
+		g_free(entry->command);
+
+	g_free(entry);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/protocols/msn/cmdproc.h	Sun Apr 25 23:40:13 2004 +0000
@@ -0,0 +1,84 @@
+/**
+ * @file cmdproc.h MSN command processor functions
+ *
+ * gaim
+ *
+ * Copyright (C) 2003, Christian Hammond <chipx86@gnupdate.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 _MSN_CMDPROC_H_
+#define _MSN_CMDPROC_H_
+
+typedef struct _MsnCmdProc MsnCmdProc;
+
+#include "session.h"
+#include "server.h"
+#include "error.h"
+#include "command.h"
+#include "table.h"
+#include "history.h"
+#include "msg.h"
+
+typedef void (*MsnPayloadCb)(MsnCmdProc *cmdproc, char *payload,
+							 size_t len);
+
+struct _MsnCmdProc
+{
+	MsnSession *session;
+	MsnServConn *servconn;
+
+	GQueue *txqueue;
+
+	gboolean ready;
+	MsnErrorType error;
+
+	MsnCommand *last_cmd;
+	char *last_trans;
+	
+	MsnTable *cbs_table;
+	MsnPayloadCb payload_cb;
+
+	MsnHistory *history;
+
+	GSList *msg_queue;
+
+	char *temp;
+};
+
+MsnCmdProc *msn_cmdproc_new(MsnSession *session);
+void msn_cmdproc_destroy(MsnCmdProc *cmdproc);
+
+void msn_cmdproc_process_queue(MsnCmdProc *cmdproc);
+
+void msn_cmdproc_send_trans(MsnCmdProc *cmdproc, MsnTransaction *trans);
+void msn_cmdproc_queue_trans(MsnCmdProc *cmdproc,
+							 MsnTransaction *trans);
+void msn_cmdproc_send(MsnCmdProc *cmdproc, const char *command,
+					  const char *format, ...);
+void msn_cmdproc_send_quick(MsnCmdProc *cmdproc, const char *command,
+					  const char *format, ...);
+void msn_cmdproc_process_msg(MsnCmdProc *cmdproc,
+							 MsnMessage *msg);
+void msn_cmdproc_process_cmd_text(MsnCmdProc *cmdproc, const char *command);
+void msn_cmdproc_process_payload(MsnCmdProc *cmdproc,
+								 char *payload, int payload_len);
+
+void msn_cmdproc_queue_message(MsnCmdProc *cmdproc, const char *command,
+								MsnMessage *msg);
+
+void msn_cmdproc_unqueue_message(MsnCmdProc *cmdproc, MsnMessage *msg);
+
+#endif /* _MSN_CMDPROC_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/protocols/msn/command.c	Sun Apr 25 23:40:13 2004 +0000
@@ -0,0 +1,117 @@
+/**
+ * @file command.c MSN command functions
+ *
+ * gaim
+ *
+ * Copyright (C) 2003, Christian Hammond <chipx86@gnupdate.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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
+ */
+#include "msn.h"
+#include "command.h"
+
+gboolean
+is_num(char *str)
+{
+	char *c;
+	for (c = str; *c; c++) {
+		if (!(g_ascii_isdigit(*c)))
+			return FALSE;
+	}
+
+	return TRUE;
+}
+
+MsnCommand *
+msn_command_from_string(const char *string)
+{
+	MsnCommand *cmd;
+	char *tmp;
+	char *param_start;
+
+	g_return_val_if_fail(string != NULL, NULL);
+
+	tmp = g_strdup(string);
+	param_start = strchr(tmp, ' ');
+
+	cmd = g_new0(MsnCommand, 1);
+	cmd->command = tmp;
+	
+	if (param_start)
+	{
+		char *param;
+		int c;
+
+		*param_start++ = '\0';
+		cmd->params = g_strsplit(param_start, " ", 0);
+
+		for (c = 0; cmd->params[c]; c++);
+		cmd->param_count = c;
+	
+		param = cmd->params[0];
+
+		cmd->trId = is_num(param) ? atoi(param) : 0;
+	}
+	else
+		cmd->trId = 0;
+	
+	msn_command_ref(cmd);
+	
+	return cmd;
+}
+
+void
+msn_command_destroy(MsnCommand *cmd)
+{
+	g_return_if_fail(cmd != NULL);
+	
+	if (cmd->ref_count > 0)
+	{
+		msn_command_unref(cmd);
+		return;
+	}
+	
+	g_free(cmd->command);
+	g_strfreev(cmd->params);
+	g_free(cmd);
+}
+
+MsnCommand *
+msn_command_ref(MsnCommand *cmd)
+{
+	g_return_val_if_fail(cmd != NULL, NULL);
+
+	cmd->ref_count++;
+	return cmd;
+}
+
+MsnCommand *
+msn_command_unref(MsnCommand *cmd)
+{
+	g_return_val_if_fail(cmd != NULL, NULL);
+
+	if (cmd->ref_count <= 0)
+		return NULL;
+
+	cmd->ref_count--;
+
+	if (cmd->ref_count == 0)
+	{
+		msn_command_destroy(cmd);
+		return NULL;
+	}
+
+	return cmd;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/protocols/msn/command.h	Sun Apr 25 23:40:13 2004 +0000
@@ -0,0 +1,55 @@
+/**
+ * @file command.h MSN command functions
+ *
+ * gaim
+ *
+ * Copyright (C) 2003, Christian Hammond <chipx86@gnupdate.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 _MSN_COMMAND_H
+#define _MSN_COMMAND_H
+
+typedef struct _MsnCommand MsnCommand;
+
+#include "cmdproc.h"
+#include "transaction.h"
+
+/* typedef void (*MsnPayloadCb)(MsnCmdProc *cmdproc, MsnCommand *cmd, char
+ * *payload, size_t len); */
+
+/**
+ * A received command.
+ */
+struct _MsnCommand
+{
+	unsigned int trId;
+
+	char *command;
+	char **params;
+	int param_count;
+
+	int ref_count;
+
+	MsnTransaction *trans;
+	/* MsnPayloadCb payload_cb; */
+};
+
+MsnCommand *msn_command_from_string(const char *string);
+void msn_command_destroy(MsnCommand *cmd);
+MsnCommand *msn_command_ref(MsnCommand *cmd);
+MsnCommand *msn_command_unref(MsnCommand *cmd);
+
+#endif /* _MSN_COMMAND_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/protocols/msn/history.c	Sun Apr 25 23:40:13 2004 +0000
@@ -0,0 +1,79 @@
+/**
+ * @file history.c MSN history functions
+ *
+ * gaim
+ *
+ * Copyright (C) 2003, Christian Hammond <chipx86@gnupdate.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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
+ */
+#include "msn.h"
+#include "history.h"
+
+MsnHistory *
+msn_history_new(void)
+{
+	MsnHistory *history = g_new0(MsnHistory, 1);
+	
+	history->trId = 1;
+	
+	history->queue = g_queue_new();
+
+	return history;
+}
+
+void
+msn_history_destroy(MsnHistory *history)
+{
+	MsnTransaction *trans;
+
+	while ((trans = g_queue_pop_head(history->queue)) != NULL)
+		msn_transaction_destroy(trans);
+
+	g_queue_free(history->queue);
+	g_free(history);
+}
+
+MsnTransaction *
+msn_history_find(MsnHistory *history, unsigned int trId)
+{
+	MsnTransaction *trans;
+	GList *list;
+
+	for (list = history->queue->head; list != NULL; list = list->next)
+	{
+		trans = list->data;
+		if (trans->trId == trId)
+			return trans;
+	}
+
+	return NULL;
+}
+
+void
+msn_history_add(MsnHistory *history, MsnTransaction *trans)
+{
+	GQueue *queue = history->queue;
+
+	trans->trId = history->trId++;
+	
+	g_queue_push_tail(queue, trans);
+	
+	if (queue->length > MSN_HIST_ELEMS)
+	{
+		trans = g_queue_pop_head(queue);
+		msn_transaction_destroy(trans);
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/protocols/msn/history.h	Sun Apr 25 23:40:13 2004 +0000
@@ -0,0 +1,45 @@
+/**
+ * @file history.h MSN history functions
+ *
+ * gaim
+ *
+ * Copyright (C) 2003, Christian Hammond <chipx86@gnupdate.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 _MSN_HISTORY_H
+#define _MSN_HISTORY_H
+
+#define MSN_HIST_ELEMS 8
+
+typedef struct _MsnHistory MsnHistory;
+
+#include "transaction.h"
+
+/**
+ * The history.
+ */
+struct _MsnHistory
+{
+	GQueue *queue;
+	unsigned int trId;
+};
+
+MsnHistory *msn_history_new(void);
+void msn_history_destroy(MsnHistory *history);
+MsnTransaction *msn_history_find(MsnHistory *history, unsigned int triId);
+void msn_history_add(MsnHistory *history, MsnTransaction *trans);
+
+#endif /* _MSN_HISTORY_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/protocols/msn/table.c	Sun Apr 25 23:40:13 2004 +0000
@@ -0,0 +1,124 @@
+/**
+ * @file table.c MSN helper structure
+ *
+ * gaim
+ *
+ * Copyright (C) 2003, Christian Hammond <chipx86@gnupdate.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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
+ */
+#include "msn.h"
+#include "table.h"
+
+static void
+null_cmd_cb(MsnCmdProc *cmdproc, MsnCommand *cmd)
+{
+}
+
+static void
+null_error_cb(MsnCmdProc *cmdproc, MsnTransaction *trans, int error)
+{
+}
+
+MsnTable *
+msn_table_new()
+{
+	MsnTable *table;
+
+	table = g_new0(MsnTable, 1);
+
+	table->cmds = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
+	table->msgs = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
+	table->errors = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
+
+	table->async = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
+
+	return table;
+}
+
+void
+msn_table_destroy(MsnTable *table)
+{
+	g_return_if_fail(table != NULL);
+
+	g_hash_table_destroy(table->cmds);
+	g_hash_table_destroy(table->msgs);
+	g_hash_table_destroy(table->errors);
+
+	g_hash_table_destroy(table->async);
+
+	g_free(table);
+}
+
+void
+msn_table_add_cmd(MsnTable *table,
+				  char *command, char *answer, MsnTransCb cb)
+{
+	GHashTable *cbs;
+
+	g_return_if_fail(table  != NULL);
+	g_return_if_fail(answer != NULL);
+
+	cbs = NULL;
+
+	if (command == NULL)
+	{
+		cbs = table->async;
+	}
+	else
+	{
+		cbs = g_hash_table_lookup(table->cmds, command);
+
+		if (cbs == NULL)
+		{
+			cbs = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
+			g_hash_table_insert(table->cmds, command, cbs);
+		}
+	}
+
+	if (cb == NULL)
+		cb = null_cmd_cb;
+
+	g_hash_table_insert(cbs, answer, cb);
+}
+
+void
+msn_table_add_error(MsnTable *table,
+					char *answer, MsnErrorCb cb)
+{
+	g_return_if_fail(table  != NULL);
+	g_return_if_fail(answer != NULL);
+
+	if (cb == NULL)
+		cb = null_error_cb;
+
+	g_hash_table_insert(table->errors, answer, cb);
+}
+
+void
+msn_table_add_msg_type(MsnTable *table,
+					   char *type, MsnMsgCb cb)
+{
+	g_return_if_fail(table != NULL);
+	g_return_if_fail(type  != NULL);
+	g_return_if_fail(cb    != NULL);
+
+#if 0
+	if (cb == NULL)
+		cb = null_msg_cb;
+#endif
+
+	g_hash_table_insert(table->msgs, type, cb);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/protocols/msn/table.h	Sun Apr 25 23:40:13 2004 +0000
@@ -0,0 +1,53 @@
+/**
+ * @file table.h MSN helper structure
+ *
+ * gaim
+ *
+ * Copyright (C) 2003, Christian Hammond <chipx86@gnupdate.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 _MSN_TABLE_H_
+#define _MSN_TABLE_H_
+
+typedef struct _MsnTable MsnTable;
+
+#include "cmdproc.h"
+#include "transaction.h"
+#include "msg.h"
+
+typedef void (*MsnTransCb)(MsnCmdProc *cmdproc, MsnCommand *cmd);
+typedef void (*MsnErrorCb)(MsnCmdProc *cmdproc, MsnTransaction *trans,
+						   int error);
+typedef void (*MsnMsgCb)(MsnCmdProc *cmdproc, MsnMessage *msg);
+
+struct _MsnTable
+{
+	GHashTable *cmds;
+	GHashTable *msgs;
+	GHashTable *errors;
+
+	GHashTable *async;
+};
+
+MsnTable *msn_table_new();
+void msn_table_destroy(MsnTable *table);
+
+void msn_table_add_cmd(MsnTable *table, char *command, char *answer,
+					   MsnTransCb cb);
+void msn_table_add_error(MsnTable *table, char *answer, MsnErrorCb cb);
+void msn_table_add_msg_type(MsnTable *table, char *type, MsnMsgCb cb);
+
+#endif /* _MSN_TABLE_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/protocols/msn/transaction.c	Sun Apr 25 23:40:13 2004 +0000
@@ -0,0 +1,98 @@
+/**
+ * @file transaction.c MSN transaction functions
+ *
+ * gaim
+ *
+ * Copyright (C) 2003, Christian Hammond <chipx86@gnupdate.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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
+ */
+#include "msn.h"
+#include "transaction.h"
+
+MsnTransaction *
+msn_transaction_new(const char *command, const char *format, ...)
+{
+	MsnTransaction *trans;
+	va_list arg;
+
+	g_return_val_if_fail(command != NULL, NULL);
+
+	trans = g_new0(MsnTransaction, 1);
+
+	trans->command = g_strdup(command);
+
+	va_start(arg, format);
+	trans->params = g_strdup_vprintf(format, arg);
+	va_end(arg);
+
+	/* trans->queue = g_queue_new(); */
+	
+	return trans;
+}
+
+void
+msn_transaction_destroy(MsnTransaction *trans)
+{
+	g_return_if_fail(trans != NULL);
+
+	g_free(trans->command);
+	g_free(trans->params);
+	g_free(trans->payload);
+
+#if 0
+	if (trans->pendent_cmd != NULL)
+		msn_message_unref(trans->pendent_msg);
+#endif
+
+#if 0
+	MsnTransaction *elem;
+	if (trans->queue != NULL)
+	{	
+		while ((elem = g_queue_pop_head(trans->queue)) != NULL)
+			msn_transaction_destroy(elem);
+		
+		g_queue_free(trans->queue);
+	}
+#endif
+
+	g_free(trans);
+}
+
+char *
+msn_transaction_to_string(MsnTransaction *trans)
+{
+	char *str;
+
+	g_return_val_if_fail(trans != NULL, FALSE);
+
+	if (trans->params != NULL)
+		str = g_strdup_printf("%s %u %s\r\n", trans->command, trans->trId, trans->params);
+	else
+		str = g_strdup_printf("%s %u\r\n", trans->command, trans->trId);
+
+	return str;
+}
+
+void
+msn_transaction_set_payload(MsnTransaction *trans,
+							const char *payload, int payload_len)
+{
+	g_return_if_fail(trans   != NULL);
+	g_return_if_fail(payload != NULL);
+
+	trans->payload = g_strdup(payload);
+	trans->payload_len = payload_len ? payload_len : strlen(trans->payload);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/protocols/msn/transaction.h	Sun Apr 25 23:40:13 2004 +0000
@@ -0,0 +1,59 @@
+/**
+ * @file transaction.h MSN transaction functions
+ *
+ * gaim
+ *
+ * Copyright (C) 2003, Christian Hammond <chipx86@gnupdate.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 _MSN_TRANSACTION_H
+#define _MSN_TRANSACTION_H
+
+typedef struct _MsnTransaction MsnTransaction;
+
+#include "command.h"
+#include "cmdproc.h"
+
+/**
+ * A transaction. A command that will initiate the transaction.
+ */
+struct _MsnTransaction
+{
+	unsigned int trId;
+
+	char *command;
+	char *params;
+
+	GHashTable *callbacks;
+	void *data;
+
+	char *payload;
+	size_t payload_len;
+
+	GQueue *queue;
+	MsnCommand *pendent_cmd;
+};
+
+MsnTransaction *msn_transaction_new(const char *command,
+									const char *format, ...);
+
+void msn_transaction_destroy(MsnTransaction *trans);
+
+char *msn_transaction_to_string(MsnTransaction *trans);
+void msn_transaction_set_payload(MsnTransaction *trans,
+								 const char *payload, int payload_len);
+
+#endif /* _MSN_TRANSACTION_H */