gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r36351 - in gnunet/src: . gns identity namestore rest


From: gnunet
Subject: [GNUnet-SVN] r36351 - in gnunet/src: . gns identity namestore rest
Date: Fri, 11 Sep 2015 17:56:39 +0200

Author: schanzen
Date: 2015-09-11 17:56:39 +0200 (Fri, 11 Sep 2015)
New Revision: 36351

Added:
   gnunet/src/rest/plugin_rest_gns.c
   gnunet/src/rest/plugin_rest_identity.c
   gnunet/src/rest/plugin_rest_namestore.c
Removed:
   gnunet/src/gns/plugin_rest_gns.c
   gnunet/src/identity/plugin_rest_identity.c
   gnunet/src/namestore/plugin_rest_namestore.c
Modified:
   gnunet/src/Makefile.am
   gnunet/src/gns/Makefile.am
   gnunet/src/identity/Makefile.am
   gnunet/src/namestore/Makefile.am
   gnunet/src/rest/Makefile.am
   gnunet/src/rest/rest.c
Log:
- move rest plugins into rest directory where they belong


Modified: gnunet/src/Makefile.am
===================================================================
--- gnunet/src/Makefile.am      2015-09-10 15:39:36 UTC (rev 36350)
+++ gnunet/src/Makefile.am      2015-09-11 15:56:39 UTC (rev 36351)
@@ -65,7 +65,6 @@
   peerinfo \
   $(MYSQL_DIR) \
   $(POSTGRES_DIR) \
-  $(REST_DIR) \
   datacache \
   datastore \
   template \
@@ -99,6 +98,7 @@
   fs \
   exit \
   pt \
+  $(REST_DIR) \
   integration-tests \
   $(EXP_DIR)
 

Modified: gnunet/src/gns/Makefile.am
===================================================================
--- gnunet/src/gns/Makefile.am  2015-09-10 15:39:36 UTC (rev 36350)
+++ gnunet/src/gns/Makefile.am  2015-09-11 15:56:39 UTC (rev 36351)
@@ -85,28 +85,12 @@
 endif
 endif
 
-if HAVE_REST
-REST_PLUGIN = libgnunet_plugin_rest_gns.la
-endif
-
 bin_SCRIPTS = gnunet-gns-proxy-setup-ca
 
 plugin_LTLIBRARIES = \
   libgnunet_plugin_block_gns.la \
-  libgnunet_plugin_gnsrecord_gns.la \
-  $(REST_PLUGIN)
+  libgnunet_plugin_gnsrecord_gns.la
 
-libgnunet_plugin_rest_gns_la_SOURCES = \
-  plugin_rest_gns.c
-libgnunet_plugin_rest_gns_la_LIBADD = \
-  $(top_builddir)/src/gns/libgnunetgns.la \
-  $(top_builddir)/src/identity/libgnunetidentity.la \
-       $(top_builddir)/src/rest/libgnunetrest.la \
-  $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
-  $(LTLIBINTL) -ljansson -lmicrohttpd
-libgnunet_plugin_rest_gns_la_LDFLAGS = \
- $(GN_PLUGIN_LDFLAGS)
-
 libgnunet_plugin_gnsrecord_gns_la_SOURCES = \
   plugin_gnsrecord_gns.c
 libgnunet_plugin_gnsrecord_gns_la_LIBADD = \

Deleted: gnunet/src/gns/plugin_rest_gns.c
===================================================================
--- gnunet/src/gns/plugin_rest_gns.c    2015-09-10 15:39:36 UTC (rev 36350)
+++ gnunet/src/gns/plugin_rest_gns.c    2015-09-11 15:56:39 UTC (rev 36351)
@@ -1,720 +0,0 @@
-/*
-   This file is part of GNUnet.
-   Copyright (C) 2012-2015 Christian Grothoff (and other contributing authors)
-
-   GNUnet is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published
-   by the Free Software Foundation; either version 3, or (at your
-   option) any later version.
-
-   GNUnet is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNUnet; see the file COPYING.  If not, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.
-   */
-/**
- * @author Martin Schanzenbach
- * @file gns/plugin_rest_gns.c
- * @brief GNUnet GNS REST plugin
- *
- */
-
-#include "platform.h"
-#include "gnunet_rest_plugin.h"
-#include <gnunet_dnsparser_lib.h>
-#include <gnunet_identity_service.h>
-#include <gnunet_gnsrecord_lib.h>
-#include <gnunet_namestore_service.h>
-#include <gnunet_gns_service.h>
-#include <gnunet_rest_lib.h>
-#include <jansson.h>
-
-#define GNUNET_REST_API_NS_GNS "/gns"
-
-#define GNUNET_REST_JSONAPI_GNS_RECORD_TYPE "record_type"
-
-#define GNUNET_REST_JSONAPI_GNS_TYPEINFO "gns_name"
-
-#define GNUNET_REST_JSONAPI_GNS_RECORD "records"
-
-#define GNUNET_REST_JSONAPI_GNS_EGO "ego"
-
-#define GNUNET_REST_JSONAPI_GNS_PKEY "pkey"
-
-#define GNUNET_REST_JSONAPI_GNS_OPTIONS "options"
-
-/**
- * @brief struct returned by the initialization function of the plugin
- */
-struct Plugin
-{
-  const struct GNUNET_CONFIGURATION_Handle *cfg;
-};
-
-const struct GNUNET_CONFIGURATION_Handle *cfg;
-
-struct LookupHandle
-{
-  /**
-   * Handle to GNS service.
-   */
-  struct GNUNET_GNS_Handle *gns;
-
-  /**
-   * Desired timeout for the lookup (default is no timeout).
-   */
-  struct GNUNET_TIME_Relative timeout;
-
-  /**
-   * Handle to lookup request
-   */
-  struct GNUNET_GNS_LookupRequest *lookup_request;
-
-  /**
-   * Lookup an ego with the identity service.
-   */
-  struct GNUNET_IDENTITY_EgoLookup *el;
-
-  /**
-   * Handle for identity service.
-   */
-  struct GNUNET_IDENTITY_Handle *identity;
-
-  /**
-   * Active operation on identity service.
-   */
-  struct GNUNET_IDENTITY_Operation *id_op;
-
-  /**
-   * ID of a task associated with the resolution process.
-   */
-  struct GNUNET_SCHEDULER_Task * timeout_task;
-
-  /**
-   * The root of the received JSON or NULL
-   */
-  json_t *json_root;
-
-  /**
-   * The plugin result processor
-   */
-  GNUNET_REST_ResultProcessor proc;
-
-  /**
-   * The closure of the result processor
-   */
-  void *proc_cls;
-
-  /**
-   * The name to look up
-   */
-  char *name;
-
-  /**
-   * The ego to use
-   * In string representation from JSON
-   */
-  const char *ego_str;
-
-  /**
-   * The Pkey to use
-   * In string representation from JSON
-   */
-  const char *pkey_str;
-
-  /**
-   * The record type
-   */
-  int type;
-
-  /**
-   * The public key of to use for lookup
-   */
-  struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
-
-  /**
-   * The public key to use for lookup
-   */
-  struct GNUNET_CRYPTO_EcdsaPublicKey pkeym;
-
-  /**
-   * The resolver options
-   */
-  enum GNUNET_GNS_LocalOptions options;
-
-  /**
-   * the shorten key
-   */
-  struct GNUNET_CRYPTO_EcdsaPrivateKey shorten_key;
-
-};
-
-
-/**
- * Cleanup lookup handle.
- *
- * @param handle Handle to clean up
- */
-static void
-cleanup_handle (struct LookupHandle *handle)
-{
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Cleaning up\n");
-  if (NULL != handle->json_root)
-    json_decref (handle->json_root);
-
-  if (NULL != handle->name)
-    GNUNET_free (handle->name);
-  if (NULL != handle->el)
-  {
-    GNUNET_IDENTITY_ego_lookup_cancel (handle->el);
-    handle->el = NULL;
-  }
-  if (NULL != handle->id_op)
-  {
-    GNUNET_IDENTITY_cancel (handle->id_op);
-    handle->id_op = NULL;
-  }
-  if (NULL != handle->lookup_request)
-  {
-    GNUNET_GNS_lookup_cancel (handle->lookup_request);
-    handle->lookup_request = NULL;
-  }
-  if (NULL != handle->identity)
-  {
-    GNUNET_IDENTITY_disconnect (handle->identity);
-    handle->identity = NULL;
-  }
-  if (NULL != handle->gns)
-  {
-    GNUNET_GNS_disconnect (handle->gns);
-    handle->gns = NULL;
-  }
-
-  if (NULL != handle->timeout_task)
-  {
-    GNUNET_SCHEDULER_cancel (handle->timeout_task);
-  }
-  GNUNET_free (handle);
-}
-
-
-/**
- * Task run on shutdown.  Cleans up everything.
- *
- * @param cls unused
- * @param tc scheduler context
- */
-static void
-do_error (void *cls,
-          const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct LookupHandle *handle = cls;
-  struct MHD_Response *resp = GNUNET_REST_create_json_response (NULL);
-  handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
-  cleanup_handle (handle);
-}
-
-
-/**
- * Create json representation of a GNSRECORD
- *
- * @param rd the GNSRECORD_Data
- */
-static json_t *
-gnsrecord_to_json (const struct GNUNET_GNSRECORD_Data *rd)
-{
-  const char *typename;
-  char *string_val;
-  const char *exp_str;
-  json_t *record_obj;
-
-  typename = GNUNET_GNSRECORD_number_to_typename (rd->record_type);
-  string_val = GNUNET_GNSRECORD_value_to_string (rd->record_type,
-                                                 rd->data,
-                                                 rd->data_size);
-
-  if (NULL == string_val)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Record of type %d malformed, skipping\n",
-                (int) rd->record_type);
-    return NULL;
-  }
-  record_obj = json_object();
-  json_object_set_new (record_obj, "type", json_string (typename));
-  json_object_set_new (record_obj, "value", json_string (string_val));
-  GNUNET_free (string_val);
-
-  if (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION & rd->flags)
-  {
-    struct GNUNET_TIME_Relative time_rel;
-    time_rel.rel_value_us = rd->expiration_time;
-    exp_str = GNUNET_STRINGS_relative_time_to_string (time_rel, 1);
-  }
-  else
-  {
-    struct GNUNET_TIME_Absolute time_abs;
-    time_abs.abs_value_us = rd->expiration_time;
-    exp_str = GNUNET_STRINGS_absolute_time_to_string (time_abs);
-  }
-  json_object_set_new (record_obj, "expiration_time", json_string (exp_str));
-
-  json_object_set_new (record_obj, "expired",
-                       json_boolean (GNUNET_YES == GNUNET_GNSRECORD_is_expired 
(rd)));
-  return record_obj;
-}
-
-/**
- * Function called with the result of a GNS lookup.
- *
- * @param cls the 'const char *' name that was resolved
- * @param rd_count number of records returned
- * @param rd array of @a rd_count records with the results
- */
-static void
-process_lookup_result (void *cls, uint32_t rd_count,
-                       const struct GNUNET_GNSRECORD_Data *rd)
-{
-  struct LookupHandle *handle = cls;
-  struct MHD_Response *resp;
-  struct JsonApiObject *json_object;
-  struct JsonApiResource *json_resource;
-  uint32_t i;
-  char *result;
-  json_t *result_array;
-  json_t *record_obj;
-
-  result_array = json_array();
-  json_object = GNUNET_REST_jsonapi_object_new ();
-  json_resource = GNUNET_REST_jsonapi_resource_new 
(GNUNET_REST_JSONAPI_GNS_TYPEINFO, handle->name);
-  handle->lookup_request = NULL;
-  for (i=0; i<rd_count; i++)
-  {
-    if ( (rd[i].record_type != handle->type) &&
-         (GNUNET_GNSRECORD_TYPE_ANY != handle->type) )
-      continue;
-    record_obj = gnsrecord_to_json (&(rd[i]));
-    json_array_append (result_array, record_obj);
-    json_decref (record_obj);
-  }
-  GNUNET_REST_jsonapi_resource_add_attr (json_resource,
-                                         GNUNET_REST_JSONAPI_GNS_RECORD,
-                                         result_array);
-  GNUNET_REST_jsonapi_object_resource_add (json_object, json_resource);
-  GNUNET_REST_jsonapi_data_serialize (json_object, &result);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result);
-  json_decref (result_array);
-  GNUNET_REST_jsonapi_object_delete (json_object);
-  resp = GNUNET_REST_create_json_response (result);
-  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
-  GNUNET_free (result);
-  cleanup_handle (handle);
-}
-
-
-/**
- * Perform the actual resolution, starting with the zone
- * identified by the given public key and the shorten zone.
- *
- * @param pkey public key to use for the zone, can be NULL
- * @param shorten_key private key used for shortening, can be NULL
- */
-static void
-lookup_with_keys (struct LookupHandle *handle, const struct 
GNUNET_CRYPTO_EcdsaPrivateKey *shorten_key)
-{
-  if (UINT32_MAX == handle->type)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Invalid typename specified, assuming `ANY'\n"));
-    handle->type = GNUNET_GNSRECORD_TYPE_ANY;
-  }
-  if (NULL != handle->name)
-  {
-    handle->lookup_request = GNUNET_GNS_lookup (handle->gns,
-                                                handle->name,
-                                                &handle->pkey,
-                                                handle->type,
-                                                handle->options,
-                                                shorten_key,
-                                                &process_lookup_result,
-                                                handle);
-  }
-  else
-  {
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-}
-
-/**
- * Method called to with the ego we are to use for shortening
- * during the lookup.
- *
- * @param cls closure contains the public key to use
- * @param ego ego handle, NULL if not found
- * @param ctx context for application to store data for this ego
- *                 (during the lifetime of this process, initially NULL)
- * @param name name assigned by the user for this ego,
- *                   NULL if the user just deleted the ego and it
- *                   must thus no longer be used
- */
-static void
-identity_shorten_cb (void *cls,
-                     struct GNUNET_IDENTITY_Ego *ego,
-                     void **ctx,
-                     const char *name)
-{
-  struct LookupHandle *handle = cls;
-
-  handle->id_op = NULL;
-  if (NULL == ego)
-    lookup_with_keys (handle, NULL);
-  else
-    lookup_with_keys (handle,
-                      GNUNET_IDENTITY_ego_get_private_key (ego));
-}
-
-/**
- * Perform the actual resolution, starting with the zone
- * identified by the given public key.
- *
- * @param pkey public key to use for the zone
- */
-static void
-lookup_with_public_key (struct LookupHandle *handle)
-{
-  handle->pkeym = handle->pkey;
-  GNUNET_break (NULL == handle->id_op);
-  handle->id_op = GNUNET_IDENTITY_get (handle->identity,
-                                       "gns-short",
-                                       &identity_shorten_cb,
-                                       handle);
-  if (NULL == handle->id_op)
-  {
-    GNUNET_break (0);
-    lookup_with_keys (handle, NULL);
-  }
-}
-
-/**
- * Method called to with the ego we are to use for the lookup,
- * when the ego is determined by a name.
- *
- * @param cls closure (NULL, unused)
- * @param ego ego handle, NULL if not found
- */
-static void
-identity_zone_cb (void *cls,
-                  const struct GNUNET_IDENTITY_Ego *ego)
-{
-  struct LookupHandle *handle = cls;
-
-  handle->el = NULL;
-  if (NULL == ego)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Ego for not found, cannot perform lookup.\n"));
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  else
-  {
-    GNUNET_IDENTITY_ego_get_public_key (ego, &handle->pkey);
-    lookup_with_public_key (handle);
-  }
-  json_decref(handle->json_root);
-}
-
-/**
- * Method called to with the ego we are to use for the lookup,
- * when the ego is the one for the default master zone.
- *
- * @param cls closure (NULL, unused)
- * @param ego ego handle, NULL if not found
- * @param ctx context for application to store data for this ego
- *                 (during the lifetime of this process, initially NULL)
- * @param name name assigned by the user for this ego,
- *                   NULL if the user just deleted the ego and it
- *                   must thus no longer be used
- */
-static void
-identity_master_cb (void *cls,
-                    struct GNUNET_IDENTITY_Ego *ego,
-                    void **ctx,
-                    const char *name)
-{
-  const char *dot;
-  struct LookupHandle *handle = cls;
-
-  handle->id_op = NULL;
-  if (NULL == ego)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Ego for `gns-master' not found, cannot perform lookup.  Did 
you run gnunet-gns-import.sh?\n"));
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  GNUNET_IDENTITY_ego_get_public_key (ego, &handle->pkey);
-  /* main name is our own master zone, do no look for that in the DHT */
-  handle->options = GNUNET_GNS_LO_LOCAL_MASTER;
-  /* if the name is of the form 'label.gnu', never go to the DHT */
-  dot = NULL;
-  if (NULL != handle->name)
-    dot = strchr (handle->name, '.');
-  if ( (NULL != dot) &&
-       (0 == strcasecmp (dot, ".gnu")) )
-    handle->options = GNUNET_GNS_LO_NO_DHT;
-  lookup_with_public_key (handle);
-}
-
-/**
- * Parse REST uri for name and record type
- *
- * @param url Url to parse
- * @param handle lookup handle to populate
- * @return GNUNET_SYSERR on error
- */
-static int
-parse_url (const char *url, struct LookupHandle *handle)
-{
-  char *name;
-  char tmp_url[strlen(url)+1];
-  char *tok;
-
-  strcpy (tmp_url, url);
-  tok = strtok ((char*)tmp_url, "/");
-  if (NULL == tok)
-    return GNUNET_SYSERR;
-  name = strtok (NULL, "/");
-  if (NULL == name)
-    return GNUNET_SYSERR;
-  GNUNET_asprintf (&handle->name,
-                   "%s",
-                   name);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Got name: %s\n", handle->name);
-  return GNUNET_OK;
-}
-
-static void
-get_gns_cont (struct RestConnectionDataHandle *conndata_handle,
-              const char* url,
-              void *cls)
-{
-  struct LookupHandle *handle = cls;
-  struct GNUNET_HashCode key;
-
-  //parse name and type from url
-  if (GNUNET_OK != parse_url (url, handle))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing url...\n");
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Connecting...\n");
-  handle->gns = GNUNET_GNS_connect (cfg);
-  handle->identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
-  handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout,
-                                                       &do_error, handle);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Connected\n");
-  if (NULL == handle->gns)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Connecting to GNS failed\n");
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_GNS_OPTIONS,
-                      strlen (GNUNET_REST_JSONAPI_GNS_OPTIONS),
-                      &key);
-  handle->options = GNUNET_GNS_LO_DEFAULT;
-  if ( GNUNET_YES ==
-       GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map,
-                                               &key) )
-  {
-    handle->options = GNUNET_GNS_LO_DEFAULT;//TODO(char*) 
GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
-    //&key);
-  }
-  GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_GNS_RECORD_TYPE,
-                      strlen (GNUNET_REST_JSONAPI_GNS_RECORD_TYPE),
-                      &key);
-  if ( GNUNET_YES ==
-       GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map,
-                                               &key) )
-  {
-    handle->type = GNUNET_GNSRECORD_typename_to_number 
-      (GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
-                                          &key));
-  }
-  else
-    handle->type = GNUNET_GNSRECORD_TYPE_ANY;
-
-  GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_GNS_PKEY,
-                      strlen (GNUNET_REST_JSONAPI_GNS_PKEY),
-                      &key);
-  if ( GNUNET_YES ==
-       GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map,
-                                               &key) )
-  {
-    handle->pkey_str = GNUNET_CONTAINER_multihashmap_get 
(conndata_handle->url_param_map,
-                                                          &key);
-    if (GNUNET_OK !=
-        GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->pkey_str,
-                                                    strlen(handle->pkey_str),
-                                                    &(handle->pkey)))
-    {
-      GNUNET_SCHEDULER_add_now (&do_error, handle);
-      return;
-    }
-    lookup_with_public_key (handle);
-    return;
-  }
-  GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_GNS_EGO,
-                      strlen (GNUNET_REST_JSONAPI_GNS_EGO),
-                      &key);
-  if ( GNUNET_YES ==
-       GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map,
-                                               &key) )
-  {
-    handle->ego_str = GNUNET_CONTAINER_multihashmap_get 
(conndata_handle->url_param_map,
-                                                         &key);
-    handle->el = GNUNET_IDENTITY_ego_lookup (cfg,
-                                             handle->ego_str,
-                                             &identity_zone_cb,
-                                             handle);
-    return;
-  }
-  if ( (NULL != handle->name) &&
-       (strlen (handle->name) > 4) &&
-       (0 == strcmp (".zkey",
-                     &handle->name[strlen (handle->name) - 4])) )
-  {
-    GNUNET_CRYPTO_ecdsa_key_get_public
-      (GNUNET_CRYPTO_ecdsa_key_get_anonymous (),
-       &(handle->pkey));
-    lookup_with_public_key (handle);
-  }
-  else
-  {
-    GNUNET_break (NULL == handle->id_op);
-    handle->id_op = GNUNET_IDENTITY_get (handle->identity,
-                                         "gns-master",
-                                         &identity_master_cb,
-                                         handle);
-    GNUNET_assert (NULL != handle->id_op);
-  }
-}
-
-/**
- * Handle rest request
- *
- * @param handle the lookup handle
- */
-static void
-options_cont (struct RestConnectionDataHandle *con_handle,
-              const char* url,
-              void *cls)
-{
-  struct MHD_Response *resp;
-  struct LookupHandle *handle = cls;
-
-  //For GNS, independent of path return all options
-  resp = GNUNET_REST_create_json_response (NULL);
-  MHD_add_response_header (resp,
-                           "Access-Control-Allow-Methods",
-                           MHD_HTTP_METHOD_GET);
-  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
-  cleanup_handle (handle);
-  return;
-}
-
-
-/**
- * Function processing the REST call
- *
- * @param method HTTP method
- * @param url URL of the HTTP request
- * @param data body of the HTTP request (optional)
- * @param data_size length of the body
- * @param proc callback function for the result
- * @param proc_cls closure for callback function
- * @return GNUNET_OK if request accepted
- */
-static void
-rest_gns_process_request(struct RestConnectionDataHandle *conndata_handle,
-                         GNUNET_REST_ResultProcessor proc,
-                         void *proc_cls)
-{
-  struct LookupHandle *handle = GNUNET_new (struct LookupHandle);
-
-  handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
-  handle->proc_cls = proc_cls;
-  handle->proc = proc;
-
-  static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
-    {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_GNS, &get_gns_cont},
-    {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_GNS, &options_cont},
-    GNUNET_REST_HANDLER_END
-  };
-
-  if (GNUNET_NO == GNUNET_REST_handle_request (conndata_handle, handlers, 
handle))
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-}
-
-
-
-/**
- * Entry point for the plugin.
- *
- * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
- * @return NULL on error, otherwise the plugin context
- */
-void *
-libgnunet_plugin_rest_gns_init (void *cls)
-{
-  static struct Plugin plugin;
-  cfg = cls;
-  struct GNUNET_REST_Plugin *api;
-
-  if (NULL != plugin.cfg)
-    return NULL;                /* can only initialize once! */
-  memset (&plugin, 0, sizeof (struct Plugin));
-  plugin.cfg = cfg;
-  api = GNUNET_new (struct GNUNET_REST_Plugin);
-  api->cls = &plugin;
-  api->name = GNUNET_REST_API_NS_GNS;
-  api->process_request = &rest_gns_process_request;
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              _("GNS REST API initialized\n"));
-  return api;
-}
-
-
-/**
- * Exit point from the plugin.
- *
- * @param cls the plugin context (as returned by "init")
- * @return always NULL
- */
-void *
-libgnunet_plugin_rest_gns_done (void *cls)
-{
-  struct GNUNET_REST_Plugin *api = cls;
-  struct Plugin *plugin = api->cls;
-
-  plugin->cfg = NULL;
-  GNUNET_free (api);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "GNS REST plugin is finished\n");
-  return NULL;
-}
-
-/* end of plugin_rest_gns.c */

