summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/Makefile.am65
-rw-r--r--common/gdm-common-config.c488
-rw-r--r--common/gdm-common-config.h75
-rw-r--r--common/gdm-common.c304
-rw-r--r--common/gdm-common.h86
-rw-r--r--common/gdm-config.c1487
-rw-r--r--common/gdm-config.h212
-rw-r--r--common/gdm-log.c191
-rw-r--r--common/gdm-log.h49
-rw-r--r--common/test-config.c303
-rw-r--r--common/test-log.c60
-rw-r--r--common/ve-signal.c160
-rw-r--r--common/ve-signal.h46
13 files changed, 0 insertions, 3526 deletions
diff --git a/common/Makefile.am b/common/Makefile.am
deleted file mode 100644
index ed049d63..00000000
--- a/common/Makefile.am
+++ /dev/null
@@ -1,65 +0,0 @@
-## Process this file with automake to produce Makefile.in
-
-NULL =
-
-INCLUDES = \
- -I. \
- -I.. \
- -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
- -DAUTHDIR=\"$(authdir)\" \
- -DBINDIR=\"$(bindir)\" \
- -DDATADIR=\"$(datadir)\" \
- -DDMCONFDIR=\"$(dmconfdir)\" \
- -DGDMCONFDIR=\"$(gdmconfdir)\" \
- -DGDMLOCALEDIR=\"$(gdmlocaledir)\" \
- -DLIBDIR=\"$(libdir)\" \
- -DLIBEXECDIR=\"$(libexecdir)\" \
- -DLOGDIR=\"$(logdir)\" \
- -DPIXMAPDIR=\"$(pixmapdir)\" \
- -DSBINDIR=\"$(sbindir)\" \
- -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
- -DGDM_DEFAULTS_CONF=\"$(GDM_DEFAULTS_CONF)\" \
- -DGDM_CUSTOM_CONF=\"$(GDM_CUSTOM_CONF)\" \
- -DGDM_OLD_CONF=\"$(GDM_OLD_CONF)\" \
- $(GLIB_CFLAGS)
-
-noinst_LIBRARIES = \
- libgdmcommon.a \
- $(null)
-
-libgdmcommon_a_SOURCES = \
- gdm-common.h \
- gdm-common.c \
- gdm-common-config.h \
- gdm-common-config.c \
- gdm-config.h \
- gdm-config.c \
- gdm-log.h \
- gdm-log.c \
- ve-signal.h \
- ve-signal.c \
- $(NULL)
-
-noinst_PROGRAMS = \
- test-config \
- test-log \
- $(NULL)
-
-test_config_SOURCES = \
- $(top_builddir)/daemon/gdm-daemon-config-entries.h \
- test-config.c \
- $(NULL)
-
-test_config_LDADD = \
- libgdmcommon.a \
- $(GLIB_LIBS) \
- $(NULL)
-
-test_log_SOURCES = \
- test-log.c \
- $(NULL)
-
-test_log_LDADD = \
- libgdmcommon.a \
- $(GLIB_LIBS) \
- $(NULL)
diff --git a/common/gdm-common-config.c b/common/gdm-common-config.c
deleted file mode 100644
index 22831e79..00000000
--- a/common/gdm-common-config.c
+++ /dev/null
@@ -1,488 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <locale.h>
-#include <syslog.h>
-
-#include <glib.h>
-
-#include "gdm-common-config.h"
-
-gboolean
-gdm_common_config_parse_key_string (const char *keystring,
- char **group,
- char **key,
- char **locale,
- char **value)
-{
- char **split1;
- char **split2;
- char *g;
- char *k;
- char *l;
- char *v;
- char *tmp1;
- char *tmp2;
- gboolean ret;
-
- g_return_val_if_fail (keystring != NULL, FALSE);
-
- ret = FALSE;
- g = k = v = l = NULL;
- split1 = split2 = NULL;
-
- g_debug ("Attempting to parse key string: %s", keystring);
-
- split1 = g_strsplit (keystring, "/", 2);
- if (split1 == NULL || split1 [0] == NULL || split1 [1] == NULL) {
- goto out;
- }
-
- g = split1 [0];
-
- split2 = g_strsplit (split1 [1], "=", 2);
- if (split2 == NULL) {
- k = split1 [1];
- } else {
- k = split2 [0];
- v = split2 [1];
- }
-
- /* trim off the locale */
- tmp1 = strchr (k, '[');
- tmp2 = strchr (k, ']');
- if (tmp1 != NULL && tmp2 != NULL && tmp2 > tmp1) {
- l = g_strndup (tmp1 + 1, tmp2 - tmp1 - 1);
- *tmp1 = '\0';
- }
-
- ret = TRUE;
- out:
- if (group != NULL) {
- *group = g_strdup (g);
- }
- if (key != NULL) {
- *key = g_strdup (k);
- }
- if (locale != NULL) {
- *locale = g_strdup (l);
- }
- if (value != NULL) {
- *value = g_strdup (v);
- }
-
- g_strfreev (split1);
- g_strfreev (split2);
-
- return ret;
-}
-
-GKeyFile *
-gdm_common_config_load (const char *filename,
- GError **error)
-{
- GKeyFile *config;
- GError *local_error;
- gboolean res;
-
- config = g_key_file_new ();
-
- local_error = NULL;
- res = g_key_file_load_from_file (config,
- filename,
- G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
- &local_error);
- if (! res) {
- g_propagate_error (error, local_error);
- g_key_file_free (config);
- return NULL;
- }
-
- return config;
-}
-
-GKeyFile *
-gdm_common_config_load_from_dirs (const char *filename,
- const char **dirs,
- GError **error)
-{
- GKeyFile *config = NULL;
- int i;
-
- /* FIXME: hope to have g_key_file_load_from_dirs
- see GNOME bug #355334
- */
-
- for (i = 0; dirs != NULL && dirs[i] != NULL; i++) {
- char *path;
-
- path = g_build_filename (dirs[i], filename, NULL);
- config = gdm_common_config_load (path, NULL);
- g_free (path);
- if (config != NULL) {
- break;
- }
- }
-
- if (config == NULL) {
- g_set_error (error,
- G_KEY_FILE_ERROR,
- G_KEY_FILE_ERROR_NOT_FOUND,
- "Unable to find file in specified directories");
- }
-
- return config;
-}
-
-gboolean
-gdm_common_config_save (GKeyFile *config,
- const char *filename,
- GError **error)
-{
- GError *local_error;
- gboolean res;
- char *contents;
- gsize length;
-
- local_error = NULL;
- contents = g_key_file_to_data (config, &length, &local_error);
- if (local_error != NULL) {
- g_propagate_error (error, local_error);
- return FALSE;
- }
-
- local_error = NULL;
- res = g_file_set_contents (filename,
- contents,
- length,
- &local_error);
- if (local_error != NULL) {
- g_propagate_error (error, local_error);
- g_free (contents);
- return FALSE;
- }
-
- g_free (contents);
- return TRUE;
-}
-
-gboolean
-gdm_common_config_get_int (GKeyFile *config,
- const char *keystring,
- int *value,
- GError **error)
-{
- char *group;
- char *key;
- char *default_value;
- int val;
- GError *local_error;
- gboolean ret;
-
- ret = FALSE;
-
- group = key = default_value = NULL;
- if (! gdm_common_config_parse_key_string (keystring, &group, &key, NULL, &default_value))
- return FALSE;
-
- local_error = NULL;
- val = g_key_file_get_integer (config,
- group,
- key,
- &local_error);
- if (local_error != NULL) {
- /* use the default */
- if (default_value != NULL) {
- ret = TRUE;
- g_error_free (local_error);
- val = atoi (default_value);
- } else {
- val = 0;
- g_propagate_error (error, local_error);
- }
- } else {
- ret = TRUE;
- }
-
- *value = val;
-
- g_free (key);
- g_free (group);
- g_free (default_value);
-
- return ret;
-}
-
-gboolean
-gdm_common_config_get_translated_string (GKeyFile *config,
- const char *keystring,
- char **value,
- GError **error)
-{
- char *group;
- char *key;
- char *default_value;
- char *val;
- const char * const *langs;
- int i;
- gboolean ret;
-
- ret = FALSE;
-
- val = NULL;
-
- group = key = default_value = NULL;
- if (! gdm_common_config_parse_key_string (keystring, &group, &key, NULL, &default_value))
- return FALSE;
-
- langs = g_get_language_names ();
-
- for (i = 0; langs[i] != NULL; i++) {
- const char *locale;
- locale = langs[i];
-
- val = g_key_file_get_locale_string (config,
- group,
- key,
- locale,
- NULL);
- if (val != NULL) {
- break;
- }
- }
-
- if (val == NULL) {
- /* use the default */
- if (default_value != NULL) {
- val = g_strdup (default_value);
- ret = TRUE;
- }
- } else {
- ret = TRUE;
- }
-
- *value = val;
-
- g_free (key);
- g_free (group);
- g_free (default_value);
-
- return ret;
-}
-
-gboolean
-gdm_common_config_get_string (GKeyFile *config,
- const char *keystring,
- char **value,
- GError **error)
-{
- char *group;
- char *key;
- char *default_value;
- char *val;
- GError *local_error;
- gboolean ret;
-
- ret = FALSE;
-
- group = key = default_value = NULL;
- if (! gdm_common_config_parse_key_string (keystring, &group, &key, NULL, &default_value)) {
- g_set_error (error,
- G_KEY_FILE_ERROR,
- G_KEY_FILE_ERROR_PARSE,
- "Unable to parse key: %s",
- keystring);
- return FALSE;
- }
-
- local_error = NULL;
- val = g_key_file_get_string (config,
- group,
- key,
- &local_error);
- if (local_error != NULL) {
- /* use the default */
- if (default_value != NULL) {
- val = g_strdup (default_value);
- ret = TRUE;
- g_error_free (local_error);
- } else {
- g_propagate_error (error, local_error);
- }
- } else {
- ret = TRUE;
- }
-
- *value = val;
-
- g_free (key);
- g_free (group);
- g_free (default_value);
-
- return ret;
-}
-
-gboolean
-gdm_common_config_get_boolean (GKeyFile *config,
- const char *keystring,
- gboolean *value,
- GError **error)
-{
- char *group;
- char *key;
- char *default_value;
- gboolean val;
- GError *local_error;
- gboolean ret;
-
- ret = FALSE;
-
- group = key = default_value = NULL;
- if (! gdm_common_config_parse_key_string (keystring, &group, &key, NULL, &default_value))
- return FALSE;
-
- local_error = NULL;
- val = g_key_file_get_boolean (config,
- group,
- key,
- &local_error);
- if (local_error != NULL) {
- /* use the default */
- if (default_value != NULL) {
- if ((default_value[0] == 'T' ||
- default_value[0] == 't' ||
- default_value[0] == 'Y' ||
- default_value[0] == 'y' ||
- atoi (default_value) != 0)) {
- val = TRUE;
- } else {
- val = FALSE;
- }
- ret = TRUE;
- g_error_free (local_error);
- } else {
- g_propagate_error (error, local_error);
- }
- } else {
- ret = TRUE;
- }
-
- *value = val;
-
- g_free (key);
- g_free (group);
- g_free (default_value);
-
- return ret;
-}
-
-void
-gdm_common_config_set_string (GKeyFile *config,
- const char *keystring,
- const char *value)
-{
- char *group;
- char *key;
- char *default_value;
-
- group = key = default_value = NULL;
- if (! gdm_common_config_parse_key_string (keystring, &group, &key, NULL, &default_value)) {
- return;
- }
-
- g_key_file_set_string (config, group, key, value);
-
- g_free (key);
- g_free (group);
- g_free (default_value);
-}
-
-void
-gdm_common_config_set_boolean (GKeyFile *config,
- const char *keystring,
- gboolean value)
-{
- char *group;
- char *key;
- char *default_value;
-
- group = key = default_value = NULL;
- if (! gdm_common_config_parse_key_string (keystring, &group, &key, NULL, &default_value)) {
- return;
- }
-
- g_key_file_set_boolean (config, group, key, value);
-
- g_free (key);
- g_free (group);
- g_free (default_value);
-}
-
-void
-gdm_common_config_set_int (GKeyFile *config,
- const char *keystring,
- int value)
-{
- char *group;
- char *key;
- char *default_value;
-
- group = key = default_value = NULL;
- if (! gdm_common_config_parse_key_string (keystring, &group, &key, NULL, &default_value)) {
- return;
- }
-
- g_key_file_set_integer (config, group, key, value);
-
- g_free (key);
- g_free (group);
- g_free (default_value);
-}
-
-void
-gdm_common_config_remove_key (GKeyFile *config,
- const char *keystring,
- GError **error)
-{
- char *group;
- char *key;
- char *default_value;
- GError *local_error;
-
- group = key = default_value = NULL;
- if (! gdm_common_config_parse_key_string (keystring, &group, &key, NULL, &default_value)) {
- return;
- }
-
- local_error = NULL;
- g_key_file_remove_key (config, group, key, &local_error);
- if (local_error != NULL) {
- g_propagate_error (error, local_error);
- }
-
- g_free (key);
- g_free (group);
- g_free (default_value);
-}
diff --git a/common/gdm-common-config.h b/common/gdm-common-config.h
deleted file mode 100644
index b03ed46e..00000000
--- a/common/gdm-common-config.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef _GDM_COMMON_CONFIG_H
-#define _GDM_COMMON_CONFIG_H
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-GKeyFile * gdm_common_config_load (const char *filename,
- GError **error);
-GKeyFile * gdm_common_config_load_from_dirs (const char *filename,
- const char **dirs,
- GError **error);
-gboolean gdm_common_config_save (GKeyFile *config,
- const char *filename,
- GError **error);
-
-gboolean gdm_common_config_get_string (GKeyFile *config,
- const char *keystring,
- char **value,
- GError **error);
-gboolean gdm_common_config_get_translated_string (GKeyFile *config,
- const char *keystring,
- char **value,
- GError **error);
-gboolean gdm_common_config_get_int (GKeyFile *config,
- const char *keystring,
- int *value,
- GError **error);
-gboolean gdm_common_config_get_boolean (GKeyFile *config,
- const char *keystring,
- gboolean *value,
- GError **error);
-gboolean gdm_common_config_parse_key_string (const char *keystring,
- char **group,
- char **key,
- char **locale,
- char **value);
-
-void gdm_common_config_set_string (GKeyFile *config,
- const char *keystring,
- const char *value);
-void gdm_common_config_set_boolean (GKeyFile *config,
- const char *keystring,
- gboolean value);
-void gdm_common_config_set_int (GKeyFile *config,
- const char *keystring,
- int value);
-
-void gdm_common_config_remove_key (GKeyFile *config,
- const char *keystring,
- GError **error);
-
-G_END_DECLS
-
-#endif /* _GDM_COMMON_CONFIG_H */
diff --git a/common/gdm-common.c b/common/gdm-common.c
deleted file mode 100644
index 5dcf9136..00000000
--- a/common/gdm-common.c
+++ /dev/null
@@ -1,304 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * (c) 2000 Eazel, Inc.
- * (c) 2001,2002 George Lebl
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <locale.h>
-#include <netinet/in.h>
-
-#ifdef HAVE_CRT_EXTERNS_H
-#include <crt_externs.h>
-#endif
-
-#include "gdm-common.h"
-
-static gboolean
-v4_v4_equal (const struct sockaddr_in *a,
- const struct sockaddr_in *b)
-{
- return a->sin_addr.s_addr == b->sin_addr.s_addr;
-}
-
-#ifdef ENABLE_IPV6
-static gboolean
-v6_v6_equal (struct sockaddr_in6 *a,
- struct sockaddr_in6 *b)
-{
- return IN6_ARE_ADDR_EQUAL (&a->sin6_addr, &b->sin6_addr);
-}
-#endif
-
-#define SA(__s) ((struct sockaddr *) __s)
-#define SIN(__s) ((struct sockaddr_in *) __s)
-#define SIN6(__s) ((struct sockaddr_in6 *) __s)
-
-gboolean
-gdm_address_equal (struct sockaddr_storage *sa,
- struct sockaddr_storage *sb)
-{
- guint8 fam_a;
- guint8 fam_b;
-
- g_return_val_if_fail (sa != NULL, FALSE);
- g_return_val_if_fail (sb != NULL, FALSE);
-
- fam_a = sa->ss_family;
- fam_b = sb->ss_family;
-
- if (fam_a == AF_INET && fam_b == AF_INET) {
- return v4_v4_equal (SIN (sa), SIN (sb));
- }
-#ifdef ENABLE_IPV6
- else if (fam_a == AF_INET6 && fam_b == AF_INET6) {
- return v6_v6_equal (SIN6 (sa), SIN6 (sb));
- }
-#endif
- return FALSE;
-}
-
-gboolean
-gdm_address_is_loopback (struct sockaddr_storage *sa)
-{
- switch(sa->ss_family){
-#ifdef AF_INET6
- case AF_INET6:
- return IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *)sa)->sin6_addr);
- break;
-#endif
- case AF_INET:
- return (INADDR_LOOPBACK == htonl (((struct sockaddr_in *)sa)->sin_addr.s_addr));
- break;
- default:
- break;
- }
-
- return FALSE;
-}
-
-void
-gdm_address_get_info (struct sockaddr_storage *ss,
- char **hostp,
- char **servp)
-{
- char host [NI_MAXHOST];
- char serv [NI_MAXSERV];
-
- host [0] = '\0';
- serv [0] = '\0';
- getnameinfo ((const struct sockaddr *)ss,
- sizeof (struct sockaddr_storage),
- host, sizeof (host),
- serv, sizeof (serv),
- NI_NUMERICHOST | NI_NUMERICSERV);
-
- if (servp != NULL) {
- *servp = g_strdup (serv);
- }
- if (hostp != NULL) {
- *hostp = g_strdup (host);
- }
-}
-
-/**
- * ve_clearenv:
- *
- * Description: Clears out the environment completely.
- * In case there is no native implementation of clearenv,
- * this could cause leaks depending on the implementation
- * of environment.
- *
- **/
-void
-ve_clearenv (void)
-{
-#ifdef HAVE_CLEARENV
- clearenv ();
-#else
-
-#ifdef HAVE__NSGETENVIRON
-#define environ (*_NSGetEnviron())
-#else
- extern char **environ;
-#endif
-
- if (environ != NULL)
- environ[0] = NULL;
-#endif
-}
-
-char *
-ve_first_word (const char *s)
-{
- int argc;
- char **argv;
- char *ret;
-
- if (s == NULL)
- return NULL;
-
- if ( ! g_shell_parse_argv (s, &argc, &argv, NULL)) {
- char *p;
- ret = g_strdup (s);
- p = strchr (ret, ' ');
- if (p != NULL)
- *p = '\0';
- return ret;
- }
-
- ret = g_strdup (argv[0]);
-
- g_strfreev (argv);
-
- return ret;
-}
-
-gboolean
-ve_first_word_executable (const char *s, gboolean only_existance)
-{
- char *bin = ve_first_word (s);
- if (bin == NULL)
- return FALSE;
- if (g_access (bin, only_existance ? F_OK : X_OK) == 0) {
- g_free (bin);
- return TRUE;
- } else {
- g_free (bin);
- return FALSE;
- }
-}
-
-char *
-ve_get_first_working_command (const char *list,
- gboolean only_existance)
-{
- int i;
- char **vector;
- char *ret = NULL;
-
- if (list == NULL)
- return NULL;
-
- vector = g_strsplit (list, ";", -1);
- for (i = 0; vector[i] != NULL; i++) {
- if (ve_first_word_executable (vector[i],
- only_existance)) {
- ret = g_strdup (vector[i]);
- break;
- }
- }
- g_strfreev (vector);
- return ret;
-}
-
-char *
-ve_locale_to_utf8 (const char *str)
-{
- char *ret = g_locale_to_utf8 (str, -1, NULL, NULL, NULL);
-
- if (ret == NULL) {
- g_warning ("string not in proper locale encoding: \"%s\"", str);
- return g_strdup (str);
- } else {
- return ret;
- }
-}
-
-char *
-ve_locale_from_utf8 (const char *str)
-{
- char *ret = g_locale_from_utf8 (str, -1, NULL, NULL, NULL);
-
- if (ret == NULL) {
- g_warning ("string not in proper utf8 encoding: \"%s\"", str);
- return g_strdup (str);
- } else {
- return ret;
- }
-}
-
-char *
-ve_filename_to_utf8 (const char *str)
-{
- char *ret = g_filename_to_utf8 (str, -1, NULL, NULL, NULL);
- if (ret == NULL) {
- g_warning ("string not in proper locale encoding: \"%s\"", str);
- return g_strdup (str);
- } else {
- return ret;
- }
-}
-
-char *
-ve_filename_from_utf8 (const char *str)
-{
- char *ret = g_filename_from_utf8 (str, -1, NULL, NULL, NULL);
- if (ret == NULL) {
- g_warning ("string not in proper utf8 encoding: \"%s\"", str);
- return g_strdup (str);
- } else {
- return ret;
- }
-}
-
-pid_t
-ve_waitpid_no_signal (pid_t pid, int *status, int options)
-{
- pid_t ret;
-
- for (;;) {
- ret = waitpid (pid, status, options);
- if (ret == 0)
- return 0;
- if (errno != EINTR)
- return ret;
- }
-}
-
-gboolean
-ve_locale_exists (const char *loc)
-{
- gboolean ret;
- char *old = g_strdup (setlocale (LC_MESSAGES, NULL));
- if (setlocale (LC_MESSAGES, loc) != NULL)
- ret = TRUE;
- else
- ret = FALSE;
- setlocale (LC_MESSAGES, old);
- g_free (old);
- return ret;
-}
-
-int
-gdm_vector_len (char * const *v)
-{
- int i;
-
- if (v == NULL)
- return 0;
-
- i = g_strv_length (v);
-
- return i;
-}
-
diff --git a/common/gdm-common.h b/common/gdm-common.h
deleted file mode 100644
index 12e5a70b..00000000
--- a/common/gdm-common.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * (c) 2000 Eazel, Inc.
- * (c) 2001,2002 George Lebl
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef _GDM_COMMON_H
-#define _GDM_COMMON_H
-
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <time.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <locale.h>
-#include <netdb.h>
-
-#include "ve-signal.h"
-#include "gdm-common-config.h"
-#include "gdm-config.h"
-
-G_BEGIN_DECLS
-
-
-gboolean gdm_address_equal (struct sockaddr_storage *sa,
- struct sockaddr_storage *sb);
-gboolean gdm_address_is_loopback (struct sockaddr_storage *sa);
-void gdm_address_get_info (struct sockaddr_storage *sa,
- char **host,
- char **port);
-int gdm_vector_len (char * const *v);
-
-void ve_clearenv (void);
-char * ve_first_word (const char *s);
-gboolean ve_first_word_executable (const char *s,
- gboolean only_existance);
-
-/* Gets the first existing command out of a list separated by semicolons */
-char * ve_get_first_working_command (const char *list,
- gboolean only_existance);
-
-#define ve_string_empty(x) ((x)==NULL||(x)[0]=='\0')
-#define ve_sure_string(x) ((x)!=NULL?(x):"")
-
-/* These two functions will ALWAYS return a non-NULL string,
- * if there is an error, they return the unconverted string */
-char * ve_locale_to_utf8 (const char *str);
-char * ve_locale_from_utf8 (const char *str);
-
-/* These two functions will ALWAYS return a non-NULL string,
- * if there is an error, they return the unconverted string */
-char * ve_filename_to_utf8 (const char *str);
-char * ve_filename_from_utf8 (const char *str);
-
-/* function which doesn't stop on signals */
-pid_t ve_waitpid_no_signal (pid_t pid, int *status, int options);
-
-/* Testing for existance of a certain locale */
-gboolean ve_locale_exists (const char *loc);
-
-#define VE_IGNORE_EINTR(expr) \
- do { \
- errno = 0; \
- expr; \
- } while G_UNLIKELY (errno == EINTR);
-
-G_END_DECLS
-
-#endif /* _GDM_COMMON_H */
diff --git a/common/gdm-config.c b/common/gdm-config.c
deleted file mode 100644
index b21ab7ff..00000000
--- a/common/gdm-config.c
+++ /dev/null
@@ -1,1487 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <locale.h>
-#include <syslog.h>
-#include <errno.h>
-#include <sys/stat.h>
-
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <glib/gi18n.h>
-
-#include "gdm-config.h"
-
-struct _GdmConfig
-{
- char *mandatory_filename;
- char *default_filename;
- char *custom_filename;
-
- gboolean mandatory_loaded;
- gboolean default_loaded;
- gboolean custom_loaded;
-
- GKeyFile *mandatory_key_file;
- GKeyFile *default_key_file;
- GKeyFile *custom_key_file;
-
- time_t mandatory_mtime;
- time_t default_mtime;
- time_t custom_mtime;
-
- GPtrArray *entries;
-
- GHashTable *value_hash;
-
- GdmConfigFunc validate_func;
- gpointer validate_func_data;
- GdmConfigFunc notify_func;
- gpointer notify_func_data;
-};
-
-
-typedef struct _GdmConfigRealValue
-{
- GdmConfigValueType type;
- union {
- gboolean bool;
- int integer;
- char *str;
- char **array;
- } val;
-} GdmConfigRealValue;
-
-#define REAL_VALUE(x) ((GdmConfigRealValue *)(x))
-
-GQuark
-gdm_config_error_quark (void)
-{
- return g_quark_from_static_string ("gdm-config-error-quark");
-}
-
-GdmConfigEntry *
-gdm_config_entry_copy (const GdmConfigEntry *src)
-{
- GdmConfigEntry *dest;
-
- dest = g_new0 (GdmConfigEntry, 1);
- dest->group = g_strdup (src->group);
- dest->key = g_strdup (src->key);
- dest->default_value = g_strdup (src->default_value);
- dest->type = src->type;
- dest->id = src->id;
-
- return dest;
-}
-
-void
-gdm_config_entry_free (GdmConfigEntry *entry)
-{
- g_free (entry->group);
- g_free (entry->key);
- g_free (entry->default_value);
-
- g_free (entry);
-}
-
-GdmConfigValue *
-gdm_config_value_new (GdmConfigValueType type)
-{
- GdmConfigValue *value;
-
- g_return_val_if_fail (type != GDM_CONFIG_VALUE_INVALID, NULL);
-
- value = (GdmConfigValue *) g_slice_new0 (GdmConfigRealValue);
- value->type = type;
-
- return value;
-}
-
-void
-gdm_config_value_free (GdmConfigValue *value)
-{
- GdmConfigRealValue *real;
-
- real = REAL_VALUE (value);
-
- switch (real->type) {
- case GDM_CONFIG_VALUE_INVALID:
- case GDM_CONFIG_VALUE_BOOL:
- case GDM_CONFIG_VALUE_INT:
- break;
- case GDM_CONFIG_VALUE_STRING:
- case GDM_CONFIG_VALUE_LOCALE_STRING:
- g_free (real->val.str);
- break;
- case GDM_CONFIG_VALUE_STRING_ARRAY:
- case GDM_CONFIG_VALUE_LOCALE_STRING_ARRAY:
- g_strfreev (real->val.array);
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
- g_slice_free (GdmConfigRealValue, real);
-}
-
-static void
-set_string (char **dest,
- const char *src)
-{
- if (*dest != NULL) {
- g_free (*dest);
- }
-
- *dest = src ? g_strdup (src) : NULL;
-}
-
-static void
-set_string_array (char ***dest,
- const char **src)
-{
- if (*dest != NULL) {
- g_strfreev (*dest);
- }
-
- *dest = src ? g_strdupv ((char **)src) : NULL;
-}
-
-GdmConfigValue *
-gdm_config_value_copy (const GdmConfigValue *src)
-{
- GdmConfigRealValue *dest;
- GdmConfigRealValue *real;
-
- g_return_val_if_fail (src != NULL, NULL);
-
- real = REAL_VALUE (src);
- dest = REAL_VALUE (gdm_config_value_new (src->type));
-
- switch (real->type) {
- case GDM_CONFIG_VALUE_INT:
- case GDM_CONFIG_VALUE_BOOL:
- case GDM_CONFIG_VALUE_INVALID:
- dest->val = real->val;
- break;
- case GDM_CONFIG_VALUE_STRING:
- case GDM_CONFIG_VALUE_LOCALE_STRING:
- set_string (&dest->val.str, real->val.str);
- break;
- case GDM_CONFIG_VALUE_STRING_ARRAY:
- case GDM_CONFIG_VALUE_LOCALE_STRING_ARRAY:
- set_string_array (&dest->val.array, (const char **)real->val.array);
- break;
- default:
- g_assert_not_reached();
- }
-
- return (GdmConfigValue *) dest;
-}
-
-const char *
-gdm_config_value_get_string (const GdmConfigValue *value)
-{
- g_return_val_if_fail (value != NULL, NULL);
- g_return_val_if_fail (value->type == GDM_CONFIG_VALUE_STRING, NULL);
- return REAL_VALUE (value)->val.str;
-}
-
-const char *
-gdm_config_value_get_locale_string (const GdmConfigValue *value)
-{
- g_return_val_if_fail (value != NULL, NULL);
- g_return_val_if_fail (value->type == GDM_CONFIG_VALUE_LOCALE_STRING, NULL);
- return REAL_VALUE (value)->val.str;
-}
-
-const char **
-gdm_config_value_get_string_array (const GdmConfigValue *value)
-{
- g_return_val_if_fail (value != NULL, NULL);
- g_return_val_if_fail (value->type == GDM_CONFIG_VALUE_STRING_ARRAY, NULL);
- return (const char **)REAL_VALUE (value)->val.array;
-}
-
-gboolean
-gdm_config_value_get_bool (const GdmConfigValue *value)
-{
- g_return_val_if_fail (value != NULL, FALSE);
- g_return_val_if_fail (value->type == GDM_CONFIG_VALUE_BOOL, FALSE);
- return REAL_VALUE (value)->val.bool;
-}
-
-int
-gdm_config_value_get_int (const GdmConfigValue *value)
-{
- g_return_val_if_fail (value != NULL, 0);
- g_return_val_if_fail (value->type == GDM_CONFIG_VALUE_INT, 0);
- return REAL_VALUE (value)->val.integer;
-}
-
-static gint
-safe_strcmp (const char *a,
- const char *b)
-{
- return strcmp (a ? a : "", b ? b : "");
-}
-
-/* based on code from gconf */
-int
-gdm_config_value_compare (const GdmConfigValue *value_a,
- const GdmConfigValue *value_b)
-{
- g_return_val_if_fail (value_a != NULL, 0);
- g_return_val_if_fail (value_b != NULL, 0);
-
- if (value_a->type < value_b->type) {
- return -1;
- } else if (value_a->type > value_b->type) {
- return 1;
- }
-
- switch (value_a->type) {
- case GDM_CONFIG_VALUE_INT:
- if (gdm_config_value_get_int (value_a) < gdm_config_value_get_int (value_b)) {
- return -1;
- } else if (gdm_config_value_get_int (value_a) > gdm_config_value_get_int (value_b)) {
- return 1;
- } else {
- return 0;
- }
- case GDM_CONFIG_VALUE_STRING:
- return safe_strcmp (gdm_config_value_get_string (value_a),
- gdm_config_value_get_string (value_b));
- case GDM_CONFIG_VALUE_LOCALE_STRING:
- return safe_strcmp (gdm_config_value_get_locale_string (value_a),
- gdm_config_value_get_locale_string (value_b));
- case GDM_CONFIG_VALUE_STRING_ARRAY:
- case GDM_CONFIG_VALUE_LOCALE_STRING_ARRAY:
- {
- char *str_a;
- char *str_b;
- int res;
-
- str_a = gdm_config_value_to_string (value_a);
- str_b = gdm_config_value_to_string (value_a);
- res = safe_strcmp (str_a, str_b);
- g_free (str_a);
- g_free (str_b);
-
- return res;
- }
- case GDM_CONFIG_VALUE_BOOL:
- if (gdm_config_value_get_bool (value_a) == gdm_config_value_get_bool (value_b)) {
- return 0;
- } else if (gdm_config_value_get_bool (value_a)) {
- return 1;
- } else {
- return -1;
- }
- case GDM_CONFIG_VALUE_INVALID:
- default:
- g_assert_not_reached ();
- break;
- }
-
- return 0;
-}
-
-/* based on code from gconf */
-GdmConfigValue *
-gdm_config_value_new_from_string (GdmConfigValueType type,
- const char *value_str,
- GError **error)
-{
- GdmConfigValue *value;
-
- g_return_val_if_fail (type != GDM_CONFIG_VALUE_INVALID, NULL);
- g_return_val_if_fail (value_str != NULL, NULL);
-
- value = gdm_config_value_new (type);
-
- switch (value->type) {
- case GDM_CONFIG_VALUE_INT:
- {
- char* endptr = NULL;
- glong result;
-
- errno = 0;
- result = strtol (value_str, &endptr, 10);
- if (endptr == value_str) {
- g_set_error (error,
- GDM_CONFIG_ERROR,
- GDM_CONFIG_ERROR_PARSE_ERROR,
- _("Didn't understand `%s' (expected integer)"),
- value_str);
- gdm_config_value_free (value);
- value = NULL;
- } else if (errno == ERANGE) {
- g_set_error (error,
- GDM_CONFIG_ERROR,
- GDM_CONFIG_ERROR_PARSE_ERROR,
- _("Integer `%s' is too large or small"),
- value_str);
- gdm_config_value_free (value);
- value = NULL;
- } else {
- gdm_config_value_set_int (value, result);
- }
- }
- break;
- case GDM_CONFIG_VALUE_BOOL:
- switch (*value_str) {
- case 't':
- case 'T':
- case '1':
- case 'y':
- case 'Y':
- gdm_config_value_set_bool (value, TRUE);
- break;
-
- case 'f':
- case 'F':
- case '0':
- case 'n':
- case 'N':
- gdm_config_value_set_bool (value, FALSE);
- break;
- default:
- g_set_error (error,
- GDM_CONFIG_ERROR,
- GDM_CONFIG_ERROR_PARSE_ERROR,
- _("Didn't understand `%s' (expected true or false)"),
- value_str);
- gdm_config_value_free (value);
- value = NULL;
- break;
- }
- break;
- case GDM_CONFIG_VALUE_STRING:
- if (! g_utf8_validate (value_str, -1, NULL)) {
- g_set_error (error,
- GDM_CONFIG_ERROR,
- GDM_CONFIG_ERROR_PARSE_ERROR,
- _("Text contains invalid UTF-8"));
- gdm_config_value_free (value);
- value = NULL;
- } else {
- gdm_config_value_set_string (value, value_str);
- }
- break;
- case GDM_CONFIG_VALUE_LOCALE_STRING:
- if (! g_utf8_validate (value_str, -1, NULL)) {
- g_set_error (error,
- GDM_CONFIG_ERROR,
- GDM_CONFIG_ERROR_PARSE_ERROR,
- _("Text contains invalid UTF-8"));
- gdm_config_value_free (value);
- value = NULL;
- } else {
- gdm_config_value_set_locale_string (value, value_str);
- }
- break;
- case GDM_CONFIG_VALUE_STRING_ARRAY:
- if (! g_utf8_validate (value_str, -1, NULL)) {
- g_set_error (error,
- GDM_CONFIG_ERROR,
- GDM_CONFIG_ERROR_PARSE_ERROR,
- _("Text contains invalid UTF-8"));
- gdm_config_value_free (value);
- value = NULL;
- } else {
- char **split;
- split = g_strsplit (value_str, ";", -1);
- gdm_config_value_set_string_array (value, (const char **)split);
- g_strfreev (split);
- }
- break;
- case GDM_CONFIG_VALUE_LOCALE_STRING_ARRAY:
- if (! g_utf8_validate (value_str, -1, NULL)) {
- g_set_error (error,
- GDM_CONFIG_ERROR,
- GDM_CONFIG_ERROR_PARSE_ERROR,
- _("Text contains invalid UTF-8"));
- gdm_config_value_free (value);
- value = NULL;
- } else {
- char **split;
- split = g_strsplit (value_str, ";", -1);
- gdm_config_value_set_locale_string_array (value, (const char **)split);
- g_strfreev (split);
- }
- break;
- case GDM_CONFIG_VALUE_INVALID:
- default:
- g_assert_not_reached ();
- break;
- }
-
- return value;
-}
-
-void
-gdm_config_value_set_string_array (GdmConfigValue *value,
- const char **array)
-{
- GdmConfigRealValue *real;
-
- g_return_if_fail (value != NULL);
- g_return_if_fail (value->type == GDM_CONFIG_VALUE_STRING_ARRAY);
-
- real = REAL_VALUE (value);
-
- g_strfreev (real->val.array);
- real->val.array = g_strdupv ((char **)array);
-}
-
-void
-gdm_config_value_set_locale_string_array (GdmConfigValue *value,
- const char **array)
-{
- GdmConfigRealValue *real;
-
- g_return_if_fail (value != NULL);
- g_return_if_fail (value->type == GDM_CONFIG_VALUE_LOCALE_STRING_ARRAY);
-
- real = REAL_VALUE (value);
-
- g_strfreev (real->val.array);
- real->val.array = g_strdupv ((char **)array);
-}
-
-void
-gdm_config_value_set_int (GdmConfigValue *value,
- int integer)
-{
- GdmConfigRealValue *real;
-
- g_return_if_fail (value != NULL);
- g_return_if_fail (value->type == GDM_CONFIG_VALUE_INT);
-
- real = REAL_VALUE (value);
-
- real->val.integer = integer;
-}
-
-void
-gdm_config_value_set_bool (GdmConfigValue *value,
- gboolean bool)
-{
- GdmConfigRealValue *real;
-
- g_return_if_fail (value != NULL);
- g_return_if_fail (value->type == GDM_CONFIG_VALUE_BOOL);
-
- real = REAL_VALUE (value);
-
- real->val.bool = bool;
-}
-
-void
-gdm_config_value_set_string (GdmConfigValue *value,
- const char *str)
-{
- GdmConfigRealValue *real;
-
- g_return_if_fail (value != NULL);
- g_return_if_fail (value->type == GDM_CONFIG_VALUE_STRING);
-
- real = REAL_VALUE (value);
-
- g_free (real->val.str);
- real->val.str = g_strdup (str);
-}
-
-void
-gdm_config_value_set_locale_string (GdmConfigValue *value,
- const char *str)
-{
- GdmConfigRealValue *real;
-
- g_return_if_fail (value != NULL);
- g_return_if_fail (value->type == GDM_CONFIG_VALUE_LOCALE_STRING);
-
- real = REAL_VALUE (value);
-
- g_free (real->val.str);
- real->val.str = g_strdup (str);
-}
-
-char *
-gdm_config_value_to_string (const GdmConfigValue *value)
-{
- GdmConfigRealValue *real;
- char *ret;
-
- g_return_val_if_fail (value != NULL, NULL);
-
- ret = NULL;
- real = REAL_VALUE (value);
-
- switch (real->type) {
- case GDM_CONFIG_VALUE_INVALID:
- break;
- case GDM_CONFIG_VALUE_BOOL:
- ret = real->val.bool ? g_strdup ("true") : g_strdup ("false");
- break;
- case GDM_CONFIG_VALUE_INT:
- ret = g_strdup_printf ("%d", real->val.integer);
- break;
- case GDM_CONFIG_VALUE_STRING:
- case GDM_CONFIG_VALUE_LOCALE_STRING:
- ret = g_strdup (real->val.str);
- break;
- case GDM_CONFIG_VALUE_STRING_ARRAY:
- case GDM_CONFIG_VALUE_LOCALE_STRING_ARRAY:
- ret = g_strjoinv (";", real->val.array);
- break;
- default:
- g_assert_not_reached ();
- break;
- }
- return ret;
-}
-
-static void
-gdm_config_init (GdmConfig *config)
-{
- config->entries = g_ptr_array_new ();
- config->value_hash = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify)g_free,
- (GDestroyNotify)gdm_config_value_free);
-}
-
-GdmConfig *
-gdm_config_new (void)
-{
- GdmConfig *config;
-
- config = g_slice_new0 (GdmConfig);
- gdm_config_init (config);
-
- return config;
-}
-
-void
-gdm_config_free (GdmConfig *config)
-{
- g_return_if_fail (config != NULL);
-
- g_ptr_array_foreach (config->entries, (GFunc)gdm_config_entry_free, NULL);
- g_ptr_array_free (config->entries, TRUE);
-
- g_free (config->mandatory_filename);
- g_free (config->default_filename);
- g_free (config->custom_filename);
-
- if (config->mandatory_key_file != NULL) {
- g_key_file_free (config->mandatory_key_file);
- }
- if (config->default_key_file != NULL) {
- g_key_file_free (config->default_key_file);
- }
- if (config->custom_key_file != NULL) {
- g_key_file_free (config->custom_key_file);
- }
- if (config->value_hash != NULL) {
- g_hash_table_destroy (config->value_hash);
- }
-
- g_slice_free (GdmConfig, config);
-}
-
-const GdmConfigEntry *
-gdm_config_lookup_entry (GdmConfig *config,
- const char *group,
- const char *key)
-{
- int i;
- const GdmConfigEntry *entry;
-
- g_return_val_if_fail (config != NULL, NULL);
- g_return_val_if_fail (group != NULL, NULL);
- g_return_val_if_fail (key != NULL, NULL);
-
- entry = NULL;
-
- for (i = 0; i < config->entries->len; i++) {
- GdmConfigEntry *this;
- this = g_ptr_array_index (config->entries, i);
- if (strcmp (this->group, group) == 0
- && strcmp (this->key, key) == 0) {
- entry = (const GdmConfigEntry *)this;
- break;
- }
- }
-
- return entry;
-}
-
-const GdmConfigEntry *
-gdm_config_lookup_entry_for_id (GdmConfig *config,
- int id)
-{
- int i;
- const GdmConfigEntry *entry;
-
- g_return_val_if_fail (config != NULL, NULL);
-
- entry = NULL;
-
- for (i = 0; i < config->entries->len; i++) {
- GdmConfigEntry *this;
- this = g_ptr_array_index (config->entries, i);
- if (this->id == id) {
- entry = (const GdmConfigEntry *)this;
- break;
- }
- }
-
- return entry;
-}
-
-void
-gdm_config_add_entry (GdmConfig *config,
- const GdmConfigEntry *entry)
-{
- GdmConfigEntry *new_entry;
-
- g_return_if_fail (config != NULL);
- g_return_if_fail (entry != NULL);
-
- new_entry = gdm_config_entry_copy (entry);
- g_ptr_array_add (config->entries, new_entry);
-}
-
-void
-gdm_config_add_static_entries (GdmConfig *config,
- const GdmConfigEntry *entries)
-{
- int i;
-
- g_return_if_fail (config != NULL);
- g_return_if_fail (entries != NULL);
-
- for (i = 0; entries[i].group != NULL; i++) {
- gdm_config_add_entry (config, &entries[i]);
- }
-}
-
-void
-gdm_config_set_validate_func (GdmConfig *config,
- GdmConfigFunc func,
- gpointer data)
-{
- g_return_if_fail (config != NULL);
-
- config->validate_func = func;
- config->validate_func_data = data;
-}
-
-void
-gdm_config_set_mandatory_file (GdmConfig *config,
- const char *name)
-{
- g_return_if_fail (config != NULL);
-
- g_free (config->mandatory_filename);
- config->mandatory_filename = g_strdup (name);
-}
-
-void
-gdm_config_set_default_file (GdmConfig *config,
- const char *name)
-{
- g_return_if_fail (config != NULL);
-
- g_free (config->default_filename);
- config->default_filename = g_strdup (name);
-}
-
-void
-gdm_config_set_custom_file (GdmConfig *config,
- const char *name)
-{
- g_return_if_fail (config != NULL);
-
- g_free (config->custom_filename);
- config->custom_filename = g_strdup (name);
-}
-
-void
-gdm_config_set_notify_func (GdmConfig *config,
- GdmConfigFunc func,
- gpointer data)
-{
- g_return_if_fail (config != NULL);
-
- config->notify_func = func;
- config->notify_func_data = data;
-}
-
-static gboolean
-key_file_get_value (GdmConfig *config,
- GKeyFile *key_file,
- const char *group,
- const char *key,
- GdmConfigValueType type,
- GdmConfigValue **valuep)
-{
- char *val;
- GError *error;
- GdmConfigValue *value;
- gboolean ret;
-
- ret = FALSE;
- value = NULL;
-
- error = NULL;
- if (type == GDM_CONFIG_VALUE_LOCALE_STRING ||
- type == GDM_CONFIG_VALUE_LOCALE_STRING_ARRAY) {
- /* Use NULL locale to detect current locale */
- val = g_key_file_get_locale_string (key_file,
- group,
- key,
- NULL,
- &error);
- g_debug ("Loading locale string: %s %s", key, val ? val : "(null)");
-
- if (error != NULL) {
- g_debug ("%s", error->message);
- g_error_free (error);
- }
- if (val == NULL) {
- error = NULL;
- val = g_key_file_get_value (key_file,
- group,
- key,
- &error);
- g_debug ("Loading non-locale string: %s %s", key, val ? val : "(null)");
- }
- } else {
- val = g_key_file_get_value (key_file,
- group,
- key,
- &error);
- }
-
- if (error != NULL) {
- g_error_free (error);
- goto out;
- }
-
- if (val == NULL) {
- goto out;
- }
-
- error = NULL;
- value = gdm_config_value_new_from_string (type, val, &error);
- if (error != NULL) {
- g_warning ("%s", error->message);
- g_error_free (error);
- goto out;
- }
-
- ret = TRUE;
-
- out:
- *valuep = value;
-
- return ret;
-}
-
-static void
-entry_get_default_value (GdmConfig *config,
- const GdmConfigEntry *entry,
- GdmConfigValue **valuep)
-{
- GdmConfigValue *value;
- GError *error;
-
- error = NULL;
- value = gdm_config_value_new_from_string (entry->type,
- entry->default_value ? entry->default_value : "",
- &error);
- if (error != NULL) {
- g_warning ("%s", error->message);
- g_error_free (error);
- }
-
- *valuep = value;
-}
-
-static gboolean
-load_value_entry (GdmConfig *config,
- const GdmConfigEntry *entry,
- GdmConfigValue **valuep,
- GdmConfigSourceType *sourcep)
-{
- GdmConfigValue *value;
- GdmConfigSourceType source;
- gboolean ret;
- gboolean res;
-
- value = NULL;
-
- /* Look for the first occurence of the key in:
- mandatory file, custom file, default file, or built-in-default
- */
-
- if (config->mandatory_filename != NULL) {
- source = GDM_CONFIG_SOURCE_MANDATORY;
- res = key_file_get_value (config,
- config->mandatory_key_file,
- entry->group,
- entry->key,
- entry->type,
- &value);
- if (res) {
- goto done;
- }
- }
- if (config->custom_filename != NULL) {
- source = GDM_CONFIG_SOURCE_CUSTOM;
- res = key_file_get_value (config,
- config->custom_key_file,
- entry->group,
- entry->key,
- entry->type,
- &value);
- if (res) {
- goto done;
- }
- }
- if (config->default_filename != NULL) {
- source = GDM_CONFIG_SOURCE_DEFAULT;
- res = key_file_get_value (config,
- config->default_key_file,
- entry->group,
- entry->key,
- entry->type,
- &value);
- if (res) {
- goto done;
- }
- }
-
-
- source = GDM_CONFIG_SOURCE_BUILT_IN;
- entry_get_default_value (config, entry, &value);
-
- done:
-
- if (value != NULL) {
- ret = TRUE;
- } else {
- ret = FALSE;
- }
-
- *valuep = value;
- *sourcep = source;
-
- return ret;
-}
-
-static int
-lookup_id_for_key (GdmConfig *config,
- const char *group,
- const char *key)
-{
- int id;
- const GdmConfigEntry *entry;
-
- id = GDM_CONFIG_INVALID_ID;
- entry = gdm_config_lookup_entry (config, group, key);
- if (entry != NULL) {
- id = entry->id;
- }
-
- return id;
-}
-
-static void
-internal_set_value (GdmConfig *config,
- GdmConfigSourceType source,
- const char *group,
- const char *key,
- GdmConfigValue *value)
-{
- char *key_path;
- int id;
- GdmConfigValue *v;
- gboolean res;
-
- g_return_if_fail (config != NULL);
-
- key_path = g_strdup_printf ("%s/%s", group, key);
-
- v = NULL;
- res = g_hash_table_lookup_extended (config->value_hash,
- key_path,
- NULL,
- (gpointer *)&v);
-
- if (res) {
- if (v != NULL && gdm_config_value_compare (v, value) == 0) {
- /* value is the same - don't update */
- goto out;
- }
- }
-
- g_hash_table_insert (config->value_hash,
- g_strdup (key_path),
- gdm_config_value_copy (value));
-
- id = lookup_id_for_key (config, group, key);
-
- if (config->notify_func) {
- (* config->notify_func) (config, source, group, key, value, id, config->notify_func_data);
- }
- out:
- g_free (key_path);
-}
-
-static void
-store_entry_value (GdmConfig *config,
- const GdmConfigEntry *entry,
- GdmConfigSourceType source,
- GdmConfigValue *value)
-{
- internal_set_value (config, source, entry->group, entry->key, value);
-}
-
-static gboolean
-load_entry (GdmConfig *config,
- const GdmConfigEntry *entry)
-{
- GdmConfigValue *value;
- GdmConfigSourceType source;
- gboolean res;
-
- value = NULL;
- source = GDM_CONFIG_SOURCE_INVALID;
-
- res = load_value_entry (config, entry, &value, &source);
- if (!res) {
- return FALSE;
- }
-
- res = TRUE;
- if (config->validate_func) {
- res = (* config->validate_func) (config, source, entry->group, entry->key, value, entry->id, config->validate_func_data);
- }
-
- if (res) {
- /* store runs notify */
- store_entry_value (config, entry, source, value);
- }
-
- return TRUE;
-}
-
-static void
-add_keys_to_hash (GKeyFile *key_file,
- const char *group_name,
- GHashTable *hash)
-{
- GError *local_error;
- char **keys;
- gsize len;
- int i;
-
- local_error = NULL;
- len = 0;
- keys = g_key_file_get_keys (key_file,
- group_name,
- &len,
- &local_error);
- if (local_error != NULL) {
- g_error_free (local_error);
- return;
- }
-
- for (i = 0; i < len; i++) {
- g_hash_table_insert (hash, keys[i], GINT_TO_POINTER (1));
- }
-}
-
-static void
-collect_hash_keys (const char *key,
- gpointer value,
- GPtrArray **array)
-{
- g_message ("Adding %s", key);
- g_ptr_array_add (*array, g_strdup (key));
-}
-
-char **
-gdm_config_get_keys_for_group (GdmConfig *config,
- const char *group,
- gsize *length,
- GError **error)
-{
- GHashTable *hash;
- gsize len;
- GPtrArray *array;
-
- hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-
- if (config->mandatory_filename != NULL) {
- add_keys_to_hash (config->mandatory_key_file, group, hash);
- }
-
- if (config->default_filename != NULL) {
- add_keys_to_hash (config->default_key_file, group, hash);
- }
-
- if (config->custom_filename != NULL) {
- add_keys_to_hash (config->custom_key_file, group, hash);
- }
-
- len = g_hash_table_size (hash);
- array = g_ptr_array_sized_new (len);
-
- g_hash_table_foreach (hash, (GHFunc)collect_hash_keys, &array);
- g_ptr_array_add (array, NULL);
-
- g_hash_table_destroy (hash);
-
- if (length != NULL) {
- *length = array->len - 1;
- }
-
- return (char **)g_ptr_array_free (array, FALSE);
-}
-
-static gboolean
-load_backend (GdmConfig *config,
- const char *filename,
- GKeyFile **key_file,
- time_t *mtime)
-{
- GError *local_error;
- gboolean res;
- gboolean ret;
- struct stat statbuf;
- GKeyFile *kf;
- time_t lmtime;
-
- if (filename == NULL) {
- return FALSE;
- }
-
- if (g_stat (filename, &statbuf) != 0) {
- return FALSE;
- }
- lmtime = statbuf.st_mtime;
-
- /* if already loaded check whether reload is necessary */
- if (*key_file != NULL) {
- if (lmtime > *mtime) {
- /* needs an update */
- g_key_file_free (*key_file);
- } else {
- /* no reload necessary so we're done */
- return TRUE;
- }
- }
-
- kf = g_key_file_new ();
-
- local_error = NULL;
- res = g_key_file_load_from_file (kf,
- filename,
- G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
- &local_error);
- if (! res) {
- g_error_free (local_error);
- g_key_file_free (kf);
- kf = NULL;
- lmtime = 0;
- ret = FALSE;
- } else {
- ret = TRUE;
- }
-
- *key_file = kf;
- *mtime = lmtime;
-
- return ret;
-}
-
-gboolean
-gdm_config_load (GdmConfig *config,
- GError **error)
-{
- g_return_val_if_fail (config != NULL, FALSE);
-
- config->mandatory_loaded = load_backend (config,
- config->mandatory_filename,
- &config->mandatory_key_file,
- &config->mandatory_mtime);
- config->default_loaded = load_backend (config,
- config->default_filename,
- &config->default_key_file,
- &config->default_mtime);
- config->custom_loaded = load_backend (config,
- config->custom_filename,
- &config->custom_key_file,
- &config->custom_mtime);
-
- return TRUE;
-}
-
-static gboolean
-process_entries (GdmConfig *config,
- const GdmConfigEntry **entries,
- gsize n_entries,
- GError **error)
-{
- gboolean ret;
- int i;
-
- ret = TRUE;
-
- for (i = 0; i < n_entries; i++) {
- load_entry (config, entries[i]);
- }
-
- return ret;
-}
-
-gboolean
-gdm_config_process_entry (GdmConfig *config,
- const GdmConfigEntry *entry,
- GError **error)
-{
- gboolean ret;
-
- g_return_val_if_fail (config != NULL, FALSE);
- g_return_val_if_fail (entry != NULL, FALSE);
-
- ret = load_entry (config, entry);
-
- return ret;
-}
-
-gboolean
-gdm_config_process_entries (GdmConfig *config,
- const GdmConfigEntry **entries,
- gsize n_entries,
- GError **error)
-{
- gboolean ret;
-
- g_return_val_if_fail (config != NULL, FALSE);
- g_return_val_if_fail (entries != NULL, FALSE);
- g_return_val_if_fail (n_entries > 0, FALSE);
-
- ret = process_entries (config, entries, n_entries, error);
-
- return ret;
-}
-
-gboolean
-gdm_config_process_all (GdmConfig *config,
- GError **error)
-{
- gboolean ret;
-
- g_return_val_if_fail (config != NULL, FALSE);
-
- ret = process_entries (config,
- (const GdmConfigEntry **)config->entries->pdata,
- config->entries->len,
- error);
-
- return ret;
-}
-
-gboolean
-gdm_config_peek_value (GdmConfig *config,
- const char *group,
- const char *key,
- const GdmConfigValue **valuep)
-{
- gboolean ret;
- char *key_path;
- const GdmConfigValue *value;
-
- g_return_val_if_fail (config != NULL, FALSE);
-
- key_path = g_strdup_printf ("%s/%s", group, key);
- value = NULL;
- ret = g_hash_table_lookup_extended (config->value_hash,
- key_path,
- NULL,
- (gpointer *)&value);
- g_free (key_path);
-
- if (valuep != NULL) {
- if (ret) {
- *valuep = value;
- } else {
- *valuep = NULL;
- }
- }
-
- return ret;
-}
-
-gboolean
-gdm_config_get_value (GdmConfig *config,
- const char *group,
- const char *key,
- GdmConfigValue **valuep)
-{
- gboolean res;
- const GdmConfigValue *value;
-
- res = gdm_config_peek_value (config, group, key, &value);
- if (valuep != NULL) {
- *valuep = (value == NULL) ? NULL : gdm_config_value_copy (value);
- }
-
- return res;
-}
-
-gboolean
-gdm_config_set_value (GdmConfig *config,
- const char *group,
- const char *key,
- GdmConfigValue *value)
-{
- g_return_val_if_fail (config != NULL, FALSE);
- g_return_val_if_fail (group != NULL, FALSE);
- g_return_val_if_fail (key != NULL, FALSE);
- g_return_val_if_fail (value != NULL, FALSE);
-
- internal_set_value (config, GDM_CONFIG_SOURCE_RUNTIME_USER, group, key, value);
-
- return TRUE;
-}
-
-static gboolean
-gdm_config_peek_value_for_id (GdmConfig *config,
- int id,
- const GdmConfigValue **valuep)
-{
- const GdmConfigEntry *entry;
-
- g_return_val_if_fail (config != NULL, FALSE);
-
- entry = gdm_config_lookup_entry_for_id (config, id);
- if (entry == NULL) {
- return FALSE;
- }
-
- return gdm_config_peek_value (config, entry->group, entry->key, valuep);
-}
-
-gboolean
-gdm_config_get_value_for_id (GdmConfig *config,
- int id,
- GdmConfigValue **valuep)
-{
- const GdmConfigEntry *entry;
-
- g_return_val_if_fail (config != NULL, FALSE);
-
- entry = gdm_config_lookup_entry_for_id (config, id);
- if (entry == NULL) {
- return FALSE;
- }
-
- return gdm_config_get_value (config, entry->group, entry->key, valuep);
-}
-
-gboolean
-gdm_config_set_value_for_id (GdmConfig *config,
- int id,
- GdmConfigValue *valuep)
-{
- const GdmConfigEntry *entry;
-
- g_return_val_if_fail (config != NULL, FALSE);
-
- entry = gdm_config_lookup_entry_for_id (config, id);
- if (entry == NULL) {
- return FALSE;
- }
-
- return gdm_config_set_value (config, entry->group, entry->key, valuep);
-}
-
-gboolean
-gdm_config_peek_string_for_id (GdmConfig *config,
- int id,
- const char **strp)
-{
- const GdmConfigValue *value;
- const char *str;
- gboolean res;
-
- g_return_val_if_fail (config != NULL, FALSE);
-
- res = gdm_config_peek_value_for_id (config, id, &value);
- if (! res) {
- return FALSE;
- }
-
- str = gdm_config_value_get_string (value);
- if (strp != NULL) {
- *strp = str;
- }
-
- return res;
-}
-
-gboolean
-gdm_config_get_string_for_id (GdmConfig *config,
- int id,
- char **strp)
-{
- gboolean res;
- const char *str;
-
- res = gdm_config_peek_string_for_id (config, id, &str);
- if (strp != NULL) {
- *strp = g_strdup (str);
- }
-
- return res;
-}
-
-gboolean
-gdm_config_get_bool_for_id (GdmConfig *config,
- int id,
- gboolean *boolp)
-{
- GdmConfigValue *value;
- gboolean bool;
- gboolean res;
-
- g_return_val_if_fail (config != NULL, FALSE);
-
- res = gdm_config_get_value_for_id (config, id, &value);
- if (! res) {
- return FALSE;
- }
-
- bool = gdm_config_value_get_bool (value);
- if (boolp != NULL) {
- *boolp = bool;
- }
-
- gdm_config_value_free (value);
-
- return res;
-}
-
-gboolean
-gdm_config_get_int_for_id (GdmConfig *config,
- int id,
- int *integerp)
-{
- GdmConfigValue *value;
- gboolean integer;
- gboolean res;
-
- g_return_val_if_fail (config != NULL, FALSE);
-
- res = gdm_config_get_value_for_id (config, id, &value);
- if (! res) {
- return FALSE;
- }
-
- integer = gdm_config_value_get_int (value);
- if (integerp != NULL) {
- *integerp = integer;
- }
-
- gdm_config_value_free (value);
-
- return res;
-}
-
-gboolean
-gdm_config_set_string_for_id (GdmConfig *config,
- int id,
- char *str)
-{
- GdmConfigValue *value;
- gboolean res;
-
- g_return_val_if_fail (config != NULL, FALSE);
-
- value = gdm_config_value_new (GDM_CONFIG_VALUE_STRING);
- gdm_config_value_set_string (value, str);
-
- res = gdm_config_set_value_for_id (config, id, value);
- gdm_config_value_free (value);
-
- return res;
-}
-
-gboolean
-gdm_config_set_bool_for_id (GdmConfig *config,
- int id,
- gboolean bool)
-{
- GdmConfigValue *value;
- gboolean res;
-
- g_return_val_if_fail (config != NULL, FALSE);
-
- value = gdm_config_value_new (GDM_CONFIG_VALUE_BOOL);
- gdm_config_value_set_bool (value, bool);
-
- res = gdm_config_set_value_for_id (config, id, value);
- gdm_config_value_free (value);
-
- return res;
-}
-
-gboolean
-gdm_config_set_int_for_id (GdmConfig *config,
- int id,
- int integer)
-{
- GdmConfigValue *value;
- gboolean res;
-
- g_return_val_if_fail (config != NULL, FALSE);
-
- value = gdm_config_value_new (GDM_CONFIG_VALUE_INT);
- gdm_config_value_set_int (value, integer);
-
- res = gdm_config_set_value_for_id (config, id, value);
- gdm_config_value_free (value);
-
- return res;
-}
diff --git a/common/gdm-config.h b/common/gdm-config.h
deleted file mode 100644
index 5fc184c1..00000000
--- a/common/gdm-config.h
+++ /dev/null
@@ -1,212 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef _GDM_CONFIG_H
-#define _GDM_CONFIG_H
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-typedef struct _GdmConfig GdmConfig;
-
-typedef enum {
- GDM_CONFIG_VALUE_INVALID,
- GDM_CONFIG_VALUE_BOOL,
- GDM_CONFIG_VALUE_INT,
- GDM_CONFIG_VALUE_STRING,
- GDM_CONFIG_VALUE_LOCALE_STRING,
- GDM_CONFIG_VALUE_STRING_ARRAY,
- GDM_CONFIG_VALUE_LOCALE_STRING_ARRAY,
-} GdmConfigValueType;
-
-typedef enum {
- GDM_CONFIG_SOURCE_INVALID,
- GDM_CONFIG_SOURCE_MANDATORY,
- GDM_CONFIG_SOURCE_DEFAULT,
- GDM_CONFIG_SOURCE_CUSTOM,
- GDM_CONFIG_SOURCE_BUILT_IN,
- GDM_CONFIG_SOURCE_RUNTIME_USER,
-} GdmConfigSourceType;
-
-#define GDM_CONFIG_INVALID_ID -1
-
-struct _GdmConfigValue
-{
- GdmConfigValueType type;
-};
-
-typedef struct _GdmConfigValue GdmConfigValue;
-
-typedef gboolean (* GdmConfigFunc) (GdmConfig *config,
- GdmConfigSourceType source,
- const char *group,
- const char *key,
- GdmConfigValue *value,
- int id,
- gpointer data);
-
-typedef struct {
- char *group;
- char *key;
- GdmConfigValueType type;
- char *default_value;
- int id;
-} GdmConfigEntry;
-
-#define GDM_CONFIG_ERROR (gdm_config_error_quark ())
-
-typedef enum
-{
- GDM_CONFIG_ERROR_UNKNOWN_OPTION,
- GDM_CONFIG_ERROR_BAD_VALUE,
- GDM_CONFIG_ERROR_PARSE_ERROR,
- GDM_CONFIG_ERROR_FAILED
-} GdmConfigError;
-
-GQuark gdm_config_error_quark (void);
-
-GdmConfig * gdm_config_new (void);
-void gdm_config_free (GdmConfig *config);
-
-void gdm_config_set_validate_func (GdmConfig *config,
- GdmConfigFunc func,
- gpointer data);
-void gdm_config_set_notify_func (GdmConfig *config,
- GdmConfigFunc func,
- gpointer data);
-void gdm_config_set_default_file (GdmConfig *config,
- const char *name);
-void gdm_config_set_mandatory_file (GdmConfig *config,
- const char *name);
-void gdm_config_set_custom_file (GdmConfig *config,
- const char *name);
-void gdm_config_add_entry (GdmConfig *config,
- const GdmConfigEntry *entry);
-void gdm_config_add_static_entries (GdmConfig *config,
- const GdmConfigEntry *entries);
-const GdmConfigEntry * gdm_config_lookup_entry (GdmConfig *config,
- const char *group,
- const char *key);
-const GdmConfigEntry * gdm_config_lookup_entry_for_id (GdmConfig *config,
- int id);
-
-gboolean gdm_config_load (GdmConfig *config,
- GError **error);
-gboolean gdm_config_process_all (GdmConfig *config,
- GError **error);
-gboolean gdm_config_process_entry (GdmConfig *config,
- const GdmConfigEntry *entry,
- GError **error);
-gboolean gdm_config_process_entries (GdmConfig *config,
- const GdmConfigEntry **entries,
- gsize n_entries,
- GError **error);
-
-gboolean gdm_config_save_custom_file (GdmConfig *config,
- GError **error);
-char ** gdm_config_get_keys_for_group (GdmConfig *config,
- const gchar *group_name,
- gsize *length,
- GError **error);
-
-gboolean gdm_config_peek_value (GdmConfig *config,
- const char *group,
- const char *key,
- const GdmConfigValue **value);
-gboolean gdm_config_get_value (GdmConfig *config,
- const char *group,
- const char *key,
- GdmConfigValue **value);
-gboolean gdm_config_set_value (GdmConfig *config,
- const char *group,
- const char *key,
- GdmConfigValue *value);
-
-/* convenience functions */
-gboolean gdm_config_get_value_for_id (GdmConfig *config,
- int id,
- GdmConfigValue **value);
-gboolean gdm_config_set_value_for_id (GdmConfig *config,
- int id,
- GdmConfigValue *value);
-
-gboolean gdm_config_peek_string_for_id (GdmConfig *config,
- int id,
- const char **str);
-gboolean gdm_config_get_string_for_id (GdmConfig *config,
- int id,
- char **str);
-gboolean gdm_config_get_bool_for_id (GdmConfig *config,
- int id,
- gboolean *bool);
-gboolean gdm_config_get_int_for_id (GdmConfig *config,
- int id,
- int *integer);
-gboolean gdm_config_set_string_for_id (GdmConfig *config,
- int id,
- char *str);
-gboolean gdm_config_set_bool_for_id (GdmConfig *config,
- int id,
- gboolean bool);
-gboolean gdm_config_set_int_for_id (GdmConfig *config,
- int id,
- int integer);
-
-/* Config Values */
-
-GdmConfigValue * gdm_config_value_new (GdmConfigValueType type);
-void gdm_config_value_free (GdmConfigValue *value);
-GdmConfigValue * gdm_config_value_copy (const GdmConfigValue *value);
-int gdm_config_value_compare (const GdmConfigValue *value_a,
- const GdmConfigValue *value_b);
-
-GdmConfigValue * gdm_config_value_new_from_string (GdmConfigValueType type,
- const char *str,
- GError **error);
-const char * gdm_config_value_get_string (const GdmConfigValue *value);
-const char * gdm_config_value_get_locale_string (const GdmConfigValue *value);
-const char ** gdm_config_value_get_string_array (const GdmConfigValue *value);
-
-int gdm_config_value_get_int (const GdmConfigValue *value);
-gboolean gdm_config_value_get_bool (const GdmConfigValue *value);
-
-void gdm_config_value_set_string (GdmConfigValue *value,
- const char *str);
-void gdm_config_value_set_locale_string (GdmConfigValue *value,
- const char *str);
-
-void gdm_config_value_set_string_array (GdmConfigValue *value,
- const char **array);
-void gdm_config_value_set_locale_string_array (GdmConfigValue *value,
- const char **array);
-void gdm_config_value_set_int (GdmConfigValue *value,
- int integer);
-void gdm_config_value_set_bool (GdmConfigValue *value,
- gboolean bool);
-char * gdm_config_value_to_string (const GdmConfigValue *value);
-
-/* Config Entries */
-GdmConfigEntry * gdm_config_entry_copy (const GdmConfigEntry *entry);
-void gdm_config_entry_free (GdmConfigEntry *entry);
-
-G_END_DECLS
-
-#endif /* _GDM_CONFIG_H */
diff --git a/common/gdm-log.c b/common/gdm-log.c
deleted file mode 100644
index bc7ecfb2..00000000
--- a/common/gdm-log.c
+++ /dev/null
@@ -1,191 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
- *
- * 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.
- *
- * Authors: William Jon McCann <mccann@jhu.edu>
- *
- */
-
-#include "config.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <signal.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <syslog.h>
-
-#include <glib.h>
-#include <glib/gstdio.h>
-
-#include "gdm-log.h"
-
-static gboolean initialized = FALSE;
-static int syslog_levels = (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
-
-static void
-log_level_to_priority_and_prefix (GLogLevelFlags log_level,
- int *priorityp,
- const char **prefixp)
-{
- int priority;
- const char *prefix;
-
- /* Process the message prefix and priority */
- switch (log_level & G_LOG_LEVEL_MASK) {
- case G_LOG_FLAG_FATAL:
- priority = LOG_EMERG;
- prefix = "FATAL";
- break;
- case G_LOG_LEVEL_ERROR:
- priority = LOG_ERR;
- prefix = "ERROR";
- break;
- case G_LOG_LEVEL_CRITICAL:
- priority = LOG_CRIT;
- prefix = "CRITICAL";
- break;
- case G_LOG_LEVEL_WARNING:
- priority = LOG_WARNING;
- prefix = "WARNING";
- break;
- case G_LOG_LEVEL_MESSAGE:
- priority = LOG_NOTICE;
- prefix = "MESSAGE";
- break;
- case G_LOG_LEVEL_INFO:
- priority = LOG_INFO;
- prefix = "INFO";
- break;
- case G_LOG_LEVEL_DEBUG:
- /* if debug was requested then bump this up to ERROR
- * to ensure it is seen in a log */
- if (syslog_levels & G_LOG_LEVEL_DEBUG) {
- priority = LOG_WARNING;
- } else {
- priority = LOG_DEBUG;
- }
- prefix = "DEBUG";
- break;
- default:
- priority = LOG_DEBUG;
- prefix = "UNKNOWN";
- break;
- }
-
- if (priorityp != NULL) {
- *priorityp = priority;
- }
- if (prefixp != NULL) {
- *prefixp = prefix;
- }
-}
-
-void
-gdm_log_default_handler (const gchar *log_domain,
- GLogLevelFlags log_level,
- const gchar *message,
- gpointer unused_data)
-{
- GString *gstring;
- int priority;
- const char *level_prefix;
- char *string;
- gboolean do_log;
- gboolean is_fatal;
-
- is_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
-
- do_log = (log_level & syslog_levels);
- if (! do_log) {
- return;
- }
-
- if (! initialized) {
- gdm_log_init ();
- }
-
- log_level_to_priority_and_prefix (log_level,
- &priority,
- &level_prefix);
-
- gstring = g_string_new (NULL);
-
- if (log_domain != NULL) {
- g_string_append (gstring, log_domain);
- g_string_append_c (gstring, '-');
- }
- g_string_append (gstring, level_prefix);
-
- g_string_append (gstring, ": ");
- if (message == NULL) {
- g_string_append (gstring, "(NULL) message");
- } else {
- g_string_append (gstring, message);
- }
- if (is_fatal) {
- g_string_append (gstring, "\naborting...\n");
- } else {
- g_string_append (gstring, "\n");
- }
-
- string = g_string_free (gstring, FALSE);
-
- syslog (priority, "%s", string);
-
- g_free (string);
-}
-
-void
-gdm_log_set_debug (gboolean debug)
-{
- if (debug) {
- syslog_levels |= G_LOG_LEVEL_DEBUG;
- } else {
- syslog_levels &= ~G_LOG_LEVEL_DEBUG;
- }
-}
-
-void
-gdm_log_init (void)
-{
- const char *prg_name;
- int options;
-
- g_log_set_default_handler (gdm_log_default_handler, NULL);
-
- prg_name = g_get_prgname ();
-
- options = LOG_PID;
-#ifdef LOG_PERROR
- options |= LOG_PERROR;
-#endif
-
- openlog (prg_name, options, LOG_DAEMON);
-
- initialized = TRUE;
-}
-
-void
-gdm_log_shutdown (void)
-{
- closelog ();
- initialized = FALSE;
-}
-
diff --git a/common/gdm-log.h b/common/gdm-log.h
deleted file mode 100644
index fd0ee437..00000000
--- a/common/gdm-log.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
- *
- * 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.
- *
- * Authors: William Jon McCann <mccann@jhu.edu>
- *
- */
-
-#ifndef __GDM_LOG_H
-#define __GDM_LOG_H
-
-#include <stdarg.h>
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-void gdm_log_default_handler (const gchar *log_domain,
- GLogLevelFlags log_level,
- const gchar *message,
- gpointer unused_data);
-void gdm_log_set_debug (gboolean debug);
-void gdm_log_init (void);
-void gdm_log_shutdown (void);
-
-/* compatibility */
-#define gdm_error g_warning
-#define gdm_info g_message
-#define gdm_debug g_debug
-
-#define gdm_assert g_assert
-#define gdm_assert_not_reached g_assert_not_reached
-
-G_END_DECLS
-
-#endif /* __GDM_LOG_H */
diff --git a/common/test-config.c b/common/test-config.c
deleted file mode 100644
index 60194d35..00000000
--- a/common/test-config.c
+++ /dev/null
@@ -1,303 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
- *
- * 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 "config.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <pwd.h>
-#include <string.h>
-#include <errno.h>
-
-#include <locale.h>
-
-#include <glib.h>
-
-#include "gdm-common.h"
-
-#include "../daemon/gdm-daemon-config-entries.h"
-
-static const char *
-source_to_name (GdmConfigSourceType source)
-{
- const char *name;
-
- switch (source) {
- case GDM_CONFIG_SOURCE_DEFAULT:
- name = "default";
- break;
- case GDM_CONFIG_SOURCE_MANDATORY:
- name = "mandatory";
- break;
- case GDM_CONFIG_SOURCE_CUSTOM:
- name = "custom";
- break;
- case GDM_CONFIG_SOURCE_BUILT_IN:
- name = "built-in";
- break;
- case GDM_CONFIG_SOURCE_RUNTIME_USER:
- name = "runtime-user";
- break;
- case GDM_CONFIG_SOURCE_INVALID:
- name = "Invalid";
- break;
- default:
- name = "Unknown";
- break;
- }
-
- return name;
-}
-
-static const char *
-type_to_name (GdmConfigValueType type)
-{
- const char *name;
-
- switch (type) {
- case GDM_CONFIG_VALUE_INT:
- name = "int";
- break;
- case GDM_CONFIG_VALUE_BOOL:
- name = "boolean";
- break;
- case GDM_CONFIG_VALUE_STRING:
- name = "string";
- break;
- case GDM_CONFIG_VALUE_LOCALE_STRING:
- name = "locale-string";
- break;
- case GDM_CONFIG_VALUE_STRING_ARRAY:
- name = "string-array";
- break;
- case GDM_CONFIG_VALUE_LOCALE_STRING_ARRAY:
- name = "locale-string-array";
- break;
- case GDM_CONFIG_VALUE_INVALID:
- name = "invalid";
- break;
- default:
- name = "unknown";
- break;
- }
-
- return name;
-}
-
-static gboolean
-notify_cb (GdmConfig *config,
- GdmConfigSourceType source,
- const char *group,
- const char *key,
- GdmConfigValue *value,
- int id,
- gpointer data)
-{
- char *str;
-
- if (value == NULL) {
- return FALSE;
- }
-
- str = gdm_config_value_to_string (value);
-
- g_print ("SOURCE=%s GROUP=%s KEY=%s ID=%d TYPE=%s VALUE=%s\n", source_to_name (source), group, key, id, type_to_name (value->type), str);
- if (strcmp (group, GDM_CONFIG_GROUP_CUSTOM_CMD) == 0 &&
- g_str_has_prefix (key, "CustomCommand") &&
- strlen (key) == 14) {
- g_message ("NOTIFY: Custom command");
- }
-
- g_free (str);
- return TRUE;
-}
-
-static gboolean
-validate_cb (GdmConfig *config,
- GdmConfigSourceType source,
- const char *group,
- const char *key,
- GdmConfigValue *value,
- int id,
- gpointer data)
-{
- /* Here you can do validation or override the values */
-
- switch (id) {
- case GDM_ID_SOUND_PROGRAM:
- gdm_config_value_set_string (value, "NONE");
- break;
- case GDM_ID_NONE:
- default:
- /* doesn't have an ID : match group/key */
- break;
- }
-
- return TRUE;
-}
-
-static void
-load_servers_group (GdmConfig *config)
-{
- char **keys;
- gsize len;
- int i;
-
- keys = gdm_config_get_keys_for_group (config, GDM_CONFIG_GROUP_SERVERS, &len, NULL);
- g_message ("Got %d keys for group %s", (int)len, GDM_CONFIG_GROUP_SERVERS);
-
- /* now construct entries for these groups */
- for (i = 0; i < len; i++) {
- GdmConfigEntry entry;
- GdmConfigValue *value;
- char *new_group;
- gboolean res;
- int j;
-
- entry.group = GDM_CONFIG_GROUP_SERVERS;
- entry.key = keys[i];
- entry.type = GDM_CONFIG_VALUE_STRING;
- entry.default_value = NULL;
- entry.id = GDM_CONFIG_INVALID_ID;
-
- gdm_config_add_entry (config, &entry);
- gdm_config_process_entry (config, &entry, NULL);
-
- res = gdm_config_get_value (config, entry.group, entry.key, &value);
- if (! res) {
- continue;
- }
-
- new_group = g_strdup_printf ("server-%s", gdm_config_value_get_string (value));
- gdm_config_value_free (value);
-
- for (j = 0; j < G_N_ELEMENTS (gdm_daemon_server_config_entries); j++) {
- GdmConfigEntry *srv_entry;
- if (gdm_daemon_server_config_entries[j].key == NULL) {
- continue;
- }
- srv_entry = gdm_config_entry_copy (&gdm_daemon_server_config_entries[j]);
- g_free (srv_entry->group);
- srv_entry->group = g_strdup (new_group);
- gdm_config_process_entry (config, srv_entry, NULL);
- gdm_config_entry_free (srv_entry);
- }
- g_free (new_group);
- }
-}
-
-static void
-test_config (void)
-{
- GdmConfig *config;
- GError *error;
- int i;
-
- config = gdm_config_new ();
-
- gdm_config_set_notify_func (config, notify_cb, NULL);
- gdm_config_set_validate_func (config, validate_cb, NULL);
-
- gdm_config_add_static_entries (config, gdm_daemon_config_entries);
-
- /* At first try loading with only defaults */
- gdm_config_set_default_file (config, DATADIR "/gdm/defaults.conf");
-
- g_message ("Loading configuration: Default source only");
-
- /* load the data files */
- error = NULL;
- gdm_config_load (config, &error);
- if (error != NULL) {
- g_warning ("Unable to load configuration: %s", error->message);
- g_error_free (error);
- } else {
- /* populate the database with all specified entries */
- gdm_config_process_all (config, &error);
- }
-
- g_message ("Getting all standard values");
- /* now test retrieving these values */
- for (i = 0; gdm_daemon_config_entries [i].group != NULL; i++) {
- GdmConfigValue *value;
- const GdmConfigEntry *entry;
- gboolean res;
- char *str;
-
- entry = &gdm_daemon_config_entries [i];
-
- res = gdm_config_get_value (config, entry->group, entry->key, &value);
- if (! res) {
- g_warning ("Unable to lookup entry g=%s k=%s", entry->group, entry->key);
- continue;
- }
-
- str = gdm_config_value_to_string (value);
-
- g_print ("Got g=%s k=%s: %s\n", entry->group, entry->key, str);
-
- g_free (str);
- gdm_config_value_free (value);
- }
-
- g_message ("Setting values");
- /* now test setting a few values */
- {
- GdmConfigValue *value;
- value = gdm_config_value_new_from_string (GDM_CONFIG_VALUE_BOOL, "false", NULL);
- gdm_config_set_value (config, "greeter", "ShowLastSession", value);
- /* should only see one notification */
- gdm_config_set_value (config, "greeter", "ShowLastSession", value);
- gdm_config_value_free (value);
- }
-
- g_message ("Loading the server entries");
- load_servers_group (config);
-
- g_message ("Loading configuration: Default and Custom sources");
- /* Now try adding a custom config */
- gdm_config_set_custom_file (config, GDMCONFDIR "/custom.conf");
- /* load the data files */
- error = NULL;
- gdm_config_load (config, &error);
- if (error != NULL) {
- g_warning ("Unable to load configuration: %s", error->message);
- g_error_free (error);
- } else {
- /* populate the database with all specified entries */
- gdm_config_process_all (config, &error);
- }
-
-
- /* Test translated keys */
-
- gdm_config_free (config);
-}
-
-int
-main (int argc, char **argv)
-{
-
- test_config ();
-
- return 0;
-}
diff --git a/common/test-log.c b/common/test-log.c
deleted file mode 100644
index 6bde7604..00000000
--- a/common/test-log.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
- *
- * 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 "config.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <pwd.h>
-#include <string.h>
-#include <errno.h>
-
-#include <locale.h>
-
-#include <glib.h>
-
-#include "gdm-common.h"
-#include "gdm-log.h"
-
-static void
-test_log (void)
-{
- gdm_log_init ();
-
- g_debug ("Test debug 1");
- gdm_log_set_debug (TRUE);
- g_debug ("Test debug 2");
-
- g_message ("Test message");
- g_warning ("Test warning");
- g_error ("Test error");
- g_critical ("Test critical");
-}
-
-int
-main (int argc, char **argv)
-{
-
- test_log ();
-
- return 0;
-}
diff --git a/common/ve-signal.c b/common/ve-signal.c
deleted file mode 100644
index 76f7ed4e..00000000
--- a/common/ve-signal.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Signal routines
- *
- * (c) 2000, 2002 Queen of England
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-#include "config.h"
-
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <glib.h>
-#include <glib/gi18n.h>
-
-#include "ve-signal.h"
-
-typedef struct _SignalSource SignalSource;
-struct _SignalSource {
- GSource source;
-
- int signal;
- guint8 index;
- guint8 shift;
-};
-
-static guint32 signals_notified[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
-
-static gboolean
-ve_signal_prepare (GSource *source,
- int *timeout)
-{
- SignalSource *ss = (SignalSource *)source;
-
- return signals_notified[ss->index] & (1 << ss->shift);
-}
-
-static gboolean
-ve_signal_check (GSource *source)
-{
- SignalSource *ss = (SignalSource *)source;
-
- return signals_notified[ss->index] & (1 << ss->shift);
-}
-
-static gboolean
-ve_signal_dispatch (GSource *source,
- GSourceFunc callback,
- gpointer user_data)
-{
- SignalSource *ss = (SignalSource *)source;
-
- signals_notified[ss->index] &= ~(1 << ss->shift);
-
- return ((VeSignalFunc)callback) (ss->signal, user_data);
-}
-
-static GSourceFuncs signal_funcs = {
- ve_signal_prepare,
- ve_signal_check,
- ve_signal_dispatch
-};
-
-guint
-ve_signal_add (int signal,
- VeSignalFunc function,
- gpointer data)
-{
- return ve_signal_add_full (G_PRIORITY_DEFAULT, signal, function, data, NULL);
-}
-
-guint
-ve_signal_add_full (int priority,
- int signal,
- VeSignalFunc function,
- gpointer data,
- GDestroyNotify destroy)
-{
- GSource *source;
- SignalSource *ss;
- guint s = 128 + signal;
-
- g_return_val_if_fail (function != NULL, 0);
-
- source = g_source_new (&signal_funcs, sizeof (SignalSource));
- ss = (SignalSource *)source;
-
- ss->signal = signal;
- ss->index = s / 32;
- ss->shift = s % 32;
-
- g_assert (ss->index < 8);
-
- g_source_set_priority (source, priority);
- g_source_set_callback (source, (GSourceFunc)function, data, destroy);
- g_source_set_can_recurse (source, TRUE);
-
- return g_source_attach (source, NULL);
-}
-
-void
-ve_signal_notify (int signal)
-{
- guint index, shift;
- guint s = 128 + signal;
-
- index = s / 32;
- shift = s % 32;
-
- g_assert (index < 8);
-
- signals_notified[index] |= 1 << shift;
-
- g_main_context_wakeup (NULL);
-}
-
-gboolean
-ve_signal_was_notified (int signal)
-{
- guint index, shift;
- guint s = 128 + signal;
-
- index = s / 32;
- shift = s % 32;
-
- g_assert (index < 8);
-
- return ((signals_notified[index]) & (1 << shift)) ? TRUE : FALSE;
-}
-
-void
-ve_signal_unnotify (int signal)
-{
- guint index, shift;
- guint s = 128 + signal;
-
- index = s / 32;
- shift = s % 32;
-
- g_assert (index < 8);
-
- signals_notified[index] &= ~(1 << shift);
-}
diff --git a/common/ve-signal.h b/common/ve-signal.h
deleted file mode 100644
index f8f4c4c3..00000000
--- a/common/ve-signal.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Signal routines
- *
- * (c) 2000, 2002 Queen of England
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef _VE_SIGNAL_H
-#define _VE_SIGNAL_H
-
-#include <glib.h>
-
-typedef gboolean (*VeSignalFunc) (int signal,
- gpointer data);
-guint ve_signal_add (int signal,
- VeSignalFunc function,
- gpointer data);
-guint ve_signal_add_full (int priority,
- int signal,
- VeSignalFunc function,
- gpointer data,
- GDestroyNotify destroy);
-/* You must handle the signal notify yourself, you add
- * this function as the signal notification function
- * however */
-void ve_signal_notify (int signal);
-
-gboolean ve_signal_was_notified (int signal);
-void ve_signal_unnotify (int signal);
-
-#endif /* _VE_CONFIG_H */