gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r37121 - in gnunet/src: gns identity identity-provider incl


From: gnunet
Subject: [GNUnet-SVN] r37121 - in gnunet/src: gns identity identity-provider include jsonapi namestore rest
Date: Wed, 4 May 2016 11:44:35 +0200

Author: schanzen
Date: 2016-05-04 11:44:35 +0200 (Wed, 04 May 2016)
New Revision: 37121

Modified:
   gnunet/src/gns/gnunet-gns-proxy.c
   gnunet/src/gns/plugin_rest_gns.c
   gnunet/src/identity-provider/identity_token.c
   gnunet/src/identity-provider/plugin_rest_identity_provider.c
   gnunet/src/identity/plugin_rest_identity.c
   gnunet/src/include/gnunet_jsonapi_lib.h
   gnunet/src/include/gnunet_rest_lib.h
   gnunet/src/include/gnunet_rest_plugin.h
   gnunet/src/jsonapi/Makefile.am
   gnunet/src/jsonapi/jsonapi.c
   gnunet/src/namestore/plugin_rest_namestore.c
   gnunet/src/rest/gnunet-rest-server.c
   gnunet/src/rest/rest.c
Log:
- rework rest/jsonapi API; bugfixes


Modified: gnunet/src/gns/gnunet-gns-proxy.c
===================================================================
--- gnunet/src/gns/gnunet-gns-proxy.c   2016-05-04 09:24:35 UTC (rev 37120)
+++ gnunet/src/gns/gnunet-gns-proxy.c   2016-05-04 09:44:35 UTC (rev 37121)
@@ -2522,7 +2522,7 @@
                                              s5r->sock,
                                              &do_s5r_read, s5r);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Processing %u bytes of socks data in state %d\n",
+             "Processing %zu bytes of socks data in state %d\n",
              s5r->rbuf_len,
              s5r->state);
   switch (s5r->state)
@@ -2943,7 +2943,7 @@
     return;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Proxy listens on port %u\n",
+              "Proxy listens on port %lu\n",
               port);
 
   /* start MHD daemon for HTTP */

Modified: gnunet/src/gns/plugin_rest_gns.c
===================================================================
--- gnunet/src/gns/plugin_rest_gns.c    2016-05-04 09:24:35 UTC (rev 37120)
+++ gnunet/src/gns/plugin_rest_gns.c    2016-05-04 09:44:35 UTC (rev 37121)
@@ -77,6 +77,11 @@
   struct GNUNET_GNS_LookupRequest *lookup_request;
 
   /**
+   * Handle to rest request
+   */
+  struct GNUNET_REST_RequestHandle *rest_handle;
+
+  /**
    * Lookup an ego with the identity service.
    */
   struct GNUNET_IDENTITY_EgoLookup *el;
@@ -153,6 +158,11 @@
    */
   struct GNUNET_CRYPTO_EcdsaPrivateKey shorten_key;
 
+  /**
+   * HTTP response code
+   */
+  int response_code;
+
 };
 
 
@@ -218,7 +228,7 @@
   struct MHD_Response *resp;
 
   resp = GNUNET_REST_create_json_response (NULL);
-  handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
+  handle->proc (handle->proc_cls, resp, handle->response_code);
   cleanup_handle (handle);
 }
 
@@ -505,7 +515,7 @@
 }
 
 static void