Modified: gnunet/src/identity/Makefile.am
===================================================================
--- gnunet/src/identity/Makefile.am     2015-09-10 15:39:36 UTC (rev 36350)
+++ gnunet/src/identity/Makefile.am     2015-09-11 15:56:39 UTC (rev 36351)
@@ -19,40 +19,10 @@
 pkgcfg_DATA = \
   identity.conf
 
-if HAVE_REST
-REST_PLUGIN = libgnunet_plugin_rest_identity.la
-plugin_LTLIBRARIES = ${REST_PLUGIN}
-endif
-
 lib_LTLIBRARIES = \
-       libgnunetidentity.la 
+       libgnunetidentity.la \
+       libgnunet_plugin_gnsrecord_identity.la
 
-if HAVE_REST
-plugin_LTLIBRARIES += \
-  libgnunet_plugin_gnsrecord_identity.la
-
-
-libgnunet_plugin_gnsrecord_identity_la_SOURCES = \
-  plugin_gnsrecord_identity.c
-libgnunet_plugin_gnsrecord_identity_la_LIBADD = \
-  $(top_builddir)/src/util/libgnunetutil.la \
-  $(LTLIBINTL)
-libgnunet_plugin_gnsrecord_identity_la_LDFLAGS = \
- $(GN_PLUGIN_LDFLAGS)
-endif
-
-libgnunet_plugin_rest_identity_la_SOURCES = \
-  plugin_rest_identity.c
-libgnunet_plugin_rest_identity_la_LIBADD = \
-  $(top_builddir)/src/identity/libgnunetidentity.la \
-       $(top_builddir)/src/rest/libgnunetrest.la \
-  $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
-  $(LTLIBINTL) -ljansson -lmicrohttpd
-libgnunet_plugin_rest_identity_la_LDFLAGS = \
- $(GN_PLUGIN_LDFLAGS)
-
-
-
 libgnunetidentity_la_SOURCES = \
   identity_api.c \
   identity_api_lookup.c \
@@ -69,10 +39,12 @@
 
 libexec_PROGRAMS = \
  gnunet-service-identity 
+
 if HAVE_REST
 bin_PROGRAMS += \
                                                                
gnunet-identity-token
 endif
+
 gnunet_service_identity_SOURCES = \
  gnunet-service-identity.c         
 gnunet_service_identity_LDADD = \
@@ -80,6 +52,15 @@
   $(top_builddir)/src/util/libgnunetutil.la \
   $(GN_LIBINTL)
 
+libgnunet_plugin_gnsrecord_identity_la_SOURCES = \
+  plugin_gnsrecord_identity.c
+libgnunet_plugin_gnsrecord_identity_la_LIBADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(LTLIBINTL)
+libgnunet_plugin_gnsrecord_identity_la_LDFLAGS = \
+ $(GN_PLUGIN_LDFLAGS)
+
+
 gnunet_identity_SOURCES = \
  gnunet-identity.c         
 gnunet_identity_LDADD = \

Deleted: gnunet/src/identity/plugin_rest_identity.c
===================================================================
--- gnunet/src/identity/plugin_rest_identity.c  2015-09-10 15:39:36 UTC (rev 
36350)
+++ gnunet/src/identity/plugin_rest_identity.c  2015-09-11 15:56:39 UTC (rev 
36351)
@@ -1,1073 +0,0 @@
-/*
-   This file is part of GNUnet.
-   Copyright (C) 2012-2015 Christian Grothoff (and other contributing authors)
-
-   GNUnet is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published
-   by the Free Software Foundation; either version 3, or (at your
-   option) any later version.
-
-   GNUnet is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNUnet; see the file COPYING.  If not, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.
-   */
-/**
- * @author Martin Schanzenbach
- * @file identity/plugin_rest_identity.c
- * @brief GNUnet Namestore REST plugin
- *
- */
-
-#include "platform.h"
-#include "gnunet_rest_plugin.h"
-#include "gnunet_identity_service.h"
-#include "gnunet_rest_lib.h"
-#include "microhttpd.h"
-#include <jansson.h>
-#include "gnunet_signatures.h"
-
-/**
- * REST root namespace
- */
-#define GNUNET_REST_API_NS_IDENTITY "/identity"
-
-/**
- * State while collecting all egos
- */
-#define ID_REST_STATE_INIT 0
-
-/**
- * Done collecting egos
- */
-#define ID_REST_STATE_POST_INIT 1
-
-/**
- * Resource type
- */
-#define GNUNET_REST_JSONAPI_IDENTITY_EGO "ego"
-
-/**
- * Name attribute
- */
-#define GNUNET_REST_JSONAPI_IDENTITY_NAME "name"
-
-/**
- * Attribute to rename "name" TODO we changed id to the pubkey
- * so this can be unified with "name"
- */
-#define GNUNET_REST_JSONAPI_IDENTITY_NEWNAME "newname"
-
-/**
- * URL parameter to change the subsytem for ego
- */
-#define GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM "subsystem"
-
-
-/**
- * URL parameter to create a GNUid token for a specific audience
- */
-#define GNUNET_REST_JSONAPI_IDENTITY_CREATE_TOKEN "create_token_for"
-
-/**
- * Attribute containing the GNUid token if
- * GNUNET_REST_JSONAPI_IDENTITY_CREATE_TOKEN was requested
- */
-#define GNUNET_REST_JSONAPI_IDENTITY_GNUID "gnuid_token"
-
-/**
- * Error messages
- */
-#define GNUNET_REST_ERROR_RESOURCE_INVALID "Resource location invalid"
-#define GNUNET_REST_ERROR_NO_DATA "No data"
-
-/**
- * GNUid token lifetime
- */
-#define GNUNET_GNUID_TOKEN_EXPIRATION_SECONDS 360
-
-/**
- * The configuration handle
- */
-const struct GNUNET_CONFIGURATION_Handle *cfg;
-
-/**
- * HTTP methods allows for this plugin
- */
-static char* allow_methods;
-
-/**
- * @brief struct returned by the initialization function of the plugin
- */
-struct Plugin
-{
-  const struct GNUNET_CONFIGURATION_Handle *cfg;
-};
-
-/**
- * The ego list
- */
-struct EgoEntry
-{
-  /**
-   * DLL
-   */
-  struct EgoEntry *next;
-  
-  /**
-   * DLL
-   */
-  struct EgoEntry *prev;
-  
-  /**
-   * Ego Identifier
-   */
-  char *identifier;
-
-  /**
-   * Public key string
-   */
-  char *keystring;
-  
-  /**
-   * The Ego
-   */
-  struct GNUNET_IDENTITY_Ego *ego;
-};
-
-
-struct RequestHandle
-{
-  /**
-   * Ego list
-   */
-  struct EgoEntry *ego_head;
-
-  /**
-   * Ego list
-   */
-  struct EgoEntry *ego_tail;
-
-  /**
-   * Handle to the rest connection
-   */
-  struct RestConnectionDataHandle *conndata_handle;
-  
-  /**
-   * The processing state
-   */
-  int state;
-
-  /**
-   * Handle to GNS service.
-   */
-  struct GNUNET_IDENTITY_Handle *identity_handle;
-
-  /**
-   * IDENTITY Operation
-   */
-  struct GNUNET_IDENTITY_Operation *op;
-
-  /**
-   * Desired timeout for the lookup (default is no timeout).
-   */
-  struct GNUNET_TIME_Relative timeout;
-
-  /**
-   * ID of a task associated with the resolution process.
-   */
-  struct GNUNET_SCHEDULER_Task * timeout_task;    
-
-  /**
-   * The plugin result processor
-   */
-  GNUNET_REST_ResultProcessor proc;
-
-  /**
-   * The closure of the result processor
-   */
-  void *proc_cls;
-
-  /**
-   * The name to look up
-   */
-  char *name;
-
-  /**
-   * The subsystem set from REST
-   */
-  char *subsys;
-
-  /**
-   * The url
-   */
-  char *url;
-
-  /**
-   * The data from the REST request
-   */
-  const char* data;
-
-  /**
-   * the length of the REST data
-   */
-  size_t data_size;
-
-  /**
-   * HTTP method
-   */
-  const char* method;
-
-  /**
-   * Error response message
-   */
-  char *emsg;
-
-};
-
-
-/**
- * Cleanup lookup handle
- * @param handle Handle to clean up
- */
-static void
-cleanup_handle (struct RequestHandle *handle)
-{
-  struct EgoEntry *ego_entry;
-  struct EgoEntry *ego_tmp;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Cleaning up\n");
-  if (NULL != handle->name)
-    GNUNET_free (handle->name);
-  if (NULL != handle->timeout_task)
-    GNUNET_SCHEDULER_cancel (handle->timeout_task);
-  if (NULL != handle->identity_handle)
-    GNUNET_IDENTITY_disconnect (handle->identity_handle);
-  if (NULL != handle->subsys)
-    GNUNET_free (handle->subsys);
-  if (NULL != handle->url)
-    GNUNET_free (handle->url);
-  if (NULL != handle->emsg)
-    GNUNET_free (handle->emsg);
-  for (ego_entry = handle->ego_head;
-       NULL != ego_entry;)
-  {
-    ego_tmp = ego_entry;
-    ego_entry = ego_entry->next;
-    GNUNET_free (ego_tmp->identifier);
-    GNUNET_free (ego_tmp->keystring);
-    GNUNET_free (ego_tmp);
-  }
-  GNUNET_free (handle);
-}
-
-
-/**
- * Task run on shutdown.  Cleans up everything.
- *
- * @param cls unused
- * @param tc scheduler context
- */
-static void
-do_error (void *cls,
-          const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct RequestHandle *handle = cls;
-  struct MHD_Response *resp;
-  char *json_error;
-
-  GNUNET_asprintf (&json_error,
-                   "{Error while processing request: %s}",
-                   &handle->emsg);
-
-  resp = GNUNET_REST_create_json_response (json_error);
-  handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
-  cleanup_handle (handle);
-  GNUNET_free (json_error);
-}
-
-/**
- * Build a GNUid token for identity
- * @param handle the handle
- * @param ego_entry the ego to build the token for
- * @param name name of the ego
- * @param token_aud token audience
- * @param token the resulting gnuid token
- */
-static void
-make_gnuid_token (struct RequestHandle *handle,
-                  struct EgoEntry *ego_entry,
-                  const char *name,
-                  const char *token_aud,
-                  char **token)
-{
-  uint64_t time;
-  char *header_str;
-  char *payload_str;
-  char *header_base64;
-  char *payload_base64;
-  char *sig_str;
-  json_t *header;
-  json_t *payload;
-  const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
-  struct GNUNET_CRYPTO_EcdsaSignature sig;
-  struct GNUNET_CRYPTO_EccSignaturePurpose *purpose;
-
-  time = GNUNET_TIME_absolute_get().abs_value_us;
-  header = json_object ();
-  json_object_set_new (header, "alg", json_string ("ED512"));
-  json_object_set_new (header, "typ", json_string ("JWT"));
-  
-  payload = json_object ();
-  json_object_set_new (payload, "iss", json_string (ego_entry->keystring));
-  json_object_set_new (payload, "sub", json_string (name));
-  json_object_set_new (payload, "nbf", json_integer (time));
-  json_object_set_new (payload, "iat", json_integer (time));
-  json_object_set_new (payload, "exp", json_integer 
(time+GNUNET_GNUID_TOKEN_EXPIRATION_SECONDS));
-  json_object_set_new (payload, "aud", json_string (token_aud));
-  header_str = json_dumps (header, JSON_COMPACT);
-  GNUNET_STRINGS_base64_encode (header_str,
-                                strlen (header_str),
-                                &header_base64);
-  char* padding = strtok(header_base64, "=");
-  while (NULL != padding)
-    padding = strtok(NULL, "=");
-
-  payload_str = json_dumps (payload, JSON_COMPACT);
-  GNUNET_STRINGS_base64_encode (payload_str,
-                                strlen (payload_str),
-                                &payload_base64);
-  padding = strtok(payload_base64, "=");
-  while (NULL != padding)
-    padding = strtok(NULL, "=");
-
-  GNUNET_asprintf (token, "%s,%s", header_base64, payload_base64);
-  priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
-  purpose = 
-    GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + 
-                   strlen (*token));
-  purpose->size = 
-    htonl (strlen (*token) + sizeof (struct 
GNUNET_CRYPTO_EccSignaturePurpose));
-  purpose->purpose = htonl(GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN);
-  memcpy (&purpose[1], *token, strlen (*token));
-  if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_sign (priv_key,
-                                             purpose,
-                                             &sig))
-    GNUNET_break(0);
-  GNUNET_free (*token);
-  sig_str = GNUNET_STRINGS_data_to_string_alloc (&sig,
-                                                 sizeof (struct 
GNUNET_CRYPTO_EcdsaSignature));
-  GNUNET_asprintf (token, "%s.%s.%s",
-                   header_base64, payload_base64, sig_str);
-  GNUNET_free (sig_str);
-  GNUNET_free (header_str);
-  GNUNET_free (header_base64);
-  GNUNET_free (payload_str);
-  GNUNET_free (payload_base64);
-  GNUNET_free (purpose);
-  json_decref (header);
-  json_decref (payload);
-}
-
-/**
- * Callback for IDENTITY_get()
- *
- * @param cls the RequestHandle
- * @param ego the Ego found
- * @param ctx the context
- * @param name the id of the ego
- */
-static void
-get_ego_for_subsys (void *cls,
-                    struct GNUNET_IDENTITY_Ego *ego,
-                    void **ctx,
-                    const char *name)
-{
-  struct RequestHandle *handle = cls;
-  struct JsonApiObject *json_object;
-  struct JsonApiResource *json_resource;
-  struct EgoEntry *ego_entry;
-  struct MHD_Response *resp;
-  json_t *name_json;
-  char *result_str;
-
-  json_object = GNUNET_REST_jsonapi_object_new ();
-
-  for (ego_entry = handle->ego_head;
-       NULL != ego_entry;
-       ego_entry = ego_entry->next)
-  {
-    if ( (NULL != name) && (0 != strcmp (name, ego_entry->identifier)) )
-      continue;
-    if (NULL == name)
-      continue;
-    json_resource = GNUNET_REST_jsonapi_resource_new
-      (GNUNET_REST_JSONAPI_IDENTITY_EGO, ego_entry->keystring);
-    name_json = json_string (ego_entry->identifier);
-    GNUNET_REST_jsonapi_resource_add_attr (json_resource,
-                                           GNUNET_REST_JSONAPI_IDENTITY_NAME,
-                                           name_json);
-    json_decref (name_json);
-    GNUNET_REST_jsonapi_object_resource_add (json_object, json_resource);
-    break;
-  }
-  if (0 == GNUNET_REST_jsonapi_object_resource_count (json_object))
-  {
-    GNUNET_REST_jsonapi_object_delete (json_object);
-    handle->emsg = GNUNET_strdup("No identity matches results!");
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  GNUNET_REST_jsonapi_data_serialize (json_object, &result_str);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
-  resp = GNUNET_REST_create_json_response (result_str);
-  GNUNET_REST_jsonapi_object_delete (json_object);
-  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
-  GNUNET_free (result_str);
-  cleanup_handle (handle);
-}
-
-/**
- * Create a response with requested ego(s)
- *
- * @param con the Rest handle
- * @param url the requested url
- * @param cls the request handle
- */
-static void
-ego_info_response (struct RestConnectionDataHandle *con,
-                   const char *url,
-                   void *cls)
-{
-  const char *egoname;
-  char *result_str;
-  char *subsys_val;
-  char *create_token_for;
-  char *token;
-  char *keystring;
-  struct RequestHandle *handle = cls;
-  struct EgoEntry *ego_entry;
-  struct GNUNET_HashCode key;
-  struct MHD_Response *resp;
-  struct JsonApiObject *json_object;
-  struct JsonApiResource *json_resource;
-  json_t *name_str;
-  json_t *token_str;
-
-  if (GNUNET_NO == GNUNET_REST_namespace_match (handle->url, 
GNUNET_REST_API_NS_IDENTITY))
-  {
-    resp = GNUNET_REST_create_json_response (NULL);
-    handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
-    cleanup_handle (handle);
-    return;
-  }
-  egoname = NULL;
-  keystring = NULL;
-  if (strlen (GNUNET_REST_API_NS_IDENTITY) < strlen (handle->url))
-  {
-    keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY)+1];
-    //Return all egos
-    for (ego_entry = handle->ego_head;
-         NULL != ego_entry;
-         ego_entry = ego_entry->next)
-    {
-      if ( (NULL != keystring) && (0 != strcmp (keystring, 
ego_entry->keystring)) )
-        continue;
-      egoname = ego_entry->identifier;
-    }
-  }
-
-  if ( NULL == egoname ) {
-    GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM,
-                        strlen (GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM),
-                        &key);
-    if ( GNUNET_YES ==
-         GNUNET_CONTAINER_multihashmap_contains 
(handle->conndata_handle->url_param_map,
-                                                 &key) )
-    {
-      subsys_val = GNUNET_CONTAINER_multihashmap_get 
(handle->conndata_handle->url_param_map,
-                                                      &key);
-      if (NULL != subsys_val)
-      {
-        GNUNET_asprintf (&handle->subsys, "%s", subsys_val);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", 
subsys_val);
-        handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
-                                          handle->subsys,
-                                          &get_ego_for_subsys,
-                                          handle);
-        return;
-      }
-    }
-  }
-
-  GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_CREATE_TOKEN,
-                      strlen (GNUNET_REST_JSONAPI_IDENTITY_CREATE_TOKEN),
-                      &key);
-
-  //Token audience
-  create_token_for = NULL;
-  if ( GNUNET_YES ==
-       GNUNET_CONTAINER_multihashmap_contains 
(handle->conndata_handle->url_param_map,
-                                               &key) )
-    create_token_for = GNUNET_CONTAINER_multihashmap_get 
(handle->conndata_handle->url_param_map,
-                                                          &key);
-
-  json_object = GNUNET_REST_jsonapi_object_new ();
-
-  //Return all egos
-  for (ego_entry = handle->ego_head;
-       NULL != ego_entry;
-       ego_entry = ego_entry->next)
-  {
-    if ( (NULL != egoname) && (0 != strcmp (egoname, ego_entry->identifier)) )
-      continue;
-    json_resource = GNUNET_REST_jsonapi_resource_new 
(GNUNET_REST_JSONAPI_IDENTITY_EGO,
-                                                      ego_entry->keystring);
-    name_str = json_string (ego_entry->identifier);
-    GNUNET_REST_jsonapi_resource_add_attr (
-                                           json_resource,
-                                           GNUNET_REST_JSONAPI_IDENTITY_NAME,
-                                           name_str);
-    json_decref (name_str);
-    if (NULL != create_token_for)
-    {
-      make_gnuid_token (handle,
-                        ego_entry,
-                        ego_entry->identifier,
-                        create_token_for,
-                        &token);
-      token_str = json_string (token);
-      GNUNET_free (token);
-      GNUNET_REST_jsonapi_resource_add_attr (json_resource,
-                                             
GNUNET_REST_JSONAPI_IDENTITY_GNUID,
-                                             token_str);
-      json_decref (token_str);
-    }
-    GNUNET_REST_jsonapi_object_resource_add (json_object, json_resource);
-  }
-  if (0 == GNUNET_REST_jsonapi_object_resource_count (json_object))
-  {
-    GNUNET_REST_jsonapi_object_delete (json_object);
-    handle->emsg = GNUNET_strdup ("No identities found!");
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  GNUNET_REST_jsonapi_data_serialize (json_object, &result_str);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
-  resp = GNUNET_REST_create_json_response (result_str);
-  GNUNET_REST_jsonapi_object_delete (json_object);
-  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
-  GNUNET_free (result_str);
-  cleanup_handle (handle);
-}
-
-/**
- * Processing finished
- *
- * @param cls request handle
- * @param emsg error message
- */
-static void
-do_finished (void *cls, const char *emsg)
-{
-  struct RequestHandle *handle = cls;
-  struct MHD_Response *resp;
-
-  handle->op = NULL;
-  if (NULL != emsg)
-  {
-    handle->emsg = GNUNET_strdup (emsg);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  resp = GNUNET_REST_create_json_response (NULL);
-  handle->proc (handle->proc_cls, resp, MHD_HTTP_NO_CONTENT);
-  cleanup_handle (handle);
-}
-
-/**
- * Create a new ego
- *
- * @param con rest handle
- * @param url url
- * @param cls request handle
- */
-static void
-ego_create_cont (struct RestConnectionDataHandle *con,
-                 const char *url,
-                 void *cls)
-{
-  struct RequestHandle *handle = cls;
-  struct EgoEntry *ego_entry;
-  struct MHD_Response *resp;
-  struct JsonApiObject *json_obj;
-  struct JsonApiResource *json_res;
-  json_t *egoname_json;
-  const char* egoname;
-  char term_data[handle->data_size+1];
-
-  if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url))
-  {
-    handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_RESOURCE_INVALID);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  if (0 >= handle->data_size)
-  {
-    handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  term_data[handle->data_size] = '\0';
-  memcpy (term_data, handle->data, handle->data_size);
-  json_obj = GNUNET_REST_jsonapi_object_parse (term_data);
-  if (NULL == json_obj)
-  {
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  if (1 != GNUNET_REST_jsonapi_object_resource_count (json_obj))
-  {
-    GNUNET_REST_jsonapi_object_delete (json_obj);
-    handle->emsg = GNUNET_strdup ("Provided resource count invalid");
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  json_res = GNUNET_REST_jsonapi_object_get_resource (json_obj, 0);
-  if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_type (json_res, 
GNUNET_REST_JSONAPI_IDENTITY_EGO))
-  {
-    GNUNET_REST_jsonapi_object_delete (json_obj);
-    resp = GNUNET_REST_create_json_response (NULL);
-    handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
-    cleanup_handle (handle);
-    return;
-  }
-  egoname_json = GNUNET_REST_jsonapi_resource_read_attr (json_res, 
GNUNET_REST_JSONAPI_IDENTITY_NAME);
-  if (!json_is_string (egoname_json))
-  {
-    GNUNET_REST_jsonapi_object_delete (json_obj); 
-    handle->emsg = GNUNET_strdup ("No name provided");
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  egoname = json_string_value (egoname_json);
-  for (ego_entry = handle->ego_head;
-       NULL != ego_entry;
-       ego_entry = ego_entry->next)
-  {
-    if (0 == strcasecmp (egoname, ego_entry->identifier))
-    {
-      GNUNET_REST_jsonapi_object_delete (json_obj);
-      resp = GNUNET_REST_create_json_response (NULL);
-      handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
-      cleanup_handle (handle);
-      return;
-    }
-  }
-  GNUNET_asprintf (&handle->name, "%s", egoname);
-  GNUNET_REST_jsonapi_object_delete (json_obj);
-  handle->op = GNUNET_IDENTITY_create (handle->identity_handle,
-                                       handle->name,
-                                       &do_finished,
-                                       handle);
-}
-
-
-/**
- * Handle ego edit request
- *
- * @param con rest connection handle
- * @param url the url that is requested
- * @param cls the RequestHandle
- */
-static void 
-ego_edit_cont (struct RestConnectionDataHandle *con,
-               const char *url,
-               void *cls)
-{
-  struct JsonApiObject *json_obj;
-  struct JsonApiResource *json_res;
-  struct RequestHandle *handle = cls;
-  struct EgoEntry *ego_entry;
-  struct MHD_Response *resp;
-  json_t *subsys_json;
-  json_t *name_json;
-  const char *keystring;
-  const char *subsys;
-  const char *newname;
-  char term_data[handle->data_size+1];
-  int ego_exists = GNUNET_NO;
-
-  if (strlen (GNUNET_REST_API_NS_IDENTITY) > strlen (handle->url))
-  {
-    handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_RESOURCE_INVALID);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-
-  keystring = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY)+1];
-
-  for (ego_entry = handle->ego_head;
-       NULL != ego_entry;
-       ego_entry = ego_entry->next)
-  {
-    if (0 != strcasecmp (keystring, ego_entry->keystring))
-      continue;
-    ego_exists = GNUNET_YES;
-    break;
-  }
-
-  if (GNUNET_NO == ego_exists)
-  {
-    resp = GNUNET_REST_create_json_response (NULL);
-    handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
-    cleanup_handle (handle);
-    return;
-  }
-
-  if (0 >= handle->data_size)
-  {
-    handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-
-  term_data[handle->data_size] = '\0';
-  memcpy (term_data, handle->data, handle->data_size);
-  json_obj = GNUNET_REST_jsonapi_object_parse (term_data);
-
-  if (NULL == json_obj)
-  {
-    handle->emsg = GNUNET_strdup ("Data invalid");
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-
-  if (1 != GNUNET_REST_jsonapi_object_resource_count (json_obj))
-  {
-    GNUNET_REST_jsonapi_object_delete (json_obj);
-    handle->emsg = GNUNET_strdup ("Resource amount invalid");
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  json_res = GNUNET_REST_jsonapi_object_get_resource (json_obj, 0); 
-
-  if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_type (json_res, 
GNUNET_REST_JSONAPI_IDENTITY_EGO))
-  {
-    GNUNET_REST_jsonapi_object_delete (json_obj);
-    handle->emsg = GNUNET_strdup ("Resource type invalid");
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-
-  //This is a rename
-  name_json = GNUNET_REST_jsonapi_resource_read_attr (json_res,
-                                                      
GNUNET_REST_JSONAPI_IDENTITY_NEWNAME);
-  if ((NULL != name_json) && json_is_string (name_json))
-  {
-    newname = json_string_value (name_json);
-    for (ego_entry = handle->ego_head;
-         NULL != ego_entry;
-         ego_entry = ego_entry->next)
-    {
-      if (0 == strcasecmp (newname, ego_entry->identifier) &&
-          0 != strcasecmp (keystring, ego_entry->keystring))
-      {
-        //Ego with same name not allowed
-        GNUNET_REST_jsonapi_object_delete (json_obj);
-        resp = GNUNET_REST_create_json_response (NULL);
-        handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
-        cleanup_handle (handle);
-        return;
-      }
-    }
-    handle->op = GNUNET_IDENTITY_rename (handle->identity_handle,
-                                         ego_entry->identifier,
-                                         newname,
-                                         &do_finished,
-                                         handle);
-    GNUNET_REST_jsonapi_object_delete (json_obj);
-    return;
-  }
-
-  //Set subsystem
-  subsys_json = GNUNET_REST_jsonapi_resource_read_attr (json_res, 
GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM);
-  if ( (NULL != subsys_json) && json_is_string (subsys_json))
-  {
-    subsys = json_string_value (subsys_json);
-    GNUNET_asprintf (&handle->subsys, "%s", subsys);
-    GNUNET_REST_jsonapi_object_delete (json_obj);
-    handle->op = GNUNET_IDENTITY_set (handle->identity_handle,
-                                      handle->subsys,
-                                      ego_entry->ego,
-                                      &do_finished,
-                                      handle);
-    return;
-  }
-  GNUNET_REST_jsonapi_object_delete (json_obj);
-  handle->emsg = GNUNET_strdup ("Subsystem not provided");
-  GNUNET_SCHEDULER_add_now (&do_error, handle);
-}
-
-void 
-ego_delete_cont (struct RestConnectionDataHandle *con_handle,
-                 const char* url,
-                 void *cls)
-{
-  const char *keystring;
-  struct EgoEntry *ego_entry;
-  struct MHD_Response *resp;
-  struct RequestHandle *handle = cls;
-  int ego_exists = GNUNET_NO;
-
-  if (strlen (GNUNET_REST_API_NS_IDENTITY) >= strlen (handle->url))
-  {
-    handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_RESOURCE_INVALID);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-
-  keystring = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY)+1];
-  for (ego_entry = handle->ego_head;
-       NULL != ego_entry;
-       ego_entry = ego_entry->next)
-  {
-    if (0 != strcasecmp (keystring, ego_entry->keystring))
-      continue;
-    ego_exists = GNUNET_YES;
-    break;
-  }
-  if (GNUNET_NO == ego_exists)
-  {
-    resp = GNUNET_REST_create_json_response (NULL);
-    handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
-    cleanup_handle (handle);
-    return;
-  }
-  handle->op = GNUNET_IDENTITY_delete (handle->identity_handle,
-                                       ego_entry->identifier,
-                                       &do_finished,
-                                       handle);
-
-}
-
-
-/**
- * Respond to OPTIONS request
- *
- * @param con_handle the connection handle
- * @param url the url
- * @param cls the RequestHandle
- */
-static void
-options_cont (struct RestConnectionDataHandle *con_handle,
-              const char* url,
-              void *cls)
-{
-  struct MHD_Response *resp;
-  struct RequestHandle *handle = cls;
-
-  //For now, independent of path return all options
-  resp = GNUNET_REST_create_json_response (NULL);
-  MHD_add_response_header (resp,
-                           "Access-Control-Allow-Methods",
-                           allow_methods);
-  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
-  cleanup_handle (handle);
-  return;
-}
-
-/**
- * Handle rest request
- *
- * @param handle the request handle
- */
-static void
-init_cont (struct RequestHandle *handle)
-{
-  static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
-    {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_info_response},
-    {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create_cont},
-    {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY, &ego_edit_cont},
-    {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_IDENTITY, &ego_delete_cont},
-    {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont},
-    GNUNET_REST_HANDLER_END
-  };
-
-  if (GNUNET_NO == GNUNET_REST_handle_request (handle->conndata_handle, 
handlers, handle))
-  {
-    handle->emsg = GNUNET_strdup ("Request unsupported");
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-  }
-}
-
-/**
- * If listing is enabled, prints information about the egos.
- *
- * This function is initially called for all egos and then again
- * whenever a ego's identifier changes or if it is deleted.  At the
- * end of the initial pass over all egos, the function is once called
- * with 'NULL' for 'ego'. That does NOT mean that the callback won't
- * be invoked in the future or that there was an error.
- *
- * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get',
- * this function is only called ONCE, and 'NULL' being passed in
- * 'ego' does indicate an error (i.e. name is taken or no default
- * value is known).  If 'ego' is non-NULL and if '*ctx'
- * is set in those callbacks, the value WILL be passed to a subsequent
- * call to the identity callback of 'GNUNET_IDENTITY_connect' (if
- * that one was not NULL).
- *
- * When an identity is renamed, this function is called with the
- * (known) ego but the NEW identifier.
- *
- * When an identity is deleted, this function is called with the
- * (known) ego and "NULL" for the 'identifier'.  In this case,
- * the 'ego' is henceforth invalid (and the 'ctx' should also be
- * cleaned up).
- *
- * @param cls closure
- * @param ego ego handle
- * @param ctx context for application to store data for this ego
- *                 (during the lifetime of this process, initially NULL)
- * @param identifier identifier assigned by the user for this ego,
- *                   NULL if the user just deleted the ego and it
- *                   must thus no longer be used
- */
-static void
-list_ego (void *cls,
-          struct GNUNET_IDENTITY_Ego *ego,
-          void **ctx,
-          const char *identifier)
-{
-  struct RequestHandle *handle = cls;
-  struct EgoEntry *ego_entry;
-  struct GNUNET_CRYPTO_EcdsaPublicKey pk;
-
-  if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state))
-  {
-    handle->state = ID_REST_STATE_POST_INIT;
-    init_cont (handle);
-    return;
-  }
-  if (ID_REST_STATE_INIT == handle->state) {
-    ego_entry = GNUNET_new (struct EgoEntry);
-    GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
-    ego_entry->keystring = 
-      GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
-    ego_entry->ego = ego;
-    GNUNET_asprintf (&ego_entry->identifier, "%s", identifier);
-    GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head,handle->ego_tail, 
ego_entry);
-  }
-
-}
-
-/**
- * Function processing the REST call
- *
- * @param method HTTP method
- * @param url URL of the HTTP request
- * @param data body of the HTTP request (optional)
- * @param data_size length of the body
- * @param proc callback function for the result
- * @param proc_cls closure for callback function
- * @return GNUNET_OK if request accepted
- */
-static void
-rest_identity_process_request(struct RestConnectionDataHandle *conndata_handle,
-                              GNUNET_REST_ResultProcessor proc,
-                              void *proc_cls)
-{
-  struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
-
-
-
-  handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
-
-  handle->proc_cls = proc_cls;
-  handle->proc = proc;
-  handle->state = ID_REST_STATE_INIT;
-  handle->conndata_handle = conndata_handle;
-  handle->data = conndata_handle->data;
-  handle->data_size = conndata_handle->data_size;
-  handle->method = conndata_handle->method;
-  GNUNET_asprintf (&handle->url, "%s", conndata_handle->url);
-  if (handle->url[strlen (handle->url)-1] == '/')
-    handle->url[strlen (handle->url)-1] = '\0';
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Connecting...\n");
-  handle->identity_handle = GNUNET_IDENTITY_connect (cfg,
-                                                     &list_ego,
-                                                     handle);
-  GNUNET_strdup ("Timeout");
-  handle->timeout_task =
-    GNUNET_SCHEDULER_add_delayed (handle->timeout,
-                                  &do_error,
-                                  handle);
-
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Connected\n");
-}
-
-/**
- * Entry point for the plugin.
- *
- * @param cls Config info
- * @return NULL on error, otherwise the plugin context
- */
-void *
-libgnunet_plugin_rest_identity_init (void *cls)
-{
-  static struct Plugin plugin;
-  struct GNUNET_REST_Plugin *api;
-
-  cfg = cls;
-  if (NULL != plugin.cfg)
-    return NULL;                /* can only initialize once! */
-  memset (&plugin, 0, sizeof (struct Plugin));
-  plugin.cfg = cfg;
-  api = GNUNET_new (struct GNUNET_REST_Plugin);
-  api->cls = &plugin;
-  api->name = GNUNET_REST_API_NS_IDENTITY;
-  api->process_request = &rest_identity_process_request;
-  GNUNET_asprintf (&allow_methods,
-                   "%s, %s, %s, %s, %s",
-                   MHD_HTTP_METHOD_GET,
-                   MHD_HTTP_METHOD_POST,
-                   MHD_HTTP_METHOD_PUT,
-                   MHD_HTTP_METHOD_DELETE,
-                   MHD_HTTP_METHOD_OPTIONS);
-
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              _("Identity REST API initialized\n"));
-  return api;
-}
-
-
-/**
- * Exit point from the plugin.
- *
- * @param cls the plugin context (as returned by "init")
- * @return always NULL
- */
-void *
-libgnunet_plugin_rest_identity_done (void *cls)
-{
-  struct GNUNET_REST_Plugin *api = cls;
-  struct Plugin *plugin = api->cls;
-
-  plugin->cfg = NULL;
-  GNUNET_free_non_null (allow_methods);
-  GNUNET_free (api);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Identity REST plugin is finished\n");
-  return NULL;
-}
-
-/* end of plugin_rest_gns.c */

