[PATCH 1/1] Added client configuration file support.

Ralf Habacker ralf.habacker at freenet.de
Mon Jun 7 07:42:40 PDT 2010


---
 cmake/CMakeLists.txt            |  103 +++++++++++++------------
 cmake/dbus/CMakeLists.txt       |   38 ++++++----
 cmake/doc/CMakeLists.txt        |    1 +
 dbus/client.conf.in             |   10 +++
 dbus/dbus-config-loader-expat.c |  159 +++++++++++++++++++++++++++++++++++++++
 dbus/dbus-config-parser.c       |   67 ++++++++++++++++
 dbus/dbus-config-parser.h       |   51 +++++++++++++
 dbus/dbus-sysdeps-win.c         |   41 ++++++++++-
 doc/clientconfig.dtd            |    3 +
 9 files changed, 408 insertions(+), 65 deletions(-)
 create mode 100644 dbus/client.conf.in
 create mode 100644 dbus/dbus-config-loader-expat.c
 create mode 100644 dbus/dbus-config-parser.c
 create mode 100644 dbus/dbus-config-parser.h
 create mode 100644 doc/clientconfig.dtd

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index 2417c43..85ba1b1 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -50,6 +50,8 @@ endif(NOT WIN32)
 #AC_ARG_ENABLE(asserts, AS_HELP_STRING([--enable-asserts],[include assertion checks]),enable_asserts=$enableval,enable_asserts=$USE_MAINTAINER_MODE)
 OPTION(DBUS_DISABLE_ASSERTS "Disable assertion checking" OFF)
 
+OPTION(DBUS_ENABLE_CLIENT_CONFIG "Enable file based client configuration" OFF)
+
 # do config checks
 INCLUDE(ConfigureChecks.cmake)
 
@@ -277,6 +279,7 @@ if(LIBEXPAT_FOUND)
     OPTION(DBUS_USE_EXPAT "Use expat (== ON) or libxml2 (==OFF)" ON)
 else(LIBEXPAT_FOUND)
     OPTION(DBUS_USE_EXPAT "Use expat (== ON) or libxml2 (==OFF)" OFF)
+	set (DBUS_ENABLE_CLIENT_CONFIG 0)
 endif(LIBEXPAT_FOUND)
 
 if(DBUS_USE_EXPAT)
@@ -425,6 +428,7 @@ if (WIN32)
   else (DBUS_USE_NONCE_TCP_DEFAULT_ADDRESS)
       set (DBUS_SESSION_BUS_DEFAULT_ADDRESS "tcp:host=localhost,port=12434")
       set (DBUS_SYSTEM_BUS_DEFAULT_ADDRESS  "tcp:host=localhost,port=12434")
+      set (DBUS_SESSION_BUS_CLIENT_DEFAULT_ADDRESS "autolaunch:")
   endif (DBUS_USE_NONCE_TCP_DEFAULT_ADDRESS)
   set (DBUS_SYSTEM_CONFIG_FILE "etc/dbus-1/system.conf")
   set (DBUS_SESSION_CONFIG_FILE "etc/dbus-1/session.conf")
@@ -513,61 +517,62 @@ GET_FILENAME_COMPONENT(CXX_COMPILER ${CMAKE_CXX_COMPILER} NAME)
 message("                  D-BUS ${DBUS_VERSION}                               ")
 message("                  ===========                                         ")
 message("                                                                      ")
