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