Modified: gnunet/src/namestore/Makefile.am
===================================================================
--- gnunet/src/namestore/Makefile.am    2015-09-10 15:39:36 UTC (rev 36350)
+++ gnunet/src/namestore/Makefile.am    2015-09-11 15:56:39 UTC (rev 36351)
@@ -106,22 +106,7 @@
  gnunet-namestore-fcfsd
 endif
 
-if HAVE_REST
-REST_PLUGIN = libgnunet_plugin_rest_namestore.la
-endif
 
-libgnunet_plugin_rest_namestore_la_SOURCES = \
-  plugin_rest_namestore.c
-libgnunet_plugin_rest_namestore_la_LIBADD = \
-  $(top_builddir)/src/namestore/libgnunetnamestore.la \
-       $(top_builddir)/src/identity/libgnunetidentity.la \
-       $(top_builddir)/src/rest/libgnunetrest.la \
-  $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
-  $(LTLIBINTL) -ljansson -lmicrohttpd
-libgnunet_plugin_rest_namestore_la_LDFLAGS = \
- $(GN_PLUGIN_LDFLAGS)
-
-
 gnunet_namestore_SOURCES = \
  gnunet-namestore.c
 gnunet_namestore_LDADD = \
@@ -158,8 +143,7 @@
 plugin_LTLIBRARIES = \
   $(SQLITE_PLUGIN) \
   $(POSTGRES_PLUGIN) \
-       $(FLAT_PLUGIN) \
-       $(REST_PLUGIN)
+       $(FLAT_PLUGIN)
 
 libgnunet_plugin_namestore_flat_la_SOURCES = \
   plugin_namestore_flat.c

