32#include "microhttpd.h"
39#define GNUNET_REST_API_NS_GNS "/gns"
44#define GNUNET_REST_GNS_PARAM_RECORD_TYPE "record_type"
49#define GNUNET_REST_GNS_ERROR_UNKNOWN "Unknown Error"
54#define GNUNET_REST_GNS_NOT_FOUND "Record not found"
171 if (NULL !=
handle->gns_lookup)
174 handle->gns_lookup = NULL;
176 if (NULL !=
handle->timeout_task)
179 handle->timeout_task = NULL;
204 struct MHD_Response *resp;
205 json_t *json_error = json_object ();
208 if (NULL !=
handle->timeout_task)
210 handle->timeout_task = NULL;
214 json_object_set_new (json_error,
"error", json_string (
handle->emsg));
216 if (0 ==
handle->response_code)
217 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
218 response = json_dumps (json_error, 0);
220 MHD_add_response_header (resp,
"Content-Type",
"application/json");
222 json_decref (json_error);
233 handle->timeout_task = NULL;
234 handle->response_code = MHD_HTTP_REQUEST_TIMEOUT;
254 struct MHD_Response *resp;
258 handle->gns_lookup = NULL;
262 handle->response_code = MHD_HTTP_NOT_FOUND;
271 result = json_dumps (result_obj, 0);
276 "application/json"));
279 json_decref (result_obj);
310 handle->response_code = MHD_HTTP_NOT_FOUND;
315 if (0 >= strlen (
name))
317 handle->response_code = MHD_HTTP_NOT_FOUND;
324 handle->record_type = UINT32_MAX;
336 if (UINT32_MAX ==
handle->record_type)
362 struct MHD_Response *resp;
367 MHD_add_response_header (resp,
"Access-Control-Allow-Methods",
allow_methods);
398 handle->response_code = 0;
401 handle->proc_cls = proc_cls;
403 handle->rest_handle = rest_handle;
443 "%s, %s, %s, %s, %s",
445 MHD_HTTP_METHOD_POST,
447 MHD_HTTP_METHOD_DELETE,
448 MHD_HTTP_METHOD_OPTIONS);
struct GNUNET_MQ_MessageHandlers handlers[]
static struct GNUNET_GNS_Handle * gns
Connection to GNS.
void * REST_gns_init(const struct GNUNET_CONFIGURATION_Handle *c)
Entry point for the plugin.
static void get_gns_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle gns GET request.
static void do_timeout(void *cls)
#define GNUNET_REST_GNS_ERROR_UNKNOWN
Rest API GNS ERROR Unknown Error.
static struct RequestHandle * requests_head
DLL.
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Respond to OPTIONS request.
void REST_gns_done(struct GNUNET_REST_Plugin *api)
Exit point from the plugin.
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.
#define GNUNET_REST_API_NS_GNS
Rest API GNS Namespace.
static char * allow_methods
HTTP methods allows for this plugin.
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.
static struct RequestHandle * requests_tail
DLL.
#define GNUNET_REST_GNS_NOT_FOUND
Rest API GNS ERROR Record not found.
#define GNUNET_REST_GNS_PARAM_RECORD_TYPE
Rest API GNS Parameter record_type.
const struct GNUNET_CONFIGURATION_Handle * gns_cfg
The configuration handle.
static void do_error(void *cls)
Task run on errors.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
static struct MHD_Response * response
Our canonical response.
struct GNUNET_HashCode key
The key used in the DHT.
static char * name
Name (label) of the records to list.
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static int result
Global testing status.
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
API that can be used to manipulate JSON GNS record data.
API that can be used to manipulate GNS record data.
API for helper library to parse/create REST.
GNUnet service REST plugin header.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
void GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle)
Shutdown connection with the GNS service.
struct GNUNET_GNS_LookupWithTldRequest * GNUNET_GNS_lookup_with_tld(struct GNUNET_GNS_Handle *handle, const char *name, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor2 proc, void *proc_cls)
Perform an asynchronous lookup operation on the GNS, determining the zone using the TLD of the given ...
void * GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr)
Cancel pending lookup request.
struct GNUNET_GNS_Handle * GNUNET_GNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the connection with the GNS service.
@ GNUNET_GNS_LO_DEFAULT
Defaults, look in cache, then in DHT.
json_t * GNUNET_GNSRECORD_JSON_from_gnsrecord(const char *rname, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
Convert GNS record to JSON.
uint32_t GNUNET_GNSRECORD_typename_to_number(const char *dns_typename)
Convert a type name (e.g.
#define GNUNET_GNSRECORD_TYPE_ANY
Record type indicating any record/'*'.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
int GNUNET_REST_handle_request(struct GNUNET_REST_RequestHandle *conn, const struct GNUNET_REST_RequestHandler *handlers, struct GNUNET_REST_RequestHandlerError *err, void *cls)
void(* GNUNET_REST_ResultProcessor)(void *cls, struct MHD_Response *resp, int status)
Iterator called on obtained result for a REST result.
#define GNUNET_REST_HANDLER_END
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
void * cls
Closure for all of the callbacks.
Connection to the GNS service.
Handle to a lookup request.
struct returned by the initialization function of the plugin
void * cls
The closure of the plugin.
const char * name
Plugin name.
const char * url
The url as string.
struct GNUNET_CONTAINER_MultiHashMap * url_param_map
Map of url parameters.
void(* proc)(struct GNUNET_REST_RequestHandle *handle, const char *url, void *cls)
Namespace to handle.
Entry in list of pending tasks.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
char * emsg
Error response message.
struct RequestHandle * prev
DLL.
int response_code
HTTP response code.
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
void * proc_cls
The closure of the result processor.
int record_type
Record type to look up.
GNUNET_REST_ResultProcessor proc
The plugin result processor.
struct RequestHandle * next
DLL.
struct GNUNET_REST_RequestHandle * rest_handle
Handle to rest request.
struct GNUNET_GNS_LookupWithTldRequest * gns_lookup
Active GNS lookup.
char * name
Name to look up.
struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).