gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r32345 - in gnunet-dbus: . src src/dht src/gns src/lib src/


From: gnunet
Subject: [GNUnet-SVN] r32345 - in gnunet-dbus: . src src/dht src/gns src/lib src/services
Date: Fri, 14 Feb 2014 12:08:47 +0100

Author: canndrew
Date: 2014-02-14 12:08:46 +0100 (Fri, 14 Feb 2014)
New Revision: 32345

Added:
   gnunet-dbus/src/lib/gnunet_dbus_lib_arg.c
   gnunet-dbus/src/lib/gnunet_dbus_lib_arg.h
   gnunet-dbus/src/lib/gnunet_dbus_lib_client.c
   gnunet-dbus/src/lib/gnunet_dbus_lib_client.h
   gnunet-dbus/src/lib/gnunet_dbus_lib_interface.c
   gnunet-dbus/src/lib/gnunet_dbus_lib_interface.h
   gnunet-dbus/src/lib/gnunet_dbus_lib_message_iter_pop.c
   gnunet-dbus/src/lib/gnunet_dbus_lib_message_iter_pop.h
   gnunet-dbus/src/lib/gnunet_dbus_lib_message_iter_push.c
   gnunet-dbus/src/lib/gnunet_dbus_lib_message_iter_push.h
   gnunet-dbus/src/lib/gnunet_dbus_lib_method.c
   gnunet-dbus/src/lib/gnunet_dbus_lib_method.h
   gnunet-dbus/src/lib/gnunet_dbus_lib_method_context.c
   gnunet-dbus/src/lib/gnunet_dbus_lib_method_context.h
   gnunet-dbus/src/lib/gnunet_dbus_lib_object.c
   gnunet-dbus/src/lib/gnunet_dbus_lib_object.h
   gnunet-dbus/src/lib/gnunet_dbus_lib_service.c
   gnunet-dbus/src/lib/gnunet_dbus_lib_service.h
   gnunet-dbus/src/lib/gnunet_dbus_lib_signature.c
   gnunet-dbus/src/lib/gnunet_dbus_lib_signature.h
   gnunet-dbus/src/lib/timeout.c
   gnunet-dbus/src/lib/timeout.h
   gnunet-dbus/src/lib/watch.c
   gnunet-dbus/src/lib/watch.h
   gnunet-dbus/src/services/
   gnunet-dbus/src/services/Makefile.am
   gnunet-dbus/src/services/gnunet-service-gns-dbus.c
   gnunet-dbus/src/services/gnunet-service-namecache-dbus.c
Removed:
   gnunet-dbus/src/dht/Makefile.am
   gnunet-dbus/src/dht/gnunet-service-dht-dbus.c
   gnunet-dbus/src/dht/gnunet-service-dht-dbus.h
   gnunet-dbus/src/dht/gnunet-service-dht-dbus_client.c
   gnunet-dbus/src/dht/gnunet-service-dht-dbus_client.h
   gnunet-dbus/src/dht/gnunet-service-dht-dbus_dht.c
   gnunet-dbus/src/dht/gnunet-service-dht-dbus_dht.h
   gnunet-dbus/src/dht/gnunet-service-dht-dbus_put.c
   gnunet-dbus/src/gns/Makefile.am
   gnunet-dbus/src/gns/gnunet-service-gns-dbus.c
   gnunet-dbus/src/gns/gnunet-service-gns-dbus_gns.c
   gnunet-dbus/src/gns/gnunet-service-gns-dbus_gns.h
   gnunet-dbus/src/gns/gnunet-service-gns-dbus_lookup.h
   gnunet-dbus/src/lib/dbus_type_to_string.c
   gnunet-dbus/src/lib/dbus_type_to_string.h
   gnunet-dbus/src/lib/gnunet_dbus_lib.c
   gnunet-dbus/src/lib/gnunet_dbus_lib_block.c
   gnunet-dbus/src/lib/gnunet_dbus_lib_crypto.c
   gnunet-dbus/src/lib/gnunet_dbus_lib_crypto.h
   gnunet-dbus/src/lib/gnunet_dbus_lib_dht.c
   gnunet-dbus/src/lib/gnunet_dbus_lib_pop.c
   gnunet-dbus/src/lib/gnunet_xstring_lib.c
   gnunet-dbus/src/lib/gnunet_xstring_lib.h
Modified:
   gnunet-dbus/configure.ac
   gnunet-dbus/src/Makefile.am
   gnunet-dbus/src/lib/Makefile.am
   gnunet-dbus/src/lib/gnunet_dbus_lib.h
Log:
Refactored library code. GNS proxy can perform lookups.

Modified: gnunet-dbus/configure.ac
===================================================================
--- gnunet-dbus/configure.ac    2014-02-14 10:35:11 UTC (rev 32344)
+++ gnunet-dbus/configure.ac    2014-02-14 11:08:46 UTC (rev 32345)
@@ -1,4 +1,4 @@
-AC_INIT([gnunet-dbus],[0.9.5a],address@hidden)
+AC_INIT([gnunet-dbus],[0.10.0],address@hidden)
 AM_INIT_AUTOMAKE([-Wall -Werror])
 AC_CONFIG_MACRO_DIR([m4])
 AC_PROG_CC
@@ -9,14 +9,11 @@
 Makefile
 src/Makefile
 src/lib/Makefile
-src/gns/Makefile
+src/services/Makefile
 ])
 
 PKG_CHECK_MODULES([DBUS], [dbus-1 >= 1.6.12])
 
-AC_CHECK_LIB([dbus-1], [dbus_type_to_string])
-AC_REPLACE_FUNCS([dbus_type_to_string])
-
 CFLAGS="$CFLAGS -Wall -Werror"
 CFLAGS="$CFLAGS $DBUS_CFLAGS"
 LDFLAGS="$LDFLAGS $DBUS_LDFLAGS"

Modified: gnunet-dbus/src/Makefile.am
===================================================================
--- gnunet-dbus/src/Makefile.am 2014-02-14 10:35:11 UTC (rev 32344)
+++ gnunet-dbus/src/Makefile.am 2014-02-14 11:08:46 UTC (rev 32345)
@@ -1,2 +1,2 @@
-SUBDIRS = lib gns
+SUBDIRS = lib services
 

Deleted: gnunet-dbus/src/dht/Makefile.am
===================================================================
--- gnunet-dbus/src/dht/Makefile.am     2014-02-14 10:35:11 UTC (rev 32344)
+++ gnunet-dbus/src/dht/Makefile.am     2014-02-14 11:08:46 UTC (rev 32345)
@@ -1,13 +0,0 @@
-bin_PROGRAMS = \
-  gnunet-service-dht-dbus
-
-gnunet_service_dht_dbus_SOURCES = \
-       gnunet-service-dht-dbus.c
-
-gnunet_service_dht_dbus_LDADD = \
-  libgnunetdbus.la \
-       libgnunetdbus_dht.la \
-       libgnunetdbus_block.la \
-       libgnunetxstring.la \
-  -lgnunetutil
-

Deleted: gnunet-dbus/src/dht/gnunet-service-dht-dbus.c
===================================================================
--- gnunet-dbus/src/dht/gnunet-service-dht-dbus.c       2014-02-14 10:35:11 UTC 
(rev 32344)
+++ gnunet-dbus/src/dht/gnunet-service-dht-dbus.c       2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -1,124 +0,0 @@
-#include "config.h"
-
-#include <stdint.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-
-#include <dbus/dbus.h>
-
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_common.h>
-#include <gnunet/gnunet_strings_lib.h>
-#include <gnunet/gnunet_program_lib.h>
-#include <gnunet/gnunet_getopt_lib.h>
-#include <gnunet/gnunet_scheduler_lib.h>
-#include <gnunet/gnunet_dht_service.h>
-
-#include "gnunet_dbus_lib.h"
-#include "gnunet-service-dht-dbus_dht.h"
-#include "xstring.h"
-
-static void
-shutdown_task (
-    void *cls,
-    const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct DHT *dht = (struct DHT *)cls;
-
-  DHT_destroy (dht);
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down.\n");
-};
-
-/*
- * Main function run by the scheduler.
- *
- * @param cls our one and only DHT object
- * @param args remaining program command line args
- * @param configfile name of the config file
- * @param cfg the program configuration
- */
-static void
-run (
-    void *cls,
-    char *const *args,
-    const char *configfile,
-    const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running.\n");
-
-  struct DHT *dht = DHT_create (cfg);
-  if (NULL == dht)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create DHT.\n");
-    return;
-  };
-  
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, shutdown_task, 
dht);
-  return;
-};
-
-int
-main (int argc, char *const *argv)
-{
-  int ret;
-
-  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_OPTION_END
-  };
-  static const char bin_name[] = "gnunet-service-dht-dbus [OPTIONS]";
-  static const char bin_help[] = gettext_noop ("DBus proxy for 
gnunet-service-dht");
-
-  ret = GNUNET_log_setup ("gnunet-service-dht-dbus", "DEBUG", NULL);
-  if (GNUNET_OK != ret)
-  {
-    fprintf(stderr, "ERROR: Failed to setup logging. GNUNET_log_setup returned 
%d\n", ret);
-    return 1;
-  }
-
-  ret = GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv);
-  if (GNUNET_OK != ret) {
-    size_t size;
-    char *error;
-    int i;
-
-    size = GNUNET_XSTRING_NEW_DEFAULT_SIZE;
-    error = GNUNET_XSTRING_new();
-    GNUNET_XSTRING_appendf(&error, &size, "Failed to utf8 encode arguments. 
GNUNET_STRINGS_get_utf_args(%d, {", argc);
-    for(i = 0; i < argc; i++) {
-      GNUNET_XSTRING_appendf(&error, &size, "\"%s\"", argv[i]);
-      if(i != argc - 1)
-        GNUNET_XSTRING_appendf(&error, &size, ", ");
-    };
-    GNUNET_XSTRING_appendf(&error, &size, "}, %p, %p) returned %d\n", &argc, 
&argv, ret);
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", error);
-    GNUNET_free(error);
-    return 1;
-  };
-
-  ret = GNUNET_PROGRAM_run (argc, argv, bin_name, bin_help, options, run, 
NULL);
-  if (GNUNET_OK != ret)
-  {
-    size_t size;
-    char *error;
-    int i;
-
-    size = GNUNET_XSTRING_NEW_DEFAULT_SIZE;
-    error = GNUNET_XSTRING_new();
-    GNUNET_XSTRING_appendf(&error, &size, "Failed to run program. 
GUNNET_PROGRAM_run(%d, {", argc);
-    for(i = 0; i < argc; i++)
-      GNUNET_XSTRING_appendf(&error, &size, "%s\"%s\"", i ? ", " : "", 
argv[i]);
-    GNUNET_XSTRING_appendf(&error, &size, "}, \"%s\", \"%s\", %p, %p, NULL) 
returned %d\n", bin_name, bin_help, &options, run, ret);
-    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s", error);
-    GNUNET_free(error);
-    GNUNET_free ((void *)argv);
-    return 1;
-  };
-
-  GNUNET_free ((void *)argv);
-  return 0;
-};
-

Deleted: gnunet-dbus/src/dht/gnunet-service-dht-dbus.h
===================================================================
--- gnunet-dbus/src/dht/gnunet-service-dht-dbus.h       2014-02-14 10:35:11 UTC 
(rev 32344)
+++ gnunet-dbus/src/dht/gnunet-service-dht-dbus.h       2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -1,14 +0,0 @@
-#ifndef GNUNET_SERVICE_DHT_DBUS_H
-#define GNUNET_SERVICE_DHT_DBUS_H
-
-struct DHTPut
-{
-  struct DHTPut *next;
-  struct DHTPut *prev;
-
-  struct GNUNET_DHT_PutHandle *put_handle;
-  char *path;
-};
-
-#endif
-

Deleted: gnunet-dbus/src/dht/gnunet-service-dht-dbus_client.c
===================================================================
--- gnunet-dbus/src/dht/gnunet-service-dht-dbus_client.c        2014-02-14 
10:35:11 UTC (rev 32344)
+++ gnunet-dbus/src/dht/gnunet-service-dht-dbus_client.c        2014-02-14 
11:08:46 UTC (rev 32345)
@@ -1,70 +0,0 @@
-#include "gnunet-service-dht-dbus_client.h"
-
-/*
- * Internal representation of connected dbus clients.
- */
-struct DHTClient
-{
-  struct DHTClient *next;
-  struct DHTClient *prev;
-
-  struct DHTPut *puts;
-
-  char *unique_name;
-
-  /*
-   * Our connection to the dht service.
-   * Each connected client uses it's own connection.
-   */
-  struct GNUNET_DHT_Handle *dht_handle;
-};
-
-struct DHTClient *
-DHTClient_create (
-    const struct GNUNET_CONFIGURATION_Handle *cfg,
-    const char *unique_name)
-{
-  struct DHTClient *client = GNUNET_new (struct DHTClient);
-  client->next = NULL;
-  client->prev = NULL;
-  client->puts = NULL;
-  client->unique_name = GNUNET_strdup (unique_name);
-  client->dht_handle = GNUNET_DHT_connect (cfg, 1);
-
-  return client;
-};
-
-void
-DHTClient_destroy (
-    struct DHTClient *client)
-{
-  if (client->dht_handle)
-    GNUNET_DHT_disconenct (client->dht_handle);
-
-  if (client->puts)
-    DHTPut_destroy_all (client->puts);
-
-  GNUNET_free (client);
-};
-
-void DHTClient_destroy_all (
-    struct DHTClient *client)
-{
-  if (client->next)
-    DHTClient_destroy_all (client->next);
-
-  GNUNET_free (client);
-};
-
-void
-DHTClient_add_put (
-    struct DHTClient *client,
-    struct DHTPut *put)
-{
-  put->next = client->puts;
-  put->prev = NULL;
-  client->puts = put;
-};
-  
-
-

Deleted: gnunet-dbus/src/dht/gnunet-service-dht-dbus_client.h
===================================================================
--- gnunet-dbus/src/dht/gnunet-service-dht-dbus_client.h        2014-02-14 
10:35:11 UTC (rev 32344)
+++ gnunet-dbus/src/dht/gnunet-service-dht-dbus_client.h        2014-02-14 
11:08:46 UTC (rev 32345)
@@ -1,20 +0,0 @@
-#ifndef GNUNET_SERVICE_DHT_DBUS_CLIENT_H
-#define GNUNET_SERVICE_DHT_DBUS_CLIENT_H
-
-struct DHTClient;
-
-struct DHTClient *
-DHTClient_create (
-    const struct GNUNET_CONFIGURATION_Handle *cfg,
-    const char *unique_name);
-
-void
-DHTClient_destroy (
-    struct DHTClient *);
-
-void
-DHTClient_destroy_all (
-    struct DHTClient *);
-
-#endif
-

Deleted: gnunet-dbus/src/dht/gnunet-service-dht-dbus_dht.c
===================================================================
--- gnunet-dbus/src/dht/gnunet-service-dht-dbus_dht.c   2014-02-14 10:35:11 UTC 
(rev 32344)
+++ gnunet-dbus/src/dht/gnunet-service-dht-dbus_dht.c   2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -1,223 +0,0 @@
-#include "gnunet-service-dht-dbus_dht.h"
-
-/*
- * Internal representation of the DHT service.
- */
-struct DHT
-{
-  /*
-   * The program configuration
-   */
-  struct GNUNET_CONFIGURATION_Handle *cfg;
-
-  struct GNUNET_DBUS_Service *service;
-  struct GNUNET_DBUS_Object *dht;
-  struct DHTClient *clients;
-};
-
-static const char *introspection_data_dht = \
-    DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                                  
     \
-    "<node>\n"                                                                 
     \
-    "  <interface name=\"org.gnunet.dht\">\n"                                  
     \
-    "    <method name=\"put\">\n"                                              
     \
-    "      <arg name=\"key\" type=\"s\" direction=\"in\"/>\n"                  
     \
-    "      <arg name=\"desired_replication_level\" type=\"u\" 
direction=\"in\"/>\n" \
-    "      <arg name=\"options\" type=\"u\" direction=\"in\"/>\n"              
     \
-    "      <arg name=\"block_type\" type=\"u\" direction=\"in\"/>\n"           
     \
-    "      <arg name=\"socket\" type=\"s\" direction=\"in\"/>\n"               
     \
-    "      <arg name=\"expiration_time\" type=\"s\" direction=\"in\"/>\n"      
     \
-    "      <arg name=\"request\" type=\"o\" direction=\"out\"/>\n"             
     \
-    "    </method>\n"                                                          
     \
-    "  </interface>\n"                                                         
     \
-    "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"             
     \
-    "    <method name=\"Introspect\">\n"                                       
     \
-    "      <arg name=\"data\" type=\"s\" direction=\"out\"/>\n"                
     \
-    "    </method>\n"                                                          
     \
-    "  </interface>\n"                                                         
     \
-    "</node>\n"                                                                
     \
-    ;
-struct DHT *
-DHT_create (
-    GNUNET_CONFIGURATION_Handle *cfg)
-{
-  int err;
-  struct DHT *dht = GNUNET_new (struct DHT);
-  dht->cfg = cfg;
-  dht->service = GNUNET_DBUS_service_create ("dht", cfg);
-  if (! dht->service)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DBUS_service_create failed to 
create dht service.\n");
-    DHT_destroy (dht);
-    return NULL;
-  }
-  dht->dht = GNUNET_DBUS_object_create (dht);
-  if (! dht->dht)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DBUS_object_create failed to 
create /dht object.\n");
-    DHT_destroy (dht);
-    return NULL;
-  }
-  err = GNUNET_DBUS_object_add_method (dht->dht, "org.gnunet.dht", "put", 
method_dht_put);
-  if (GNUNET_OK != err)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DBUS_object_add_method failed 
to add put method to dht.\n");
-    DHT_destroy (dht);
-    return NULL;
-  }
-  err = GNUNET_DBUS_service_register_object (dht->service, dht->dht, "/dht");
-  if (GNUNET_OK != err)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DBUS_service_register_object 
failed to register /dht object.\n");
-    DHT_destroy (dht);
-    return NULL;
-  }
-  dht->clients = NULL;
-  return dht;
-};
-
-void
-DHT_destroy (
-    struct DHT *dht)
-{
-  if (dht->service)
-    GNUNET_DBUS_service_destroy (dht->service);
-  if (dht->dht)
-    GNUNET_DBUS_object_destroy (dht->dht);
-  if (dht->clients)
-    DHTClient_destroy_all (dht->clients);
-};
-
-static DBusMessage *
-method_dht_introspect (
-    struct GNUNET_DBUS_Client *client,
-    struct GNUNET_DBUS_Object *object,
-    DBusMessage *message)
-{
-  (void)client;
-  (void)object;
-
-  DBusMessage *ret = dbus_message_new_method_return (message);
-  if (! ret)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "dbus_message_new_method_return 
returned NULL. Out of memory.\n");
-    return NULL;
-  }
-
-  DBusMessageIter args;
-  dbus_message_iter_init_append (ret, &args);
-  if (! dbus_message_iter_append_basic (
-      &args,
-      DBUS_TYPE_STRING,
-      &introspection_data_dht))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "dbus_message_iter_append_basic 
returned NULL. Out of memory.\n");
-    return NULL;
-  };
-
-  return ret;
-};
-
-static void
-put_continuation (
-    void *cls,
-    int success)
-{
-  
-};
-
-static DBusMessage *
-method_dht_put (
-    struct GNUNET_DBUS_Object *object,
-    DBusMessage *message)
-{
-  DBusMessage *ret = NULL;
-
-  struct GNUNET_HashCode key;
-  uint32_t desired_replication_level;
-  enum GNUNET_DHT_RouteOption options;
-  enum GNUNET_BLOCK_Type type;
-  uint32_t size;
-  char *data;
-  struct GNUNET_TIME_Absolute expiration;
-
-  dbus_message_iter_init (message, &iter);
-  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_hashcode (message, &iter, 
"key", &key);
-  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_uint32 (message, &iter, 
"desired_replication_level", &desired_replication_level);
-  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_dht_routeoption (message, 
&iter, "options", &options);
-  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_block_type (message, &iter, 
"type", &type);
-  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_uint32 (message, &iter, 
"size", &size);
-  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_array_byte (message, &iter, 
"data", &data);
-  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_absolute_time (message, 
&iter, "expiration", &expiration);
-  if (ret)
-    return ret;
-
-#if 0
-  struct DHT *dht                 = (struct DHT *)GNUNET_DBUS_object_get_data 
(object);
-  if (! dht)
-  {
-    return dbus_message_new_error_printf (
-      message,
-      DBUS_ERROR_FAILED,
-      "GNUNET_DBUS_object_get_data returned NULL in method_dht_put. Check 
GNUNet logs for more info.");
-  };
-
-  struct DHTClient *dht_client    = DHT_get_client (dht, 
dbus_message_get_sender (message));
-  if (! dht_client)
-  {
-    return dbus_message_new_error_printf (
-      message,
-      DBUS_ERROR_FAILED,
-      "DHT_get_client returned NULL in method_dht_put. Check GNUNet logs for 
more info.");
-  };
-
-  struct DHTPut *dht_put = GNUNET_new (struct DHTPut);
-  dht_put->ph = GNUNET_DHT_put (
-      dht_client->dht_handle,
-      key,
-      desired_replication_level,
-      options,
-      type,
-      size,
-      data,
-      expiration,
-      timeout,
-      put_continuation,
-      dht_put);
-  if (! dht_put->ph)
-  {
-    GNUNET_free (dht_put);
-    return dbus_message_new_error_printf (
-        message,
-        DBUS_ERROR_FAILED,
-        "Failed to create put request. GNUNET_DHT_put returned NULL");
-  };
-
-  dht_put->obj = GNUNET_DBUS_object_create (dht_put);
-  // add methods
-#endif
-
-  size_t path_size = GNUNET_XSTRING_NEW_DEFAULT_SIZE;
-  char *path = GNUNET_XSTRING_new ();
-  GNUNET_XSTRING_appendf (&path, &path_size, "/outgoing/%08x", 
dbus_message_get_serial (message));
-
-#if 0
-  GNUNET_DBUS_service_register_object (service, dht_put->obj, path);
-  GNUNET_free (path);
-
-  DHTClient_add_put (dht_client, dht_put);
-
-#endif
-
-  ret = dbus_message_new_method_return (message);
-  dbus_bool_t succ = dbus_message_append_args (ret, DBUS_TYPE_OBJECT_PATH, 
put_path, DBUS_TYPE_INVALID);
-  if (! succ)
-  {
-    DHTClient_cancel_put (dht_put);
-    dbus_message_unref (ret);
-    return NULL; // out of memory
-  };
-
-
-  
-};
-

Deleted: gnunet-dbus/src/dht/gnunet-service-dht-dbus_dht.h
===================================================================
--- gnunet-dbus/src/dht/gnunet-service-dht-dbus_dht.h   2014-02-14 10:35:11 UTC 
(rev 32344)
+++ gnunet-dbus/src/dht/gnunet-service-dht-dbus_dht.h   2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -1,27 +0,0 @@
-#ifndef GNUNET_SERVICE_DHT_DBUS_DHT_H
-#define GNUNET_SERVICE_DHT_DBUS_DHT_H
-
-struct DHT;
-
-struct DHT *
-DHT_create (
-    GNUNET_CONFIGURATION_Handle *cfg);
-
-void
-DHT_destroy (
-    struct DHT *dht);
-
-DBusMessage *
-method_dht_introspect (
-    GNUNET_DBUS_Client *client,
-    DBusMessage *message,
-    void *wrapped);
-
-DBusMessage *
-method_dht_put (
-    GNUNET_DBUS_Client *client,
-    DBusMessage *message,
-    void *wrapped);
-
-#endif
-

Deleted: gnunet-dbus/src/dht/gnunet-service-dht-dbus_put.c
===================================================================
--- gnunet-dbus/src/dht/gnunet-service-dht-dbus_put.c   2014-02-14 10:35:11 UTC 
(rev 32344)
+++ gnunet-dbus/src/dht/gnunet-service-dht-dbus_put.c   2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -1,17 +0,0 @@
-struct DHTPut
-{
-  struct GNUNET_DHT_PutHandle *ph;
-  GNUNET_DBUS_Object *obj;
-};
-
-
-struct DHTPut *
-DHTPut_create (
-    GNUNET_DBUS_Service *service,
-    GNUNET_DHT_Handle *dht_handle;
-{
-  struct DHTPut *ret = GNUNET_new (struct DHTPut);
-  dht->ph = GNUNET_DHT_put (
-      dht_handle,
-
-  

Deleted: gnunet-dbus/src/gns/Makefile.am
===================================================================
--- gnunet-dbus/src/gns/Makefile.am     2014-02-14 10:35:11 UTC (rev 32344)
+++ gnunet-dbus/src/gns/Makefile.am     2014-02-14 11:08:46 UTC (rev 32345)
@@ -1,17 +0,0 @@
-AM_CFLAGS = \
-       -I$(top_builddir)/src/lib
-
-bin_PROGRAMS = \
-       gnunet-service-gns-dbus
-
-gnunet_service_gns_dbus_SOURCES = \
-       gnunet-service-gns-dbus.c \
-       gnunet-service-gns-dbus_gns.c
-
-gnunet_service_gns_dbus_LDADD = \
-       $(top_builddir)/src/lib/libgnunetdbus.la \
-       $(top_builddir)/src/lib/libgnunetdbus_crypto.la \
-       $(top_builddir)/src/lib/libgnunetxstring.la \
-       -lgnunetgns \
-       -lgnunetutil
-

Deleted: gnunet-dbus/src/gns/gnunet-service-gns-dbus.c
===================================================================
--- gnunet-dbus/src/gns/gnunet-service-gns-dbus.c       2014-02-14 10:35:11 UTC 
(rev 32344)
+++ gnunet-dbus/src/gns/gnunet-service-gns-dbus.c       2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -1,79 +0,0 @@
-#include "config.h"
-
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_common.h>
-#include <gnunet/gnunet_configuration_lib.h>
-#include <gnunet/gnunet_getopt_lib.h>
-#include <gnunet/gnunet_strings_lib.h>
-#include <gnunet/gnunet_program_lib.h>
-
-#include "gnunet-service-gns-dbus_gns.h"
-
-static void
-shutdown_task (
-    void *cls,
-    const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct GNSService *gns_service = (struct GNSService *)cls;
-
-  GNSService_destroy (gns_service);
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down.\n");
-};
-
-static void
-run (
-    void *cls,
-    char *const *args,
-    const char *configfile,
-    const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  struct GNSService *gns_service = GNSService_create (cfg);
-  if (! gns_service)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GNSService_create failed.\n");
-    return;
-  };
-
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running.\n");
-
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, shutdown_task, 
gns_service);
-};
-
-int
-main (
-    int argc,
-    char *const *argv)
-{
-  int ret;
-
-  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_OPTION_END
-  };
-  static const char bin_name[] = "gnunet-service-gns-dbus [OPTIONS]";
-  static const char bin_help[] = gettext_noop ("DBus proxyfor 
gnunet-service-gns");
-
-  ret = GNUNET_log_setup ("gnunet-service-gns-dbus", "DEBUG", NULL);
-  if (GNUNET_OK != ret)
-  {
-    fprintf (stderr, "ERROR: Failed to setup logging. GNUNET_log_setup 
returned %d\n", ret);
-    return 1;
-  }
-
-  ret = GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv);
-  if (GNUNET_OK != ret)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to parse command line 
options. GNUNET_STRINGS_get_utf8_args returned %d\n", ret);
-    return 1;
-  };
-
-  ret = GNUNET_PROGRAM_run (argc, argv, bin_name, bin_help, options, run, 
NULL);
-  if (GNUNET_OK != ret)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to run program. 
GNUNET_PROGRAM_run returned %d\n", ret);
-    return 1;
-  };
-
-  GNUNET_free ((void *)argv);
-  return 0;
-};
-

Deleted: gnunet-dbus/src/gns/gnunet-service-gns-dbus_gns.c
===================================================================
--- gnunet-dbus/src/gns/gnunet-service-gns-dbus_gns.c   2014-02-14 10:35:11 UTC 
(rev 32344)
+++ gnunet-dbus/src/gns/gnunet-service-gns-dbus_gns.c   2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -1,301 +0,0 @@
-#include "config.h"
-
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_common.h>
-#include <gnunet/gnunet_gns_service.h>
-
-#include "gnunet_dbus_lib.h"
-#include "gnunet_dbus_lib_crypto.h"
-#include "gnunet_xstring_lib.h"
-#include "gnunet-service-gns-dbus_gns.h"
-#include "gnunet-service-gns-dbus_lookup.h"
-
-struct GNSService
-{
-  struct GNUNET_DBUS_Service *service;
-  struct GNUNET_DBUS_Object *object;
-  struct GNUNET_GNS_Handle *handle;
-  struct GNSLookup *lookups;
-  uint32_t lookup_id_gen;
-};
-
-static const char *gns_introspection_data = \
-    DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
-    "<node>\n"
-    "  <interface name='org.freedesktop.DBus.Introspectable'>\n"
-    "    <method name='Introspect'>\n"
-    "      <arg name='data' type='s' direction='out'/>\n"
-    "    </method>\n"
-    "  </interface>\n"
-    "  <interface name='org.gnunet.gns'>\n"
-    "    <method name='lookup'>\n"
-    "      <arg name='name' type='s' direction='in'/>\n"
-    "      <arg name='zone' type='s' direction='in'/>\n"
-    "      <arg name='type' type='u' direction='in'/>\n"
-    "      <arg name='only_cached' type='b' direction='in'/>\n"
-    "      <arg name='path' type='o' direction='out'/>\n"
-    "    </method>\n"
-    "  </interface>\n"
-    "</node>\n"
-    ;
-
-static const char *lookup_introspection_data = \
-    DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
-    "<node>\n"
-    "  <interface name='org.freedesktop.DBus.Introspectable'>\n"
-    "    <method name='Introspect'>\n"
-    "      <arg name='data' type='s' direction='out'/>\n"
-    "    </method>\n"
-    "  </interface>\n"
-    "</node>\n"
-    ;
-
-static DBusMessage *
-lookup_introspect (
-    struct GNUNET_DBUS_Object *object,
-    DBusMessage *message)
-{
-  DBusMessage *ret;
-
-  ret = dbus_message_new_method_return (message);
-  if (! ret)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "dbus_message_new_method_return 
returned NULL.\n");
-    return NULL;
-  };
-
-  DBusMessageIter args;
-  dbus_bool_t succ;
-
-  dbus_message_iter_init_append (ret, &args);
-  succ = dbus_message_iter_append_basic (
-      &args,
-      DBUS_TYPE_STRING,
-      &lookup_introspection_data);
-  if (! succ) {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "dbus_message_iter_append_basic 
failed.\n");
-    return NULL;
-  };
-
-  return ret;
-};
-
-static void
-gns_lookup_result (
-    void *cls,
-    uint32_t rd_count,
-    const struct GNUNET_GNSRECORD_Data *rd)
-{
-  
-};
-
-static DBusMessage *
-gns_introspect (
-    struct GNUNET_DBUS_Object *object,
-    DBusMessage *message)
-{
-  DBusMessage *ret;
-
-  ret = dbus_message_new_method_return (message);
-  if (! ret)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "dbus_message_new_method_return 
returned NULL. Out of memory.\n");
-    return NULL;
-  };
-
-  DBusMessageIter args;
-  dbus_bool_t succ;
-
-  dbus_message_iter_init_append (ret, &args);
-  succ = dbus_message_iter_append_basic (
-      &args,
-      DBUS_TYPE_STRING,
-      &gns_introspection_data);
-  if (! succ) {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "dbus_message_iter_append_basic 
failed. Out of memory.\n");
-    return NULL;
-  };
-
-  return ret;
-};
-
-static DBusMessage *
-gns_lookup (
-    struct GNUNET_DBUS_Object *object,
-    DBusMessage *message)
-{
-  DBusMessage *ret = NULL;
-
-  const char *name;
-  struct GNUNET_CRYPTO_EcdsaPublicKey zone;
-  dbus_uint32_t type;
-  dbus_bool_t only_cached;
-
-  DBusMessageIter iter;
-  dbus_message_iter_init (message, &iter);
-  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_string (message, &iter, 
"name", &name);
-  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_ecdsa_public_key (message, 
&iter, "zone", &zone);
-  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_uint32 (message, &iter, 
"type", &type);
-  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_bool (message, &iter, 
"only_cached", &only_cached);
-  //ret = ret ? ret : GNUNET_DBUS_message_iter_pop_string (message, &iter, 
"ego", &ego);
-  if (ret)
-    return ret;
-
-  struct GNSService *gns_service = (struct GNSService 
*)GNUNET_DBUS_object_get_data (object);
-
-  char *lpath = GNUNET_XSTRING_new ();
-  size_t lpath_size = GNUNET_XSTRING_NEW_DEFAULT_SIZE;
-  GNUNET_XSTRING_appendf(&lpath, &lpath_size, "/lookup/%08x", 
gns_service->lookup_id_gen++);
-
-  struct GNSLookup *lookup = GNUNET_new (struct GNSLookup);
-  lookup->path = lpath;
-  lookup->object = GNUNET_DBUS_object_create (lookup);
-  lookup->req = GNUNET_GNS_lookup (
-      gns_service->handle,
-      name,
-      &zone,
-      (int)type,
-      (int)only_cached,
-      NULL,
-      gns_lookup_result,
-      lookup);
-  lookup->next = gns_service->lookups;
-  lookup->prev = NULL;
-  if (gns_service->lookups)
-    gns_service->lookups->prev = lookup;
-  gns_service->lookups = lookup;
-
-  int err;
-  err = GNUNET_DBUS_object_add_method (lookup->object, 
"org.freedesktop.DBus.Introspectable", "Introspect", lookup_introspect);
-  if (GNUNET_OK != err)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create Introspect 
method.\n");
-    return NULL;
-  };
-
-  err = GNUNET_DBUS_service_register_object (gns_service->service, 
lookup->object, lookup->path);
-  if (GNUNET_OK != err)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failed to register object path 
\"%s\"\n", lookup->path);
-    return NULL;
-  };
-
-  printf ("path is '%s'\n", lookup->path);
-
-  ret = dbus_message_new_method_return (message);
-  if (! ret)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "dbus_message_new_method_return 
failed.\n");
-    return NULL;
-  };
-
-  DBusMessageIter retiter;
-  dbus_message_iter_init_append (ret, &retiter);
-
-  dbus_bool_t succ = dbus_message_iter_append_basic (
-      &retiter,
-      DBUS_TYPE_OBJECT_PATH,
-      &lookup->path);
-  if (! succ)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "dbus_message_iter_append_basic 
failed. Out of memory.\n");
-    return NULL;
-  };
-
-  return ret;
-};
-
-struct GNSService *
-GNSService_create (
-    const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  struct GNSService *ret;
-  int err;
-
-  ret = GNUNET_new (struct GNSService);
-  if (! ret)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Out of memory!\n");
-    return NULL;
-  };
-
-  ret->handle = GNUNET_GNS_connect (cfg);
-  if (! ret->handle)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GNUNET_GNS_connect failed.\n");
-    GNSService_destroy (ret);
-    return NULL;
-  };
-
-  ret->service = GNUNET_DBUS_service_create ("gns", cfg);
-  if (! ret->service)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DBUS_service_create 
failed.\n");
-    GNSService_destroy (ret);
-    return NULL;
-  };
-
-  ret->object = GNUNET_DBUS_object_create (ret);
-  if (! ret->object)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DBUS_object_create 
failed.\n");
-    GNSService_destroy (ret);
-    return NULL;
-  };
-
-  err = GNUNET_DBUS_object_add_method (ret->object, 
"org.freedesktop.DBus.Introspectable", "Introspect", gns_introspect);
-  if (GNUNET_OK != err)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DBUS_object_add_method 
\"Introspect\" failed.\n");
-    GNSService_destroy (ret);
-    return NULL;
-  };
-
-  err = GNUNET_DBUS_object_add_method (ret->object, "org.gnunet.gns", 
"lookup", gns_lookup);
-  if (GNUNET_OK != err)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DBUS_object_add_method 
\"lookup\" failed.\n");
-    GNSService_destroy (ret);
-    return NULL;
-  };
-
-  err = GNUNET_DBUS_service_register_object (ret->service, ret->object, 
"/gns");
-  if (GNUNET_OK != err)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DBUS_service_register_object 
\"/gns\" failed.\n");
-    GNSService_destroy (ret);
-    return NULL;
-  };
-
-  ret->lookup_id_gen = 0;
-
-  return ret;
-};
-
-void
-GNSService_destroy (
-    struct GNSService *gns_service)
-{
-  if (gns_service->handle)
-    GNUNET_GNS_disconnect (gns_service->handle);
-
-  if (gns_service->service)
-    GNUNET_DBUS_service_destroy (gns_service->service);
-
-  if (gns_service->object)
-    GNUNET_DBUS_object_destroy (gns_service->object);
-
-  struct GNSLookup *lookup = gns_service->lookups;
-  while (lookup)
-  {
-    struct GNSLookup *next = lookup->next;
-    GNUNET_free (lookup->path);
-    GNUNET_DBUS_object_destroy (lookup->object);
-    GNUNET_free (lookup);
-
-    lookup = next;
-  };
-
-  GNUNET_free (gns_service);
-};
-

