Mercurial > pidgin.yaz
annotate src/core.c @ 2584:34812d648f72
[gaim-migrate @ 2597]
heh. this was pointless.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 23 Oct 2001 08:06:09 +0000 |
parents | 271011bbe14e |
children | 35c23df11d16 |
rev | line source |
---|---|
2416 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
22 #ifdef HAVE_CONFIG_H | |
23 #include "config.h" | |
24 #endif | |
25 | |
26 #include <glib.h> | |
27 #include <stdio.h> | |
28 #include <stdlib.h> | |
29 #include <sys/types.h> | |
30 #include <sys/socket.h> | |
31 #include <sys/stat.h> | |
32 #include <sys/un.h> | |
33 #include <unistd.h> | |
34 #include <errno.h> | |
35 #include <signal.h> | |
36 #include <getopt.h> | |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
37 #include <stdarg.h> |
2416 | 38 |
39 #include "gaim.h" | |
40 | |
41 static gint UI_fd = -1; | |
42 GSList *uis = NULL; | |
43 | |
2544
271011bbe14e
[gaim-migrate @ 2557]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2541
diff
changeset
|
44 static guchar *UI_build(guint32 *len, guchar type, guchar subtype, va_list args) |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
45 { |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
46 guchar *buffer; |
2462
cf2f2450f7cc
[gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2447
diff
changeset
|
47 guint32 pos; |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
48 int size; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
49 void *data; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
50 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
51 *len = sizeof(guchar) * 2 + 4; |
2462
cf2f2450f7cc
[gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2447
diff
changeset
|
52 buffer = g_malloc(*len); |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
53 pos = 0; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
54 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
55 memcpy(buffer + pos, &type, sizeof(type)); pos += sizeof(type); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
56 memcpy(buffer + pos, &subtype, sizeof(subtype)); pos += sizeof(subtype); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
57 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
58 /* we come back and do size last */ |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
59 pos += 4; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
60 |
2544
271011bbe14e
[gaim-migrate @ 2557]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2541
diff
changeset
|
61 size = va_arg(args, int); |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
62 while (size != -1) { |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
63 *len += size; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
64 buffer = g_realloc(buffer, *len); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
65 |
2544
271011bbe14e
[gaim-migrate @ 2557]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2541
diff
changeset
|
66 data = va_arg(args, void *); |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
67 memcpy(buffer + pos, data, size); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
68 pos += size; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
69 |
2544
271011bbe14e
[gaim-migrate @ 2557]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2541
diff
changeset
|
70 size = va_arg(args, int); |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
71 } |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
72 |
2482
7e4757801725
[gaim-migrate @ 2495]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2462
diff
changeset
|
73 pos -= sizeof(guchar) * 2 + 4; |
7e4757801725
[gaim-migrate @ 2495]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2462
diff
changeset
|
74 |
2462
cf2f2450f7cc
[gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2447
diff
changeset
|
75 /* now we do size */ |
cf2f2450f7cc
[gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2447
diff
changeset
|
76 memcpy(buffer + sizeof(guchar) * 2, &pos, 4); |
cf2f2450f7cc
[gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2447
diff
changeset
|
77 |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
78 return buffer; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
79 } |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
80 |
2435
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
81 gint UI_write(struct UI *ui, guchar *data, gint len) |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
82 { |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
83 gint sent; |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
84 /* we'll let the write silently fail because the read will pick it up as dead */ |
2482
7e4757801725
[gaim-migrate @ 2495]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2462
diff
changeset
|
85 g_io_channel_write(ui->channel, data, len, &sent); |
2435
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
86 return sent; |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
87 } |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
88 |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
89 void UI_build_write(struct UI *ui, guchar type, guchar subtype, ...) |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
90 { |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
91 va_list ap; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
92 gchar *data; |
2462
cf2f2450f7cc
[gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2447
diff
changeset
|
93 guint32 len; |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
94 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
95 va_start(ap, subtype); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
96 data = UI_build(&len, type, subtype, ap); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
97 va_end(ap); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
98 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
99 UI_write(ui, data, len); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
100 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
101 g_free(data); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
102 } |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
103 |
2435
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
104 void UI_broadcast(guchar *data, gint len) |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
105 { |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
106 GSList *u = uis; |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
107 while (u) { |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
108 struct UI *ui = u->data; |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
109 UI_write(ui, data, len); |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
110 u = u->next; |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
111 } |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
112 } |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
113 |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
114 void UI_build_broadcast(guchar type, guchar subtype, ...) |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
115 { |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
116 va_list ap; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
117 gchar *data; |
2462
cf2f2450f7cc
[gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2447
diff
changeset
|
118 guint32 len; |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
119 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
120 if (!uis) |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
121 return; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
122 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
123 va_start(ap, subtype); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
124 data = UI_build(&len, type, subtype, ap); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
125 va_end(ap); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
126 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
127 UI_broadcast(data, len); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
128 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
129 g_free(data); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
130 } |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
131 |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
132 static void meta_handler(struct UI *ui, guchar subtype, guchar *data) |
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
133 { |
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
134 switch (subtype) { |
2440
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
135 case CUI_META_LIST: |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
136 break; |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
137 case CUI_META_QUIT: |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
138 while (uis) { |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
139 ui = uis->data; |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
140 uis = g_slist_remove(uis, ui); |
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
141 g_io_channel_close(ui->channel); |
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
142 g_source_remove(ui->inpa); |
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
143 g_free(ui); |
2440
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
144 } |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
145 do_quit(); |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
146 break; |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
147 case CUI_META_DETACH: |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
148 uis = g_slist_remove(uis, ui); |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
149 g_io_channel_close(ui->channel); |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
150 g_source_remove(ui->inpa); |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
151 g_free(ui); |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
152 break; |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
153 default: |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
154 debug_printf("unhandled meta subtype %d\n", subtype); |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
155 break; |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
156 } |
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
157 } |
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
158 |
2443
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
159 static void plugin_handler(struct UI *ui, guchar subtype, guchar *data) |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
160 { |
2446
f9cad82d321b
[gaim-migrate @ 2459]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
161 #ifdef GAIM_PLUGINS |
2443
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
162 guint id; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
163 struct gaim_plugin *p; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
164 |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
165 switch (subtype) { |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
166 /* |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
167 case CUI_PLUGIN_LIST: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
168 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
169 */ |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
170 case CUI_PLUGIN_LOAD: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
171 p = load_plugin(data); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
172 /* XXX need to broadcast to UIs that plugin has been loaded */ |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
173 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
174 case CUI_PLUGIN_UNLOAD: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
175 memcpy(&id, data, sizeof(id)); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
176 p = g_list_nth_data(plugins, id); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
177 if (p) { |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
178 unload_plugin(p); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
179 /* XXX need to broadcast to UIs that plugin has been unloaded */ |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
180 } |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
181 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
182 case CUI_PLUGIN_RELOAD: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
183 memcpy(&id, data, sizeof(id)); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
184 p = g_list_nth_data(plugins, id); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
185 if (p) { |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
186 p = reload_plugin(p); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
187 /* XXX need to broadcast to UIs that plugin has been reloaded */ |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
188 } |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
189 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
190 default: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
191 debug_printf("unhandled plugin subtype %d\n", subtype); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
192 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
193 } |
2446
f9cad82d321b
[gaim-migrate @ 2459]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
194 #endif |
2443
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
195 } |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
196 |
2441
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
197 static void user_handler(struct UI *ui, guchar subtype, guchar *data) |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
198 { |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
199 guint id; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
200 struct aim_user *u; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
201 |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
202 switch (subtype) { |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
203 /* |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
204 case CUI_USER_LIST: |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
205 break; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
206 case CUI_USER_ADD: |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
207 break; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
208 case CUI_USER_REMOVE: |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
209 break; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
210 case CUI_USER_MODIFY: |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
211 break; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
212 */ |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
213 case CUI_USER_SIGNON: |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
214 if (!data) |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
215 return; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
216 memcpy(&id, data, sizeof(id)); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
217 u = g_slist_nth_data(aim_users, id); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
218 if (u) |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
219 serv_login(u); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
220 /* don't need to do anything here because the UI will get updates from other handlers */ |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
221 break; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
222 default: |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
223 debug_printf("unhandled user subtype %d\n", subtype); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
224 break; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
225 } |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
226 } |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
227 |
2443
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
228 static void message_handler(struct UI *ui, guchar subtype, guchar *data) |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
229 { |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
230 switch (subtype) { |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
231 case CUI_MESSAGE_LIST: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
232 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
233 case CUI_MESSAGE_SEND: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
234 if (!data) |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
235 return; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
236 { |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
237 guint id; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
238 struct gaim_connection *gc; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
239 guint len; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
240 char *who, *msg; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
241 gint flags; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
242 int pos = 0; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
243 |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
244 memcpy(&id, data + pos, sizeof(id)); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
245 pos += sizeof(id); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
246 gc = g_slist_nth_data(connections, id); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
247 if (!gc) |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
248 return; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
249 |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
250 memcpy(&len, data + pos, sizeof(len)); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
251 pos += sizeof(len); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
252 who = g_strndup(data + pos, len + 1); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
253 pos += len; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
254 |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
255 memcpy(&len, data + pos, sizeof(len)); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
256 pos += sizeof(len); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
257 msg = g_strndup(data + pos, len + 1); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
258 pos += len; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
259 |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
260 memcpy(&flags, data + pos, sizeof(flags)); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
261 serv_send_im(gc, who, msg, flags); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
262 |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
263 g_free(who); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
264 g_free(msg); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
265 } |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
266 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
267 case CUI_MESSAGE_RECV: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
268 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
269 default: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
270 debug_printf("unhandled message subtype %d\n", subtype); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
271 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
272 } |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
273 } |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
274 |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2503
diff
changeset
|
275 static gint gaim_recv(GIOChannel *source, guchar *buf, gint len) |
2416 | 276 { |
277 gint total = 0; | |
278 gint cur; | |
279 | |
280 while (total < len) { | |
281 if (g_io_channel_read(source, buf + total, len - total, &cur) != G_IO_ERROR_NONE) | |
282 return -1; | |
283 if (cur == 0) | |
284 return total; | |
285 total += cur; | |
286 } | |
287 | |
288 return total; | |
289 } | |
290 | |
291 static gboolean UI_readable(GIOChannel *source, GIOCondition cond, gpointer data) | |
292 { | |
293 struct UI *ui = data; | |
294 | |
2438
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
295 guchar type; |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
296 guchar subtype; |
2416 | 297 guint32 len; |
298 | |
299 guchar *in; | |
300 | |
301 /* no byte order worries! this'll change if we go to TCP */ | |
2438
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
302 if (gaim_recv(source, &type, sizeof(type)) != sizeof(type)) { |
2416 | 303 debug_printf("UI has abandoned us!\n"); |
304 uis = g_slist_remove(uis, ui); | |
305 g_io_channel_close(ui->channel); | |
306 g_source_remove(ui->inpa); | |
307 g_free(ui); | |
308 return FALSE; | |
309 } | |
310 | |
2438
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
311 if (gaim_recv(source, &subtype, sizeof(subtype)) != sizeof(subtype)) { |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
312 debug_printf("UI has abandoned us!\n"); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
313 uis = g_slist_remove(uis, ui); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
314 g_io_channel_close(ui->channel); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
315 g_source_remove(ui->inpa); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
316 g_free(ui); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
317 return FALSE; |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
318 } |
2416 | 319 |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2503
diff
changeset
|
320 if (gaim_recv(source, (guchar *)&len, sizeof(len)) != sizeof(len)) { |
2438
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
321 debug_printf("UI has abandoned us!\n"); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
322 uis = g_slist_remove(uis, ui); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
323 g_io_channel_close(ui->channel); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
324 g_source_remove(ui->inpa); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
325 g_free(ui); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
326 return FALSE; |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
327 } |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
328 |
2441
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
329 if (len) { |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
330 in = g_new0(guchar, len); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
331 if (gaim_recv(source, in, len) != len) { |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
332 debug_printf("UI has abandoned us!\n"); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
333 uis = g_slist_remove(uis, ui); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
334 g_io_channel_close(ui->channel); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
335 g_source_remove(ui->inpa); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
336 g_free(ui); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
337 return FALSE; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
338 } |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
339 } else |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
340 in = NULL; |
2438
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
341 |
2416 | 342 switch (type) { |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
343 case CUI_TYPE_META: |
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
344 meta_handler(ui, subtype, in); |
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
345 break; |
2416 | 346 case CUI_TYPE_PLUGIN: |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
347 plugin_handler(ui, subtype, in); |
2416 | 348 break; |
349 case CUI_TYPE_USER: | |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
350 user_handler(ui, subtype, in); |
2416 | 351 break; |
2441
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
352 /* |
2416 | 353 case CUI_TYPE_CONN: |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
354 conn_handler(ui, subtype, in); |
2416 | 355 break; |
356 case CUI_TYPE_BUDDY: | |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
357 buddy_handler(ui, subtype, in); |
2416 | 358 break; |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
359 */ |
2416 | 360 case CUI_TYPE_MESSAGE: |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
361 message_handler(ui, subtype, in); |
2416 | 362 break; |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
363 /* |
2416 | 364 case CUI_TYPE_CHAT: |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
365 chat_handler(ui, subtype, in); |
2416 | 366 break; |
367 */ | |
368 default: | |
369 debug_printf("unhandled type %d\n", type); | |
370 break; | |
371 } | |
372 | |
2441
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
373 if (in) |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
374 g_free(in); |
2416 | 375 return TRUE; |
376 } | |
377 | |
378 static gboolean socket_readable(GIOChannel *source, GIOCondition cond, gpointer data) | |
379 { | |
380 struct sockaddr_un saddr; | |
381 gint len; | |
382 gint fd; | |
383 | |
384 struct UI *ui; | |
385 | |
386 if ((fd = accept(UI_fd, (struct sockaddr *)&saddr, &len)) == -1) | |
387 return FALSE; | |
388 | |
389 ui = g_new0(struct UI, 1); | |
390 uis = g_slist_append(uis, ui); | |
391 | |
392 ui->channel = g_io_channel_unix_new(fd); | |
393 ui->inpa = g_io_add_watch(ui->channel, G_IO_IN | G_IO_HUP | G_IO_ERR, UI_readable, ui); | |
394 g_io_channel_unref(ui->channel); | |
395 | |
396 debug_printf("got one\n"); | |
397 return TRUE; | |
398 } | |
399 | |
400 static gint open_socket() | |
401 { | |
402 struct sockaddr_un saddr; | |
403 gint fd; | |
404 | |
405 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) { | |
2503
b4ac3b5f484b
[gaim-migrate @ 2516]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2482
diff
changeset
|
406 mode_t m = umask(0177); |
2416 | 407 saddr.sun_family = AF_UNIX; |
408 g_snprintf(saddr.sun_path, 108, "%s/gaim_%s.%d", | |
409 g_get_tmp_dir(), g_get_user_name(), getpid()); | |
410 if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) != -1) | |
411 listen(fd, 100); | |
412 else | |
413 g_log(NULL, G_LOG_LEVEL_CRITICAL, | |
414 "Failed to assign %s to a socket (Error: %s)", | |
415 saddr.sun_path, strerror(errno)); | |
2503
b4ac3b5f484b
[gaim-migrate @ 2516]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2482
diff
changeset
|
416 umask(m); |
2416 | 417 } else |
418 g_log(NULL, G_LOG_LEVEL_CRITICAL, "Unable to open socket: %s", strerror(errno)); | |
419 return fd; | |
420 } | |
421 | |
422 int core_main() | |
423 { | |
424 /* | |
425 GMainLoop *loop; | |
426 */ | |
427 | |
428 GIOChannel *channel; | |
429 | |
430 UI_fd = open_socket(); | |
431 if (UI_fd < 0) | |
432 return 1; | |
433 | |
434 channel = g_io_channel_unix_new(UI_fd); | |
435 g_io_add_watch(channel, G_IO_IN, socket_readable, NULL); | |
436 g_io_channel_unref(channel); | |
437 | |
438 /* | |
439 loop = g_main_new(TRUE); | |
440 g_main_run(loop); | |
441 */ | |
442 | |
443 return 0; | |
444 } | |
445 | |
446 void core_quit() | |
447 { | |
448 char buf[1024]; | |
449 close(UI_fd); | |
450 sprintf(buf, "%s/gaim_%s.%d", g_get_tmp_dir(), g_get_user_name(), getpid()); | |
451 unlink(buf); | |
452 } |