diff src/core.c @ 2447:6bdeb91abe4e

[gaim-migrate @ 2460] i hope this works committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Mon, 08 Oct 2001 01:12:02 +0000
parents f9cad82d321b
children cf2f2450f7cc
line wrap: on
line diff
--- a/src/core.c	Sat Oct 06 06:21:01 2001 +0000
+++ b/src/core.c	Mon Oct 08 01:12:02 2001 +0000
@@ -34,12 +34,50 @@
 #include <errno.h>
 #include <signal.h>
 #include <getopt.h>
+#include <stdarg.h>
 
 #include "gaim.h"
 
 static gint UI_fd = -1;
 GSList *uis = NULL;
 
+static guchar *UI_build(int *len, guchar type, guchar subtype, va_list args1)
+{
+	va_list args2;
+	guchar *buffer;
+	int pos;
+	int size;
+	void *data;
+
+	G_VA_COPY(args2, args1);
+
+	buffer = g_malloc(sizeof(guchar) * 2 + 4);
+	*len = sizeof(guchar) * 2 + 4;
+	pos = 0;
+
+	memcpy(buffer + pos, &type, sizeof(type)); pos += sizeof(type);
+	memcpy(buffer + pos, &subtype, sizeof(subtype)); pos += sizeof(subtype);
+
+	/* we come back and do size last */
+	pos += 4;
+
+	size = va_arg(args2, int);
+	while (size != -1) {
+		*len += size;
+		buffer = g_realloc(buffer, *len);
+
+		data = va_arg(args2, void *);
+		memcpy(buffer + pos, data, size);
+		pos += size;
+
+		size = va_arg(args2, int);
+	}
+
+	va_end(args2);
+
+	return buffer;
+}
+
 gint UI_write(struct UI *ui, guchar *data, gint len)
 {
 	guchar *send = g_new0(guchar, len + 6);
@@ -53,6 +91,21 @@
 	return sent;
 }
 
+void UI_build_write(struct UI *ui, guchar type, guchar subtype, ...)
+{
+	va_list ap;
+	gchar *data;
+	int len;
+
+	va_start(ap, subtype);
+	data = UI_build(&len, type, subtype, ap);
+	va_end(ap);
+
+	UI_write(ui, data, len);
+
+	g_free(data);
+}
+
 void UI_broadcast(guchar *data, gint len)
 {
 	GSList *u = uis;
@@ -63,6 +116,24 @@
 	}
 }
 
+void UI_build_broadcast(guchar type, guchar subtype, ...)
+{
+	va_list ap;
+	gchar *data;
+	int len;
+
+	if (!uis)
+		return;
+
+	va_start(ap, subtype);
+	data = UI_build(&len, type, subtype, ap);
+	va_end(ap);
+
+	UI_broadcast(data, len);
+
+	g_free(data);
+}
+
 static void meta_handler(struct UI *ui, guchar subtype, guchar *data)
 {
 	switch (subtype) {
@@ -290,9 +361,11 @@
 		case CUI_TYPE_BUDDY:
 			buddy_handler(ui, subtype, in);
 			break;
+			*/
 		case CUI_TYPE_MESSAGE:
 			message_handler(ui, subtype, in);
 			break;
+			/*
 		case CUI_TYPE_CHAT:
 			chat_handler(ui, subtype, in);
 			break;