Deleted: gnunet-dbus/src/gns/gnunet-service-gns-dbus_gns.h
===================================================================
--- gnunet-dbus/src/gns/gnunet-service-gns-dbus_gns.h   2014-02-14 10:35:11 UTC 
(rev 32344)
+++ gnunet-dbus/src/gns/gnunet-service-gns-dbus_gns.h   2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -1,19 +0,0 @@
-#ifndef GNUNET_SERVICE_GNS_DBUS_GNS_H
-#define GNUNET_SERVICE_GNS_DBUS_GNS_H
-
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_common.h>
-#include <gnunet/gnunet_configuration_lib.h>
-
-struct GNSService;
-
-struct GNSService *
-GNSService_create (
-    const struct GNUNET_CONFIGURATION_Handle *cfg);
-
-void
-GNSService_destroy (
-    struct GNSService *gns_service);
-
-#endif
-

Deleted: gnunet-dbus/src/gns/gnunet-service-gns-dbus_lookup.h
===================================================================
--- gnunet-dbus/src/gns/gnunet-service-gns-dbus_lookup.h        2014-02-14 
10:35:11 UTC (rev 32344)
+++ gnunet-dbus/src/gns/gnunet-service-gns-dbus_lookup.h        2014-02-14 
11:08:46 UTC (rev 32345)
@@ -1,21 +0,0 @@
-#ifndef GNUNET_SERVICE_GNS_DBUS_LOOKUP_H
-#define GNUNET_SERVICE_GNS_DBUS_LOOKUP_H
-
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_common.h>
-#include <gnunet/gnunet_gns_service.h>
-
-#include "gnunet_dbus_lib.h"
-
-struct GNSLookup
-{
-  struct GNSLookup *next;
-  struct GNSLookup *prev;
-
-  char *path;
-  struct GNUNET_GNS_LookupRequest *req;
-  struct GNUNET_DBUS_Object *object;
-};
-
-#endif
-

Modified: gnunet-dbus/src/lib/Makefile.am
===================================================================
--- gnunet-dbus/src/lib/Makefile.am     2014-02-14 10:35:11 UTC (rev 32344)
+++ gnunet-dbus/src/lib/Makefile.am     2014-02-14 11:08:46 UTC (rev 32345)
@@ -1,37 +1,26 @@
+AM_CFLAGS = \
+       -I$(top_builddir)/src/lib
+
 lib_LTLIBRARIES = \
-       libgnunetdbus.la \
-       libgnunetdbus_dht.la \
-       libgnunetdbus_block.la \
-       libgnunetdbus_crypto.la \
-       libgnunetxstring.la
+       libgnunetdbus.la
 
 libgnunetdbus_la_SOURCES = \
-       gnunet_dbus_lib.h \
-       gnunet_dbus_lib.c \
-       gnunet_dbus_lib_pop.c \
-       dbus_type_to_string.c
-
-libgnunetdbus_la_LIBADD = \
-       libgnunetxstring.la
-
-libgnunetdbus_la_DEPENDENCIES = \
-       libgnunetxstring.la
-
+       watch.c \
+       timeout.c \
+       gnunet_dbus_lib_service.c \
+       gnunet_dbus_lib_object.c \
+       gnunet_dbus_lib_interface.c \
+       gnunet_dbus_lib_method.c \
+       gnunet_dbus_lib_arg.c \
+       gnunet_dbus_lib_method_context.c \
+       gnunet_dbus_lib_message_iter_pop.c \
+       gnunet_dbus_lib_message_iter_push.c \
+       gnunet_dbus_lib_client.c \
+       gnunet_dbus_lib_signature.c
+       
 libgnunetdbus_la_CFLAGS = \
        $(DBUS_CFLAGS)
 
 libgnunetdbus_la_LDFLAGS = \
        $(DBUS_LIBS)
-
-libgnunetdbus_dht_la_SOURCES = \
-       gnunet_dbus_lib_dht.c
-
-libgnunetdbus_block_la_SOURCES = \
-       gnunet_dbus_lib_block.c
-
-libgnunetdbus_crypto_la_SOURCES = \
-       gnunet_dbus_lib_crypto.c
-
-libgnunetxstring_la_SOURCES = \
-       gnunet_xstring_lib.c
-
+       

Deleted: gnunet-dbus/src/lib/dbus_type_to_string.c
===================================================================
--- gnunet-dbus/src/lib/dbus_type_to_string.c   2014-02-14 10:35:11 UTC (rev 
32344)
+++ gnunet-dbus/src/lib/dbus_type_to_string.c   2014-02-14 11:08:46 UTC (rev 
32345)
@@ -1,61 +0,0 @@
-#include "config.h"
-
-#include <dbus/dbus.h>
-
-/*
- * Copy-pasted from libdbus dbus-marshall-basic.c
- */
-const char *
-dbus_type_to_string (int typecode)
-{
-  switch (typecode)
-    {
-    case DBUS_TYPE_INVALID:
-      return "invalid";
-    case DBUS_TYPE_BOOLEAN:
-      return "boolean";
-    case DBUS_TYPE_BYTE:
-      return "byte";
-    case DBUS_TYPE_INT16:
-      return "int16";
-    case DBUS_TYPE_UINT16:
-      return "uint16";
-    case DBUS_TYPE_INT32:
-      return "int32";
-    case DBUS_TYPE_UINT32:
-      return "uint32";
-    case DBUS_TYPE_INT64:
-      return "int64";
-    case DBUS_TYPE_UINT64:
-      return "uint64";      
-    case DBUS_TYPE_DOUBLE:
-      return "double";
-    case DBUS_TYPE_STRING:
-      return "string";
-    case DBUS_TYPE_OBJECT_PATH:
-      return "object_path";
-    case DBUS_TYPE_SIGNATURE:
-      return "signature";
-    case DBUS_TYPE_STRUCT:
-      return "struct";
-    case DBUS_TYPE_DICT_ENTRY:
-      return "dict_entry";
-    case DBUS_TYPE_ARRAY:
-      return "array";
-    case DBUS_TYPE_VARIANT:
-      return "variant";
-    case DBUS_STRUCT_BEGIN_CHAR:
-      return "begin_struct";
-    case DBUS_STRUCT_END_CHAR:
-      return "end_struct";
-    case DBUS_DICT_ENTRY_BEGIN_CHAR:
-      return "begin_dict_entry";
-    case DBUS_DICT_ENTRY_END_CHAR:
-      return "end_dict_entry";
-    case DBUS_TYPE_UNIX_FD:
-      return "unix_fd";
-    default:
-      return "unknown";
-    }
-}
-

Deleted: gnunet-dbus/src/lib/dbus_type_to_string.h
===================================================================
--- gnunet-dbus/src/lib/dbus_type_to_string.h   2014-02-14 10:35:11 UTC (rev 
32344)
+++ gnunet-dbus/src/lib/dbus_type_to_string.h   2014-02-14 11:08:46 UTC (rev 
32345)
@@ -1,12 +0,0 @@
-#ifndef DBUS_TYPE_TO_STRING_H
-#define DBUS_TYPE_TO_STRING_H
-
-#ifndef HAVE_dbus_type_to_string
-
-const char *
-dbus_type_to_string (int typecode);
-
-#endif
-
-#endif
-

