mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 03:22:04 +00:00
...
This commit is contained in:
parent
3886f0ecac
commit
2830c9d748
@ -8,8 +8,12 @@ msm_SOURCES= \
|
||||
gui.h \
|
||||
main.c \
|
||||
main.h \
|
||||
props.c \
|
||||
props.h \
|
||||
server.c \
|
||||
server.h \
|
||||
session.c \
|
||||
session.h \
|
||||
util.c \
|
||||
util.h
|
||||
|
||||
|
233
src/msm/client.c
233
src/msm/client.c
@ -20,6 +20,11 @@
|
||||
*/
|
||||
|
||||
#include "client.h"
|
||||
#include "props.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct _MsmClient
|
||||
{
|
||||
@ -33,35 +38,6 @@ struct _MsmClient
|
||||
GList *properties;
|
||||
};
|
||||
|
||||
static GList* find_property_link_by_name (MsmClient *client,
|
||||
const char *name);
|
||||
|
||||
static SmProp* find_property_by_name (MsmClient *client,
|
||||
const char *name);
|
||||
|
||||
static gboolean find_card8_property (MsmClient *client,
|
||||
const char *name,
|
||||
int *result)
|
||||
|
||||
static gboolean find_string_property (MsmClient *client,
|
||||
const char *name,
|
||||
char **result);
|
||||
|
||||
static gboolean find_vector_property (MsmClient *client,
|
||||
const char *name,
|
||||
int *argcp,
|
||||
char ***argvp);
|
||||
|
||||
static gboolean get_card8_value (SmProp *prop,
|
||||
int *result);
|
||||
static gboolean get_string_value (SmProp *prop,
|
||||
char **result);
|
||||
static gboolean get_vector_value (SmProp *prop,
|
||||
int *argcp,
|
||||
char ***argvp);
|
||||
|
||||
static SmProp* copy_property (SmProp *prop);
|
||||
|
||||
#define DEFAULT_RESTART_STYLE SmRestartIfRunning
|
||||
|
||||
MsmClient*
|
||||
@ -168,7 +144,7 @@ msm_client_register (MsmClient *client,
|
||||
|
||||
SmsRegisterClientReply (client->cnxn, client->id);
|
||||
|
||||
p = SmsClientHostName (smsConn);
|
||||
p = SmsClientHostName (client->cnxn);
|
||||
client->hostname = g_strdup (p);
|
||||
free (p);
|
||||
}
|
||||
@ -190,9 +166,7 @@ msm_client_interact_request (MsmClient *client)
|
||||
|
||||
void
|
||||
msm_client_begin_interact (MsmClient *client)
|
||||
{
|
||||
g_return_if_fail (client->interact_requested);
|
||||
|
||||
{
|
||||
SmsInteract (client->cnxn);
|
||||
}
|
||||
|
||||
@ -234,7 +208,7 @@ msm_client_initial_save (MsmClient *client)
|
||||
/* This is the save on client registration in the spec under
|
||||
* RegisterClientReply
|
||||
*/
|
||||
internal_save (client, SmSaveLocal, allow_interaction, shut_down);
|
||||
internal_save (client, SmSaveLocal, FALSE, FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
@ -322,7 +296,7 @@ msm_client_set_property_taking_ownership (MsmClient *client,
|
||||
return;
|
||||
}
|
||||
|
||||
list = find_property_link_by_name (prop->name);
|
||||
list = proplist_find_link_by_name (client->properties, prop->name);
|
||||
if (list)
|
||||
{
|
||||
SmFreeProperty (list->data);
|
||||
@ -338,7 +312,7 @@ msm_client_set_property_taking_ownership (MsmClient *client,
|
||||
if (strcmp (prop->name, "SmRestartStyleHint") == 0)
|
||||
{
|
||||
int hint;
|
||||
if (get_card8_value (prop, &hint))
|
||||
if (smprop_get_card8 (prop, &hint))
|
||||
client->restart_style = hint;
|
||||
else
|
||||
client->restart_style = DEFAULT_RESTART_STYLE;
|
||||
@ -351,7 +325,7 @@ msm_client_unset_property (MsmClient *client,
|
||||
{
|
||||
GList *list;
|
||||
|
||||
list = find_property_link_by_name (prop->name);
|
||||
list = proplist_find_link_by_name (client->properties, name);
|
||||
if (list)
|
||||
{
|
||||
SmFreeProperty (list->data);
|
||||
@ -375,7 +349,7 @@ msm_client_send_properties (MsmClient *client)
|
||||
int i;
|
||||
|
||||
n_props = g_list_length (client->properties);
|
||||
props = g_new (SmProp, n_props);
|
||||
props = g_new (SmProp*, n_props);
|
||||
|
||||
i = 0;
|
||||
tmp = client->properties;
|
||||
@ -391,186 +365,3 @@ msm_client_send_properties (MsmClient *client)
|
||||
|
||||
g_free (props);
|
||||
}
|
||||
|
||||
/* Property functions stolen from gnome-session */
|
||||
|
||||
static GList*
|
||||
find_property_link_by_name (MsmClient *client,
|
||||
const char *name)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
for (list = client->properties; list; list = list->next)
|
||||
{
|
||||
SmProp *prop = (SmProp *) list->data;
|
||||
if (strcmp (prop->name, name) == 0)
|
||||
return list;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
SmProp*
|
||||
find_property_by_name (MsmClient *client, const char *name)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
list = find_property_link_by_name (client, name);
|
||||
|
||||
return list ? list->data : NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
find_card8_property (MsmClient *client, const char *name,
|
||||
int *result)
|
||||
{
|
||||
SmProp *prop;
|
||||
|
||||
g_return_val_if_fail (result != NULL, FALSE);
|
||||
|
||||
prop = find_property_by_name (client, name);
|
||||
if (prop == NULL)
|
||||
return FALSE;
|
||||
else
|
||||
return get_card8_value (prop, result);
|
||||
}
|
||||
|
||||
gboolean
|
||||
find_string_property (MsmClient *client, const char *name,
|
||||
char **result)
|
||||
{
|
||||
SmProp *prop;
|
||||
|
||||
g_return_val_if_fail (result != NULL, FALSE);
|
||||
|
||||
prop = find_property_by_name (client, name);
|
||||
if (prop == NULL)
|
||||
return FALSE;
|
||||
else
|
||||
return get_string_value (prop, result);
|
||||
}
|
||||
|
||||
gboolean
|
||||
find_vector_property (MsmClient *client, const char *name,
|
||||
int *argcp, char ***argvp)
|
||||
{
|
||||
SmProp *prop;
|
||||
|
||||
g_return_val_if_fail (argcp != NULL, FALSE);
|
||||
g_return_val_if_fail (argvp != NULL, FALSE);
|
||||
|
||||
prop = find_property_by_name (client, name);
|
||||
if (prop == NULL)
|
||||
return FALSE;
|
||||
else
|
||||
return get_vector_value (prop, argcp, argvp);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_card8_value (SmProp *prop,
|
||||
int *result)
|
||||
{
|
||||
g_return_val_if_fail (result != NULL, FALSE);
|
||||
|
||||
if (strcmp (prop->type, SmCARD8) == 0)
|
||||
{
|
||||
char *p;
|
||||
p = prop->vals[0].value;
|
||||
*result = *p;
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_string_value (SmProp *prop,
|
||||
char **result)
|
||||
{
|
||||
g_return_val_if_fail (result != NULL, FALSE);
|
||||
|
||||
if (strcmp (prop->type, SmARRAY8) == 0)
|
||||
{
|
||||
*result = g_malloc (prop->vals[0].length + 1);
|
||||
memcpy (*result, prop->vals[0].value, prop->vals[0].length);
|
||||
(*result)[prop->vals[0].length] = '\0';
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_vector_value (SmProp *prop,
|
||||
int *argcp,
|
||||
char ***argvp)
|
||||
{
|
||||
g_return_val_if_fail (argcp != NULL, FALSE);
|
||||
g_return_val_if_fail (argvp != NULL, FALSE);
|
||||
|
||||
if (strcmp (prop->type, SmLISTofARRAY8) == 0)
|
||||
{
|
||||
int i;
|
||||
|
||||
*argcp = prop->num_vals;
|
||||
*argvp = g_new0 (char *, *argcp + 1);
|
||||
for (i = 0; i < *argcp; ++i)
|
||||
{
|
||||
(*argvp)[i] = g_malloc (prop->vals[i].length + 1);
|
||||
memcpy ((*argvp)[i], prop->vals[i].value, prop->vals[i].length);
|
||||
(*argvp)[i][prop->vals[i].length] = '\0';
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static SmProp*
|
||||
copy_property (SmProp *prop)
|
||||
{
|
||||
int i;
|
||||
SmProp *copy;
|
||||
|
||||
/* This all uses malloc so we can use SmFreeProperty() */
|
||||
|
||||
copy = msm_non_glib_malloc (sizeof (SmProp));
|
||||
|
||||
if (prop->name)
|
||||
copy->name = msm_non_glib_strdup (prop->name);
|
||||
else
|
||||
copy->name = NULL;
|
||||
|
||||
if (prop->type)
|
||||
copy->type = msm_non_glib_strdup (prop->type);
|
||||
else
|
||||
copy->type = NULL;
|
||||
|
||||
copy->num_vals = prop->num_vals;
|
||||
copy->vals = NULL;
|
||||
|
||||
if (copy->num_vals > 0 && prop->vals)
|
||||
{
|
||||
copy->vals = msm_non_glib_malloc (sizeof (SmPropValue) * copy->num_vals);
|
||||
|
||||
for (i = 0; i < copy->num_vals; i++)
|
||||
{
|
||||
if (prop->vals[i].value)
|
||||
{
|
||||
copy->vals[i].length = prop->vals[i].length;
|
||||
copy->vals[i].value = msm_non_glib_malloc (copy->vals[i].length);
|
||||
memcpy (copy->vals[i].value, prop->vals[i].value,
|
||||
copy->vals[i].length);
|
||||
}
|
||||
else
|
||||
{
|
||||
copy->vals[i].length = 0;
|
||||
copy->vals[i].value = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "server.h"
|
||||
#include "util.h"
|
||||
|
210
src/msm/props.c
Normal file
210
src/msm/props.c
Normal file
@ -0,0 +1,210 @@
|
||||
/* msm SmProp utils */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2001 Havoc Pennington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "props.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Property functions stolen from gnome-session */
|
||||
|
||||
GList*
|
||||
proplist_find_link_by_name (GList *list,
|
||||
const char *name)
|
||||
{
|
||||
for (; list; list = list->next)
|
||||
{
|
||||
SmProp *prop = (SmProp *) list->data;
|
||||
if (strcmp (prop->name, name) == 0)
|
||||
return list;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
SmProp*
|
||||
proplist_find_by_name (GList *list, const char *name)
|
||||
{
|
||||
GList *ret;
|
||||
|
||||
ret = proplist_find_link_by_name (list, name);
|
||||
|
||||
return ret ? ret->data : NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
proplist_find_card8 (GList *list, const char *name,
|
||||
int *result)
|
||||
{
|
||||
SmProp *prop;
|
||||
|
||||
g_return_val_if_fail (result != NULL, FALSE);
|
||||
|
||||
prop = proplist_find_by_name (list, name);
|
||||
if (prop == NULL)
|
||||
return FALSE;
|
||||
else
|
||||
return smprop_get_card8 (prop, result);
|
||||
}
|
||||
|
||||
gboolean
|
||||
proplist_find_string (GList *list, const char *name,
|
||||
char **result)
|
||||
{
|
||||
SmProp *prop;
|
||||
|
||||
g_return_val_if_fail (result != NULL, FALSE);
|
||||
|
||||
prop = proplist_find_by_name (list, name);
|
||||
if (prop == NULL)
|
||||
return FALSE;
|
||||
else
|
||||
return smprop_get_string (prop, result);
|
||||
}
|
||||
|
||||
gboolean
|
||||
proplist_find_vector (GList *list, const char *name,
|
||||
int *argcp, char ***argvp)
|
||||
{
|
||||
SmProp *prop;
|
||||
|
||||
g_return_val_if_fail (argcp != NULL, FALSE);
|
||||
g_return_val_if_fail (argvp != NULL, FALSE);
|
||||
|
||||
prop = proplist_find_by_name (list, name);
|
||||
if (prop == NULL)
|
||||
return FALSE;
|
||||
else
|
||||
return smprop_get_vector (prop, argcp, argvp);
|
||||
}
|
||||
|
||||
gboolean
|
||||
smprop_get_card8 (SmProp *prop,
|
||||
int *result)
|
||||
{
|
||||
g_return_val_if_fail (result != NULL, FALSE);
|
||||
|
||||
if (strcmp (prop->type, SmCARD8) == 0)
|
||||
{
|
||||
char *p;
|
||||
p = prop->vals[0].value;
|
||||
*result = *p;
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
smprop_get_string (SmProp *prop,
|
||||
char **result)
|
||||
{
|
||||
g_return_val_if_fail (result != NULL, FALSE);
|
||||
|
||||
if (strcmp (prop->type, SmARRAY8) == 0)
|
||||
{
|
||||
*result = g_malloc (prop->vals[0].length + 1);
|
||||
memcpy (*result, prop->vals[0].value, prop->vals[0].length);
|
||||
(*result)[prop->vals[0].length] = '\0';
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
smprop_get_vector (SmProp *prop,
|
||||
int *argcp,
|
||||
char ***argvp)
|
||||
{
|
||||
g_return_val_if_fail (argcp != NULL, FALSE);
|
||||
g_return_val_if_fail (argvp != NULL, FALSE);
|
||||
|
||||
if (strcmp (prop->type, SmLISTofARRAY8) == 0)
|
||||
{
|
||||
int i;
|
||||
|
||||
*argcp = prop->num_vals;
|
||||
*argvp = g_new0 (char *, *argcp + 1);
|
||||
for (i = 0; i < *argcp; ++i)
|
||||
{
|
||||
(*argvp)[i] = g_malloc (prop->vals[i].length + 1);
|
||||
memcpy ((*argvp)[i], prop->vals[i].value, prop->vals[i].length);
|
||||
(*argvp)[i][prop->vals[i].length] = '\0';
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
SmProp*
|
||||
smprop_copy (SmProp *prop)
|
||||
{
|
||||
int i;
|
||||
SmProp *copy;
|
||||
|
||||
/* This all uses malloc so we can use SmFreeProperty() */
|
||||
|
||||
copy = msm_non_glib_malloc (sizeof (SmProp));
|
||||
|
||||
if (prop->name)
|
||||
copy->name = msm_non_glib_strdup (prop->name);
|
||||
else
|
||||
copy->name = NULL;
|
||||
|
||||
if (prop->type)
|
||||
copy->type = msm_non_glib_strdup (prop->type);
|
||||
else
|
||||
copy->type = NULL;
|
||||
|
||||
copy->num_vals = prop->num_vals;
|
||||
copy->vals = NULL;
|
||||
|
||||
if (copy->num_vals > 0 && prop->vals)
|
||||
{
|
||||
copy->vals = msm_non_glib_malloc (sizeof (SmPropValue) * copy->num_vals);
|
||||
|
||||
for (i = 0; i < copy->num_vals; i++)
|
||||
{
|
||||
if (prop->vals[i].value)
|
||||
{
|
||||
copy->vals[i].length = prop->vals[i].length;
|
||||
copy->vals[i].value = msm_non_glib_malloc (copy->vals[i].length);
|
||||
memcpy (copy->vals[i].value, prop->vals[i].value,
|
||||
copy->vals[i].length);
|
||||
}
|
||||
else
|
||||
{
|
||||
copy->vals[i].length = 0;
|
||||
copy->vals[i].value = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
|
55
src/msm/props.h
Normal file
55
src/msm/props.h
Normal file
@ -0,0 +1,55 @@
|
||||
/* msm SmProp utils */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2001 Havoc Pennington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef MSM_PROPS_H
|
||||
#define MSM_PROPS_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <X11/ICE/ICElib.h>
|
||||
#include <X11/SM/SMlib.h>
|
||||
|
||||
GList* proplist_find_link_by_name (GList *list,
|
||||
const char *name);
|
||||
SmProp* proplist_find_by_name (GList *list,
|
||||
const char *name);
|
||||
gboolean proplist_find_card8 (GList *list,
|
||||
const char *name,
|
||||
int *result);
|
||||
gboolean proplist_find_string (GList *list,
|
||||
const char *name,
|
||||
char **result);
|
||||
gboolean proplist_find_vector (GList *list,
|
||||
const char *name,
|
||||
int *argcp,
|
||||
char ***argvp);
|
||||
|
||||
gboolean smprop_get_card8 (SmProp *prop,
|
||||
int *result);
|
||||
gboolean smprop_get_string (SmProp *prop,
|
||||
char **result);
|
||||
gboolean smprop_get_vector (SmProp *prop,
|
||||
int *argcp,
|
||||
char ***argvp);
|
||||
|
||||
SmProp* smprop_copy (SmProp *prop);
|
||||
|
||||
#endif
|
||||
|
162
src/msm/server.c
162
src/msm/server.c
@ -41,8 +41,22 @@
|
||||
* authorization from The Open Group.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <X11/ICE/ICEutil.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
#include "server.h"
|
||||
#include "session.h"
|
||||
#include "util.h"
|
||||
|
||||
#define MAGIC_COOKIE_LEN 16
|
||||
|
||||
/* FIXME we need to time out anytime we're waiting for a client
|
||||
* response, such as InteractDone, SaveYourselfDone, ConnectionClosed
|
||||
@ -102,8 +116,8 @@ static void get_properties_callback (SmsConn cnxn,
|
||||
|
||||
static Status new_client_callback (SmsConn cnxn,
|
||||
SmPointer manager_data,
|
||||
unsigned long *maskRet,
|
||||
SmsCallbacks *callbacksRet,
|
||||
unsigned long *mask_ret,
|
||||
SmsCallbacks *callbacks_ret,
|
||||
char **failure_reason_ret);
|
||||
static Bool host_auth_callback (char *hostname);
|
||||
|
||||
@ -111,11 +125,12 @@ static Bool host_auth_callback (char *hostname);
|
||||
static void ice_init (MsmServer *server);
|
||||
|
||||
static gboolean create_auth_entries (MsmServer *server,
|
||||
IceListenObject *listen_objs,
|
||||
IceListenObj *listen_objs,
|
||||
int n_listen_objs);
|
||||
static void free_auth_entries (IceAuthDataEntry *entries);
|
||||
static void free_auth_entries (IceAuthDataEntry *entries,
|
||||
int n_entries);
|
||||
|
||||
static void
|
||||
static MsmServer*
|
||||
msm_server_new_with_session (MsmSession *session)
|
||||
{
|
||||
char errbuf[256];
|
||||
@ -150,7 +165,7 @@ msm_server_new (const char *session_name)
|
||||
{
|
||||
MsmSession *session;
|
||||
|
||||
session = msm_session_new (session_name);
|
||||
session = msm_session_get (session_name);
|
||||
|
||||
return msm_server_new_with_session (session);
|
||||
}
|
||||
@ -223,10 +238,11 @@ register_client_callback (SmsConn cnxn,
|
||||
* Whenever previous_id is non-NULL we need to free() it.
|
||||
* (What an incredibly broken interface...)
|
||||
*/
|
||||
|
||||
MsmClient *client;
|
||||
MsmServer *server;
|
||||
|
||||
client = manager_data;
|
||||
server = msm_client_get_server (client);
|
||||
|
||||
if (previous_id == NULL)
|
||||
{
|
||||
@ -446,7 +462,7 @@ delete_properties_callback (SmsConn cnxn,
|
||||
i = 0;
|
||||
while (i < numProps)
|
||||
{
|
||||
msm_client_unset_property (propNames[i]);
|
||||
msm_client_unset_property (client, propNames[i]);
|
||||
|
||||
++i;
|
||||
}
|
||||
@ -468,8 +484,8 @@ get_properties_callback (SmsConn cnxn,
|
||||
static Status
|
||||
new_client_callback (SmsConn cnxn,
|
||||
SmPointer manager_data,
|
||||
unsigned long *maskRet,
|
||||
SmsCallbacks *callbacksRet,
|
||||
unsigned long *mask_ret,
|
||||
SmsCallbacks *callbacks_ret,
|
||||
char **failure_reason_ret)
|
||||
{
|
||||
MsmClient *client;
|
||||
@ -491,47 +507,47 @@ new_client_callback (SmsConn cnxn,
|
||||
client = msm_client_new (server, cnxn);
|
||||
server->clients = g_list_prepend (server->clients, client);
|
||||
|
||||
*maskRet = 0;
|
||||
*mask_ret = 0;
|
||||
|
||||
*maskRet |= SmsRegisterClientProcMask;
|
||||
callbacksRet->register_client.callback = register_client_callback;
|
||||
callbacksRet->register_client.manager_data = client;
|
||||
*mask_ret |= SmsRegisterClientProcMask;
|
||||
callbacks_ret->register_client.callback = register_client_callback;
|
||||
callbacks_ret->register_client.manager_data = client;
|
||||
|
||||
*maskRet |= SmsInteractRequestProcMask;
|
||||
callbacksRet->interact_request.callback = interact_request_callback;
|
||||
callbacksRet->interact_request.manager_data = client;
|
||||
*mask_ret |= SmsInteractRequestProcMask;
|
||||
callbacks_ret->interact_request.callback = interact_request_callback;
|
||||
callbacks_ret->interact_request.manager_data = client;
|
||||
|
||||
*maskRet |= SmsInteractDoneProcMask;
|
||||
callbacksRet->interact_done.callback = interact_done_callback;
|
||||
callbacksRet->interact_done.manager_data = client;
|
||||
*mask_ret |= SmsInteractDoneProcMask;
|
||||
callbacks_ret->interact_done.callback = interact_done_callback;
|
||||
callbacks_ret->interact_done.manager_data = client;
|
||||
|
||||
*maskRet |= SmsSaveYourselfRequestProcMask;
|
||||
callbacksRet->save_yourself_request.callback = save_yourself_request_callback;
|
||||
callbacksRet->save_yourself_request.manager_data = client;
|
||||
*mask_ret |= SmsSaveYourselfRequestProcMask;
|
||||
callbacks_ret->save_yourself_request.callback = save_yourself_request_callback;
|
||||
callbacks_ret->save_yourself_request.manager_data = client;
|
||||
|
||||
*maskRet |= SmsSaveYourselfP2RequestProcMask;
|
||||
callbacksRet->save_yourself_phase2_request.callback = save_yourself_phase2_request_callback;
|
||||
callbacksRet->save_yourself_phase2_request.manager_data = client;
|
||||
*mask_ret |= SmsSaveYourselfP2RequestProcMask;
|
||||
callbacks_ret->save_yourself_phase2_request.callback = save_yourself_phase2_request_callback;
|
||||
callbacks_ret->save_yourself_phase2_request.manager_data = client;
|
||||
|
||||
*maskRet |= SmsSaveYourselfDoneProcMask;
|
||||
callbacksRet->save_yourself_done.callback = save_yourself_done_callback;
|
||||
callbacksRet->save_yourself_done.manager_data = client;
|
||||
*mask_ret |= SmsSaveYourselfDoneProcMask;
|
||||
callbacks_ret->save_yourself_done.callback = save_yourself_done_callback;
|
||||
callbacks_ret->save_yourself_done.manager_data = client;
|
||||
|
||||
*maskRet |= SmsCloseConnectionProcMask;
|
||||
callbacksRet->close_connection.callback = close_connection_callback;
|
||||
callbacksRet->close_connection.manager_data = client;
|
||||
*mask_ret |= SmsCloseConnectionProcMask;
|
||||
callbacks_ret->close_connection.callback = close_connection_callback;
|
||||
callbacks_ret->close_connection.manager_data = client;
|
||||
|
||||
*maskRet |= SmsSetPropertiesProcMask;
|
||||
callbacksRet->set_properties.callback = set_properties_callback;
|
||||
callbacksRet->set_properties.manager_data = client;
|
||||
*mask_ret |= SmsSetPropertiesProcMask;
|
||||
callbacks_ret->set_properties.callback = set_properties_callback;
|
||||
callbacks_ret->set_properties.manager_data = client;
|
||||
|
||||
*maskRet |= SmsDeletePropertiesProcMask;
|
||||
callbacksRet->delete_properties.callback = delete_properties_callback;
|
||||
callbacksRet->delete_properties.manager_data = client;
|
||||
*mask_ret |= SmsDeletePropertiesProcMask;
|
||||
callbacks_ret->delete_properties.callback = delete_properties_callback;
|
||||
callbacks_ret->delete_properties.manager_data = client;
|
||||
|
||||
*maskRet |= SmsGetPropertiesProcMask;
|
||||
callbacksRet->get_properties.callback = get_properties_callback;
|
||||
callbacksRet->get_properties.manager_data = client;
|
||||
*mask_ret |= SmsGetPropertiesProcMask;
|
||||
callbacks_ret->get_properties.callback = get_properties_callback;
|
||||
callbacks_ret->get_properties.manager_data = client;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -723,7 +739,7 @@ msm_server_consider_phase_change (MsmServer *server)
|
||||
}
|
||||
|
||||
/* Write to disk. */
|
||||
msm_session_save (server->session);
|
||||
msm_session_save (server->session, server);
|
||||
}
|
||||
|
||||
/* msm_session_save() may have cancelled any shutdown that was in progress,
|
||||
@ -845,10 +861,6 @@ static void ice_io_error_handler (IceConn connection);
|
||||
static void new_ice_connection (IceConn connection, IcePointer client_data,
|
||||
Bool opening, IcePointer *watch_data);
|
||||
|
||||
static void setup_authentication (MsmServer *server,
|
||||
IceListenObject *listen_objs,
|
||||
int n_listen_objs);
|
||||
|
||||
/* This is called when data is available on an ICE connection. */
|
||||
static gboolean
|
||||
process_ice_messages (GIOChannel *channel,
|
||||
@ -920,7 +932,7 @@ accept_connection (GIOChannel *channel,
|
||||
GIOCondition condition,
|
||||
gpointer client_data)
|
||||
{
|
||||
IceListenObject *listen_obj;
|
||||
IceListenObj listen_obj;
|
||||
IceAcceptStatus status;
|
||||
IceConnectStatus cstatus;
|
||||
IceConn cnxn;
|
||||
@ -1026,7 +1038,7 @@ ice_init (MsmServer *server)
|
||||
|
||||
g_io_add_watch (channel, G_IO_IN,
|
||||
accept_connection,
|
||||
&listen_objs[i]);
|
||||
listen_objs[i]);
|
||||
|
||||
g_io_channel_unref (channel);
|
||||
|
||||
@ -1035,7 +1047,7 @@ ice_init (MsmServer *server)
|
||||
|
||||
if (!create_auth_entries (server, listen_objs, n_listen_objs))
|
||||
{
|
||||
meta_fatal (_("Could not set up authentication"));
|
||||
msm_fatal (_("Could not set up authentication"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1068,9 +1080,9 @@ run_iceauth_script (const char *filename)
|
||||
GError *err;
|
||||
int status;
|
||||
|
||||
argv[0] = "iceauth";
|
||||
argv[1] = "source";
|
||||
argv[2] = filename;
|
||||
argv[0] = (char*) "iceauth";
|
||||
argv[1] = (char*) "source";
|
||||
argv[2] = (char*) filename;
|
||||
argv[3] = NULL;
|
||||
|
||||
err = NULL;
|
||||
@ -1095,9 +1107,37 @@ run_iceauth_script (const char *filename)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
printhex (FILE *fp, const char *data, int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
fprintf (fp, "%02x", data[i]);
|
||||
}
|
||||
|
||||
static void
|
||||
write_iceauth (FILE *addfp, FILE *removefp, IceAuthDataEntry *entry)
|
||||
{
|
||||
fprintf (addfp,
|
||||
"add %s \"\" %s %s ",
|
||||
entry->protocol_name,
|
||||
entry->network_id,
|
||||
entry->auth_name);
|
||||
|
||||
printhex (addfp, entry->auth_data, entry->auth_data_length);
|
||||
fprintf (addfp, "\n");
|
||||
|
||||
fprintf (removefp,
|
||||
"remove protoname=%s protodata=\"\" netid=%s authname=%s\n",
|
||||
entry->protocol_name,
|
||||
entry->network_id,
|
||||
entry->auth_name);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
create_auth_entries (MsmServer *server,
|
||||
IceListenObject *listen_objs,
|
||||
IceListenObj *listen_objs,
|
||||
int n_listen_objs)
|
||||
{
|
||||
FILE *addfp = NULL;
|
||||
@ -1122,7 +1162,7 @@ create_auth_entries (MsmServer *server,
|
||||
msm_fatal (_("Could not create ICE authentication script: %s\n"),
|
||||
err->message);
|
||||
g_assert_not_reached ();
|
||||
return;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
addfp = fdopen (fd, "w");
|
||||
@ -1141,7 +1181,7 @@ create_auth_entries (MsmServer *server,
|
||||
msm_fatal (_("Could not create ICE authentication script: %s\n"),
|
||||
err->message);
|
||||
g_assert_not_reached ();
|
||||
return;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
removefp = fdopen (fd, "w");
|
||||
@ -1206,15 +1246,15 @@ create_auth_entries (MsmServer *server,
|
||||
if (removefp)
|
||||
fclose (removefp);
|
||||
|
||||
if (addAuthFile)
|
||||
if (add_file)
|
||||
{
|
||||
unlink (addAuthFile);
|
||||
free (addAuthFile);
|
||||
unlink (add_file);
|
||||
free (add_file);
|
||||
}
|
||||
if (remAuthFile)
|
||||
if (remove_file)
|
||||
{
|
||||
unlink (remAuthFile);
|
||||
free (remAuthFile);
|
||||
unlink (remove_file);
|
||||
free (remove_file);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
@ -20,12 +20,24 @@
|
||||
*/
|
||||
|
||||
#include "session.h"
|
||||
#include "util.h"
|
||||
#include "props.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
typedef struct _MsmSavedClient MsmSavedClient;
|
||||
|
||||
struct _MsmSavedClient
|
||||
{
|
||||
char **restart_command;
|
||||
char *id;
|
||||
|
||||
};
|
||||
|
||||
@ -48,6 +60,10 @@ typedef enum
|
||||
|
||||
static GHashTable *sessions = NULL;
|
||||
|
||||
MsmSavedClient *saved_new (void);
|
||||
void saved_free (MsmSavedClient *saved);
|
||||
|
||||
|
||||
static MsmSession* recover_failed_session (MsmSession *session,
|
||||
MsmSessionFailureReason reason,
|
||||
const char *details);
|
||||
@ -55,6 +71,13 @@ static MsmSession* recover_failed_session (MsmSession *session,
|
||||
static gboolean parse_session_file (MsmSession *session,
|
||||
GError **error);
|
||||
|
||||
void
|
||||
msm_session_clear (MsmSession *session)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
msm_session_update_client (MsmSession *session,
|
||||
MsmClient *client)
|
||||
@ -77,6 +100,7 @@ msm_session_client_id_known (MsmSession *session,
|
||||
{
|
||||
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@ -86,6 +110,26 @@ msm_session_launch (MsmSession *session)
|
||||
|
||||
}
|
||||
|
||||
MsmSavedClient*
|
||||
saved_new (void)
|
||||
{
|
||||
MsmSavedClient *saved;
|
||||
|
||||
saved = g_new (MsmSavedClient, 1);
|
||||
|
||||
saved->id = NULL;
|
||||
|
||||
return saved;
|
||||
}
|
||||
|
||||
void
|
||||
saved_free (MsmSavedClient *saved)
|
||||
{
|
||||
g_free (saved->id);
|
||||
|
||||
g_free (saved);
|
||||
}
|
||||
|
||||
static const char*
|
||||
session_dir (void)
|
||||
{
|
||||
@ -109,14 +153,14 @@ set_close_on_exec (int fd)
|
||||
val = fcntl (fd, F_GETFD, 0);
|
||||
if (val < 0)
|
||||
{
|
||||
gconf_log (GCL_DEBUG, "couldn't F_GETFD: %s\n", g_strerror (errno));
|
||||
msm_warning ("couldn't F_GETFD: %s\n", g_strerror (errno));
|
||||
return;
|
||||
}
|
||||
|
||||
val |= FD_CLOEXEC;
|
||||
|
||||
if (fcntl (fd, F_SETFD, val) < 0)
|
||||
gconf_log (GCL_DEBUG, "couldn't F_SETFD: %s\n", g_strerror (errno));
|
||||
msm_warning ("couldn't F_SETFD: %s\n", g_strerror (errno));
|
||||
}
|
||||
|
||||
/* Your basic Stevens cut-and-paste */
|
||||
@ -146,7 +190,6 @@ msm_session_get_for_filename (const char *name,
|
||||
int fd = -1;
|
||||
GError *dir_error = NULL;
|
||||
GError *err;
|
||||
gboolean use_global_file;
|
||||
|
||||
session = g_hash_table_lookup (sessions, filename);
|
||||
if (session)
|
||||
@ -160,7 +203,7 @@ msm_session_get_for_filename (const char *name,
|
||||
session->lock_fd = -1;
|
||||
|
||||
dir_error = NULL;
|
||||
msm_create_dir_and_parents (session_dir (), &dir_error);
|
||||
msm_create_dir_and_parents (session_dir (), 0700, &dir_error);
|
||||
/* We save dir_error for later; if creating the file fails,
|
||||
* we give dir_error in the reason.
|
||||
*/
|
||||
@ -309,13 +352,59 @@ msm_session_save (MsmSession *session,
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
static MsmSession*
|
||||
recover_failed_session (MsmSession *session,
|
||||
MsmSessionFailureReason reason,
|
||||
const char *details)
|
||||
{
|
||||
/* FIXME, actually give option to recover, don't just complain */
|
||||
GtkWidget *dialog;
|
||||
char *message;
|
||||
|
||||
message = NULL;
|
||||
|
||||
switch (reason)
|
||||
{
|
||||
case MSM_SESSION_FAILURE_OPENING_FILE:
|
||||
message = g_strdup_printf (_("Could not open the session \"%s.\""),
|
||||
session->name);
|
||||
break;
|
||||
|
||||
case MSM_SESSION_FAILURE_LOCKING:
|
||||
message = g_strdup_printf (_("You are already logged in elsewhere, using the session \"%s.\" You can only use a session from one location at a time."),
|
||||
session->name);
|
||||
break;
|
||||
|
||||
case MSM_SESSION_FAILURE_BAD_FILE:
|
||||
message = g_strdup_printf (_("The session file for session \"%s\" appears to be invalid or corrupted."),
|
||||
session->name);
|
||||
break;
|
||||
|
||||
case MSM_SESSION_FAILURE_EMPTY:
|
||||
message = g_strdup_printf (_("The session \"%s\" contains no applications."),
|
||||
session->name);
|
||||
break;
|
||||
}
|
||||
|
||||
dialog = gtk_message_dialog_new (NULL,
|
||||
GTK_DIALOG_MODAL,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
message);
|
||||
|
||||
g_free (message);
|
||||
|
||||
gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
|
||||
exit (1);
|
||||
|
||||
/* FIXME instead of exiting, always recover by coming up with some sort
|
||||
* of session. Also, offer nice recovery options specific to each of the above
|
||||
* failure modes.
|
||||
*/
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -28,7 +28,9 @@ typedef struct _MsmSession MsmSession;
|
||||
|
||||
MsmSession* msm_session_get (const char *name);
|
||||
MsmSession* msm_session_get_failsafe (void);
|
||||
void msm_session_save (MsmSession *session);
|
||||
void msm_session_save (MsmSession *session,
|
||||
MsmServer *server);
|
||||
void msm_session_clear (MsmSession *session);
|
||||
void msm_session_update_client (MsmSession *session,
|
||||
MsmClient *client);
|
||||
void msm_session_remove_client (MsmSession *session,
|
||||
|
@ -21,6 +21,13 @@
|
||||
|
||||
#include "util.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
void
|
||||
msm_fatal (const char *format, ...)
|
||||
@ -130,7 +137,7 @@ msm_create_dir_and_parents (const char *dir,
|
||||
const char*
|
||||
msm_get_work_directory (void)
|
||||
{
|
||||
static char *dir = NULL;
|
||||
static const char *dir = NULL;
|
||||
|
||||
if (dir == NULL)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user