-message("        install prefix:           ${prefix}                           ")
-message("        install exec_prefix:      ${exec_prefix}                      ")
-message("        install libdir:           ${EXPANDED_LIBDIR}                  ")
-message("        install bindir:           ${EXPANDED_BINDIR}                  ")
-message("        install sysconfdir:       ${EXPANDED_SYSCONFDIR}              ")
-#message("        install localstatedir:    ${EXPANDED_LOCALSTATEDIR}           ")
-message("        install datadir:          ${EXPANDED_DATADIR}                 ")
-message("        source code location:     ${DBUS_SOURCE_DIR}                  ")
-message("        build dir:                ${CMAKE_BINARY_DIR}                 ")
-message("        c compiler:               ${C_COMPILER}                       ")
-message("        cflags:                   ${CMAKE_C_FLAGS}                    ")
-message("        cflags debug:             ${CMAKE_C_FLAGS_DEBUG}              ")
-message("        cflags release:           ${CMAKE_C_FLAGS_RELEASE}            ")
-message("        cxx compiler:             ${CXX_COMPILER}                     ")
-message("        cxxflags:                 ${CMAKE_CXX_FLAGS}                  ")
-message("        cxxflags debug:           ${CMAKE_CXX_FLAGS_DEBUG}            ")
-message("        cxxflags release:         ${CMAKE_CXX_FLAGS_RELEASE}          ")
-message("        64-bit int:               ${DBUS_INT64_TYPE}                  ")
-message("        32-bit int:               ${DBUS_INT32_TYPE}                  ")
-message("        16-bit int:               ${DBUS_INT16_TYPE}                  ")
-message("        Doxygen:                  ${DOXYGEN}                          ")
-message("        Docbook Generator:        ${DOCBOOK_GENERATOR_NAME}           ")
-
-
-#message("        Maintainer mode:          ${USE_MAINTAINER_MODE}              ")
-message("        gcc coverage profiling:   ${DBUS_GCOV_ENABLED}                ")
-message("        Building unit tests:      ${DBUS_BUILD_TESTS}                 ")
-message("        Building verbose mode:    ${DBUS_ENABLE_VERBOSE_MODE}         ")
-message("        Building w/o assertions:  ${DBUS_DISABLE_ASSERTS}             ")
-message("        Building w/o checks:      ${DBUS_DISABLE_CHECKS}              ")
-message("        installing system libs:   ${DBUS_INSTALL_SYSTEM_LIBS}         ")
+message("        install prefix:             ${prefix}                           ")
+message("        install exec_prefix:        ${exec_prefix}                      ")
+message("        install libdir:             ${EXPANDED_LIBDIR}                  ")
+message("        install bindir:             ${EXPANDED_BINDIR}                  ")
+message("        install sysconfdir:         ${EXPANDED_SYSCONFDIR}              ")
+#message("        install localstatedir:      ${EXPANDED_LOCALSTATEDIR}           ")
+message("        install datadir:            ${EXPANDED_DATADIR}                 ")
+message("        source code location:       ${DBUS_SOURCE_DIR}                  ")
+message("        build dir:                  ${CMAKE_BINARY_DIR}                 ")
+message("        c compiler:                 ${C_COMPILER}                       ")
+message("        cflags:                     ${CMAKE_C_FLAGS}                    ")
+message("        cflags debug:               ${CMAKE_C_FLAGS_DEBUG}              ")
+message("        cflags release:             ${CMAKE_C_FLAGS_RELEASE}            ")
+message("        cxx compiler:               ${CXX_COMPILER}                     ")
+message("        cxxflags:                   ${CMAKE_CXX_FLAGS}                  ")
+message("        cxxflags debug:             ${CMAKE_CXX_FLAGS_DEBUG}            ")
+message("        cxxflags release:           ${CMAKE_CXX_FLAGS_RELEASE}          ")
+message("        64-bit int:                 ${DBUS_INT64_TYPE}                  ")
+message("        32-bit int:                 ${DBUS_INT32_TYPE}                  ")
+message("        16-bit int:                 ${DBUS_INT16_TYPE}                  ")
+message("        Doxygen:                    ${DOXYGEN}                          ")
+message("        Docbook Generator:          ${DOCBOOK_GENERATOR_NAME}           ")
+
+
+#message("        Maintainer mode:            ${USE_MAINTAINER_MODE}              ")
+message("        gcc coverage profiling:     ${DBUS_GCOV_ENABLED}                ")
+message("        Building unit tests:        ${DBUS_BUILD_TESTS}                 ")
+message("        Building verbose mode:      ${DBUS_ENABLE_VERBOSE_MODE}         ")
+message("        Building w/o assertions:    ${DBUS_DISABLE_ASSERTS}             ")
+message("        Building w/o checks:        ${DBUS_DISABLE_CHECKS}              ")
+message("        installing system libs:     ${DBUS_INSTALL_SYSTEM_LIBS}         ")
 #message("        Building SELinux support: ${have_selinux}                     ")
 #message("        Building dnotify support: ${have_dnotify}                     ")