Deleted: gnunet/src/namestore/plugin_rest_namestore.c
===================================================================
--- gnunet/src/namestore/plugin_rest_namestore.c        2015-09-10 15:39:36 UTC 
(rev 36350)
+++ gnunet/src/namestore/plugin_rest_namestore.c        2015-09-11 15:56:39 UTC 
(rev 36351)
@@ -1,1063 +0,0 @@
-/*
-   This file is part of GNUnet.
-   Copyright (C) 2012-2015 Christian Grothoff (and other contributing authors)
-
-   GNUnet is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published
-   by the Free Software Foundation; either version 3, or (at your
-   option) any later version.
-
-   GNUnet is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNUnet; see the file COPYING.  If not, write to the
-   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.
-   */
-/**
- * @author Martin Schanzenbach
- * @file namestore/plugin_rest_namestore.c
- * @brief GNUnet Namestore REST plugin
- *
- */
-
-#include "platform.h"
-#include "gnunet_rest_plugin.h"
-#include "gnunet_namestore_service.h"
-#include "gnunet_identity_service.h"
-#include "gnunet_rest_lib.h"
-#include "microhttpd.h"
-#include <jansson.h>
-
-#define GNUNET_REST_API_NS_NAMESTORE "/names"
-
-#define GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO "record"
-
-#define GNUNET_REST_JSONAPI_NAMESTORE_RECORD 
GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO
-
-#define GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE "record_type"
-
-#define GNUNET_REST_JSONAPI_NAMESTORE_VALUE "value"
-
-#define GNUNET_REST_JSONAPI_NAMESTORE_PUBLIC "public"
-
-#define GNUNET_REST_JSONAPI_NAMESTORE_SHADOW "shadow"
-
-#define GNUNET_REST_JSONAPI_NAMESTORE_PKEY "pkey"
-
-#define GNUNET_REST_JSONAPI_NAMESTORE_EXPIRATION "expiration"
-
-#define GNUNET_REST_JSONAPI_NAMESTORE_EGO "ego"
-
-/**
- * @brief struct returned by the initialization function of the plugin
- */
-struct Plugin
-{
-  const struct GNUNET_CONFIGURATION_Handle *cfg;
-};
-
-const struct GNUNET_CONFIGURATION_Handle *cfg;
-
-struct RecordEntry
-{
-  /**
-   * DLL
-   */
-  struct RecordEntry *next;
-  
-  /**
-   * DLL
-   */
-  struct RecordEntry *prev;
-  
-};
-
-struct RequestHandle
-{
-  /**
-   * Ego list
-   */
-  struct RecordEntry *record_head;
-
-  /**
-   * Ego list
-   */
-  struct record_entry *record_tail;
-
-  /**
-   * JSON response object
-   */
-  struct JsonApiObject *resp_object;
-  
-  /**
-   * Rest connection
-   */
-  struct RestConnectionDataHandle *conndata_handle;
-  
-  /**
-   * Handle to GNS service.
-   */
-  struct GNUNET_IDENTITY_Handle *identity_handle;
-
-  /**
-   * Handle to NAMESTORE
-   */
-  struct GNUNET_NAMESTORE_Handle *ns_handle;
-  
-  /**
-   * Handle to NAMESTORE it
-   */
-  struct GNUNET_NAMESTORE_ZoneIterator *list_it;
-  
-  /**
-   * Private key for the zone
-   */
-  struct GNUNET_CRYPTO_EcdsaPrivateKey zone_pkey;
-
-  /**
-   * Handle to identity lookup
-   */
-  struct GNUNET_IDENTITY_EgoLookup *ego_lookup;
-
-  /**
-   * Default Ego operation
-   */
-  struct GNUNET_IDENTITY_Operation *get_default;
-
-  /**
-   * Name of the ego
-   */
-  char *ego_name;
-
-  /**
-   * Record is public
-   */
-  int is_public;
-
-  /**
-   * Shadow record
-   */
-  int is_shadow;
-
-  /**
-   * Name of the record to modify
-   */
-  char *name;
-
-  /**
-   * Value of the record
-   */
-  char *value;
-
-  /**
-   * record type
-   */
-  uint32_t type;
-
-  /**
-   * Records to store
-   */
-  struct GNUNET_GNSRECORD_Data *rd;
-
-  /**
-   * record count
-   */
-  unsigned int rd_count;
-
-    /**
-   * NAMESTORE Operation
-   */
-  struct GNUNET_NAMESTORE_QueueEntry *add_qe;
-
-  /**
-   * Desired timeout for the lookup (default is no timeout).
-   */
-  struct GNUNET_TIME_Relative timeout;
-
-  /**
-   * ID of a task associated with the resolution process.
-   */
-  struct GNUNET_SCHEDULER_Task * timeout_task;    
-
-  /**
-   * The plugin result processor
-   */
-  GNUNET_REST_ResultProcessor proc;
-
-  /**
-   * The closure of the result processor
-   */
-  void *proc_cls;
-
-  /**
-   * The url
-   */
-  char *url;
-
-  /**
-   * The data from the REST request
-   */
-  const char* data;
-
-  /**
-   * the length of the REST data
-   */
-  size_t data_size;
-  
-  /**
-   * Cfg
-   */
-  const struct GNUNET_CONFIGURATION_Handle *cfg;
-
-};
-
-
-/**
- * Cleanup lookup handle
- * @param handle Handle to clean up
- */
-static void
-cleanup_handle (struct RequestHandle *handle)
-{
-  struct RecordEntry *record_entry;
-  struct RecordEntry *record_tmp;
-  int i;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Cleaning up\n");
-  if (NULL != handle->name)
-    GNUNET_free (handle->name);
-  if (NULL != handle->timeout_task)
-    GNUNET_SCHEDULER_cancel (handle->timeout_task);
-  if (NULL != handle->ego_lookup)
-    GNUNET_IDENTITY_ego_lookup_cancel (handle->ego_lookup);
-  if (NULL != handle->get_default)
-    GNUNET_IDENTITY_cancel (handle->get_default);
-  if (NULL != handle->list_it)
-    GNUNET_NAMESTORE_zone_iteration_stop (handle->list_it);
-  if (NULL != handle->add_qe)
-    GNUNET_NAMESTORE_cancel (handle->add_qe);
-  if (NULL != handle->identity_handle)
-    GNUNET_IDENTITY_disconnect (handle->identity_handle);
-  if (NULL != handle->ns_handle)
-    GNUNET_NAMESTORE_disconnect (handle->ns_handle);
-  if (NULL != handle->url)
-    GNUNET_free (handle->url);
-  if (NULL != handle->value)
-    GNUNET_free (handle->value);
-  if (NULL != handle->rd)
-  {
-    for (i = 0; i < handle->rd_count; i++)
-    {
-      if (NULL != handle->rd[i].data)
-        GNUNET_free ((void*)handle->rd[i].data);
-    }
-    GNUNET_free (handle->rd);
-  }
-  if (NULL != handle->ego_name)
-    GNUNET_free (handle->ego_name);
-  for (record_entry = handle->record_head;
-       NULL != record_entry;)
-  {
-    record_tmp = record_entry;
-    record_entry = record_entry->next;
-    GNUNET_free (record_tmp);
-  }
-  GNUNET_free (handle);
-}
-
-/**
- * Create json representation of a GNSRECORD
- *
- * @param rd the GNSRECORD_Data
- */
-static json_t *
-gnsrecord_to_json (const struct GNUNET_GNSRECORD_Data *rd)
-{
-  const char *typename;
-  char *string_val;
-  const char *exp_str;
-  json_t *record_obj;
-
-  typename = GNUNET_GNSRECORD_number_to_typename (rd->record_type);
-  string_val = GNUNET_GNSRECORD_value_to_string (rd->record_type,
-                                                 rd->data,
-                                                 rd->data_size);
-
-  if (NULL == string_val)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Record of type %d malformed, skipping\n",
-                (int) rd->record_type);
-    return NULL;
-  }
-  record_obj = json_object();
-  json_object_set_new (record_obj,
-                       GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE,
-                       json_string (typename));
-  json_object_set_new (record_obj,
-                       GNUNET_REST_JSONAPI_NAMESTORE_VALUE,
-                       json_string (string_val));
-  GNUNET_free (string_val);
-
-  if (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION & rd->flags)
-  {
-    struct GNUNET_TIME_Relative time_rel;
-    time_rel.rel_value_us = rd->expiration_time;
-    exp_str = GNUNET_STRINGS_relative_time_to_string (time_rel, 1);
-  }
-  else
-  {
-    struct GNUNET_TIME_Absolute time_abs;
-    time_abs.abs_value_us = rd->expiration_time;
-    exp_str = GNUNET_STRINGS_absolute_time_to_string (time_abs);
-  }
-  json_object_set_new (record_obj, GNUNET_REST_JSONAPI_NAMESTORE_EXPIRATION, 
json_string (exp_str));
-
-  json_object_set_new (record_obj, "expired",
-                       json_boolean (GNUNET_YES == GNUNET_GNSRECORD_is_expired 
(rd)));
-  return record_obj;
-}
-
-
-/**
- * Task run on shutdown.  Cleans up everything.
- *
- * @param cls unused
- * @param tc scheduler context
- */
-static void
-do_error (void *cls,
-          const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  struct RequestHandle *handle = cls;
-  struct MHD_Response *resp = GNUNET_REST_create_json_response (NULL);
-  handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
-  cleanup_handle (handle);
-}
-
-static void
-cleanup_handle_delayed (void *cls,
-                        const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  cleanup_handle (cls);
-}
-
-/**
- * Create a response with requested records
- *
- * @param handle the RequestHandle
- */
-static void
-namestore_list_response (void *cls,
-                         const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
-                         const char *rname,
-                         unsigned int rd_len,
-                         const struct GNUNET_GNSRECORD_Data *rd)
-{
-  struct RequestHandle *handle = cls;
-  struct JsonApiResource *json_resource;
-  struct MHD_Response *resp;
-  json_t *result_array;
-  json_t *record_obj;
-  int i;
-  char *result;
-
-  if (NULL == handle->resp_object)
-    handle->resp_object = GNUNET_REST_jsonapi_object_new ();
-
-  if (NULL == rname)
-  {
-    handle->list_it = NULL;
-    //Handle response
-    if (GNUNET_SYSERR == GNUNET_REST_jsonapi_data_serialize 
(handle->resp_object, &result))
-    {
-      GNUNET_SCHEDULER_add_now (&do_error, handle);
-      return;
-    }
-    GNUNET_REST_jsonapi_object_delete (handle->resp_object);
-    resp = GNUNET_REST_create_json_response (result);
-    handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
-    GNUNET_free (result);
-    GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
-    return;
-  }
-
-  if ( (NULL != handle->name) &&
-       (0 != strcmp (handle->name, rname)) )
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "%s does not match %s\n", rname, handle->name);
-    GNUNET_NAMESTORE_zone_iterator_next (handle->list_it);
-    return;
-  }
-
-  result_array = json_array ();
-  for (i=0; i<rd_len; i++)
-  {
-    if ( (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
-         (0 != strcmp (rname, "+")) )
-      continue;
-
-    if ( (rd[i].record_type != handle->type) &&
-         (GNUNET_GNSRECORD_TYPE_ANY != handle->type) )
-      continue;
-    record_obj = gnsrecord_to_json (&(rd[i]));
-    json_array_append (result_array, record_obj);
-    json_decref (record_obj);
-  }
-
-  json_resource = GNUNET_REST_jsonapi_resource_new 
(GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO,
-                                                    rname);
-  GNUNET_REST_jsonapi_resource_add_attr (json_resource,
-                                         GNUNET_REST_JSONAPI_NAMESTORE_RECORD,
-                                         result_array);
-  GNUNET_REST_jsonapi_object_resource_add (handle->resp_object, json_resource);
-
-  json_decref (result_array);
-  GNUNET_NAMESTORE_zone_iterator_next (handle->list_it);
-}
-
-static void
-create_finished (void *cls, int32_t success, const char *emsg)
-{
-  struct RequestHandle *handle = cls;
-  struct MHD_Response *resp;
-
-  handle->add_qe = NULL;
-  if (GNUNET_YES != success)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Error storing records%s%s\n",
-                (NULL == emsg) ? "" : ": ",
-                (NULL == emsg) ? "" : emsg);
-    GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
-    return;
-  }
-  resp = GNUNET_REST_create_json_response (NULL);
-  handle->proc (handle->proc_cls, resp, MHD_HTTP_NO_CONTENT);
-  GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
-}
-
-
-/**
- * We're storing a new record; this requires
- * that no record already exists
- *
- * @param cls closure, unused
- * @param zone_key private key of the zone
- * @param rec_name name that is being mapped (at most 255 characters long)
- * @param rd_count number of entries in @a rd array
- * @param rd array of records with data to store
- */
-static void
-create_new_record_cont (void *cls,
-                        const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
-                        const char *rec_name,
-                        unsigned int rd_count,
-                        const struct GNUNET_GNSRECORD_Data *rd)
-{
-  struct RequestHandle *handle = cls;
-
-  handle->add_qe = NULL;
-  if ( (NULL != zone_key) &&
-       (0 != strcmp (rec_name, handle->name)) )
-  {
-    GNUNET_break (0);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-              "Received %u records for name `%s'\n",
-              rd_count, rec_name);
-  if (0 != rd_count)
-  {
-    handle->proc (handle->proc_cls,
-                  GNUNET_REST_create_json_response (NULL),
-                  MHD_HTTP_CONFLICT);
-    GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
-    return;
-  }
-
-  GNUNET_assert (NULL != handle->name);
-  handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
-                                                   &handle->zone_pkey,
-                                                   handle->name,
-                                                   handle->rd_count,
-                                                   handle->rd,
-                                                   &create_finished,
-                                                   handle);
-}
-
-static void
-del_finished (void *cls,
-              int32_t success,
-              const char *emsg)
-{
-  struct RequestHandle *handle = cls;
-
-  handle->add_qe = NULL;
-  if (GNUNET_NO == success)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Deleting record failed, record does not exist%s%s\n"),
-                (NULL != emsg) ? ": " : "",
-                (NULL != emsg) ? emsg : "");
-    GNUNET_SCHEDULER_add_now (&do_error, handle); //do_not_found TODO
-    return;
-  }
-  if (GNUNET_SYSERR == success)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Deleting record failed%s%s\n"),
-                (NULL != emsg) ? ": " : "",
-                (NULL != emsg) ? emsg : "");
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  handle->proc (handle->proc_cls,
-                GNUNET_REST_create_json_response (NULL),
-                MHD_HTTP_NO_CONTENT);
-  GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
-}
-
-static void
-del_cont (void *cls,
-          const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
-          const char *label,
-          unsigned int rd_count,
-          const struct GNUNET_GNSRECORD_Data *rd)
-{
-  struct RequestHandle *handle = cls;
-
-  if (0 == rd_count)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("There are no records under label `%s' that could be 
deleted.\n"),
-                label);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-
-  handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
-                                                   &handle->zone_pkey,
-                                                   handle->name,
-                                                   0, NULL,
-                                                   &del_finished,
-                                                   handle);
-}
-
-static void
-namestore_delete_cont (struct RestConnectionDataHandle *con,
-                       const char *url,
-                       void *cls)
-{
-  struct RequestHandle *handle = cls;
-
-  if (NULL == handle->name)
-  {
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-
-  handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
-                                                    &handle->zone_pkey,
-                                                    handle->name,
-                                                    &del_cont,
-                                                    handle);
-}
-
-static int
-json_to_gnsrecord (const json_t *records_json,
-                   struct GNUNET_GNSRECORD_Data **rd,
-                   unsigned int *rd_count)
-{
-  struct GNUNET_TIME_Relative etime_rel;
-  struct GNUNET_TIME_Absolute etime_abs;
-  char *value;
-  void *rdata;
-  size_t rdata_size;
-  const char *typestring;
-  const char *expirationstring;
-  int i;
-  json_t *type_json;
-  json_t *value_json;
-  json_t *record_json;
-  json_t *exp_json;
-
-  *rd_count = json_array_size (records_json);
-  *rd = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Data) * *rd_count);
-  for (i = 0; i < *rd_count; i++)
-  {
-    memset (&((*rd)[i]), 0, sizeof (struct GNUNET_GNSRECORD_Data));
-    record_json = json_array_get (records_json, i);
-    type_json = json_object_get (record_json,
-                                 GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE);
-    if (!json_is_string (type_json))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  "Type property is no string\n");
-      return GNUNET_SYSERR;
-    }
-    typestring = json_string_value (type_json);
-    (*rd)[i].record_type = GNUNET_GNSRECORD_typename_to_number (typestring);
-    if (UINT32_MAX == (*rd)[i].record_type)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Unsupported type `%s'\n"),
-                  json_string_value (type_json));
-      return GNUNET_SYSERR;
-    }
-    value_json = json_object_get (record_json,
-                                  GNUNET_REST_JSONAPI_NAMESTORE_VALUE);
-    if (!json_is_string (value_json))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  "Value property is no string\n");
-      return GNUNET_SYSERR;
-    }
-    GNUNET_asprintf (&value, "%s", json_string_value (value_json));
-    if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value ((*rd)[i].record_type,
-                                                       value,
-                                                       &rdata,
-                                                       &rdata_size))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Value `%s' invalid for record 
type `%s'\n"),
-                  value, typestring);
-      return GNUNET_SYSERR;
-    }
-    (*rd)[i].data = rdata;
-    (*rd)[i].data_size = rdata_size;
-    /**TODO
-     * if (1 == handle->is_shadow)
-     rde->flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD;
-     if (1 != handle->is_public)
-     rde->flags |= GNUNET_GNSRECORD_RF_PRIVATE;
-     */
-    exp_json = json_object_get (record_json,
-                                GNUNET_REST_JSONAPI_NAMESTORE_EXPIRATION);
-    if (!json_is_string (exp_json))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  "Expiration property is no string\n");
-      return GNUNET_SYSERR;
-    }
-    expirationstring = json_string_value (exp_json);
-    if (0 == strcmp (expirationstring, "never"))
-    {
-      (*rd)[i].expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
-    }
-    else if (GNUNET_OK ==
-             GNUNET_STRINGS_fancy_time_to_relative (expirationstring,
-                                                    &etime_rel))
-    {
-      (*rd)[i].expiration_time = etime_rel.rel_value_us;
-      (*rd)[i].flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
-    }
-    else if (GNUNET_OK ==
-             GNUNET_STRINGS_fancy_time_to_absolute (expirationstring,
-                                                    &etime_abs))
-    {
-      (*rd)[i].expiration_time = etime_abs.abs_value_us;
-    }
-    else 
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Value `%s' invalid for record 
type `%s'\n"),
-                  value, typestring);
-      return GNUNET_SYSERR;
-    }
-  }
-  return GNUNET_OK;
-}
-
-static void
-namestore_create_cont (struct RestConnectionDataHandle *con,
-                       const char *url,
-                       void *cls)
-{
-  struct RequestHandle *handle = cls;
-  struct MHD_Response *resp;
-  struct JsonApiObject *json_obj;
-  struct JsonApiResource *json_res;
-  json_t *name_json;
-  json_t *records_json;
-  char term_data[handle->data_size+1];
-
-  if (strlen (GNUNET_REST_API_NS_NAMESTORE) != strlen (handle->url))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Cannot create under %s\n", handle->url);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  if (0 >= handle->data_size)
-  {
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  term_data[handle->data_size] = '\0';
-  memcpy (term_data, handle->data, handle->data_size);
-  json_obj = GNUNET_REST_jsonapi_object_parse (term_data);
-  if (NULL == json_obj)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Unable to parse JSONAPI Object from %s\n",
-                term_data);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  if (1 != GNUNET_REST_jsonapi_object_resource_count (json_obj))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Cannot create more than 1 resource! (Got %d)\n",
-                GNUNET_REST_jsonapi_object_resource_count (json_obj));
-    GNUNET_REST_jsonapi_object_delete (json_obj);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  json_res = GNUNET_REST_jsonapi_object_get_resource (json_obj, 0);
-  if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_type (json_res,
-                                                            
GNUNET_REST_JSONAPI_NAMESTORE_RECORD))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Unsupported JSON data type\n");
-    GNUNET_REST_jsonapi_object_delete (json_obj);
-    resp = GNUNET_REST_create_json_response (NULL);
-    handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
-    cleanup_handle (handle);
-    return;
-  }
-  name_json = GNUNET_REST_jsonapi_resource_read_attr (json_res, 
GNUNET_REST_JSONAPI_KEY_ID);
-  if (!json_is_string (name_json))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Name property is no string\n");
-    GNUNET_REST_jsonapi_object_delete (json_obj); 
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  GNUNET_asprintf (&handle->name, "%s", json_string_value (name_json));
-  records_json = GNUNET_REST_jsonapi_resource_read_attr (json_res,
-                                                         
GNUNET_REST_JSONAPI_NAMESTORE_RECORD);
-  if (NULL == records_json)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "No records given\n");
-    GNUNET_REST_jsonapi_object_delete (json_obj);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  if (GNUNET_SYSERR == json_to_gnsrecord (records_json, &handle->rd, 
&handle->rd_count))
-  {
-    GNUNET_REST_jsonapi_object_delete (json_obj);
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  GNUNET_REST_jsonapi_object_delete (json_obj);
-
-  handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
-                                                    &handle->zone_pkey,
-                                                    handle->name,
-                                                    &create_new_record_cont, 
handle );
-}
-
-
-
-
-
-static void
-namestore_info_cont (struct RestConnectionDataHandle *con,
-                     const char *url,
-                     void *cls)
-{
-  struct RequestHandle *handle = cls;
-  handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
-                                                           &handle->zone_pkey,
-                                                           
&namestore_list_response,
-                                                           handle);
-}
-
-static char*
-get_name_from_url (const char* url)
-{
-  if (strlen (url) <= strlen (GNUNET_REST_API_NS_NAMESTORE))
-    return NULL;
-  return (char*)url + strlen (GNUNET_REST_API_NS_NAMESTORE) + 1;
-}
-
-/**
- * Function called with the result from the check if the namestore
- * service is actually running.  If it is, we start the actual
- * operation.
- *
- * @param cls closure with our configuration
- * @param result #GNUNET_YES if the namestore service is running
- */
-static void
-testservice_task (void *cls,
-                  int result)
-{
-  struct RequestHandle *handle = cls;
-  static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
-    {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_info_cont}, 
//list
-    {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, 
&namestore_create_cont}, //create
-    //    {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_NAMESTORE, 
&namestore_edit_cont}, //update. TODO this shoul be PATCH
-    {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE, 
&namestore_delete_cont}, //delete
-    GNUNET_REST_HANDLER_END
-  };
-
-  if (GNUNET_YES != result)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Service `%s' is not running\n"),
-                "namestore");
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-  handle->ns_handle = GNUNET_NAMESTORE_connect (cfg);
-  if (NULL == handle->ns_handle)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Failed to connect to namestore\n"));
-    GNUNET_SCHEDULER_add_now (&do_error, handle);
-    return;
-  }
-
-  if (GNUNET_NO == GNUNET_REST_handle_request (handle->conndata_handle, 
handlers, handle))
-    GNUNET_SCHEDULER_add_now (&do_error, (void*) handle);
-
-}
-
-/**
- * Callback invoked from identity service with ego information.
- * An @a ego of NULL means the ego was not found.
- *
- * @param cls closure with the configuration
- * @param ego an ego known to identity service, or NULL
- */
-static void
-identity_cb (void *cls,
-             const struct GNUNET_IDENTITY_Ego *ego)
-{
-  struct RequestHandle *handle = cls;
-  struct MHD_Response *resp;
-
-  handle->ego_lookup = NULL;
-  if (NULL == ego)
-  {
-    if (NULL != handle->ego_name)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  _("Ego `%s' not known to identity service\n"),
-                  handle->ego_name);
-    }
-    resp = GNUNET_REST_create_json_response (NULL);
-    handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
-    cleanup_handle (handle);
-    return;
-  }
-  handle->zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
-  GNUNET_CLIENT_service_test ("namestore", handle->cfg,
-                              GNUNET_TIME_UNIT_SECONDS,
-                              &testservice_task,
-                              (void *) handle);
-}
-
-static void
-default_ego_cb (void *cls,
-                struct GNUNET_IDENTITY_Ego *ego,
-                void **ctx,
-                const char *name)
-{
-  struct RequestHandle *handle = cls;
-  struct MHD_Response *resp;
-  handle->get_default = NULL;
-  if (NULL == ego)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("No default ego configured in identity service\n"));
-    resp = GNUNET_REST_create_json_response (NULL);
-    handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
-    cleanup_handle (handle);
-    return;
-  }
-  else
-  {
-    identity_cb (cls, ego);
-  }
-}
-
-static void
-id_connect_cb (void *cls,
-               struct GNUNET_IDENTITY_Ego *ego,
-               void **ctx,
-               const char *name)
-{
-  struct RequestHandle *handle = cls;
-  if (NULL == ego)
-  {
-    handle->get_default = GNUNET_IDENTITY_get (handle->identity_handle,
-                                               "namestore",
-                                               &default_ego_cb, handle);
-  }
-}
-
-static void
-testservice_id_task (void *cls, int result)
-{
-  struct RequestHandle *handle = cls;
-  struct MHD_Response *resp;
-  struct GNUNET_HashCode key;
-  char *ego;
-  char *name;
-  char *type;
-
-  if (result != GNUNET_YES)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Identity service is not running\n"));
-    resp = GNUNET_REST_create_json_response (NULL);
-    handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
-    cleanup_handle (handle);
-    return;
-  }
-  ego = NULL;
-  GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_EGO,
-                      strlen (GNUNET_REST_JSONAPI_NAMESTORE_EGO),
-                      &key);
-  if ( GNUNET_YES == 
-       GNUNET_CONTAINER_multihashmap_contains 
(handle->conndata_handle->url_param_map,
-                                               &key) )
-  {
-    ego = GNUNET_CONTAINER_multihashmap_get 
(handle->conndata_handle->url_param_map,
-                                             &key);
-  }
-
-  type = GNUNET_GNSRECORD_TYPE_ANY;
-  GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE,
-                      strlen (GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE),
-                      &key);
-  if ( GNUNET_YES == 
-       GNUNET_CONTAINER_multihashmap_contains 
(handle->conndata_handle->url_param_map,
-                                               &key) )
-  {
-    type = GNUNET_CONTAINER_multihashmap_get 
(handle->conndata_handle->url_param_map,
-                                              &key);
-  }
-  handle->type = GNUNET_GNSRECORD_typename_to_number (type);
-  name = get_name_from_url (handle->url);
-  if (NULL != ego)
-    GNUNET_asprintf (&handle->ego_name, "%s", ego);
-  if (NULL != name)
-    GNUNET_asprintf (&handle->name, "%s", name);
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", handle->ego_name);
-  if (NULL == handle->ego_name)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", handle->ego_name);
-    handle->identity_handle = GNUNET_IDENTITY_connect (handle->cfg, 
&id_connect_cb, handle);
-    if (NULL == handle->identity_handle)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Cannot connect to identity 
service\n"));
-      resp = GNUNET_REST_create_json_response (NULL);
-      handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
-      cleanup_handle (handle);
-    }
-    return;
-  }
-  handle->ego_lookup = GNUNET_IDENTITY_ego_lookup (cfg,
-                                                   handle->ego_name,
-                                                   &identity_cb,
-                                                   handle);
-}
-
-/**
- * Function processing the REST call
- *
- * @param method HTTP method
- * @param url URL of the HTTP request
- * @param data body of the HTTP request (optional)
- * @param data_size length of the body
- * @param proc callback function for the result
- * @param proc_cls closure for callback function
- * @return GNUNET_OK if request accepted
- */
-static void
-rest_identity_process_request(struct RestConnectionDataHandle *conndata_handle,
-                              GNUNET_REST_ResultProcessor proc,
-                              void *proc_cls)
-{
-  struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
-
-  handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
-  handle->proc_cls = proc_cls;
-  handle->proc = proc;
-  handle->conndata_handle = conndata_handle;
-  handle->data = conndata_handle->data;
-  handle->data_size = conndata_handle->data_size;
-  GNUNET_asprintf (&handle->url, "%s", conndata_handle->url);
-  if (handle->url[strlen (handle->url)-1] == '/')
-    handle->url[strlen (handle->url)-1] = '\0';
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Connecting...\n");
-  handle->cfg = cfg;
-  GNUNET_CLIENT_service_test ("identity",
-                              cfg,
-                              GNUNET_TIME_UNIT_SECONDS,
-                              &testservice_id_task,
-                              handle);
-  handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout,
-                                                       &do_error,
-                                                       handle);
-
-
-}
-
-/**
- * Entry point for the plugin.
- *
- * @param cls Config info
- * @return NULL on error, otherwise the plugin context
- */
-void *
-libgnunet_plugin_rest_namestore_init (void *cls)
-{
-  static struct Plugin plugin;
-  cfg = cls;
-  struct GNUNET_REST_Plugin *api;
-
-  if (NULL != plugin.cfg)
-    return NULL;                /* can only initialize once! */
-  memset (&plugin, 0, sizeof (struct Plugin));
-  plugin.cfg = cfg;
-  api = GNUNET_new (struct GNUNET_REST_Plugin);
-  api->cls = &plugin;
-  api->name = GNUNET_REST_API_NS_NAMESTORE;
-  api->process_request = &rest_identity_process_request;
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              _("Namestore REST API initialized\n"));
-  return api;
-}
-
-
-/**
- * Exit point from the plugin.
- *
- * @param cls the plugin context (as returned by "init")
- * @return always NULL
- */
-void *
-libgnunet_plugin_rest_namestore_done (void *cls)
-{
-  struct GNUNET_REST_Plugin *api = cls;
-  struct Plugin *plugin = api->cls;
-
-  plugin->cfg = NULL;
-  GNUNET_free (api);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Namestore REST plugin is finished\n");
-  return NULL;
-}
-
-/* end of plugin_rest_namestore.c */

