annotate src/session.c @ 4258:2bf6afa2408b

[gaim-migrate @ 4509] these are a good thing committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Wed, 08 Jan 2003 21:43:51 +0000
parents e11393a176d5
children 65a859488240
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 *
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
4 * Copyright (C) 2002, Robert McQueen <robot101@debian.org> but
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 * much code shamelessly cribbed from GsmClient (C) 2001 Havoc
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6 * Pennington, which is in turn inspired by various other pieces
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 * of code including GnomeClient (C) 1998 Carsten Schaar, Tom
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8 * Tromey, and twm session code (C) 1998 The Open Group.
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 *
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 * 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
12 * the Free Software Foundation; either version 2 of the License, or
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 * (at your option) any later version.
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 *
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 * GNU General Public License for more details.
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 *
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
23 *
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
24 */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
25
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
26 #ifdef HAVE_CONFIG_H
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
27 #include <config.h>
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
28 #endif
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
29
4210
e11393a176d5 [gaim-migrate @ 4447]
Luke Schierer <lschiere@pidgin.im>
parents: 4158
diff changeset
30 #include <string.h>
e11393a176d5 [gaim-migrate @ 4447]
Luke Schierer <lschiere@pidgin.im>
parents: 4158
diff changeset
31
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
32 #include "gaim.h"
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
33
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
34 #ifdef USE_SM
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
35
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
36 #include <X11/ICE/ICElib.h>
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
37 #include <X11/SM/SMlib.h>
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
38 #include <unistd.h>
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
39 #include <fcntl.h>
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
40 #define ERROR_LENGTH 512
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
41
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
42 static IceIOErrorHandler ice_installed_io_error_handler;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
43 static SmcConn session = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
44 static gchar *myself = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
45 static gboolean had_first_save = FALSE;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
46 gboolean session_managed = FALSE;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
47
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
48 /* ICE belt'n'braces stuff */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
49
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
50 static gboolean ice_process_messages(GIOChannel *channel, GIOCondition condition,
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
51 gpointer data) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
52 IceConn connection = (IceConn)data;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
53 IceProcessMessagesStatus status;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
54
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
55 /* please don't block... please! */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
56 status = IceProcessMessages(connection, NULL, NULL);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
57
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
58 if (status == IceProcessMessagesIOError) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
59 debug_printf("Session Management: ICE IO error, closing connection... ");
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
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
65 debug_printf("done\n");
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 */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
68 return FALSE;
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 /* live to see another day */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
72 return TRUE;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
73 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
74
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
75 static void ice_connection_watch(IceConn connection, IcePointer client_data,
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
76 Bool opening, IcePointer *watch_data) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
77 guint input_id;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
78
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
79 if (opening) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
80 GIOChannel *channel;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
81
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
82 debug_printf("Session Management: handling new ICE connection... ");
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
83
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
84 /* ensure ICE connection is not passed to child processes */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
85 fcntl(IceConnectionNumber(connection), F_SETFD, FD_CLOEXEC);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
86
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
87 /* get glib to watch the connection for us */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
88 channel = g_io_channel_unix_new(IceConnectionNumber(connection));
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
89 input_id = g_io_add_watch(channel, G_IO_IN | G_IO_ERR,
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
90 ice_process_messages, connection);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
91 g_io_channel_unref(channel);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
92
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
93 /* store the input ID as a pointer for when it closes */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
94 *watch_data = (IcePointer)GUINT_TO_POINTER(input_id);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
95 } else {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
96 debug_printf("Session Management: handling closed ICE connection... ");
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 /* get the input ID back and stop watching it */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
99 input_id = GPOINTER_TO_UINT((gpointer) *watch_data);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
100 g_source_remove(input_id);
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
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
103 debug_printf("done\n");
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
104 }
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 /* We call any handler installed before (or after) ice_init but
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
107 * avoid calling the default libICE handler which does an exit().
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
108 *
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
109 * This means we do nothing by default, which is probably correct,
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
110 * the connection will get closed by libICE
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
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
113 static void ice_io_error_handler(IceConn connection) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
114 debug_printf("Session Management: handling ICE IO error... ");
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
115
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
116 if (ice_installed_io_error_handler)
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
117 (*ice_installed_io_error_handler)(connection);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
118
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
119 debug_printf("done\n");
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
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
122 static void ice_init() {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
123 IceIOErrorHandler default_handler;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
124
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
125 ice_installed_io_error_handler = IceSetIOErrorHandler(NULL);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
126 default_handler = IceSetIOErrorHandler(ice_io_error_handler);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
127
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
128 if (ice_installed_io_error_handler == default_handler)
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
129 ice_installed_io_error_handler = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
130
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
131 IceAddConnectionWatch(ice_connection_watch, NULL);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
132
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
133 debug_printf("Session Management: ICE initialised\n");
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
134 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
135
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
136 /* SM callback handlers */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
137
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
138 void session_save_yourself(SmcConn conn, SmPointer data, int save_type,
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
139 Bool shutdown, int interact_style, Bool fast) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
140 if (had_first_save == FALSE && save_type == SmSaveLocal &&
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
141 interact_style == SmInteractStyleNone && !shutdown &&
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
142 !fast) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
143 /* this is just a dry run, spit it back */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
144 debug_printf("Session Management: received first save_yourself\n");
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
145 SmcSaveYourselfDone(conn, True);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
146 had_first_save = TRUE;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
147 return;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
148 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
149
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
150 /* tum ti tum... don't add anything else here without *
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
151 * reading SMlib.PS from an X.org ftp server near you */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
152
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
153 debug_printf("Session Management: received save_yourself\n");
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
154
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
155 if (save_type == SmSaveGlobal || save_type == SmSaveBoth) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
156 /* may as well do something ... */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
157 save_prefs();
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
158 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
159
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
160 SmcSaveYourselfDone(conn, True);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
161 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
162
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
163 void session_die(SmcConn conn, SmPointer data) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
164 debug_printf("Session Management: received die\n");
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
165 do_quit();
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
166 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
167
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
168 void session_save_complete(SmcConn conn, SmPointer data) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
169 debug_printf("Session Management: received save_complete\n");
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
170 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
171
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
172 void session_shutdown_cancelled(SmcConn conn, SmPointer data) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
173 debug_printf("Session Management: received shutdown_cancelled\n");
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
174 }
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 /* utility functions stolen from Gnome-client */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
177
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
178 static void session_set_value(SmcConn conn, gchar *name, char *type,
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
179 int num_vals, SmPropValue *vals) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
180 SmProp *proplist[1];
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
181 SmProp prop;
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 g_return_if_fail(conn);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
184
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
185 prop.name = name;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
186 prop.type = type;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
187 prop.num_vals = num_vals;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
188 prop.vals = vals;
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 proplist[0] = &prop;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
191 SmcSetProperties(conn, 1, proplist);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
192 }
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 static void session_set_string(SmcConn conn, gchar *name, gchar *value) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
195 SmPropValue val;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
196
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
197 g_return_if_fail(name);
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 val.length = strlen (value)+1;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
200 val.value = value;
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 session_set_value(conn, name, SmARRAY8, 1, &val);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
203 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
204
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
205 static void session_set_gchar(SmcConn conn, gchar *name, gchar value) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
206 SmPropValue val;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
207
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
208 g_return_if_fail(name);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
209
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
210 val.length = 1;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
211 val.value = &value;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
212
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
213 session_set_value(conn, name, SmCARD8, 1, &val);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
214 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
215
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
216 static void session_set_array(SmcConn conn, gchar *name, gchar *array[]) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
217 gint argc;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
218 gchar **ptr;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
219 gint i;
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 SmPropValue *vals;
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 g_return_if_fail (name);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
224
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
225 /* We count the number of elements in our array. */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
226 for (ptr = array, argc = 0; *ptr ; ptr++, argc++) /* LOOP */;
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 /* Now initialize the 'vals' array. */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
229 vals = g_new (SmPropValue, argc);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
230 for (ptr = array, i = 0 ; i < argc ; ptr++, i++) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
231 vals[i].length = strlen (*ptr);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
232 vals[i].value = *ptr;
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
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
235 session_set_value(conn, name, SmLISTofARRAY8, argc, vals);
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 g_free (vals);
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 #endif /* USE_SM */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
241
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
242 /* setup functions */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
243
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
244 void session_init(gchar *argv0, gchar *previous_id) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
245 #ifdef USE_SM
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
246 SmcCallbacks callbacks;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
247 gchar *client_id = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
248 gchar error[ERROR_LENGTH] = "";
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
249 gchar *tmp = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
250 gchar *cmd[4] = { NULL, NULL, NULL, NULL };
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 if (session != NULL) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
253 /* session is already established, what the hell is going on? */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
254 debug_printf("Session Management: duplicated call to session_init!\n");
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
255 return;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
256 }
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 if (g_getenv("SESSION_MANAGER") == NULL) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
259 debug_printf("Session Management: no SESSION_MANAGER found, aborting\n");
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
260 return;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
261 }
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 ice_init();
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
264
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
265 callbacks.save_yourself.callback = session_save_yourself;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
266 callbacks.die.callback = session_die;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
267 callbacks.save_complete.callback = session_save_complete;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
268 callbacks.shutdown_cancelled.callback = session_shutdown_cancelled;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
269
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
270 callbacks.save_yourself.client_data = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
271 callbacks.die.client_data = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
272 callbacks.save_complete.client_data = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
273 callbacks.shutdown_cancelled.client_data = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
274
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
275 debug_printf("Session Management: connecting with previous ID %s\n", previous_id);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
276
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
277 session = SmcOpenConnection(NULL, "session", SmProtoMajor, SmProtoMinor, SmcSaveYourselfProcMask |
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
278 SmcDieProcMask | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask,
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
279 &callbacks, previous_id, &client_id, ERROR_LENGTH, error);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
280
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
281 if (session == NULL) {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
282 if (error[0] != '\0') {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
283 debug_printf("Session Management: connection failed with error: %s\n", error);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
284 } else {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
285 debug_printf("Session Management: connection failed with unknown error\n");
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
286 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
287 return;
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
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
290 tmp = SmcVendor(session);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
291 debug_printf("Session Management: connected to manager (%s) with client ID %s\n", tmp, client_id);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
292 g_free(tmp);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
293
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
294 session_managed = TRUE;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
295 gdk_set_sm_client_id(client_id);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
296
4210
e11393a176d5 [gaim-migrate @ 4447]
Luke Schierer <lschiere@pidgin.im>
parents: 4158
diff changeset
297 tmp = g_strdup_printf("%d", (int) getpid());
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
298 session_set_string(session, SmProcessID, tmp);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
299 g_free(tmp);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
300
4210
e11393a176d5 [gaim-migrate @ 4447]
Luke Schierer <lschiere@pidgin.im>
parents: 4158
diff changeset
301 tmp = g_strdup(g_get_user_name());
4158
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
302 session_set_string(session, SmUserID, tmp);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
303 g_free(tmp);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
304
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
305 session_set_gchar(session, SmRestartStyleHint, (gchar) SmRestartIfRunning);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
306 session_set_string(session, SmProgram, g_get_prgname());
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
307
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
308 myself = g_strdup(argv0);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
309 debug_printf("Session Management: using %s as command\n", myself);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
310
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
311 cmd[0] = myself;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
312 cmd[1] = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
313 session_set_array(session, SmCloneCommand, cmd);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
314
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
315 cmd[1] = "-v";
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
316 cmd[2] = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
317 session_set_array(session, SmDiscardCommand, cmd);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
318
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
319 cmd[1] = "--session";
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
320 cmd[2] = client_id;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
321 cmd[3] = NULL;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
322 session_set_array(session, SmRestartCommand, cmd);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
323 g_free(client_id);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
324 #endif /* USE_SM */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
325 }
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
326
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
327 void session_end() {
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
328 #ifdef USE_SM
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
329 if (session == NULL) /* no session to close */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
330 return;
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
331
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
332 SmcCloseConnection(session, 0, NULL);
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
333
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
334 debug_printf("Session Management: connection closed\n");
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
335 #endif /* USE_SM */
a638bc9454a6 [gaim-migrate @ 4386]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
336 }