-message("        Building Doxygen docs:    ${DBUS_ENABLE_DOXYGEN_DOCS}         ")
-message("        Building XML docs:        ${DBUS_ENABLE_XML_DOCS}             ")
-#message("        Gettext libs (empty OK):  ${INTLLIBS}                         ")
-message("        Using XML parser:         ${XML_LIB}                          ")
-message("        Daemon executable name:   ${DBUS_DAEMON_NAME}")
+message("        Building Doxygen docs:      ${DBUS_ENABLE_DOXYGEN_DOCS}         ")
+message("        Building XML docs:          ${DBUS_ENABLE_XML_DOCS}             ")
+message("        Client config file support: ${DBUS_ENABLE_CLIENT_CONFIG}      ")
+#message("        Gettext libs (empty OK):    ${INTLLIBS}                         ")
+message("        Using XML parser:           ${XML_LIB}                          ")
+message("        Daemon executable name:     ${DBUS_DAEMON_NAME}")
 if (WIN32)
-message("        System bus address:       ${DBUS_SYSTEM_BUS_DEFAULT_ADDRESS}  ")
-message("        Session bus address:      ${DBUS_SESSION_BUS_DEFAULT_ADDRESS} ")
+message("        System bus address:         ${DBUS_SYSTEM_BUS_DEFAULT_ADDRESS}  ")
+message("        Session bus address:        ${DBUS_SESSION_BUS_DEFAULT_ADDRESS} ")
 else (WIN32)
-#message("        Init scripts style:       ${with_init_scripts}                ")
-#message("        Abstract socket names:    ${have_abstract_sockets}            ")
-message("        System bus socket:        ${DBUS_SYSTEM_SOCKET}               ")
-message("        System bus address:       ${DBUS_SYSTEM_BUS_DEFAULT_ADDRESS}  ")
-message("        System bus PID file:      ${DBUS_SYSTEM_PID_FILE}             ")
-message("        Session bus socket dir:   ${DBUS_SESSION_SOCKET_DIR}          ")
-message("        Console auth dir:         ${DBUS_CONSOLE_AUTH_DIR}            ")
-message("        System bus user:          ${DBUS_USER}                        ")
-message("        'make check' socket dir:  ${TEST_SOCKET_DIR}                  ")
+#message("        Init scripts style:         ${with_init_scripts}                ")
+#message("        Abstract socket names:      ${have_abstract_sockets}            ")
+message("        System bus socket:          ${DBUS_SYSTEM_SOCKET}               ")
+message("        System bus address:         ${DBUS_SYSTEM_BUS_DEFAULT_ADDRESS}  ")
+message("        System bus PID file:        ${DBUS_SYSTEM_PID_FILE}             ")
+message("        Session bus socket dir:     ${DBUS_SESSION_SOCKET_DIR}          ")
+message("        Console auth dir:           ${DBUS_CONSOLE_AUTH_DIR}            ")
+message("        System bus user:            ${DBUS_USER}                        ")
+message("        'make check' socket dir:    ${TEST_SOCKET_DIR}                  ")
 endif (WIN32)
-message("        Test listen address:      ${TEST_LISTEN}                      ")
+message("        Test listen address:        ${TEST_LISTEN}                      ")
 if (MSVC)
-message("        build timestamp:          ${DBUS_BUILD_TIMESTAMP}             ")
+message("        build timestamp:            ${DBUS_BUILD_TIMESTAMP}             ")
 endif (MSVC)
 
 MESSAGE(" ")
