annotate src/socket.c @ 8986:8cf32769ba1b

[gaim-migrate @ 9761] " This patch adds a Plugin Actions menu item after the Account Actions menu. The Plugin Actions menu is populated from the added 'actions' slot in GaimPluginInfo. As a demonstration, the Idle Maker plugin has been converted to no longer require GTK code and the Preferences interface just to perform its actions. Instead, it uses a Plugin Action to spawn a Fields Request. There's also a minor fix for consistency in the menu building for buddy actions. The pre-existing method for instructing a menu list to display a separator was to insert a NULL rather than a proto_buddy_menu into the GList of actions. The code for the buddy menus was instead checking for a proto_buddy_menu with a '-' label. This has been fixed, and it now correctly uses NULL to indicate a separator." "Date: 2004-05-16 02:25 Sender: taliesein Logged In: YES user_id=77326 I need to add a callback to this patch to watch for loading/unloading of plugins (to determine when to rebuild the menu). Since the appropriate way to handle Plugin Actions is still mildly up for debate, I'm holding of on correcting the patch until I know for sure whether I should fix this patch, or scrap it and write a new one using a different method." "Date: 2004-05-18 12:26 Sender: taliesein Logged In: YES user_id=77326 I've completed changes to this patch to also add plugin load and unload signals (it looks like plugin.c actually had pre-signal callbacks in place, but they were never used or converted to signals) This patch now will correctly update the Plugin Action menu as plugins load and unload." I'm not entirely sure i like the ui of a plugins actions menu, but i think that having some way for plugins to add actions on an account is a good thing, and i'm not sure that every viable action fits under the accounts actions menu. we may want to merge the two (the existing accounts actions and this plugins actions), but both times it came up in #gaim no one seemed to want to comment, and on one commented to the gaim-devel post either. committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Thu, 20 May 2004 05:11:44 +0000
parents fa6395637e2c
children 61852117568f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /*
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * gaim-remote
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 *
8046
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
4 * Gaim is the legal property of its developers, whose names are too numerous
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
6 * source distribution.
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 *
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 * (at your option) any later version.
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 *
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 * GNU General Public License for more details.
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 *
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 *
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 */
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23
8046
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 3867
diff changeset
24 /* Somewhat inspired by XMMS*/
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 /* This provides code for connecting to a Gaim socket and communicating with
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 * it. It will eventually be made a library once the core and ui are split. */
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28
3499
bb49f0c4f7cd [gaim-migrate @ 3562]
Sean Egan <seanegan@gmail.com>
parents: 3478
diff changeset
29 #include <sys/types.h>
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 #include <sys/socket.h>
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 #include <sys/un.h>
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3499
diff changeset
32 #include <unistd.h>
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 #include "gaim.h"
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 #include "gaim-socket.h"
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 void cui_send_packet (int fd, struct gaim_cui_packet *p) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 int len = sizeof(p->type) + sizeof(p->subtype) + sizeof(p->length) + p->length;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 char *pack = g_malloc(len);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 char *a = pack;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 memcpy (a, &(p->type), sizeof(p->type));
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 a = a + sizeof(p->type);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 memcpy (a, &(p->subtype), sizeof(p->subtype));
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43 a = a + sizeof(p->subtype);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 memcpy (a, &(p->length), sizeof(p->length));
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 a = a + sizeof(p->length);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46 memcpy (a, p->data, p->length);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 write(fd, pack, len);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 g_free(pack);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52 void cui_packet_append_string(struct gaim_cui_packet *p, char *str) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 int len = p->length + strlen(str);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 char *k = g_malloc(len);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 memcpy(k, p->data, p->length);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 memcpy(k + p->length, str, strlen(str));
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 if (p->data)
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 g_free(p->data);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 p->data = k;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 p->length = len;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 void cui_packet_append_char(struct gaim_cui_packet *p, char c) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 int len = p->length + sizeof(char);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 char *k = g_malloc(len);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 memcpy(k, p->data, p->length);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 k[p->length] = c;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 if (p->data)
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 g_free(p->data);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 p->data = k;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 p->length = len;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 void cui_packet_append_raw(struct gaim_cui_packet *p, char *str, int len) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 int lent = p->length + len;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76 char *k = g_malloc(lent);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 memcpy(k, p->data, p->length);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 memcpy(k + p->length, str, len);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79 if (p->data)
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 g_free(p->data);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 p->data = k;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82 p->length = lent;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 struct gaim_cui_packet *cui_packet_new(guchar type, guchar subtype) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86 struct gaim_cui_packet *p = g_new0(struct gaim_cui_packet, 1);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87 p->type = type;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88 p->subtype = subtype;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89 p->length = 0;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 p->data = NULL;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91 return p;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94 void cui_packet_free(struct gaim_cui_packet *p) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95 if (p->data)
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96 g_free(p->data);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97 g_free(p);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100 struct gaim_cui_packet *cui_read_packet(int fd) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101 struct gaim_cui_packet *p = g_new0(struct gaim_cui_packet, 1);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102 char *data = NULL;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3499
diff changeset
104 if (!(read(fd, &p->type, sizeof(p->type)))) {
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 g_free(p);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106 return NULL;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3499
diff changeset
110 if (!(read(fd, &p->subtype, sizeof(p->subtype)))) {
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 g_free(p);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 return NULL;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3499
diff changeset
116 if (!(read(fd, &p->length, sizeof(p->length)))) {
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 g_free(p);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118 return NULL;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 if (p->length) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122 data = g_malloc(p->length);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 if (!(read(fd, data, p->length))) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 g_free(p);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 return NULL;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 p->data = data;
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3499
diff changeset
129 return p;
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 /* copied directly from xmms_connect_to_session */
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133 gint gaim_connect_to_session(gint session)
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 gint fd;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 uid_t stored_uid, euid;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 struct sockaddr_un saddr;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1)
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 saddr.sun_family = AF_UNIX;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142 stored_uid = getuid();
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 euid = geteuid();
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 setuid(euid);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145 sprintf(saddr.sun_path, "%s/gaim_%s.%d", g_get_tmp_dir(), g_get_user_name(), session);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 setreuid(stored_uid, euid);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147 if (connect(fd, (struct sockaddr *) &saddr, sizeof (saddr)) != -1)
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148 return fd;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150 close(fd);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 return -1;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 gboolean gaim_session_exists(int sess)
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155 {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156 struct gaim_cui_packet *pack = NULL;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 int fd = gaim_connect_to_session(sess);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 if (fd > 0) {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160 pack = cui_packet_new(CUI_TYPE_META, CUI_META_PING);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161 cui_send_packet(fd, pack);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162 cui_packet_free(pack);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163 close(fd);
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164 } else {
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165 return FALSE;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167 return TRUE;
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168 }
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
169