Deleted: gnunet-dbus/src/lib/gnunet_dbus_lib.c
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib.c       2014-02-14 10:35:11 UTC (rev 
32344)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib.c       2014-02-14 11:08:46 UTC (rev 
32345)
@@ -1,1101 +0,0 @@
-#include <stdint.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <sys/socket.h>
-
-#include <dbus/dbus.h>
-
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_common.h>
-#include <gnunet/gnunet_scheduler_lib.h>
-
-#include "gnunet_dbus_lib.h"
-
-/*
- * Wraps a file descriptor that needs to be watched 
- * for activity with select()
- */
-struct Watch
-{
-  /* doubly-linked list */
-  struct Watch *next;
-  struct Watch *prev;
-
-  /*
-   * DBus watch data. Contains the actual file descritor wrapped by libdbus
-   */
-  DBusWatch *watch;
-
-  /*
-   * Have we asked the scheduler to watch this?
-   * Will be false if the associated task has not been
-   * re-scheduled yet after execution or because dbus has asked
-   * us to disable this watch.
-   */
-  bool scheduled;
-
-  /*
-   * The task that is watching our file descriptor.
-   * Only valid if scheduled is true.
-   */
-  GNUNET_SCHEDULER_TaskIdentifier task;
-
-  struct GNUNET_NETWORK_Handle *net_handle;
-  struct GNUNET_DISK_FileHandle *file_handle;
-};
-
-struct Timeout
-{
-  /* doubly-linked list */
-  struct Timeout *next;
-  struct Timeout *prev;
-
-  DBusTimeout *timeout;
-
-  bool scheduled;
-
-  GNUNET_SCHEDULER_TaskIdentifier task;
-};
-
-/*
- * Represents a DBus service such as "org.gnunet.dht"
- */
-struct GNUNET_DBUS_Service
-{
-  /*
-   * Our connection to the DBus message bus.
-   */
-  DBusConnection *conn;
-
-  /*
-   * Linked list of watches
-   */
-  struct Watch *watches;
-
-  /*
-   * Linked list of timeouts
-   */
-  struct Timeout *timeouts;
-
-#if 0
-  /*
-   * Callback that is executed when we receive a message from a new
-   * never-before-seen client
-   */
-  GNUNET_DBUS_ClientConnects client_connects;
-
-  /*
-   * Linked list of DBus clients we have seen.
-   */
-  struct GNUNET_DBUS_Client *clients;
-#endif
-};
-
-#if 0
-struct GNUNET_DBUS_Client
-{
-  struct GNUNET_DBUS_Client *next;
-  struct GNUNET_DBUS_Client *prev;
-
-  const char *unique_name;
-
-  /*
-   * Application-specific data associated with this client
-   */
-  void *data;
-};
-#endif
-
-/*
- * A container for methods that can be exposed on DBus.
- */
-struct Method
-{
-  /* doubly-linked list */
-  struct Method *next;
-  struct Method *prev;
-
-  /*
-   * DBus interface of the method
-   */
-  const char *interface;
-  
-  /*
-   * Name of the method as through DBus
-   */
-  const char *method_name;
-
-  /* The actual method */
-  GNUNET_DBUS_Method method;
-};
-
-/*
- * A DBus object exposed through a service.
- * In DBus, each service presents a set of objects and each object presents a
- * set of methods that can be called on it.
- */
-struct GNUNET_DBUS_Object
-{
-  /*
-   * Closure passed in to GNUNET_DBUS_object_create.
-   * Points to the actual data structure wrapped by this DBus object.
-   */
-  void *data;
-
-#if 0
-  /*
-   * The service we are an object of
-   */
-  struct GNUNET_DBUS_Service *service;
-
-  /*
-   * The object path
-   */
-  const char *path;
-#endif
-
-  /*
-   * Linked list of methods this object exposes
-   */
-  struct Method *methods;
-};
-
-static void
-handle_watch (
-    void *cls,
-    const struct GNUNET_SCHEDULER_TaskContext *tc);
-
-static int
-watch_schedule (
-  struct Watch *w);
-
-static int
-watch_unschedule (
-    struct Watch *w);
-
-static dbus_bool_t
-watch_add (
-    DBusWatch *watch,
-    void *data);
-
-static void
-watch_remove (
-    DBusWatch *watch,
-    void *data);
-
-static void
-watch_toggle (
-    DBusWatch *watch,
-    void *data);
-
-/*
- * Called by the scheduler when a watch has activity on it
- *
- * @param cls The watch
- * @param tc the context given to us by the scheduler for this execution
- */
-static void
-handle_watch (
-    void *cls,
-    const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct Watch *w = (struct Watch *)cls;
-
-  printf ("handle_watch\n");
-
-  unsigned flags = 0;
-  if (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)
-    flags |= DBUS_WATCH_READABLE;
-  if (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)
-    flags |= DBUS_WATCH_WRITABLE;
-#if 0
-  if (tc->reason & GNUNET_SCHEDULER_REASON_EXCEPTION)
-    flags |= DBUS_WATCH_ERROR;
-#endif
-  printf ("  %x\n", flags);
-  if (flags)
-    dbus_watch_handle(w->watch, flags);
-
-  w->scheduled = false;
-
-  if(! (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    int err;
-    err = watch_schedule (w);
-    if (GNUNET_OK != err)
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "watch_schedule failed\n");
-  };
-};
-
-/*
- * Ask the scheduler to watch this watch for activity.
- *
- * @param w The watch
- * @return GNUNET_OK or GNUNET_SYSERR
- */
-static int
-watch_schedule (
-  struct Watch *w)
-{
-  unsigned flags = dbus_watch_get_flags (w->watch);
-
-  printf ("watch_schedule\n");
-
-  // sanity check
-  if (! dbus_watch_get_enabled (w->watch))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Tried to schedule watch that is 
disabled!\n");
-    return GNUNET_SYSERR;
-  };
-
-  if (w->scheduled)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Scheduling watch that is already 
scheduled!\n");
-    return GNUNET_SYSERR;
-  };
-
-  if (w->net_handle)
-  {
-    w->task = GNUNET_SCHEDULER_add_net_with_priority(
-        GNUNET_TIME_UNIT_FOREVER_REL,
-        GNUNET_SCHEDULER_PRIORITY_DEFAULT,
-        w->net_handle,
-        flags & DBUS_WATCH_READABLE,
-        flags & DBUS_WATCH_WRITABLE,
-        handle_watch,
-        w);
-    w->scheduled = true;
-    return GNUNET_OK;
-  };
-
-  if (w->file_handle)
-  {
-    w->task = GNUNET_SCHEDULER_add_file_with_priority(
-        GNUNET_TIME_UNIT_FOREVER_REL,
-        GNUNET_SCHEDULER_PRIORITY_DEFAULT,
-        w->file_handle,
-        flags & DBUS_WATCH_READABLE,
-        flags & DBUS_WATCH_WRITABLE,
-        handle_watch,
-        w);
-    w->scheduled = true;
-    return GNUNET_OK;
-  };
-
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to schedule watch.\n");
-  return GNUNET_SYSERR;
-};
-
-/*
- * Ask the scheduler to stop monitoring a watch either because we are shutting
- * down or dbus has asked us to disable this watch.
- *
- * @param w The watch
- * @return GNUNET_OK or GNUNET_SYSERR
- */
-static int
-watch_unschedule (
-    struct Watch *w)
-{
-  printf ("watch_unschedule\n");
-
-  if(w->scheduled)
-  {
-    void *cls = GNUNET_SCHEDULER_cancel (w->task);
-    if ((struct Watch *)cls != w)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to unschedule task. w == 
%p, GNUNET_SCHEDULER_cancel returned %p\n", w, cls);
-      return GNUNET_SYSERR;
-    }
-  }
-  else
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Attempting to unschedule task that 
is not scheduled!\n");
-    return GNUNET_SYSERR;
-  };
-
-  return GNUNET_OK;
-};
-
-/*
- * Called by DBus when it has a new watch that it wants us to watch.
- *
- * @param watch The DBus watch, created and passed to us by DBus.
- * @param data the GNUNET_DBUS_Service we passed to 
dbus_connection_set_watch_functions
- * @return true on success, false on an unrecoverable error such as running 
out of memory.
- */
-static dbus_bool_t
-watch_add (
-    DBusWatch *watch,
-    void *data)
-{
-  struct GNUNET_DBUS_Service *service = (struct GNUNET_DBUS_Service *)data;
-  struct Watch *w = GNUNET_new (struct Watch);
-
-  printf ("watch_add\n");
-
-  if(w == NULL)
-    return false;
-
-  w->watch = watch;
-  w->scheduled = false;
-  w->net_handle = NULL;
-  w->file_handle = NULL;
-
-  SOCKTYPE sock = dbus_watch_get_socket (watch);
-  if (-1 != sock)
-  {
-    w->net_handle = GNUNET_NETWORK_socket_box_native (sock);
-    if (NULL == w->net_handle)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to box network socket 
passed in from dbus.\n");
-      GNUNET_free (w);
-      return false;
-    };
-  }
-  else {
-    int fd = dbus_watch_get_unix_fd (watch);
-    if (-1 != fd)
-    {
-      w->file_handle = GNUNET_DISK_get_handle_from_int_fd (fd);
-      if (NULL == w->file_handle)
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to box file handle passed 
in from dbus.\n");
-        GNUNET_free (w);
-        return false;
-      };
-    };
-  };
-
-  if (! w->net_handle && ! w->file_handle)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to add watch.\n");
-    GNUNET_free (w);
-  };
-
-  if (dbus_watch_get_enabled (watch))
-  {
-    int err = watch_schedule (w);
-    if (GNUNET_OK != err)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to schedule watch.\n");
-      if (w->net_handle)
-        GNUNET_free (w->net_handle);
-      if (w->file_handle)
-        GNUNET_free (w->file_handle);
-      GNUNET_free (w);
-      return false;
-    };
-  };
-
-  w->next = service->watches;
-  w->prev = NULL;
-  if (service->watches)
-    service->watches->prev = w;
-  service->watches = w;
-
-  return true;
-};
-
-/*
- * Called by DBus when it want to permanently disable and remove a watch
- *
- * @param watch The DBus watch, passed to us by DBus.
- * @param data the GNUNET_DBUS_Service we passed to 
dbus_connection_set_watch_functions
- */
-static void
-watch_remove (
-    DBusWatch *watch,
-    void *data)
-{
-  struct GNUNET_DBUS_Service *service = (struct GNUNET_DBUS_Service *)data;
-  struct Watch *w = service->watches;
-
-  printf ("watch_remove\n");
-
-  while(w && w->watch != watch)
-    w = w->next;
-
-  if (NULL == w)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Asked to remove watch that has not 
been added\n");
-    return;
-  };
-
-  if (w->scheduled)
-  {
-    int err = watch_unschedule (w);
-    if (GNUNET_OK != err)
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "watch_unschedule returned 
error.\n");
-  };
-
-  if (w->net_handle)
-    GNUNET_free (w->net_handle);
-  if (w->file_handle)
-    GNUNET_free (w->file_handle);
-
-  if (w->next)
-    w->next->prev = w->prev;
-  if (w->prev)
-    w->prev->next = w->next;
-  else
-    service->watches = w->next;
-
-  GNUNET_free (w);
-};
-
-/*
- * Called by DBus when it wants to enable or disable a watch.
- * Schedules or unschedules the scheduler to monitor this watch as appropriate.
- *
- * @param watch The DBus watch, passed to us by DBus.
- * @param data the GNUNET_DBUS_Service we passed to 
dbus_connection_set_watch_functions
- */
-static void
-watch_toggle (
-    DBusWatch *watch,
-    void *data)
-{
-  struct GNUNET_DBUS_Service *service = (struct GNUNET_DBUS_Service *)data;
-  struct Watch *w = service->watches;
-
-  printf ("watch_toggle\n");
-
-  while(w && w->watch != watch)
-    w = w->next;
-
-  if (NULL == w)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Asked to toggle watch that has not 
been added\n");
-    return;
-  };
-
-  bool enabled = dbus_watch_get_enabled (watch);
-  bool scheduled = w->scheduled;
-
-  if (enabled && ! scheduled)
-    watch_schedule (w);
-  if (! enabled && scheduled)
-    watch_unschedule (w);
-};
-
-static int
-timeout_schedule (
-    struct Timeout *t);
-
-static void
-handle_timeout (
-    void *cls,
-    const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct Timeout *t = (struct Timeout *)cls;
-
-  printf ("handle_timeout\n");
-
-  if (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)
-    dbus_timeout_handle (t->timeout);
-
-  t->scheduled = false;
-
-  if (! (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    int err;
-    err = timeout_schedule (t);
-    if (GNUNET_OK != err)
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "timeout_schedule failed\n");
-  };
-};
-
-static int
-timeout_schedule (
-    struct Timeout *t)
-{
-  printf ("timeout_schedule\n");
-
-  DBusTimeout *timeout = t->timeout;
-  if (! dbus_timeout_get_enabled (t->timeout))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Tried to schedule timeout that is 
disabled!\n");
-    return GNUNET_SYSERR;
-  };
-
-  if (t->scheduled)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Scheduling timeout that is already 
scheduled!\n");
-    return GNUNET_SYSERR;
-  };
-
-  int interval = dbus_timeout_get_interval (timeout);
-  struct GNUNET_TIME_Relative delay;
-  delay.rel_value_us = interval * 1000;
-  t->task = GNUNET_SCHEDULER_add_delayed (
-      delay,
-      handle_timeout,
-      t);
-  t->scheduled = true;
-  return GNUNET_OK;
-};
-
-static int
-timeout_unschedule (
-    struct Timeout *t)
-{
-  printf ("timeout_unschedule\n");
-
-  if (t->scheduled)
-  {
-    void *cls = GNUNET_SCHEDULER_cancel (t->task);
-    if ((struct Timeout *)cls != t)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to unschedule timeout. t == 
%p, GNUNET_SCHEDULER_cancel returned %p\n", t, cls);
-      return GNUNET_SYSERR;
-    };
-  }
-  else
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Attempting to unschedule task that 
is not scheduled!\n");
-    return GNUNET_SYSERR;
-  };
-
-  return GNUNET_OK;
-};
-
-static dbus_bool_t
-timeout_add (
-    DBusTimeout *timeout,
-    void *data)
-{
-  printf ("timeout_add\n");
-
-  struct GNUNET_DBUS_Service *service = (struct GNUNET_DBUS_Service *)data;
-  struct Timeout *t = GNUNET_new (struct Timeout);
-
-  if (t == NULL)
-    return false;
-
-  t->timeout = timeout;
-  t->scheduled = false;
-  
-  t->next = service->timeouts;
-  t->prev = NULL;
-  if (service->timeouts)
-    service->timeouts->prev = t;
-  service->timeouts = t;
-
-  if (dbus_timeout_get_enabled (timeout))
-  {
-    int err = timeout_schedule (t);
-    if (GNUNET_OK != err)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to schedule timeout.\n");
-      return false;
-    };
-  };
-  
-  return true;
-};
-
-static void
-timeout_remove (
-    DBusTimeout *timeout,
-    void *data)
-{
-  printf ("timeout_remove\n");
-
-  struct GNUNET_DBUS_Service *service = (struct GNUNET_DBUS_Service *)data;
-  struct Timeout *t = service->timeouts;
-
-  while (t && t->timeout != timeout)
-    t = t->next;
-
-  if (NULL == t)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "asked to remove timeout that has 
not been added\n");
-    return;
-  };
-
-  if (t->scheduled)
-  {
-    int err = timeout_unschedule (t);
-    if (GNUNET_OK != err)
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "timeout_unschedule failed.\n");
-  };
-
-  if (t->next)
-    t->next->prev = t->prev;
-  if (t->prev)
-    t->prev->next = t->next;
-  else
-    service->timeouts = t->next;
-
-  GNUNET_free (t);
-};
-
-static void
-timeout_toggle (
-    DBusTimeout *timeout,
-    void *data)
-{
-  printf ("timeout_toggle\n");
-
-  struct GNUNET_DBUS_Service *service = (struct GNUNET_DBUS_Service *)data;
-  struct Timeout *t = service->timeouts;
-
-  while (t && t->timeout != timeout)
-    t = t->next;
-
-  if (NULL == t)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "asked to remove timeout that has 
not been added\n");
-    return;
-  };
-
-  bool enabled = dbus_timeout_get_enabled (timeout);
-  bool scheduled = t->scheduled;
-
-  if (enabled && ! scheduled)
-    timeout_schedule (t);
-  if (! enabled && scheduled)
-    timeout_unschedule (t);
-};
-
-static void
-dispatch (
-    void *cls,
-    const struct GNUNET_SCHEDULER_TaskContext *tc);
-
-static void
-handle_dispatch (
-    DBusConnection *conn,
-    DBusDispatchStatus status)
-{
-  printf ("handle_dispatch\n");
-
-  switch (status)
-  {
-  case DBUS_DISPATCH_DATA_REMAINS:
-    GNUNET_SCHEDULER_add_continuation (
-        dispatch,
-        conn,
-        GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-    break;
-  case DBUS_DISPATCH_COMPLETE:
-    break;
-  case DBUS_DISPATCH_NEED_MEMORY:
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Out of memory!\n");
-    break;
-  default:
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unrecognized dispatch status\n");
-    break;
-  };
-};
-
-static void
-dispatch (
-    void *cls,
-    const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  printf ("dispatch\n");
-
-  struct DBusConnection *conn = (struct DBusConnection *)cls;
-  dbus_connection_dispatch (conn);
-  handle_dispatch (conn, dbus_connection_get_dispatch_status (conn));
-};
-
-static void
-dispatch_status_changed (
-    DBusConnection *conn,
-    DBusDispatchStatus new_status,
-    void *data)
-{
-  (void)data;
-  printf ("dispatch_status_changed\n");
-
-  handle_dispatch (conn, new_status);
-};
-
-/*
- * Create a new DBus service and register it with the message bus.
- *
- * @param service_name  The name of the GNUnet service. Gets appended to
- *                      "org.gnunet.`peername`" to form the name of the DBus
- *                      service.
- * @param cfg The service configuration
- * @param data the appliation-specific data associated with this service
- */
-struct GNUNET_DBUS_Service *
-GNUNET_DBUS_service_create (
-    const char *service_name,
-    const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  struct GNUNET_DBUS_Service *ret;
-  ret = GNUNET_new(struct GNUNET_DBUS_Service);
-  ret->watches = NULL;
-
-  DBusError err;
-  DBusConnection *conn;
-
-  dbus_error_init(&err);
-    
-  conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
-  if(dbus_error_is_set(&err))
-  {
-    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to dbus system bus 
(%s)\n", err.message);
-    dbus_error_free(&err);
-    GNUNET_free (ret);
-    return NULL;
-  };
-  if(! conn)
-  {
-    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to connect to dbus system bus; 
dbus_bus_get returned NULL\n");
-    dbus_error_free(&err);
-    GNUNET_free (ret);
-    return NULL;
-  };
-  ret->conn = conn;
-
-  dbus_bool_t succ = dbus_connection_set_watch_functions (conn, watch_add, 
watch_remove, watch_toggle, ret, NULL);
-  if(! succ)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "dbus_connection_set_watch_functions 
returned false. Out of memory.\n");
-    GNUNET_DBUS_service_destroy (ret);
-    return NULL;
-  };
-
-  dbus_connection_set_dispatch_status_function (conn, dispatch_status_changed, 
ret, NULL);
-  handle_dispatch (conn, dbus_connection_get_dispatch_status (conn));
-
-  succ = dbus_connection_set_timeout_functions (conn, timeout_add, 
timeout_remove, timeout_toggle, ret, NULL);
-  if (! succ)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
"dbus_connection_set_timeout_functions returned false. Out of memory.\n");
-    GNUNET_DBUS_service_destroy (ret);
-    return NULL;
-  };
-
-  char name[128];
-  snprintf(name, 128, "org.gnunet.%s", service_name);
-  int request_result = dbus_bus_request_name(conn, name, 
DBUS_NAME_FLAG_DO_NOT_QUEUE, &err);
-  if(dbus_error_is_set(&err)) {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to request the bus name 
(%s)\n", err.message);
-    dbus_error_free(&err);
-    GNUNET_DBUS_service_destroy (ret);
-    return NULL;
-  };
-  switch(request_result) {
-  case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
-    break;
-  case DBUS_REQUEST_NAME_REPLY_EXISTS:
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to request the bus name 
\"%s\"; name is already taken.\n", name);
-    GNUNET_DBUS_service_destroy (ret);
-    return NULL;
-  default:
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unable to interpret result of 
dbus_request_name (%d)\n", request_result);
-    GNUNET_DBUS_service_destroy (ret);
-    return NULL;
-  };
-
-  return ret;
-};
-
-/*
- * Destroy a dbus service, unregistering it from the messagebus and freeing
- * it's associated memory.
- *
- * @param service The service.
- */
-void
-GNUNET_DBUS_service_destroy (
-    struct GNUNET_DBUS_Service *service)
-{
-  dbus_connection_set_dispatch_status_function (service->conn, NULL, NULL, 
NULL);
-  dbus_connection_close (service->conn);
-  dbus_connection_unref (service->conn);
-
-  struct Watch *w = service->watches;
-  while (w)
-  {
-    struct Watch *next = w->next;
-    if (w->scheduled)
-    {
-      int err = watch_unschedule (w);
-      if (GNUNET_OK != err)
-        GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to unschedule watch 
that should have been scheduled while destroying service.\n");
-    };
-
-    GNUNET_free (w);
-    w = next;
-  };
-
-  struct Timeout *t = service->timeouts;
-  while (t)
-  {
-    struct Timeout *next = t->next;
-    if (t->scheduled)
-    {
-      int err = timeout_unschedule (t);
-      if (GNUNET_OK != err)
-        GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to unschedule timeout 
that should have been scheduled while destroying service.\n");
-    };
-    
-    GNUNET_free (t);
-    t = next;
-  };
-
-  GNUNET_free (service);
-};
-
-/*
- * Called whenever a message arrives from DBus
- *
- * @param conn The connection it arrived on.
- * @param message The message
- * @param cls The closure passed to dbus_connection_try_register_object_path
- *            in our case this is the GNUNET_DBUS_Object that the message was
- *            sent to.
- *
- * @return DBUS_HANDLER_RESULT_NEED_MEMORY if anything failed due to lack of
- *         memory.
- *         DBUS_HANDLER_RESULT_HANDLED if any method returned a reply.
- *         DBUS_HANDLER_RESULT_NOT_YET_HANDLED otherwise.
- */
-DBusHandlerResult
-handle_object_message (
-    DBusConnection *conn,
-    DBusMessage *message,
-    void *cls)
-{
-  struct GNUNET_DBUS_Object *obj = (struct GNUNET_DBUS_Object *)cls;
-
-#if 1
-  const char *msg_path = dbus_message_get_path (message);
-  const char *type_string = dbus_message_type_to_string (dbus_message_get_type 
(message));
-  const char *interface = dbus_message_get_interface (message);
-  const char *member = dbus_message_get_member (message);
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Recieved DBus message for %s\n", 
msg_path);
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "    type      == %s\n", type_string ? 
type_string : "(none)");
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "    interface == %s\n", interface   ? 
interface   : "(none)");
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "    member    == %s\n", member      ? 
member      : "(none)");
-#endif
-
-  int type = dbus_message_get_type (message);
-  if (type != DBUS_MESSAGE_TYPE_METHOD_CALL)
-    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-  struct Method *pos = obj->methods;
-  while (pos)
-  {
-    if (dbus_message_is_method_call (
-        message,
-        pos->interface,
-        pos->method_name))
-    {
-      DBusMessage *reply = pos->method (obj, message);
-      if (! reply)
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "method returned NULL. Out of 
memory.\n");
-        reply = dbus_message_new_error_printf (
-            message,
-            DBUS_ERROR_FAILED,
-            "Internal error. pos->method returned NULL.");
-      };
-      if (! dbus_message_get_no_reply (message))
-      {
-        dbus_bool_t succ = dbus_connection_send (conn, reply, NULL);
-        return succ ? DBUS_HANDLER_RESULT_HANDLED : 
DBUS_HANDLER_RESULT_NEED_MEMORY;
-      }
-      dbus_message_unref (reply);
-      return DBUS_HANDLER_RESULT_HANDLED;
-    };
-    pos = pos->next;
-  };
-
-  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-};
-
-struct GNUNET_DBUS_Object *
-GNUNET_DBUS_object_create (
-    void *data)
-{
-  struct GNUNET_DBUS_Object *ret;
-  ret = GNUNET_new (struct GNUNET_DBUS_Object);
-  ret->data = data;
-  ret->methods = NULL;
-
-  return ret;
-};
-
-/*
- * Destroys a GNUNET_DBUS_Object freeing it's memory.
- * It is a bug to call this if the object is registered with any services.
- *
- * @param obj The object.
- */
-void
-GNUNET_DBUS_object_destroy (
-    struct GNUNET_DBUS_Object *obj)
-{
-  struct Method *m = obj->methods;
-  while(m) {
-    struct Method *next = m->next;
-    GNUNET_free (m);
-    m = next;
-  };
-  GNUNET_free (obj);
-};
-
-void *
-GNUNET_DBUS_object_get_data (
-    struct GNUNET_DBUS_Object *obj)
-{
-  return obj->data;
-};
-
-int
-GNUNET_DBUS_service_register_object (
-    struct GNUNET_DBUS_Service *service,
-    struct GNUNET_DBUS_Object *obj,
-    const char *path)
-{
-  DBusError err;
-  dbus_error_init(&err);
-    
-  DBusObjectPathVTable vtable;
-  vtable.message_function = handle_object_message;
-  vtable.unregister_function = NULL;
-  dbus_bool_t succ = dbus_connection_try_register_object_path (
-      service->conn,
-      path,
-      &vtable,
-      obj,
-      &err);
-  if (dbus_error_is_set (&err))
-  {
-    GNUNET_log (
-        GNUNET_ERROR_TYPE_ERROR,
-        "dbus_connection_try_register failed to register path \"%s\": %s\n",
-          path,
-          err.message);
-    return GNUNET_SYSERR;
-  };
-  if (! succ)
-  {
-    GNUNET_log (
-        GNUNET_ERROR_TYPE_ERROR,
-        "dbus_connection_try_register returned false when registering path 
\"%s\"\n",
-          path);
-    return GNUNET_SYSERR;
-  };
-
-  return GNUNET_OK;
-};
-
-int
-GNUNET_DBUS_service_unregister_object (
-    struct GNUNET_DBUS_Service *service,
-    const char *path)
-{
-  dbus_bool_t succ = dbus_connection_unregister_object_path (service->conn, 
path);
-  if (! succ)
-  {
-    GNUNET_log (
-        GNUNET_ERROR_TYPE_ERROR,
-        "dbus_connection_unregister_object_path failed. Out of memory.\n");
-    return GNUNET_SYSERR;
-  };
-  return GNUNET_OK;
-};
-    
-
-int
-GNUNET_DBUS_object_add_method (
-    struct GNUNET_DBUS_Object *obj,
-    const char *interface,
-    const char *method_name,
-    GNUNET_DBUS_Method method)
-{
-  struct Method *add = GNUNET_new (struct Method);
-  if (NULL == add)
-    return GNUNET_SYSERR;
-
-  add->interface = interface;
-  add->method_name = method_name;
-  add->method = method;
-
-  add->next = obj->methods;
-  add->prev = NULL;
-  obj->methods = add;
-  return GNUNET_OK;
-};
-
-struct GNUNET_NETWORK_Handle *
-GNUNET_DBUS_create_socket_from_dbus_address(
-    const char *address)
-{
-  DBusAddressEntry *entry;
-  DBusAddressEntry **entries;
-  int entry_len;
-  int res;
-  struct GNUNET_NETWORK_Handle *ret;
-  int i;
-
-  DBusError err;
-  dbus_error_init(&err);
-
-  ret = NULL;
-  dbus_parse_address (address, &entries, &entry_len, &err);
-  if (dbus_error_is_set (&err))
-  {
-    dbus_error_free (&err);
-    return NULL;
-  };
-
-  for(i = 0, entry = entries[i]; entry; entry = entries[++i]) {
-    const char *method;
-        
-    method = dbus_address_entry_get_method(entry);
-    if(! strcmp(method, "unix")) {
-      struct sockaddr_un addr;
-      const char *path;
-      socklen_t addr_len;
-
-      addr.sun_family = AF_UNIX;
-      memset(addr.sun_path, 0, sizeof(addr.sun_path));
-      path = dbus_address_entry_get_value(entry, "path");
-      if(path) {
-        strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
-        addr_len = sizeof(addr);
-      }
-      else {
-        path = dbus_address_entry_get_value(entry, "abstract");
-        if(path) {
-          strncpy(addr.sun_path + 1, path, sizeof(addr.sun_path) - 2);
-          addr_len =   sizeof(addr) \
-                     + strnlen(addr.sun_path + 1, sizeof(addr.sun_path) - 1) \
-                     - sizeof(addr.sun_path);
-        }
-        else
-          continue;
-      };
-
-      ret = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_STREAM, 0);
-      if(! ret)
-        continue;
-
-      res = GNUNET_NETWORK_socket_connect(ret, (struct sockaddr *)&addr, 
addr_len);
-      if(res != GNUNET_OK) {
-        res = GNUNET_NETWORK_socket_close(ret);
-        if(res != GNUNET_OK)
-          GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to close socket.\n");
-        ret = NULL;
-        continue;
-      }
-
-      break;
-    }
-  };
-
-  dbus_address_entries_free(entries);
-  return ret;
-};
-

Modified: gnunet-dbus/src/lib/gnunet_dbus_lib.h
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib.h       2014-02-14 10:35:11 UTC (rev 
32344)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib.h       2014-02-14 11:08:46 UTC (rev 
32345)
@@ -1,146 +1,16 @@
 #ifndef GNUNET_DBUS_LIB_H
 #define GNUNET_DBUS_LIB_H
 