diff --git a/cmake/dbus/CMakeLists.txt b/cmake/dbus/CMakeLists.txt
index 52cbf90..a1ba969 100644
--- a/cmake/dbus/CMakeLists.txt
+++ b/cmake/dbus/CMakeLists.txt
@@ -3,6 +3,9 @@ project(dbus-lib)
 SET(DBUS_DIR ${CMAKE_SOURCE_DIR}/../dbus)
 
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dbus-arch-deps.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/dbus-arch-deps.h )
+if (DBUS_ENABLE_CLIENT_CONFIG)
+	configure_file(${DBUS_DIR}/client.conf.in ${CMAKE_CURRENT_BINARY_DIR}/client.conf )
+endif (DBUS_ENABLE_CLIENT_CONFIG)
 
 add_definitions(-DDBUS_COMPILATION)
 
@@ -227,26 +230,24 @@ else (WIN32)
 	)
 endif (WIN32)
 
-set(libdbus_SOURCES
-	${DBUS_LIB_SOURCES}
-	${DBUS_SHARED_SOURCES}
-	# for debugging
-	${DBUS_UTIL_SOURCES}
-)
+if (DBUS_ENABLE_CLIENT_CONFIG)
+	set (DBUS_CONFIG_SOURCES
+		${DBUS_DIR}/dbus-config-parser.c
+		${DBUS_DIR}/dbus-config-loader-expat.c
+	)
+	set (DBUS_CONFIG_HEADERS
+		${DBUS_DIR}/dbus-config-parser.h
+	)
+	include_directories(${XML_INCLUDE_DIR})
+endif (DBUS_ENABLE_CLIENT_CONFIG)
 
-set(libdbus_HEADERS 
-	${DBUS_LIB_HEADERS}
-	${DBUS_SHARED_HEADERS}
-	# for debugging
-	${DBUS_UTIL_HEADERS}
-)
 if (MSVC)
     set (BUILD_FILEVERSION ${DBUS_MAJOR_VERSION},${DBUS_MINOR_VERSION},${DBUS_MICRO_VERSION},${DBUS_PATCH_VERSION})
     set (BUILD_TIMESTAMP ${DBUS_BUILD_TIMESTAMP})
     
     configure_file(${DBUS_DIR}/versioninfo.rc.in ${CMAKE_CURRENT_BINARY_DIR}/versioninfo.rc)
     file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/afxres.h "")
-    list(APPEND libdbus_SOURCES versioninfo.rc)
+    list(APPEND DBUS_UTIL_SOURCES versioninfo.rc)
     set_source_files_properties(versioninfo.rc COMPILE_FLAGS "-D__LINE__=1")
 endif (MSVC)
 
@@ -254,6 +255,7 @@ if(MSVC_IDE)
 	project_source_group(${GROUP_CODE} DBUS_LIB_SOURCES DBUS_LIB_HEADERS)
 	project_source_group(${GROUP_CODE} DBUS_SHARED_SOURCES DBUS_SHARED_HEADERS)
 	project_source_group(${GROUP_CODE} DBUS_UTIL_SOURCES DBUS_UTIL_SOURCES)
+	project_source_group(${GROUP_CODE} DBUS_CONFIG_SOURCES DBUS_CONFIG_SOURCES)
 endif(MSVC_IDE)
 
 ### Client library
@@ -262,7 +264,10 @@ add_library(dbus-1 SHARED
 			${DBUS_LIB_SOURCES}
 			${DBUS_SHARED_SOURCES}
 			${DBUS_LIB_HEADERS}
-			${DBUS_SHARED_HEADERS})
+			${DBUS_SHARED_HEADERS}
+			${DBUS_CONFIG_SOURCES}
+			${DBUS_CONFIG_HEADERS}
+)
 if(WIN32)
     if(WINCE)
         target_link_libraries(dbus-1 ws2)
