Mercurial > pidgin
comparison 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 |
comparison
equal
deleted
inserted
replaced
2446:f9cad82d321b | 2447:6bdeb91abe4e |
---|---|
32 #include <sys/un.h> | 32 #include <sys/un.h> |
33 #include <unistd.h> | 33 #include <unistd.h> |
34 #include <errno.h> | 34 #include <errno.h> |
35 #include <signal.h> | 35 #include <signal.h> |
36 #include <getopt.h> | 36 #include <getopt.h> |
37 #include <stdarg.h> | |
37 | 38 |
38 #include "gaim.h" | 39 #include "gaim.h" |
39 | 40 |
40 static gint UI_fd = -1; | 41 static gint UI_fd = -1; |
41 GSList *uis = NULL; | 42 GSList *uis = NULL; |
43 | |
44 static guchar *UI_build(int *len, guchar type, guchar subtype, va_list args1) | |
45 { | |
46 va_list args2; | |
47 guchar *buffer; | |
48 int pos; | |
49 int size; | |
50 void *data; | |
51 | |
52 G_VA_COPY(args2, args1); | |
53 | |
54 buffer = g_malloc(sizeof(guchar) * 2 + 4); | |
55 *len = sizeof(guchar) * 2 + 4; | |
56 pos = 0; | |
57 | |
58 memcpy(buffer + pos, &type, sizeof(type)); pos += sizeof(type); | |
59 memcpy(buffer + pos, &subtype, sizeof(subtype)); pos += sizeof(subtype); | |
60 | |
61 /* we come back and do size last */ | |
62 pos += 4; | |
63 | |
64 size = va_arg(args2, int); | |
65 while (size != -1) { | |
66 *len += size; | |
67 buffer = g_realloc(buffer, *len); | |
68 | |
69 data = va_arg(args2, void *); | |
70 memcpy(buffer + pos, data, size); | |
71 pos += size; | |
72 | |
73 size = va_arg(args2, int); | |
74 } | |
75 | |
76 va_end(args2); | |
77 | |
78 return buffer; | |
79 } | |
42 | 80 |
43 gint UI_write(struct UI *ui, guchar *data, gint len) | 81 gint UI_write(struct UI *ui, guchar *data, gint len) |
44 { | 82 { |
45 guchar *send = g_new0(guchar, len + 6); | 83 guchar *send = g_new0(guchar, len + 6); |
46 gint sent; | 84 gint sent; |
51 /* we'll let the write silently fail because the read will pick it up as dead */ | 89 /* we'll let the write silently fail because the read will pick it up as dead */ |
52 g_io_channel_write(ui->channel, send, len + 6, &sent); | 90 g_io_channel_write(ui->channel, send, len + 6, &sent); |
53 return sent; | 91 return sent; |
54 } | 92 } |
55 | 93 |
94 void UI_build_write(struct UI *ui, guchar type, guchar subtype, ...) | |
95 { | |
96 va_list ap; | |
97 gchar *data; | |
98 int len; | |
99 | |
100 va_start(ap, subtype); | |
101 data = UI_build(&len, type, subtype, ap); | |
102 va_end(ap); | |
103 | |
104 UI_write(ui, data, len); | |
105 | |
106 g_free(data); | |
107 } | |
108 | |
56 void UI_broadcast(guchar *data, gint len) | 109 void UI_broadcast(guchar *data, gint len) |
57 { | 110 { |
58 GSList *u = uis; | 111 GSList *u = uis; |
59 while (u) { | 112 while (u) { |
60 struct UI *ui = u->data; | 113 struct UI *ui = u->data; |
61 UI_write(ui, data, len); | 114 UI_write(ui, data, len); |
62 u = u->next; | 115 u = u->next; |
63 } | 116 } |
117 } | |
118 | |
119 void UI_build_broadcast(guchar type, guchar subtype, ...) | |
120 { | |
121 va_list ap; | |
122 gchar *data; | |
123 int len; | |
124 | |
125 if (!uis) | |
126 return; | |
127 | |
128 va_start(ap, subtype); | |
129 data = UI_build(&len, type, subtype, ap); | |
130 va_end(ap); | |
131 | |
132 UI_broadcast(data, len); | |
133 | |
134 g_free(data); | |
64 } | 135 } |
65 | 136 |
66 static void meta_handler(struct UI *ui, guchar subtype, guchar *data) | 137 static void meta_handler(struct UI *ui, guchar subtype, guchar *data) |
67 { | 138 { |
68 switch (subtype) { | 139 switch (subtype) { |
288 conn_handler(ui, subtype, in); | 359 conn_handler(ui, subtype, in); |
289 break; | 360 break; |
290 case CUI_TYPE_BUDDY: | 361 case CUI_TYPE_BUDDY: |
291 buddy_handler(ui, subtype, in); | 362 buddy_handler(ui, subtype, in); |
292 break; | 363 break; |
364 */ | |
293 case CUI_TYPE_MESSAGE: | 365 case CUI_TYPE_MESSAGE: |
294 message_handler(ui, subtype, in); | 366 message_handler(ui, subtype, in); |
295 break; | 367 break; |
368 /* | |
296 case CUI_TYPE_CHAT: | 369 case CUI_TYPE_CHAT: |
297 chat_handler(ui, subtype, in); | 370 chat_handler(ui, subtype, in); |
298 break; | 371 break; |
299 */ | 372 */ |
300 default: | 373 default: |