![]() |
GNUnet
0.11.x
|
GNUnet Namestore REST plugin. More...
#include "platform.h"
#include "gnunet_rest_plugin.h"
#include "gnunet_gns_service.h"
#include "gnunet_namestore_service.h"
#include "gnunet_identity_service.h"
#include "gnunet_rest_lib.h"
#include "gnunet_gnsrecord_json_lib.h"
#include "microhttpd.h"
#include <jansson.h>
Go to the source code of this file.
Data Structures | |
struct | Plugin |
Handle for a plugin. More... | |
struct | EgoEntry |
The ego list. More... | |
struct | RequestHandle |
The request handle. More... | |
Macros | |
#define | GNUNET_REST_API_NS_NAMESTORE "/namestore" |
Namestore Namespace. More... | |
#define | GNUNET_REST_NAMESTORE_ERROR_UNKNOWN "Unknown Error" |
Error message Unknown Error. More... | |
#define | GNUNET_REST_IDENTITY_NOT_FOUND "No identity found" |
Error message No identity found. More... | |
#define | GNUNET_REST_NAMESTORE_FAILED "Namestore action failed" |
Error message Failed request. More... | |
#define | GNUNET_REST_NAMESTORE_INVALID_DATA "Data invalid" |
Error message invalid data. More... | |
#define | GNUNET_REST_NAMESTORE_NO_DATA "No data" |
Error message No data. More... | |
#define | ID_REST_STATE_INIT 0 |
State while collecting all egos. More... | |
#define | ID_REST_STATE_POST_INIT 1 |
Done collecting egos. More... | |
Enumerations | |
enum | UpdateStrategy { UPDATE_STRATEGY_REPLACE , UPDATE_STRATEGY_APPEND } |
Functions | |
static void | cleanup_handle (void *cls) |
Cleanup lookup handle. More... | |
static void | do_error (void *cls) |
Task run on errors. More... | |
struct EgoEntry * | get_egoentry_namestore (struct RequestHandle *handle, char *name) |
Get EgoEntry from list with either a public key or a name If public key and name are not NULL, it returns the public key result first. More... | |
static void | namestore_iteration_error (void *cls) |
Does internal server error when iteration failed. More... | |
static void | create_finished (void *cls, int32_t success, const char *emsg) |
Create finished callback. More... | |
static void | del_finished (void *cls, int32_t success, const char *emsg) |
Delete finished callback. More... | |
static void | namestore_list_finished (void *cls) |
Iteration over all results finished, build final response. More... | |
static void | namestore_list_iteration (void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd) |
Create a response with requested records. More... | |
static void | ns_lookup_error_cb (void *cls) |
Handle lookup error. More... | |
static void | ns_get_lookup_cb (void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd) |
void | namestore_get (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Handle namestore GET request. More... | |
static void | ns_lookup_cb (void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd) |
void | namestore_add_or_update (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Handle namestore POST/PUT request. More... | |
void | namestore_update (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Handle namestore PUT request. More... | |
void | namestore_add (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Handle namestore POST request. More... | |
void | namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Handle namestore DELETE request. More... | |
static void | options_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Respond to OPTIONS request. More... | |
static void | list_ego (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier) |
static enum GNUNET_GenericReturnValue | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls) |
Function processing the REST call. More... | |
void * | libgnunet_plugin_rest_namestore_init (void *cls) |
Entry point for the plugin. More... | |
void * | libgnunet_plugin_rest_namestore_done (void *cls) |
Exit point from the plugin. More... | |
Variables | |
const struct GNUNET_CONFIGURATION_Handle * | cfg |
The configuration handle. More... | |
static char * | allow_methods |
HTTP methods allows for this plugin. More... | |
static struct EgoEntry * | ego_head |
Ego list. More... | |
static struct EgoEntry * | ego_tail |
Ego list. More... | |
static int | state |
The processing state. More... | |
static struct GNUNET_NAMESTORE_Handle * | ns_handle |
Handle to NAMESTORE. More... | |
static struct GNUNET_IDENTITY_Handle * | identity_handle |
Handle to Identity service. More... | |
static struct RequestHandle * | requests_head |
DLL. More... | |
static struct RequestHandle * | requests_tail |
DLL. More... | |
GNUnet Namestore REST plugin.
Definition in file plugin_rest_namestore.c.
#define GNUNET_REST_API_NS_NAMESTORE "/namestore" |
Namestore Namespace.
Definition at line 40 of file plugin_rest_namestore.c.
#define GNUNET_REST_NAMESTORE_ERROR_UNKNOWN "Unknown Error" |
Error message Unknown Error.
Definition at line 45 of file plugin_rest_namestore.c.
#define GNUNET_REST_IDENTITY_NOT_FOUND "No identity found" |
Error message No identity found.
Definition at line 50 of file plugin_rest_namestore.c.
#define GNUNET_REST_NAMESTORE_FAILED "Namestore action failed" |
Error message Failed request.
Definition at line 56 of file plugin_rest_namestore.c.
#define GNUNET_REST_NAMESTORE_INVALID_DATA "Data invalid" |
Error message invalid data.
Definition at line 61 of file plugin_rest_namestore.c.
#define GNUNET_REST_NAMESTORE_NO_DATA "No data" |
Error message No data.
Definition at line 66 of file plugin_rest_namestore.c.
#define ID_REST_STATE_INIT 0 |
State while collecting all egos.
Definition at line 71 of file plugin_rest_namestore.c.
#define ID_REST_STATE_POST_INIT 1 |
Done collecting egos.
Definition at line 76 of file plugin_rest_namestore.c.
enum UpdateStrategy |
Enumerator | |
---|---|
UPDATE_STRATEGY_REPLACE | |
UPDATE_STRATEGY_APPEND |
Definition at line 152 of file plugin_rest_namestore.c.
|
static |
Cleanup lookup handle.
handle | Handle to clean up |
Definition at line 286 of file plugin_rest_namestore.c.
References GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_free_nz, GNUNET_log, GNUNET_NAMESTORE_cancel(), GNUNET_NAMESTORE_zone_iteration_stop(), GNUNET_SCHEDULER_cancel(), handle, requests_head, and requests_tail.
Referenced by create_finished(), del_finished(), do_error(), namestore_list_finished(), and options_cont().
|
static |
Task run on errors.
Reports an error and cleans up everything.
cls | the struct RequestHandle |
Definition at line 335 of file plugin_rest_namestore.c.
References cleanup_handle(), GNUNET_free, GNUNET_REST_create_response(), GNUNET_REST_NAMESTORE_ERROR_UNKNOWN, GNUNET_strdup, handle, and response.
Referenced by create_finished(), del_finished(), libgnunet_plugin_rest_namestore_done(), namestore_add_or_update(), namestore_delete(), namestore_get(), namestore_iteration_error(), ns_lookup_cb(), and ns_lookup_error_cb().
struct EgoEntry* get_egoentry_namestore | ( | struct RequestHandle * | handle, |
char * | name | ||
) |
Get EgoEntry from list with either a public key or a name If public key and name are not NULL, it returns the public key result first.
handle | the RequestHandle |
pubkey | the public key of an identity (only one can be NULL) |
name | the name of an identity (only one can be NULL) |
Definition at line 369 of file plugin_rest_namestore.c.
References ego_head, GNUNET_free, GNUNET_strdup, EgoEntry::identifier, name, and EgoEntry::next.
Referenced by namestore_add_or_update(), namestore_delete(), and namestore_get().
|
static |
Does internal server error when iteration failed.
cls | the struct RequestHandle |
Definition at line 399 of file plugin_rest_namestore.c.
References do_error(), GNUNET_REST_NAMESTORE_FAILED, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, and handle.
Referenced by namestore_get().
|
static |
Create finished callback.
cls | the struct RequestHandle |
success | the success indicating integer, GNUNET_OK on success |
emsg | the error message (can be NULL) |
Definition at line 417 of file plugin_rest_namestore.c.
References cleanup_handle(), do_error(), GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_YES, and handle.
Referenced by ns_lookup_cb().
|
static |
Delete finished callback.
cls | the struct RequestHandle |
success | the success indicating integer, GNUNET_OK on success |
emsg | the error message (can be NULL) |
Definition at line 449 of file plugin_rest_namestore.c.
References cleanup_handle(), do_error(), RequestHandle::emsg, GNUNET_NO, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_SYSERR, and handle.
Referenced by namestore_delete().
|
static |
Iteration over all results finished, build final response.
cls | the struct RequestHandle |
Definition at line 487 of file plugin_rest_namestore.c.
References cleanup_handle(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), and handle.
Referenced by namestore_get(), and ns_get_lookup_cb().
|
static |
Create a response with requested records.
handle | the RequestHandle |
Only add if not empty
Definition at line 514 of file plugin_rest_namestore.c.
References GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_JSON_from_gnsrecord(), GNUNET_GNSRECORD_TYPE_ANY, GNUNET_NAMESTORE_zone_iterator_next(), handle, and GNUNET_GNSRECORD_Data::record_type.
Referenced by namestore_get().
|
static |
Handle lookup error.
cls | the request handle |
Definition at line 555 of file plugin_rest_namestore.c.
References do_error(), GNUNET_REST_NAMESTORE_FAILED, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, and handle.
Referenced by namestore_add_or_update(), and namestore_get().
|
static |
Only add if not empty
Definition at line 565 of file plugin_rest_namestore.c.
References GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_JSON_from_gnsrecord(), GNUNET_GNSRECORD_TYPE_ANY, GNUNET_SCHEDULER_add_now(), handle, namestore_list_finished(), and GNUNET_GNSRECORD_Data::record_type.
Referenced by namestore_get().
void namestore_get | ( | struct GNUNET_REST_RequestHandle * | con_handle, |
const char * | url, | ||
void * | cls | ||
) |
Handle namestore GET request.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 609 of file plugin_rest_namestore.c.
References do_error(), EgoEntry::ego, egoname, get_egoentry_namestore(), GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_GNSRECORD_TYPE_ANY, GNUNET_GNSRECORD_typename_to_number(), GNUNET_IDENTITY_ego_get_private_key(), GNUNET_NAMESTORE_records_lookup(), GNUNET_NAMESTORE_zone_iteration_start(), GNUNET_NO, GNUNET_REST_API_NS_NAMESTORE, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_REST_NAMESTORE_FAILED, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, EgoEntry::identifier, key, namestore_iteration_error(), namestore_list_finished(), namestore_list_iteration(), ns_get_lookup_cb(), ns_handle, ns_lookup_error_cb(), and GNUNET_REST_RequestHandle::url_param_map.
|
static |
Definition at line 693 of file plugin_rest_namestore.c.
References create_finished(), do_error(), GNUNET_NAMESTORE_records_store(), GNUNET_REST_NAMESTORE_FAILED, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, ns_handle, and UPDATE_STRATEGY_APPEND.
Referenced by namestore_add_or_update().
void namestore_add_or_update | ( | struct GNUNET_REST_RequestHandle * | con_handle, |
const char * | url, | ||
void * | cls | ||
) |
Handle namestore POST/PUT request.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 735 of file plugin_rest_namestore.c.
References do_error(), EgoEntry::ego, egoname, get_egoentry_namestore(), GNUNET_GNSRECORD_JSON_spec_gnsrecord(), GNUNET_IDENTITY_ego_get_private_key(), GNUNET_JSON_parse(), GNUNET_JSON_parse_free(), GNUNET_JSON_spec_end(), GNUNET_memcpy, GNUNET_NAMESTORE_records_lookup(), GNUNET_OK, GNUNET_REST_API_NS_NAMESTORE, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_REST_NAMESTORE_FAILED, GNUNET_REST_NAMESTORE_INVALID_DATA, GNUNET_REST_NAMESTORE_NO_DATA, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, ns_handle, ns_lookup_cb(), and ns_lookup_error_cb().
Referenced by namestore_add(), and namestore_update().
void namestore_update | ( | struct GNUNET_REST_RequestHandle * | con_handle, |
const char * | url, | ||
void * | cls | ||
) |
Handle namestore PUT request.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 827 of file plugin_rest_namestore.c.
References handle, namestore_add_or_update(), UPDATE_STRATEGY_REPLACE, and RequestHandle::url.
void namestore_add | ( | struct GNUNET_REST_RequestHandle * | con_handle, |
const char * | url, | ||
void * | cls | ||
) |
Handle namestore POST request.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 845 of file plugin_rest_namestore.c.
References handle, namestore_add_or_update(), UPDATE_STRATEGY_APPEND, and RequestHandle::url.
void namestore_delete | ( | struct GNUNET_REST_RequestHandle * | con_handle, |
const char * | url, | ||
void * | cls | ||
) |
Handle namestore DELETE request.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 863 of file plugin_rest_namestore.c.
References del_finished(), do_error(), EgoEntry::ego, egoname, get_egoentry_namestore(), GNUNET_IDENTITY_ego_get_private_key(), GNUNET_NAMESTORE_records_store(), GNUNET_REST_API_NS_NAMESTORE, GNUNET_REST_IDENTITY_NOT_FOUND, GNUNET_REST_NAMESTORE_FAILED, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, EgoEntry::identifier, and ns_handle.
|
static |
Respond to OPTIONS request.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 928 of file plugin_rest_namestore.c.
References allow_methods, cleanup_handle(), GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), and handle.
|
static |
Definition at line 945 of file plugin_rest_namestore.c.
References EgoEntry::ego, ego_head, ego_tail, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_IDENTITY_ego_get_public_key(), GNUNET_IDENTITY_public_key_to_string(), GNUNET_log, GNUNET_new, GNUNET_strdup, ID_REST_STATE_INIT, ID_REST_STATE_POST_INIT, EgoEntry::identifier, EgoEntry::keystring, EgoEntry::next, pk, and state.
Referenced by libgnunet_plugin_rest_namestore_init().
|
static |
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 945 of file plugin_rest_namestore.c.
Referenced by libgnunet_plugin_rest_namestore_init().
void* libgnunet_plugin_rest_namestore_init | ( | void * | cls | ) |
Entry point for the plugin.
cls | Config info |
Definition at line 1086 of file plugin_rest_namestore.c.
References _, allow_methods, Plugin::cfg, cfg, GNUNET_REST_Plugin::cls, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_IDENTITY_connect(), GNUNET_log, GNUNET_NAMESTORE_connect(), GNUNET_new, GNUNET_REST_API_NS_NAMESTORE, ID_REST_STATE_INIT, identity_handle, list_ego(), GNUNET_REST_Plugin::name, ns_handle, plugin, GNUNET_REST_Plugin::process_request, rest_process_request(), and state.
void* libgnunet_plugin_rest_namestore_done | ( | void * | cls | ) |
Exit point from the plugin.
cls | the plugin context (as returned by "init") |
Definition at line 1123 of file plugin_rest_namestore.c.
References allow_methods, Plugin::api, Plugin::cfg, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_REST_Plugin::cls, do_error(), ego_head, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_IDENTITY_disconnect(), GNUNET_log, GNUNET_NAMESTORE_disconnect(), EgoEntry::identifier, identity_handle, EgoEntry::keystring, EgoEntry::next, ns_handle, plugin, request, and requests_head.
const struct GNUNET_CONFIGURATION_Handle* cfg |
The configuration handle.
Handle to our configuration.
Definition at line 80 of file plugin_rest_namestore.c.
Referenced by libgnunet_plugin_rest_namestore_init().
|
static |
HTTP methods allows for this plugin.
Definition at line 85 of file plugin_rest_namestore.c.
Referenced by libgnunet_plugin_rest_namestore_done(), libgnunet_plugin_rest_namestore_init(), and options_cont().
|
static |
Ego list.
Definition at line 90 of file plugin_rest_namestore.c.
Referenced by get_egoentry_namestore(), libgnunet_plugin_rest_namestore_done(), and list_ego().
|
static |
|
static |
The processing state.
Definition at line 100 of file plugin_rest_namestore.c.
Referenced by libgnunet_plugin_rest_namestore_init(), and list_ego().
|
static |
Handle to NAMESTORE.
Definition at line 105 of file plugin_rest_namestore.c.
Referenced by libgnunet_plugin_rest_namestore_done(), libgnunet_plugin_rest_namestore_init(), namestore_add_or_update(), namestore_delete(), namestore_get(), and ns_lookup_cb().
|
static |
Handle to Identity service.
Definition at line 110 of file plugin_rest_namestore.c.
Referenced by libgnunet_plugin_rest_namestore_done(), and libgnunet_plugin_rest_namestore_init().
|
static |
DLL.
Definition at line 273 of file plugin_rest_namestore.c.
Referenced by cleanup_handle(), and libgnunet_plugin_rest_namestore_done().
|
static |