@@ -271,6 +276,11 @@ if(WIN32)
     endif(WINCE)
 endif(WIN32)
 
+if (DBUS_ENABLE_CLIENT_CONFIG)
+	set_target_properties(dbus-1 PROPERTIES COMPILE_FLAGS -DDBUS_ENABLE_CLIENT_CONFIG)
+	target_link_libraries(dbus-1 ${XML_LIBRARY})
+endif (DBUS_ENABLE_CLIENT_CONFIG)
+
 install_targets(/lib dbus-1 )
 install_files(/include/dbus FILES ${dbusinclude_HEADERS})
 
diff --git a/cmake/doc/CMakeLists.txt b/cmake/doc/CMakeLists.txt
index df6b587..52668d2 100644
--- a/cmake/doc/CMakeLists.txt
+++ b/cmake/doc/CMakeLists.txt
@@ -111,6 +111,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/index.html DESTINATION share/doc/dbus)
 
 set (EXTRA_DIST 	
 	${CMAKE_SOURCE_DIR}/../doc/busconfig.dtd			
+	${CMAKE_SOURCE_DIR}/../doc/clientconfig.dtd
 	${CMAKE_SOURCE_DIR}/../doc/introspect.dtd			
 	${CMAKE_SOURCE_DIR}/../doc/introspect.xsl
 )
