annotate src/session.c @ 8273:f24172f53650

[gaim-migrate @ 8997] This is Scott Lamb's eventloop abstraction patch. If it breaks things, Scott Lamb will be glad to take the punishment. If it doesn't, it should make integration into other event loops easier. Well, no, not easier, harder actually, but it'll be done more appropriately and less hackily.. er, hacky. Is hackily a word? committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 17 Feb 2004 02:17:48 +0000
parents fa6395637e2c
children 084ed9f7ac19
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1 /*
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
2 * session management for Gaim
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
3 *
8046
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 6485
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: 6485
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: 6485
diff changeset
6 * source distribution.
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 *
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 * (at your option) any later version.
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
12 *
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 * GNU General Public License for more details.
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 *
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21 *
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
22 */
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5593
diff changeset
23 #include "internal.h"
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
24
6245
9083f92e0d58 [gaim-migrate @ 6739]
Nathan Walp <nwalp@pidgin.im>
parents: 6179
diff changeset
25 #include "core.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5593
diff changeset
26 #include "debug.h"
8273
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8046
diff changeset
27 #include "eventloop.h"
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
28
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5593
diff changeset
29 extern char *opt_rcfile_arg;
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
30
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
31 #ifdef USE_SM
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
32
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
33 #include <X11/ICE/ICElib.h>
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
34 #include <X11/SM/SMlib.h>
6485
70d5122bc3ff [gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents: 6245
diff changeset
35 #include <gdk/gdkx.h>
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
36 #include <unistd.h>
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
37 #include <fcntl.h>
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5593
diff changeset
38
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
39 #define ERROR_LENGTH 512
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
40
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
41 static IceIOErrorHandler ice_installed_io_error_handler;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
42 static SmcConn session = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
43 static gchar *myself = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
44 static gboolean had_first_save = FALSE;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
45 gboolean session_managed = FALSE;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
46
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
47 /* ICE belt'n'braces stuff */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
48
8273
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8046
diff changeset
49 static void ice_process_messages(gpointer data, gint fd,
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8046
diff changeset
50 GaimInputCondition condition) {
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
51 IceConn connection = (IceConn)data;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
52 IceProcessMessagesStatus status;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
53
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
54 /* please don't block... please! */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
55 status = IceProcessMessages(connection, NULL, NULL);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
56
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
57 if (status == IceProcessMessagesIOError) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
58 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
59 "ICE IO error, closing connection... ");
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
60
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
61 /* IO error, please disconnect */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
62 IceSetShutdownNegotiation(connection, False);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
63 IceCloseConnection(connection);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
64
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
65 gaim_debug(GAIM_DEBUG_INFO, NULL, "done.\n");
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
66
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
67 /* cancel the handler */
8273
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8046
diff changeset
68 gaim_input_remove(IceConnectionNumber(connection));
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
69 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
70 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
71
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
72 static void ice_connection_watch(IceConn connection, IcePointer client_data,
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
73 Bool opening, IcePointer *watch_data) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
74 if (opening) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
75 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
76 "Handling new ICE connection... ");
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
77
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
78 /* ensure ICE connection is not passed to child processes */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
79 fcntl(IceConnectionNumber(connection), F_SETFD, FD_CLOEXEC);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
80
8273
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8046
diff changeset
81 /* watch the connection */
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8046
diff changeset
82 gaim_input_add(IceConnectionNumber(connection), GAIM_INPUT_READ,
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8046
diff changeset
83 ice_process_messages, connection);
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
84 } else {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
85 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
86 "Handling closed ICE connection... ");
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
87
8273
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8046
diff changeset
88 /* stop watching it */
f24172f53650 [gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents: 8046
diff changeset
89 gaim_input_remove(IceConnectionNumber(connection));
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
90 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
91
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
92 gaim_debug(GAIM_DEBUG_INFO, NULL, "done.\n");
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
93 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
94
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
95 /* We call any handler installed before (or after) ice_init but
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
96 * avoid calling the default libICE handler which does an exit().
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
97 *
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
98 * This means we do nothing by default, which is probably correct,
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
99 * the connection will get closed by libICE
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
100 */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
101
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
102 static void ice_io_error_handler(IceConn connection) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
103 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
104 "Handling ICE IO error... ");
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
105
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
106 if (ice_installed_io_error_handler)
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
107 (*ice_installed_io_error_handler)(connection);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
108
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
109 gaim_debug(GAIM_DEBUG_INFO, NULL, "done.\n");
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
110 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
111
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
112 static void ice_init() {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
113 IceIOErrorHandler default_handler;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
114
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
115 ice_installed_io_error_handler = IceSetIOErrorHandler(NULL);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
116 default_handler = IceSetIOErrorHandler(ice_io_error_handler);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
117
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
118 if (ice_installed_io_error_handler == default_handler)
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
119 ice_installed_io_error_handler = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
120
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
121 IceAddConnectionWatch(ice_connection_watch, NULL);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
122
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
123 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
124 "ICE initialized.\n");
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
125 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
126
4281
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
127 /* my magic utility function */
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
128
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
129 static gchar **session_make_command(gchar *client_id) {
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
130 gint i = 2;
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
131 gint j = 0;
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
132 gchar **ret;
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
133
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
134 if (client_id) i += 2;
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
135 if (opt_rcfile_arg) i += 2;
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
136
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
137 ret = g_new(gchar *, i);
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
138 ret[j++] = g_strdup(myself);
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
139
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
140 if (client_id) {
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
141 ret[j++] = g_strdup("--session");
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
142 ret[j++] = g_strdup(client_id);
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
143 }
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
144
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
145 if (opt_rcfile_arg) {
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
146 ret[j++] = g_strdup("--file");
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
147 ret[j++] = g_strdup(opt_rcfile_arg);
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
148 }
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
149
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
150 ret[j++] = NULL;
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
151
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
152 return ret;
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
153 }
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
154
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
155 /* SM callback handlers */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
156
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
157 void session_save_yourself(SmcConn conn, SmPointer data, int save_type,
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
158 Bool shutdown, int interact_style, Bool fast) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
159 if (had_first_save == FALSE && save_type == SmSaveLocal &&
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
160 interact_style == SmInteractStyleNone && !shutdown &&
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
161 !fast) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
162 /* this is just a dry run, spit it back */
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
163 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
164 "Received first save_yourself\n");
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
165 SmcSaveYourselfDone(conn, True);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
166 had_first_save = TRUE;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
167 return;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
168 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
169
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
170 /* tum ti tum... don't add anything else here without *
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
171 * reading SMlib.PS from an X.org ftp server near you */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
172
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
173 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
174 "Received save_yourself\n");
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
175
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
176 if (save_type == SmSaveGlobal || save_type == SmSaveBoth) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
177 /* may as well do something ... */
5593
b07aa997ddd8 [gaim-migrate @ 5997]
Christian Hammond <chipx86@chipx86.com>
parents: 5211
diff changeset
178 /* or not -- save_prefs(); */
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
179 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
180
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
181 SmcSaveYourselfDone(conn, True);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
182 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
183
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
184 void session_die(SmcConn conn, SmPointer data) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
185 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
186 "Received die\n");
6179
16e384bb7fbf [gaim-migrate @ 6664]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
187 gaim_core_quit();
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
188 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
189
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
190 void session_save_complete(SmcConn conn, SmPointer data) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
191 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
192 "Received save_complete\n");
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
193 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
194
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
195 void session_shutdown_cancelled(SmcConn conn, SmPointer data) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
196 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
197 "Received shutdown_cancelled\n");
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
198 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
199
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
200 /* utility functions stolen from Gnome-client */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
201
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
202 static void session_set_value(SmcConn conn, gchar *name, char *type,
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
203 int num_vals, SmPropValue *vals) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
204 SmProp *proplist[1];
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
205 SmProp prop;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
206
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
207 g_return_if_fail(conn);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
208
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
209 prop.name = name;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
210 prop.type = type;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
211 prop.num_vals = num_vals;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
212 prop.vals = vals;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
213
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
214 proplist[0] = &prop;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
215 SmcSetProperties(conn, 1, proplist);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
216 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
217
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
218 static void session_set_string(SmcConn conn, gchar *name, gchar *value) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
219 SmPropValue val;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
220
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
221 g_return_if_fail(name);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
222
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
223 val.length = strlen (value)+1;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
224 val.value = value;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
225
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
226 session_set_value(conn, name, SmARRAY8, 1, &val);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
227 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
228
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
229 static void session_set_gchar(SmcConn conn, gchar *name, gchar value) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
230 SmPropValue val;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
231
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
232 g_return_if_fail(name);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
233
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
234 val.length = 1;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
235 val.value = &value;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
236
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
237 session_set_value(conn, name, SmCARD8, 1, &val);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
238 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
239
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
240 static void session_set_array(SmcConn conn, gchar *name, gchar *array[]) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
241 gint argc;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
242 gchar **ptr;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
243 gint i;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
244
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
245 SmPropValue *vals;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
246
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
247 g_return_if_fail (name);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
248
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
249 /* We count the number of elements in our array. */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
250 for (ptr = array, argc = 0; *ptr ; ptr++, argc++) /* LOOP */;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
251
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
252 /* Now initialize the 'vals' array. */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
253 vals = g_new (SmPropValue, argc);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
254 for (ptr = array, i = 0 ; i < argc ; ptr++, i++) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
255 vals[i].length = strlen (*ptr);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
256 vals[i].value = *ptr;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
257 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
258
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
259 session_set_value(conn, name, SmLISTofARRAY8, argc, vals);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
260
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
261 g_free (vals);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
262 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
263
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
264 #endif /* USE_SM */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
265
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
266 /* setup functions */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
267
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
268 void session_init(gchar *argv0, gchar *previous_id) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
269 #ifdef USE_SM
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
270 SmcCallbacks callbacks;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
271 gchar *client_id = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
272 gchar error[ERROR_LENGTH] = "";
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
273 gchar *tmp = NULL;
4281
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
274 gchar **cmd = NULL;
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
275
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
276 if (session != NULL) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
277 /* session is already established, what the hell is going on? */
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
278 gaim_debug(GAIM_DEBUG_WARNING, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
279 "Duplicated call to session_init!\n");
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
280 return;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
281 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
282
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
283 if (g_getenv("SESSION_MANAGER") == NULL) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
284 gaim_debug(GAIM_DEBUG_ERROR, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
285 "No SESSION_MANAGER found, aborting.\n");
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
286 return;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
287 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
288
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
289 ice_init();
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
290
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
291 callbacks.save_yourself.callback = session_save_yourself;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
292 callbacks.die.callback = session_die;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
293 callbacks.save_complete.callback = session_save_complete;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
294 callbacks.shutdown_cancelled.callback = session_shutdown_cancelled;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
295
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
296 callbacks.save_yourself.client_data = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
297 callbacks.die.client_data = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
298 callbacks.save_complete.client_data = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
299 callbacks.shutdown_cancelled.client_data = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
300
4544
96a2a6c9affc [gaim-migrate @ 4823]
Luke Schierer <lschiere@pidgin.im>
parents: 4281
diff changeset
301 if (previous_id) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
302 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
303 "Connecting with previous ID %s\n", previous_id);
4544
96a2a6c9affc [gaim-migrate @ 4823]
Luke Schierer <lschiere@pidgin.im>
parents: 4281
diff changeset
304 } else {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
305 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
306 "Connecting with no previous ID\n");
4544
96a2a6c9affc [gaim-migrate @ 4823]
Luke Schierer <lschiere@pidgin.im>
parents: 4281
diff changeset
307 }
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
308
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
309 session = SmcOpenConnection(NULL, "session", SmProtoMajor, SmProtoMinor, SmcSaveYourselfProcMask |
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
310 SmcDieProcMask | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask,
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
311 &callbacks, previous_id, &client_id, ERROR_LENGTH, error);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
312
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
313 if (session == NULL) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
314 if (error[0] != '\0') {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
315 gaim_debug(GAIM_DEBUG_ERROR, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
316 "Connection failed with error: %s\n", error);
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
317 } else {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
318 gaim_debug(GAIM_DEBUG_ERROR, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
319 "Connetion failed with unknown error.\n");
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
320 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
321 return;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
322 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
323
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
324 tmp = SmcVendor(session);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
325 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
326 "Connected to manager (%s) with client ID %s\n",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
327 tmp, client_id);
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
328 g_free(tmp);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
329
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
330 session_managed = TRUE;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
331 gdk_set_sm_client_id(client_id);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
332
4265
65a859488240 [gaim-migrate @ 4516]
Sean Egan <seanegan@gmail.com>
parents: 4210
diff changeset
333 tmp = g_get_current_dir();
65a859488240 [gaim-migrate @ 4516]
Sean Egan <seanegan@gmail.com>
parents: 4210
diff changeset
334 session_set_string(session, SmCurrentDirectory, tmp);
65a859488240 [gaim-migrate @ 4516]
Sean Egan <seanegan@gmail.com>
parents: 4210
diff changeset
335 g_free(tmp);
65a859488240 [gaim-migrate @ 4516]
Sean Egan <seanegan@gmail.com>
parents: 4210
diff changeset
336
4210
e11393a176d5 [gaim-migrate @ 4447]
Luke Schierer <lschiere@pidgin.im>
parents: 4158
diff changeset
337 tmp = g_strdup_printf("%d", (int) getpid());
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
338 session_set_string(session, SmProcessID, tmp);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
339 g_free(tmp);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
340
4210
e11393a176d5 [gaim-migrate @ 4447]
Luke Schierer <lschiere@pidgin.im>
parents: 4158
diff changeset
341 tmp = g_strdup(g_get_user_name());
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
342 session_set_string(session, SmUserID, tmp);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
343 g_free(tmp);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
344
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
345 session_set_gchar(session, SmRestartStyleHint, (gchar) SmRestartIfRunning);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
346 session_set_string(session, SmProgram, g_get_prgname());
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
347
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
348 myself = g_strdup(argv0);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
349 gaim_debug(GAIM_DEBUG_MISC, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
350 "Using %s as command\n", myself);
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
351
4281
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
352 cmd = session_make_command(NULL);
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
353 session_set_array(session, SmCloneCommand, cmd);
4281
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
354 g_strfreev(cmd);
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
355
4265
65a859488240 [gaim-migrate @ 4516]
Sean Egan <seanegan@gmail.com>
parents: 4210
diff changeset
356 /* this is currently useless, but gnome-session warns 'the following applications will not
65a859488240 [gaim-migrate @ 4516]
Sean Egan <seanegan@gmail.com>
parents: 4210
diff changeset
357 save their current status' bla bla if we don't have it and the user checks 'Save Session'
65a859488240 [gaim-migrate @ 4516]
Sean Egan <seanegan@gmail.com>
parents: 4210
diff changeset
358 when they log out */
4281
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
359 cmd = g_new(gchar *, 2);
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
360 cmd[0] = g_strdup("/bin/true");
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
361 cmd[1] = NULL;
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
362 session_set_array(session, SmDiscardCommand, cmd);
4281
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
363 g_strfreev(cmd);
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
364
4281
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
365 cmd = session_make_command(client_id);
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
366 session_set_array(session, SmRestartCommand, cmd);
4281
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
367 g_strfreev(cmd);
d956ac6157cd [gaim-migrate @ 4532]
Luke Schierer <lschiere@pidgin.im>
parents: 4265
diff changeset
368
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
369 g_free(client_id);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
370 #endif /* USE_SM */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
371 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
372
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
373 void session_end() {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
374 #ifdef USE_SM
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
375 if (session == NULL) /* no session to close */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
376 return;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
377
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
378 SmcCloseConnection(session, 0, NULL);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
379
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
380 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 4544
diff changeset
381 "Connection closed.\n");
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
382 #endif /* USE_SM */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
383 }