annotate src/core.c @ 3668:5b82f99d028d

[gaim-migrate @ 3798] Just getting some things set up committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Sun, 13 Oct 2002 23:06:22 +0000
parents 9682c0e022c6
children d7e83b4db191
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 /*
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 * gaim
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 *
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 *
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 * (at your option) any later version.
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 *
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 * GNU General Public License for more details.
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 *
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 *
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 */
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 #ifdef HAVE_CONFIG_H
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 #include "config.h"
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 #endif
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26 #include <glib.h>
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 #include <stdio.h>
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28 #include <stdlib.h>
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29 #include <sys/types.h>
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
30
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
31 #ifdef _WIN32
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
32 #include <winsock.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
33 #include <io.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
34 #else
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 #include <sys/socket.h>
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 #include <sys/un.h>
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 #include <unistd.h>
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
38 #endif
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
39
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
40 #include <sys/stat.h>
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 #include <errno.h>
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 #include <signal.h>
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 #include "gaim.h"
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
48 #include "gaim-socket.h"
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
50 #ifdef _WIN32
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
51 #include "win32dep.h"
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
52 #endif
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
53
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 static gint UI_fd = -1;
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
55 int gaim_session = 0;
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56 GSList *uis = NULL;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57
2544
271011bbe14e [gaim-migrate @ 2557]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
58 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
59 {
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
60 guchar *buffer;
2462
cf2f2450f7cc [gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2447
diff changeset
61 guint32 pos;
2447
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
62 int size;
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
63 void *data;
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
64
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
65 *len = sizeof(guchar) * 2 + 4;
2462
cf2f2450f7cc [gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2447
diff changeset
66 buffer = g_malloc(*len);
2447
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
67 pos = 0;
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
68
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
69 memcpy(buffer + pos, &type, sizeof(type)); pos += sizeof(type);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
70 memcpy(buffer + pos, &subtype, sizeof(subtype)); pos += sizeof(subtype);
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 /* we come back and do size last */
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
73 pos += 4;
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
74
2544
271011bbe14e [gaim-migrate @ 2557]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
75 size = va_arg(args, int);
2447
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
76 while (size != -1) {
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
77 *len += size;
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
78 buffer = g_realloc(buffer, *len);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
79
2544
271011bbe14e [gaim-migrate @ 2557]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
80 data = va_arg(args, void *);
2447
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
81 memcpy(buffer + pos, data, size);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
82 pos += size;
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
83
2544
271011bbe14e [gaim-migrate @ 2557]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2541
diff changeset
84 size = va_arg(args, int);
2447
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
85 }
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
86
2482
7e4757801725 [gaim-migrate @ 2495]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2462
diff changeset
87 pos -= sizeof(guchar) * 2 + 4;
7e4757801725 [gaim-migrate @ 2495]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2462
diff changeset
88
2462
cf2f2450f7cc [gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2447
diff changeset
89 /* now we do size */
cf2f2450f7cc [gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2447
diff changeset
90 memcpy(buffer + sizeof(guchar) * 2, &pos, 4);
cf2f2450f7cc [gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2447
diff changeset
91
2447
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
92 return buffer;
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
2435
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
95 gint UI_write(struct UI *ui, guchar *data, gint len)
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
96 {
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
97 gint sent;
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
98 /* 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
99 g_io_channel_write(ui->channel, data, len, &sent);
2435
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
100 return sent;
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
101 }
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
102
2447
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
103 void UI_build_write(struct UI *ui, guchar type, guchar subtype, ...)
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
104 {
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
105 va_list ap;
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
106 gchar *data;
2462
cf2f2450f7cc [gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2447
diff changeset
107 guint32 len;
2447
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
108
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
109 va_start(ap, subtype);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
110 data = UI_build(&len, type, subtype, ap);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
111 va_end(ap);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
112
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
113 UI_write(ui, data, len);
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 g_free(data);
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
2435
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
118 void UI_broadcast(guchar *data, gint len)
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
119 {
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
120 GSList *u = uis;
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
121 while (u) {
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
122 struct UI *ui = u->data;
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
123 UI_write(ui, data, len);
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
124 u = u->next;
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
125 }
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
126 }
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
127
2447
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
128 void UI_build_broadcast(guchar type, guchar subtype, ...)
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 va_list ap;
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
131 gchar *data;
2462
cf2f2450f7cc [gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2447
diff changeset
132 guint32 len;
2447
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 if (!uis)
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
135 return;
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 va_start(ap, subtype);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
138 data = UI_build(&len, type, subtype, ap);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
139 va_end(ap);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
140
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
141 UI_broadcast(data, len);
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 g_free(data);
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
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
146 #ifndef _WIN32
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
147 static void meta_handler(struct UI *ui, guchar subtype, guchar *data)
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
148 {
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
149 struct gaim_cui_packet *p;
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
150 switch (subtype) {
2440
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
151 case CUI_META_LIST:
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
152 break;
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
153 case CUI_META_QUIT:
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
154 while (uis) {
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
155 ui = uis->data;
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
156 uis = g_slist_remove(uis, ui);
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
157 g_io_channel_close(ui->channel);
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
158 g_source_remove(ui->inpa);
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
159 g_free(ui);
2440
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
160 }
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
161 do_quit();
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
162 break;
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
163 case CUI_META_DETACH:
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
164 uis = g_slist_remove(uis, ui);
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
165 g_io_channel_close(ui->channel);
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
166 g_source_remove(ui->inpa);
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
167 g_free(ui);
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
168 break;
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
169 case CUI_META_PING:
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
170 p = cui_packet_new(CUI_TYPE_META, CUI_META_ACK);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
171 cui_send_packet(g_io_channel_unix_get_fd(ui->channel), p);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
172 cui_packet_free(p);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
173 break;
2440
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
174 default:
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
175 debug_printf("unhandled meta subtype %d\n", subtype);
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
176 break;
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
177 }
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
178 }
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
179
2443
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
180 static void plugin_handler(struct UI *ui, guchar subtype, guchar *data)
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
181 {
2446
f9cad82d321b [gaim-migrate @ 2459]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2443
diff changeset
182 #ifdef GAIM_PLUGINS
2443
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
183 guint id;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
184 struct gaim_plugin *p;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
185
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
186 switch (subtype) {
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 case CUI_PLUGIN_LIST:
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
189 break;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
190 */
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
191 case CUI_PLUGIN_LOAD:
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
192 p = load_plugin(data);
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
193 /* XXX need to broadcast to UIs that plugin has been loaded */
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
194 break;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
195 case CUI_PLUGIN_UNLOAD:
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
196 memcpy(&id, data, sizeof(id));
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
197 p = g_list_nth_data(plugins, id);
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
198 if (p) {
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
199 unload_plugin(p);
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
200 /* XXX need to broadcast to UIs that plugin has been unloaded */
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
201 }
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
202 break;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
203 case CUI_PLUGIN_RELOAD:
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
204 memcpy(&id, data, sizeof(id));
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
205 p = g_list_nth_data(plugins, id);
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
206 if (p) {
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
207 p = reload_plugin(p);
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
208 /* XXX need to broadcast to UIs that plugin has been reloaded */
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
209 }
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
210 break;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
211 default:
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
212 debug_printf("unhandled plugin subtype %d\n", subtype);
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
213 break;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
214 }
2446
f9cad82d321b [gaim-migrate @ 2459]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2443
diff changeset
215 #endif
2443
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
216 }
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
217
2441
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
218 static void user_handler(struct UI *ui, guchar subtype, guchar *data)
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 guint id;
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
221 struct aim_user *u;
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
222
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
223 switch (subtype) {
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 case CUI_USER_LIST:
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
226 break;
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
227 case CUI_USER_ADD:
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_REMOVE:
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_MODIFY:
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 */
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
234 case CUI_USER_SIGNON:
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
235 if (!data)
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
236 return;
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
237 memcpy(&id, data, sizeof(id));
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
238 u = g_slist_nth_data(aim_users, id);
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
239 if (u)
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
240 serv_login(u);
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
241 /* 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
242 break;
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
243 default:
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
244 debug_printf("unhandled user subtype %d\n", subtype);
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
245 break;
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
246 }
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
247 }
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
248
2443
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
249 static void message_handler(struct UI *ui, guchar subtype, guchar *data)
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
250 {
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
251 switch (subtype) {
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
252 case CUI_MESSAGE_LIST:
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
253 break;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
254 case CUI_MESSAGE_SEND:
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
255 if (!data)
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
256 return;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
257 {
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
258 guint id;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
259 struct gaim_connection *gc;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
260 guint len;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
261 char *who, *msg;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
262 gint flags;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
263 int pos = 0;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
264
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
265 memcpy(&id, data + pos, sizeof(id));
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
266 pos += sizeof(id);
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
267 gc = g_slist_nth_data(connections, id);
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
268 if (!gc)
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
269 return;
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 who = 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(&len, data + pos, sizeof(len));
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
277 pos += sizeof(len);
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
278 msg = g_strndup(data + pos, len + 1);
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
279 pos += len;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
280
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
281 memcpy(&flags, data + pos, sizeof(flags));
3033
1143524a2eaf [gaim-migrate @ 3046]
Sean Egan <seanegan@gmail.com>
parents: 2755
diff changeset
282 serv_send_im(gc, who, msg, -1, flags);
2443
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
283
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
284 g_free(who);
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
285 g_free(msg);
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
286 }
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 case CUI_MESSAGE_RECV:
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 default:
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
291 debug_printf("unhandled message subtype %d\n", subtype);
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
292 break;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
293 }
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
294 }
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
295
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2503
diff changeset
296 static gint gaim_recv(GIOChannel *source, guchar *buf, gint len)
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
297 {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
298 gint total = 0;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
299 gint cur;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
300
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
301 while (total < len) {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
302 if (g_io_channel_read(source, buf + total, len - total, &cur) != G_IO_ERROR_NONE)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
303 return -1;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
304 if (cur == 0)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
305 return total;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
306 total += cur;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
307 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
308
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
309 return total;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
310 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
311
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
312 static void remote_handler(struct UI *ui, guchar subtype, guchar *data, int len)
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
313 {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
314 const char *resp;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
315 char *send;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
316 switch (subtype) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
317 case CUI_REMOTE_CONNECTIONS:
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
318 break;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
319 case CUI_REMOTE_URI:
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
320 send = g_malloc(len + 1);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
321 memcpy(send, data, len);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
322 send[len] = 0;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
323 resp = handle_uri(send);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
324 g_free(send);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
325 /* report error */
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
326 break;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
327 default:
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
328 debug_printf("Unhandled remote subtype %d\n", subtype);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
329 break;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
330 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
331 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
332
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
333 static gboolean UI_readable(GIOChannel *source, GIOCondition cond, gpointer data)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
334 {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
335 struct UI *ui = data;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
336
2438
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
337 guchar type;
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
338 guchar subtype;
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
339 guint32 len;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
340
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
341 guchar *in;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
342
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
343 /* 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
344 if (gaim_recv(source, &type, sizeof(type)) != sizeof(type)) {
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
345 debug_printf("UI has abandoned us!\n");
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
346 uis = g_slist_remove(uis, ui);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
347 g_io_channel_close(ui->channel);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
348 g_source_remove(ui->inpa);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
349 g_free(ui);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
350 return FALSE;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
351 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
352
2438
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
353 if (gaim_recv(source, &subtype, sizeof(subtype)) != sizeof(subtype)) {
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
354 debug_printf("UI has abandoned us!\n");
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
355 uis = g_slist_remove(uis, ui);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
356 g_io_channel_close(ui->channel);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
357 g_source_remove(ui->inpa);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
358 g_free(ui);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
359 return FALSE;
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
360 }
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
361
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2503
diff changeset
362 if (gaim_recv(source, (guchar *)&len, sizeof(len)) != sizeof(len)) {
2438
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
363 debug_printf("UI has abandoned us!\n");
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
364 uis = g_slist_remove(uis, ui);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
365 g_io_channel_close(ui->channel);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
366 g_source_remove(ui->inpa);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
367 g_free(ui);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
368 return FALSE;
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
369 }
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
370
2441
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
371 if (len) {
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
372 in = g_new0(guchar, len);
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
373 if (gaim_recv(source, in, len) != len) {
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
374 debug_printf("UI has abandoned us!\n");
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
375 uis = g_slist_remove(uis, ui);
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
376 g_io_channel_close(ui->channel);
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
377 g_source_remove(ui->inpa);
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
378 g_free(ui);
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
379 return FALSE;
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
380 }
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
381 } else
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
382 in = NULL;
2438
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
383
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
384 switch (type) {
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
385 case CUI_TYPE_META:
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
386 meta_handler(ui, subtype, in);
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
387 break;
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
388 case CUI_TYPE_PLUGIN:
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
389 plugin_handler(ui, subtype, in);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
390 break;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
391 case CUI_TYPE_USER:
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
392 user_handler(ui, subtype, in);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
393 break;
2441
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
394 /*
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
395 case CUI_TYPE_CONN:
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
396 conn_handler(ui, subtype, in);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
397 break;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
398 case CUI_TYPE_BUDDY:
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
399 buddy_handler(ui, subtype, in);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
400 break;
2447
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
401 */
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
402 case CUI_TYPE_MESSAGE:
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
403 message_handler(ui, subtype, in);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
404 break;
2447
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
405 /*
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
406 case CUI_TYPE_CHAT:
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
407 chat_handler(ui, subtype, in);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
408 break;
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
409 */
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
410 case CUI_TYPE_REMOTE:
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
411 remote_handler(ui, subtype, in, len);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
412 break;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
413 default:
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
414 debug_printf("unhandled type %d\n", type);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
415 break;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
416 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
417
2441
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
418 if (in)
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
419 g_free(in);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
420 return TRUE;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
421 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
422
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
423 static gboolean socket_readable(GIOChannel *source, GIOCondition cond, gpointer data)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
424 {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
425 struct sockaddr_un saddr;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
426 gint len;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
427 gint fd;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
428
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
429 struct UI *ui;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
430
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
431 if ((fd = accept(UI_fd, (struct sockaddr *)&saddr, &len)) == -1)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
432 return FALSE;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
433
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
434 ui = g_new0(struct UI, 1);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
435 uis = g_slist_append(uis, ui);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
436
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
437 ui->channel = g_io_channel_unix_new(fd);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
438 ui->inpa = g_io_add_watch(ui->channel, G_IO_IN | G_IO_HUP | G_IO_ERR, UI_readable, ui);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
439 g_io_channel_unref(ui->channel);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
440
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
441 debug_printf("got one\n");
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
442 return TRUE;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
443 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
444
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
445 static gint open_socket()
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
446 {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
447 struct sockaddr_un saddr;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
448 gint fd;
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
449
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
450 while (gaim_session_exists(gaim_session))
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
451 gaim_session++;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
452
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
453 debug_printf("session: %d\n", gaim_session);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
454
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
455 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) {
2503
b4ac3b5f484b [gaim-migrate @ 2516]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2482
diff changeset
456 mode_t m = umask(0177);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
457 saddr.sun_family = AF_UNIX;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
458
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
459 g_snprintf(saddr.sun_path, sizeof(saddr.sun_path), "%s" G_DIR_SEPARATOR_S "gaim_%s.%d",
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
460 g_get_tmp_dir(), g_get_user_name(), gaim_session);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
461 if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) != -1)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
462 listen(fd, 100);
3091
1e12a24b7f27 [gaim-migrate @ 3105]
Sean Egan <seanegan@gmail.com>
parents: 3033
diff changeset
463 else {
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
464 g_log(NULL, G_LOG_LEVEL_CRITICAL,
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
465 "Failed to assign %s to a socket (Error: %s)",
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
466 saddr.sun_path, strerror(errno));
3091
1e12a24b7f27 [gaim-migrate @ 3105]
Sean Egan <seanegan@gmail.com>
parents: 3033
diff changeset
467 return -1;
1e12a24b7f27 [gaim-migrate @ 3105]
Sean Egan <seanegan@gmail.com>
parents: 3033
diff changeset
468 }
2503
b4ac3b5f484b [gaim-migrate @ 2516]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2482
diff changeset
469 umask(m);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
470 } else
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
471 g_log(NULL, G_LOG_LEVEL_CRITICAL, "Unable to open socket: %s", strerror(errno));
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
472 return fd;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
473 }
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
474 #endif /*! _WIN32*/
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
475
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
476 int core_main()
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
477 {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
478 /*
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
479 GMainLoop *loop;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
480 */
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
481
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
482 #ifndef _WIN32
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
483 GIOChannel *channel;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
484
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
485 UI_fd = open_socket();
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
486 if (UI_fd < 0)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
487 return 1;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
488
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
489 channel = g_io_channel_unix_new(UI_fd);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
490 g_io_add_watch(channel, G_IO_IN, socket_readable, NULL);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
491 g_io_channel_unref(channel);
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
492 #endif
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
493
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
494 #ifdef _WIN32
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
495 WORD wVersionRequested;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
496 WSADATA wsaData;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
497 int err;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
498
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
499 wVersionRequested = MAKEWORD( 2, 2 );
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
500
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
501 err = WSAStartup( wVersionRequested, &wsaData );
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
502 if ( err != 0 ) {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
503 return 1;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
504 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
505
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
506 /* Confirm that the winsock DLL supports 2.2 */
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
507 /* Note that if the DLL supports versions greater than
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
508 2.2 in addition to 2.2, it will still return 2.2 in
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
509 wVersion since that is the version we requested. */
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
510
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
511 if ( LOBYTE( wsaData.wVersion ) != 2 ||
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
512 HIBYTE( wsaData.wVersion ) != 2 ) {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
513 debug_printf("Could not find a usable WinSock DLL. Oh well.\n");
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
514 WSACleanup( );
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
515 return 1;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
516 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
517 #endif /* _WIN32 */
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
518
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
519 /*
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
520 loop = g_main_new(TRUE);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
521 g_main_run(loop);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
522 */
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
523
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
524 return 0;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
525 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
526
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
527 void core_quit()
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
528 {
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
529 #ifndef _WIN32
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
530 char buf[1024];
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
531 close(UI_fd);
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
532 sprintf(buf, "%s" G_DIR_SEPARATOR_S "gaim_%s.%d", g_get_tmp_dir(), g_get_user_name(), gaim_session);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
533 unlink(buf);
2755
adbda5d9b50c [gaim-migrate @ 2768]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
534 debug_printf("Removed core\n");
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
535 #else
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
536 WSACleanup( );
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
537 #endif
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
538 }