-#include <dbus/dbus.h>
+#include "gnunet_dbus_lib_service.h"
+#include "gnunet_dbus_lib_object.h"
+#include "gnunet_dbus_lib_interface.h"
+#include "gnunet_dbus_lib_method.h"
+#include "gnunet_dbus_lib_arg.h"
+#include "gnunet_dbus_lib_method_context.h"
+#include "gnunet_dbus_lib_client.h"
+#include "gnunet_dbus_lib_signature.h"
+#include "gnunet_dbus_lib_message_iter_push.h"
+#include "gnunet_dbus_lib_message_iter_pop.h"
 
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_common.h>
-#include <gnunet/gnunet_configuration_lib.h>
-#include <gnunet/gnunet_crypto_lib.h>
-
-struct GNUNET_DBUS_Service;
-struct GNUNET_DBUS_Object;
-
-struct GNUNET_DBUS_StringEnumPair
-{
-  const char *name;
-  int value;
-};
-
-typedef DBusMessage *(*GNUNET_DBUS_Method) (
-    struct GNUNET_DBUS_Object *object,
-    DBusMessage *message);
-
-struct GNUNET_DBUS_Service *
-GNUNET_DBUS_service_create (
-    const char *service_name,
-    const struct GNUNET_CONFIGURATION_Handle *cfg);
-
-void
-GNUNET_DBUS_service_destroy (
-    struct GNUNET_DBUS_Service *service);
-
-struct GNUNET_DBUS_Object *
-GNUNET_DBUS_object_create (
-    void *data);
-
-void
-GNUNET_DBUS_object_destroy (
-    struct GNUNET_DBUS_Object *obj);
-
-void *
-GNUNET_DBUS_object_get_data (
-    struct GNUNET_DBUS_Object *obj);
-
-int
-GNUNET_DBUS_service_register_object (
-    struct GNUNET_DBUS_Service *service,
-    struct GNUNET_DBUS_Object *obj,
-    const char *path);
-
-int
-GNUNET_DBUS_object_add_method (
-    struct GNUNET_DBUS_Object *obj,
-    const char *interface,
-    const char *method_name,
-    GNUNET_DBUS_Method method);
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_basic (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    int expected_type,
-    void *value);
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_string (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    const char **val);
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_uint32 (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    dbus_uint32_t *value);
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_bool (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    dbus_bool_t *value);
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_fixed_array (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    int expected_type,
-    void *value,
-    int *n_elements);
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_array_byte (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    const char **value,
-    int *n_elements);
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_bitfield (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    int *value,
-    const struct GNUNET_DBUS_StringEnumPair *fields);
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_enum (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    int *value,
-    const struct GNUNET_DBUS_StringEnumPair *names);
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_hashcode (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    struct GNUNET_HashCode *hc);
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_socket (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    struct GNUNET_NETWORK_Handle **socket_handle);
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_absolute_time (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    struct GNUNET_TIME_Absolute *value);
-
-struct GNUNET_NETWORK_Handle *
-GNUNET_DBUS_create_socket_from_dbus_address(
-    const char *address);
-
 #endif
 

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_arg.c
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_arg.c                           (rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_arg.c   2014-02-14 11:08:46 UTC (rev 
32345)
@@ -0,0 +1,76 @@
+#include "config.h"
+
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
+
+#include "gnunet_dbus_lib_arg.h"
+
+#define LOG(kind, ...) GNUNET_log_from(kind, "dbus-arg", __VA_ARGS__)
+
+struct GNUNET_DBUS_Arg
+{
+  char *name;
+  const char *signature;
+  unsigned ref_count;
+};
+
+struct GNUNET_DBUS_Arg *
+GNUNET_DBUS_arg_create (
+    const char *name,
+    const char *signature)
+{
+  struct GNUNET_DBUS_Arg *arg = GNUNET_new (struct GNUNET_DBUS_Arg);
+  arg->name = GNUNET_strdup (name);
+  arg->signature = signature;
+  arg->ref_count = 0;
+  return arg;
+};
+
+void
+GNUNET_DBUS_arg_destroy (
+    struct GNUNET_DBUS_Arg *arg)
+{
+  if (0 != arg->ref_count)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Tried to destroy arg that still has 
references. name == \"%s\", ref_count == %zu\n", arg->name, arg->ref_count);
+    GNUNET_abort ();
+  };
+
+  GNUNET_free (arg->name);
+  GNUNET_free (arg);
+};
+
+void
+GNUNET_DBUS_arg_ref (
+    struct GNUNET_DBUS_Arg *arg)
+{
+  arg->ref_count++;
+};
+
+void
+GNUNET_DBUS_arg_unref (
+    struct GNUNET_DBUS_Arg *arg)
+{
+  if (arg->ref_count == 0)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Tried to unreference arg with ref count 
0\n");
+    GNUNET_abort ();
+  };
+  if (--arg->ref_count == 0)
+    GNUNET_DBUS_arg_destroy (arg);
+};
+
+const char *
+GNUNET_DBUS_arg_get_name (
+    const struct GNUNET_DBUS_Arg *arg)
+{
+  return arg->name;
+};
+
+const char *
+GNUNET_DBUS_arg_get_signature (
+    const struct GNUNET_DBUS_Arg *arg)
+{
+  return arg->signature;
+};
+

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_arg.h
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_arg.h                           (rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_arg.h   2014-02-14 11:08:46 UTC (rev 
32345)
@@ -0,0 +1,55 @@
+#ifndef GNUNET_DBUS_LIB_ARG_H
+#define GNUNET_DBUS_LIB_ARG_H
+
+struct GNUNET_DBUS_Arg;
+
+struct GNUNET_DBUS_ArgIterator
+{
+  /* linked list */
+  struct GNUNET_DBUS_ArgIterator *next;
+  struct GNUNET_DBUS_ArgIterator *prev;
+
+  struct GNUNET_DBUS_Arg *arg;
+};
+
+struct GNUNET_DBUS_Arg *
+GNUNET_DBUS_arg_create (
+    const char *name,
+    const char *signature);
+
+void
+GNUNET_DBUS_arg_destroy (
+    struct GNUNET_DBUS_Arg *arg);
+
+void
+GNUNET_DBUS_arg_ref (
+    struct GNUNET_DBUS_Arg *arg);
+
+void
+GNUNET_DBUS_arg_unref (
+    struct GNUNET_DBUS_Arg *arg);
+
+const char *
+GNUNET_DBUS_arg_get_name (
+    const struct GNUNET_DBUS_Arg *arg);
+
+const char *
+GNUNET_DBUS_arg_get_signature (
+    const struct GNUNET_DBUS_Arg *arg);
+
+#if 0
+void
+GNUNET_DBUS_arg_pop_message (
+    const struct GNUNET_DBUS_Arg *arg,
+    DBusMessageIter *dbus_message_iter,
+    void *value);
+
+void
+GNUNET_DBUS_arg_push_message (
+    const struct GNUNET_DBUS_Arg *arg,
+    DBusMessageIter *dbus_message_iter,
+    va_list vl);
+#endif
+
+#endif
+

Deleted: gnunet-dbus/src/lib/gnunet_dbus_lib_block.c
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_block.c 2014-02-14 10:35:11 UTC (rev 
32344)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_block.c 2014-02-14 11:08:46 UTC (rev 
32345)
@@ -1,59 +0,0 @@
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_common.h>
-#include <gnunet/gnunet_block_lib.h>
-
-#include "gnunet_dbus_lib.h"
-
-/*
- * Pop a value of type GNUNET_BLOCK_Type from a DBusMessage
- *
- * @param message The message
- * @param iter The iterator over the message. This will be advanced by one
- *             argument
- * @param arg_name The human-readable name of the argument. Used for producing
- *                 error messages.
- * @param value pointer to a location to store the GNUNET_BLOCK_Type
- * 
- * @return NULL on success, otherwise a pointer to a DBusMessage containing an
- *         error reply that can be sent to a dbus client.
- */
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_block_type (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    enum GNUNET_BLOCK_Type *value)
-{
-  static const struct GNUNET_DBUS_StringEnumPair names[] = {
-      {"any",            GNUNET_BLOCK_TYPE_ANY},
-      {"fs_dblock",      GNUNET_BLOCK_TYPE_FS_DBLOCK},
-      {"fs_iblock",      GNUNET_BLOCK_TYPE_FS_IBLOCK},
-      {"fs_kblock",      GNUNET_BLOCK_TYPE_FS_KBLOCK},
-      {"fs_sblock",      GNUNET_BLOCK_TYPE_FS_SBLOCK},
-      {"fs_nblock",      GNUNET_BLOCK_TYPE_FS_NBLOCK},
-      {"fs_ondemand",    GNUNET_BLOCK_TYPE_FS_ONDEMAND},
-      {"dht_hello",      GNUNET_BLOCK_TYPE_DHT_HELLO},
-      {"test",           GNUNET_BLOCK_TYPE_TEST},
-      {"fs_ublock",      GNUNET_BLOCK_TYPE_FS_UBLOCK},
-      {"dns",            GNUNET_BLOCK_TYPE_DNS},
-      {"gns_namerecord", GNUNET_BLOCK_TYPE_GNS_NAMERECORD},
-      {"mesh_peer",      GNUNET_BLOCK_TYPE_MESH_PEER},
-      {"regex",          GNUNET_BLOCK_TYPE_REGEX},
-      {"regex_accept",   GNUNET_BLOCK_TYPE_REGEX_ACCEPT},
-      {NULL,             0}
-  };
-
-  int v;
-  DBusMessage *ret = GNUNET_DBUS_message_iter_pop_enum (
-      message,
-      iter,
-      arg_name,
-      &v,
-      names);
-  if (ret)
-    return ret;
-
-  *value = (enum GNUNET_BLOCK_Type)v;
-  return NULL;
-};
-

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_client.c
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_client.c                                
(rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_client.c        2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -0,0 +1,77 @@
+#include "config.h"
+
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
+
+#include "gnunet_dbus_lib_client.h"
+
+#define LOG(kind, ...) GNUNET_log_from (kind, "dbus-client", __VA_ARGS__)
+
+struct GNUNET_DBUS_Client
+{
+  char *unique_name;
+  void *data;
+  bool prefers_pretty_encodings;
+};
+
+struct GNUNET_DBUS_Client *
+GNUNET_DBUS_client_create (
+    const char *unique_name)
+{
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating client with unique name %s\n", 
unique_name);
+
+  struct GNUNET_DBUS_Client *client = GNUNET_new (struct GNUNET_DBUS_Client);
+  client->unique_name = GNUNET_strdup (unique_name);
+  client->data = NULL;
+  client->prefers_pretty_encodings = false;
+
+  return client;
+};
+
+void
+GNUNET_DBUS_client_destroy (
+    struct GNUNET_DBUS_Client *client)
+{
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying client with unique name %s\n", 
client->unique_name);
+
+  GNUNET_free (client->unique_name);
+  GNUNET_free (client);
+};
+
+const char *
+GNUNET_DBUS_client_get_unique_name (
+    const struct GNUNET_DBUS_Client *client)
+{
+  return client->unique_name;
+};
+
+void
+GNUNET_DBUS_client_set_data (
+    struct GNUNET_DBUS_Client *client,
+    void *data)
+{
+  client->data = data;
+};
+
+void *
+GNUNET_DBUS_client_get_data (
+    const struct GNUNET_DBUS_Client *client)
+{
+  return client->data;
+};
+
+void
+GNUNET_DBUS_client_set_prefers_pretty_encodings (
+    struct GNUNET_DBUS_Client *client,
+    bool prefers_pretty_encodings)
+{
+  client->prefers_pretty_encodings = prefers_pretty_encodings;
+}
+
+bool
+GNUNET_DBUS_client_get_prefers_pretty_encodings (
+    const struct GNUNET_DBUS_Client *client)
+{
+  return client->prefers_pretty_encodings;
+};
+

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_client.h
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_client.h                                
(rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_client.h        2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -0,0 +1,47 @@
+#ifndef GNUNET_DBUS_CLIENT_H
+#define GNUNET_DBUS_CLIENT_H
+
+#include <stdbool.h>
+
+struct GNUNET_DBUS_Client;
+
+struct GNUNET_DBUS_ClientIterator
+{
+  struct GNUNET_DBUS_ClientIterator *next;
+  struct GNUNET_DBUS_ClientIterator *prev;
+
+  struct GNUNET_DBUS_Client *client;
+};
+
+struct GNUNET_DBUS_Client *
+GNUNET_DBUS_client_create (
+    const char *unique_name);
+
+void
+GNUNET_DBUS_client_destroy (
+    struct GNUNET_DBUS_Client *client);
+
+const char *
+GNUNET_DBUS_client_get_unique_name (
+    const struct GNUNET_DBUS_Client *client);
+
+void
+GNUNET_DBUS_client_set_data (
+    struct GNUNET_DBUS_Client *client,
+    void *data);
+
+void *
+GNUNET_DBUS_client_get_data (
+    const struct GNUNET_DBUS_Client *client);
+
+void
+GNUNET_DBUS_client_set_prefers_pretty_encodings (
+    struct GNUNET_DBUS_Client *client,
+    bool prefers_pretty_encodings);
+
+bool
+GNUNET_DBUS_client_get_prefers_pretty_encodings (
+    const struct GNUNET_DBUS_Client *client);
+
+#endif
+

Deleted: gnunet-dbus/src/lib/gnunet_dbus_lib_crypto.c
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_crypto.c        2014-02-14 10:35:11 UTC 
(rev 32344)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_crypto.c        2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -1,32 +0,0 @@
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_common.h>
-#include <gnunet/gnunet_crypto_lib.h>
-
-#include "gnunet_dbus_lib.h"
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_ecdsa_public_key (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    struct GNUNET_CRYPTO_EcdsaPublicKey *key)
-{
-  const char *key_in;
-  DBusMessage *ret = GNUNET_DBUS_message_iter_pop_string (message, iter, 
arg_name, &key_in);
-  if (ret)
-    return ret;
-
-  int err = GNUNET_CRYPTO_ecdsa_public_key_from_string (key_in, strlen 
(key_in), key);
-  if (GNUNET_OK != err)
-  {
-    return dbus_message_new_error_printf (
-        message,
-        DBUS_ERROR_INVALID_ARGS,
-        "Bad argument for '%s'. Malformed ECDSA public key. 
GNUNET_CRYPTO_ecdsa_public_key_from_string returned %d",
-          arg_name,
-          err);
-  };
-
-  return NULL;
-};
-

Deleted: gnunet-dbus/src/lib/gnunet_dbus_lib_crypto.h
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_crypto.h        2014-02-14 10:35:11 UTC 
(rev 32344)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_crypto.h        2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -1,12 +0,0 @@
-#ifndef GNUNET_DBUS_LIB_CRYPTO_H
-#define GNUNET_DBUS_LIB_CRYPTO_H
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_ecdsa_public_key (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    struct GNUNET_CRYPTO_EcdsaPublicKey *key);
-
-#endif
-

Deleted: gnunet-dbus/src/lib/gnunet_dbus_lib_dht.c
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_dht.c   2014-02-14 10:35:11 UTC (rev 
32344)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_dht.c   2014-02-14 11:08:46 UTC (rev 
32345)
@@ -1,36 +0,0 @@
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_common.h>
-#include <gnunet/gnunet_dht_service.h>
-
-#include "gnunet_dbus_lib.h"
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_dht_routeoption (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    enum GNUNET_DHT_RouteOption *value)
-{
-  static const struct GNUNET_DBUS_StringEnumPair fields[] = {
-      {"demultiplex_everywhere", GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE},
-      {"record_route",           GNUNET_DHT_RO_RECORD_ROUTE},
-      {"find_peer",              GNUNET_DHT_RO_FIND_PEER},
-      {"bart",                   GNUNET_DHT_RO_BART},
-      {NULL,                     0}
-  };
-
-  int bf;
-  DBusMessage *ret = GNUNET_DBUS_message_iter_pop_bitfield (
-      message,
-      iter,
-      arg_name,
-      &bf,
-      fields);
-  if (ret)
-    return ret;
-
-  *value = (enum GNUNET_DHT_RouteOption)bf;
-  return NULL;
-};
-
-

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_interface.c
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_interface.c                             
(rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_interface.c     2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -0,0 +1,214 @@
+#include "config.h"
+
+#include <dbus/dbus.h>
+
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_container_lib.h>
+
+#include "gnunet_dbus_lib_object.h"
+#include "gnunet_dbus_lib_interface.h"
+#include "gnunet_dbus_lib_method.h"
+#include "gnunet_dbus_lib_arg.h"
+#include "gnunet_dbus_lib_message_iter_push.h"
+#include "gnunet_dbus_lib_signature.h"
+
+#define LOG(kind, ...) GNUNET_log_from (kind, "dbus-interface", __VA_ARGS__)
+
+struct GNUNET_DBUS_Interface
+{
+  struct GNUNET_DBUS_MethodIterator *methods_front;
+  struct GNUNET_DBUS_MethodIterator *methods_back;
+
+  char *name;
+  unsigned ref_count;
+};
+
+struct GNUNET_DBUS_Interface *
+GNUNET_DBUS_interface_create (
+    const char *name)
+{
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating interface %s\n", name);
+
+  struct GNUNET_DBUS_Interface *interface = GNUNET_new (struct 
GNUNET_DBUS_Interface);
+
+  interface->methods_front = NULL;
+  interface->methods_back = NULL;
+  interface->name = GNUNET_strdup (name);
+  interface->ref_count = 0;
+
+  return interface;
+};
+
+void
+GNUNET_DBUS_interface_destroy (
+    struct GNUNET_DBUS_Interface *interface)
+{
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying interface %s\n", interface->name);
+
+  if (0 != interface->ref_count)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Tried to destroy interface that still has 
references. name == \"%s\", ref_count == %zu\n", interface->name, 
interface->ref_count);
+    GNUNET_abort ();
+  };
+
+  struct GNUNET_DBUS_MethodIterator *methods_iter = interface->methods_front;
+  while (methods_iter)
+  {
+    struct GNUNET_DBUS_MethodIterator *next = methods_iter->next;
+    GNUNET_DBUS_method_unref (methods_iter->method);
+    GNUNET_free (methods_iter);
+    methods_iter = next;
+  };
+
+  GNUNET_free (interface->name);
+  GNUNET_free (interface);
+};
+
+void
+GNUNET_DBUS_interface_ref (
+    struct GNUNET_DBUS_Interface *interface)
+{
+  interface->ref_count++;
+};
+
+void
+GNUNET_DBUS_interface_unref (
+    struct GNUNET_DBUS_Interface *interface)
+{
+  if (interface->ref_count == 0)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Tried to unreference interface with ref 
count 0\n");
+    GNUNET_abort ();
+  };
+  if (--interface->ref_count == 0)
+    GNUNET_DBUS_interface_destroy (interface);
+};
+
+void
+GNUNET_DBUS_interface_add_method (
+    struct GNUNET_DBUS_Interface *interface,
+    struct GNUNET_DBUS_Method *method)
+{
+  struct GNUNET_DBUS_MethodIterator *meth_it = GNUNET_new (struct 
GNUNET_DBUS_MethodIterator);
+  meth_it->method = method;
+  GNUNET_DBUS_method_ref (method);
+
+  GNUNET_CONTAINER_DLL_insert (interface->methods_front,
+                               interface->methods_back,
+                               meth_it);
+};
+
+const char *
+GNUNET_DBUS_interface_get_name (
+    const struct GNUNET_DBUS_Interface *interface)
+{
+  return interface->name;
+};
+
+const struct GNUNET_DBUS_MethodIterator *
+GNUNET_DBUS_interface_iterate_methods (
+    const struct GNUNET_DBUS_Interface *interface)
+{
+  return interface->methods_front;
+};
+
+static void
+introspectable_introspect (
+    struct GNUNET_DBUS_MethodContext *mc)
+{
+  char *data = NULL;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Introspecting\n");
+  struct GNUNET_DBUS_Object *object = mc->object;
+  GNUNET_append_sprintf (&data, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "here\n");
+  GNUNET_append_sprintf (&data, "<node>\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "and here\n");
+  const struct GNUNET_DBUS_InterfaceIterator *int_it = 
GNUNET_DBUS_object_iterate_interfaces (object);
+  while (int_it)
+  {
+    struct GNUNET_DBUS_Interface *interface = int_it->interface;
+    const char *interface_name = GNUNET_DBUS_interface_get_name (interface);
+    GNUNET_append_sprintf (&data, "  <interface name='%s'>\n", interface_name);
+    const struct GNUNET_DBUS_MethodIterator *meth_it = 
GNUNET_DBUS_interface_iterate_methods (interface);
+    while (meth_it)
+    {
+      struct GNUNET_DBUS_Method *method = meth_it->method;
+      const char *method_name = GNUNET_DBUS_method_get_name (method);
+      GNUNET_append_sprintf (&data, "    <method name='%s'>\n", method_name);
+      const struct GNUNET_DBUS_ArgIterator *arg_it = 
GNUNET_DBUS_method_iterate_args (method);
+      while (arg_it)
+      {
+        struct GNUNET_DBUS_Arg *arg = arg_it->arg;
+        const char *arg_name = GNUNET_DBUS_arg_get_name (arg);
+        const char *signature = GNUNET_DBUS_arg_get_signature (arg);
+        GNUNET_append_sprintf (
+            &data, 
+            "      <arg name='%s' type='%s' direction='in'/>\n",
+              arg_name,
+              signature);
+        arg_it = arg_it->next;
+      };
+
+      arg_it = GNUNET_DBUS_method_iterate_return_args (method);
+      while (arg_it)
+      {
+        struct GNUNET_DBUS_Arg *arg = arg_it->arg;
+        const char *arg_name = GNUNET_DBUS_arg_get_name (arg);
+        const char *signature = GNUNET_DBUS_arg_get_signature (arg);
+        GNUNET_append_sprintf (
+            &data, 
+            "      <arg name='%s' type='%s' direction='out'/>\n",
+              arg_name,
+              signature);
+        arg_it = arg_it->next;
+      };
+      GNUNET_append_sprintf (&data, "    </method>\n");
+      meth_it = meth_it->next;
+    };
+    GNUNET_append_sprintf (&data, "  </interface>\n");
+    int_it = int_it->next;
+  };
+  GNUNET_append_sprintf (&data, "</node>\n");
+
+  DBusMessage *message = mc->message;
+  DBusMessage *reply = dbus_message_new_method_return (message);
+  DBusMessageIter reply_iter;
+  dbus_message_iter_init_append (reply, &reply_iter);
+  GNUNET_DBUS_message_iter_push_string (mc, &reply_iter, data);
+  GNUNET_DBUS_method_context_send_reply (mc, reply);
+  GNUNET_DBUS_method_context_unref (mc);
+  GNUNET_free (data);
+};
+
+struct GNUNET_DBUS_Interface *
+GNUNET_DBUS_interface_introspectable ()
+{
+  static struct GNUNET_DBUS_Interface *introspectable = NULL;
+
+  if (NULL == introspectable)
+  {
+    introspectable = GNUNET_DBUS_interface_create 
("org.freedesktop.DBus.Introspectable");
+    struct GNUNET_DBUS_Method *introspect = GNUNET_DBUS_method_create 
("Introspect", introspectable_introspect);
+    GNUNET_DBUS_method_add_return_arg (introspect, "data", 
GNUNET_DBUS_SIGNATURE_STRING);
+    GNUNET_DBUS_interface_add_method (introspectable, introspect);
+    GNUNET_DBUS_interface_ref (introspectable);
+  };
+
+  return introspectable;
+};
+
+const struct GNUNET_DBUS_InterfaceIterator *
+GNUNET_DBUS_interface_find (
+    const struct GNUNET_DBUS_InterfaceIterator *int_it,
+    const char *name)
+{
+  for (; int_it; int_it = int_it->next)
+  {
+    if (! strcmp (name, int_it->interface->name))
+      return int_it;
+  }
+  return NULL;
+}
+

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_interface.h
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_interface.h                             
(rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_interface.h     2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -0,0 +1,59 @@
+#ifndef GNUNET_DBUS_LIB_INTERFACE_H
+#define GNUNET_DBUS_LIB_INTERFACE_H
+
+#include <stdbool.h>
+
+struct GNUNET_DBUS_Interface;
+
+#include "gnunet_dbus_lib_object.h"
+#include "gnunet_dbus_lib_method.h"
+#include "gnunet_dbus_lib_method_context.h"
+
+struct GNUNET_DBUS_InterfaceIterator
+{
+  /* linked list */
+  struct GNUNET_DBUS_InterfaceIterator *next;
+  struct GNUNET_DBUS_InterfaceIterator *prev;
+
+  struct GNUNET_DBUS_Interface *interface;
+};
+
+struct GNUNET_DBUS_Interface *
+GNUNET_DBUS_interface_create (
+    const char *name);
+
+void
+GNUNET_DBUS_interface_destroy (
+    struct GNUNET_DBUS_Interface *interface);
+
+void
+GNUNET_DBUS_interface_ref (
+    struct GNUNET_DBUS_Interface *interface);
+
+void
+GNUNET_DBUS_interface_unref (
+    struct GNUNET_DBUS_Interface *interface);
+
+void
+GNUNET_DBUS_interface_add_method (
+    struct GNUNET_DBUS_Interface *interface,
+    struct GNUNET_DBUS_Method *method);
+
+const char *
+GNUNET_DBUS_interface_get_name (
+    const struct GNUNET_DBUS_Interface *interface);
+
+const struct GNUNET_DBUS_MethodIterator *
+GNUNET_DBUS_interface_iterate_methods (
+    const struct GNUNET_DBUS_Interface *interface);
+
+struct GNUNET_DBUS_Interface *
+GNUNET_DBUS_interface_introspectable ();
+
+const struct GNUNET_DBUS_InterfaceIterator *
+GNUNET_DBUS_interface_find (
+    const struct GNUNET_DBUS_InterfaceIterator *int_it,
+    const char *name);
+
+#endif
+

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_message_iter_pop.c
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_message_iter_pop.c                      
        (rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_message_iter_pop.c      2014-02-14 
11:08:46 UTC (rev 32345)
@@ -0,0 +1,620 @@
+#include "config.h"
+
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_strings_lib.h>
+
+#include "gnunet_dbus_lib_message_iter_pop.h"
+#include "gnunet_dbus_lib_method_context.h"
+#include "gnunet_dbus_lib_client.h"
+#include "gnunet_dbus_lib_signature.h"
+
+#define LOG(kind, ...) GNUNET_log_from (kind, "dbus-pop", __VA_ARGS__)
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_basic (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    int expected_type,
+    void *value)
+{
+  int arg_type = dbus_message_iter_get_arg_type (iter);
+  if (expected_type != arg_type)
+  {
+    return dbus_message_new_error_printf (
+        mc->message,
+        DBUS_ERROR_INVALID_ARGS,
+        "Bad argument for '%s'. Expected %s. Got %s",
+          arg_name,
+          GNUNET_DBUS_signature_typecode_to_string (expected_type),
+          GNUNET_DBUS_signature_typecode_to_string (arg_type));
+  };
+  dbus_message_iter_get_basic (iter, value);
+  dbus_message_iter_next (iter);
+
+  return NULL;
+};
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_string (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    const char **value)
+{
+  return GNUNET_DBUS_message_iter_pop_basic (
+      mc,
+      iter,
+      arg_name,
+      DBUS_TYPE_STRING,
+      (void *)value);
+};
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_byte (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    unsigned char *value)
+{
+  return GNUNET_DBUS_message_iter_pop_basic (
+      mc,
+      iter,
+      arg_name,
+      DBUS_TYPE_BYTE,
+      (void *)value);
+};
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_int32 (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    dbus_int32_t *value)
+{
+  return GNUNET_DBUS_message_iter_pop_basic (
+      mc,
+      iter,
+      arg_name,
+      DBUS_TYPE_INT32,
+      (void *)value);
+};
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_uint32 (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    dbus_uint32_t *value)
+{
+  return GNUNET_DBUS_message_iter_pop_basic (
+      mc,
+      iter,
+      arg_name,
+      DBUS_TYPE_UINT32,
+      (void *)value);
+};
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_uint64 (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    dbus_uint64_t *value)
+{
+  return GNUNET_DBUS_message_iter_pop_basic (
+      mc,
+      iter,
+      arg_name,
+      DBUS_TYPE_UINT64,
+      (void *)value);
+};
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_bool (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    dbus_bool_t *value)
+{
+  return GNUNET_DBUS_message_iter_pop_basic (
+      mc,
+      iter,
+      arg_name,
+      DBUS_TYPE_BOOLEAN,
+      (void *)value);
+};
+
+#if 0
+void
+GNUNET_DBUS_message_iter_pop_recurse_array (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    DBusMessageIter *iter_sub,
+    const char *arg_name)
+{
+  int arg_type = dbus_message_iter_get_arg_type (iter);
+  if (DBUS_TYPE_ARRAY != arg_type)
+  {
+    return dbus_message_new_error_printf (
+        mc->message,
+        DBUS_ERROR_INVALID_ARGS,
+          "Bad argument for '%s'. Expected '%s'. Got '%s'",
+            arg_name,
+            dbus_message_type_to_string (DBUS_TYPE_ARRAY),
+            dbus_message_type_to_string (arg_type));
+  }
+
+  DBusMessageIter iter_sub;
+  dbus_message_iter_recurse (iter, &iter_sub);
+}
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_fixed_array (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    int expected_type,
+    void *value,
+    int *n_elements)
+{
+  int element_type = dbus_message_iter_get_arg_type (iter);
+  if (expected_type != element_type)
+  {
+    return dbus_message_new_error_printf (
+        message,
+        DBUS_ERROR_INVALID_ARGS,
+        "Bad argument for '%s'. Expected array of %s. Got array of %s",
+          arg_name,
+          dbus_message_type_to_string (expected_type),
+          dbus_message_type_to_string (element_type));
+  };
+
+  DBusMessageIter itersub;
+  dbus_message_iter_recurse (iter, &itersub);
+  dbus_message_iter_get_fixed_array (&itersub, value, n_elements);
+
+  return NULL;
+};
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_array_byte (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    const char **value,
+    int *n_elements)
+{
+  return GNUNET_DBUS_message_iter_pop_fixed_array (
+      message,
+      iter,
+      arg_name,
+      DBUS_TYPE_BYTE,
+      (void *)value,
+      n_elements);
+};
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_array_string (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    const char ***value,
+    int *n_elements)
+{
+  return GNUNET_DBUS_message_iter_pop_fixed_array (
+      message,
+      iter,
+      arg_name,
+      DBUS_TYPE_STRING,
+      (void *)value,
+      n_elements);
+};
+
+/*
+ * bitfield enums can be sent across the wire in either their integer form (as
+ * an array of bit flags) or as an array of strings. Sending an int is more
+ * efficient and is what libraries built around the DBus API would use, people
+ * using the DBus API directly may want to pass human-readable strings for
+ * convenience.
+ */
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_bitfield (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    int *value,
+    const struct GNUNET_DBUS_StringEnumPair *fields)
+{
+  uint32_t flags;
+  DBusMessage *ret = GNUNET_DBUS_message_iter_pop_uint32 (message, iter, 
arg_name, &flags);
+  if (! ret)
+  {
+    *value = (int)flags;
+    return NULL;
+  };
+  dbus_message_unref (ret);
+
+  const char **options;
+  int num_options;
+  ret = GNUNET_DBUS_message_iter_pop_array_string (message, iter, arg_name, 
&options, &num_options);
+  if (! ret)
+  {
+    *value = 0;
+    int i;
+    for (i = 0; i < num_options; i++)
+    {
+      int j;
+      for (j = 0; fields[j].name; j++)
+      {
+        if (! strcmp (options[i], fields[j].name))
+        {
+          *value |= fields[j].value;
+          break;
+        };
+      };
+      if (! fields[j].name)
+      {
+        char *errmsg = NULL;
+        GNUNET_append_sprintf (&errmsg, "Unrecognized option '%s'. Valid 
options are: [", options[i]);
+        for (j = 0; fields[j].name; j++)
+          GNUNET_append_sprintf (&errmsg, "%s'%s'", j ? ", " : "", 
fields[j].name);
+        GNUNET_append_sprintf (&errmsg, "].");
+        ret = dbus_message_new_error_printf (
+            message,
+            DBUS_ERROR_INVALID_ARGS,
+            "%s",
+              errmsg);
+        GNUNET_free (errmsg);
+        return ret;
+      };
+    };
+
+    return NULL;
+  };
+  dbus_message_unref (ret);
+
+  return dbus_message_new_error_printf (
+      message,
+      DBUS_ERROR_INVALID_ARGS,
+      "Bad argument for '%s'. Expected either a bitfield uint32 or an array of 
string options.",
+        arg_name);
+};
+#endif
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_enum (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    int *value,
+    const struct GNUNET_DBUS_StringEnumPair *names)
+{
+  uint32_t v;
+  DBusMessage *ret = GNUNET_DBUS_message_iter_pop_uint32 (mc, iter, arg_name, 
&v);
+  if (! ret)
+  {
+    *value = (int)v;
+    return NULL;
+  };
+  dbus_message_unref (ret);
+
+  const char *name;
+  ret = GNUNET_DBUS_message_iter_pop_string (mc, iter, arg_name, &name);
+  if (! ret)
+  {
+    int i;
+    for (i = 0; names[i].name; i++)
+    {
+      if (! strcmp (name, names[i].name))
+      {
+        *value = names[i].value;
+        break;
+      };
+    };
+    if (! names[i].name)
+    {
+      char *errmsg = NULL;
+      GNUNET_append_sprintf (&errmsg, "Unrecognized option '%s'. Valid options 
are: [", name);
+      for (i = 0; names[i].name; i++)
+        GNUNET_append_sprintf (&errmsg, "%s'%s'", i ? ", " : "", 
names[i].name);
+      GNUNET_append_sprintf (&errmsg, "].");
+      ret = dbus_message_new_error_printf (
+          mc->message,
+          DBUS_ERROR_INVALID_ARGS,
+          "%s",
+            errmsg);
+      GNUNET_free (errmsg);
+      return ret;
+    };
+    return NULL;
+  };
+  dbus_message_unref (ret);
+  
+  return dbus_message_new_error_printf (
+      mc->message,
+      DBUS_ERROR_INVALID_ARGS,
+      "Bad argument for '%s'. Expected either a uint32 or a string option",
+        arg_name);
+};
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_hashcode (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    struct GNUNET_HashCode *hc)
+{
+  const char *hc_in;
+  DBusMessage *ret = GNUNET_DBUS_message_iter_pop_string (mc, iter, arg_name, 
&hc_in);
+  if (ret)
+    return ret;
+
+  int err = GNUNET_CRYPTO_hash_from_string2 (hc_in, strlen(hc_in), hc);
+  if (GNUNET_OK != err)
+  {
+    return dbus_message_new_error_printf (
+        mc->message,
+        DBUS_ERROR_INVALID_ARGS,
+        "Bad argument for '%s'. Malformed hash string. 
GNUNET_CRYPTO_hash_from_string2 returned %d",
+          arg_name,
+          err);
+  };
+
+  return NULL;
+};
+
+#if 0
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_socket (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    struct GNUNET_NETWORK_Handle **socket_handle)
+{
+  const char *address;
+
+  DBusMessage *ret = GNUNET_DBUS_message_iter_pop_string (message, iter, 
arg_name, &address);
+  if (ret)
+    return ret;
+
+  *socket_handle = GNUNET_DBUS_create_socket_from_dbus_address (address);
+  if (! *socket_handle)
+  {
+    return dbus_message_new_error_printf (
+        message,
+        DBUS_ERROR_INVALID_ARGS,
+        "Bad argument for '%s'. Malformed address",
+          arg_name);
+  };
+
+  return NULL;
+};
+#endif
+
+
+#if 0 // make it use variants and set pretty
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_absolute_time (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    struct GNUNET_TIME_Absolute *value)
+{
+  const char *time;
+  DBusMessage *ret = GNUNET_DBUS_message_iter_pop_string (mc, iter, arg_name, 
&time);
+  if (ret)
+  {
+    dbus_message_unref (ret);
+    ret = GNUNET_DBUS_message_iter_pop_uint64 (mc, iter, arg_name, 
&value->abs_value_us);
+    if (ret)
+      return ret;
+  };
+
+  int err = GNUNET_STRINGS_fancy_time_to_absolute (time, value);
+  if (GNUNET_OK != err)
+  {
+    return dbus_message_new_error_printf (
+        mc->message,
+        DBUS_ERROR_INVALID_ARGS,
+        "Bad argument for '%s'. Malformed time string. 
GNUNET_STRINGS_fancy_time_to_absolute returned %d",
+          arg_name,
+          err);
+  };
+
+  return NULL;
+};
+#endif
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_enter_variant (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    DBusMessageIter *iter_sub,
+    const char *arg_name)
+{
+  int arg_type = dbus_message_iter_get_arg_type (iter);
+  if (DBUS_TYPE_VARIANT != arg_type)
+  {
+    return dbus_message_new_error_printf (
+        mc->message,
+        DBUS_ERROR_INVALID_ARGS,
+        "Bad argument for '%s'. Expected '%s'. Got '%s'.",
+          arg_name,
+          GNUNET_DBUS_signature_typecode_to_string (DBUS_TYPE_VARIANT),
+          GNUNET_DBUS_signature_typecode_to_string (arg_type));
+  };
+
+  dbus_message_iter_recurse (iter, iter_sub);
+  dbus_message_iter_next (iter);
+  return NULL;
+}
+    
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_enter_struct (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    DBusMessageIter *iter_sub,
+    const char *arg_name)
+{
+  int arg_type = dbus_message_iter_get_arg_type (iter);
+  if (DBUS_TYPE_STRUCT != arg_type)
+  {
+    return dbus_message_new_error_printf (
+        mc->message,
+        DBUS_ERROR_INVALID_ARGS,
+        "Bad argument for '%s'. Expected '%s'. Got '%s'.",
+          arg_name,
+          GNUNET_DBUS_signature_typecode_to_string (DBUS_TYPE_STRUCT),
+          GNUNET_DBUS_signature_typecode_to_string (arg_type));
+  };
+
+  dbus_message_iter_recurse (iter, iter_sub);
+  return NULL;
+}
+
+void
+GNUNET_DBUS_message_iter_pop_exit_struct (
+    DBusMessageIter *iter)
+{
+  int arg_type = dbus_message_iter_get_arg_type (iter);
+  if (DBUS_TYPE_STRUCT != arg_type)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DBUS_message_iter_pop_exit_struct 
called when not inside a struct\n");
+    GNUNET_abort ();
+  }
+
+  dbus_message_iter_next (iter);
+}
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_ecdsa_public_key (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    struct GNUNET_CRYPTO_EcdsaPublicKey *value)
+{
+  DBusMessage *ret = NULL;
+  DBusMessageIter iter_sub;
+  DBusMessageIter iter_sub_sub;
+
+  ret = GNUNET_DBUS_message_iter_pop_enter_variant (mc, iter, &iter_sub, 
arg_name);
+  if (ret)
+    return ret;
+
+  const char *encoded;
+  int success;
+  int arg_type = dbus_message_iter_get_arg_type (&iter_sub);
+  int element_type;
+  int n_elements;
+  unsigned char *marshalled_array;
+  switch (arg_type)
+  {
+  case DBUS_TYPE_STRING:
+    dbus_message_iter_get_basic (&iter_sub, &encoded);
+    success = GNUNET_CRYPTO_ecdsa_public_key_from_string (encoded, strlen 
(encoded), value);
+    if (GNUNET_OK != success)
+    {
+      return dbus_message_new_error_printf (
+          mc->message,
+          DBUS_ERROR_INVALID_ARGS,
+          "String is not a valid base32 encoded ECDSA public key for argument 
'%s'",
+            arg_name);
+    }
+    GNUNET_DBUS_client_set_prefers_pretty_encodings (mc->client, true);
+    return NULL;
+  case DBUS_TYPE_ARRAY:
+    element_type = dbus_message_iter_get_element_type (&iter_sub);
+    if (DBUS_TYPE_BYTE == element_type)
+    {
+      dbus_message_iter_recurse (&iter_sub, &iter_sub_sub);
+      dbus_message_iter_get_fixed_array (&iter_sub_sub, &marshalled_array, 
&n_elements);
+      if (sizeof (value->q_y) == n_elements)
+      {
+        memcpy (value->q_y, marshalled_array, n_elements);
+        return NULL;
+      };
+      return dbus_message_new_error_printf (
+          mc->message,
+          DBUS_ERROR_INVALID_ARGS,
+          "ECDSA public key consists of 32 bytes (256 bits). Array given for 
argument '%s' contains %d bytes.",
+            arg_name,
+            n_elements);
+    };
+    return dbus_message_new_error_printf (
+        mc->message,
+        DBUS_ERROR_INVALID_ARGS,
+        "Invalid type for argument '%s'. Variant contains an array of '%s'. 
Should contain a base32 encoded ECDSA public key in the form of a string or an 
array of 32 bytes (256 bits).",
+          arg_name,
+          GNUNET_DBUS_signature_typecode_to_string (element_type));
+  default:
+    return dbus_message_new_error_printf (
+        mc->message,
+        DBUS_ERROR_INVALID_ARGS,
+        "Invalid type in variant for argument '%s'. Should contain a base32 
encoded ECDSA public key in the form of a string or an array of 32 bytes (256 
bits). Contains '%s'",
+          arg_name,
+          GNUNET_DBUS_signature_typecode_to_string (arg_type));
+  }
+}
+
+#if 0
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_ecdsa_signature (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    struct GNUNET_CRYPTO_EcdsaSignature *value)
+{
+  DBusMessage *ret = NULL;
+  DBusMessageIter iter_sub;
+  DBusMessageIter iter_sub_sub;
+  DBusMessageIter iter_sub_sub_sub;
+  DBusMessage *ret = GNUNET_DBUS_message_iter_pop_enter_struct (message, iter, 
&iter_sub, arg_name);
+  
+}
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_ecc_signature_purpose (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    struct GNUNET_CRYPTO_EccSignaturePurpose *value)
+{
+  DBusMessageIter iter_sub;
+  DBusMessage *ret = NULL;
+  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_enter_struct (message, iter, 
&iter_sub, arg_name);
+  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_uint32 (message, &iter_sub, 
"size",    &value->size);
+  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_uint32 (message, &iter_sub, 
"purpose", &value->purpose);
+  if (ret)
+    return ret;
+  GNUNET_DBUS_message_iter_pop_exit_struct (iter);
+
+ return NULL;
+}
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_gnsrecord_block (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    struct GNUNET_GNSRECORD_Block *value)
+{
+  DBusMessageIter iter_sub;
+  DBusMessage *ret = NULL;
+  struct GNUNET_TIME_Absolute expiration_time;
+  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_enter_struct          
(message, iter, &iter_sub, arg_name);
+  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_ecdsa_signature       
(message, &iter_sub, "signature",       &value->signature);
+  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_ecdsa_public_key      
(message, &iter_sub, "derived_key",     &value->derived_key);
+  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_ecc_signature_purpose 
(message, &iter_sub, "purpose",         &value->purpose);
+  ret = ret ? ret : GNUNET_DBUS_message_iter_pop_absolute_time         
(message, &iter_sub, "expiration_time", &expiration_time);
+  if (ret)
+    return ret;
+  GNUNET_DBUS_message_iter_pop_exit_struct (iter);
+  value->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
+
+  return NULL;
+}
+#endif
+
+

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_message_iter_pop.h
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_message_iter_pop.h                      
        (rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_message_iter_pop.h      2014-02-14 
11:08:46 UTC (rev 32345)
@@ -0,0 +1,154 @@
+#ifndef GNUNET_DBUS_LIB_MESSAGE_ITER_POP
+#define GNUNET_DBUS_LIB_MESSAGE_ITER_POP
+
+#include <stdbool.h>
+
+#include <dbus/dbus.h>
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_crypto_lib.h>
+#include <gnunet/gnunet_gnsrecord_lib.h>
+
+#include "gnunet_dbus_lib_method_context.h"
+
+struct GNUNET_DBUS_StringEnumPair
+{
+  const char *name;
+  int value;
+};
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_basic (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    int expected_type,
+    void *value);
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_string (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    const char **value);
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_int32 (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    dbus_int32_t *value);
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_uint32 (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    dbus_uint32_t *value);
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_bool (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    dbus_bool_t *value);
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_fixed_array (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    int expected_type,
+    void *value,
+    int *n_elements);
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_array_byte (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    const char **value,
+    int *n_elements);
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_array_string (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    const char ***value,
+    int *n_elements);
+
+/*
+ * bitfield enums can be sent across the wire in either their integer form (as
+ * an array of bit flags) or as an array of strings. Sending an int is more
+ * efficient and is what libraries built around the DBus API would use, people
+ * using the DBus API directly may want to pass human-readable strings for
+ * convenience.
+ */
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_bitfield (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    int *value,
+    const struct GNUNET_DBUS_StringEnumPair *fields);
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_enum (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    int *value,
+    const struct GNUNET_DBUS_StringEnumPair *names);
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_hashcode (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    struct GNUNET_HashCode *hc);
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_socket (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    struct GNUNET_NETWORK_Handle **socket_handle);
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_absolute_time (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    struct GNUNET_TIME_Absolute *value);
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_ecdsa_public_key (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    struct GNUNET_CRYPTO_EcdsaPublicKey *value);
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_ecdsa_signature (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    struct GNUNET_CRYPTO_EcdsaSignature *value);
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_ecc_signature_purpose (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    struct GNUNET_CRYPTO_EccSignaturePurpose *value);
+
+DBusMessage *
+GNUNET_DBUS_message_iter_pop_gnsrecord_block (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *arg_name,
+    struct GNUNET_GNSRECORD_Block *value);
+
+#endif
+

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_message_iter_push.c
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_message_iter_push.c                     
        (rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_message_iter_push.c     2014-02-14 
11:08:46 UTC (rev 32345)
@@ -0,0 +1,219 @@
+#include "config.h"
+
+#include <stdbool.h>
+
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_strings_lib.h>
+
+#include "gnunet_dbus_lib_signature.h"
+#include "gnunet_dbus_lib_client.h"
+#include "gnunet_dbus_lib_message_iter_push.h"
+
+#define LOG(kind, ...) GNUNET_log_from (kind, "dbus-push", __VA_ARGS__)
+
+void
+GNUNET_DBUS_message_iter_push_basic (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    int type,
+    void *value)
+{
+  (void)mc;
+  bool success = dbus_message_iter_append_basic (iter, type, value);
+  if (! success)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Ran out of memory in 
dbus_message_iter_append_basic\n");
+    GNUNET_abort ();
+  }
+}
+
+void
+GNUNET_DBUS_message_iter_push_int32 (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    int32_t value)
+{
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Pushing int32\n");
+  GNUNET_DBUS_message_iter_push_basic (
+      mc,
+      iter,
+      DBUS_TYPE_INT32,
+      &value);
+}
+
+void
+GNUNET_DBUS_message_iter_push_uint32 (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    uint32_t value)
+{
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Pushing uint32\n");
+  GNUNET_DBUS_message_iter_push_basic (
+      mc,
+      iter,
+      DBUS_TYPE_UINT32,
+      &value);
+}
+
+void
+GNUNET_DBUS_message_iter_push_uint64 (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    uint64_t value)
+{
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Pushing uint64\n");
+  GNUNET_DBUS_message_iter_push_basic (
+      mc,
+      iter,
+      DBUS_TYPE_UINT64,
+      &value);
+}
+
+void
+GNUNET_DBUS_message_iter_push_string (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *value)
+{
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Pushing string\n");
+  GNUNET_DBUS_message_iter_push_basic (
+      mc,
+      iter,
+      DBUS_TYPE_STRING,
+      &value);
+}
+
+void
+GNUNET_DBUS_message_iter_push_open_array (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    DBusMessageIter *iter_sub,
+    const char *signature)
+{
+  (void)mc;
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Opening array\n");
+  bool success = dbus_message_iter_open_container (iter, DBUS_TYPE_ARRAY, 
signature, iter_sub);
+  if (! success)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Ran out of memory in 
dbus_message_iter_open_container\n");
+    GNUNET_abort ();
+  }
+}
+
+void
+GNUNET_DBUS_message_iter_push_close_container (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    DBusMessageIter *iter_sub)
+{
+  (void)mc;
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Closing container\n");
+  bool success = dbus_message_iter_close_container (iter, iter_sub);
+  if (! success)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Ran out of memory in 
dbus_message_iter_close_container\n");
+    GNUNET_abort ();
+  }
+}
+
+/*
+ * Push an array of fixed-size types. The array must be opened with
+ * GNUNET_DBUS_message_iter_push_open_array first and closed with
+ * GNUNET_DBUS_message_iter_push_close_container afterwards.
+ */
+void
+GNUNET_DBUS_message_iter_push_fixed_array (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    int type,
+    const void *value,
+    size_t value_count)
+{
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Pushing fixed array\n");
+  bool success = dbus_message_iter_append_fixed_array (iter, type, value, 
(int)value_count);
+  if (! success)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Ran out of memory in 
dbus_message_iter_push_fixed_array\n");
+    GNUNET_abort ();
+  }
+}
+
+void
+GNUNET_DBUS_message_iter_push_bytes (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const unsigned char *value,
+    size_t value_count)
+{
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Pushing byte array\n");
+  GNUNET_DBUS_message_iter_push_fixed_array (
+      mc,
+      iter,
+      DBUS_TYPE_BYTE,
+      &value,
+      value_count);
+}
+
+void
+GNUNET_DBUS_message_iter_push_open_variant (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    DBusMessageIter *iter_sub,
+    const char *signature)
+{
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Opening variant\n");
+  bool success = dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, 
signature, iter_sub);
+  if (! success)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Ran out of memory in 
dbus_message_iter_open_container when open variant\n");
+    GNUNET_abort ();
+  }
+}
+
+void
+GNUNET_DBUS_message_iter_push_time_absolute (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const struct GNUNET_TIME_Absolute *value)
+{
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Pushing absolute time\n");
+  DBusMessageIter iter_sub;
+  if (GNUNET_DBUS_client_get_prefers_pretty_encodings (mc->client))
+  {
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Encoding time as string\n");
+    GNUNET_DBUS_message_iter_push_open_variant (mc, iter, &iter_sub, 
GNUNET_DBUS_SIGNATURE_STRING);
+    GNUNET_DBUS_message_iter_push_string (mc, &iter_sub, 
GNUNET_STRINGS_absolute_time_to_string (*value));
+    GNUNET_DBUS_message_iter_push_close_variant (mc, iter, &iter_sub);
+  }
+  else
+  {
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Encoding time as uint64\n");
+    GNUNET_DBUS_message_iter_push_open_variant (mc, iter, &iter_sub, 
GNUNET_DBUS_SIGNATURE_UINT64);
+    GNUNET_DBUS_message_iter_push_uint64 (mc, &iter_sub, value->abs_value_us);
+    GNUNET_DBUS_message_iter_push_close_variant (mc, iter, &iter_sub);
+  }
+};
+
+void
+GNUNET_DBUS_message_iter_push_gns_record (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const struct GNUNET_GNSRECORD_Data *value)
+{
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Pushing GNUNET_GNSRECORD_Data\n");
+  DBusMessageIter iter_sub;
+  GNUNET_DBUS_message_iter_push_open_array (mc, iter, &iter_sub, 
GNUNET_DBUS_SIGNATURE_BYTE);
+  GNUNET_DBUS_message_iter_push_bytes (mc, &iter_sub, (const unsigned char 
*)value->data, value->data_size);
+  GNUNET_DBUS_message_iter_push_close_array (mc, iter, &iter_sub);
+  
+  struct GNUNET_TIME_Absolute expiration_time;
+  expiration_time.abs_value_us = value->expiration_time;
+  GNUNET_DBUS_message_iter_push_time_absolute (mc, iter, &expiration_time);
+  GNUNET_DBUS_message_iter_push_uint32 (mc, iter, value->record_type);
+  GNUNET_DBUS_message_iter_push_uint32 (mc, iter, value->flags);
+}
+
+
+
+

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_message_iter_push.h
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_message_iter_push.h                     
        (rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_message_iter_push.h     2014-02-14 
11:08:46 UTC (rev 32345)
@@ -0,0 +1,92 @@
+#ifndef GNUNET_DBUS_LIB_MESSAGE_ITER_PUSH_H
+#define GNUNET_DBUS_LIB_MESSAGE_ITER_PUSH_H
+
+#include <dbus/dbus.h>
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_crypto_lib.h>
+#include <gnunet/gnunet_gnsrecord_lib.h>
+
+#include "gnunet_dbus_lib_method_context.h"
+
+#define GNUNET_DBUS_message_iter_push_close_array   
GNUNET_DBUS_message_iter_push_close_container
+#define GNUNET_DBUS_message_iter_push_close_variant 
GNUNET_DBUS_message_iter_push_close_container
+
+void
+GNUNET_DBUS_message_iter_push_basic (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    int type,
+    void *value);
+
+void
+GNUNET_DBUS_message_iter_push_int32 (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    int32_t value);
+
+void
+GNUNET_DBUS_message_iter_push_uint32 (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    uint32_t value);
+
+void
+GNUNET_DBUS_message_iter_push_uint64 (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    uint64_t value);
+
+void
+GNUNET_DBUS_message_iter_push_string (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const char *value);
+
+void
+GNUNET_DBUS_message_iter_push_open_array (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    DBusMessageIter *iter_sub,
+    const char *signature);
+
+void
+GNUNET_DBUS_message_iter_push_close_container (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    DBusMessageIter *iter_sub);
+
+/*
+ * Push an array of fixed-size types. The array must be opened with
+ * GNUNET_DBUS_message_iter_push_open_array first and closed with
+ * GNUNET_DBUS_message_iter_push_close_container afterwards.
+ */
+void
+GNUNET_DBUS_message_iter_push_fixed_array (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    int type,
+    const void *value,
+    size_t value_count);
+
+void
+GNUNET_DBUS_message_iter_push_bytes (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const unsigned char *value,
+    size_t value_count);
+
+void
+GNUNET_DBUS_message_iter_push_time_absolute (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const struct GNUNET_TIME_Absolute *value);
+
+void
+GNUNET_DBUS_message_iter_push_gns_record (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessageIter *iter,
+    const struct GNUNET_GNSRECORD_Data *value);
+
+#endif
+

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_method.c
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_method.c                                
(rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_method.c        2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -0,0 +1,145 @@
+#include "config.h"
+
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_container_lib.h>
+
+#include "gnunet_dbus_lib_method.h"
+#include "gnunet_dbus_lib_arg.h"
+
+#define LOG(kind, ...) GNUNET_log_from (kind, "dbus-method", __VA_ARGS__)
+
+struct GNUNET_DBUS_Method
+{
+  struct GNUNET_DBUS_ArgIterator *args_front;
+  struct GNUNET_DBUS_ArgIterator *args_back;
+
+  struct GNUNET_DBUS_ArgIterator *return_args_front;
+  struct GNUNET_DBUS_ArgIterator *return_args_back;
+
+  char *name;
+
+  void (*underlying_method)(struct GNUNET_DBUS_MethodContext *mc);
+
+  unsigned ref_count;
+};
+
+struct GNUNET_DBUS_Method *
+GNUNET_DBUS_method_create (
+    const char *name,
+    void (*underlying_method)(struct GNUNET_DBUS_MethodContext *mc))
+{
+  struct GNUNET_DBUS_Method *method = GNUNET_new (struct GNUNET_DBUS_Method);
+  method->name = GNUNET_strdup (name);
+  method->underlying_method = underlying_method;
+  method->ref_count = 0;
+
+  return method;
+};
+
+void
+GNUNET_DBUS_method_destroy (
+    struct GNUNET_DBUS_Method *method)
+{
+  if (0 != method->ref_count)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Tried to destroy method that still has 
references. name == \"%s\", ref_count == %zu\n", method->name, 
method->ref_count);
+    GNUNET_abort ();
+  };
+
+  GNUNET_free (method->name);
+  GNUNET_free (method);
+};
+
+void
+GNUNET_DBUS_method_ref (
+    struct GNUNET_DBUS_Method *method)
+{
+  method->ref_count++;
+};
+
+void
+GNUNET_DBUS_method_unref (
+    struct GNUNET_DBUS_Method *method)
+{
+  if (method->ref_count == 0)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Tried to unreference method with ref count 
0\n");
+    GNUNET_abort ();
+  };
+  if (--method->ref_count == 0)
+    GNUNET_DBUS_method_destroy (method);
+};
+
+void
+GNUNET_DBUS_method_add_arg (
+    struct GNUNET_DBUS_Method *method,
+    const char *name,
+    const char *signature)
+{
+  struct GNUNET_DBUS_Arg *arg = GNUNET_DBUS_arg_create (name, signature);
+  struct GNUNET_DBUS_ArgIterator *arg_it = GNUNET_new (struct 
GNUNET_DBUS_ArgIterator);
+  arg_it->arg = arg;
+  GNUNET_DBUS_arg_ref (arg);
+  GNUNET_CONTAINER_DLL_insert_tail (method->args_front,
+                                    method->args_back,
+                                    arg_it);
+};
+
+void
+GNUNET_DBUS_method_add_return_arg (
+    struct GNUNET_DBUS_Method *method,
+    const char *name,
+    const char *signature)
+{
+  struct GNUNET_DBUS_Arg *arg = GNUNET_DBUS_arg_create (name, signature);
+  struct GNUNET_DBUS_ArgIterator *arg_it = GNUNET_new (struct 
GNUNET_DBUS_ArgIterator);
+  arg_it->arg = arg;
+  GNUNET_DBUS_arg_ref (arg);
+  GNUNET_CONTAINER_DLL_insert_tail (method->return_args_front,
+                                    method->return_args_back,
+                                    arg_it);
+};
+
+const char *
+GNUNET_DBUS_method_get_name (
+    const struct GNUNET_DBUS_Method *method)
+{
+  return method->name;
+};
+
+const struct GNUNET_DBUS_ArgIterator *
+GNUNET_DBUS_method_iterate_args (
+    const struct GNUNET_DBUS_Method *method)
+{
+  return method->args_front;
+};
+
+const struct GNUNET_DBUS_ArgIterator *
+GNUNET_DBUS_method_iterate_return_args (
+    const struct GNUNET_DBUS_Method *method)
+{
+  return method->return_args_front;
+};
+
+void
+GNUNET_DBUS_method_call (
+    struct GNUNET_DBUS_Method *method,
+    struct GNUNET_DBUS_MethodContext *mc)
+{
+  method->underlying_method (mc);
+};
+
+const struct GNUNET_DBUS_MethodIterator *
+GNUNET_DBUS_method_find (
+    const struct GNUNET_DBUS_MethodIterator *meth_it,
+    const char *name)
+{
+  for (; meth_it; meth_it = meth_it->next)
+  {
+    if (! strcmp (name, meth_it->method->name))
+      return meth_it;
+  }
+  return NULL;
+}
+

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_method.h
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_method.h                                
(rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_method.h        2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -0,0 +1,72 @@
+#ifndef GNUNET_DBUS_LIB_METHOD_H
+#define GNUNET_DBUS_LIB_METHOD_H
+
+#include <stdbool.h>
+
+struct GNUNET_DBUS_Method;
+
+#include "gnunet_dbus_lib_object.h"
+#include "gnunet_dbus_lib_method_context.h"
+
+struct GNUNET_DBUS_MethodIterator
+{
+  /* linked list */
+  struct GNUNET_DBUS_MethodIterator *next;
+  struct GNUNET_DBUS_MethodIterator *prev;
+
+  struct GNUNET_DBUS_Method *method;
+};
+
+struct GNUNET_DBUS_Method *
+GNUNET_DBUS_method_create (
+    const char *name,
+    void (*underlying_method)(struct GNUNET_DBUS_MethodContext *mc));
+
+void
+GNUNET_DBUS_method_destroy (
+    struct GNUNET_DBUS_Method *method);
+
+void
+GNUNET_DBUS_method_ref (
+    struct GNUNET_DBUS_Method *method);
+
+void
+GNUNET_DBUS_method_unref (
+    struct GNUNET_DBUS_Method *method);
+
+void
+GNUNET_DBUS_method_add_arg (
+    struct GNUNET_DBUS_Method *method,
+    const char *name,
+    const char *signature);
+
+void
+GNUNET_DBUS_method_add_return_arg (
+    struct GNUNET_DBUS_Method *method,
+    const char *name,
+    const char *signature);
+
+const char *
+GNUNET_DBUS_method_get_name (
+    const struct GNUNET_DBUS_Method *method);
+
+const struct GNUNET_DBUS_ArgIterator *
+GNUNET_DBUS_method_iterate_args (
+    const struct GNUNET_DBUS_Method *method);
+
+const struct GNUNET_DBUS_ArgIterator *
+GNUNET_DBUS_method_iterate_return_args (
+    const struct GNUNET_DBUS_Method *method);
+
+void
+GNUNET_DBUS_method_call (
+    struct GNUNET_DBUS_Method *method,
+    struct GNUNET_DBUS_MethodContext *mc);
+
+const struct GNUNET_DBUS_MethodIterator *
+GNUNET_DBUS_method_find (
+    const struct GNUNET_DBUS_MethodIterator *meth_it,
+    const char *name);
+
+#endif
+

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_method_context.c
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_method_context.c                        
        (rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_method_context.c        2014-02-14 
11:08:46 UTC (rev 32345)
@@ -0,0 +1,86 @@
+#include "config.h"
+
+#include <dbus/dbus.h>
+
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_container_lib.h>
+
+#include "gnunet_dbus_lib_service.h"
+#include "gnunet_dbus_lib_method.h"
+#include "gnunet_dbus_lib_arg.h"
+#include "gnunet_dbus_lib_method_context.h"
+
+#define LOG(kind, ...) GNUNET_log_from (kind, "dbus-method-context", 
__VA_ARGS__)
+
+struct GNUNET_DBUS_MethodContext *
+GNUNET_DBUS_method_context_create (
+    struct GNUNET_DBUS_Client *client,
+    struct GNUNET_DBUS_Service *service,
+    struct GNUNET_DBUS_Object *object,
+    struct GNUNET_DBUS_Interface *interface,
+    struct GNUNET_DBUS_Method *method,
+    DBusMessage *message)
+{
+  struct GNUNET_DBUS_MethodContext *ret = GNUNET_new (struct 
GNUNET_DBUS_MethodContext);
+  ret->client         = client;
+  ret->service        = service;
+  ret->object         = object;
+  ret->interface      = interface;
+  ret->method         = method;
+  ret->message        = message;
+  ret->expects_reply  = ! dbus_message_get_no_reply (message);
+
+  ret->replied = false;
+  ret->ref_count = 0;
+  dbus_message_ref (message);
+
+  return ret;
+};
+
+void
+GNUNET_DBUS_method_context_destroy (
+    struct GNUNET_DBUS_MethodContext *mc)
+{
+  if (0 != mc->ref_count)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Tried to destroy method context with ref 
count %u\n", mc->ref_count);
+    GNUNET_abort ();
+  };
+
+  dbus_message_unref (mc->message);
+  GNUNET_free (mc);
+};
+
+void
+GNUNET_DBUS_method_context_ref (
+    struct GNUNET_DBUS_MethodContext *mc)
+{
+  mc->ref_count++;
+};
+
+void
+GNUNET_DBUS_method_context_unref (
+    struct GNUNET_DBUS_MethodContext *mc)
+{
+  if (0 == mc->ref_count)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Tried to unreference method context with 
ref count 0\n");
+    GNUNET_abort ();
+  };
+  if (0 == --mc->ref_count)
+    GNUNET_DBUS_method_context_destroy (mc);
+};
+
+void
+GNUNET_DBUS_method_context_send_reply (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessage *reply)
+{
+  if (! mc->expects_reply)
+    return;
+
+  GNUNET_DBUS_service_send (mc->service, reply);
+  dbus_message_unref (reply);
+};
+

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_method_context.h
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_method_context.h                        
        (rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_method_context.h        2014-02-14 
11:08:46 UTC (rev 32345)
@@ -0,0 +1,48 @@
+#ifndef GNUNET_DBUS_LIB_METHOD_CONTEXT_H
+#define GNUNET_DBUS_LIB_METHOD_CONTEXT_H
+
+#include <stdbool.h>
+
+#include <dbus/dbus.h>
+
+struct GNUNET_DBUS_MethodContext
+{
+  struct GNUNET_DBUS_Client *client;
+  struct GNUNET_DBUS_Service *service;
+  struct GNUNET_DBUS_Object *object;
+  struct GNUNET_DBUS_Interface *interface;
+  struct GNUNET_DBUS_Method *method;
+  DBusMessage *message;
+  bool expects_reply;
+  bool replied;
+  unsigned ref_count;
+};
+
+struct GNUNET_DBUS_MethodContext *
+GNUNET_DBUS_method_context_create (
+    struct GNUNET_DBUS_Client *client,
+    struct GNUNET_DBUS_Service *service,
+    struct GNUNET_DBUS_Object *object,
+    struct GNUNET_DBUS_Interface *interface,
+    struct GNUNET_DBUS_Method *method,
+    DBusMessage *message);
+  
+void
+GNUNET_DBUS_method_context_destroy (
+    struct GNUNET_DBUS_MethodContext *mc);
+
+void
+GNUNET_DBUS_method_context_ref (
+    struct GNUNET_DBUS_MethodContext *mc);
+
+void
+GNUNET_DBUS_method_context_unref (
+    struct GNUNET_DBUS_MethodContext *mc);
+
+void
+GNUNET_DBUS_method_context_send_reply (
+    struct GNUNET_DBUS_MethodContext *mc,
+    DBusMessage *reply);
+
+#endif
+

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_object.c
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_object.c                                
(rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_object.c        2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -0,0 +1,107 @@
+#include "config.h"
+
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_container_lib.h>
+
+#include "gnunet_dbus_lib_object.h"
+#include "gnunet_dbus_lib_interface.h"
+
+#define LOG(kind, ...) GNUNET_log_from (kind, "dbus-object", __VA_ARGS__)
+
+struct GNUNET_DBUS_Object
+{
+  struct GNUNET_DBUS_InterfaceIterator *interfaces_front;
+  struct GNUNET_DBUS_InterfaceIterator *interfaces_back;
+
+  char *path;
+  void *data;
+  unsigned ref_count;
+};
+
+struct GNUNET_DBUS_Object *
+GNUNET_DBUS_object_create (
+    const char *path,
+    void *data)
+{
+  struct GNUNET_DBUS_Object *object = GNUNET_new (struct GNUNET_DBUS_Object);
+  object->path = GNUNET_strdup (path);
+  object->data = data;
+  object->interfaces_front = NULL;
+  object->interfaces_back = NULL;
+  object->ref_count = 0;
+  
+  return object;
+};
+
+void
+GNUNET_DBUS_object_destroy (
+    struct GNUNET_DBUS_Object *object)
+{
+  if (0 != object->ref_count)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Tried to destroy object that still has 
references. path == \"%s\", ref_count == %zu\n", object->path, 
object->ref_count);
+    GNUNET_abort ();
+  };
+
+  struct GNUNET_DBUS_InterfaceIterator *int_it = object->interfaces_front;
+  while (int_it)
+  {
+    struct GNUNET_DBUS_InterfaceIterator *next = int_it->next;
+    GNUNET_DBUS_interface_unref (int_it->interface);
+    GNUNET_free (int_it);
+    int_it = next;
+  };
+
+  GNUNET_free (object->path);
+  GNUNET_free (object);
+};
+
+void
+GNUNET_DBUS_object_ref (
+    struct GNUNET_DBUS_Object *object)
+{
+  object->ref_count++;
+};
+
+void
+GNUNET_DBUS_object_unref (
+    struct GNUNET_DBUS_Object *object)
+{
+  if (object->ref_count == 0)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Tried to unreference object with ref count 
0\n");
+    GNUNET_abort ();
+  };
+  if (--object->ref_count == 0)
+    GNUNET_DBUS_object_destroy (object);
+};
+
+const char *
+GNUNET_DBUS_object_get_path (
+    struct GNUNET_DBUS_Object *object)
+{
+  return object->path;
+};
+
+void
+GNUNET_DBUS_object_add_interface (
+    struct GNUNET_DBUS_Object *object,
+    struct GNUNET_DBUS_Interface *interface)
+{
+  struct GNUNET_DBUS_InterfaceIterator *int_it = GNUNET_new (struct 
GNUNET_DBUS_InterfaceIterator);
+  int_it->interface = interface;
+  GNUNET_DBUS_interface_ref (interface);
+
+  GNUNET_CONTAINER_DLL_insert (object->interfaces_front,
+                               object->interfaces_back,
+                               int_it);
+};
+
+const struct GNUNET_DBUS_InterfaceIterator *
+GNUNET_DBUS_object_iterate_interfaces (
+    struct GNUNET_DBUS_Object *object)
+{
+  return object->interfaces_front;
+};
+

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_object.h
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_object.h                                
(rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_object.h        2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -0,0 +1,48 @@
+#ifndef GNUNET_DBUS_LIB_OBJECT_H
+#define GNUNET_DBUS_LIB_OBJECT_H
+
+struct GNUNET_DBUS_Object;
+
+#include "gnunet_dbus_lib_interface.h"
+
+struct GNUNET_DBUS_ObjectIterator
+{
+  /* linked list */
+  struct GNUNET_DBUS_ObjectIterator *next;
+  struct GNUNET_DBUS_ObjectIterator *prev;
+
+  struct GNUNET_DBUS_Object *object;
+};
+
+struct GNUNET_DBUS_Object *
+GNUNET_DBUS_object_create (
+    const char *path,
+    void *data);
+
+void
+GNUNET_DBUS_object_destroy (
+    struct GNUNET_DBUS_Object *object);
+
+void
+GNUNET_DBUS_object_ref (
+    struct GNUNET_DBUS_Object *object);
+
+void
+GNUNET_DBUS_object_unref (
+    struct GNUNET_DBUS_Object *object);
+
+const char *
+GNUNET_DBUS_object_get_path (
+    struct GNUNET_DBUS_Object *object);
+
+void
+GNUNET_DBUS_object_add_interface (
+    struct GNUNET_DBUS_Object *object,
+    struct GNUNET_DBUS_Interface *interface);
+
+const struct GNUNET_DBUS_InterfaceIterator *
+GNUNET_DBUS_object_iterate_interfaces (
+    struct GNUNET_DBUS_Object *object);
+
+#endif
+

Deleted: gnunet-dbus/src/lib/gnunet_dbus_lib_pop.c
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_pop.c   2014-02-14 10:35:11 UTC (rev 
32344)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_pop.c   2014-02-14 11:08:46 UTC (rev 
32345)
@@ -1,362 +0,0 @@
-#include <dbus/dbus.h>
-
-#include <gnunet/platform.h>
-#include <gnunet/gnunet_common.h>
-#include <gnunet/gnunet_strings_lib.h>
-
-#include "gnunet_dbus_lib.h"
-#include "gnunet_xstring_lib.h"
-
-#include "dbus_type_to_string.h"
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_basic (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    int expected_type,
-    void *value)
-{
-  int arg_type = dbus_message_iter_get_arg_type (iter);
-  if (expected_type != arg_type)
-  {
-    return dbus_message_new_error_printf (
-        message,
-        DBUS_ERROR_INVALID_ARGS,
-        "Bad argument for '%s'. Expected %s. Got %s",
-          arg_name,
-          dbus_type_to_string (expected_type),
-          dbus_type_to_string (arg_type));
-  };
-  dbus_message_iter_get_basic (iter, value);
-  dbus_message_iter_next (iter);
-
-  return NULL;
-};
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_string (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    const char **value)
-{
-  return GNUNET_DBUS_message_iter_pop_basic (
-      message,
-      iter,
-      arg_name,
-      DBUS_TYPE_STRING,
-      (void *)value);
-};
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_uint32 (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    dbus_uint32_t *value)
-{
-  return GNUNET_DBUS_message_iter_pop_basic (
-      message,
-      iter,
-      arg_name,
-      DBUS_TYPE_UINT32,
-      (void *)value);
-};
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_bool (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    dbus_bool_t *value)
-{
-  return GNUNET_DBUS_message_iter_pop_basic (
-      message,
-      iter,
-      arg_name,
-      DBUS_TYPE_BOOLEAN,
-      (void *)value);
-};
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_fixed_array (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    int expected_type,
-    void *value,
-    int *n_elements)
-{
-  int arg_type = dbus_message_iter_get_arg_type (iter);
-  if (DBUS_TYPE_ARRAY != arg_type)
-  {
-    return dbus_message_new_error_printf (
-        message,
-        DBUS_ERROR_INVALID_ARGS,
-        "Bad argument for '%s'. Expected %s. Got %s",
-          arg_name,
-          dbus_message_type_to_string (DBUS_TYPE_ARRAY),
-          dbus_message_type_to_string (arg_type));
-  };
-
-  int element_type = dbus_message_iter_get_element_type (iter);
-  if (expected_type != element_type)
-  {
-    return dbus_message_new_error_printf (
-        message,
-        DBUS_ERROR_INVALID_ARGS,
-        "Bad argument for '%s'. Expected array of %s. Got array of %s",
-          arg_name,
-          dbus_message_type_to_string (expected_type),
-          dbus_message_type_to_string (element_type));
-  };
-
-  DBusMessageIter itersub;
-  dbus_message_iter_recurse (iter, &itersub);
-  dbus_message_iter_get_fixed_array (&itersub, value, n_elements);
-
-  return NULL;
-};
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_array_byte (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    const char **value,
-    int *n_elements)
-{
-  return GNUNET_DBUS_message_iter_pop_fixed_array (
-      message,
-      iter,
-      arg_name,
-      DBUS_TYPE_BYTE,
-      (void *)value,
-      n_elements);
-};
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_array_string (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    const char ***value,
-    int *n_elements)
-{
-  return GNUNET_DBUS_message_iter_pop_fixed_array (
-      message,
-      iter,
-      arg_name,
-      DBUS_TYPE_STRING,
-      (void *)value,
-      n_elements);
-};
-
-/*
- * bitfield enums can be sent across the wire in either their integer form (as
- * an array of bit flags) or as an array of strings. Sending an int is more
- * efficient and is what libraries built around the DBus API would use, people
- * using the DBus API directly may want to pass human-readable strings for
- * convenience.
- */
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_bitfield (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    int *value,
-    const struct GNUNET_DBUS_StringEnumPair *fields)
-{
-  uint32_t flags;
-  DBusMessage *ret = GNUNET_DBUS_message_iter_pop_uint32 (message, iter, 
arg_name, &flags);
-  if (! ret)
-  {
-    *value = (int)flags;
-    return NULL;
-  };
-  dbus_message_unref (ret);
-
-  const char **options;
-  int num_options;
-  ret = GNUNET_DBUS_message_iter_pop_array_string (message, iter, arg_name, 
&options, &num_options);
-  if (! ret)
-  {
-    *value = 0;
-    int i;
-    for (i = 0; i < num_options; i++)
-    {
-      int j;
-      for (j = 0; fields[j].name; j++)
-      {
-        if (! strcmp (options[i], fields[j].name))
-        {
-          *value |= fields[j].value;
-          break;
-        };
-      };
-      if (! fields[j].name)
-      {
-        size_t size = GNUNET_XSTRING_NEW_DEFAULT_SIZE;
-        char *errmsg = GNUNET_XSTRING_new ();
-        GNUNET_XSTRING_appendf (&errmsg, &size, "Unrecognized option '%s'. 
Valid options are: [", options[i]);
-        for (j = 0; fields[j].name; j++)
-          GNUNET_XSTRING_appendf (&errmsg, &size, "%s'%s'", j ? ", " : "", 
fields[j].name);
-        GNUNET_XSTRING_append (&errmsg, &size, "].");
-        ret = dbus_message_new_error_printf (
-            message,
-            DBUS_ERROR_INVALID_ARGS,
-            "%s",
-              errmsg);
-        GNUNET_free (errmsg);
-        return ret;
-      };
-    };
-
-    return NULL;
-  };
-  dbus_message_unref (ret);
-
-  return dbus_message_new_error_printf (
-      message,
-      DBUS_ERROR_INVALID_ARGS,
-      "Bad argument for '%s'. Expected either a bitfield uint32 or an array of 
string options.",
-        arg_name);
-};
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_enum (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    int *value,
-    const struct GNUNET_DBUS_StringEnumPair *names)
-{
-  uint32_t v;
-  DBusMessage *ret = GNUNET_DBUS_message_iter_pop_uint32 (message, iter, 
arg_name, &v);
-  if (! ret)
-  {
-    *value = (int)v;
-    return NULL;
-  };
-  dbus_message_unref (ret);
-
-  const char *name;
-  ret = GNUNET_DBUS_message_iter_pop_string (message, iter, arg_name, &name);
-  if (! ret)
-  {
-    int i;
-    for (i = 0; names[i].name; i++)
-    {
-      if (! strcmp (name, names[i].name))
-      {
-        *value = names[i].value;
-        break;
-      };
-    };
-    if (! names[i].name)
-    {
-      size_t size = GNUNET_XSTRING_NEW_DEFAULT_SIZE;
-      char *errmsg = GNUNET_XSTRING_new ();
-      GNUNET_XSTRING_appendf (&errmsg, &size, "Unrecognized option '%s'. Valid 
options are: [", name);
-      for (i = 0; names[i].name; i++)
-        GNUNET_XSTRING_appendf (&errmsg, &size, "%s'%s'", i ? ", " : "", 
names[i].name);
-      GNUNET_XSTRING_append (&errmsg, &size, "].");
-      ret = dbus_message_new_error_printf (
-          message,
-          DBUS_ERROR_INVALID_ARGS,
-          "%s",
-            errmsg);
-      GNUNET_free (errmsg);
-      return ret;
-    };
-    return NULL;
-  };
-  dbus_message_unref (ret);
-  
-  return dbus_message_new_error_printf (
-      message,
-      DBUS_ERROR_INVALID_ARGS,
-      "Bad argument for '%s'. Expected either a uint32 or a string option",
-        arg_name);
-};
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_hashcode (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    struct GNUNET_HashCode *hc)
-{
-  const char *hc_in;
-  DBusMessage *ret = GNUNET_DBUS_message_iter_pop_string (message, iter, 
arg_name, &hc_in);
-  if (ret)
-    return ret;
-
-  int err = GNUNET_CRYPTO_hash_from_string2 (hc_in, strlen(hc_in), hc);
-  if (GNUNET_OK != err)
-  {
-    return dbus_message_new_error_printf (
-        message,
-        DBUS_ERROR_INVALID_ARGS,
-        "Bad argument for '%s'. Malformed hash string. 
GNUNET_CRYPTO_hash_from_string2 returned %d",
-          arg_name,
-          err);
-  };
-
-  return NULL;
-};
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_socket (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    struct GNUNET_NETWORK_Handle **socket_handle)
-{
-  const char *address;
-
-  DBusMessage *ret = GNUNET_DBUS_message_iter_pop_string (message, iter, 
arg_name, &address);
-  if (ret)
-    return ret;
-
-  *socket_handle = GNUNET_DBUS_create_socket_from_dbus_address (address);
-  if (! *socket_handle)
-  {
-    return dbus_message_new_error_printf (
-        message,
-        DBUS_ERROR_INVALID_ARGS,
-        "Bad argument for '%s'. Malformed address",
-          arg_name);
-  };
-
-  return NULL;
-};
-
-DBusMessage *
-GNUNET_DBUS_message_iter_pop_absolute_time (
-    DBusMessage *message,
-    DBusMessageIter *iter,
-    const char *arg_name,
-    struct GNUNET_TIME_Absolute *value)
-{
-  const char *time;
-  DBusMessage *ret = GNUNET_DBUS_message_iter_pop_string (message, iter, 
arg_name, &time);
-  if (ret)
-    return ret;
-
-  int err = GNUNET_STRINGS_fancy_time_to_absolute (time, value);
-  if (GNUNET_OK != err)
-  {
-    return dbus_message_new_error_printf (
-        message,
-        DBUS_ERROR_INVALID_ARGS,
-        "Bad argument for '%s'. Malformed time string. 
GNUNET_STRINGS_fancy_time_to_absolute returned %d",
-          arg_name,
-          err);
-  };
-
-  return NULL;
-};
-
-

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_service.c
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_service.c                               
(rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_service.c       2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -0,0 +1,558 @@
+#include "config.h"
+
+#include <stdbool.h>
+#include <dbus/dbus.h>
+
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_scheduler_lib.h>
+#include <gnunet/gnunet_container_lib.h>
+
+#include "gnunet_dbus_lib_service.h"
+#include "gnunet_dbus_lib_object.h"
+#include "gnunet_dbus_lib_arg.h"
+#include "gnunet_dbus_lib_client.h"
+
+#include "watch.h"
+#include "timeout.h"
+
+#define LOG(kind, ...) GNUNET_log_from (kind, "dbus-service", __VA_ARGS__)
+
+struct GNUNET_DBUS_Service
+{
+  struct GNUNET_DBUS_ObjectIterator *objects_front;
+  struct GNUNET_DBUS_ObjectIterator *objects_back;
+
+  DBusConnection *dbus_connection;
+  const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+  char *gnunet_name;
+  char *well_known_name;
+
+  /*
+   * Linked list of watches
+   */
+  struct WatchIter *watches_front;
+  struct WatchIter *watches_back;
+
+  /*
+   * Linked list of timeouts
+   */
+  struct TimeoutIter *timeouts_front;
+  struct TimeoutIter *timeouts_back;
+
+  /*
+   * Linked list of clients
+   */
+  struct GNUNET_DBUS_ClientIterator *clients_front;
+  struct GNUNET_DBUS_ClientIterator *clients_back;
+
+  GNUNET_DBUS_ClientConnectsHandler client_connects;
+  GNUNET_DBUS_ClientDisconnectsHandler client_disconnects;
+};
+
+static dbus_int32_t service_slot_id ()
+{
+  static dbus_int32_t id = -1;
+  if (-1 == id)
+  {
+    dbus_bool_t succ = dbus_connection_allocate_data_slot (&id);
+    if (! succ || -1 == id)
+    {
+      LOG (GNUNET_ERROR_TYPE_ERROR, "dbus_connection_allocate_data_slot 
failed. id == %lld\n", (long long)id);
+      GNUNET_abort ();
+    };
+  };
+
+  return id;
+};
+
+/*
+ * Called by DBus when it has a new watch that it wants us to watch.
+ *
+ * @param watch The DBus watch, created and passed to us by DBus.
+ * @param data the GNUNET_DBUS_Service we passed to 
dbus_connection_set_watch_functions
+ * @return true on success, false on an unrecoverable error.
+ */
+static dbus_bool_t
+watch_add (
+    DBusWatch *watch,
+    void *data)
+{
+  struct GNUNET_DBUS_Service *service = (struct GNUNET_DBUS_Service *)data;
+  struct Watch *w = watch_create (watch);
+
+  if (dbus_watch_get_enabled (watch))
+    watch_schedule (w);
+
+  struct WatchIter *wi = GNUNET_new (struct WatchIter);
+  wi->w = w;
+  GNUNET_CONTAINER_DLL_insert (service->watches_front,
+                               service->watches_back,
+                               wi);
+  watch_ref (w);
+  return true;
+};
+
+/*
+ * Called by DBus when it want to permanently disable and remove a watch
+ *
+ * @param watch The DBus watch, passed to us by DBus.
+ * @param data the GNUNET_DBUS_Service we passed to 
dbus_connection_set_watch_functions
+ */
+static void
+watch_remove (
+    DBusWatch *watch,
+    void *data)
+{
+  struct GNUNET_DBUS_Service *service = (struct GNUNET_DBUS_Service *)data;
+  struct WatchIter *wi = watch_find (service->watches_front, watch);
+
+  if (NULL == wi)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Asked to remove watch that has not been 
added\n");
+    GNUNET_abort ();
+  };
+
+  struct Watch *w = wi->w;
+  watch_unschedule (w);
+  GNUNET_CONTAINER_DLL_remove (service->watches_front,
+                               service->watches_back,
+                               wi);
+  watch_unref (w);
+};
+
+/*
+ * Called by DBus when it wants to enable or disable a watch.
+ * Schedules or unschedules the scheduler to monitor this watch as appropriate.
+ *
+ * @param watch The DBus watch, passed to us by DBus.
+ * @param data the GNUNET_DBUS_Service we passed to 
dbus_connection_set_watch_functions
+ */
+static void
+watch_toggle (
+    DBusWatch *watch,
+    void *data)
+{
+  struct GNUNET_DBUS_Service *service = (struct GNUNET_DBUS_Service *)data;
+  struct WatchIter *wi = watch_find (service->watches_front, watch);
+
+  if (NULL == wi)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Asked to toggle watch that has not been 
added\n");
+    GNUNET_abort ();
+  };
+
+  struct Watch *w = wi->w;
+  if (dbus_watch_get_enabled (watch))
+    watch_unschedule (w);
+  else
+    watch_schedule (w);
+};
+
+static dbus_bool_t
+timeout_add (
+    DBusTimeout *timeout,
+    void *data)
+{
+  struct GNUNET_DBUS_Service *service = (struct GNUNET_DBUS_Service *)data;
+  struct Timeout *t = timeout_create (timeout);
+  
+  if (dbus_timeout_get_enabled (timeout))
+    timeout_schedule (t);
+  
+  struct TimeoutIter *ti = GNUNET_new (struct TimeoutIter);
+  ti->t = t;
+  GNUNET_CONTAINER_DLL_insert (service->timeouts_front,
+                               service->timeouts_back,
+                               ti);
+  timeout_ref (t);
+  return true;
+};
+
+static void
+timeout_remove (
+    DBusTimeout *timeout,
+    void *data)
+{
+  struct GNUNET_DBUS_Service *service = (struct GNUNET_DBUS_Service *)data;
+  struct TimeoutIter *ti = timeout_find (service->timeouts_front, timeout);
+
+  if (NULL == ti)
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING, "Asked to remove timeout that has not been 
added\n");
+    return;
+  };
+
+  struct Timeout *t = ti->t;
+  timeout_unschedule (t);
+  GNUNET_CONTAINER_DLL_remove (service->timeouts_front,
+                               service->timeouts_back,
+                               ti);
+  timeout_unref (t);
+};
+
+static void
+timeout_toggle (
+    DBusTimeout *timeout,
+    void *data)
+{
+  struct GNUNET_DBUS_Service *service = (struct GNUNET_DBUS_Service *)data;
+  struct TimeoutIter *ti = timeout_find (service->timeouts_front, timeout);
+
+  if (NULL == ti)
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING, "asked to toggle timeout that has not been 
added\n");
+    return;
+  };
+
+  struct Timeout *t = ti->t;
+  if (dbus_timeout_get_enabled (timeout))
+    timeout_unschedule (t);
+  else
+    timeout_schedule (t);
+};
+
+static void
+dispatch (
+    void *cls,
+    const struct GNUNET_SCHEDULER_TaskContext *tc);
+
+static void
+handle_dispatch (
+    DBusConnection *dbus_connection,
+    DBusDispatchStatus status)
+{
+  switch (status)
+  {
+  case DBUS_DISPATCH_DATA_REMAINS:
+    GNUNET_SCHEDULER_add_continuation (
+        dispatch,
+        dbus_connection,
+        GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+    break;
+  case DBUS_DISPATCH_COMPLETE:
+    break;
+  case DBUS_DISPATCH_NEED_MEMORY:
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Out of memory!\n");
+    GNUNET_abort ();
+    break;
+  default:
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Unrecognized dispatch status\n");
+    break;
+  };
+};
+
+static void
+dispatch (
+    void *cls,
+    const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct DBusConnection *dbus_connection = (struct DBusConnection *)cls;
+  dbus_connection_dispatch (dbus_connection);
+  handle_dispatch (dbus_connection, dbus_connection_get_dispatch_status 
(dbus_connection));
+};
+
+static void
+dispatch_status_changed (
+    DBusConnection *dbus_connection,
+    DBusDispatchStatus new_status,
+    void *data)
+{
+  (void)data;
+  handle_dispatch (dbus_connection, new_status);
+};
+
+struct GNUNET_DBUS_Service *
+GNUNET_DBUS_service_create (
+    const struct GNUNET_CONFIGURATION_Handle *cfg,
+    const char *name)
+{
+  struct GNUNET_DBUS_Service *service = GNUNET_new (struct 
GNUNET_DBUS_Service);
+  service->cfg = cfg;
+  service->gnunet_name = GNUNET_strdup (name);
+  service->watches_front = NULL;
+  service->watches_back = NULL;
+  service->timeouts_front = NULL;
+  service->timeouts_back = NULL;
+  service->objects_front = NULL;
+  service->objects_back = NULL;
+  service->client_connects = NULL;
+  service->client_disconnects = NULL;
+
+  DBusError err;
+  dbus_error_init(&err);
+    
+  service->dbus_connection = dbus_bus_get_private (DBUS_BUS_SYSTEM, &err);
+  if (! service->dbus_connection)
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to connect to dbus system bus 
(%s)\n", dbus_error_is_set (&err) ? err.message : "dbus_bus_get_private 
returned NULL");
+  else
+  {
+    dbus_connection_set_exit_on_disconnect (service->dbus_connection,
+                                            false);
+    dbus_bool_t succ = dbus_connection_set_data (service->dbus_connection,
+                                                 service_slot_id (),
+                                                 service,
+                                                 NULL);
+    if (! succ)
+    {
+      LOG (GNUNET_ERROR_TYPE_ERROR, "dbus_connection_set_data returned false. 
Out of memory.\n");
+      GNUNET_abort ();
+    };
+
+    succ = dbus_connection_set_watch_functions (service->dbus_connection, 
watch_add, watch_remove, watch_toggle, service, NULL);
+    if(! succ)
+    {
+      LOG (GNUNET_ERROR_TYPE_ERROR, "dbus_connection_set_watch_functions 
returned false. Out of memory.\n");
+      GNUNET_abort ();
+    };
+
+    dbus_connection_set_dispatch_status_function (service->dbus_connection, 
dispatch_status_changed, service, NULL);
+    handle_dispatch (service->dbus_connection, 
dbus_connection_get_dispatch_status (service->dbus_connection));
+
+    succ = dbus_connection_set_timeout_functions (service->dbus_connection, 
timeout_add, timeout_remove, timeout_toggle, service, NULL);
+    if (! succ)
+    {
+      LOG (GNUNET_ERROR_TYPE_ERROR, "dbus_connection_set_timeout_functions 
returned false. Out of memory.\n");
+      GNUNET_abort ();
+    };
+
+    service->well_known_name = NULL;
+    GNUNET_asprintf (&service->well_known_name, "gnu.gnunet.%s", name);
+    int request_result = dbus_bus_request_name (service->dbus_connection, 
service->well_known_name, DBUS_NAME_FLAG_DO_NOT_QUEUE, &err);
+    if (dbus_error_is_set (&err))
+      LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to request the bus name (%s)\n", 
err.message);
+    else
+    {
+      switch(request_result)
+      {
+      case DBUS_REQUEST_NAME_REPLY_EXISTS:
+        LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to request the bus name \"%s\"; 
name is already taken.\n", service->well_known_name);
+        break;
+      default:
+        LOG (GNUNET_ERROR_TYPE_ERROR, "Unable to interpret result of 
dbus_request_name (%d)\n", request_result);
+        break;
+      case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
+
+        /* Success! */
+        return service;
+
+      }
+    }
+    dbus_connection_close (service->dbus_connection);
+    dbus_connection_unref (service->dbus_connection);
+  }
+  GNUNET_free (service->well_known_name);
+  GNUNET_free (service->gnunet_name);
+  GNUNET_free (service);
+  LOG (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DBUS_service create failed.\n");
+  return NULL;
+};
+
+void
+GNUNET_DBUS_service_destroy (
+    struct GNUNET_DBUS_Service *service)
+{
+  struct GNUNET_DBUS_ObjectIterator *objects_it = service->objects_front;
+  while (objects_it)
+  {
+    struct GNUNET_DBUS_ObjectIterator *next = objects_it->next;
+    GNUNET_DBUS_object_unref (objects_it->object);
+    GNUNET_free (objects_it);
+    objects_it = next;
+  };
+
+  GNUNET_free (service->well_known_name);
+  GNUNET_free (service->gnunet_name);
+  GNUNET_free (service);
+};
+
+const struct GNUNET_CONFIGURATION_Handle *
+GNUNET_DBUS_service_get_config (
+    struct GNUNET_DBUS_Service *service)
+{
+  return service->cfg;
+};
+
+/*
+ * Called whenever a message arrives from DBus
+ *
+ * @param conn The connection it arrived on.
+ * @param message The message
+ * @param cls The closure passed to dbus_connection_try_register_object_path
+ *            in our case this is the GNUNET_DBUS_Object that the message was
+ *            sent to.
+ *
+ * @return DBUS_HANDLER_RESULT_NEED_MEMORY if anything failed due to lack of
+ *         memory.
+ *         DBUS_HANDLER_RESULT_HANDLED if any method returned a reply.
+ *         DBUS_HANDLER_RESULT_NOT_YET_HANDLED otherwise.
+ */
+DBusHandlerResult
+handle_object_message (
+    DBusConnection *connection,
+    DBusMessage *dbus_message,
+    void *cls)
+{
+  struct GNUNET_DBUS_Object *object = (struct GNUNET_DBUS_Object *)cls;
+
+  const char *object_path    = dbus_message_get_path (dbus_message);
+  const char *type_string    = dbus_message_type_to_string 
(dbus_message_get_type (dbus_message));
+  const char *interface_name = dbus_message_get_interface (dbus_message);
+  const char *member_name    = dbus_message_get_member (dbus_message);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Recieved DBus message for %s\n", object_path);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "    type      == %s\n", type_string    ? 
type_string    : "(none)");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "    interface == %s\n", interface_name ? 
interface_name : "(none)");
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "    member    == %s\n", member_name    ? 
member_name    : "(none)");
+
+  struct GNUNET_DBUS_Service *service = dbus_connection_get_data (connection, 
service_slot_id ());
+
+  const char *unique_name = dbus_message_get_sender (dbus_message);
+  struct GNUNET_DBUS_ClientIterator *client_it = service->clients_front;
+  struct GNUNET_DBUS_Client *client = NULL;
+  for (; client_it; client_it = client_it->next)
+  {
+    client = client_it->client;
+    const char *this_unique_name = GNUNET_DBUS_client_get_unique_name (client);
+    if (! strcmp (unique_name, this_unique_name))
+      break;
+  };
+  if (! client_it)
+  {
+    client = GNUNET_DBUS_client_create (unique_name);
+    client_it = GNUNET_new (struct GNUNET_DBUS_ClientIterator);
+    client_it->client = client;
+    GNUNET_CONTAINER_DLL_insert (service->clients_front,
+                                 service->clients_back,
+                                 client_it);
+    if (service->client_connects)
+      service->client_connects (service, client);
+    /*  
+     
+        ** TODO **
+
+        detect when a client is no longer on the bus and
+        destroy the client object. At the moment this will slowly
+        leak memory as clients come and go.
+
+    */
+  };
+
+  if (! member_name)
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+  if (! interface_name)
+    interface_name = service->well_known_name;
+
+  int dbus_message_type = dbus_message_get_type (dbus_message);
+  if (dbus_message_type != DBUS_MESSAGE_TYPE_METHOD_CALL)
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+  const struct GNUNET_DBUS_InterfaceIterator *int_it = \
+      GNUNET_DBUS_interface_find ( \
+          GNUNET_DBUS_object_iterate_interfaces (object),
+          interface_name);
+  if (! int_it)
+  {
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "No such interface: %s\n", interface_name);
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+  };
+  struct GNUNET_DBUS_Interface *interface = int_it->interface;
+
+  const struct GNUNET_DBUS_MethodIterator *meth_it = \
+      GNUNET_DBUS_method_find ( \
+          GNUNET_DBUS_interface_iterate_methods (interface),
+          member_name);
+  if (! meth_it)
+  {
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "No such method: %s\n", member_name);
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+  };
+  struct GNUNET_DBUS_Method *method = meth_it->method;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Found method.\n");
+
+  struct GNUNET_DBUS_MethodContext *mc = GNUNET_DBUS_method_context_create (
+    client,
+    service,
+    object,
+    interface,
+    method,
+    dbus_message
+  );
+  GNUNET_DBUS_method_context_ref (mc);
+  GNUNET_DBUS_method_call (method, mc);
+  GNUNET_DBUS_method_context_unref (mc);
+  return DBUS_HANDLER_RESULT_HANDLED;
+};
+
+int
+GNUNET_DBUS_service_add_object (
+    struct GNUNET_DBUS_Service *service,
+    struct GNUNET_DBUS_Object *object)
+{
+  DBusError err;
+  dbus_error_init(&err);
+    
+  const char *path = GNUNET_DBUS_object_get_path (object);
+
+  DBusObjectPathVTable vtable;
+  vtable.message_function = handle_object_message;
+  vtable.unregister_function = NULL;
+  dbus_bool_t succ = dbus_connection_try_register_object_path (
+      service->dbus_connection,
+      path,
+      &vtable,
+      object,
+      &err);
+  if (dbus_error_is_set (&err))
+  {
+    LOG (
+        GNUNET_ERROR_TYPE_ERROR,
+        "dbus_connection_try_register failed to register path \"%s\": %s\n",
+          path,
+          err.message);
+    return GNUNET_SYSERR;
+  };
+  if (! succ)
+  {
+    LOG (
+        GNUNET_ERROR_TYPE_ERROR,
+        "dbus_connection_try_register returned false when registering path 
\"%s\"\n",
+          path);
+    return GNUNET_SYSERR;
+  };
+
+  struct GNUNET_DBUS_ObjectIterator *object_it = GNUNET_new (struct 
GNUNET_DBUS_ObjectIterator);
+  object_it->object = object;
+  GNUNET_DBUS_object_ref (object);
+  GNUNET_CONTAINER_DLL_insert (service->objects_front,
+                               service->objects_back,
+                               object_it);
+
+  return GNUNET_OK;
+};
+
+void
+GNUNET_DBUS_service_send (
+    struct GNUNET_DBUS_Service *service,
+    DBusMessage *dbus_message)
+{
+  dbus_bool_t succ = dbus_connection_send (service->dbus_connection, 
dbus_message, NULL);
+  if (! succ)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "dbus_connection_send failed. Out of 
memory.\n");
+    GNUNET_abort ();
+  };
+};
+
+void
+GNUNET_DBUS_service_set_client_handlers (
+    struct GNUNET_DBUS_Service *service,
+    GNUNET_DBUS_ClientConnectsHandler client_connects,
+    GNUNET_DBUS_ClientDisconnectsHandler client_disconnects)
+{
+  service->client_connects = client_connects;
+  service->client_disconnects = client_disconnects;
+};
+

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_service.h
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_service.h                               
(rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_service.h       2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -0,0 +1,51 @@
+#ifndef GNUNET_DBUS_LIB_SERVICE_H
+#define GNUNET_DBUS_LIB_SERVICE_H
+
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_configuration_lib.h>
+
+struct GNUNET_DBUS_Service;
+
+#include "gnunet_dbus_lib_object.h"
+#include "gnunet_dbus_lib_client.h"
+
+typedef void (*GNUNET_DBUS_ClientConnectsHandler)(
+    struct GNUNET_DBUS_Service *service,
+    struct GNUNET_DBUS_Client *client);
+typedef void (*GNUNET_DBUS_ClientDisconnectsHandler)(
+    struct GNUNET_DBUS_Service *service,
+    struct GNUNET_DBUS_Client *client);
+
+struct GNUNET_DBUS_Service *
+GNUNET_DBUS_service_create (
+    const struct GNUNET_CONFIGURATION_Handle *cfg,
+    const char *name);
+
+void
+GNUNET_DBUS_service_destroy (
+    struct GNUNET_DBUS_Service *service);
+
+const struct GNUNET_CONFIGURATION_Handle *
+GNUNET_DBUS_service_get_config (
+    struct GNUNET_DBUS_Service *service);
+
+int
+GNUNET_DBUS_service_add_object (
+    struct GNUNET_DBUS_Service *service,
+    struct GNUNET_DBUS_Object *object)
+  __attribute__((warn_unused_result));
+
+void
+GNUNET_DBUS_service_send (
+    struct GNUNET_DBUS_Service *service,
+    DBusMessage *dbus_message);
+
+void
+GNUNET_DBUS_service_set_client_handlers (
+    struct GNUNET_DBUS_Service *service,
+    GNUNET_DBUS_ClientConnectsHandler client_connects,
+    GNUNET_DBUS_ClientDisconnectsHandler client_disconnects);
+
+#endif
+

Copied: gnunet-dbus/src/lib/gnunet_dbus_lib_signature.c (from rev 31728, 
gnunet-dbus/src/lib/dbus_type_to_string.c)
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_signature.c                             
(rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_signature.c     2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -0,0 +1,60 @@
+#include "config.h"
+
+#include "gnunet_dbus_lib_signature.h"
+
+const char *
+GNUNET_DBUS_signature_typecode_to_string (
+    int typecode)
+{
+  switch (typecode)
+    {
+    case DBUS_TYPE_INVALID:
+      return "invalid";
+    case DBUS_TYPE_BOOLEAN:
+      return "boolean";
+    case DBUS_TYPE_BYTE:
+      return "byte";
+    case DBUS_TYPE_INT16:
+      return "int16";
+    case DBUS_TYPE_UINT16:
+      return "uint16";
+    case DBUS_TYPE_INT32:
+      return "int32";
+    case DBUS_TYPE_UINT32:
+      return "uint32";
+    case DBUS_TYPE_INT64:
+      return "int64";
+    case DBUS_TYPE_UINT64:
+      return "uint64";      
+    case DBUS_TYPE_DOUBLE:
+      return "double";
+    case DBUS_TYPE_STRING:
+      return "string";
+    case DBUS_TYPE_OBJECT_PATH:
+      return "object_path";
+    case DBUS_TYPE_SIGNATURE:
+      return "signature";
+    case DBUS_TYPE_STRUCT:
+      return "struct";
+    case DBUS_TYPE_DICT_ENTRY:
+      return "dict_entry";
+    case DBUS_TYPE_ARRAY:
+      return "array";
+    case DBUS_TYPE_VARIANT:
+      return "variant";
+    case DBUS_STRUCT_BEGIN_CHAR:
+      return "begin_struct";
+    case DBUS_STRUCT_END_CHAR:
+      return "end_struct";
+    case DBUS_DICT_ENTRY_BEGIN_CHAR:
+      return "begin_dict_entry";
+    case DBUS_DICT_ENTRY_END_CHAR:
+      return "end_dict_entry";
+    case DBUS_TYPE_UNIX_FD:
+      return "unix_fd";
+    default:
+      return "unknown";
+    }
+}
+
+  

Added: gnunet-dbus/src/lib/gnunet_dbus_lib_signature.h
===================================================================
--- gnunet-dbus/src/lib/gnunet_dbus_lib_signature.h                             
(rev 0)
+++ gnunet-dbus/src/lib/gnunet_dbus_lib_signature.h     2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -0,0 +1,62 @@
+#ifndef GNUNET_DBUS_LIB_SIGNATURE_H
+#define GNUNET_DBUS_LIB_SIGNATURE_H
+
+#include <dbus/dbus.h>
+
+#define GNUNET_DBUS_SIGNATURE_BYTE        DBUS_TYPE_BYTE_AS_STRING
+#define GNUNET_DBUS_SIGNATURE_BOOLEAN     DBUS_TYPE_BOOLEAN_AS_STRING
+#define GNUNET_DBUS_SIGNATURE_INT16       DBUS_TYPE_INT16_AS_STRING
+#define GNUNET_DBUS_SIGNATURE_UINT16      DBUS_TYPE_UINT16_AS_STRING
+#define GNUNET_DBUS_SIGNATURE_INT32       DBUS_TYPE_INT32_AS_STRING
+#define GNUNET_DBUS_SIGNATURE_UINT32      DBUS_TYPE_UINT32_AS_STRING
+#define GNUNET_DBUS_SIGNATURE_INT64       DBUS_TYPE_INT64_AS_STRING
+#define GNUNET_DBUS_SIGNATURE_UINT64      DBUS_TYPE_UINT64_AS_STRING
+#define GNUNET_DBUS_SIGNATURE_DOUBLE      DBUS_TYPE_DOUBLE_AS_STRING
+#define GNUNET_DBUS_SIGNATURE_STRING      DBUS_TYPE_STRING_AS_STRING
+#define GNUNET_DBUS_SIGNATURE_OBJECT_PATH DBUS_TYPE_OBJECT_PATH_AS_STRING
+#define GNUNET_DBUS_SIGNATURE_SIGNATURE   DBUS_TYPE_SIGNATURE_AS_STRING
+#define GNUNET_DBUS_SIGNATURE_UNIX_FD     DBUS_TYPE_UNIX_FD_AS_STRING
+#define GNUNET_DBUS_SIGNATURE_VARIANT     DBUS_TYPE_VARIANT_AS_STRING
+
+#define GNUNET_DBUS_SIGNATURE_ARRAY(s)    DBUS_TYPE_ARRAY_AS_STRING s
+#define GNUNET_DBUS_SIGNATURE_DICT(s)     DBUS_TYPE_ARRAY_AS_STRING 
DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING s DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+#define GNUNET_DBUS_SIGNATURE_STRUCT(s)   DBUS_STRUCT_BEGIN_CHAR_AS_STRING s 
DBUS_STRUCT_END_CHAR_AS_STRING
+
+#define GNUNET_DBUS_SIGNATURE_ABSOLUTE_TIME GNUNET_DBUS_SIGNATURE_VARIANT
+
+#define GNUNET_DBUS_SIGNATURE_GNSRECORD_DATA \
+    GNUNET_DBUS_SIGNATURE_STRUCT ( \
+        GNUNET_DBUS_SIGNATURE_ARRAY (GNUNET_DBUS_SIGNATURE_BYTE) \
+        GNUNET_DBUS_SIGNATURE_ABSOLUTE_TIME \
+        GNUNET_DBUS_SIGNATURE_UINT32 \
+        GNUNET_DBUS_SIGNATURE_UINT32 \
+    )
+
+#define GNUNET_DBUS_SIGNATURE_ECDSA_SIGNATURE \
+    GNUNET_DBUS_SIGNATURE_STRUCT ( \
+        GNUNET_DBUS_SIGNATURE_VARIANT \
+        GNUNET_DBUS_SIGNATURE_VARIANT \
+    )
+
+#define GNUNET_DBUS_SIGNATURE_ECC_SIGNATURE_PURPOSE \
+    GNUNET_DBUS_SIGNATURE_STRUCT ( \
+        GNUNET_DBUS_SIGNATURE_UINT32 \
+        GNUNET_DBUS_SIGNATURE_UINT32 \
+    )
+
+#define GNUNET_DBUS_SIGNATURE_GNSRECORD_BLOCK \
+    GNUNET_DBUS_SIGNATURE_STRUCT ( \
+        GNUNET_DBUS_SIGNATURE_ECDSA_SIGNATURE \
+        GNUNET_DBUS_SIGNATURE_ECDSA_PUBLIC_KEY \
+        GNUNET_DBUS_SIGNATURE_ECC_SIGNATURE_PURPOSE \
+        GNUNET_DBUS_SIGNATURE_ABSOLUTE_TIME \
+    ) 
+
+#define GNUNET_DBUS_SIGNATURE_ECDSA_PUBLIC_KEY GNUNET_DBUS_SIGNATURE_VARIANT
+
+const char *
+GNUNET_DBUS_signature_typecode_to_string (
+    int typecode);
+
+#endif
+

Deleted: gnunet-dbus/src/lib/gnunet_xstring_lib.c
===================================================================
--- gnunet-dbus/src/lib/gnunet_xstring_lib.c    2014-02-14 10:35:11 UTC (rev 
32344)
+++ gnunet-dbus/src/lib/gnunet_xstring_lib.c    2014-02-14 11:08:46 UTC (rev 
32345)
@@ -1,99 +0,0 @@
-#include <stdint.h>
-#include <stdarg.h>
-#include <stdbool.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/socket.h>
-
-#include <gnunet/gnunet_common.h>
-
-#include "gnunet_xstring_lib.h"
-
-char *
-GNUNET_XSTRING_new()
-{
-  char *ret = (char *)GNUNET_malloc(GNUNET_XSTRING_NEW_DEFAULT_SIZE);
-  ret[0] = '\0';
-  return ret;
-};
-
-int
-GNUNET_XSTRING_append ( \
-    char **dest,
-    size_t *dest_size,
-    const char *arg)
-{
-  size_t old_len, new_len, total_len;
-  size_t newsize;
-
-  old_len = strnlen(*dest, *dest_size);
-  new_len = strlen(arg);
-  total_len = old_len + new_len;
-  newsize = *dest_size;
-
-  if(newsize == 0)
-    newsize = GNUNET_XSTRING_NEW_DEFAULT_SIZE;
-
-  while( \
-         (total_len + 1 > newsize || newsize < 
GNUNET_XSTRING_NEW_DEFAULT_SIZE) \
-      && newsize != 0)
-    newsize *= 2;
-
-  if(newsize == 0)
-    return GNUNET_SYSERR;
-
-  if(newsize > *dest_size)
-  {
-    *dest_size = newsize;
-    *dest = GNUNET_realloc(*dest, *dest_size);
-    if(*dest == NULL)
-      return GNUNET_SYSERR;
-  };
-
-  memcpy(*dest + old_len, arg, new_len + 1);
-  return GNUNET_OK;
-};
-
-int __attribute__ ((format (printf, 3, 4)))
-GNUNET_XSTRING_appendf ( \
-    char **dest,
-    size_t *dest_size,
-    const char *fmt,
-    ...)
-{
-  size_t old_len;
-  va_list args;
-  
-  old_len = strnlen(*dest, *dest_size);
-  va_start(args, fmt);
-
-  while(true)
-  {
-    size_t remaining;
-    char *end;
-    int written;
-
-    remaining = *dest_size - old_len;
-    end = *dest + old_len;
-    written = vsnprintf(end, remaining, fmt, args);
-
-    if(written < 0)
-      return GNUNET_SYSERR;
-
-    if((size_t)written >= remaining)
-    {
-      *dest_size *= 2;
-      *dest = GNUNET_realloc(*dest, *dest_size);
-      if(*dest == NULL)
-        return GNUNET_SYSERR;
-      continue;
-    };
-    
-    break;
-  };
-  va_end(args);
-
-  return GNUNET_OK;
-};
-
-

Deleted: gnunet-dbus/src/lib/gnunet_xstring_lib.h
===================================================================
--- gnunet-dbus/src/lib/gnunet_xstring_lib.h    2014-02-14 10:35:11 UTC (rev 
32344)
+++ gnunet-dbus/src/lib/gnunet_xstring_lib.h    2014-02-14 11:08:46 UTC (rev 
32345)
@@ -1,26 +0,0 @@
-#ifndef GNUNET_XSTRING_LIB_H
-#define GNUNET_XSTRING_LIB_H
-
-#include <stdlib.h>
-#include <stddef.h>
-
-#define GNUNET_XSTRING_NEW_DEFAULT_SIZE 64
-
-char *
-GNUNET_XSTRING_new ();
-
-int
-GNUNET_XSTRING_append ( \
-    char **dest,
-    size_t *dest_size,
-    const char *arg);
-
-int __attribute__ ((format (printf, 3, 4)))
-GNUNET_XSTRING_appendf ( \
-    char **dest,
-    size_t *dest_size,
-    const char *fmt,
-    ...);
-
-#endif // GNUNET_XSTRING_LIB_H
-

Added: gnunet-dbus/src/lib/timeout.c
===================================================================
--- gnunet-dbus/src/lib/timeout.c                               (rev 0)
+++ gnunet-dbus/src/lib/timeout.c       2014-02-14 11:08:46 UTC (rev 32345)
@@ -0,0 +1,141 @@
+#include "timeout.h"
+
+#include <stdbool.h>
+
+#define LOG(kind, ...) GNUNET_log_from (kind, "dbus-timeout", __VA_ARGS__)
+
+struct Timeout
+{
+  /* doubly-linked list */
+  struct Timeout *next;
+  struct Timeout *prev;
+
+  DBusTimeout *timeout;
+
+  bool scheduled;
+
+  GNUNET_SCHEDULER_TaskIdentifier task;
+
+  unsigned ref_count;
+};
+
+struct Timeout *
+timeout_create (
+    DBusTimeout *timeout)
+{
+  struct Timeout *t = GNUNET_new (struct Timeout);
+
+  t->timeout = timeout;
+  t->scheduled = false;
+
+  return t;
+}
+
+void
+timeout_destroy (
+    struct Timeout *t)
+{
+  if (0 != t->ref_count)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Tried to destroy timeout with ref_count == 
%u\n", t->ref_count);
+    GNUNET_abort ();
+  };
+
+  GNUNET_free (t);
+}
+
+void
+timeout_ref (
+    struct Timeout *t)
+{
+  t->ref_count++;
+}
+
+void
+timeout_unref (
+    struct Timeout *t)
+{
+  if (0 == t->ref_count)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Tried to unref timeout with ref_count == 
0\n");
+    GNUNET_abort ();
+  };
+
+  if (0 == --t->ref_count)
+    timeout_destroy (t);
+}
+
+static void
+handle_timeout (
+    void *cls,
+    const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct Timeout *t = (struct Timeout *)cls;
+
+  t->scheduled = false;
+
+  if (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)
+    dbus_timeout_handle (t->timeout);
+
+  if (t->ref_count > 1 && ! (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+    timeout_schedule (t);
+  timeout_unref (t);
+};
+
+void
+timeout_schedule (
+    struct Timeout *t)
+{
+  if (! dbus_timeout_get_enabled (t->timeout))
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING, "Tried to schedule timeout that is 
disabled!\n");
+    return;
+  };
+
+  if (t->scheduled)
+    return;
+
+  int interval = dbus_timeout_get_interval (t->timeout);
+  struct GNUNET_TIME_Relative delay;
+  delay.rel_value_us = interval * 1000;
+  t->task = GNUNET_SCHEDULER_add_delayed (
+      delay,
+      handle_timeout,
+      t);
+  t->scheduled = true;
+  timeout_ref (t);
+}
+
+void
+do_timeout_unschedule (
+    void *cls,
+    const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  (void)tc;
+  struct Timeout *t = (struct Timeout *)cls;
+
+  if (! t->scheduled)
+    return;
+  
+  void *ret = GNUNET_SCHEDULER_cancel (t->task);
+  if ((struct Timeout *)ret != t)
+    LOG (GNUNET_ERROR_TYPE_WARNING, "Weird result unscheduling task. t == %p, 
GNUNET_SCHEDULER_cancel returned %p\n", t, ret);
+
+  timeout_unref (t);
+}
+
+void
+timeout_unschedule (
+    struct Timeout *t)
+{
+  GNUNET_SCHEDULER_add_now (do_timeout_unschedule, t);
+}
+
+struct TimeoutIter *
+timeout_find (struct TimeoutIter *ti, DBusTimeout *timeout)
+{
+  while (ti && ti->t->timeout != timeout)
+    ti = ti->next;
+  return ti;
+}
+

Added: gnunet-dbus/src/lib/timeout.h
===================================================================
--- gnunet-dbus/src/lib/timeout.h                               (rev 0)
+++ gnunet-dbus/src/lib/timeout.h       2014-02-14 11:08:46 UTC (rev 32345)
@@ -0,0 +1,32 @@
+#ifndef TIMEOUT_H
+#define TIMEOUT_H
+
+#include <dbus/dbus.h>
+
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_scheduler_lib.h>
+
+struct Timeout;
+
+struct TimeoutIter
+{
+  struct TimeoutIter *next;
+  struct TimeoutIter *prev;
+
+  struct Timeout *t;
+};
+
+struct Timeout *timeout_create (DBusTimeout *timeout);
+void timeout_destroy (struct Timeout *t);
+void timeout_ref (struct Timeout *t);
+void timeout_unref (struct Timeout *t);
+
+void timeout_schedule (struct Timeout *t);
+void timeout_unschedule (struct Timeout *t);
+void do_timeout_unschedule (void *cls, const struct 
GNUNET_SCHEDULER_TaskContext *tc);
+
+struct TimeoutIter *timeout_find (struct TimeoutIter *, DBusTimeout *timeout);
+
+#endif
+

Added: gnunet-dbus/src/lib/watch.c
===================================================================
--- gnunet-dbus/src/lib/watch.c                         (rev 0)
+++ gnunet-dbus/src/lib/watch.c 2014-02-14 11:08:46 UTC (rev 32345)
@@ -0,0 +1,245 @@
+#include "watch.h"
+
+#include <stdbool.h>
+
+#define LOG(kind, ...) GNUNET_log_from (kind, "dbus-watch", __VA_ARGS__)
+
+/*
+ * Wraps a file descriptor that needs to be watched 
+ * for activity with select()
+ */
+struct Watch
+{
+  /*
+   * DBus watch data. Contains the actual file descritor wrapped by libdbus
+   */
+  DBusWatch *watch;
+
+  /*
+   * Have we asked the scheduler to watch this?
+   * Will be false if the associated task has not been
+   * re-scheduled yet after execution or because dbus has asked
+   * us to disable this watch.
+   */
+  bool scheduled;
+
+  /*
+   * The task that is watching our file descriptor.
+   * Only valid if scheduled is true.
+   */
+  GNUNET_SCHEDULER_TaskIdentifier task;
+
+  struct GNUNET_NETWORK_Handle *net_handle;
+  struct GNUNET_DISK_FileHandle *file_handle;
+
+  unsigned ref_count;
+};
+
+struct Watch *
+watch_create (
+    DBusWatch *watch)
+{
+  struct Watch *w = GNUNET_new (struct Watch);
+
+  w->watch = watch;
+  w->scheduled = false;
+  w->net_handle = NULL;
+  w->file_handle = NULL;
+
+  SOCKTYPE sock = dbus_watch_get_socket (watch);
+  if (-1 != sock)
+  {
+    w->net_handle = GNUNET_NETWORK_socket_box_native (sock);
+    if (NULL == w->net_handle)
+    {
+      LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to box network socket passed in 
from dbus.\n");
+      GNUNET_abort ();
+    };
+  }
+  else {
+    int fd = dbus_watch_get_unix_fd (watch);
+    if (-1 != fd)
+    {
+      w->file_handle = GNUNET_DISK_get_handle_from_int_fd (fd);
+      if (NULL == w->file_handle)
+      {
+        LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to box file handle passed in 
from dbus.\n");
+        GNUNET_abort ();
+      };
+    };
+  };
+
+  if (! w->net_handle && ! w->file_handle)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to create watch. 
dbus_watch_get_socket returned %d\n", (int)sock);
+    GNUNET_abort ();
+  };
+
+  return w;
+};
+
+void
+watch_destroy (
+    struct Watch *w)
+{
+  if (0 != w->ref_count)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Tried to destroy watch with ref_count == 
%zu\n", w->ref_count);
+    GNUNET_abort ();
+  };
+
+  if (w->net_handle)
+    GNUNET_free (w->net_handle);
+  if (w->file_handle)
+    GNUNET_free (w->file_handle);
+
+  GNUNET_free (w);
+};
+
+void
+watch_ref (
+    struct Watch *w)
+{
+  w->ref_count++;
+};
+
+void
+watch_unref (
+    struct Watch *w)
+{
+  if (0 == w->ref_count)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, "Tried to unref watch with ref_count == 
0\n");
+    GNUNET_abort ();
+  };
+
+  if (0 == --w->ref_count)
+    watch_destroy (w);
+};
+
+/*
+ * Callback called by the scheduler to tell libdbus that there is activity on
+ * one of its file descriptors.
+ *
+ * @param cls The watch
+ * @param tc the context given to us by the scheduler for this execution
+ */
+void
+handle_watch (
+    void *cls,
+    const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct Watch *w = (struct Watch *)cls;
+
+  w->scheduled = false;
+
+  unsigned flags = 0;
+  if (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)
+    flags |= DBUS_WATCH_READABLE;
+  if (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)
+    flags |= DBUS_WATCH_WRITABLE;
+  if (flags)
+  {
+    dbus_watch_handle(w->watch, flags);
+  };
+
+  if(w->ref_count > 1 && ! (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+    watch_schedule (w);
+  watch_unref (w);
+};
+
+/*
+ * Ask the scheduler to watch this watch for activity.
+ *
+ * @param w The watch
+ * @return GNUNET_OK or GNUNET_SYSERR
+ */
+void
+watch_schedule (
+  struct Watch *w)
+{
+  unsigned flags = dbus_watch_get_flags (w->watch);
+
+  if (! dbus_watch_get_enabled (w->watch))
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING, "Tried to schedule watch that is 
disabled!\n");
+    return;
+  };
+
+  if (w->scheduled)
+    return;
+
+  if (w->net_handle)
+  {
+    w->task = GNUNET_SCHEDULER_add_net_with_priority(
+        GNUNET_TIME_UNIT_FOREVER_REL,
+        GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+        w->net_handle,
+        flags & DBUS_WATCH_READABLE,
+        flags & DBUS_WATCH_WRITABLE,
+        handle_watch,
+        w);
+    w->scheduled = true;
+    watch_ref (w);
+    return;
+  };
+
+  if (w->file_handle)
+  {
+    w->task = GNUNET_SCHEDULER_add_file_with_priority(
+        GNUNET_TIME_UNIT_FOREVER_REL,
+        GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+        w->file_handle,
+        flags & DBUS_WATCH_READABLE,
+        flags & DBUS_WATCH_WRITABLE,
+        handle_watch,
+        w);
+    w->scheduled = true;
+    watch_ref (w);
+    return;
+  };
+
+  LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to schedule watch.\n");
+  GNUNET_abort ();
+};
+
+/*
+ * Ask the scheduler to stop monitoring a watch either because we are shutting
+ * down or dbus has asked us to disable this watch.
+ *
+ * @param w The watch
+ * @return GNUNET_OK or GNUNET_SYSERR
+ */
+void
+do_watch_unschedule (
+    void *cls,
+    const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  (void)tc;
+  struct Watch *w = (struct Watch *)cls;
+
+  if (! w->scheduled)
+    return;
+
+  void *ret = GNUNET_SCHEDULER_cancel (w->task);
+  if ((struct Watch *)ret != w)
+    LOG (GNUNET_ERROR_TYPE_WARNING, "Weird result unscheduling task. w == %p, 
GNUNET_SCHEDULER_cancel returned %p\n", w, ret);
+
+  watch_unref (w);
+};
+
+void
+watch_unschedule (
+    struct Watch *w)
+{
+  GNUNET_SCHEDULER_add_now (do_watch_unschedule, w);
+};
+
+struct WatchIter *
+watch_find (struct WatchIter *wi, DBusWatch *watch)
+{
+  while (wi && wi->w->watch != watch)
+    wi = wi->next;
+  return wi;
+};
+

Added: gnunet-dbus/src/lib/watch.h
===================================================================
--- gnunet-dbus/src/lib/watch.h                         (rev 0)
+++ gnunet-dbus/src/lib/watch.h 2014-02-14 11:08:46 UTC (rev 32345)
@@ -0,0 +1,35 @@
+#ifndef WATCH_H
+#define WATCH_H
+
+#include <dbus/dbus.h>
+
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_scheduler_lib.h>
+
+struct Watch;
+
+struct WatchIter
+{
+  struct WatchIter *next;
+  struct WatchIter *prev;
+
+  struct Watch *w;
+};
+
+struct Watch *watch_create (DBusWatch *watch);
+void watch_destroy (struct Watch *w);
+void watch_ref (struct Watch *w);
+void watch_unref (struct Watch *w);
+
+/*
+ * Schedule or schedule the scheduler to monitor dbus file descriptors.
+ */
+void watch_schedule (struct Watch *w);
+void watch_unschedule (struct Watch *w);
+void do_watch_unschedule (void *cls, const struct GNUNET_SCHEDULER_TaskContext 
*tc);
+
+struct WatchIter *watch_find (struct WatchIter *, DBusWatch *watch);
+
+#endif
+

Copied: gnunet-dbus/src/services/Makefile.am (from rev 31728, 
gnunet-dbus/src/gns/Makefile.am)
===================================================================
--- gnunet-dbus/src/services/Makefile.am                                (rev 0)
+++ gnunet-dbus/src/services/Makefile.am        2014-02-14 11:08:46 UTC (rev 
32345)
@@ -0,0 +1,14 @@
+AM_CFLAGS = \
+       -I$(top_builddir)/src/lib
+
+bin_PROGRAMS = \
+       gnunet-service-gns-dbus
+
+gnunet_service_gns_dbus_SOURCES = \
+       gnunet-service-gns-dbus.c
+
+gnunet_service_gns_dbus_LDADD = \
+       $(top_builddir)/src/lib/libgnunetdbus.la \
+       -lgnunetgns \
+       -lgnunetutil
+

Added: gnunet-dbus/src/services/gnunet-service-gns-dbus.c
===================================================================
--- gnunet-dbus/src/services/gnunet-service-gns-dbus.c                          
(rev 0)
+++ gnunet-dbus/src/services/gnunet-service-gns-dbus.c  2014-02-14 11:08:46 UTC 
(rev 32345)
@@ -0,0 +1,196 @@
+#include "config.h"
+
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_configuration_lib.h>
+#include <gnunet/gnunet_getopt_lib.h>
+#include <gnunet/gnunet_strings_lib.h>
+#include <gnunet/gnunet_program_lib.h>
+#include <gnunet/gnunet_gns_service.h>
+
+#include "gnunet_dbus_lib.h"
+
+#define LOG(kind, ...) GNUNET_log_from (kind, "gns-dbus", __VA_ARGS__)
+
+static void
+lookup_return (
+    void *cls,
+    uint32_t rd_count,
+    const struct GNUNET_GNSRECORD_Data *rd)
+{
+  struct GNUNET_DBUS_MethodContext *mc = (struct GNUNET_DBUS_MethodContext 
*)cls;
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received reply from GNS. Method call id 
%u\n", dbus_message_get_serial (mc->message));
+  DBusMessage *message = mc->message;
+  DBusMessage *reply = dbus_message_new_method_return (message);
+  DBusMessageIter reply_iter;
+  dbus_message_iter_init_append (reply, &reply_iter);
+
+  DBusMessageIter reply_iter_sub;
+  GNUNET_DBUS_message_iter_push_open_array (mc, &reply_iter, &reply_iter_sub, 
GNUNET_DBUS_SIGNATURE_GNSRECORD_DATA);
+  uint32_t i;
+  for (i = 0; i < rd_count; i++)
+    GNUNET_DBUS_message_iter_push_gns_record (mc, &reply_iter_sub, rd + i);
+  GNUNET_DBUS_message_iter_push_close_container (mc, &reply_iter, 
&reply_iter_sub);
+
+  GNUNET_DBUS_method_context_send_reply (mc, reply);
+  GNUNET_DBUS_method_context_unref (mc);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Forwarded reply to dbus. Method call id 
%u\n", dbus_message_get_serial (mc->message));
+};
+
+#if 0
+static void
+lookup_timeout (
+    void *cls,
+    const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct GNUNET_GNS_LookupRequest *lr = (struct GNUNET_GNS_LookupRequest *)cls;
+  GNUNET_G
+}
+#endif
+
+static void
+lookup (
+    struct GNUNET_DBUS_MethodContext *mc)
+{
+  const char *name;
+  struct GNUNET_CRYPTO_EcdsaPublicKey zone;
+  uint32_t type;
+  dbus_bool_t only_cached;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received lookup request from dbus. Method 
call id %u\n", dbus_message_get_serial (mc->message));
+
+  DBusMessageIter message_iter;
+  dbus_message_iter_init (mc->message, &message_iter);
+
+  DBusMessage *reply = NULL;
+  reply = reply ? reply : GNUNET_DBUS_message_iter_pop_string (mc, 
&message_iter, "name", &name);
+  reply = reply ? reply : GNUNET_DBUS_message_iter_pop_ecdsa_public_key (mc, 
&message_iter, "zone", &zone);
+  reply = reply ? reply : GNUNET_DBUS_message_iter_pop_uint32 (mc, 
&message_iter, "type", &type);
+  reply = reply ? reply : GNUNET_DBUS_message_iter_pop_bool (mc, 
&message_iter, "only_cached", &only_cached);
+  if (reply)
+  {
+    GNUNET_DBUS_method_context_send_reply (mc, reply);
+    return;
+  };
+
+  GNUNET_DBUS_method_context_ref (mc);
+  struct GNUNET_GNS_Handle *handle = GNUNET_DBUS_client_get_data (mc->client);
+  struct GNUNET_GNS_LookupRequest *lr = GNUNET_GNS_lookup (
+      handle,
+      name, &zone, (int)type, (int)only_cached, NULL,
+      lookup_return, mc);
+  (void)lr;
+
+  //GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (500, 
GNUNET_TIME_UNIT_MILLISECONDS), 
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Forwarded lookup to GNS. Method call id 
%u\n", dbus_message_get_serial (mc->message));
+};
+
+static void
+client_connects (
+    struct GNUNET_DBUS_Service *service,
+    struct GNUNET_DBUS_Client *client)
+{
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating GNS client for %s\n", 
GNUNET_DBUS_client_get_unique_name (client));
+  const struct GNUNET_CONFIGURATION_Handle *cfg = 
GNUNET_DBUS_service_get_config (service);
+  struct GNUNET_GNS_Handle *handle = GNUNET_GNS_connect (cfg);
+  GNUNET_DBUS_client_set_data (client, handle);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished creating GNS client for %s\n", 
GNUNET_DBUS_client_get_unique_name (client));
+};
+
+static void
+client_disconnects (
+    struct GNUNET_DBUS_Service *service,
+    struct GNUNET_DBUS_Client *client)
+{
+  (void)service;
+  GNUNET_GNS_disconnect (GNUNET_DBUS_client_get_data (client));
+};
+
+static void
+shutdown_task (
+    void *cls,
+    const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  (void)tc;
+
+  struct GNUNET_DBUS_Service *gns_service = (struct GNUNET_DBUS_Service *)cls;
+  GNUNET_DBUS_service_destroy (gns_service);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Exiting.\n");
+};
+
+static void
+run (
+    void *cls,
+    char *const *args,
+    const char *configfile,
+    const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running.\n");
+
+  struct GNUNET_DBUS_Service *gns_service = GNUNET_DBUS_service_create (cfg, 
"gns");
+  GNUNET_DBUS_service_set_client_handlers (gns_service, client_connects, 
client_disconnects);
+
+  struct GNUNET_DBUS_Object *gns_object = GNUNET_DBUS_object_create ("/", 
NULL);
+  int err = GNUNET_DBUS_service_add_object (gns_service, gns_object);
+  if (GNUNET_OK != err)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to add / object. 
GNUNET_DBUS_service_add_object returned %d\n", err);
+    GNUNET_abort();
+  };
+
+  struct GNUNET_DBUS_Interface *gns_interface = GNUNET_DBUS_interface_create 
("gnu.gnunet.gns");
+  GNUNET_DBUS_object_add_interface (gns_object, 
GNUNET_DBUS_interface_introspectable ());
+  GNUNET_DBUS_object_add_interface (gns_object, gns_interface);
+
+  struct GNUNET_DBUS_Method *gns_method_lookup = GNUNET_DBUS_method_create 
("lookup", lookup);
+  GNUNET_DBUS_interface_add_method (gns_interface, gns_method_lookup);
+  GNUNET_DBUS_method_add_arg (gns_method_lookup, "name", 
GNUNET_DBUS_SIGNATURE_STRING);
+  GNUNET_DBUS_method_add_arg (gns_method_lookup, "zone", 
GNUNET_DBUS_SIGNATURE_ECDSA_PUBLIC_KEY);
+  GNUNET_DBUS_method_add_arg (gns_method_lookup, "type", 
GNUNET_DBUS_SIGNATURE_UINT32);
+  GNUNET_DBUS_method_add_arg (gns_method_lookup, "only_cached", 
GNUNET_DBUS_SIGNATURE_BOOLEAN);
+
+  GNUNET_DBUS_method_add_return_arg (gns_method_lookup, "records", 
GNUNET_DBUS_SIGNATURE_ARRAY (GNUNET_DBUS_SIGNATURE_GNSRECORD_DATA));
+
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, shutdown_task, 
gns_service);
+};
+
+int
+main (
+    int argc,
+    char *const *argv)
+{
+  int ret;
+
+  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_OPTION_END
+  };
+  static const char bin_name[] = "gnunet-service-gns-dbus [OPTIONS]";
+  static const char bin_help[] = gettext_noop ("DBus proxy for 
gnunet-service-gns");
+
+  ret = GNUNET_log_setup ("gnunet-service-gns-dbus", "DEBUG", NULL);
+  if (GNUNET_OK != ret)
+  {
+    fprintf (stderr, "ERROR: Failed to setup logging. GNUNET_log_setup 
returned %d\n", ret);
+    return 1;
+  }
+
+  ret = GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv);
+  if (GNUNET_OK != ret)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to parse command line 
options. GNUNET_STRINGS_get_utf8_args returned %d\n", ret);
+    return 1;
+  };
+
+  ret = GNUNET_PROGRAM_run (argc, argv, bin_name, bin_help, options, run, 
NULL);
+  if (GNUNET_OK != ret)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to run program. 
GNUNET_PROGRAM_run returned %d\n", ret);
+    return 1;
+  };
+
+  GNUNET_free ((void *)argv);
+  return 0;
+};
+
+

