[Xfce4-commits] r26834 - in xfconf/trunk: common xfconf xfconfd
Brian Tarricone
kelnos at xfce.org
Mon Apr 14 08:00:11 CEST 2008
Author: kelnos
Date: 2008-04-14 06:00:10 +0000 (Mon, 14 Apr 2008)
New Revision: 26834
Added:
xfconf/trunk/xfconfd/xfconf-locking-utils.c
xfconf/trunk/xfconfd/xfconf-locking-utils.h
Removed:
xfconf/trunk/common/xfconf-util.c
xfconf/trunk/common/xfconf-util.h
Modified:
xfconf/trunk/common/Makefile.am
xfconf/trunk/common/xfconf-gvaluefuncs.c
xfconf/trunk/common/xfconf-gvaluefuncs.h
xfconf/trunk/common/xfconf-types.c
xfconf/trunk/xfconf/Makefile.am
xfconf/trunk/xfconfd/Makefile.am
xfconf/trunk/xfconfd/xfconf-backend-perchannel-xml.c
xfconf/trunk/xfconfd/xfconf-daemon.c
Log:
do some rearranging of code locations
* the locking evaluation stuff is really only needed in the daemon
* clean up an extra copy of xfconf_g_value_free()
* move _xfconf_gtype_from_string() to gvaluefuncs
* compile xfconf-types.c directly into the daemon and libxfconf separately
to avoid problems with the aliasdef stuff
Modified: xfconf/trunk/common/Makefile.am
===================================================================
--- xfconf/trunk/common/Makefile.am 2008-04-13 20:46:32 UTC (rev 26833)
+++ xfconf/trunk/common/Makefile.am 2008-04-14 06:00:10 UTC (rev 26834)
@@ -6,10 +6,7 @@
libxfconf_common_la_SOURCES = \
xfconf-errors.c \
xfconf-marshal.c \
- xfconf-marshal.h \
- xfconf-types.c \
- xfconf-util.c \
- xfconf-util.h
+ xfconf-marshal.h
libxfconf_common_la_CFLAGS = \
-DLIBXFCONF_COMPILATION \
@@ -74,4 +71,5 @@
xfconf-aliasdef.c \
xfconf-common-private.h \
xfconf-dbus.xml \
- xfconf-marshal.list
+ xfconf-marshal.list \
+ xfconf-types.c
Modified: xfconf/trunk/common/xfconf-gvaluefuncs.c
===================================================================
--- xfconf/trunk/common/xfconf-gvaluefuncs.c 2008-04-13 20:46:32 UTC (rev 26833)
+++ xfconf/trunk/common/xfconf-gvaluefuncs.c 2008-04-14 06:00:10 UTC (rev 26834)
@@ -63,6 +63,41 @@
#define XFCONF_MAXUCHAR (255)
#endif
+GType
+_xfconf_gtype_from_string(const gchar *type)
+{
+ if(!strcmp(type, "string"))
+ return G_TYPE_STRING;
+ else if(!strcmp(type, "uchar"))
+ return G_TYPE_UCHAR;
+ else if(!strcmp(type, "char"))
+ return G_TYPE_CHAR;
+ else if(!strcmp(type, "uint16"))
+ return XFCONF_TYPE_UINT16;
+ else if(!strcmp(type, "int16"))
+ return XFCONF_TYPE_INT16;
+ else if(!strcmp(type, "uint"))
+ return G_TYPE_UINT;
+ else if(!strcmp(type, "int"))
+ return G_TYPE_INT;
+ else if(!strcmp(type, "uint64"))
+ return G_TYPE_UINT64;
+ else if(!strcmp(type, "int64"))
+ return G_TYPE_INT64;
+ else if(!strcmp(type, "float"))
+ return G_TYPE_FLOAT;
+ else if(!strcmp(type, "double"))
+ return G_TYPE_DOUBLE;
+ else if(!strcmp(type, "bool"))
+ return G_TYPE_BOOLEAN;
+ else if(!strcmp(type, "array"))
+ return XFCONF_TYPE_G_VALUE_ARRAY;
+ else if(!strcmp(type, "empty"))
+ return G_TYPE_NONE;
+
+ return G_TYPE_INVALID;
+}
+
gboolean
_xfconf_gvalue_from_string(GValue *value,
const gchar *str)
Modified: xfconf/trunk/common/xfconf-gvaluefuncs.h
===================================================================
--- xfconf/trunk/common/xfconf-gvaluefuncs.h 2008-04-13 20:46:32 UTC (rev 26833)
+++ xfconf/trunk/common/xfconf-gvaluefuncs.h 2008-04-14 06:00:10 UTC (rev 26834)
@@ -24,6 +24,8 @@
G_BEGIN_DECLS
+GType _xfconf_gtype_from_string(const gchar *type) G_GNUC_INTERNAL;
+
gboolean _xfconf_gvalue_from_string(GValue *value,
const gchar *str) G_GNUC_INTERNAL;
Modified: xfconf/trunk/common/xfconf-types.c
===================================================================
--- xfconf/trunk/common/xfconf-types.c 2008-04-13 20:46:32 UTC (rev 26833)
+++ xfconf/trunk/common/xfconf-types.c 2008-04-14 06:00:10 UTC (rev 26834)
@@ -184,6 +184,7 @@
}
-
+#ifdef LIBXFCONF_COMPILATION
#define __XFCONF_TYPES_C__
#include "xfconf-aliasdef.c"
+#endif
Deleted: xfconf/trunk/common/xfconf-util.c
Deleted: xfconf/trunk/common/xfconf-util.h
Modified: xfconf/trunk/xfconf/Makefile.am
===================================================================
--- xfconf/trunk/xfconf/Makefile.am 2008-04-13 20:46:32 UTC (rev 26833)
+++ xfconf/trunk/xfconf/Makefile.am 2008-04-14 06:00:10 UTC (rev 26834)
@@ -13,7 +13,8 @@
xfconf-channel.c \
xfconf-dbus-bindings.h \
xfconf-private.h \
- xfconf.c
+ xfconf.c \
+ $(top_srcdir)/common/xfconf-types.c
libxfconf_0_la_CFLAGS = \
-I$(top_srcdir) \
Modified: xfconf/trunk/xfconfd/Makefile.am
===================================================================
--- xfconf/trunk/xfconfd/Makefile.am 2008-04-13 20:46:32 UTC (rev 26833)
+++ xfconf/trunk/xfconfd/Makefile.am 2008-04-14 06:00:10 UTC (rev 26834)
@@ -18,7 +18,10 @@
xfconf-daemon.c \
xfconf-daemon.h \
xfconf-dbus-server.h \
- $(xfconf_backend_sources)
+ xfconf-locking-utils.c \
+ xfconf-locking-utils.h \
+ $(xfconf_backend_sources) \
+ $(top_srcdir)/common/xfconf-types.c
xfconfd_CFLAGS = \
-DLIBXFCONF_COMPILATION \
Modified: xfconf/trunk/xfconfd/xfconf-backend-perchannel-xml.c
===================================================================
--- xfconf/trunk/xfconfd/xfconf-backend-perchannel-xml.c 2008-04-13 20:46:32 UTC (rev 26833)
+++ xfconf/trunk/xfconfd/xfconf-backend-perchannel-xml.c 2008-04-14 06:00:10 UTC (rev 26834)
@@ -56,7 +56,7 @@
#include "xfconf-backend-perchannel-xml.h"
#include "xfconf-backend.h"
-#include "xfconf-util.h"
+#include "xfconf-locking-utils.h"
#include "xfconf-gvaluefuncs.h"
#include "xfconf/xfconf-types.h"
#include "xfconf-common-private.h"
@@ -793,41 +793,6 @@
return properties;
}
-static GType
-xfconf_string_type_to_gtype(const gchar *type)
-{
- if(!strcmp(type, "string"))
- return G_TYPE_STRING;
- else if(!strcmp(type, "uchar"))
- return G_TYPE_UCHAR;
- else if(!strcmp(type, "char"))
- return G_TYPE_CHAR;
- else if(!strcmp(type, "uint16"))
- return XFCONF_TYPE_UINT16;
- else if(!strcmp(type, "int16"))
- return XFCONF_TYPE_INT16;
- else if(!strcmp(type, "uint"))
- return G_TYPE_UINT;
- else if(!strcmp(type, "int"))
- return G_TYPE_INT;
- else if(!strcmp(type, "uint64"))
- return G_TYPE_UINT64;
- else if(!strcmp(type, "int64"))
- return G_TYPE_INT64;
- else if(!strcmp(type, "float"))
- return G_TYPE_FLOAT;
- else if(!strcmp(type, "double"))
- return G_TYPE_DOUBLE;
- else if(!strcmp(type, "bool"))
- return G_TYPE_BOOLEAN;
- else if(!strcmp(type, "array"))
- return XFCONF_TYPE_G_VALUE_ARRAY;
- else if(!strcmp(type, "empty"))
- return G_TYPE_NONE;
-
- return G_TYPE_INVALID;
-}
-
static void
xfconf_backend_perchannel_xml_start_elem(GMarkupParseContext *context,
const gchar *element_name,
@@ -1029,7 +994,7 @@
}
/* parse types and values */
- value_type = xfconf_string_type_to_gtype(type);
+ value_type = _xfconf_gtype_from_string(type);
if(G_TYPE_INVALID == value_type) {
if(error) {
g_set_error(error, G_MARKUP_ERROR,
@@ -1090,7 +1055,7 @@
}
}
- value_type = xfconf_string_type_to_gtype(type);
+ value_type = _xfconf_gtype_from_string(type);
if(XFCONF_TYPE_G_VALUE_ARRAY == value_type) {
if(error) {
g_set_error(error, G_MARKUP_ERROR,
Modified: xfconf/trunk/xfconfd/xfconf-daemon.c
===================================================================
--- xfconf/trunk/xfconfd/xfconf-daemon.c 2008-04-13 20:46:32 UTC (rev 26833)
+++ xfconf/trunk/xfconfd/xfconf-daemon.c 2008-04-14 06:00:10 UTC (rev 26834)
@@ -28,7 +28,6 @@
#include "xfconf-backend-factory.h"
#include "xfconf-backend.h"
#include "xfconf-marshal.h"
-#include "xfconf-util.h"
#include "xfconf-gvaluefuncs.h"
#include "xfconf/xfconf-errors.h"
Copied: xfconf/trunk/xfconfd/xfconf-locking-utils.c (from rev 26833, xfconf/trunk/common/xfconf-util.c)
===================================================================
--- xfconf/trunk/xfconfd/xfconf-locking-utils.c (rev 0)
+++ xfconf/trunk/xfconfd/xfconf-locking-utils.c 2008-04-14 06:00:10 UTC (rev 26834)
@@ -0,0 +1,133 @@
+/*
+ * xfconf
+ *
+ * Copyright (c) 2007 Brian Tarricone <bjt23 at cornell.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; version 2 of the License ONLY.
+ *
+ * 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 Library 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#ifdef HAVE_GRP_H
+#include <grp.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "xfconf-locking-utils.h"
+
+/* group cache stuff */
+
+static time_t etc_group_mtime = 0;
+static GHashTable *group_cache = NULL;
+
+static void
+xfconf_ensure_group_cache()
+{
+ gboolean needs_rebuild = FALSE;
+ struct stat st;
+ struct group *gr;
+ GHashTable *members;
+
+ if(!stat("/etc/group", &st)) {
+ if(st.st_mtime > etc_group_mtime) {
+ etc_group_mtime = st.st_mtime;
+ needs_rebuild = TRUE;
+ }
+ } else
+ needs_rebuild = TRUE;
+
+ if(!needs_rebuild && group_cache)
+ return;
+
+ if(group_cache)
+ g_hash_table_destroy(group_cache);
+
+ group_cache = g_hash_table_new_full(g_str_hash, g_str_equal,
+ (GDestroyNotify)g_free,
+ (GDestroyNotify)g_hash_table_destroy);
+
+ for(setgrent(), gr = getgrent(); gr; gr = getgrent()) {
+ gint i;
+
+ members = g_hash_table_new_full(g_str_hash, g_str_equal,
+ (GDestroyNotify)g_free, NULL);
+
+ for(i = 0; gr->gr_mem[i]; ++i) {
+ g_hash_table_replace(members, g_strdup(gr->gr_mem[i]),
+ GINT_TO_POINTER(1));
+ }
+
+ g_hash_table_replace(group_cache, g_strdup(gr->gr_name), members);
+ }
+}
+
+static gboolean
+xfconf_user_is_in_group(const gchar *user,
+ const gchar *group)
+{
+ GHashTable *members;
+
+ xfconf_ensure_group_cache();
+
+ members = g_hash_table_lookup(group_cache, group);
+
+ if(G_UNLIKELY(!members))
+ return FALSE;
+
+ return g_hash_table_lookup(members, user) ? TRUE : FALSE;
+}
+
+gboolean
+xfconf_user_is_in_list(const gchar *list)
+{
+ gboolean ret = FALSE;
+ const gchar *user_name = g_get_user_name();
+ gchar **tokens;
+ gint i;
+
+ tokens = g_strsplit(list, ";", -1);
+
+ for(i = 0; tokens[i]; ++i) {
+ if(!*tokens[i])
+ continue;
+ else if(*tokens[i] == '@') {
+ if(xfconf_user_is_in_group(user_name, tokens[i]+1)) {
+ ret = TRUE;
+ break;
+ }
+ } else {
+ if(!strcmp(user_name, tokens[i])) {
+ ret = TRUE;
+ break;
+ }
+ }
+ }
+
+ g_strfreev(tokens);
+
+ return ret;
+}
Copied: xfconf/trunk/xfconfd/xfconf-locking-utils.h (from rev 26833, xfconf/trunk/common/xfconf-util.h)
===================================================================
--- xfconf/trunk/xfconfd/xfconf-locking-utils.h (rev 0)
+++ xfconf/trunk/xfconfd/xfconf-locking-utils.h 2008-04-14 06:00:10 UTC (rev 26834)
@@ -0,0 +1,33 @@
+/*
+ * xfconf
+ *
+ * Copyright (c) 2007 Brian Tarricone <bjt23 at cornell.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; version 2 of the License ONLY.
+ *
+ * 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 Library 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 __XFCONF_UTIL_H__
+#define __XFCONF_UTIL_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define XFCONF_DBUS_TYPE_G_DOUBLE_ARRAY (dbus_g_type_get_collection("GArray", G_TYPE_DOUBLE))
+
+gboolean xfconf_user_is_in_list(const gchar *list) G_GNUC_INTERNAL;
+
+G_END_DECLS
+
+#endif /* __XFCONF_UTIL_H__ */
More information about the Xfce4-commits
mailing list