diff --git a/dbus/client.conf.in b/dbus/client.conf.in
new file mode 100644
index 0000000..24277d6
--- /dev/null
+++ b/dbus/client.conf.in
@@ -0,0 +1,10 @@
+
+<!-- This configuration file controls how dbus clients access the session bus -->
+
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Client Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/clientconfig.dtd">
+<clientconfig>
+	<sessionbus>
+		<connect>@DBUS_SESSION_BUS_CLIENT_DEFAULT_ADDRESS@</connect>
+	</sessionbus>
+</clientconfig>
diff --git a/dbus/dbus-config-loader-expat.c b/dbus/dbus-config-loader-expat.c
new file mode 100644
index 0000000..9897eaf
--- /dev/null
+++ b/dbus/dbus-config-loader-expat.c
@@ -0,0 +1,159 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-config-loader-expat.c  expat XML loader
+ *
+ * Copyright (C) 2010  Ralf Habacker <ralf.habacker at freenet.de>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <config.h>
+#include <dbus/dbus-config-parser.h>
+#include <dbus/dbus-errors.h>
+#include <dbus/dbus-internals.h>
+#include <string.h>
+#include <expat.h>
+
+#ifdef XML_LARGE_SIZE
+#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400
+#define XML_FMT_INT_MOD "I64"
+#else
+#define XML_FMT_INT_MOD "ll"
+#endif
+#else
+#define XML_FMT_INT_MOD "l"
+#endif
+
+typedef struct {
+    ClientConfigParser *parser;
+    DBusString content;
+    dbus_bool_t in_session_bus;
+    DBusError *error;
+    dbus_bool_t failed;
+} ExpatClientParseContext;
+
+static void XMLCALL
+client_config_start_element (void *userData, const char *name, const char **atts)
+{
+  ExpatClientParseContext *context  = userData;
+  _dbus_string_set_length (&context->content, 0);
+  if (strcmp (name,"sessionbus") == 0)
+      context->in_session_bus = TRUE;
+}
+
+static void XMLCALL
+client_config_end_element (void *userData, const char *name)
+{
+  ExpatClientParseContext *context = userData;
+
+  if (_dbus_string_get_length (&context->content) > 0)
+    {
+       if (context->in_session_bus && strcmp (name,"connect") == 0)
+           context->parser->session_bus_address = _dbus_strdup (_dbus_string_get_const_data (&context->content));
+      _dbus_string_set_length (&context->content, 0);
+    }
+   if (strcmp (name,"sessionbus") == 0)
+	   context->in_session_bus = FALSE;
+}
+
+/* s is not 0 terminated. */
+static void
+client_config_CharacterDataHandler (void           *userData,
+                                    const XML_Char *s,
+                                    int             len)
+{
+  ExpatClientParseContext *context = userData;
+  if (context->failed)
+    return;
+
+  if (!_dbus_string_append_len (&context->content,
+                                s, len))
+    {
+      dbus_set_error (context->error, DBUS_ERROR_NO_MEMORY, NULL);
+      context->failed = TRUE;
+      return;
+    }
+}
+
+ClientConfigParser*
+client_config_load (const DBusString         *file,
+                   const ClientConfigParser *parent,
+                   DBusError                *error)
+{
+  ClientConfigParser *parser;
+  ExpatClientParseContext context;
+  DBusString data;
+  const char *data_str;
+  XML_Parser expat = XML_ParserCreate(NULL);
+
+  parser = NULL;
+  context.error = error;
+  context.failed = FALSE;
+  context.in_session_bus = FALSE;
+
+  if (!_dbus_string_init (&context.content))
+    {
+      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+      return NULL;
+    }
+
+  if (!_dbus_string_init (&data))
+    {
+      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+      goto failed;
+    }
+
+  if (!_dbus_file_get_contents (&data, file, error))
+    {
+      _dbus_string_free (&data);
+      goto failed;
+    }
+
+  data_str = _dbus_string_get_const_data (&data);
+
+  context.parser = client_config_parser_new (0,0,0);
+
+  XML_SetUserData (expat, &context);
+  XML_SetElementHandler (expat, client_config_start_element, client_config_end_element);
+  XML_SetCharacterDataHandler (expat, client_config_CharacterDataHandler);
+  if (!XML_Parse (expat, data_str, _dbus_string_get_length (&data), TRUE))
+    {
+      if (context.error != NULL &&
+          !dbus_error_is_set (context.error))
+        {
+          enum XML_Error e;
+
+          e = XML_GetErrorCode (expat);
+          if (e == XML_ERROR_NO_MEMORY)
+            dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+          else
+            dbus_set_error (error, DBUS_ERROR_FAILED,
+                            "Error in file %s, line %d, column %d: %s\n",
+                            _dbus_string_get_const_data (file),
+                            XML_GetCurrentLineNumber (expat),
+                            XML_GetCurrentColumnNumber (expat),
+                            XML_ErrorString (e));
+        }
+    }
+    _dbus_string_free (&data);
+
+  XML_ParserFree (expat);
+  return context.parser;
+failed:
+  XML_ParserFree (expat);
+  return 0;
+}
diff --git a/dbus/dbus-config-parser.c b/dbus/dbus-config-parser.c
new file mode 100644
index 0000000..ee8dd04
--- /dev/null
+++ b/dbus/dbus-config-parser.c
@@ -0,0 +1,67 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-config-parser.c client config parser implementation
+ *
+ * Copyright (C) 2010  Ralf Habacker <ralf.habacker at freenet.de>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <config.h>
+#include "dbus-config-parser.h"
+#include "dbus-internals.h"
+
+ClientConfigParser* client_config_parser_new (const DBusString         *basedir,
+                                              dbus_bool_t               is_toplevel,
+                                              const ClientConfigParser *parent)
+{
+  ClientConfigParser *parser = dbus_new0(ClientConfigParser,1);
+  if (parser == NULL)
+    return NULL;
+
+  parser->session_bus_address = 0;
+  parser->refcount = 1;
+  return parser;
+}
+
+ClientConfigParser *client_config_parser_ref (ClientConfigParser *parser)
+{
+  _dbus_assert (parser->refcount > 0);
+
+  parser->refcount += 1;
+
+  return parser;
+}
+
+void client_config_parser_unref (ClientConfigParser *parser)
+{
+  _dbus_assert (parser->refcount > 0);
+
+  parser->refcount -= 1;
+
+  if (parser->refcount == 0)
+    {
+      if (parser->session_bus_address)
+          dbus_free(parser->session_bus_address);
+      dbus_free(parser);
+    }
+}
+
+const char *client_config_parser_get_session_bus_address (ClientConfigParser *parser)
+{
+    return parser->session_bus_address;
+}
diff --git a/dbus/dbus-config-parser.h b/dbus/dbus-config-parser.h
new file mode 100644
index 0000000..ff27ce2
--- /dev/null
+++ b/dbus/dbus-config-parser.h
@@ -0,0 +1,51 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-config-parser.h client config parser definitions
+ *
+ * Copyright (C) 2010  Ralf Habacker <ralf.habacker at freenet.de>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef DBUS_CONFIG_PARSER_H
+#define DBUS_CONFIG_PARSER_H
+
+#include "dbus-string.h"
+#include "dbus-errors.h"
+
+typedef struct {
+    char *session_bus_address;
+    int refcount;
+} ClientConfigParser;
+
+ClientConfigParser* client_config_parser_new (const DBusString         *basedir,
+                                              dbus_bool_t               is_toplevel,
+                                              const ClientConfigParser *parent);
+
+const char *client_config_parser_get_session_bus_address (ClientConfigParser *parser);
+
+void client_config_parser_unref (ClientConfigParser *parser);
+
+ClientConfigParser *client_config_parser_ref (ClientConfigParser *parser);
+
+ClientConfigParser*
+client_config_load (const DBusString         *file,
+                    const ClientConfigParser *parent,
+                    DBusError                *error);
+
+
+#endif
diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c
index aad342c..cce15e0 100644
--- a/dbus/dbus-sysdeps-win.c
+++ b/dbus/dbus-sysdeps-win.c
@@ -37,6 +37,7 @@
 #endif
 
 #include "dbus-internals.h"
