annotate plugins/gaim-remote/remote-socket.c @ 7380:259210cf5dfa

[gaim-migrate @ 7975] if we're gonna put this back, we may as well do it right committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Thu, 30 Oct 2003 15:00:26 +0000
parents 5239a3b4ab33
children b4b9dabdd7c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5859
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1 /*
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
2 * gaim-remote
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
3 *
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
4 * Copyright (C) 2002, Sean Egan <bj91704@binghamton.edu>
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
5 *
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
9 * (at your option) any later version.
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
10 *
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14 * GNU General Public License for more details.
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
15 *
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
19 *
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
20 */
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
21
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
22 /* Somewhat inspired by XMMS:
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
23 * Copyright (C) 1998-2002 Peter Alm, Mikael Alm, Olle Hallnas,
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
24 * Thomas Nilsson and 4Front Technologies
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
25 * Copyright (C) 1999-2002 Haavard Kvaalen
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
26 */
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
27
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
28 /* This provides code for connecting to a Gaim socket and communicating with
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
29 * it. It will eventually be made a library once the core and ui are split. */
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
30
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5859
diff changeset
31 #include "internal.h"
5859
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
32 #include <sys/un.h>
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5859
diff changeset
33 #include <gaim-remote/remote.h>
6063
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 5872
diff changeset
34 #include <sys/types.h>
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 5872
diff changeset
35 #include <unistd.h>
5859
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
36
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
37 void
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
38 gaim_remote_session_send_packet(int fd, GaimRemotePacket *p)
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
39 {
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
40 int len = sizeof(p->type) + sizeof(p->subtype) +
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
41 sizeof(p->length) + p->length;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
42 char *pack = g_malloc(len);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
43 char *a = pack;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
44
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
45 memcpy (a, &(p->type), sizeof(p->type));
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
46 a = a + sizeof(p->type);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
47 memcpy (a, &(p->subtype), sizeof(p->subtype));
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
48 a = a + sizeof(p->subtype);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
49 memcpy (a, &(p->length), sizeof(p->length));
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
50 a = a + sizeof(p->length);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
51 memcpy (a, p->data, p->length);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
52 write(fd, pack, len);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
53 g_free(pack);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
54 }
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
55
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
56 void
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
57 gaim_remote_packet_append_string(GaimRemotePacket *p, char *str)
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
58 {
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
59 int len = p->length + strlen(str);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
60 char *k = g_malloc(len);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
61
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
62 memcpy(k, p->data, p->length);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
63 memcpy(k + p->length, str, strlen(str));
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
64
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
65 if (p->data)
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
66 g_free(p->data);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
67
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
68 p->data = k;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
69 p->length = len;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
70 }
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
71
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
72 void
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
73 gaim_remote_packet_append_char(GaimRemotePacket *p, char c)
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
74 {
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
75 int len = p->length + sizeof(char);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
76 char *k = g_malloc(len);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
77
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
78 memcpy(k, p->data, p->length);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
79 k[p->length] = c;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
80
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
81 if (p->data)
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
82 g_free(p->data);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
83
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
84 p->data = k;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
85 p->length = len;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
86 }
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
87
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
88 void
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
89 gaim_remote_packet_append_raw(GaimRemotePacket *p, char *str, int len)
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
90 {
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
91 int lent = p->length + len;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
92 char *k = g_malloc(lent);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
93
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
94 memcpy(k, p->data, p->length);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
95 memcpy(k + p->length, str, len);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
96
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
97 if (p->data)
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
98 g_free(p->data);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
99
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
100 p->data = k;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
101 p->length = lent;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
102 }
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
103
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
104 GaimRemotePacket *
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
105 gaim_remote_packet_new(guchar type, guchar subtype)
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
106 {
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
107 GaimRemotePacket *p = g_new0(GaimRemotePacket, 1);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
108 p->type = type;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
109 p->subtype = subtype;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
110 p->length = 0;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
111 p->data = NULL;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
112 return p;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
113 }
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
114
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
115 void
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
116 gaim_remote_packet_free(GaimRemotePacket *p)
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
117 {
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
118 if (p->data)
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
119 g_free(p->data);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
120 g_free(p);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
121 }
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
122
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
123 GaimRemotePacket *
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
124 gaim_remote_session_read_packet(int fd)
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
125 {
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
126 GaimRemotePacket *p = g_new0(GaimRemotePacket, 1);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
127 char *data = NULL;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
128
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
129 if (!(read(fd, &p->type, sizeof(p->type)))) {
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
130 g_free(p);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
131 return NULL;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
132 }
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
133
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
134 if (!(read(fd, &p->subtype, sizeof(p->subtype)))) {
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
135 g_free(p);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
136 return NULL;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
137 }
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
138
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
139 if (!(read(fd, &p->length, sizeof(p->length)))) {
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
140 g_free(p);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
141 return NULL;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
142 }
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
143
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
144 if (p->length) {
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
145 data = g_malloc(p->length);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
146
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
147 if (!(read(fd, data, p->length))) {
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
148 g_free(p);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
149 return NULL;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
150 }
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
151 }
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
152
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
153 p->data = data;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
154
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
155 return p;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
156 }
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
157
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
158 /* copied directly from xmms_connect_to_session */
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
159 int
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
160 gaim_remote_session_connect(int session)
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
161 {
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
162 gint fd;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
163 uid_t stored_uid, euid;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
164 struct sockaddr_un saddr;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
165
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
166 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1)
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
167 {
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
168 saddr.sun_family = AF_UNIX;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
169 stored_uid = getuid();
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
170 euid = geteuid();
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
171 setuid(euid);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
172 sprintf(saddr.sun_path, "%s/gaim_%s.%d",
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
173 g_get_tmp_dir(), g_get_user_name(), session);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
174 setreuid(stored_uid, euid);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
175
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
176 if (connect(fd, (struct sockaddr *) &saddr, sizeof (saddr)) != -1)
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
177 return fd;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
178 }
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
179
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
180 close(fd);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
181
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
182 return -1;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
183 }
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
184
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
185 gboolean
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
186 gaim_remote_session_exists(int sess)
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
187 {
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
188 GaimRemotePacket *pack = NULL;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
189 int fd = gaim_remote_session_connect(sess);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
190
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
191 if (fd > 0) {
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
192 pack = gaim_remote_packet_new(CUI_TYPE_META, CUI_META_PING);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
193 gaim_remote_session_send_packet(fd, pack);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
194 gaim_remote_packet_free(pack);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
195 close(fd);
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
196
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
197 return TRUE;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
198 }
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
199
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
200 return FALSE;
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
201 }
022786c7ab53 [gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
202