Modified: gnunet/src/rest/Makefile.am
===================================================================
--- gnunet/src/rest/Makefile.am 2015-09-10 15:39:36 UTC (rev 36350)
+++ gnunet/src/rest/Makefile.am 2015-09-11 15:56:39 UTC (rev 36351)
@@ -20,12 +20,18 @@
   XLIBS = -lgcov
 endif
 
+REST_PLUGINS = libgnunet_plugin_rest_gns.la \
+                                                        
libgnunet_plugin_rest_identity.la \
+                                                        
libgnunet_plugin_rest_namestore.la
+
 lib_LTLIBRARIES = \
-       libgnunetrest.la
+       libgnunetrest.la \
+       $(REST_PLUGINS)
 
 libexec_PROGRAMS = \
  gnunet-rest-server
 
+
 gnunet_rest_server_SOURCES = \
  gnunet-rest-server.c
 
@@ -41,3 +47,34 @@
 libgnunetrest_la_LDFLAGS = \
   $(GN_LIB_LDFLAGS) \
   -version-info 0:0:0
+
+libgnunet_plugin_rest_gns_la_SOURCES = \
+  plugin_rest_gns.c
+libgnunet_plugin_rest_gns_la_LIBADD = \
+  $(top_builddir)/src/gns/libgnunetgns.la \
+  $(top_builddir)/src/identity/libgnunetidentity.la \
+  $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
+  $(LTLIBINTL) -ljansson -lmicrohttpd
+libgnunet_plugin_rest_gns_la_LDFLAGS = \
+ $(GN_PLUGIN_LDFLAGS)
+
+
+libgnunet_plugin_rest_identity_la_SOURCES = \
+  plugin_rest_namestore.c
+libgnunet_plugin_rest_identity_la_LIBADD = \
+       $(top_builddir)/src/identity/libgnunetidentity.la \
+  $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
+  $(LTLIBINTL) -ljansson -lmicrohttpd
+libgnunet_plugin_rest_identity_la_LDFLAGS = \
+ $(GN_PLUGIN_LDFLAGS)
+
+libgnunet_plugin_rest_namestore_la_SOURCES = \
+  plugin_rest_namestore.c
+libgnunet_plugin_rest_namestore_la_LIBADD = \
+  $(top_builddir)/src/namestore/libgnunetnamestore.la \
+       $(top_builddir)/src/identity/libgnunetidentity.la \
+  $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
+  $(LTLIBINTL) -ljansson -lmicrohttpd
+libgnunet_plugin_rest_namestore_la_LDFLAGS = \
+ $(GN_PLUGIN_LDFLAGS)
+

Copied: gnunet/src/rest/plugin_rest_gns.c (from rev 36350, 
gnunet/src/gns/plugin_rest_gns.c)
===================================================================
--- gnunet/src/rest/plugin_rest_gns.c                           (rev 0)
+++ gnunet/src/rest/plugin_rest_gns.c   2015-09-11 15:56:39 UTC (rev 36351)
@@ -0,0 +1,720 @@
+/*
+   This file is part of GNUnet.
+   Copyright (C) 2012-2015 Christian Grothoff (and other contributing authors)
+
+   GNUnet is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNUnet; see the file COPYING.  If not, write to the
+   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.
+   */
+/**
+ * @author Martin Schanzenbach
+ * @file gns/plugin_rest_gns.c
+ * @brief GNUnet GNS REST plugin
+ *
+ */
+
+#include "platform.h"
+#include "gnunet_rest_plugin.h"
+#include <gnunet_dnsparser_lib.h>
+#include <gnunet_identity_service.h>
+#include <gnunet_gnsrecord_lib.h>
+#include <gnunet_namestore_service.h>
+#include <gnunet_gns_service.h>
+#include <gnunet_rest_lib.h>
+#include <jansson.h>
+
+#define GNUNET_REST_API_NS_GNS "/gns"
+
+#define GNUNET_REST_JSONAPI_GNS_RECORD_TYPE "record_type"
+
+#define GNUNET_REST_JSONAPI_GNS_TYPEINFO "gns_name"
+
+#define GNUNET_REST_JSONAPI_GNS_RECORD "records"
+
+#define GNUNET_REST_JSONAPI_GNS_EGO "ego"
+
+#define GNUNET_REST_JSONAPI_GNS_PKEY "pkey"
+
+#define GNUNET_REST_JSONAPI_GNS_OPTIONS "options"
+
+/**
+ * @brief struct returned by the initialization function of the plugin
+ */
+struct Plugin
+{
+  const struct GNUNET_CONFIGURATION_Handle *cfg;
+};
+
+const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+struct LookupHandle
+{
+  /**
+   * Handle to GNS service.
+   */
+  struct GNUNET_GNS_Handle *gns;
+
+  /**
+   * Desired timeout for the lookup (default is no timeout).
+   */
+  struct GNUNET_TIME_Relative timeout;
+
+  /**
+   * Handle to lookup request
+   */
+  struct GNUNET_GNS_LookupRequest *lookup_request;
+
+  /**
+   * Lookup an ego with the identity service.
+   */
+  struct GNUNET_IDENTITY_EgoLookup *el;
+
+  /**
+   * Handle for identity service.
+   */
+  struct GNUNET_IDENTITY_Handle *identity;
+
+  /**
+   * Active operation on identity service.
+   */
+  struct GNUNET_IDENTITY_Operation *id_op;
+
+  /**
+   * ID of a task associated with the resolution process.
+   */
+  struct GNUNET_SCHEDULER_Task * timeout_task;
+
+  /**
+   * The root of the received JSON or NULL
+   */
+  json_t *json_root;
+
+  /**
+   * The plugin result processor
+   */
+  GNUNET_REST_ResultProcessor proc;
+
+  /**
+   * The closure of the result processor
+   */
+  void *proc_cls;
+
+  /**
+   * The name to look up
+   */
+  char *name;
+
+  /**
+   * The ego to use
+   * In string representation from JSON
+   */
+  const char *ego_str;
+
+  /**
+   * The Pkey to use
+   * In string representation from JSON
+   */
+  const char *pkey_str;
+
+  /**
+   * The record type
+   */
+  int type;
+
+  /**
+   * The public key of to use for lookup
+   */
+  struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
+
+  /**
+   * The public key to use for lookup
+   */
+  struct GNUNET_CRYPTO_EcdsaPublicKey pkeym;
+
+  /**
+   * The resolver options
+   */
+  enum GNUNET_GNS_LocalOptions options;
+
+  /**
+   * the shorten key
+   */
+  struct GNUNET_CRYPTO_EcdsaPrivateKey shorten_key;
+
+};
+
+
+/**
+ * Cleanup lookup handle.
+ *
+ * @param handle Handle to clean up
+ */
+static void
+cleanup_handle (struct LookupHandle *handle)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Cleaning up\n");
+  if (NULL != handle->json_root)
+    json_decref (handle->json_root);
+
+  if (NULL != handle->name)
+    GNUNET_free (handle->name);
+  if (NULL != handle->el)
+  {
+    GNUNET_IDENTITY_ego_lookup_cancel (handle->el);
+    handle->el = NULL;
+  }
+  if (NULL != handle->id_op)
+  {
+    GNUNET_IDENTITY_cancel (handle->id_op);
+    handle->id_op = NULL;
+  }
+  if (NULL != handle->lookup_request)
+  {
+    GNUNET_GNS_lookup_cancel (handle->lookup_request);
+    handle->lookup_request = NULL;
+  }
+  if (NULL != handle->identity)
+  {
+    GNUNET_IDENTITY_disconnect (handle->identity);
+    handle->identity = NULL;
+  }
+  if (NULL != handle->gns)
+  {
+    GNUNET_GNS_disconnect (handle->gns);
+    handle->gns = NULL;
+  }
+
+  if (NULL != handle->timeout_task)
+  {
+    GNUNET_SCHEDULER_cancel (handle->timeout_task);
+  }
+  GNUNET_free (handle);
+}
+
+
+/**
+ * Task run on shutdown.  Cleans up everything.
+ *
+ * @param cls unused
+ * @param tc scheduler context
+ */
+static void
+do_error (void *cls,
+          const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct LookupHandle *handle = cls;
+  struct MHD_Response *resp = GNUNET_REST_create_json_response (NULL);
+  handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
+  cleanup_handle (handle);
+}
+
+
+/**
+ * Create json representation of a GNSRECORD
+ *
+ * @param rd the GNSRECORD_Data
+ */
+static json_t *
+gnsrecord_to_json (const struct GNUNET_GNSRECORD_Data *rd)
+{
+  const char *typename;
+  char *string_val;
+  const char *exp_str;
+  json_t *record_obj;
+
+  typename = GNUNET_GNSRECORD_number_to_typename (rd->record_type);
+  string_val = GNUNET_GNSRECORD_value_to_string (rd->record_type,
+                                                 rd->data,
+                                                 rd->data_size);
+
+  if (NULL == string_val)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Record of type %d malformed, skipping\n",
+                (int) rd->record_type);
+    return NULL;
+  }
+  record_obj = json_object();
+  json_object_set_new (record_obj, "type", json_string (typename));
+  json_object_set_new (record_obj, "value", json_string (string_val));
+  GNUNET_free (string_val);
+
+  if (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION & rd->flags)
+  {
+    struct GNUNET_TIME_Relative time_rel;
+    time_rel.rel_value_us = rd->expiration_time;
+    exp_str = GNUNET_STRINGS_relative_time_to_string (time_rel, 1);
+  }
+  else
+  {
+    struct GNUNET_TIME_Absolute time_abs;
+    time_abs.abs_value_us = rd->expiration_time;
+    exp_str = GNUNET_STRINGS_absolute_time_to_string (time_abs);
+  }
+  json_object_set_new (record_obj, "expiration_time", json_string (exp_str));
+
+  json_object_set_new (record_obj, "expired",
+                       json_boolean (GNUNET_YES == GNUNET_GNSRECORD_is_expired 
(rd)));
+  return record_obj;
+}
+
+/**
+ * Function called with the result of a GNS lookup.
+ *
+ * @param cls the 'const char *' name that was resolved
+ * @param rd_count number of records returned
+ * @param rd array of @a rd_count records with the results
+ */
+static void
+process_lookup_result (void *cls, uint32_t rd_count,
+                       const struct GNUNET_GNSRECORD_Data *rd)
+{
+  struct LookupHandle *handle = cls;
+  struct MHD_Response *resp;
+  struct JsonApiObject *json_object;
+  struct JsonApiResource *json_resource;
+  uint32_t i;
+  char *result;
+  json_t *result_array;
+  json_t *record_obj;
+
+  result_array = json_array();
+  json_object = GNUNET_REST_jsonapi_object_new ();
+  json_resource = GNUNET_REST_jsonapi_resource_new 
(GNUNET_REST_JSONAPI_GNS_TYPEINFO, handle->name);
+  handle->lookup_request = NULL;
+  for (i=0; i<rd_count; i++)
+  {
+    if ( (rd[i].record_type != handle->type) &&
+         (GNUNET_GNSRECORD_TYPE_ANY != handle->type) )
+      continue;
+    record_obj = gnsrecord_to_json (&(rd[i]));
+    json_array_append (result_array, record_obj);
+    json_decref (record_obj);
+  }
+  GNUNET_REST_jsonapi_resource_add_attr (json_resource,
+                                         GNUNET_REST_JSONAPI_GNS_RECORD,
+                                         result_array);
+  GNUNET_REST_jsonapi_object_resource_add (json_object, json_resource);
+  GNUNET_REST_jsonapi_data_serialize (json_object, &result);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result);
+  json_decref (result_array);
+  GNUNET_REST_jsonapi_object_delete (json_object);
+  resp = GNUNET_REST_create_json_response (result);
+  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
+  GNUNET_free (result);
+  cleanup_handle (handle);
+}
+
+
+/**
+ * Perform the actual resolution, starting with the zone
+ * identified by the given public key and the shorten zone.
+ *
+ * @param pkey public key to use for the zone, can be NULL
+ * @param shorten_key private key used for shortening, can be NULL
+ */
+static void
+lookup_with_keys (struct LookupHandle *handle, const struct 
GNUNET_CRYPTO_EcdsaPrivateKey *shorten_key)
+{
+  if (UINT32_MAX == handle->type)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Invalid typename specified, assuming `ANY'\n"));
+    handle->type = GNUNET_GNSRECORD_TYPE_ANY;
+  }
+  if (NULL != handle->name)
+  {
+    handle->lookup_request = GNUNET_GNS_lookup (handle->gns,
+                                                handle->name,
+                                                &handle->pkey,
+                                                handle->type,
+                                                handle->options,
+                                                shorten_key,
+                                                &process_lookup_result,
+                                                handle);
+  }
+  else
+  {
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+}
+
+/**
+ * Method called to with the ego we are to use for shortening
+ * during the lookup.
+ *
+ * @param cls closure contains the public key to use
+ * @param ego ego handle, NULL if not found
+ * @param ctx context for application to store data for this ego
+ *                 (during the lifetime of this process, initially NULL)
+ * @param name name assigned by the user for this ego,
+ *                   NULL if the user just deleted the ego and it
+ *                   must thus no longer be used
+ */
+static void
+identity_shorten_cb (void *cls,
+                     struct GNUNET_IDENTITY_Ego *ego,
+                     void **ctx,
+                     const char *name)
+{
+  struct LookupHandle *handle = cls;
+
+  handle->id_op = NULL;
+  if (NULL == ego)
+    lookup_with_keys (handle, NULL);
+  else
+    lookup_with_keys (handle,
+                      GNUNET_IDENTITY_ego_get_private_key (ego));
+}
+
+/**
+ * Perform the actual resolution, starting with the zone
+ * identified by the given public key.
+ *
+ * @param pkey public key to use for the zone
+ */
+static void
+lookup_with_public_key (struct LookupHandle *handle)
+{
+  handle->pkeym = handle->pkey;
+  GNUNET_break (NULL == handle->id_op);
+  handle->id_op = GNUNET_IDENTITY_get (handle->identity,
+                                       "gns-short",
+                                       &identity_shorten_cb,
+                                       handle);
+  if (NULL == handle->id_op)
+  {
+    GNUNET_break (0);
+    lookup_with_keys (handle, NULL);
+  }
+}
+
+/**
+ * Method called to with the ego we are to use for the lookup,
+ * when the ego is determined by a name.
+ *
+ * @param cls closure (NULL, unused)
+ * @param ego ego handle, NULL if not found
+ */
+static void
+identity_zone_cb (void *cls,
+                  const struct GNUNET_IDENTITY_Ego *ego)
+{
+  struct LookupHandle *handle = cls;
+
+  handle->el = NULL;
+  if (NULL == ego)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Ego for not found, cannot perform lookup.\n"));
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  else
+  {
+    GNUNET_IDENTITY_ego_get_public_key (ego, &handle->pkey);
+    lookup_with_public_key (handle);
+  }
+  json_decref(handle->json_root);
+}
+
+/**
+ * Method called to with the ego we are to use for the lookup,
+ * when the ego is the one for the default master zone.
+ *
+ * @param cls closure (NULL, unused)
+ * @param ego ego handle, NULL if not found
+ * @param ctx context for application to store data for this ego
+ *                 (during the lifetime of this process, initially NULL)
+ * @param name name assigned by the user for this ego,
+ *                   NULL if the user just deleted the ego and it
+ *                   must thus no longer be used
+ */
+static void
+identity_master_cb (void *cls,
+                    struct GNUNET_IDENTITY_Ego *ego,
+                    void **ctx,
+                    const char *name)
+{
+  const char *dot;
+  struct LookupHandle *handle = cls;
+
+  handle->id_op = NULL;
+  if (NULL == ego)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Ego for `gns-master' not found, cannot perform lookup.  Did 
you run gnunet-gns-import.sh?\n"));
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  GNUNET_IDENTITY_ego_get_public_key (ego, &handle->pkey);
+  /* main name is our own master zone, do no look for that in the DHT */
+  handle->options = GNUNET_GNS_LO_LOCAL_MASTER;
+  /* if the name is of the form 'label.gnu', never go to the DHT */
+  dot = NULL;
+  if (NULL != handle->name)
+    dot = strchr (handle->name, '.');
+  if ( (NULL != dot) &&
+       (0 == strcasecmp (dot, ".gnu")) )
+    handle->options = GNUNET_GNS_LO_NO_DHT;
+  lookup_with_public_key (handle);
+}
+
+/**
+ * Parse REST uri for name and record type
+ *
+ * @param url Url to parse
+ * @param handle lookup handle to populate
+ * @return GNUNET_SYSERR on error
+ */
+static int
+parse_url (const char *url, struct LookupHandle *handle)
+{
+  char *name;
+  char tmp_url[strlen(url)+1];
+  char *tok;
+
+  strcpy (tmp_url, url);
+  tok = strtok ((char*)tmp_url, "/");
+  if (NULL == tok)
+    return GNUNET_SYSERR;
+  name = strtok (NULL, "/");
+  if (NULL == name)
+    return GNUNET_SYSERR;
+  GNUNET_asprintf (&handle->name,
+                   "%s",
+                   name);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Got name: %s\n", handle->name);
+  return GNUNET_OK;
+}
+
+static void
+get_gns_cont (struct RestConnectionDataHandle *conndata_handle,
+              const char* url,
+              void *cls)
+{
+  struct LookupHandle *handle = cls;
+  struct GNUNET_HashCode key;
+
+  //parse name and type from url
+  if (GNUNET_OK != parse_url (url, handle))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing url...\n");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Connecting...\n");
+  handle->gns = GNUNET_GNS_connect (cfg);
+  handle->identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
+  handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout,
+                                                       &do_error, handle);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Connected\n");
+  if (NULL == handle->gns)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Connecting to GNS failed\n");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_GNS_OPTIONS,
+                      strlen (GNUNET_REST_JSONAPI_GNS_OPTIONS),
+                      &key);
+  handle->options = GNUNET_GNS_LO_DEFAULT;
+  if ( GNUNET_YES ==
+       GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map,
+                                               &key) )
+  {
+    handle->options = GNUNET_GNS_LO_DEFAULT;//TODO(char*) 
GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
+    //&key);
+  }
+  GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_GNS_RECORD_TYPE,
+                      strlen (GNUNET_REST_JSONAPI_GNS_RECORD_TYPE),
+                      &key);
+  if ( GNUNET_YES ==
+       GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map,
+                                               &key) )
+  {
+    handle->type = GNUNET_GNSRECORD_typename_to_number 
+      (GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map,
+                                          &key));
+  }
+  else
+    handle->type = GNUNET_GNSRECORD_TYPE_ANY;
+
+  GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_GNS_PKEY,
+                      strlen (GNUNET_REST_JSONAPI_GNS_PKEY),
+                      &key);
+  if ( GNUNET_YES ==
+       GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map,
+                                               &key) )
+  {
+    handle->pkey_str = GNUNET_CONTAINER_multihashmap_get 
(conndata_handle->url_param_map,
+                                                          &key);
+    if (GNUNET_OK !=
+        GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->pkey_str,
+                                                    strlen(handle->pkey_str),
+                                                    &(handle->pkey)))
+    {
+      GNUNET_SCHEDULER_add_now (&do_error, handle);
+      return;
+    }
+    lookup_with_public_key (handle);
+    return;
+  }
+  GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_GNS_EGO,
+                      strlen (GNUNET_REST_JSONAPI_GNS_EGO),
+                      &key);
+  if ( GNUNET_YES ==
+       GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map,
+                                               &key) )
+  {
+    handle->ego_str = GNUNET_CONTAINER_multihashmap_get 
(conndata_handle->url_param_map,
+                                                         &key);
+    handle->el = GNUNET_IDENTITY_ego_lookup (cfg,
+                                             handle->ego_str,
+                                             &identity_zone_cb,
+                                             handle);
+    return;
+  }
+  if ( (NULL != handle->name) &&
+       (strlen (handle->name) > 4) &&
+       (0 == strcmp (".zkey",
+                     &handle->name[strlen (handle->name) - 4])) )
+  {
+    GNUNET_CRYPTO_ecdsa_key_get_public
+      (GNUNET_CRYPTO_ecdsa_key_get_anonymous (),
+       &(handle->pkey));
+    lookup_with_public_key (handle);
+  }
+  else
+  {
+    GNUNET_break (NULL == handle->id_op);
+    handle->id_op = GNUNET_IDENTITY_get (handle->identity,
+                                         "gns-master",
+                                         &identity_master_cb,
+                                         handle);
+    GNUNET_assert (NULL != handle->id_op);
+  }
+}
+
+/**
+ * Handle rest request
+ *
+ * @param handle the lookup handle
+ */
+static void
+options_cont (struct RestConnectionDataHandle *con_handle,
+              const char* url,
+              void *cls)
+{
+  struct MHD_Response *resp;
+  struct LookupHandle *handle = cls;
+
+  //For GNS, independent of path return all options
+  resp = GNUNET_REST_create_json_response (NULL);
+  MHD_add_response_header (resp,
+                           "Access-Control-Allow-Methods",
+                           MHD_HTTP_METHOD_GET);
+  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
+  cleanup_handle (handle);
+  return;
+}
+
+
+/**
+ * Function processing the REST call
+ *
+ * @param method HTTP method
+ * @param url URL of the HTTP request
+ * @param data body of the HTTP request (optional)
+ * @param data_size length of the body
+ * @param proc callback function for the result
+ * @param proc_cls closure for callback function
+ * @return GNUNET_OK if request accepted
+ */
+static void
+rest_gns_process_request(struct RestConnectionDataHandle *conndata_handle,
+                         GNUNET_REST_ResultProcessor proc,
+                         void *proc_cls)
+{
+  struct LookupHandle *handle = GNUNET_new (struct LookupHandle);
+
+  handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
+  handle->proc_cls = proc_cls;
+  handle->proc = proc;
+
+  static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
+    {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_GNS, &get_gns_cont},
+    {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_GNS, &options_cont},
+    GNUNET_REST_HANDLER_END
+  };
+
+  if (GNUNET_NO == GNUNET_REST_handle_request (conndata_handle, handlers, 
handle))
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+}
+
+
+
+/**
+ * Entry point for the plugin.
+ *
+ * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
+ * @return NULL on error, otherwise the plugin context
+ */
+void *
+libgnunet_plugin_rest_gns_init (void *cls)
+{
+  static struct Plugin plugin;
+  cfg = cls;
+  struct GNUNET_REST_Plugin *api;
+
+  if (NULL != plugin.cfg)
+    return NULL;                /* can only initialize once! */
+  memset (&plugin, 0, sizeof (struct Plugin));
+  plugin.cfg = cfg;
+  api = GNUNET_new (struct GNUNET_REST_Plugin);
+  api->cls = &plugin;
+  api->name = GNUNET_REST_API_NS_GNS;
+  api->process_request = &rest_gns_process_request;
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              _("GNS REST API initialized\n"));
+  return api;
+}
+
+
+/**
+ * Exit point from the plugin.
+ *
+ * @param cls the plugin context (as returned by "init")
+ * @return always NULL
+ */
+void *
+libgnunet_plugin_rest_gns_done (void *cls)
+{
+  struct GNUNET_REST_Plugin *api = cls;
+  struct Plugin *plugin = api->cls;
+
+  plugin->cfg = NULL;
+  GNUNET_free (api);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "GNS REST plugin is finished\n");
+  return NULL;
+}
+
+/* end of plugin_rest_gns.c */