-get_gns_cont (struct RestConnectionDataHandle *conndata_handle,
+get_gns_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
               const char* url,
               void *cls)
 {
@@ -621,7 +631,7 @@
  * @param handle the lookup handle
  */
 static void
-options_cont (struct RestConnectionDataHandle *con_handle,
+options_cont (struct GNUNET_REST_RequestHandle *con_handle,
               const char* url,
               void *cls)
 {
@@ -652,24 +662,32 @@
  * @return GNUNET_OK if request accepted
  */
 static void
-rest_gns_process_request(struct RestConnectionDataHandle *conndata_handle,
+rest_gns_process_request(struct GNUNET_REST_RequestHandle *conndata_handle,
                          GNUNET_REST_ResultProcessor proc,
                          void *proc_cls)
 {
   struct LookupHandle *handle = GNUNET_new (struct LookupHandle);
+  struct GNUNET_REST_RequestHandlerError err;
 
   handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
   handle->proc_cls = proc_cls;
   handle->proc = proc;
+  handle->rest_handle = conndata_handle;
 
-  static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
+  static const struct GNUNET_REST_RequestHandler 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))
+  if (GNUNET_NO == GNUNET_JSONAPI_handle_request (conndata_handle,
+                                                  handlers,
+                                                  &err,
+                                                  handle))
+  {
+    handle->response_code = err.error_code;
     GNUNET_SCHEDULER_add_now (&do_error, handle);
+  }
 }
 
 

Modified: gnunet/src/identity/plugin_rest_identity.c
===================================================================
--- gnunet/src/identity/plugin_rest_identity.c  2016-05-04 09:24:35 UTC (rev 
37120)
+++ gnunet/src/identity/plugin_rest_identity.c  2016-05-04 09:44:35 UTC (rev 
37121)
@@ -146,9 +146,14 @@
   /**
    * Handle to the rest connection
    */
-  struct RestConnectionDataHandle *conndata_handle;
+  struct GNUNET_REST_RequestHandle *conndata_handle;
 
   /**
+   * response code
+   */
+  int response_code;
+
+  /**
    * The processing state
    */
   int state;
@@ -276,7 +281,7 @@
   resp = GNUNET_REST_create_json_response (json_error);
   handle->proc (handle->proc_cls,
                resp,
-               MHD_HTTP_BAD_REQUEST);
+               handle->response_code);
   cleanup_handle (handle);
   GNUNET_free (json_error);
 }
@@ -348,7 +353,7 @@
  * @param cls the request handle
  */
 static void
