Mercurial > pidgin
annotate src/core.c @ 3809:627c373f1678
[gaim-migrate @ 3956]
yes i know jabber account registration crashes. where is JSeymour when you need him?
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sun, 27 Oct 2002 21:28:49 +0000 |
parents | d7e83b4db191 |
children | b5dbc9d49939 |
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; |
59 | |
2544
271011bbe14e
[gaim-migrate @ 2557]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2541
diff
changeset
|
60 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
|
61 { |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
62 guchar *buffer; |
2462
cf2f2450f7cc
[gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2447
diff
changeset
|
63 guint32 pos; |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
64 int size; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
65 void *data; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
66 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
67 *len = sizeof(guchar) * 2 + 4; |
2462
cf2f2450f7cc
[gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2447
diff
changeset
|
68 buffer = g_malloc(*len); |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
69 pos = 0; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
70 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
71 memcpy(buffer + pos, &type, sizeof(type)); pos += sizeof(type); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
72 memcpy(buffer + pos, &subtype, sizeof(subtype)); pos += sizeof(subtype); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
73 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
74 /* we come back and do size last */ |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
75 pos += 4; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
76 |
2544
271011bbe14e
[gaim-migrate @ 2557]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2541
diff
changeset
|
77 size = va_arg(args, int); |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
78 while (size != -1) { |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
79 *len += size; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
80 buffer = g_realloc(buffer, *len); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
81 |
2544
271011bbe14e
[gaim-migrate @ 2557]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2541
diff
changeset
|
82 data = va_arg(args, void *); |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
83 memcpy(buffer + pos, data, size); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
84 pos += size; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
85 |
2544
271011bbe14e
[gaim-migrate @ 2557]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2541
diff
changeset
|
86 size = va_arg(args, int); |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
87 } |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
88 |
2482
7e4757801725
[gaim-migrate @ 2495]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2462
diff
changeset
|
89 pos -= sizeof(guchar) * 2 + 4; |
7e4757801725
[gaim-migrate @ 2495]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2462
diff
changeset
|
90 |
2462
cf2f2450f7cc
[gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2447
diff
changeset
|
91 /* now we do size */ |
cf2f2450f7cc
[gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2447
diff
changeset
|
92 memcpy(buffer + sizeof(guchar) * 2, &pos, 4); |
cf2f2450f7cc
[gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2447
diff
changeset
|
93 |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
94 return buffer; |
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 |
2435
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
97 gint UI_write(struct UI *ui, guchar *data, gint len) |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
98 { |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
99 gint sent; |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
100 /* 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
|
101 g_io_channel_write(ui->channel, data, len, &sent); |
2435
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
102 return sent; |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
103 } |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
104 |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
105 void UI_build_write(struct UI *ui, guchar type, guchar subtype, ...) |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
106 { |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
107 va_list ap; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
108 gchar *data; |
2462
cf2f2450f7cc
[gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2447
diff
changeset
|
109 guint32 len; |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
110 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
111 va_start(ap, subtype); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
112 data = UI_build(&len, type, subtype, ap); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
113 va_end(ap); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
114 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
115 UI_write(ui, data, len); |
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 g_free(data); |
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 |
2435
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
120 void UI_broadcast(guchar *data, gint len) |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
121 { |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
122 GSList *u = uis; |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
123 while (u) { |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
124 struct UI *ui = u->data; |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
125 UI_write(ui, data, len); |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
126 u = u->next; |
b4f2a53c0ee5
[gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2430
diff
changeset
|
127 } |
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 |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
130 void UI_build_broadcast(guchar type, guchar subtype, ...) |
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 va_list ap; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
133 gchar *data; |
2462
cf2f2450f7cc
[gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2447
diff
changeset
|
134 guint32 len; |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
135 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
136 if (!uis) |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
137 return; |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
138 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
139 va_start(ap, subtype); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
140 data = UI_build(&len, type, subtype, ap); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
141 va_end(ap); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
142 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
143 UI_broadcast(data, len); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
144 |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
145 g_free(data); |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
146 } |
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
147 |
3630 | 148 #ifndef _WIN32 |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
149 static void meta_handler(struct UI *ui, guchar subtype, guchar *data) |
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
150 { |
3478 | 151 struct gaim_cui_packet *p; |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
152 switch (subtype) { |
2440
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
153 case CUI_META_LIST: |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
154 break; |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
155 case CUI_META_QUIT: |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
156 while (uis) { |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
157 ui = uis->data; |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
158 uis = g_slist_remove(uis, ui); |
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
159 g_io_channel_close(ui->channel); |
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
160 g_source_remove(ui->inpa); |
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
161 g_free(ui); |
2440
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
162 } |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
163 do_quit(); |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
164 break; |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
165 case CUI_META_DETACH: |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
166 uis = g_slist_remove(uis, ui); |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
167 g_io_channel_close(ui->channel); |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
168 g_source_remove(ui->inpa); |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
169 g_free(ui); |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
170 break; |
3478 | 171 case CUI_META_PING: |
172 p = cui_packet_new(CUI_TYPE_META, CUI_META_ACK); | |
173 cui_send_packet(g_io_channel_unix_get_fd(ui->channel), p); | |
174 cui_packet_free(p); | |
175 break; | |
2440
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
176 default: |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
177 debug_printf("unhandled meta subtype %d\n", subtype); |
8306c042bac7
[gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2439
diff
changeset
|
178 break; |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
179 } |
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 |
2443
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
182 static void plugin_handler(struct UI *ui, guchar subtype, guchar *data) |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
183 { |
2446
f9cad82d321b
[gaim-migrate @ 2459]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
184 #ifdef GAIM_PLUGINS |
2443
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
185 guint id; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
186 struct gaim_plugin *p; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
187 |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
188 switch (subtype) { |
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 case CUI_PLUGIN_LIST: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
191 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
192 */ |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
193 case CUI_PLUGIN_LOAD: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
194 p = load_plugin(data); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
195 /* XXX need to broadcast to UIs that plugin has been loaded */ |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
196 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
197 case CUI_PLUGIN_UNLOAD: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
198 memcpy(&id, data, sizeof(id)); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
199 p = g_list_nth_data(plugins, id); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
200 if (p) { |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
201 unload_plugin(p); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
202 /* XXX need to broadcast to UIs that plugin has been unloaded */ |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
203 } |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
204 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
205 case CUI_PLUGIN_RELOAD: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
206 memcpy(&id, data, sizeof(id)); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
207 p = g_list_nth_data(plugins, id); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
208 if (p) { |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
209 p = reload_plugin(p); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
210 /* XXX need to broadcast to UIs that plugin has been reloaded */ |
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 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
213 default: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
214 debug_printf("unhandled plugin subtype %d\n", subtype); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
215 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
216 } |
2446
f9cad82d321b
[gaim-migrate @ 2459]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
217 #endif |
2443
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
218 } |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
219 |
2441
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
220 static void user_handler(struct UI *ui, guchar subtype, guchar *data) |
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 guint id; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
223 struct aim_user *u; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
224 |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
225 switch (subtype) { |
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 case CUI_USER_LIST: |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
228 break; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
229 case CUI_USER_ADD: |
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 case CUI_USER_REMOVE: |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
232 break; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
233 case CUI_USER_MODIFY: |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
234 break; |
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 case CUI_USER_SIGNON: |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
237 if (!data) |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
238 return; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
239 memcpy(&id, data, sizeof(id)); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
240 u = g_slist_nth_data(aim_users, id); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
241 if (u) |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
242 serv_login(u); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
243 /* 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
|
244 break; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
245 default: |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
246 debug_printf("unhandled user subtype %d\n", subtype); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
247 break; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
248 } |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
249 } |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
250 |
2443
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
251 static void message_handler(struct UI *ui, guchar subtype, guchar *data) |
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 switch (subtype) { |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
254 case CUI_MESSAGE_LIST: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
255 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
256 case CUI_MESSAGE_SEND: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
257 if (!data) |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
258 return; |
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 guint id; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
261 struct gaim_connection *gc; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
262 guint len; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
263 char *who, *msg; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
264 gint flags; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
265 int pos = 0; |
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 memcpy(&id, data + pos, sizeof(id)); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
268 pos += sizeof(id); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
269 gc = g_slist_nth_data(connections, id); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
270 if (!gc) |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
271 return; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
272 |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
273 memcpy(&len, data + pos, sizeof(len)); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
274 pos += sizeof(len); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
275 who = g_strndup(data + pos, len + 1); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
276 pos += len; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
277 |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
278 memcpy(&len, data + pos, sizeof(len)); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
279 pos += sizeof(len); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
280 msg = g_strndup(data + pos, len + 1); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
281 pos += len; |
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 memcpy(&flags, data + pos, sizeof(flags)); |
3033 | 284 serv_send_im(gc, who, msg, -1, flags); |
2443
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
285 |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
286 g_free(who); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
287 g_free(msg); |
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 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
290 case CUI_MESSAGE_RECV: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
291 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
292 default: |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
293 debug_printf("unhandled message subtype %d\n", subtype); |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
294 break; |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
295 } |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
296 } |
7f2432a87376
[gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2441
diff
changeset
|
297 |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2503
diff
changeset
|
298 static gint gaim_recv(GIOChannel *source, guchar *buf, gint len) |
2416 | 299 { |
300 gint total = 0; | |
301 gint cur; | |
302 | |
303 while (total < len) { | |
304 if (g_io_channel_read(source, buf + total, len - total, &cur) != G_IO_ERROR_NONE) | |
305 return -1; | |
306 if (cur == 0) | |
307 return total; | |
308 total += cur; | |
309 } | |
310 | |
311 return total; | |
312 } | |
313 | |
3478 | 314 static void remote_handler(struct UI *ui, guchar subtype, guchar *data, int len) |
315 { | |
316 const char *resp; | |
317 char *send; | |
318 switch (subtype) { | |
319 case CUI_REMOTE_CONNECTIONS: | |
320 break; | |
321 case CUI_REMOTE_URI: | |
322 send = g_malloc(len + 1); | |
323 memcpy(send, data, len); | |
324 send[len] = 0; | |
325 resp = handle_uri(send); | |
326 g_free(send); | |
327 /* report error */ | |
328 break; | |
329 default: | |
330 debug_printf("Unhandled remote subtype %d\n", subtype); | |
331 break; | |
332 } | |
333 } | |
334 | |
2416 | 335 static gboolean UI_readable(GIOChannel *source, GIOCondition cond, gpointer data) |
336 { | |
337 struct UI *ui = data; | |
338 | |
2438
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
339 guchar type; |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
340 guchar subtype; |
2416 | 341 guint32 len; |
342 | |
343 guchar *in; | |
344 | |
345 /* 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
|
346 if (gaim_recv(source, &type, sizeof(type)) != sizeof(type)) { |
2416 | 347 debug_printf("UI has abandoned us!\n"); |
348 uis = g_slist_remove(uis, ui); | |
349 g_io_channel_close(ui->channel); | |
350 g_source_remove(ui->inpa); | |
351 g_free(ui); | |
352 return FALSE; | |
353 } | |
354 | |
2438
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
355 if (gaim_recv(source, &subtype, sizeof(subtype)) != sizeof(subtype)) { |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
356 debug_printf("UI has abandoned us!\n"); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
357 uis = g_slist_remove(uis, ui); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
358 g_io_channel_close(ui->channel); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
359 g_source_remove(ui->inpa); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
360 g_free(ui); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
361 return FALSE; |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
362 } |
2416 | 363 |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2503
diff
changeset
|
364 if (gaim_recv(source, (guchar *)&len, sizeof(len)) != sizeof(len)) { |
2438
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
365 debug_printf("UI has abandoned us!\n"); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
366 uis = g_slist_remove(uis, ui); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
367 g_io_channel_close(ui->channel); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
368 g_source_remove(ui->inpa); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
369 g_free(ui); |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
370 return FALSE; |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
371 } |
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
372 |
2441
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
373 if (len) { |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
374 in = g_new0(guchar, len); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
375 if (gaim_recv(source, in, len) != len) { |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
376 debug_printf("UI has abandoned us!\n"); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
377 uis = g_slist_remove(uis, ui); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
378 g_io_channel_close(ui->channel); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
379 g_source_remove(ui->inpa); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
380 g_free(ui); |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
381 return FALSE; |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
382 } |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
383 } else |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
384 in = NULL; |
2438
5cbe86a444d9
[gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2435
diff
changeset
|
385 |
2416 | 386 switch (type) { |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
387 case CUI_TYPE_META: |
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
388 meta_handler(ui, subtype, in); |
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
389 break; |
2416 | 390 case CUI_TYPE_PLUGIN: |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
391 plugin_handler(ui, subtype, in); |
2416 | 392 break; |
393 case CUI_TYPE_USER: | |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
394 user_handler(ui, subtype, in); |
2416 | 395 break; |
2441
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
396 /* |
2416 | 397 case CUI_TYPE_CONN: |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
398 conn_handler(ui, subtype, in); |
2416 | 399 break; |
400 case CUI_TYPE_BUDDY: | |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
401 buddy_handler(ui, subtype, in); |
2416 | 402 break; |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
403 */ |
2416 | 404 case CUI_TYPE_MESSAGE: |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
405 message_handler(ui, subtype, in); |
2416 | 406 break; |
2447
6bdeb91abe4e
[gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2446
diff
changeset
|
407 /* |
2416 | 408 case CUI_TYPE_CHAT: |
2439
932adc1ac9ed
[gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2438
diff
changeset
|
409 chat_handler(ui, subtype, in); |
2416 | 410 break; |
3478 | 411 */ |
412 case CUI_TYPE_REMOTE: | |
413 remote_handler(ui, subtype, in, len); | |
414 break; | |
415 default: | |
2416 | 416 debug_printf("unhandled type %d\n", type); |
417 break; | |
418 } | |
419 | |
2441
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
420 if (in) |
2c2c1f717616
[gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2440
diff
changeset
|
421 g_free(in); |
2416 | 422 return TRUE; |
423 } | |
424 | |
425 static gboolean socket_readable(GIOChannel *source, GIOCondition cond, gpointer data) | |
426 { | |
427 struct sockaddr_un saddr; | |
428 gint len; | |
429 gint fd; | |
430 | |
431 struct UI *ui; | |
432 | |
433 if ((fd = accept(UI_fd, (struct sockaddr *)&saddr, &len)) == -1) | |
434 return FALSE; | |
435 | |
436 ui = g_new0(struct UI, 1); | |
437 uis = g_slist_append(uis, ui); | |
438 | |
439 ui->channel = g_io_channel_unix_new(fd); | |
440 ui->inpa = g_io_add_watch(ui->channel, G_IO_IN | G_IO_HUP | G_IO_ERR, UI_readable, ui); | |
441 g_io_channel_unref(ui->channel); | |
442 | |
443 debug_printf("got one\n"); | |
444 return TRUE; | |
445 } | |
446 | |
447 static gint open_socket() | |
448 { | |
449 struct sockaddr_un saddr; | |
450 gint fd; | |
3478 | 451 |
452 while (gaim_session_exists(gaim_session)) | |
453 gaim_session++; | |
454 | |
455 debug_printf("session: %d\n", gaim_session); | |
456 | |
2416 | 457 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) { |
2503
b4ac3b5f484b
[gaim-migrate @ 2516]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2482
diff
changeset
|
458 mode_t m = umask(0177); |
2416 | 459 saddr.sun_family = AF_UNIX; |
3630 | 460 |
461 g_snprintf(saddr.sun_path, sizeof(saddr.sun_path), "%s" G_DIR_SEPARATOR_S "gaim_%s.%d", | |
462 g_get_tmp_dir(), g_get_user_name(), gaim_session); | |
2416 | 463 if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) != -1) |
464 listen(fd, 100); | |
3091 | 465 else { |
2416 | 466 g_log(NULL, G_LOG_LEVEL_CRITICAL, |
3478 | 467 "Failed to assign %s to a socket (Error: %s)", |
468 saddr.sun_path, strerror(errno)); | |
3091 | 469 return -1; |
470 } | |
2503
b4ac3b5f484b
[gaim-migrate @ 2516]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2482
diff
changeset
|
471 umask(m); |
2416 | 472 } else |
473 g_log(NULL, G_LOG_LEVEL_CRITICAL, "Unable to open socket: %s", strerror(errno)); | |
474 return fd; | |
475 } | |
3630 | 476 #endif /*! _WIN32*/ |
2416 | 477 |
478 int core_main() | |
479 { | |
480 /* | |
481 GMainLoop *loop; | |
482 */ | |
483 | |
3630 | 484 #ifndef _WIN32 |
2416 | 485 GIOChannel *channel; |
486 | |
487 UI_fd = open_socket(); | |
488 if (UI_fd < 0) | |
489 return 1; | |
490 | |
491 channel = g_io_channel_unix_new(UI_fd); | |
492 g_io_add_watch(channel, G_IO_IN, socket_readable, NULL); | |
493 g_io_channel_unref(channel); | |
3630 | 494 #endif |
495 | |
496 #ifdef _WIN32 | |
497 WORD wVersionRequested; | |
498 WSADATA wsaData; | |
499 int err; | |
500 | |
501 wVersionRequested = MAKEWORD( 2, 2 ); | |
502 | |
503 err = WSAStartup( wVersionRequested, &wsaData ); | |
504 if ( err != 0 ) { | |
505 return 1; | |
506 } | |
507 | |
508 /* Confirm that the winsock DLL supports 2.2 */ | |
509 /* Note that if the DLL supports versions greater than | |
510 2.2 in addition to 2.2, it will still return 2.2 in | |
511 wVersion since that is the version we requested. */ | |
512 | |
513 if ( LOBYTE( wsaData.wVersion ) != 2 || | |
514 HIBYTE( wsaData.wVersion ) != 2 ) { | |
515 debug_printf("Could not find a usable WinSock DLL. Oh well.\n"); | |
516 WSACleanup( ); | |
517 return 1; | |
518 } | |
519 #endif /* _WIN32 */ | |
2416 | 520 |
521 /* | |
522 loop = g_main_new(TRUE); | |
523 g_main_run(loop); | |
524 */ | |
525 | |
526 return 0; | |
527 } | |
528 | |
529 void core_quit() | |
530 { | |
3630 | 531 #ifndef _WIN32 |
2416 | 532 char buf[1024]; |
533 close(UI_fd); | |
3630 | 534 sprintf(buf, "%s" G_DIR_SEPARATOR_S "gaim_%s.%d", g_get_tmp_dir(), g_get_user_name(), gaim_session); |
2416 | 535 unlink(buf); |
2755
adbda5d9b50c
[gaim-migrate @ 2768]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2596
diff
changeset
|
536 debug_printf("Removed core\n"); |
3630 | 537 #else |
538 WSACleanup( ); | |
539 #endif | |
2416 | 540 } |