Copied: gnunet/src/rest/plugin_rest_identity.c (from rev 36350, 
gnunet/src/identity/plugin_rest_identity.c)
===================================================================
--- gnunet/src/rest/plugin_rest_identity.c                              (rev 0)
+++ gnunet/src/rest/plugin_rest_identity.c      2015-09-11 15:56:39 UTC (rev 
36351)
@@ -0,0 +1,1080 @@
+/*
+   This file is part of GNUnet.
+   Copyright (C) 2012-2015 Christian Grothoff (and other contributing authors)
+
+   GNUnet is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNUnet; see the file COPYING.  If not, write to the
+   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.
+   */
+/**
+ * @author Martin Schanzenbach
+ * @file identity/plugin_rest_identity.c
+ * @brief GNUnet Namestore REST plugin
+ *
+ */
+
+#include "platform.h"
+#include "gnunet_rest_plugin.h"
+#include "gnunet_identity_service.h"
+#include "gnunet_rest_lib.h"
+#include "microhttpd.h"
+#include <jansson.h>
+#include "gnunet_signatures.h"
+
+/**
+ * REST root namespace
+ */
+#define GNUNET_REST_API_NS_IDENTITY "/identity"
+
+/**
+ * State while collecting all egos
+ */
+#define ID_REST_STATE_INIT 0
+
+/**
+ * Done collecting egos
+ */
+#define ID_REST_STATE_POST_INIT 1
+
+/**
+ * Resource type
+ */
+#define GNUNET_REST_JSONAPI_IDENTITY_EGO "ego"
+
+/**
+ * Name attribute
+ */
+#define GNUNET_REST_JSONAPI_IDENTITY_NAME "name"
+
+/**
+ * Attribute to rename "name" TODO we changed id to the pubkey
+ * so this can be unified with "name"
+ */
+#define GNUNET_REST_JSONAPI_IDENTITY_NEWNAME "newname"
+
+/**
+ * URL parameter to change the subsytem for ego
+ */
+#define GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM "subsystem"
+
+
+/**
+ * URL parameter to create a GNUid token for a specific audience
+ */
+#define GNUNET_REST_JSONAPI_IDENTITY_CREATE_TOKEN "create_token_for"
+
+/**
+ * Attribute containing the GNUid token if
+ * GNUNET_REST_JSONAPI_IDENTITY_CREATE_TOKEN was requested
+ */
+#define GNUNET_REST_JSONAPI_IDENTITY_GNUID "gnuid_token"
+
+/**
+ * Error messages
+ */
+#define GNUNET_REST_ERROR_RESOURCE_INVALID "Resource location invalid"
+#define GNUNET_REST_ERROR_NO_DATA "No data"
+
+/**
+ * GNUid token lifetime
+ */
+#define GNUNET_GNUID_TOKEN_EXPIRATION_MICROSECONDS 300000000
+
+/**
+ * The configuration handle
+ */
+const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+/**
+ * HTTP methods allows for this plugin
+ */
+static char* allow_methods;
+
+/**
+ * @brief struct returned by the initialization function of the plugin
+ */
+struct Plugin
+{
+  const struct GNUNET_CONFIGURATION_Handle *cfg;
+};
+
+/**
+ * The ego list
+ */
+struct EgoEntry
+{
+  /**
+   * DLL
+   */
+  struct EgoEntry *next;
+  
+  /**
+   * DLL
+   */
+  struct EgoEntry *prev;
+  
+  /**
+   * Ego Identifier
+   */
+  char *identifier;
+
+  /**
+   * Public key string
+   */
+  char *keystring;
+  
+  /**
+   * The Ego
+   */
+  struct GNUNET_IDENTITY_Ego *ego;
+};
+
+
+struct RequestHandle
+{
+  /**
+   * Ego list
+   */
+  struct EgoEntry *ego_head;
+
+  /**
+   * Ego list
+   */
+  struct EgoEntry *ego_tail;
+
+  /**
+   * Handle to the rest connection
+   */
+  struct RestConnectionDataHandle *conndata_handle;
+  
+  /**
+   * The processing state
+   */
+  int state;
+
+  /**
+   * Handle to GNS service.
+   */
+  struct GNUNET_IDENTITY_Handle *identity_handle;
+
+  /**
+   * IDENTITY Operation
+   */
+  struct GNUNET_IDENTITY_Operation *op;
+
+  /**
+   * Desired timeout for the lookup (default is no timeout).
+   */
+  struct GNUNET_TIME_Relative timeout;
+
+  /**
+   * ID of a task associated with the resolution process.
+   */
+  struct GNUNET_SCHEDULER_Task * timeout_task;    
+
+  /**
+   * The plugin result processor
+   */
+  GNUNET_REST_ResultProcessor proc;
+
+  /**
+   * The closure of the result processor
+   */
+  void *proc_cls;
+
+  /**
+   * The name to look up
+   */
+  char *name;
+
+  /**
+   * The subsystem set from REST
+   */
+  char *subsys;
+
+  /**
+   * The url
+   */
+  char *url;
+
+  /**
+   * The data from the REST request
+   */
+  const char* data;
+
+  /**
+   * the length of the REST data
+   */
+  size_t data_size;
+
+  /**
+   * HTTP method
+   */
+  const char* method;
+
+  /**
+   * Error response message
+   */
+  char *emsg;
+
+};
+
+
+/**
+ * Cleanup lookup handle
+ * @param handle Handle to clean up
+ */
+static void
+cleanup_handle (struct RequestHandle *handle)
+{
+  struct EgoEntry *ego_entry;
+  struct EgoEntry *ego_tmp;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Cleaning up\n");
+  if (NULL != handle->name)
+    GNUNET_free (handle->name);
+  if (NULL != handle->timeout_task)
+    GNUNET_SCHEDULER_cancel (handle->timeout_task);
+  if (NULL != handle->identity_handle)
+    GNUNET_IDENTITY_disconnect (handle->identity_handle);
+  if (NULL != handle->subsys)
+    GNUNET_free (handle->subsys);
+  if (NULL != handle->url)
+    GNUNET_free (handle->url);
+  if (NULL != handle->emsg)
+    GNUNET_free (handle->emsg);
+  for (ego_entry = handle->ego_head;
+       NULL != ego_entry;)
+  {
+    ego_tmp = ego_entry;
+    ego_entry = ego_entry->next;
+    GNUNET_free (ego_tmp->identifier);
+    GNUNET_free (ego_tmp->keystring);
+    GNUNET_free (ego_tmp);
+  }
+  GNUNET_free (handle);
+}
+
+
+/**
+ * Task run on shutdown.  Cleans up everything.
+ *
+ * @param cls unused
+ * @param tc scheduler context
+ */
+static void
+do_error (void *cls,
+          const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct RequestHandle *handle = cls;
+  struct MHD_Response *resp;
+  char *json_error;
+
+  GNUNET_asprintf (&json_error,
+                   "{Error while processing request: %s}",
+                   &handle->emsg);
+
+  resp = GNUNET_REST_create_json_response (json_error);
+  handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
+  cleanup_handle (handle);
+  GNUNET_free (json_error);
+}
+
+/**
+ * Build a GNUid token for identity
+ * @param handle the handle
+ * @param ego_entry the ego to build the token for
+ * @param name name of the ego
+ * @param token_aud token audience
+ * @param token the resulting gnuid token
+ */
+static void
+make_gnuid_token (struct RequestHandle *handle,
+                  struct EgoEntry *ego_entry,
+                  const char *name,
+                  const char *token_aud,
+                  char **token)
+{
+  uint64_t time;
+  uint64_t lbl;
+  char *header_str;
+  char *payload_str;
+  char *header_base64;
+  char *payload_base64;
+  char *sig_str;
+  char *lbl_str;
+  json_t *header;
+  json_t *payload;
+  const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
+  struct GNUNET_CRYPTO_EcdsaSignature sig;
+  struct GNUNET_CRYPTO_EccSignaturePurpose *purpose;
+
+  time = GNUNET_TIME_absolute_get().abs_value_us;
+  lbl = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX);
+  GNUNET_STRINGS_base64_encode ((char*)&lbl, sizeof (uint64_t), &lbl_str);
+
+  header = json_object ();
+  json_object_set_new (header, "alg", json_string ("ED512"));
+  json_object_set_new (header, "typ", json_string ("JWT"));
+  
+  payload = json_object ();
+  json_object_set_new (payload, "iss", json_string (ego_entry->keystring));
+  json_object_set_new (payload, "lbl", json_string (lbl_str));
+  json_object_set_new (payload, "sub", json_string (name));
+  json_object_set_new (payload, "nbf", json_integer (time));
+  json_object_set_new (payload, "iat", json_integer (time));
+  json_object_set_new (payload, "exp", json_integer 
(time+GNUNET_GNUID_TOKEN_EXPIRATION_MICROSECONDS));
+  json_object_set_new (payload, "aud", json_string (token_aud));
+  header_str = json_dumps (header, JSON_COMPACT);
+  GNUNET_STRINGS_base64_encode (header_str,
+                                strlen (header_str),
+                                &header_base64);
+  char* padding = strtok(header_base64, "=");
+  while (NULL != padding)
+    padding = strtok(NULL, "=");
+
+  payload_str = json_dumps (payload, JSON_COMPACT);
+  GNUNET_STRINGS_base64_encode (payload_str,
+                                strlen (payload_str),
+                                &payload_base64);
+  padding = strtok(payload_base64, "=");
+  while (NULL != padding)
+    padding = strtok(NULL, "=");
+
+  GNUNET_asprintf (token, "%s,%s", header_base64, payload_base64);
+  priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
+  purpose = 
+    GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + 
+                   strlen (*token));
+  purpose->size = 
+    htonl (strlen (*token) + sizeof (struct 
GNUNET_CRYPTO_EccSignaturePurpose));
+  purpose->purpose = htonl(GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN);
+  memcpy (&purpose[1], *token, strlen (*token));
+  if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_sign (priv_key,
+                                             purpose,
+                                             &sig))
+    GNUNET_break(0);
+  GNUNET_free (*token);
+  sig_str = GNUNET_STRINGS_data_to_string_alloc (&sig,
+                                                 sizeof (struct 
GNUNET_CRYPTO_EcdsaSignature));
+  GNUNET_asprintf (token, "%s.%s.%s",
+                   header_base64, payload_base64, sig_str);
+  GNUNET_free (sig_str);
+  GNUNET_free (header_str);
+  GNUNET_free (header_base64);
+  GNUNET_free (payload_str);
+  GNUNET_free (payload_base64);
+  GNUNET_free (purpose);
+  GNUNET_free (lbl_str);
+  json_decref (header);
+  json_decref (payload);
+}
+
+/**
+ * Callback for IDENTITY_get()
+ *
+ * @param cls the RequestHandle
+ * @param ego the Ego found
+ * @param ctx the context
+ * @param name the id of the ego
+ */
+static void
+get_ego_for_subsys (void *cls,
+                    struct GNUNET_IDENTITY_Ego *ego,
+                    void **ctx,
+                    const char *name)
+{
+  struct RequestHandle *handle = cls;
+  struct JsonApiObject *json_object;
+  struct JsonApiResource *json_resource;
+  struct EgoEntry *ego_entry;
+  struct MHD_Response *resp;
+  json_t *name_json;
+  char *result_str;
+
+  json_object = GNUNET_REST_jsonapi_object_new ();
+
+  for (ego_entry = handle->ego_head;
+       NULL != ego_entry;
+       ego_entry = ego_entry->next)
+  {
+    if ( (NULL != name) && (0 != strcmp (name, ego_entry->identifier)) )
+      continue;
+    if (NULL == name)
+      continue;
+    json_resource = GNUNET_REST_jsonapi_resource_new
+      (GNUNET_REST_JSONAPI_IDENTITY_EGO, ego_entry->keystring);
+    name_json = json_string (ego_entry->identifier);
+    GNUNET_REST_jsonapi_resource_add_attr (json_resource,
+                                           GNUNET_REST_JSONAPI_IDENTITY_NAME,
+                                           name_json);
+    json_decref (name_json);
+    GNUNET_REST_jsonapi_object_resource_add (json_object, json_resource);
+    break;
+  }
+  if (0 == GNUNET_REST_jsonapi_object_resource_count (json_object))
+  {
+    GNUNET_REST_jsonapi_object_delete (json_object);
+    handle->emsg = GNUNET_strdup("No identity matches results!");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  GNUNET_REST_jsonapi_data_serialize (json_object, &result_str);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
+  resp = GNUNET_REST_create_json_response (result_str);
+  GNUNET_REST_jsonapi_object_delete (json_object);
+  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
+  GNUNET_free (result_str);
+  cleanup_handle (handle);
+}
+
+/**
+ * Create a response with requested ego(s)
+ *
+ * @param con the Rest handle
+ * @param url the requested url
+ * @param cls the request handle
+ */
+static void
+ego_info_response (struct RestConnectionDataHandle *con,
+                   const char *url,
+                   void *cls)
+{
+  const char *egoname;
+  char *result_str;
+  char *subsys_val;
+  char *create_token_for;
+  char *token;
+  char *keystring;
+  struct RequestHandle *handle = cls;
+  struct EgoEntry *ego_entry;
+  struct GNUNET_HashCode key;
+  struct MHD_Response *resp;
+  struct JsonApiObject *json_object;
+  struct JsonApiResource *json_resource;
+  json_t *name_str;
+  json_t *token_str;
+
+  if (GNUNET_NO == GNUNET_REST_namespace_match (handle->url, 
GNUNET_REST_API_NS_IDENTITY))
+  {
+    resp = GNUNET_REST_create_json_response (NULL);
+    handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
+    cleanup_handle (handle);
+    return;
+  }
+  egoname = NULL;
+  keystring = NULL;
+  if (strlen (GNUNET_REST_API_NS_IDENTITY) < strlen (handle->url))
+  {
+    keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY)+1];
+    //Return all egos
+    for (ego_entry = handle->ego_head;
+         NULL != ego_entry;
+         ego_entry = ego_entry->next)
+    {
+      if ( (NULL != keystring) && (0 != strcmp (keystring, 
ego_entry->keystring)) )
+        continue;
+      egoname = ego_entry->identifier;
+    }
+  }
+
+  if ( NULL == egoname ) {
+    GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM,
+                        strlen (GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM),
+                        &key);
+    if ( GNUNET_YES ==
+         GNUNET_CONTAINER_multihashmap_contains 
(handle->conndata_handle->url_param_map,
+                                                 &key) )
+    {
+      subsys_val = GNUNET_CONTAINER_multihashmap_get 
(handle->conndata_handle->url_param_map,
+                                                      &key);
+      if (NULL != subsys_val)
+      {
+        GNUNET_asprintf (&handle->subsys, "%s", subsys_val);
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", 
subsys_val);
+        handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
+                                          handle->subsys,
+                                          &get_ego_for_subsys,
+                                          handle);
+        return;
+      }
+    }
+  }
+
+  GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_CREATE_TOKEN,
+                      strlen (GNUNET_REST_JSONAPI_IDENTITY_CREATE_TOKEN),
+                      &key);
+
+  //Token audience
+  create_token_for = NULL;
+  if ( GNUNET_YES ==
+       GNUNET_CONTAINER_multihashmap_contains 
(handle->conndata_handle->url_param_map,
+                                               &key) )
+    create_token_for = GNUNET_CONTAINER_multihashmap_get 
(handle->conndata_handle->url_param_map,
+                                                          &key);
+
+  json_object = GNUNET_REST_jsonapi_object_new ();
+
+  //Return all egos
+  for (ego_entry = handle->ego_head;
+       NULL != ego_entry;
+       ego_entry = ego_entry->next)
+  {
+    if ( (NULL != egoname) && (0 != strcmp (egoname, ego_entry->identifier)) )
+      continue;
+    json_resource = GNUNET_REST_jsonapi_resource_new 
(GNUNET_REST_JSONAPI_IDENTITY_EGO,
+                                                      ego_entry->keystring);
+    name_str = json_string (ego_entry->identifier);
+    GNUNET_REST_jsonapi_resource_add_attr (
+                                           json_resource,
+                                           GNUNET_REST_JSONAPI_IDENTITY_NAME,
+                                           name_str);
+    json_decref (name_str);
+    if (NULL != create_token_for)
+    {
+      make_gnuid_token (handle,
+                        ego_entry,
+                        ego_entry->identifier,
+                        create_token_for,
+                        &token);
+      token_str = json_string (token);
+      GNUNET_free (token);
+      GNUNET_REST_jsonapi_resource_add_attr (json_resource,
+                                             
GNUNET_REST_JSONAPI_IDENTITY_GNUID,
+                                             token_str);
+      json_decref (token_str);
+    }
+    GNUNET_REST_jsonapi_object_resource_add (json_object, json_resource);
+  }
+  if (0 == GNUNET_REST_jsonapi_object_resource_count (json_object))
+  {
+    GNUNET_REST_jsonapi_object_delete (json_object);
+    handle->emsg = GNUNET_strdup ("No identities found!");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  GNUNET_REST_jsonapi_data_serialize (json_object, &result_str);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
+  resp = GNUNET_REST_create_json_response (result_str);
+  GNUNET_REST_jsonapi_object_delete (json_object);
+  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
+  GNUNET_free (result_str);
+  cleanup_handle (handle);
+}
+
+/**
+ * Processing finished
+ *
+ * @param cls request handle
+ * @param emsg error message
+ */
+static void
+do_finished (void *cls, const char *emsg)
+{
+  struct RequestHandle *handle = cls;
+  struct MHD_Response *resp;
+
+  handle->op = NULL;
+  if (NULL != emsg)
+  {
+    handle->emsg = GNUNET_strdup (emsg);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  resp = GNUNET_REST_create_json_response (NULL);
+  handle->proc (handle->proc_cls, resp, MHD_HTTP_NO_CONTENT);
+  cleanup_handle (handle);
+}
+
+/**
+ * Create a new ego
+ *
+ * @param con rest handle
+ * @param url url
+ * @param cls request handle
+ */
+static void
+ego_create_cont (struct RestConnectionDataHandle *con,
+                 const char *url,
+                 void *cls)
+{
+  struct RequestHandle *handle = cls;
+  struct EgoEntry *ego_entry;
+  struct MHD_Response *resp;
+  struct JsonApiObject *json_obj;
+  struct JsonApiResource *json_res;
+  json_t *egoname_json;
+  const char* egoname;
+  char term_data[handle->data_size+1];
+
+  if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url))
+  {
+    handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_RESOURCE_INVALID);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  if (0 >= handle->data_size)
+  {
+    handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  term_data[handle->data_size] = '\0';
+  memcpy (term_data, handle->data, handle->data_size);
+  json_obj = GNUNET_REST_jsonapi_object_parse (term_data);
+  if (NULL == json_obj)
+  {
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  if (1 != GNUNET_REST_jsonapi_object_resource_count (json_obj))
+  {
+    GNUNET_REST_jsonapi_object_delete (json_obj);
+    handle->emsg = GNUNET_strdup ("Provided resource count invalid");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  json_res = GNUNET_REST_jsonapi_object_get_resource (json_obj, 0);
+  if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_type (json_res, 
GNUNET_REST_JSONAPI_IDENTITY_EGO))
+  {
+    GNUNET_REST_jsonapi_object_delete (json_obj);
+    resp = GNUNET_REST_create_json_response (NULL);
+    handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
+    cleanup_handle (handle);
+    return;
+  }
+  egoname_json = GNUNET_REST_jsonapi_resource_read_attr (json_res, 
GNUNET_REST_JSONAPI_IDENTITY_NAME);
+  if (!json_is_string (egoname_json))
+  {
+    GNUNET_REST_jsonapi_object_delete (json_obj); 
+    handle->emsg = GNUNET_strdup ("No name provided");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  egoname = json_string_value (egoname_json);
+  for (ego_entry = handle->ego_head;
+       NULL != ego_entry;
+       ego_entry = ego_entry->next)
+  {
+    if (0 == strcasecmp (egoname, ego_entry->identifier))
+    {
+      GNUNET_REST_jsonapi_object_delete (json_obj);
+      resp = GNUNET_REST_create_json_response (NULL);
+      handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
+      cleanup_handle (handle);
+      return;
+    }
+  }
+  GNUNET_asprintf (&handle->name, "%s", egoname);
+  GNUNET_REST_jsonapi_object_delete (json_obj);
+  handle->op = GNUNET_IDENTITY_create (handle->identity_handle,
+                                       handle->name,
+                                       &do_finished,
+                                       handle);
+}
+
+
+/**
+ * Handle ego edit request
+ *
+ * @param con rest connection handle
+ * @param url the url that is requested
+ * @param cls the RequestHandle
+ */
+static void 
+ego_edit_cont (struct RestConnectionDataHandle *con,
+               const char *url,
+               void *cls)
+{
+  struct JsonApiObject *json_obj;
+  struct JsonApiResource *json_res;
+  struct RequestHandle *handle = cls;
+  struct EgoEntry *ego_entry;
+  struct MHD_Response *resp;
+  json_t *subsys_json;
+  json_t *name_json;
+  const char *keystring;
+  const char *subsys;
+  const char *newname;
+  char term_data[handle->data_size+1];
+  int ego_exists = GNUNET_NO;
+
+  if (strlen (GNUNET_REST_API_NS_IDENTITY) > strlen (handle->url))
+  {
+    handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_RESOURCE_INVALID);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+
+  keystring = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY)+1];
+
+  for (ego_entry = handle->ego_head;
+       NULL != ego_entry;
+       ego_entry = ego_entry->next)
+  {
+    if (0 != strcasecmp (keystring, ego_entry->keystring))
+      continue;
+    ego_exists = GNUNET_YES;
+    break;
+  }
+
+  if (GNUNET_NO == ego_exists)
+  {
+    resp = GNUNET_REST_create_json_response (NULL);
+    handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
+    cleanup_handle (handle);
+    return;
+  }
+
+  if (0 >= handle->data_size)
+  {
+    handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+
+  term_data[handle->data_size] = '\0';
+  memcpy (term_data, handle->data, handle->data_size);
+  json_obj = GNUNET_REST_jsonapi_object_parse (term_data);
+
+  if (NULL == json_obj)
+  {
+    handle->emsg = GNUNET_strdup ("Data invalid");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+
+  if (1 != GNUNET_REST_jsonapi_object_resource_count (json_obj))
+  {
+    GNUNET_REST_jsonapi_object_delete (json_obj);
+    handle->emsg = GNUNET_strdup ("Resource amount invalid");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  json_res = GNUNET_REST_jsonapi_object_get_resource (json_obj, 0); 
+
+  if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_type (json_res, 
GNUNET_REST_JSONAPI_IDENTITY_EGO))
+  {
+    GNUNET_REST_jsonapi_object_delete (json_obj);
+    handle->emsg = GNUNET_strdup ("Resource type invalid");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+
+  //This is a rename
+  name_json = GNUNET_REST_jsonapi_resource_read_attr (json_res,
+                                                      
GNUNET_REST_JSONAPI_IDENTITY_NEWNAME);
+  if ((NULL != name_json) && json_is_string (name_json))
+  {
+    newname = json_string_value (name_json);
+    for (ego_entry = handle->ego_head;
+         NULL != ego_entry;
+         ego_entry = ego_entry->next)
+    {
+      if (0 == strcasecmp (newname, ego_entry->identifier) &&
+          0 != strcasecmp (keystring, ego_entry->keystring))
+      {
+        //Ego with same name not allowed
+        GNUNET_REST_jsonapi_object_delete (json_obj);
+        resp = GNUNET_REST_create_json_response (NULL);
+        handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
+        cleanup_handle (handle);
+        return;
+      }
+    }
+    handle->op = GNUNET_IDENTITY_rename (handle->identity_handle,
+                                         ego_entry->identifier,
+                                         newname,
+                                         &do_finished,
+                                         handle);
+    GNUNET_REST_jsonapi_object_delete (json_obj);
+    return;
+  }
+
+  //Set subsystem
+  subsys_json = GNUNET_REST_jsonapi_resource_read_attr (json_res, 
GNUNET_REST_JSONAPI_IDENTITY_SUBSYSTEM);
+  if ( (NULL != subsys_json) && json_is_string (subsys_json))
+  {
+    subsys = json_string_value (subsys_json);
+    GNUNET_asprintf (&handle->subsys, "%s", subsys);
+    GNUNET_REST_jsonapi_object_delete (json_obj);
+    handle->op = GNUNET_IDENTITY_set (handle->identity_handle,
+                                      handle->subsys,
+                                      ego_entry->ego,
+                                      &do_finished,
+                                      handle);
+    return;
+  }
+  GNUNET_REST_jsonapi_object_delete (json_obj);
+  handle->emsg = GNUNET_strdup ("Subsystem not provided");
+  GNUNET_SCHEDULER_add_now (&do_error, handle);
+}
+
+void 
+ego_delete_cont (struct RestConnectionDataHandle *con_handle,
+                 const char* url,
+                 void *cls)
+{
+  const char *keystring;
+  struct EgoEntry *ego_entry;
+  struct MHD_Response *resp;
+  struct RequestHandle *handle = cls;
+  int ego_exists = GNUNET_NO;
+
+  if (strlen (GNUNET_REST_API_NS_IDENTITY) >= strlen (handle->url))
+  {
+    handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_RESOURCE_INVALID);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+
+  keystring = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY)+1];
+  for (ego_entry = handle->ego_head;
+       NULL != ego_entry;
+       ego_entry = ego_entry->next)
+  {
+    if (0 != strcasecmp (keystring, ego_entry->keystring))
+      continue;
+    ego_exists = GNUNET_YES;
+    break;
+  }
+  if (GNUNET_NO == ego_exists)
+  {
+    resp = GNUNET_REST_create_json_response (NULL);
+    handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
+    cleanup_handle (handle);
+    return;
+  }
+  handle->op = GNUNET_IDENTITY_delete (handle->identity_handle,
+                                       ego_entry->identifier,
+                                       &do_finished,
+                                       handle);
+
+}
+
+
+/**
+ * Respond to OPTIONS request
+ *
+ * @param con_handle the connection handle
+ * @param url the url
+ * @param cls the RequestHandle
+ */
+static void
+options_cont (struct RestConnectionDataHandle *con_handle,
+              const char* url,
+              void *cls)
+{
+  struct MHD_Response *resp;
+  struct RequestHandle *handle = cls;
+
+  //For now, independent of path return all options
+  resp = GNUNET_REST_create_json_response (NULL);
+  MHD_add_response_header (resp,
+                           "Access-Control-Allow-Methods",
+                           allow_methods);
+  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
+  cleanup_handle (handle);
+  return;
+}
+
+/**
+ * Handle rest request
+ *
+ * @param handle the request handle
+ */
+static void
+init_cont (struct RequestHandle *handle)
+{
+  static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
+    {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_info_response},
+    {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create_cont},
+    {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY, &ego_edit_cont},
+    {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_IDENTITY, &ego_delete_cont},
+    {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont},
+    GNUNET_REST_HANDLER_END
+  };
+
+  if (GNUNET_NO == GNUNET_REST_handle_request (handle->conndata_handle, 
handlers, handle))
+  {
+    handle->emsg = GNUNET_strdup ("Request unsupported");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+  }
+}
+
+/**
+ * If listing is enabled, prints information about the egos.
+ *
+ * This function is initially called for all egos and then again
+ * whenever a ego's identifier changes or if it is deleted.  At the
+ * end of the initial pass over all egos, the function is once called
+ * with 'NULL' for 'ego'. That does NOT mean that the callback won't
+ * be invoked in the future or that there was an error.
+ *
+ * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get',
+ * this function is only called ONCE, and 'NULL' being passed in
+ * 'ego' does indicate an error (i.e. name is taken or no default
+ * value is known).  If 'ego' is non-NULL and if '*ctx'
+ * is set in those callbacks, the value WILL be passed to a subsequent
+ * call to the identity callback of 'GNUNET_IDENTITY_connect' (if
+ * that one was not NULL).
+ *
+ * When an identity is renamed, this function is called with the
+ * (known) ego but the NEW identifier.
+ *
+ * When an identity is deleted, this function is called with the
+ * (known) ego and "NULL" for the 'identifier'.  In this case,
+ * the 'ego' is henceforth invalid (and the 'ctx' should also be
+ * cleaned up).
+ *
+ * @param cls closure
+ * @param ego ego handle
+ * @param ctx context for application to store data for this ego
+ *                 (during the lifetime of this process, initially NULL)
+ * @param identifier identifier assigned by the user for this ego,
+ *                   NULL if the user just deleted the ego and it
+ *                   must thus no longer be used
+ */
+static void
+list_ego (void *cls,
+          struct GNUNET_IDENTITY_Ego *ego,
+          void **ctx,
+          const char *identifier)
+{
+  struct RequestHandle *handle = cls;
+  struct EgoEntry *ego_entry;
+  struct GNUNET_CRYPTO_EcdsaPublicKey pk;
+
+  if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state))
+  {
+    handle->state = ID_REST_STATE_POST_INIT;
+    init_cont (handle);
+    return;
+  }
+  if (ID_REST_STATE_INIT == handle->state) {
+    ego_entry = GNUNET_new (struct EgoEntry);
+    GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
+    ego_entry->keystring = 
+      GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
+    ego_entry->ego = ego;
+    GNUNET_asprintf (&ego_entry->identifier, "%s", identifier);
+    GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head,handle->ego_tail, 
ego_entry);
+  }
+
+}
+
+/**
+ * Function processing the REST call
+ *
+ * @param method HTTP method
+ * @param url URL of the HTTP request
+ * @param data body of the HTTP request (optional)
+ * @param data_size length of the body
+ * @param proc callback function for the result
+ * @param proc_cls closure for callback function
+ * @return GNUNET_OK if request accepted
+ */
+static void
+rest_identity_process_request(struct RestConnectionDataHandle *conndata_handle,
+                              GNUNET_REST_ResultProcessor proc,
+                              void *proc_cls)
+{
+  struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
+
+
+
+  handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
+
+  handle->proc_cls = proc_cls;
+  handle->proc = proc;
+  handle->state = ID_REST_STATE_INIT;
+  handle->conndata_handle = conndata_handle;
+  handle->data = conndata_handle->data;
+  handle->data_size = conndata_handle->data_size;
+  handle->method = conndata_handle->method;
+  GNUNET_asprintf (&handle->url, "%s", conndata_handle->url);
+  if (handle->url[strlen (handle->url)-1] == '/')
+    handle->url[strlen (handle->url)-1] = '\0';
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Connecting...\n");
+  handle->identity_handle = GNUNET_IDENTITY_connect (cfg,
+                                                     &list_ego,
+                                                     handle);
+  GNUNET_strdup ("Timeout");
+  handle->timeout_task =
+    GNUNET_SCHEDULER_add_delayed (handle->timeout,
+                                  &do_error,
+                                  handle);
+
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Connected\n");
+}
+
+/**
+ * Entry point for the plugin.
+ *
+ * @param cls Config info
+ * @return NULL on error, otherwise the plugin context
+ */
+void *
+libgnunet_plugin_rest_identity_init (void *cls)
+{
+  static struct Plugin plugin;
+  struct GNUNET_REST_Plugin *api;
+
+  cfg = cls;
+  if (NULL != plugin.cfg)
+    return NULL;                /* can only initialize once! */
+  memset (&plugin, 0, sizeof (struct Plugin));
+  plugin.cfg = cfg;
+  api = GNUNET_new (struct GNUNET_REST_Plugin);
+  api->cls = &plugin;
+  api->name = GNUNET_REST_API_NS_IDENTITY;
+  api->process_request = &rest_identity_process_request;
+  GNUNET_asprintf (&allow_methods,
+                   "%s, %s, %s, %s, %s",
+                   MHD_HTTP_METHOD_GET,
+                   MHD_HTTP_METHOD_POST,
+                   MHD_HTTP_METHOD_PUT,
+                   MHD_HTTP_METHOD_DELETE,
+                   MHD_HTTP_METHOD_OPTIONS);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              _("Identity REST API initialized\n"));
+  return api;
+}
+
+
+/**
+ * Exit point from the plugin.
+ *
+ * @param cls the plugin context (as returned by "init")
+ * @return always NULL
+ */
+void *
+libgnunet_plugin_rest_identity_done (void *cls)
+{
+  struct GNUNET_REST_Plugin *api = cls;
+  struct Plugin *plugin = api->cls;
+
+  plugin->cfg = NULL;
+  GNUNET_free_non_null (allow_methods);
+  GNUNET_free (api);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Identity REST plugin is finished\n");
+  return NULL;
+}
+
+/* end of plugin_rest_gns.c */