+#include "dbus-config-parser.h"
 #include "dbus-sysdeps.h"
 #include "dbus-threads.h"
 #include "dbus-protocol.h"
@@ -3062,14 +3063,52 @@ _dbus_append_session_config_file (DBusString *str)
   return _dbus_get_config_file_name(str, "session.conf");
 }
 
+dbus_bool_t
+_dbus_append_client_config_file (DBusString *str)
+{
+  return _dbus_get_config_file_name(str, "client.conf");
+}
+
 /* See comment in dbus-sysdeps-unix.c */
 dbus_bool_t
 _dbus_lookup_session_address (dbus_bool_t *supported,
                               DBusString  *address,
                               DBusError   *error)
 {
-  /* Probably fill this in with something based on COM? */
-  *supported = FALSE;
+#if DBUS_ENABLE_CLIENT_CONFIG
+  DBusString client_config_file;
+  ClientConfigParser *parser;
+  char *s;
+  *supported = TRUE;
+
+  if (!_dbus_string_init (&client_config_file))
+    {
+      _DBUS_SET_OOM (error);
+      return FALSE;
+    }
+
+  if (!_dbus_append_client_config_file (&client_config_file))
+    {
+      _DBUS_SET_OOM (error);
+      return FALSE;
+    }
+
+  parser = client_config_load (&client_config_file,0,error);
+  if (!parser)
+    {
+      _dbus_warn ("Could not load client config file %s: %s\n",
+                  _dbus_string_get_const_data (&client_config_file),
+                  error->message);
+      dbus_error_free (error);
+      _dbus_string_free (&client_config_file);
+      return FALSE;
+    }
+  s  = client_config_parser_get_session_bus_address (parser);
+  _dbus_string_append (address,s);
+  client_config_parser_unref (parser);
+#else
+  *supported = FALSE;
+#endif
   return TRUE;
 }
 
