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