annotate src/core.c @ 2438:5cbe86a444d9

[gaim-migrate @ 2451] more updates to core. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sat, 06 Oct 2001 00:10:29 +0000
parents b4f2a53c0ee5
children 932adc1ac9ed
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>
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 #include <sys/socket.h>
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31 #include <sys/stat.h>
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32 #include <sys/un.h>
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 #include <unistd.h>
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 #include <errno.h>
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 #include <signal.h>
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 #include <getopt.h>
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 #include "gaim.h"
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 static gint UI_fd = -1;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 struct UI {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 GIOChannel *channel;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43 guint inpa;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 };
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 GSList *uis = NULL;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46
2435
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
47 gint UI_write(struct UI *ui, guchar *data, gint len)
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
48 {
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
49 guchar *send = g_new0(guchar, len + 6);
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
50 gint sent;
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
51 send[0] = 'f';
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
52 send[1] = 1;
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
53 memcpy(send + 2, &len, sizeof(len));
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
54 memcpy(send + 6, data, len);
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
55 /* we'll let the write silently fail because the read will pick it up as dead */
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
56 g_io_channel_write(ui->channel, send, len + 6, &sent);
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
57 return sent;
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
58 }
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
59
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
60 void UI_broadcast(guchar *data, gint len)
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
61 {
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
62 GSList *u = uis;
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
63 while (u) {
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
64 struct UI *ui = u->data;
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
65 UI_write(ui, data, len);
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
66 u = u->next;
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
67 }
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
68 }
b4f2a53c0ee5 [gaim-migrate @ 2448]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2430
diff changeset
69
2438
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
70 static gint gaim_recv(GIOChannel *source, void *buf, gint len)
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71 {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 gint total = 0;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73 gint cur;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 while (total < len) {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 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
77 return -1;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 if (cur == 0)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 return total;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 total += cur;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83 return total;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 static gboolean UI_readable(GIOChannel *source, GIOCondition cond, gpointer data)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87 {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 struct UI *ui = data;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89
2438
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
90 guchar type;
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
91 guchar subtype;
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
92 guint32 len;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 guchar *in;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
95
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
96 /* 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
97 if (gaim_recv(source, &type, sizeof(type)) != sizeof(type)) {
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98 debug_printf("UI has abandoned us!\n");
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99 uis = g_slist_remove(uis, ui);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 g_io_channel_close(ui->channel);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101 g_source_remove(ui->inpa);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 g_free(ui);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103 return FALSE;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105
2438
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
106 if (gaim_recv(source, &subtype, sizeof(subtype)) != sizeof(subtype)) {
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
107 debug_printf("UI has abandoned us!\n");
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
108 uis = g_slist_remove(uis, ui);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
109 g_io_channel_close(ui->channel);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
110 g_source_remove(ui->inpa);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
111 g_free(ui);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
112 return FALSE;
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
113 }
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
114
2438
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
115 if (gaim_recv(source, &len, sizeof(len)) != sizeof(len)) {
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
116 debug_printf("UI has abandoned us!\n");
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
117 uis = g_slist_remove(uis, ui);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
118 g_io_channel_close(ui->channel);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
119 g_source_remove(ui->inpa);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
120 g_free(ui);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
121 return FALSE;
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
122 }
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
123
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
124 in = g_new0(guchar, len);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
125 if (gaim_recv(source, in, len) != len) {
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
126 debug_printf("UI has abandoned us!\n");
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
127 uis = g_slist_remove(uis, ui);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
128 g_io_channel_close(ui->channel);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
129 g_source_remove(ui->inpa);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
130 g_free(ui);
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
131 return FALSE;
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
132 }
5cbe86a444d9 [gaim-migrate @ 2451]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2435
diff changeset
133
2416
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 switch (type) {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135 /*
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136 case CUI_TYPE_META:
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137 meta_handler(ui, in);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138 break;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
139 case CUI_TYPE_PLUGIN:
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
140 plugin_handler(ui, in);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
141 break;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
142 case CUI_TYPE_USER:
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143 user_handler(ui, in);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
144 break;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
145 case CUI_TYPE_CONN:
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
146 conn_handler(ui, in);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
147 break;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
148 case CUI_TYPE_BUDDY:
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
149 buddy_handler(ui, in);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
150 break;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
151 case CUI_TYPE_MESSAGE:
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
152 message_handler(ui, in);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
153 break;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
154 case CUI_TYPE_CHAT:
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
155 chat_handler(ui, in);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
156 break;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
157 */
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158 default:
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159 debug_printf("unhandled type %d\n", type);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 break;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163 g_free(in);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164 return TRUE;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
165 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
166
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167 static gboolean socket_readable(GIOChannel *source, GIOCondition cond, gpointer data)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168 {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
169 struct sockaddr_un saddr;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
170 gint len;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
171 gint fd;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
172
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
173 struct UI *ui;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
174
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
175 if ((fd = accept(UI_fd, (struct sockaddr *)&saddr, &len)) == -1)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
176 return FALSE;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
177
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
178 ui = g_new0(struct UI, 1);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
179 uis = g_slist_append(uis, ui);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
180
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
181 ui->channel = g_io_channel_unix_new(fd);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
182 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
183 g_io_channel_unref(ui->channel);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
184
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
185 debug_printf("got one\n");
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
186 return TRUE;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
187 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
188
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
189 static gint open_socket()
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
190 {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
191 struct sockaddr_un saddr;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
192 gint fd;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
193
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
194 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
195 umask(0177);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
196 saddr.sun_family = AF_UNIX;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
197 g_snprintf(saddr.sun_path, 108, "%s/gaim_%s.%d",
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
198 g_get_tmp_dir(), g_get_user_name(), getpid());
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
199 if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) != -1)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
200 listen(fd, 100);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
201 else
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
202 g_log(NULL, G_LOG_LEVEL_CRITICAL,
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
203 "Failed to assign %s to a socket (Error: %s)",
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
204 saddr.sun_path, strerror(errno));
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
205 } else
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
206 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
207 return fd;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
208 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
209
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
210 int core_main()
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
211 {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
212 /*
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
213 GMainLoop *loop;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
214 */
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
215
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
216 GIOChannel *channel;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
217
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
218 UI_fd = open_socket();
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
219 if (UI_fd < 0)
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
220 return 1;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
221
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
222 channel = g_io_channel_unix_new(UI_fd);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
223 g_io_add_watch(channel, G_IO_IN, socket_readable, NULL);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
224 g_io_channel_unref(channel);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
225
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
226 /*
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
227 loop = g_main_new(TRUE);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
228 g_main_run(loop);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
229 */
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
230
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
231 return 0;
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
232 }
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
233
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
234 void core_quit()
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
235 {
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
236 char buf[1024];
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
237 close(UI_fd);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
238 sprintf(buf, "%s/gaim_%s.%d", g_get_tmp_dir(), g_get_user_name(), getpid());
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
239 unlink(buf);
61b816a7b467 [gaim-migrate @ 2429]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
240 }