annotate src/core.c @ 5370:058230cccebb

[gaim-migrate @ 5746] Adding some stuff here that is, er, a bit important. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Wed, 14 May 2003 05:53:48 +0000
parents 1cf4eb75e3ee
children a2f26666de42
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
3716
d7e83b4db191 [gaim-migrate @ 3849]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
54 #ifndef _WIN32
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 static gint UI_fd = -1;
3716
d7e83b4db191 [gaim-migrate @ 3849]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 3630
diff changeset
56 #endif
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
57 int gaim_session = 0;
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58 GSList *uis = NULL;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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 {
4817
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
99 GError *error = NULL;
2435
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
100 gint sent;
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
101 /* we'll let the write silently fail because the read will pick it up as dead */
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4770
diff changeset
102 g_io_channel_write_chars(ui->channel, data, len, &sent, &error);
4817
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
103 if (error)
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
104 g_error_free(error);
2435
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
105 return sent;
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
106 }
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
107
2447
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
108 void UI_build_write(struct UI *ui, guchar type, guchar subtype, ...)
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
109 {
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
110 va_list ap;
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
111 gchar *data;
2462
cf2f2450f7cc [gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2447
diff changeset
112 guint32 len;
2447
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
113
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
114 va_start(ap, subtype);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
115 data = UI_build(&len, type, subtype, ap);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
116 va_end(ap);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
117
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
118 UI_write(ui, data, len);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
119
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
120 g_free(data);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
121 }
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
122
2435
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
123 void UI_broadcast(guchar *data, gint len)
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
124 {
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
125 GSList *u = uis;
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
126 while (u) {
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
127 struct UI *ui = u->data;
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
128 UI_write(ui, data, len);
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
129 u = u->next;
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
130 }
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
131 }
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
132
2447
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
133 void UI_build_broadcast(guchar type, guchar subtype, ...)
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
134 {
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
135 va_list ap;
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
136 gchar *data;
2462
cf2f2450f7cc [gaim-migrate @ 2475]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2447
diff changeset
137 guint32 len;
2447
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 if (!uis)
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
140 return;
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
141
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
142 va_start(ap, subtype);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
143 data = UI_build(&len, type, subtype, ap);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
144 va_end(ap);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
145
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
146 UI_broadcast(data, len);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
147
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
148 g_free(data);
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
149 }
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
150
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
151 #ifndef _WIN32
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
152 static void meta_handler(struct UI *ui, guchar subtype, guchar *data)
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
153 {
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
154 struct gaim_cui_packet *p;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4770
diff changeset
155 GError *error = NULL;
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
156 switch (subtype) {
2440
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
157 case CUI_META_LIST:
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
158 break;
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
159 case CUI_META_QUIT:
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
160 while (uis) {
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
161 ui = uis->data;
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
162 uis = g_slist_remove(uis, ui);
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4770
diff changeset
163 g_io_channel_shutdown(ui->channel, TRUE, &error);
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
164 g_source_remove(ui->inpa);
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
165 g_free(ui);
2440
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
166 }
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
167 do_quit();
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
168 break;
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
169 case CUI_META_DETACH:
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
170 uis = g_slist_remove(uis, ui);
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4770
diff changeset
171 g_io_channel_shutdown(ui->channel, TRUE, &error);
2440
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
172 g_source_remove(ui->inpa);
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
173 g_free(ui);
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
174 break;
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
175 case CUI_META_PING:
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
176 p = cui_packet_new(CUI_TYPE_META, CUI_META_ACK);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
177 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
178 cui_packet_free(p);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
179 break;
2440
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
180 default:
5213
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
181 gaim_debug(GAIM_DEBUG_WARNING, "cui",
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
182 "Unhandled meta subtype %d\n", subtype);
2440
8306c042bac7 [gaim-migrate @ 2453]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2439
diff changeset
183 break;
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
184 }
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4770
diff changeset
185
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4770
diff changeset
186 if(error)
4800
4af15fbcb00a [gaim-migrate @ 5120]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
187 g_error_free(error);
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
188 }
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
189
2443
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
190 static void plugin_handler(struct UI *ui, guchar subtype, guchar *data)
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
191 {
2446
f9cad82d321b [gaim-migrate @ 2459]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2443
diff changeset
192 #ifdef GAIM_PLUGINS
2443
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
193 guint id;
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 4817
diff changeset
194 GaimPlugin *p;
2443
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
195
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
196 switch (subtype) {
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
197 /*
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
198 case CUI_PLUGIN_LIST:
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
199 break;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
200 */
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
201 case CUI_PLUGIN_LOAD:
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 4817
diff changeset
202 gaim_plugin_load(gaim_plugin_probe(data));
2443
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
203 break;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
204 case CUI_PLUGIN_UNLOAD:
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
205 memcpy(&id, data, sizeof(id));
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 4817
diff changeset
206 p = g_list_nth_data(gaim_plugins_get_loaded(), id);
2443
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
207 if (p) {
5205
fefad67de2c7 [gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents: 4817
diff changeset
208 gaim_plugin_unload(p);
2443
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:
5213
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
212 gaim_debug(GAIM_DEBUG_WARNING, "cui",
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
213 "Unhandled plugin subtype %d\n", subtype);
2443
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
214 break;
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
215 }
2446
f9cad82d321b [gaim-migrate @ 2459]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2443
diff changeset
216 #endif
2443
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
217 }
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
218
2441
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
219 static void user_handler(struct UI *ui, guchar subtype, guchar *data)
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
220 {
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
221 guint id;
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4349
diff changeset
222 struct gaim_account *account;
2441
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
223
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
224 switch (subtype) {
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
225 /*
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
226 case CUI_USER_LIST:
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
227 break;
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
228 case CUI_USER_ADD:
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
229 break;
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
230 case CUI_USER_REMOVE:
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
231 break;
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
232 case CUI_USER_MODIFY:
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
233 break;
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
234 */
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
235 case CUI_USER_SIGNON:
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
236 if (!data)
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
237 return;
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
238 memcpy(&id, data, sizeof(id));
4491
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4349
diff changeset
239 account = g_slist_nth_data(gaim_accounts, id);
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4349
diff changeset
240 if (account)
3196d9044a45 [gaim-migrate @ 4766]
Nathan Walp <nwalp@pidgin.im>
parents: 4349
diff changeset
241 serv_login(account);
2441
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
242 /* 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
243 break;
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
244 default:
5213
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
245 gaim_debug(GAIM_DEBUG_WARNING, "cui",
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
246 "Unhandled user subtype %d\n", subtype);
2441
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
1143524a2eaf [gaim-migrate @ 3046]
Sean Egan <seanegan@gmail.com>
parents: 2755
diff changeset
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:
5213
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
293 gaim_debug(GAIM_DEBUG_WARNING, "cui",
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
294 "Unhandled message subtype %d\n", subtype);
2443
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
295 break;
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 }
7f2432a87376 [gaim-migrate @ 2456]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2441
diff changeset
298
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2503
diff changeset
299 static gint gaim_recv(GIOChannel *source, guchar *buf, gint len)
2416
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 gint total = 0;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
302 gint cur;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
303
4800
4af15fbcb00a [gaim-migrate @ 5120]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
304 GError *error = NULL;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4770
diff changeset
305
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
306 while (total < len) {
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4770
diff changeset
307 if (g_io_channel_read_chars(source, buf + total, len - total, &cur, &error) != G_IO_STATUS_NORMAL) {
4817
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
308 if (error)
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
309 g_error_free(error);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
310 return -1;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4770
diff changeset
311 }
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
312 if (cur == 0)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
313 return total;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
314 total += cur;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
315 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
316
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
317 return total;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
318 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
319
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
320 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
321 {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
322 const char *resp;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
323 char *send;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
324 switch (subtype) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
325 case CUI_REMOTE_CONNECTIONS:
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 case CUI_REMOTE_URI:
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
328 send = g_malloc(len + 1);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
329 memcpy(send, data, len);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
330 send[len] = 0;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
331 resp = handle_uri(send);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
332 g_free(send);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
333 /* report error */
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
334 break;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
335 default:
5213
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
336 gaim_debug(GAIM_DEBUG_WARNING, "cui",
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
337 "Unhandled remote subtype %d\n", subtype);
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
338 break;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
339 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
340 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
341
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
342 static gboolean UI_readable(GIOChannel *source, GIOCondition cond, gpointer data)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
343 {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
344 struct UI *ui = data;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
345
2438
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
346 guchar type;
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
347 guchar subtype;
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
348 guint32 len;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
349
4817
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
350 GError *error = NULL;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4770
diff changeset
351
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
352 guchar *in;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
353
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
354 /* 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
355 if (gaim_recv(source, &type, sizeof(type)) != sizeof(type)) {
5213
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
356 gaim_debug(GAIM_DEBUG_ERROR, "cui", "UI has abandoned us!\n");
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
357 uis = g_slist_remove(uis, ui);
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4770
diff changeset
358 g_io_channel_shutdown(ui->channel, TRUE, &error);
4817
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
359 if(error) {
4800
4af15fbcb00a [gaim-migrate @ 5120]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
360 g_error_free(error);
4817
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
361 error = NULL;
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
362 }
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
363 g_source_remove(ui->inpa);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
364 g_free(ui);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
365 return FALSE;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
366 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
367
2438
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
368 if (gaim_recv(source, &subtype, sizeof(subtype)) != sizeof(subtype)) {
5213
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
369 gaim_debug(GAIM_DEBUG_ERROR, "cui", "UI has abandoned us!\n");
2438
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
370 uis = g_slist_remove(uis, ui);
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4770
diff changeset
371 g_io_channel_shutdown(ui->channel, TRUE, &error);
4817
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
372 if(error) {
4800
4af15fbcb00a [gaim-migrate @ 5120]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
373 g_error_free(error);
4817
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
374 error = NULL;
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
375 }
2438
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
376 g_source_remove(ui->inpa);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
377 g_free(ui);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
378 return FALSE;
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
379 }
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
380
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2503
diff changeset
381 if (gaim_recv(source, (guchar *)&len, sizeof(len)) != sizeof(len)) {
5213
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
382 gaim_debug(GAIM_DEBUG_ERROR, "cui", "UI has abandoned us!\n");
2438
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
383 uis = g_slist_remove(uis, ui);
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4770
diff changeset
384 g_io_channel_shutdown(ui->channel, TRUE, &error);
4817
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
385 if(error) {
4800
4af15fbcb00a [gaim-migrate @ 5120]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
386 g_error_free(error);
4817
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
387 error = NULL;
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
388 }
2438
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
389 g_source_remove(ui->inpa);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
390 g_free(ui);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
391 return FALSE;
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
392 }
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
393
2441
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
394 if (len) {
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
395 in = g_new0(guchar, len);
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
396 if (gaim_recv(source, in, len) != len) {
5213
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
397 gaim_debug(GAIM_DEBUG_ERROR, "cui", "UI has abandoned us!\n");
2441
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
398 uis = g_slist_remove(uis, ui);
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4770
diff changeset
399 g_io_channel_shutdown(ui->channel, TRUE, &error);
4817
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
400 if(error) {
4800
4af15fbcb00a [gaim-migrate @ 5120]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
401 g_error_free(error);
4817
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
402 error = NULL;
b4ca2cc6bed9 [gaim-migrate @ 5141]
Luke Schierer <lschiere@pidgin.im>
parents: 4800
diff changeset
403 }
2441
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
404 g_source_remove(ui->inpa);
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
405 g_free(ui);
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
406 return FALSE;
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
407 }
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
408 } else
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
409 in = NULL;
2438
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
410
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
411 switch (type) {
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
412 case CUI_TYPE_META:
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
413 meta_handler(ui, subtype, in);
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
414 break;
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
415 case CUI_TYPE_PLUGIN:
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
416 plugin_handler(ui, subtype, in);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
417 break;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
418 case CUI_TYPE_USER:
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
419 user_handler(ui, subtype, in);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
420 break;
2441
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
421 /*
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
422 case CUI_TYPE_CONN:
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
423 conn_handler(ui, subtype, in);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
424 break;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
425 case CUI_TYPE_BUDDY:
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
426 buddy_handler(ui, subtype, in);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
427 break;
2447
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
428 */
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
429 case CUI_TYPE_MESSAGE:
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
430 message_handler(ui, subtype, in);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
431 break;
2447
6bdeb91abe4e [gaim-migrate @ 2460]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2446
diff changeset
432 /*
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
433 case CUI_TYPE_CHAT:
2439
932adc1ac9ed [gaim-migrate @ 2452]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2438
diff changeset
434 chat_handler(ui, subtype, in);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
435 break;
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
436 */
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
437 case CUI_TYPE_REMOTE:
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
438 remote_handler(ui, subtype, in, len);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
439 break;
5213
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
440 default:
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
441 gaim_debug(GAIM_DEBUG_WARNING, "cui",
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
442 "Unhandled type %d\n", type);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
443 break;
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
2441
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
446 if (in)
2c2c1f717616 [gaim-migrate @ 2454]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2440
diff changeset
447 g_free(in);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
448 return TRUE;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
449 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
450
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
451 static gboolean socket_readable(GIOChannel *source, GIOCondition cond, gpointer data)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
452 {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
453 struct sockaddr_un saddr;
4073
405340263d75 [gaim-migrate @ 4287]
Sean Egan <seanegan@gmail.com>
parents: 4064
diff changeset
454 gint len = sizeof(saddr);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
455 gint fd;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
456
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
457 struct UI *ui;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
458
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
459 if ((fd = accept(UI_fd, (struct sockaddr *)&saddr, &len)) == -1)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
460 return FALSE;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
461
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
462 ui = g_new0(struct UI, 1);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
463 uis = g_slist_append(uis, ui);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
464
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
465 ui->channel = g_io_channel_unix_new(fd);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
466 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
467 g_io_channel_unref(ui->channel);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
468
5213
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
469 gaim_debug(GAIM_DEBUG_MISC, "cui", "Got one\n");
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
470 return TRUE;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
471 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
472
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
473 static gint open_socket()
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
474 {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
475 struct sockaddr_un saddr;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
476 gint fd;
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
477
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
478 while (gaim_session_exists(gaim_session))
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
479 gaim_session++;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
480
5213
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
481 gaim_debug(GAIM_DEBUG_MISC, "cui", "Session: %d\n", gaim_session);
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
482
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
483 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) {
2503
b4ac3b5f484b [gaim-migrate @ 2516]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2482
diff changeset
484 mode_t m = umask(0177);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
485 saddr.sun_family = AF_UNIX;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
486
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
487 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
488 g_get_tmp_dir(), g_get_user_name(), gaim_session);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
489 if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) != -1)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
490 listen(fd, 100);
3091
1e12a24b7f27 [gaim-migrate @ 3105]
Sean Egan <seanegan@gmail.com>
parents: 3033
diff changeset
491 else {
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
492 g_log(NULL, G_LOG_LEVEL_CRITICAL,
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
493 "Failed to assign %s to a socket (Error: %s)",
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3091
diff changeset
494 saddr.sun_path, strerror(errno));
3091
1e12a24b7f27 [gaim-migrate @ 3105]
Sean Egan <seanegan@gmail.com>
parents: 3033
diff changeset
495 return -1;
1e12a24b7f27 [gaim-migrate @ 3105]
Sean Egan <seanegan@gmail.com>
parents: 3033
diff changeset
496 }
2503
b4ac3b5f484b [gaim-migrate @ 2516]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2482
diff changeset
497 umask(m);
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
498 } else
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
499 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
500 return fd;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
501 }
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
502 #endif /*! _WIN32*/
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
503
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
504 int core_main()
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
505 {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
506 /*
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
507 GMainLoop *loop;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
508 */
4502
7a2e45719bd0 [gaim-migrate @ 4777]
Nathan Walp <nwalp@pidgin.im>
parents: 4501
diff changeset
509 #ifndef _WIN32
7a2e45719bd0 [gaim-migrate @ 4777]
Nathan Walp <nwalp@pidgin.im>
parents: 4501
diff changeset
510 GIOChannel *channel;
7a2e45719bd0 [gaim-migrate @ 4777]
Nathan Walp <nwalp@pidgin.im>
parents: 4501
diff changeset
511 #endif
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
512
4753
7c1db830f57b [gaim-migrate @ 5070]
Mark Doliner <mark@kingant.net>
parents: 4502
diff changeset
513 gaim_set_blist(gaim_blist_new());
4501
5a2bc74c283a [gaim-migrate @ 4776]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
514 gaim_blist_load();
5a2bc74c283a [gaim-migrate @ 4776]
Nathan Walp <nwalp@pidgin.im>
parents: 4491
diff changeset
515
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
516 #ifndef _WIN32
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
517
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
518 UI_fd = open_socket();
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
519 if (UI_fd < 0)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
520 return 1;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
521
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
522 channel = g_io_channel_unix_new(UI_fd);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
523 g_io_add_watch(channel, G_IO_IN, socket_readable, NULL);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
524 g_io_channel_unref(channel);
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
525 #endif
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
526
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
527 /*
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
528 loop = g_main_new(TRUE);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
529 g_main_run(loop);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
530 */
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
531
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
532 return 0;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
533 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
534
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
535 void core_quit()
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
536 {
4082
4b04ecb3eb97 [gaim-migrate @ 4297]
Luke Schierer <lschiere@pidgin.im>
parents: 4073
diff changeset
537 /* don't save prefs after plugins are gone... */
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
538 #ifndef _WIN32
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
539 char buf[1024];
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
540 close(UI_fd);
5213
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
541 sprintf(buf, "%s" G_DIR_SEPARATOR_S "gaim_%s.%d",
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
542 g_get_tmp_dir(), g_get_user_name(), gaim_session);
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
543
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
544 unlink(buf);
5213
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
545
1cf4eb75e3ee [gaim-migrate @ 5583]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
546 gaim_debug(GAIM_DEBUG_MISC, "core", "Removed core\n");
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3533
diff changeset
547 #endif
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
548 }