Added: gnunet-dbus/src/services/gnunet-service-namecache-dbus.c
===================================================================
--- gnunet-dbus/src/services/gnunet-service-namecache-dbus.c                    
        (rev 0)
+++ gnunet-dbus/src/services/gnunet-service-namecache-dbus.c    2014-02-14 
11:08:46 UTC (rev 32345)
@@ -0,0 +1,158 @@
+#include "config.h"
+
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_configuration_lib.h>
+#include <gnunet/gnunet_getopt_lib.h>
+#include <gnunet/gnunet_strings_lib.h>
+#include <gnunet/gnunet_program_lib.h>
+#include <gnunet/gnunet_namecache_service.h>
+
+#include "gnunet_dbus_lib.h"
+
+static void
+block_cache_return (
+    void *cls,
+    int32_t success,
+    const char *emsg)
+{
+  struct GNUNET_DBUS_MethodContext *mc = (struct GNUNET_DBUS_MethodContext 
*)cls;
+
+  DBusMessage *message = mc->message;
+  DBusMessage *reply = dbus_message_new_method_return (message);
+  DBusMessageIter reply_iter;
+  dbus_message_iter_init_append (reply, &reply_iter);
+  GNUNET_DBUS_message_iter_push_int32 (&reply_iter, success);
+  GNUNET_DBUS_message_iter_push_string (&reply_iter, emsg);
+
+  GNUNET_DBUS_method_context_send_reply (mc, reply);
+  GNUNET_DBUS_method_context_unref (mc);
+};
+
+static void
+block_cache (
+    struct GNUNET_DBUS_MethodContext *mc)
+{
+  struct GNUNET_GNSRECORD_Block block;
+
+  DBusMessage *dbus_message = mc->message;
+  DBusMessageIter iter;
+  dbus_message_iter_init (dbus_message, &iter);
+  DBusMessage *reply = GNUNET_DBUS_message_iter_pop_gnsrecord_block 
(dbus_message, &iter, "block", &block);
+  if (reply)
+  {
+    GNUNET_DBUS_method_context_send_reply (mc, reply);
+    return;
+  };
+
+  GNUNET_DBUS_method_context_ref (mc);
+  struct GNUNET_NAMECACHE_Handle *handle = GNUNET_DBUS_client_get_data 
(mc->client);
+  GNUNET_NAMECACHE_block_cache (handle, &block, block_cache_return, mc);
+};
+
+static void
+client_connects (
+    struct GNUNET_DBUS_Service *service,
+    struct GNUNET_DBUS_Client *client)
+{
+  const struct GNUNET_CONFIGURATION_Handle *cfg = 
GNUNET_DBUS_service_get_config (service);
+  struct GNUNET_NAMECACHE_Handle *handle = GNUNET_NAMECACHE_connect (cfg);
+  GNUNET_DBUS_client_set_data (client, handle);
+};
+
+static void
+client_disconnects (
+    struct GNUNET_DBUS_Service *service,
+    struct GNUNET_DBUS_Client *client)
+{
+  (void)service;
+  GNUNET_NAMECACHE_disconnect (GNUNET_DBUS_client_get_data (client));
+};
+
+static void
+shutdown_task (
+    void *cls,
+    const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  (void)tc;
+
+  struct GNUNET_DBUS_Service *gns_service = (struct GNUNET_DBUS_Service *)cls;
+  GNUNET_DBUS_service_destroy (gns_service);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Exiting.\n");
+};
+
+static void
+run (
+    void *cls,
+    char *const *args,
+    const char *configfile,
+    const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running.\n");
+
+  struct GNUNET_DBUS_Service *namecache_service = GNUNET_DBUS_service_create 
(cfg, "namecache");
+  GNUNET_DBUS_service_set_client_handlers (namecache_service, client_connects, 
client_disconnects);
+
+  struct GNUNET_DBUS_Object *namecache_object = GNUNET_DBUS_object_create 
("/namecache", NULL);
+  int err = GNUNET_DBUS_service_add_object (namecache_service, 
namecache_object);
+  if (GNUNET_OK != err)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to add /namecache object. 
GNUNET_DBUS_service_add_object returned %d\n", err);
+    GNUNET_abort ();
+  };
+
+  struct GNUNET_DBUS_Interface *namecache_interface = 
GNUNET_DBUS_interface_create ("gnu.gnunet.namecache");
+  GNUNET_DBUS_object_add_interface (namecache_object, 
GNUNET_DBUS_interface_introspectable ());
+  GNUNET_DBUS_object_add_interface (namecache_object, namecache_interface);
+  
+  struct GNUNET_DBUS_Method *namecache_method_block_cache = 
GNUNET_DBUS_method_create ("block_cache", block_cache);
+  GNUNET_DBUS_interface_add_method (namecache_interface, 
namecache_method_block_cache);
+  GNUNET_DBUS_method_add_arg (namecache_method_block_cache, "block", 
GNUNET_DBUS_SIGNATURE_GNSRECORD_BLOCK);
+
+  GNUNET_DBUS_method_add_return_arg (namecache_method_block_cache, "success", 
GNUNET_DBUS_SIGNATURE_INT32);
+  GNUNET_DBUS_method_add_return_arg (namecache_method_block_cache, 
"error_msg", GNUNET_DBUS_SIGNATURE_STRING);
+
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, shutdown_task, 
namecache_service);
+};
+
+int
+main (
+    int argc,
+    char *const *argv)
+{
+  int ret;
+
+  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_OPTION_END
+  };
+
+  static const char bin_name[] = "gnunet-service-namecache-dbus [OPTIONS]";
+  static const char bin_help[] = "DBus proxy for gnunet-service-namecache";
+
+  ret = GNUNET_log_setup ("gnunet-service-namecache-dbus", "DEBUG", NULL);
+  if (GNUNET_OK != ret)
+  {
+    fprintf (stderr, "ERROR: Failed to setup logging. GNUNET_log_setup 
returned %d\n", ret);
+    return 1;
+  };
+
+  ret = GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv);
+  if (GNUNET_OK != ret)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to parse command line 
options. GNUNET_STRINGS_get_utf8_args returned %d\n", ret);
+    return 1;
+  };
+
+  ret = GNUNET_PROGRAM_run (argc, argv, bin_name, bin_help, options, run, 
NULL);
+  if (GNUNET_OK != ret)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to run program. 
GNUNET_PROGRAM_run returned %d\n", ret);
+    return 1;
+  };
+
+  printf ("leaving main()\n");
+  GNUNET_free ((void *)argv);
+  return 0;
+}
+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]