plugins/gaim-remote/remote-socket.c

Tue, 21 Jun 2005 04:40:34 +0000

author
Sean Egan <seanegan@pidgin.im>
date
Tue, 21 Jun 2005 04:40:34 +0000
changeset 11016
9990e360ee9c
parent 10899
87d9aec5b72d
permissions
-rw-r--r--

[gaim-migrate @ 12885]
Wherever possible, allow users to act on objects and data directly, rather
than through dialogs or explicit commands. For example, it is more intuitive
to drag a circle object around in a diagram rather than selecting a "Move"
command from a menu while the circle is selected. Simlarly, in an email
application, allow the user to attach files by dragging them from the file
manager and dropping them onto the message composition window if they wish.
-- GNOME HIG

This allows direct manipulation of buddy aliases and group names, by moving
the features from dialogs to GtkTreeView's inline editing.

I think this is a great change, but it seems like the type of thing that
might stir up controversy. If so, take it to the mailing list for discussion.
If not, I'll go ahead and perfect this sometime later.

-s.

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

mercurial