-ego_info_response (struct RestConnectionDataHandle *con,
+ego_info_response (struct GNUNET_REST_RequestHandle *con,
                    const char *url,
                    void *cls)
 {
@@ -477,7 +482,7 @@
  * @param cls request handle
  */
 static void
-ego_create_cont (struct RestConnectionDataHandle *con,
+ego_create_cont (struct GNUNET_REST_RequestHandle *con,
                  const char *url,
                  void *cls)
 {
@@ -566,7 +571,7 @@
  * @param cls the RequestHandle
  */
 static void
-ego_edit_cont (struct RestConnectionDataHandle *con,
+ego_edit_cont (struct GNUNET_REST_RequestHandle *con,
                const char *url,
                void *cls)
 {
@@ -696,7 +701,7 @@
 }
 
 void
-ego_delete_cont (struct RestConnectionDataHandle *con_handle,
+ego_delete_cont (struct GNUNET_REST_RequestHandle *con_handle,
                  const char* url,
                  void *cls)
 {
@@ -746,7 +751,7 @@
  * @param cls the RequestHandle
  */
 static void
-options_cont (struct RestConnectionDataHandle *con_handle,
+options_cont (struct GNUNET_REST_RequestHandle *con_handle,
               const char* url,
               void *cls)
 {
@@ -771,7 +776,8 @@
 static void
 init_cont (struct RequestHandle *handle)
 {
-  static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
+  struct GNUNET_REST_RequestHandlerError err;
+  static const struct GNUNET_REST_RequestHandler 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},
@@ -780,9 +786,12 @@
     GNUNET_REST_HANDLER_END
   };
 
-  if (GNUNET_NO == GNUNET_REST_handle_request (handle->conndata_handle, 
handlers, handle))
+  if (GNUNET_NO == GNUNET_JSONAPI_handle_request (handle->conndata_handle,
+                                                  handlers,
+                                                  &err,
+                                                  handle))
   {
-    handle->emsg = GNUNET_strdup ("Request unsupported");
+    handle->response_code = err.error_code;
     GNUNET_SCHEDULER_add_now (&do_error, handle);
   }
 }
@@ -860,7 +869,7 @@
  * @return GNUNET_OK if request accepted
  */
 static void
-rest_identity_process_request(struct RestConnectionDataHandle *conndata_handle,
+rest_identity_process_request(struct GNUNET_REST_RequestHandle 
*conndata_handle,
                               GNUNET_REST_ResultProcessor proc,
                               void *proc_cls)
 {

Modified: gnunet/src/identity-provider/identity_token.c
===================================================================
--- gnunet/src/identity-provider/identity_token.c       2016-05-04 09:24:35 UTC 
(rev 37120)
+++ gnunet/src/identity-provider/identity_token.c       2016-05-04 09:44:35 UTC 
(rev 37121)
@@ -98,7 +98,10 @@
                                               &enc_key,
                                               &enc_iv,
                                               str_buf);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypted bytes: %d Expected bytes: 
%d\n", str_size, cyphertext_len);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Decrypted bytes: %zd Expected bytes: %zd\n",
+              str_size,
+              cyphertext_len);
   if (-1 == str_size)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ECDH invalid\n");
@@ -172,7 +175,7 @@
                                                         pub_key,
                                                         &new_key_hash));
   create_sym_key_from_ecdh(&new_key_hash, &skey, &iv);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting string %s\n (len=%d)",
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting string %s\n (len=%zd)",
               plaintext,
               strlen (plaintext));
   enc_size = GNUNET_CRYPTO_symmetric_encrypt (plaintext,
@@ -179,7 +182,7 @@
                                               strlen (plaintext),
                                               &skey, &iv,
                                               *cyphertext);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted (len=%d)", enc_size);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted (len=%zd)", enc_size);
   return GNUNET_OK;
 }
 

Modified: gnunet/src/identity-provider/plugin_rest_identity_provider.c
===================================================================
--- gnunet/src/identity-provider/plugin_rest_identity_provider.c        
2016-05-04 09:24:35 UTC (rev 37120)
+++ gnunet/src/identity-provider/plugin_rest_identity_provider.c        
2016-05-04 09:44:35 UTC (rev 37121)
@@ -199,7 +199,7 @@
   /**
    * Handle to the rest connection
    */
-  struct RestConnectionDataHandle *conndata_handle;
+  struct GNUNET_REST_RequestHandle *conndata_handle;
 
   /**
    * The processing state
@@ -272,6 +272,11 @@
   char *emsg;
 
   /**
+   * Reponse code
+   */
+  int response_code;
+
+  /**
    * Response object
    */
   struct GNUNET_JSONAPI_Object *resp_object;
@@ -337,7 +342,7 @@
                    "{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);
+  handle->proc (handle->proc_cls, resp, handle->response_code);
   cleanup_handle (handle);
   GNUNET_free (json_error);
 }
@@ -434,7 +439,7 @@
  * @param cls the request handle
  */
 static void
-issue_token_cont (struct RestConnectionDataHandle *con,
+issue_token_cont (struct GNUNET_REST_RequestHandle *con,
                   const char *url,
                   void *cls)
 {
@@ -730,7 +735,7 @@
  * @param cls the RequestHandle
  */
 static void
-list_token_cont (struct RestConnectionDataHandle *con_handle,
+list_token_cont (struct GNUNET_REST_RequestHandle *con_handle,
                  const char* url,
                  void *cls)
 {
@@ -919,7 +924,7 @@
  * @param cls the RequestHandle
  */
 static void
-exchange_token_ticket_cont (struct RestConnectionDataHandle *con_handle,
+exchange_token_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
                             const char* url,
                             void *cls)
 {
@@ -940,7 +945,7 @@
  * @param cls the RequestHandle
  */
 static void
-options_cont (struct RestConnectionDataHandle *con_handle,
+options_cont (struct GNUNET_REST_RequestHandle *con_handle,
               const char* url,
               void *cls)
 {
@@ -965,7 +970,8 @@
 static void
 init_cont (struct RequestHandle *handle)
 {
-  static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
+  struct GNUNET_REST_RequestHandlerError err;
+  static const struct GNUNET_REST_RequestHandler handlers[] = {
     {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TOKEN_ISSUE, 
&issue_token_cont},
     //{MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_TOKEN_CHECK, 
&check_token_cont},
     {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PROVIDER, 
&list_token_cont},
@@ -974,9 +980,12 @@
     GNUNET_REST_HANDLER_END
   };
 
-  if (GNUNET_NO == GNUNET_REST_handle_request (handle->conndata_handle, 
handlers, handle))
+  if (GNUNET_NO == GNUNET_REST_handle_request (handle->conndata_handle,
+                                               handlers,
+                                               &err,
+                                               handle))
   {
-    handle->emsg = GNUNET_strdup ("Request unsupported");
+    handle->response_code = err.error_code;
     GNUNET_SCHEDULER_add_now (&do_error, handle);
   }
 }
@@ -1054,7 +1063,7 @@
  * @return GNUNET_OK if request accepted
  */
 static void
-rest_identity_process_request(struct RestConnectionDataHandle *conndata_handle,
+rest_identity_process_request(struct GNUNET_REST_RequestHandle 
*conndata_handle,
                               GNUNET_REST_ResultProcessor proc,
                               void *proc_cls)
 {

Modified: gnunet/src/include/gnunet_jsonapi_lib.h
===================================================================
--- gnunet/src/include/gnunet_jsonapi_lib.h     2016-05-04 09:24:35 UTC (rev 
37120)
+++ gnunet/src/include/gnunet_jsonapi_lib.h     2016-05-04 09:44:35 UTC (rev 
37121)
@@ -22,6 +22,7 @@
 #define GNUNET_JSONAPI_LIB_H
 
 #include "gnunet_util_lib.h"
+#include "gnunet_rest_lib.h"
 #include "gnunet_json_lib.h"
 
 
@@ -200,5 +201,41 @@
  */
 json_t*
 GNUNET_JSONAPI_resource_get_id (const struct GNUNET_JSONAPI_Resource 
*resource);
+
+
 /* end of gnunet_jsonapi_lib.h */
+
+/**
+ * Check rest request for validity
+ *
+ * @param req handle to the request
+ * @return GNUNET_OK if valid
+ */
+int
+GNUNET_JSONAPI_check_request_acceptable (struct GNUNET_REST_RequestHandle 
*req);
+
+/**
+ * Check rest request for validity
+ *
+ * @param req handle to the request
+ * @return GNUNET_OK if valid
+ */
+int
+GNUNET_JSONAPI_check_request_supported (struct GNUNET_REST_RequestHandle *req);
+
+
+/**
+ * Handle jsonapi rest request. Checks request headers for jsonapi compliance
+ *
+ * @param req rest request handle
+ * @param handler rest request handlers
+ * @param cls closure
+ * @return GNUNET_OK if successful
+ */
+int
+GNUNET_JSONAPI_handle_request (struct GNUNET_REST_RequestHandle *req,
+                               const struct GNUNET_REST_RequestHandler 
*handlers,
+                               struct GNUNET_REST_RequestHandlerError *err,
+                               void *cls);
+
 #endif

Modified: gnunet/src/include/gnunet_rest_lib.h
===================================================================
--- gnunet/src/include/gnunet_rest_lib.h        2016-05-04 09:24:35 UTC (rev 
37120)
+++ gnunet/src/include/gnunet_rest_lib.h        2016-05-04 09:44:35 UTC (rev 
37121)
@@ -37,7 +37,7 @@
 
 #define GNUNET_REST_HANDLER_END {NULL, NULL, NULL}
 
-struct RestConnectionDataHandle
+struct GNUNET_REST_RequestHandle
 {
   struct GNUNET_CONTAINER_MultiHashMap *url_param_map;
   const char *method;
@@ -44,10 +44,15 @@
   const char *url;
   const char *data;
   size_t data_size;
+};
 
+struct GNUNET_REST_RequestHandlerError
+{
+  int error_code;
+  char* error_text;
 };
 
-struct GNUNET_REST_RestConnectionHandler
+struct GNUNET_REST_RequestHandler
 {
   /**
    * Http method to handle
@@ -62,7 +67,7 @@
   /**
    * callback handler
    */
-  void (*proc) (struct RestConnectionDataHandle *handle,
+  void (*proc) (struct GNUNET_REST_RequestHandle *handle,
                 const char *url,
                 void *cls);
 
@@ -101,8 +106,9 @@
 
 
 int
-GNUNET_REST_handle_request (struct RestConnectionDataHandle *conn,
-                            const struct GNUNET_REST_RestConnectionHandler 
*handlers,
+GNUNET_REST_handle_request (struct GNUNET_REST_RequestHandle *conn,
+                            const struct GNUNET_REST_RequestHandler *handlers,
+                            struct GNUNET_REST_RequestHandlerError *err,
                             void *cls);
 
 

Modified: gnunet/src/include/gnunet_rest_plugin.h
===================================================================
--- gnunet/src/include/gnunet_rest_plugin.h     2016-05-04 09:24:35 UTC (rev 
37120)
+++ gnunet/src/include/gnunet_rest_plugin.h     2016-05-04 09:44:35 UTC (rev 
37121)
@@ -71,7 +71,7 @@
    * @param proc the callback for result
    * @param proc_cls closure for callback
    */
-  void (*process_request) (struct RestConnectionDataHandle *handle,
+  void (*process_request) (struct GNUNET_REST_RequestHandle *handle,
                            GNUNET_REST_ResultProcessor proc,
                            void *proc_cls);
 

Modified: gnunet/src/jsonapi/Makefile.am
===================================================================
--- gnunet/src/jsonapi/Makefile.am      2016-05-04 09:24:35 UTC (rev 37120)
+++ gnunet/src/jsonapi/Makefile.am      2016-05-04 09:44:35 UTC (rev 37121)
@@ -17,6 +17,7 @@
 libgnunetjsonapi_la_LIBADD = \
   $(top_builddir)/src/util/libgnunetutil.la \
        $(top_builddir)/src/json/libgnunetjson.la \
+       $(top_builddir)/src/rest/libgnunetrest.la \
   -ljansson \
   $(XLIB)
 

Modified: gnunet/src/jsonapi/jsonapi.c
===================================================================
--- gnunet/src/jsonapi/jsonapi.c        2016-05-04 09:24:35 UTC (rev 37120)
+++ gnunet/src/jsonapi/jsonapi.c        2016-05-04 09:44:35 UTC (rev 37121)
@@ -20,6 +20,7 @@
  */
 #include "platform.h"
 #include "gnunet_json_lib.h"
+#include "gnunet_rest_lib.h"
 
 #define GNUNET_JSONAPI_KEY_DATA "data"
 
@@ -476,3 +477,56 @@
   *jsonapi_object = NULL;
   return ret;
 }
+
+/**
+ * Check rest request for validity
+ *
+ * @param req handle to the request
+ * @return GNUNET_OK if valid
+ */
+int
+GNUNET_JSONAPI_check_request_acceptable (struct GNUNET_REST_RequestHandle *req)
+{
+  //TODO
+  return GNUNET_OK;
+}
+
+/**
+ * Check rest request for validity
+ *
+ * @param req handle to the request
+ * @return GNUNET_OK if valid
+ */
+int
+GNUNET_JSONAPI_check_request_supported (struct GNUNET_REST_RequestHandle *req)
+{
+  //TODO
+  return GNUNET_OK;
+}
+
+/**
+ * Handle jsonapi rest request. Checks request headers for jsonapi compliance
+ *
+ * @param req rest request handle
+ * @param handler rest request handlers
+ * @param cls closure
+ * @return GNUNET_OK if successful
+ */
+int
+GNUNET_JSONAPI_handle_request (struct GNUNET_REST_RequestHandle *handle,
+                               const struct GNUNET_REST_RequestHandler 
*handlers,
+                               struct GNUNET_REST_RequestHandlerError *err,
+                               void *cls)
+{
+  if (GNUNET_OK != GNUNET_JSONAPI_check_request_acceptable (handle))
+  {
+    err->error_code = MHD_HTTP_NOT_ACCEPTABLE;
+    return GNUNET_SYSERR;
+  }
+  if (GNUNET_OK != GNUNET_JSONAPI_check_request_supported (handle))
+  {
+    err->error_code = MHD_HTTP_UNSUPPORTED_MEDIA_TYPE;
+    return GNUNET_SYSERR;
+  }
+  return GNUNET_REST_handle_request (handle, handlers, err, cls);
+}

Modified: gnunet/src/namestore/plugin_rest_namestore.c
===================================================================
--- gnunet/src/namestore/plugin_rest_namestore.c        2016-05-04 09:24:35 UTC 
(rev 37120)
+++ gnunet/src/namestore/plugin_rest_namestore.c        2016-05-04 09:44:35 UTC 
(rev 37121)
@@ -111,7 +111,7 @@
   /**
    * Rest connection
    */
-  struct RestConnectionDataHandle *conndata_handle;
+  struct GNUNET_REST_RequestHandle *rest_handle;
 
   /**
    * Handle to GNS service.
@@ -224,20 +224,15 @@
   char *url;
 
   /**
-   * The data from the REST request
+   * Cfg
    */
-  const char* data;
+  const struct GNUNET_CONFIGURATION_Handle *cfg;
 
   /**
-   * the length of the REST data
+   * HTTP response code
    */
-  size_t data_size;
+  int response_code;
 
-  /**
-   * Cfg
-   */
-  const struct GNUNET_CONFIGURATION_Handle *cfg;
-
 };
 
 
@@ -364,7 +359,7 @@
   struct RequestHandle *handle = cls;
   struct MHD_Response *resp = GNUNET_REST_create_json_response (NULL);
 
-  handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
+  handle->proc (handle->proc_cls, resp, handle->response_code);
   cleanup_handle (handle);
 }
 
@@ -596,7 +591,7 @@
 }
 
 static void
-namestore_delete_cont (struct RestConnectionDataHandle *con,
+namestore_delete_cont (struct GNUNET_REST_RequestHandle *con,
                        const char *url,
                        void *cls)
 {
@@ -718,7 +713,7 @@
 }
 
 static void
-namestore_create_cont (struct RestConnectionDataHandle *con,
+namestore_create_cont (struct GNUNET_REST_RequestHandle *con,
                        const char *url,
                        void *cls)
 {
@@ -728,7 +723,7 @@
   struct GNUNET_JSONAPI_Resource *json_res;
   json_t *name_json;
   json_t *records_json;
-  char term_data[handle->data_size+1];
+  char term_data[handle->rest_handle->data_size+1];
 
   if (strlen (GNUNET_REST_API_NS_NAMESTORE) != strlen (handle->url))
   {
@@ -737,13 +732,15 @@
     GNUNET_SCHEDULER_add_now (&do_error, handle);
     return;
   }
-  if (0 >= handle->data_size)
+  if (0 >= handle->rest_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);
+  term_data[handle->rest_handle->data_size] = '\0';
+  memcpy (term_data,
+          handle->rest_handle->data,
+          handle->rest_handle->data_size);
   GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_object_parse (term_data,
                                                            &json_obj));
   if (NULL == json_obj)
@@ -853,7 +850,7 @@
 }
 
 static void
-namestore_zkey_cont (struct RestConnectionDataHandle *con,
+namestore_zkey_cont (struct GNUNET_REST_RequestHandle *con,
                      const char *url,
                      void *cls)
 {
@@ -865,7 +862,7 @@
                       strlen (GNUNET_REST_JSONAPI_NAMESTORE_ZKEY),
                       &key);
   if ( GNUNET_NO ==
-       GNUNET_CONTAINER_multihashmap_contains 
(handle->conndata_handle->url_param_map,
+       GNUNET_CONTAINER_multihashmap_contains 
(handle->rest_handle->url_param_map,
                                                &key) )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -873,7 +870,7 @@
     GNUNET_SCHEDULER_add_now (&do_error, handle);
     return;
   }
-  handle->zkey_str = GNUNET_CONTAINER_multihashmap_get 
(handle->conndata_handle->url_param_map,
+  handle->zkey_str = GNUNET_CONTAINER_multihashmap_get 
(handle->rest_handle->url_param_map,
                                             &key);
   if (GNUNET_OK !=
       GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->zkey_str,
@@ -893,7 +890,7 @@
 }
 
 static void
-namestore_info_cont (struct RestConnectionDataHandle *con,
+namestore_info_cont (struct GNUNET_REST_RequestHandle *con,
                      const char *url,
                      void *cls)
 {
@@ -920,7 +917,7 @@
  * @param cls the RequestHandle
  */
 static void
-options_cont (struct RestConnectionDataHandle *con_handle,
+options_cont (struct GNUNET_REST_RequestHandle *con_handle,
               const char* url,
               void *cls)
 {
@@ -950,7 +947,8 @@
                   int result)
 {
   struct RequestHandle *handle = cls;
-  static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
+  struct GNUNET_REST_RequestHandlerError err;
+  static const struct GNUNET_REST_RequestHandler handlers[] = {
     {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE_ZKEY, 
&namestore_zkey_cont}, //reverse
     {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
@@ -976,8 +974,14 @@
     return;
   }
 
-  if (GNUNET_NO == GNUNET_REST_handle_request (handle->conndata_handle, 
handlers, handle))
+  if (GNUNET_OK != GNUNET_JSONAPI_handle_request (handle->rest_handle,
+                                                  handlers,
+                                                  &err,
+                                                  handle))
+  {
+    handle->response_code = err.error_code;
     GNUNET_SCHEDULER_add_now (&do_error, (void*) handle);
+  }
 
 }
 
@@ -1079,10 +1083,10 @@
                       strlen (GNUNET_REST_JSONAPI_NAMESTORE_EGO),
                       &key);
   if ( GNUNET_YES ==
-       GNUNET_CONTAINER_multihashmap_contains 
(handle->conndata_handle->url_param_map,
+       GNUNET_CONTAINER_multihashmap_contains 
(handle->rest_handle->url_param_map,
                                                &key) )
   {
-    ego = GNUNET_CONTAINER_multihashmap_get 
(handle->conndata_handle->url_param_map,
+    ego = GNUNET_CONTAINER_multihashmap_get 
(handle->rest_handle->url_param_map,
                                              &key);
   }
 
@@ -1091,10 +1095,10 @@
                       strlen (GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE),
                       &key);
   if ( GNUNET_YES ==
-       GNUNET_CONTAINER_multihashmap_contains 
(handle->conndata_handle->url_param_map,
+       GNUNET_CONTAINER_multihashmap_contains 
(handle->rest_handle->url_param_map,
                                                &key) )
   {
-    type = GNUNET_CONTAINER_multihashmap_get 
(handle->conndata_handle->url_param_map,
+    type = GNUNET_CONTAINER_multihashmap_get 
(handle->rest_handle->url_param_map,
                                               &key);
 
     handle->type = GNUNET_GNSRECORD_typename_to_number (type);
@@ -1134,7 +1138,7 @@
  * @return GNUNET_OK if request accepted
  */
 static void
-rest_identity_process_request(struct RestConnectionDataHandle *conndata_handle,
+rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
                               GNUNET_REST_ResultProcessor proc,
                               void *proc_cls)
 {
@@ -1143,10 +1147,8 @@
   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);
+  handle->rest_handle = rest_handle;
+  GNUNET_asprintf (&handle->url, "%s", rest_handle->url);
   if (handle->url[strlen (handle->url)-1] == '/')
     handle->url[strlen (handle->url)-1] = '\0';
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,

Modified: gnunet/src/rest/gnunet-rest-server.c
===================================================================
--- gnunet/src/rest/gnunet-rest-server.c        2016-05-04 09:24:35 UTC (rev 
37120)
+++ gnunet/src/rest/gnunet-rest-server.c        2016-05-04 09:44:35 UTC (rev 
37121)
@@ -129,7 +129,7 @@
 
   struct GNUNET_REST_Plugin *plugin;
 
-  struct RestConnectionDataHandle *data_handle;
+  struct GNUNET_REST_RequestHandle *data_handle;
 
   int status;
 
@@ -217,7 +217,7 @@
               const char *key,
               const char *value)
 {
-  struct RestConnectionDataHandle *handle = cls;
+  struct GNUNET_REST_RequestHandle *handle = cls;
   struct GNUNET_HashCode hkey;
   char *val;
 
@@ -274,7 +274,7 @@
   char *plugin_name;
   struct GNUNET_HashCode key;
   struct MhdConnectionHandle *con_handle;
-  struct RestConnectionDataHandle *rest_conndata_handle;
+  struct GNUNET_REST_RequestHandle *rest_conndata_handle;
 
   con_handle = *con_cls;
 
@@ -311,7 +311,7 @@
   }
   if (GN_REST_STATE_INIT == con_handle->state)
   {
-    rest_conndata_handle = GNUNET_new (struct RestConnectionDataHandle);
+    rest_conndata_handle = GNUNET_new (struct GNUNET_REST_RequestHandle);
     rest_conndata_handle->method = meth;
     rest_conndata_handle->url = url;
     rest_conndata_handle->data = upload_data;

Modified: gnunet/src/rest/rest.c
===================================================================
--- gnunet/src/rest/rest.c      2016-05-04 09:24:35 UTC (rev 37120)
+++ gnunet/src/rest/rest.c      2016-05-04 09:44:35 UTC (rev 37121)
@@ -75,8 +75,9 @@
 }
 
 int
-GNUNET_REST_handle_request (struct RestConnectionDataHandle *conn,
-                            const struct GNUNET_REST_RestConnectionHandler 
*handlers,
+GNUNET_REST_handle_request (struct GNUNET_REST_RequestHandle *conn,
+                            const struct GNUNET_REST_RequestHandler *handlers,
+                            struct GNUNET_REST_RequestHandlerError *err,
                             void *cls)
 {
   int count;
@@ -104,6 +105,7 @@
     return GNUNET_YES;
   }
   GNUNET_free (url);
+  err->error_code = MHD_HTTP_BAD_REQUEST;
   return GNUNET_NO;
 }
 




reply via email to

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