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)
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 */
*/
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_CRYPTO_EcdsaPrivateKey shorten_key;
+ /**
+ * HTTP response code
+ */
+ int response_code;
+
};
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);
}
}
static void
-get_gns_cont (struct RestConnectionDataHandle *conndata_handle,
+get_gns_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
const char* url,
void *cls)
{
* @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)
{
* @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);
+ }
}
&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");
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,
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;
}
/**
* Handle to the rest connection
*/
- struct RestConnectionDataHandle *conndata_handle;
+ struct GNUNET_REST_RequestHandle *conndata_handle;
/**
* The processing state
*/
char *emsg;
+ /**
+ * Reponse code
+ */
+ int response_code;
+
/**
* Response object
*/
"{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);
}
* @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)
{
* @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)
{
* @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)
{
* @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)
{
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},
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);
}
}
* @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)
{
/**
* Handle to the rest connection
*/
- struct RestConnectionDataHandle *conndata_handle;
+ struct GNUNET_REST_RequestHandle *conndata_handle;
+
+ /**
+ * response code
+ */
+ int response_code;
/**
* The processing state
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);
}
* @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)
{
* @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)
{
* @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)
{
}
void
-ego_delete_cont (struct RestConnectionDataHandle *con_handle,
+ego_delete_cont (struct GNUNET_REST_RequestHandle *con_handle,
const char* url,
void *cls)
{
* @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)
{
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},
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);
}
}
* @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)
{
#define GNUNET_JSONAPI_LIB_H
#include "gnunet_util_lib.h"
+#include "gnunet_rest_lib.h"
#include "gnunet_json_lib.h"
*/
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
#define GNUNET_REST_HANDLER_END {NULL, NULL, NULL}
-struct RestConnectionDataHandle
+struct GNUNET_REST_RequestHandle
{
struct GNUNET_CONTAINER_MultiHashMap *url_param_map;
const char *method;
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
/**
* callback handler
*/
- void (*proc) (struct RestConnectionDataHandle *handle,
+ void (*proc) (struct GNUNET_REST_RequestHandle *handle,
const char *url,
void *cls);
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);
* @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);
libgnunetjsonapi_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/json/libgnunetjson.la \
+ $(top_builddir)/src/rest/libgnunetrest.la \
-ljansson \
$(XLIB)
*/
#include "platform.h"
#include "gnunet_json_lib.h"
+#include "gnunet_rest_lib.h"
#define GNUNET_JSONAPI_KEY_DATA "data"
*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);
+}
/**
* Rest connection
*/
- struct RestConnectionDataHandle *conndata_handle;
+ struct GNUNET_REST_RequestHandle *rest_handle;
/**
* Handle to GNS service.
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;
-
- /**
- * Cfg
- */
- const struct GNUNET_CONFIGURATION_Handle *cfg;
+ int response_code;
};
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);
}
}
static void
-namestore_delete_cont (struct RestConnectionDataHandle *con,
+namestore_delete_cont (struct GNUNET_REST_RequestHandle *con,
const char *url,
void *cls)
{
}
static void
-namestore_create_cont (struct RestConnectionDataHandle *con,
+namestore_create_cont (struct GNUNET_REST_RequestHandle *con,
const char *url,
void *cls)
{
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))
{
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)
}
static void
-namestore_zkey_cont (struct RestConnectionDataHandle *con,
+namestore_zkey_cont (struct GNUNET_REST_RequestHandle *con,
const char *url,
void *cls)
{
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,
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,
}
static void
-namestore_info_cont (struct RestConnectionDataHandle *con,
+namestore_info_cont (struct GNUNET_REST_RequestHandle *con,
const char *url,
void *cls)
{
* @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)
{
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
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);
+ }
}
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);
}
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);
* @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)
{
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,
struct GNUNET_REST_Plugin *plugin;
- struct RestConnectionDataHandle *data_handle;
+ struct GNUNET_REST_RequestHandle *data_handle;
int status;
const char *key,
const char *value)
{
- struct RestConnectionDataHandle *handle = cls;
+ struct GNUNET_REST_RequestHandle *handle = cls;
struct GNUNET_HashCode hkey;
char *val;
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;
}
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;
}
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;
return GNUNET_YES;
}
GNUNET_free (url);
+ err->error_code = MHD_HTTP_BAD_REQUEST;
return GNUNET_NO;
}