#include "platform.h"
#include "gnunet_rest_plugin.h"
#include "gnunet_rest_lib.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_gnsrecord_json_lib.h"
#include "gnunet_gns_service.h"
#include "microhttpd.h"
#include <jansson.h>
#include "gns_plugin.h"
Go to the source code of this file.
Data Structures | |
struct | Plugin |
Handle for a plugin. More... | |
struct | RequestHandle |
The request handle. More... | |
Macros | |
#define | GNUNET_REST_API_NS_GNS "/gns" |
Rest API GNS Namespace. More... | |
#define | GNUNET_REST_GNS_PARAM_RECORD_TYPE "record_type" |
Rest API GNS Parameter record_type. More... | |
#define | GNUNET_REST_GNS_ERROR_UNKNOWN "Unknown Error" |
Rest API GNS ERROR Unknown Error. More... | |
#define | GNUNET_REST_GNS_NOT_FOUND "Record not found" |
Rest API GNS ERROR Record not found. More... | |
Functions | |
static void | cleanup_handle (void *cls) |
Cleanup lookup handle. More... | |
static void | do_error (void *cls) |
Task run on errors. More... | |
static void | do_timeout (void *cls) |
static void | handle_gns_response (void *cls, int was_gns, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd) |
Iterator called on obtained result for a GNS lookup. More... | |
static void | get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Handle gns GET request. More... | |
static void | options_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Respond to OPTIONS request. More... | |
enum GNUNET_GenericReturnValue | REST_gns_process_request (void *plugin, struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls) |
Function processing the REST call. More... | |
void * | REST_gns_init (const struct GNUNET_CONFIGURATION_Handle *c) |
Entry point for the plugin. More... | |
void | REST_gns_done (struct GNUNET_REST_Plugin *api) |
Exit point from the plugin. More... | |
Variables | |
const struct GNUNET_CONFIGURATION_Handle * | gns_cfg |
The configuration handle. More... | |
static char * | allow_methods |
HTTP methods allows for this plugin. More... | |
static struct GNUNET_GNS_Handle * | gns |
Connection to GNS. More... | |
static struct RequestHandle * | requests_head |
DLL. More... | |
static struct RequestHandle * | requests_tail |
DLL. More... | |
#define GNUNET_REST_API_NS_GNS "/gns" |
Rest API GNS Namespace.
Definition at line 39 of file gns_plugin.c.
#define GNUNET_REST_GNS_PARAM_RECORD_TYPE "record_type" |
Rest API GNS Parameter record_type.
Definition at line 44 of file gns_plugin.c.
#define GNUNET_REST_GNS_ERROR_UNKNOWN "Unknown Error" |
Rest API GNS ERROR Unknown Error.
Definition at line 49 of file gns_plugin.c.
#define GNUNET_REST_GNS_NOT_FOUND "Record not found" |
Rest API GNS ERROR Record not found.
Definition at line 54 of file gns_plugin.c.
|
static |
Cleanup lookup handle.
cls | struct RequestHandle to clean up |
Definition at line 165 of file gns_plugin.c.
References GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNS_lookup_with_tld_cancel(), GNUNET_log, GNUNET_SCHEDULER_cancel(), handle, requests_head, and requests_tail.
Referenced by do_error(), handle_gns_response(), options_cont(), and REST_gns_process_request().
|
static |
Task run on errors.
Reports an error and cleans up everything.
cls | the struct RequestHandle |
Definition at line 201 of file gns_plugin.c.
References cleanup_handle(), GNUNET_free, GNUNET_REST_create_response(), GNUNET_REST_GNS_ERROR_UNKNOWN, GNUNET_SCHEDULER_cancel(), GNUNET_strdup, handle, MHD_HTTP_INTERNAL_SERVER_ERROR, and response.
Referenced by do_timeout(), get_gns_cont(), handle_gns_response(), and REST_gns_done().
|
static |
Definition at line 229 of file gns_plugin.c.
References do_error(), handle, and MHD_HTTP_REQUEST_TIMEOUT.
Referenced by REST_gns_process_request().
|
static |
Iterator called on obtained result for a GNS lookup.
cls | closure with the object |
was_gns | GNUNET_NO if name was not a GNS name |
rd_count | number of records in rd |
rd | the records in reply |
Definition at line 248 of file gns_plugin.c.
References cleanup_handle(), do_error(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_JSON_from_gnsrecord(), GNUNET_log, GNUNET_NO, GNUNET_REST_create_response(), GNUNET_REST_GNS_NOT_FOUND, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, MHD_HTTP_NOT_FOUND, MHD_HTTP_OK, rd, rd_count, and result.
Referenced by get_gns_cont().
|
static |
Handle gns GET request.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 292 of file gns_plugin.c.
References do_error(), gns, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_GNS_LO_DEFAULT, GNUNET_GNS_lookup_with_tld(), GNUNET_GNSRECORD_TYPE_ANY, GNUNET_GNSRECORD_typename_to_number(), GNUNET_REST_API_NS_GNS, GNUNET_REST_GNS_NOT_FOUND, GNUNET_REST_GNS_PARAM_RECORD_TYPE, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_YES, handle, handle_gns_response(), key, MHD_HTTP_NOT_FOUND, name, and GNUNET_REST_RequestHandle::url_param_map.
Referenced by REST_gns_process_request().
|
static |
Respond to OPTIONS request.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 358 of file gns_plugin.c.
References allow_methods, cleanup_handle(), GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), handle, and MHD_HTTP_OK.
Referenced by REST_gns_process_request().
enum GNUNET_GenericReturnValue REST_gns_process_request | ( | void * | plugin, |
struct GNUNET_REST_RequestHandle * | rest_handle, | ||
GNUNET_REST_ResultProcessor | proc, | ||
void * | proc_cls | ||
) |
Function processing the REST call.
method | HTTP method |
url | URL of the HTTP request |
data | body of the HTTP request (optional) |
data_size | length of the body |
proc | callback function for the result |
proc_cls | closure for callback function |
Definition at line 386 of file gns_plugin.c.
References cleanup_handle(), do_timeout(), get_gns_cont(), GNUNET_CONTAINER_DLL_insert, GNUNET_new, GNUNET_NO, GNUNET_REST_API_NS_GNS, GNUNET_REST_handle_request(), GNUNET_REST_HANDLER_END, GNUNET_SCHEDULER_add_delayed(), GNUNET_strdup, GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_SECONDS, GNUNET_YES, handle, handlers, options_cont(), GNUNET_REST_RequestHandler::proc, requests_head, requests_tail, and GNUNET_REST_RequestHandle::url.
Referenced by run().
void * REST_gns_init | ( | const struct GNUNET_CONFIGURATION_Handle * | c | ) |
Entry point for the plugin.
cls | Config info |
Definition at line 431 of file gns_plugin.c.
References _, allow_methods, GNUNET_REST_Plugin::cls, gns, gns_cfg, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNS_connect(), GNUNET_log, GNUNET_new, GNUNET_REST_API_NS_GNS, GNUNET_REST_Plugin::name, and plugin.
Referenced by run().
void REST_gns_done | ( | struct GNUNET_REST_Plugin * | api | ) |
Exit point from the plugin.
cls | the plugin context (as returned by "init") |
Definition at line 463 of file gns_plugin.c.
References allow_methods, Plugin::api, GNUNET_BLOCK_PluginFunctions::cls, do_error(), gns, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNS_disconnect(), GNUNET_log, plugin, request, and requests_head.
Referenced by do_shutdown().
const struct GNUNET_CONFIGURATION_Handle* gns_cfg |
The configuration handle.
Definition at line 59 of file gns_plugin.c.
Referenced by REST_gns_init().
|
static |
HTTP methods allows for this plugin.
Definition at line 64 of file gns_plugin.c.
Referenced by options_cont(), REST_gns_done(), and REST_gns_init().
|
static |
Connection to GNS.
Definition at line 69 of file gns_plugin.c.
Referenced by get_gns_cont(), REST_gns_done(), and REST_gns_init().
|
static |
DLL.
Definition at line 153 of file gns_plugin.c.
Referenced by cleanup_handle(), REST_gns_done(), and REST_gns_process_request().
|
static |
DLL.
Definition at line 158 of file gns_plugin.c.
Referenced by cleanup_handle(), and REST_gns_process_request().