diff --git a/doc/clientconfig.dtd b/doc/clientconfig.dtd
new file mode 100644
index 0000000..d79103a
--- /dev/null
+++ b/doc/clientconfig.dtd
@@ -0,0 +1,3 @@
+<!ELEMENT clientconfig (sessionbus)*>
+<!ELEMENT sessionbus(connect)*>
+<!ELEMENT connect(#PCDATA)>
-- 
1.7.0.2.msysgit.0


--------------060100070800000203000106
Content-Type: text/xml;
 name="libdbus.xml"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="libdbus.xml"

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
                   "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
<refentry id='libdbus_configuration'>
<!--   -->
<!--  libdbus manual page. -->
<!--  Copyright (C) 2010 Ralf Habacker -->

<refmeta>
<refentrytitle>libdbus configuration</refentrytitle>
<manvolnum>1</manvolnum>
</refmeta>
<refnamediv id='name'>
<refname>libdbus configuration</refname>
<refpurpose>message bus library configuration</refpurpose>
</refnamediv>

<refsect1 id='configuration_file'><title>CONFIGURATION FILE</title>
<para>The dbus message bus library could be compiled to have a client configuration file. 
The client configuration file allows to set client related parameters like bus addresses.</para>
<para>
The client configuration file is an alternative to the usage of environment variables. 
The main cases for using this client configuration file are operating system environments 
where environment variables are not usable or does not fit into the required use cases.</para>

<para>The configuration file is not part of any interoperability
specification and its backward compatibility is not guaranteed; this
document is documentation, not specification.</para>

<para>The standard message bus client setups are configured in the files "/etc/dbus-1/client.conf" on unix or 
"&lt;install-root&gt;/etc/dbus-1/client.conf" on other systems.</para>

<para>The configuration file is an XML document. It must have the following
doctype declaration:</para>
<literallayout remap='.nf'>
   &lt;!DOCTYPE clientconfig PUBLIC "-//freedesktop//DTD D-Bus Client Configuration 1.0//EN"
    "<ulink url='http://www.freedesktop.org/standards/dbus/1.0/clientconfig.dtd'>http://www.freedesktop.org/standards/dbus/1.0/clientconfig.dtd</ulink>"&gt;
</literallayout> <!-- .fi -->

<para>The following elements may be present in the configuration file.</para>

<variablelist remap='TP'>
  <varlistentry>
  <term><emphasis remap='I'>&lt;clientconfig&gt;</emphasis></term>
  <listitem>
<para></para> 
  </listitem>
  </varlistentry>
</variablelist>

<para>Root element.</para>

<variablelist remap='TP'>
  <varlistentry>
  <term><emphasis remap='I'>&lt;sessionbus&gt;</emphasis></term>
  <listitem>

<para></para> <!-- FIXME: blank list item -->
  </listitem>
  </varlistentry>
</variablelist>

<para>Specifies that the following elements belongs to the message bus. The following elements are available:</para>

<variablelist remap='TP'>
  <varlistentry>
  <term><emphasis remap='I'>&lt;connect&gt;</emphasis></term>
  <listitem>
<para></para> 
  </listitem>
  </varlistentry>
</variablelist>

<para>Specifices the session bus address to which the client should connect.</para>

<para>Example: &lt;connect&gt;tcp:host=localhost,port=1234&lt;/connect&gt;</para>
<para>Example: &lt;connect&gt;autolaunch:&lt;/connect&gt;</para>

<variablelist remap='TP'>
  <varlistentry>
  <term><emphasis remap='I'>&lt;verbose&gt;</emphasis></term>
  <listitem>
<para></para> 
  </listitem>
  </varlistentry>
</variablelist>

<refsect1 id='author'><title>AUTHOR</title>
<para>See <ulink url='http://www.freedesktop.org/software/dbus/doc/AUTHORS'>http://www.freedesktop.org/software/dbus/doc/AUTHORS</ulink></para>

</refsect1>

<refsect1 id='bugs'><title>BUGS</title>
<para>Please send bug reports to the D-Bus mailing list or bug tracker,
see <ulink url='http://www.freedesktop.org/software/dbus/'>http://www.freedesktop.org/software/dbus/</ulink></para>
</refsect1>
</refentry>


--------------060100070800000203000106--


More information about the dbus mailing list