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