Copied: gnunet/src/rest/plugin_rest_namestore.c (from rev 36350, 
gnunet/src/namestore/plugin_rest_namestore.c)
===================================================================
--- gnunet/src/rest/plugin_rest_namestore.c                             (rev 0)
+++ gnunet/src/rest/plugin_rest_namestore.c     2015-09-11 15:56:39 UTC (rev 
36351)
@@ -0,0 +1,1107 @@
+/*
+   This file is part of GNUnet.
+   Copyright (C) 2012-2015 Christian Grothoff (and other contributing authors)
+
+   GNUnet is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GNUnet is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNUnet; see the file COPYING.  If not, write to the
+   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.
+   */
+/**
+ * @author Martin Schanzenbach
+ * @file namestore/plugin_rest_namestore.c
+ * @brief GNUnet Namestore REST plugin
+ *
+ */
+
+#include "platform.h"
+#include "gnunet_rest_plugin.h"
+#include "gnunet_namestore_service.h"
+#include "gnunet_identity_service.h"
+#include "gnunet_rest_lib.h"
+#include "microhttpd.h"
+#include <jansson.h>
+
+#define GNUNET_REST_API_NS_NAMESTORE "/names"
+
+#define GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO "record"
+
+#define GNUNET_REST_JSONAPI_NAMESTORE_RECORD 
GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO
+
+#define GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE "record_type"
+
+#define GNUNET_REST_JSONAPI_NAMESTORE_VALUE "value"
+
+#define GNUNET_REST_JSONAPI_NAMESTORE_PUBLIC "public"
+
+#define GNUNET_REST_JSONAPI_NAMESTORE_SHADOW "shadow"
+
+#define GNUNET_REST_JSONAPI_NAMESTORE_PKEY "pkey"
+
+#define GNUNET_REST_JSONAPI_NAMESTORE_EXPIRATION "expiration"
+
+#define GNUNET_REST_JSONAPI_NAMESTORE_EGO "ego"
+
+/**
+ * @brief struct returned by the initialization function of the plugin
+ */
+struct Plugin
+{
+  const struct GNUNET_CONFIGURATION_Handle *cfg;
+};
+
+
+/**
+ * HTTP methods allows for this plugin
+ */
+static char* allow_methods;
+
+const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+struct RecordEntry
+{
+  /**
+   * DLL
+   */
+  struct RecordEntry *next;
+  
+  /**
+   * DLL
+   */
+  struct RecordEntry *prev;
+  
+};
+
+struct RequestHandle
+{
+  /**
+   * Ego list
+   */
+  struct RecordEntry *record_head;
+
+  /**
+   * Ego list
+   */
+  struct record_entry *record_tail;
+
+  /**
+   * JSON response object
+   */
+  struct JsonApiObject *resp_object;
+  
+  /**
+   * Rest connection
+   */
+  struct RestConnectionDataHandle *conndata_handle;
+  
+  /**
+   * Handle to GNS service.
+   */
+  struct GNUNET_IDENTITY_Handle *identity_handle;
+
+  /**
+   * Handle to NAMESTORE
+   */
+  struct GNUNET_NAMESTORE_Handle *ns_handle;
+  
+  /**
+   * Handle to NAMESTORE it
+   */
+  struct GNUNET_NAMESTORE_ZoneIterator *list_it;
+  
+  /**
+   * Private key for the zone
+   */
+  struct GNUNET_CRYPTO_EcdsaPrivateKey zone_pkey;
+
+  /**
+   * Handle to identity lookup
+   */
+  struct GNUNET_IDENTITY_EgoLookup *ego_lookup;
+
+  /**
+   * Default Ego operation
+   */
+  struct GNUNET_IDENTITY_Operation *get_default;
+
+  /**
+   * Name of the ego
+   */
+  char *ego_name;
+
+  /**
+   * Record is public
+   */
+  int is_public;
+
+  /**
+   * Shadow record
+   */
+  int is_shadow;
+
+  /**
+   * Name of the record to modify
+   */
+  char *name;
+
+  /**
+   * Value of the record
+   */
+  char *value;
+
+  /**
+   * record type
+   */
+  uint32_t type;
+
+  /**
+   * Records to store
+   */
+  struct GNUNET_GNSRECORD_Data *rd;
+
+  /**
+   * record count
+   */
+  unsigned int rd_count;
+
+    /**
+   * NAMESTORE Operation
+   */
+  struct GNUNET_NAMESTORE_QueueEntry *add_qe;
+
+  /**
+   * Desired timeout for the lookup (default is no timeout).
+   */
+  struct GNUNET_TIME_Relative timeout;
+
+  /**
+   * ID of a task associated with the resolution process.
+   */
+  struct GNUNET_SCHEDULER_Task * timeout_task;    
+
+  /**
+   * The plugin result processor
+   */
+  GNUNET_REST_ResultProcessor proc;
+
+  /**
+   * The closure of the result processor
+   */
+  void *proc_cls;
+
+  /**
+   * The url
+   */
+  char *url;
+
+  /**
+   * The data from the REST request
+   */
+  const char* data;
+
+  /**
+   * the length of the REST data
+   */
+  size_t data_size;
+  
+  /**
+   * Cfg
+   */
+  const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+};
+
+
+/**
+ * Cleanup lookup handle
+ * @param handle Handle to clean up
+ */
+static void
+cleanup_handle (struct RequestHandle *handle)
+{
+  struct RecordEntry *record_entry;
+  struct RecordEntry *record_tmp;
+  int i;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Cleaning up\n");
+  if (NULL != handle->name)
+    GNUNET_free (handle->name);
+  if (NULL != handle->timeout_task)
+    GNUNET_SCHEDULER_cancel (handle->timeout_task);
+  if (NULL != handle->ego_lookup)
+    GNUNET_IDENTITY_ego_lookup_cancel (handle->ego_lookup);
+  if (NULL != handle->get_default)
+    GNUNET_IDENTITY_cancel (handle->get_default);
+  if (NULL != handle->list_it)
+    GNUNET_NAMESTORE_zone_iteration_stop (handle->list_it);
+  if (NULL != handle->add_qe)
+    GNUNET_NAMESTORE_cancel (handle->add_qe);
+  if (NULL != handle->identity_handle)
+    GNUNET_IDENTITY_disconnect (handle->identity_handle);
+  if (NULL != handle->ns_handle)
+    GNUNET_NAMESTORE_disconnect (handle->ns_handle);
+  if (NULL != handle->url)
+    GNUNET_free (handle->url);
+  if (NULL != handle->value)
+    GNUNET_free (handle->value);
+  if (NULL != handle->rd)
+  {
+    for (i = 0; i < handle->rd_count; i++)
+    {
+      if (NULL != handle->rd[i].data)
+        GNUNET_free ((void*)handle->rd[i].data);
+    }
+    GNUNET_free (handle->rd);
+  }
+  if (NULL != handle->ego_name)
+    GNUNET_free (handle->ego_name);
+  for (record_entry = handle->record_head;
+       NULL != record_entry;)
+  {
+    record_tmp = record_entry;
+    record_entry = record_entry->next;
+    GNUNET_free (record_tmp);
+  }
+  GNUNET_free (handle);
+}
+
+/**
+ * Create json representation of a GNSRECORD
+ *
+ * @param rd the GNSRECORD_Data
+ */
+static json_t *
+gnsrecord_to_json (const struct GNUNET_GNSRECORD_Data *rd)
+{
+  const char *typename;
+  char *string_val;
+  const char *exp_str;
+  json_t *record_obj;
+
+  typename = GNUNET_GNSRECORD_number_to_typename (rd->record_type);
+  string_val = GNUNET_GNSRECORD_value_to_string (rd->record_type,
+                                                 rd->data,
+                                                 rd->data_size);
+
+  if (NULL == string_val)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Record of type %d malformed, skipping\n",
+                (int) rd->record_type);
+    return NULL;
+  }
+  record_obj = json_object();
+  json_object_set_new (record_obj,
+                       GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE,
+                       json_string (typename));
+  json_object_set_new (record_obj,
+                       GNUNET_REST_JSONAPI_NAMESTORE_VALUE,
+                       json_string (string_val));
+  GNUNET_free (string_val);
+
+  if (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION & rd->flags)
+  {
+    struct GNUNET_TIME_Relative time_rel;
+    time_rel.rel_value_us = rd->expiration_time;
+    exp_str = GNUNET_STRINGS_relative_time_to_string (time_rel, 1);
+  }
+  else
+  {
+    struct GNUNET_TIME_Absolute time_abs;
+    time_abs.abs_value_us = rd->expiration_time;
+    exp_str = GNUNET_STRINGS_absolute_time_to_string (time_abs);
+  }
+  json_object_set_new (record_obj, GNUNET_REST_JSONAPI_NAMESTORE_EXPIRATION, 
json_string (exp_str));
+
+  json_object_set_new (record_obj, "expired",
+                       json_boolean (GNUNET_YES == GNUNET_GNSRECORD_is_expired 
(rd)));
+  return record_obj;
+}
+
+
+/**
+ * Task run on shutdown.  Cleans up everything.
+ *
+ * @param cls unused
+ * @param tc scheduler context
+ */
+static void
+do_error (void *cls,
+          const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct RequestHandle *handle = cls;
+  struct MHD_Response *resp = GNUNET_REST_create_json_response (NULL);
+  handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
+  cleanup_handle (handle);
+}
+
+static void
+cleanup_handle_delayed (void *cls,
+                        const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  cleanup_handle (cls);
+}
+
+/**
+ * Create a response with requested records
+ *
+ * @param handle the RequestHandle
+ */
+static void
+namestore_list_response (void *cls,
+                         const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
+                         const char *rname,
+                         unsigned int rd_len,
+                         const struct GNUNET_GNSRECORD_Data *rd)
+{
+  struct RequestHandle *handle = cls;
+  struct JsonApiResource *json_resource;
+  struct MHD_Response *resp;
+  json_t *result_array;
+  json_t *record_obj;
+  int i;
+  char *result;
+
+  if (NULL == handle->resp_object)
+    handle->resp_object = GNUNET_REST_jsonapi_object_new ();
+
+  if (NULL == rname)
+  {
+    handle->list_it = NULL;
+    //Handle response
+    if (GNUNET_SYSERR == GNUNET_REST_jsonapi_data_serialize 
(handle->resp_object, &result))
+    {
+      GNUNET_SCHEDULER_add_now (&do_error, handle);
+      return;
+    }
+    GNUNET_REST_jsonapi_object_delete (handle->resp_object);
+    resp = GNUNET_REST_create_json_response (result);
+    handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
+    GNUNET_free (result);
+    GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
+    return;
+  }
+
+  if ( (NULL != handle->name) &&
+       (0 != strcmp (handle->name, rname)) )
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "%s does not match %s\n", rname, handle->name);
+    GNUNET_NAMESTORE_zone_iterator_next (handle->list_it);
+    return;
+  }
+
+  result_array = json_array ();
+  for (i=0; i<rd_len; i++)
+  {
+    if ( (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
+         (0 != strcmp (rname, "+")) )
+      continue;
+
+    if ( (rd[i].record_type != handle->type) &&
+         (GNUNET_GNSRECORD_TYPE_ANY != handle->type) )
+      continue;
+    record_obj = gnsrecord_to_json (&(rd[i]));
+    json_array_append (result_array, record_obj);
+    json_decref (record_obj);
+  }
+  
+  if (0 < json_array_size(result_array))
+  {
+    json_resource = GNUNET_REST_jsonapi_resource_new 
(GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO,
+                                                      rname);
+    GNUNET_REST_jsonapi_resource_add_attr (json_resource,
+                                           
GNUNET_REST_JSONAPI_NAMESTORE_RECORD,
+                                           result_array);
+    GNUNET_REST_jsonapi_object_resource_add (handle->resp_object, 
json_resource);
+  }
+
+  json_decref (result_array);
+  GNUNET_NAMESTORE_zone_iterator_next (handle->list_it);
+}
+
+static void
+create_finished (void *cls, int32_t success, const char *emsg)
+{
+  struct RequestHandle *handle = cls;
+  struct MHD_Response *resp;
+
+  handle->add_qe = NULL;
+  if (GNUNET_YES != success)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Error storing records%s%s\n",
+                (NULL == emsg) ? "" : ": ",
+                (NULL == emsg) ? "" : emsg);
+    GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
+    return;
+  }
+  resp = GNUNET_REST_create_json_response (NULL);
+  handle->proc (handle->proc_cls, resp, MHD_HTTP_NO_CONTENT);
+  GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
+}
+
+
+/**
+ * We're storing a new record; this requires
+ * that no record already exists
+ *
+ * @param cls closure, unused
+ * @param zone_key private key of the zone
+ * @param rec_name name that is being mapped (at most 255 characters long)
+ * @param rd_count number of entries in @a rd array
+ * @param rd array of records with data to store
+ */
+static void
+create_new_record_cont (void *cls,
+                        const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
+                        const char *rec_name,
+                        unsigned int rd_count,
+                        const struct GNUNET_GNSRECORD_Data *rd)
+{
+  struct RequestHandle *handle = cls;
+
+  handle->add_qe = NULL;
+  if ( (NULL != zone_key) &&
+       (0 != strcmp (rec_name, handle->name)) )
+  {
+    GNUNET_break (0);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "Received %u records for name `%s'\n",
+              rd_count, rec_name);
+  if (0 != rd_count)
+  {
+    handle->proc (handle->proc_cls,
+                  GNUNET_REST_create_json_response (NULL),
+                  MHD_HTTP_CONFLICT);
+    GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
+    return;
+  }
+
+  GNUNET_assert (NULL != handle->name);
+  handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
+                                                   &handle->zone_pkey,
+                                                   handle->name,
+                                                   handle->rd_count,
+                                                   handle->rd,
+                                                   &create_finished,
+                                                   handle);
+}
+
+static void
+del_finished (void *cls,
+              int32_t success,
+              const char *emsg)
+{
+  struct RequestHandle *handle = cls;
+
+  handle->add_qe = NULL;
+  if (GNUNET_NO == success)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Deleting record failed, record does not exist%s%s\n"),
+                (NULL != emsg) ? ": " : "",
+                (NULL != emsg) ? emsg : "");
+    GNUNET_SCHEDULER_add_now (&do_error, handle); //do_not_found TODO
+    return;
+  }
+  if (GNUNET_SYSERR == success)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Deleting record failed%s%s\n"),
+                (NULL != emsg) ? ": " : "",
+                (NULL != emsg) ? emsg : "");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  handle->proc (handle->proc_cls,
+                GNUNET_REST_create_json_response (NULL),
+                MHD_HTTP_NO_CONTENT);
+  GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
+}
+
+static void
+del_cont (void *cls,
+          const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
+          const char *label,
+          unsigned int rd_count,
+          const struct GNUNET_GNSRECORD_Data *rd)
+{
+  struct RequestHandle *handle = cls;
+
+  if (0 == rd_count)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("There are no records under label `%s' that could be 
deleted.\n"),
+                label);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+
+  handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
+                                                   &handle->zone_pkey,
+                                                   handle->name,
+                                                   0, NULL,
+                                                   &del_finished,
+                                                   handle);
+}
+
+static void
+namestore_delete_cont (struct RestConnectionDataHandle *con,
+                       const char *url,
+                       void *cls)
+{
+  struct RequestHandle *handle = cls;
+
+  if (NULL == handle->name)
+  {
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+
+  handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
+                                                    &handle->zone_pkey,
+                                                    handle->name,
+                                                    &del_cont,
+                                                    handle);
+}
+
+static int
+json_to_gnsrecord (const json_t *records_json,
+                   struct GNUNET_GNSRECORD_Data **rd,
+                   unsigned int *rd_count)
+{
+  struct GNUNET_TIME_Relative etime_rel;
+  struct GNUNET_TIME_Absolute etime_abs;
+  char *value;
+  void *rdata;
+  size_t rdata_size;
+  const char *typestring;
+  const char *expirationstring;
+  int i;
+  json_t *type_json;
+  json_t *value_json;
+  json_t *record_json;
+  json_t *exp_json;
+
+  *rd_count = json_array_size (records_json);
+  *rd = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Data) * *rd_count);
+  for (i = 0; i < *rd_count; i++)
+  {
+    memset (&((*rd)[i]), 0, sizeof (struct GNUNET_GNSRECORD_Data));
+    record_json = json_array_get (records_json, i);
+    type_json = json_object_get (record_json,
+                                 GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE);
+    if (!json_is_string (type_json))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Type property is no string\n");
+      return GNUNET_SYSERR;
+    }
+    typestring = json_string_value (type_json);
+    (*rd)[i].record_type = GNUNET_GNSRECORD_typename_to_number (typestring);
+    if (UINT32_MAX == (*rd)[i].record_type)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Unsupported type `%s'\n"),
+                  json_string_value (type_json));
+      return GNUNET_SYSERR;
+    }
+    value_json = json_object_get (record_json,
+                                  GNUNET_REST_JSONAPI_NAMESTORE_VALUE);
+    if (!json_is_string (value_json))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Value property is no string\n");
+      return GNUNET_SYSERR;
+    }
+    GNUNET_asprintf (&value, "%s", json_string_value (value_json));
+    if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value ((*rd)[i].record_type,
+                                                       value,
+                                                       &rdata,
+                                                       &rdata_size))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Value `%s' invalid for record 
type `%s'\n"),
+                  value, typestring);
+      return GNUNET_SYSERR;
+    }
+    (*rd)[i].data = rdata;
+    (*rd)[i].data_size = rdata_size;
+    /**TODO
+     * if (1 == handle->is_shadow)
+     rde->flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD;
+     if (1 != handle->is_public)
+     rde->flags |= GNUNET_GNSRECORD_RF_PRIVATE;
+     */
+    exp_json = json_object_get (record_json,
+                                GNUNET_REST_JSONAPI_NAMESTORE_EXPIRATION);
+    if (!json_is_string (exp_json))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "Expiration property is no string\n");
+      return GNUNET_SYSERR;
+    }
+    expirationstring = json_string_value (exp_json);
+    if (0 == strcmp (expirationstring, "never"))
+    {
+      (*rd)[i].expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
+    }
+    else if (GNUNET_OK ==
+             GNUNET_STRINGS_fancy_time_to_relative (expirationstring,
+                                                    &etime_rel))
+    {
+      (*rd)[i].expiration_time = etime_rel.rel_value_us;
+      (*rd)[i].flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
+    }
+    else if (GNUNET_OK ==
+             GNUNET_STRINGS_fancy_time_to_absolute (expirationstring,
+                                                    &etime_abs))
+    {
+      (*rd)[i].expiration_time = etime_abs.abs_value_us;
+    }
+    else 
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Value `%s' invalid for record 
type `%s'\n"),
+                  value, typestring);
+      return GNUNET_SYSERR;
+    }
+  }
+  return GNUNET_OK;
+}
+
+static void
+namestore_create_cont (struct RestConnectionDataHandle *con,
+                       const char *url,
+                       void *cls)
+{
+  struct RequestHandle *handle = cls;
+  struct MHD_Response *resp;
+  struct JsonApiObject *json_obj;
+  struct JsonApiResource *json_res;
+  json_t *name_json;
+  json_t *records_json;
+  char term_data[handle->data_size+1];
+
+  if (strlen (GNUNET_REST_API_NS_NAMESTORE) != strlen (handle->url))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Cannot create under %s\n", handle->url);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  if (0 >= handle->data_size)
+  {
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  term_data[handle->data_size] = '\0';
+  memcpy (term_data, handle->data, handle->data_size);
+  json_obj = GNUNET_REST_jsonapi_object_parse (term_data);
+  if (NULL == json_obj)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unable to parse JSONAPI Object from %s\n",
+                term_data);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  if (1 != GNUNET_REST_jsonapi_object_resource_count (json_obj))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Cannot create more than 1 resource! (Got %d)\n",
+                GNUNET_REST_jsonapi_object_resource_count (json_obj));
+    GNUNET_REST_jsonapi_object_delete (json_obj);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  json_res = GNUNET_REST_jsonapi_object_get_resource (json_obj, 0);
+  if (GNUNET_NO == GNUNET_REST_jsonapi_resource_check_type (json_res,
+                                                            
GNUNET_REST_JSONAPI_NAMESTORE_RECORD))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unsupported JSON data type\n");
+    GNUNET_REST_jsonapi_object_delete (json_obj);
+    resp = GNUNET_REST_create_json_response (NULL);
+    handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT);
+    cleanup_handle (handle);
+    return;
+  }
+  name_json = GNUNET_REST_jsonapi_resource_read_attr (json_res, 
GNUNET_REST_JSONAPI_KEY_ID);
+  if (!json_is_string (name_json))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Name property is no string\n");
+    GNUNET_REST_jsonapi_object_delete (json_obj); 
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  GNUNET_asprintf (&handle->name, "%s", json_string_value (name_json));
+  records_json = GNUNET_REST_jsonapi_resource_read_attr (json_res,
+                                                         
GNUNET_REST_JSONAPI_NAMESTORE_RECORD);
+  if (NULL == records_json)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "No records given\n");
+    GNUNET_REST_jsonapi_object_delete (json_obj);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  if (GNUNET_SYSERR == json_to_gnsrecord (records_json, &handle->rd, 
&handle->rd_count))
+  {
+    GNUNET_REST_jsonapi_object_delete (json_obj);
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  GNUNET_REST_jsonapi_object_delete (json_obj);
+
+  handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
+                                                    &handle->zone_pkey,
+                                                    handle->name,
+                                                    &create_new_record_cont, 
handle );
+}
+
+
+
+
+
+static void
+namestore_info_cont (struct RestConnectionDataHandle *con,
+                     const char *url,
+                     void *cls)
+{
+  struct RequestHandle *handle = cls;
+  handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
+                                                           &handle->zone_pkey,
+                                                           
&namestore_list_response,
+                                                           handle);
+}
+
+static char*
+get_name_from_url (const char* url)
+{
+  if (strlen (url) <= strlen (GNUNET_REST_API_NS_NAMESTORE))
+    return NULL;
+  return (char*)url + strlen (GNUNET_REST_API_NS_NAMESTORE) + 1;
+}
+
+/**
+ * Respond to OPTIONS request
+ *
+ * @param con_handle the connection handle
+ * @param url the url
+ * @param cls the RequestHandle
+ */
+static void
+options_cont (struct RestConnectionDataHandle *con_handle,
+              const char* url,
+              void *cls)
+{
+  struct MHD_Response *resp;
+  struct RequestHandle *handle = cls;
+
+  //For now, independent of path return all options
+  resp = GNUNET_REST_create_json_response (NULL);
+  MHD_add_response_header (resp,
+                           "Access-Control-Allow-Methods",
+                           allow_methods);
+  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
+  cleanup_handle (handle);
+  return;
+}
+
+/**
+ * Function called with the result from the check if the namestore
+ * service is actually running.  If it is, we start the actual
+ * operation.
+ *
+ * @param cls closure with our configuration
+ * @param result #GNUNET_YES if the namestore service is running
+ */
+static void
+testservice_task (void *cls,
+                  int result)
+{
+  struct RequestHandle *handle = cls;
+  static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
+    {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_info_cont}, 
//list
+    {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, 
&namestore_create_cont}, //create
+    //    {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_NAMESTORE, 
&namestore_edit_cont}, //update. TODO this shoul be PATCH
+    {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE, 
&namestore_delete_cont}, //delete
+    {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_NAMESTORE, &options_cont},
+    GNUNET_REST_HANDLER_END
+  };
+
+  if (GNUNET_YES != result)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Service `%s' is not running\n"),
+                "namestore");
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+  handle->ns_handle = GNUNET_NAMESTORE_connect (cfg);
+  if (NULL == handle->ns_handle)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Failed to connect to namestore\n"));
+    GNUNET_SCHEDULER_add_now (&do_error, handle);
+    return;
+  }
+
+  if (GNUNET_NO == GNUNET_REST_handle_request (handle->conndata_handle, 
handlers, handle))
+    GNUNET_SCHEDULER_add_now (&do_error, (void*) handle);
+
+}
+
+/**
+ * Callback invoked from identity service with ego information.
+ * An @a ego of NULL means the ego was not found.
+ *
+ * @param cls closure with the configuration
+ * @param ego an ego known to identity service, or NULL
+ */
+static void
+identity_cb (void *cls,
+             const struct GNUNET_IDENTITY_Ego *ego)
+{
+  struct RequestHandle *handle = cls;
+  struct MHD_Response *resp;
+
+  handle->ego_lookup = NULL;
+  if (NULL == ego)
+  {
+    if (NULL != handle->ego_name)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  _("Ego `%s' not known to identity service\n"),
+                  handle->ego_name);
+    }
+    resp = GNUNET_REST_create_json_response (NULL);
+    handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
+    cleanup_handle (handle);
+    return;
+  }
+  handle->zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
+  GNUNET_CLIENT_service_test ("namestore", handle->cfg,
+                              GNUNET_TIME_UNIT_SECONDS,
+                              &testservice_task,
+                              (void *) handle);
+}
+
+static void
+default_ego_cb (void *cls,
+                struct GNUNET_IDENTITY_Ego *ego,
+                void **ctx,
+                const char *name)
+{
+  struct RequestHandle *handle = cls;
+  struct MHD_Response *resp;
+  handle->get_default = NULL;
+  if (NULL == ego)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("No default ego configured in identity service\n"));
+    resp = GNUNET_REST_create_json_response (NULL);
+    handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
+    cleanup_handle (handle);
+    return;
+  }
+  else
+  {
+    identity_cb (cls, ego);
+  }
+}
+
+static void
+id_connect_cb (void *cls,
+               struct GNUNET_IDENTITY_Ego *ego,
+               void **ctx,
+               const char *name)
+{
+  struct RequestHandle *handle = cls;
+  if (NULL == ego)
+  {
+    handle->get_default = GNUNET_IDENTITY_get (handle->identity_handle,
+                                               "namestore",
+                                               &default_ego_cb, handle);
+  }
+}
+
+static void
+testservice_id_task (void *cls, int result)
+{
+  struct RequestHandle *handle = cls;
+  struct MHD_Response *resp;
+  struct GNUNET_HashCode key;
+  char *ego;
+  char *name;
+  char *type;
+
+  if (result != GNUNET_YES)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Identity service is not running\n"));
+    resp = GNUNET_REST_create_json_response (NULL);
+    handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
+    cleanup_handle (handle);
+    return;
+  }
+  ego = NULL;
+  GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_EGO,
+                      strlen (GNUNET_REST_JSONAPI_NAMESTORE_EGO),
+                      &key);
+  if ( GNUNET_YES == 
+       GNUNET_CONTAINER_multihashmap_contains 
(handle->conndata_handle->url_param_map,
+                                               &key) )
+  {
+    ego = GNUNET_CONTAINER_multihashmap_get 
(handle->conndata_handle->url_param_map,
+                                             &key);
+  }
+
+  handle->type = GNUNET_GNSRECORD_TYPE_ANY;
+  GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE,
+                      strlen (GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE),
+                      &key);
+  if ( GNUNET_YES == 
+       GNUNET_CONTAINER_multihashmap_contains 
(handle->conndata_handle->url_param_map,
+                                               &key) )
+  {
+    type = GNUNET_CONTAINER_multihashmap_get 
(handle->conndata_handle->url_param_map,
+                                              &key);
+
+    handle->type = GNUNET_GNSRECORD_typename_to_number (type);
+  }
+  name = get_name_from_url (handle->url);
+  if (NULL != ego)
+    GNUNET_asprintf (&handle->ego_name, "%s", ego);
+  if (NULL != name)
+    GNUNET_asprintf (&handle->name, "%s", name);
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", handle->ego_name);
+  if (NULL == handle->ego_name)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", handle->ego_name);
+    handle->identity_handle = GNUNET_IDENTITY_connect (handle->cfg, 
&id_connect_cb, handle);
+    if (NULL == handle->identity_handle)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Cannot connect to identity 
service\n"));
+      resp = GNUNET_REST_create_json_response (NULL);
+      handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
+      cleanup_handle (handle);
+    }
+    return;
+  }
+  handle->ego_lookup = GNUNET_IDENTITY_ego_lookup (cfg,
+                                                   handle->ego_name,
+                                                   &identity_cb,
+                                                   handle);
+}
+
+/**
+ * Function processing the REST call
+ *
+ * @param method HTTP method
+ * @param url URL of the HTTP request
+ * @param data body of the HTTP request (optional)
+ * @param data_size length of the body
+ * @param proc callback function for the result
+ * @param proc_cls closure for callback function
+ * @return GNUNET_OK if request accepted
+ */
+static void
+rest_identity_process_request(struct RestConnectionDataHandle *conndata_handle,
+                              GNUNET_REST_ResultProcessor proc,
+                              void *proc_cls)
+{
+  struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
+
+  handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
+  handle->proc_cls = proc_cls;
+  handle->proc = proc;
+  handle->conndata_handle = conndata_handle;
+  handle->data = conndata_handle->data;
+  handle->data_size = conndata_handle->data_size;
+  GNUNET_asprintf (&handle->url, "%s", conndata_handle->url);
+  if (handle->url[strlen (handle->url)-1] == '/')
+    handle->url[strlen (handle->url)-1] = '\0';
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Connecting...\n");
+  handle->cfg = cfg;
+  GNUNET_CLIENT_service_test ("identity",
+                              cfg,
+                              GNUNET_TIME_UNIT_SECONDS,
+                              &testservice_id_task,
+                              handle);
+  handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout,
+                                                       &do_error,
+                                                       handle);
+
+
+}
+
+/**
+ * Entry point for the plugin.
+ *
+ * @param cls Config info
+ * @return NULL on error, otherwise the plugin context
+ */
+void *
+libgnunet_plugin_rest_namestore_init (void *cls)
+{
+  static struct Plugin plugin;
+  cfg = cls;
+  struct GNUNET_REST_Plugin *api;
+
+  if (NULL != plugin.cfg)
+    return NULL;                /* can only initialize once! */
+  memset (&plugin, 0, sizeof (struct Plugin));
+  plugin.cfg = cfg;
+  api = GNUNET_new (struct GNUNET_REST_Plugin);
+  api->cls = &plugin;
+  api->name = GNUNET_REST_API_NS_NAMESTORE;
+  api->process_request = &rest_identity_process_request;
+  GNUNET_asprintf (&allow_methods,
+                   "%s, %s, %s, %s, %s",
+                   MHD_HTTP_METHOD_GET,
+                   MHD_HTTP_METHOD_POST,
+                   MHD_HTTP_METHOD_PUT,
+                   MHD_HTTP_METHOD_DELETE,
+                   MHD_HTTP_METHOD_OPTIONS);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              _("Namestore REST API initialized\n"));
+  return api;
+}
+
+
+/**
+ * Exit point from the plugin.
+ *
+ * @param cls the plugin context (as returned by "init")
+ * @return always NULL
+ */
+void *
+libgnunet_plugin_rest_namestore_done (void *cls)
+{
+  struct GNUNET_REST_Plugin *api = cls;
+  struct Plugin *plugin = api->cls;
+
+  plugin->cfg = NULL;
+  GNUNET_free (api);
+  GNUNET_free_non_null (allow_methods);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Namestore REST plugin is finished\n");
+  return NULL;
+}
+
+/* end of plugin_rest_namestore.c */

Modified: gnunet/src/rest/rest.c
===================================================================
--- gnunet/src/rest/rest.c      2015-09-10 15:39:36 UTC (rev 36350)
+++ gnunet/src/rest/rest.c      2015-09-11 15:56:39 UTC (rev 36351)
@@ -403,13 +403,16 @@
   json_t *root_json;
   json_t *res_arr;
   
-  if ( (NULL == resp) ||
-       (0 == resp->res_count) )
+  if ((NULL == resp))
     return GNUNET_SYSERR;
 
   root_json = json_object ();
-  if (1 == resp->res_count)
+  if (0 == resp->res_count)
   {
+    json_object_set (root_json, GNUNET_REST_JSONAPI_KEY_DATA, json_array());
+  }
+  else if (1 == resp->res_count)
+  {
     json_object_set (root_json, GNUNET_REST_JSONAPI_KEY_DATA, 
resp->res_list_head->res_obj);
   }
   else




reply via email to

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