#include "platform.h"#include "gnunet_error_codes.h"#include "gnunet_rest_plugin.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>#include "namestore_plugin.h"Go to the source code of this file.
Data Structures | |
| struct | Plugin |
| Handle for a plugin. More... | |
| struct | EgoEntry |
| The default namestore ego. More... | |
| struct | RequestHandle |
| The request handle. More... | |
Macros | |
| #define | GNUNET_REST_API_NS_NAMESTORE "/namestore" |
| Namestore namespace. | |
| #define | GNUNET_REST_API_NS_NAMESTORE_IMPORT "/namestore/import" |
| Namestore import API namespace. | |
| #define | ID_REST_STATE_INIT 0 |
| State while collecting all egos. | |
| #define | ID_REST_STATE_POST_INIT 1 |
| Done collecting egos. | |
Enumerations | |
| enum | UpdateStrategy { UPDATE_STRATEGY_REPLACE , UPDATE_STRATEGY_APPEND } |
Functions | |
| static void | cleanup_handle (void *cls) |
| Cleanup lookup handle. | |
| static void | do_error (void *cls) |
| Task run on errors. | |
| static 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. | |
| static void | namestore_iteration_error (void *cls) |
| Does internal server error when iteration failed. | |
| static void | create_finished (void *cls, enum GNUNET_ErrorCode ec) |
| static void | del_finished (void *cls, enum GNUNET_ErrorCode ec) |
| static void | namestore_list_finished (void *cls) |
| Iteration over all results finished, build final response. | |
| static void | namestore_list_iteration (void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute expiry) |
| Create a response with requested records. | |
| static void | ns_lookup_error_cb (void *cls) |
| Handle lookup error. | |
| static void | ns_get_lookup_cb (void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const char *label, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd) |
| static void | namestore_get (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
| Handle namestore GET request. | |
| static void | ns_lookup_cb (void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd) |
| static void | import_next_cb (void *cls, enum GNUNET_ErrorCode ec) |
| static void | bulk_tx_start (struct RequestHandle *handle) |
| static void | namestore_import (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
| Handle namestore POST import. | |
| static void | namestore_add_or_update (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
| Handle namestore POST/PUT request. | |
| static void | namestore_update (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
| Handle namestore PUT request. | |
| static void | namestore_add (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
| Handle namestore POST request. | |
| static void | namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
| Handle namestore DELETE request. | |
| static void | options_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
| Respond to OPTIONS request. | |
| static void | list_ego (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier) |
| enum GNUNET_GenericReturnValue | REST_namestore_process_request (void *plugin, struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls) |
| Function processing the REST call. | |
| void * | REST_namestore_init (const struct GNUNET_CONFIGURATION_Handle *c) |
| Entry point for the plugin. | |
| void | REST_namestore_done (struct GNUNET_REST_Plugin *api) |
| Exit point from the plugin. | |
Variables | |
| const struct GNUNET_CONFIGURATION_Handle * | ns_cfg |
| The configuration handle. | |
| static char * | allow_methods |
| HTTP methods allows for this plugin. | |
| static struct EgoEntry * | ego_head |
| Ego list. | |
| static struct EgoEntry * | ego_tail |
| Ego list. | |
| static int | state |
| The processing state. | |
| static struct GNUNET_NAMESTORE_Handle * | ns_handle |
| Handle to NAMESTORE. | |
| static struct GNUNET_IDENTITY_Handle * | identity_handle |
| Handle to Identity service. | |
| static struct RequestHandle * | requests_head |
| DLL. | |
| static struct RequestHandle * | requests_tail |
| DLL. | |
| #define GNUNET_REST_API_NS_NAMESTORE "/namestore" |
Namestore namespace.
Definition at line 41 of file namestore_plugin.c.
| #define GNUNET_REST_API_NS_NAMESTORE_IMPORT "/namestore/import" |
Namestore import API namespace.
Definition at line 46 of file namestore_plugin.c.
| #define ID_REST_STATE_INIT 0 |
State while collecting all egos.
Definition at line 51 of file namestore_plugin.c.
| #define ID_REST_STATE_POST_INIT 1 |
Done collecting egos.
Definition at line 56 of file namestore_plugin.c.
| enum UpdateStrategy |
| Enumerator | |
|---|---|
| UPDATE_STRATEGY_REPLACE | |
| UPDATE_STRATEGY_APPEND | |
Definition at line 132 of file namestore_plugin.c.
|
static |
Cleanup lookup handle.
| cls | Handle to clean up |
Definition at line 282 of file namestore_plugin.c.
References GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_free_nz, GNUNET_log, GNUNET_NAMESTORE_cancel(), GNUNET_NAMESTORE_disconnect(), GNUNET_NAMESTORE_zone_iteration_stop(), GNUNET_SCHEDULER_cancel(), handle, requests_head, and requests_tail.
Referenced by create_finished(), del_finished(), do_error(), import_next_cb(), namestore_list_finished(), options_cont(), and REST_namestore_process_request().
|
static |
Task run on errors.
Reports an error and cleans up everything.
| cls | the struct RequestHandle |
Definition at line 330 of file namestore_plugin.c.
References cleanup_handle(), GNUNET_assert, GNUNET_ErrorCode_get_hint(), GNUNET_ErrorCode_get_http_status(), GNUNET_free, GNUNET_REST_create_response(), handle, and response.
Referenced by bulk_tx_start(), create_finished(), del_finished(), import_next_cb(), namestore_add_or_update(), namestore_delete(), namestore_get(), namestore_import(), namestore_iteration_error(), namestore_list_finished(), ns_get_lookup_cb(), ns_lookup_cb(), ns_lookup_error_cb(), REST_namestore_done(), and REST_namestore_process_request().
|
static |
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 367 of file namestore_plugin.c.
References ego_head, GNUNET_free, GNUNET_strdup, EgoEntry::identifier, name, and EgoEntry::next.
Referenced by namestore_add_or_update(), namestore_delete(), namestore_get(), and namestore_import().
|
static |
Does internal server error when iteration failed.
| cls | the struct RequestHandle |
Definition at line 397 of file namestore_plugin.c.
References do_error(), GNUNET_EC_NAMESTORE_ITERATION_FAILED, GNUNET_SCHEDULER_add_now(), and handle.
Referenced by namestore_get().
|
static |
Definition at line 408 of file namestore_plugin.c.
References cleanup_handle(), do_error(), GNUNET_EC_NONE, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), and handle.
Referenced by ns_lookup_cb().
|
static |
Definition at line 427 of file namestore_plugin.c.
References cleanup_handle(), do_error(), RequestHandle::ec, GNUNET_EC_NONE, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), and handle.
Referenced by namestore_delete().
|
static |
Iteration over all results finished, build final response.
| cls | the struct RequestHandle |
Definition at line 452 of file namestore_plugin.c.
References cleanup_handle(), do_error(), GNUNET_assert, GNUNET_EC_NAMESTORE_ZONE_EMPTY, 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 |
skip
Only add if not empty
Definition at line 484 of file namestore_plugin.c.
References GNUNET_GNSRECORD_Data::data, GNUNET_GNSRECORD_JSON_from_gnsrecord(), GNUNET_GNSRECORD_TYPE_ANY, GNUNET_NAMESTORE_zone_iterator_next(), handle, rd, and GNUNET_GNSRECORD_Data::record_type.
Referenced by namestore_get().
|
static |
Handle lookup error.
| cls | the request handle |
Definition at line 534 of file namestore_plugin.c.
References do_error(), GNUNET_EC_NAMESTORE_LOOKUP_ERROR, GNUNET_SCHEDULER_add_now(), and handle.
Referenced by namestore_add_or_update(), and namestore_get().
|
static |
Return 404 if no set was found
Definition at line 544 of file namestore_plugin.c.
References GNUNET_GNSRECORD_Data::data, do_error(), GNUNET_EC_NAMESTORE_RECORD_NOT_FOUND, GNUNET_GNSRECORD_JSON_from_gnsrecord(), GNUNET_GNSRECORD_TYPE_ANY, GNUNET_SCHEDULER_add_now(), handle, namestore_list_finished(), rd, and GNUNET_GNSRECORD_Data::record_type.
Referenced by namestore_get().
|
static |
Handle namestore GET request.
| con_handle | the connection handle |
| url | the url |
| cls | the RequestHandle |
Definition at line 587 of file namestore_plugin.c.
References do_error(), EgoEntry::ego, egoname, get_egoentry_namestore(), GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_EC_NAMESTORE_UNKNOWN, GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND, GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE, GNUNET_GNSRECORD_FILTER_NONE, GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE, GNUNET_GNSRECORD_TYPE_ANY, GNUNET_GNSRECORD_typename_to_number(), GNUNET_IDENTITY_ego_get_private_key(), GNUNET_NAMESTORE_records_lookup2(), GNUNET_NAMESTORE_zone_iteration_start2(), GNUNET_REST_API_NS_NAMESTORE, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, GNUNET_YES, 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.
Referenced by REST_namestore_process_request().
|
static |
Definition at line 695 of file namestore_plugin.c.
References create_finished(), do_error(), GNUNET_EC_NAMESTORE_UNKNOWN, GNUNET_NAMESTORE_record_set_store(), GNUNET_SCHEDULER_add_now(), handle, ns_handle, rd, rd_count, and UPDATE_STRATEGY_APPEND.
Referenced by namestore_add_or_update().
|
static |
Definition at line 730 of file namestore_plugin.c.
References cleanup_handle(), do_error(), RequestHandle::ec, GNUNET_EC_NAMESTORE_UNKNOWN, GNUNET_EC_NONE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NAMESTORE_records_store(), GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), handle, and import_next_cb().
Referenced by bulk_tx_start(), and import_next_cb().
|
static |
Definition at line 787 of file namestore_plugin.c.
References do_error(), GNUNET_EC_NAMESTORE_NO_RECORDS_GIVEN, GNUNET_EC_NAMESTORE_RECORD_DATA_INVALID, GNUNET_EC_NAMESTORE_UNKNOWN, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_GNSRECORD_JSON_spec_gnsrecord(), GNUNET_JSON_parse(), GNUNET_JSON_spec_end(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_NAMESTORE_records_store(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), handle, import_next_cb(), rd, and value.
Referenced by namestore_import().
|
static |
Handle namestore POST import.
| con_handle | the connection handle |
| url | the url |
| cls | the RequestHandle |
Definition at line 884 of file namestore_plugin.c.
References bulk_tx_start(), do_error(), EgoEntry::ego, egoname, get_egoentry_namestore(), GNUNET_EC_NAMESTORE_UNKNOWN, GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_NAMESTORE_connect(), GNUNET_REST_API_NS_NAMESTORE_IMPORT, GNUNET_SCHEDULER_add_now(), handle, and ns_cfg.
Referenced by REST_namestore_process_request().
|
static |
Handle namestore POST/PUT request.
| con_handle | the connection handle |
| url | the url |
| cls | the RequestHandle |
Definition at line 933 of file namestore_plugin.c.
References do_error(), EgoEntry::ego, egoname, get_egoentry_namestore(), GNUNET_EC_NAMESTORE_NO_RECORDS_GIVEN, GNUNET_EC_NAMESTORE_RECORD_DATA_INVALID, GNUNET_EC_NAMESTORE_UNKNOWN, GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND, 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_SCHEDULER_add_now(), handle, ns_handle, ns_lookup_cb(), and ns_lookup_error_cb().
Referenced by namestore_add(), and namestore_update().
|
static |
Handle namestore PUT request.
| con_handle | the connection handle |
| url | the url |
| cls | the RequestHandle |
Definition at line 1021 of file namestore_plugin.c.
References handle, namestore_add_or_update(), UPDATE_STRATEGY_REPLACE, and RequestHandle::url.
Referenced by REST_namestore_process_request().
|
static |
Handle namestore POST request.
| con_handle | the connection handle |
| url | the url |
| cls | the RequestHandle |
Definition at line 1039 of file namestore_plugin.c.
References handle, namestore_add_or_update(), UPDATE_STRATEGY_APPEND, and RequestHandle::url.
Referenced by REST_namestore_process_request().
|
static |
Handle namestore DELETE request.
| con_handle | the connection handle |
| url | the url |
| cls | the RequestHandle |
Definition at line 1057 of file namestore_plugin.c.
References del_finished(), do_error(), EgoEntry::ego, egoname, get_egoentry_namestore(), GNUNET_EC_NAMESTORE_NO_LABEL_GIVEN, GNUNET_EC_NAMESTORE_UNKNOWN, GNUNET_EC_NAMESTORE_ZONE_NOT_FOUND, GNUNET_IDENTITY_ego_get_private_key(), GNUNET_NAMESTORE_record_set_store(), GNUNET_REST_API_NS_NAMESTORE, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, EgoEntry::identifier, and ns_handle.
Referenced by REST_namestore_process_request().
|
static |
Respond to OPTIONS request.
| con_handle | the connection handle |
| url | the url |
| cls | the RequestHandle |
Definition at line 1119 of file namestore_plugin.c.
References allow_methods, cleanup_handle(), GNUNET_assert, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), and handle.
Referenced by REST_namestore_process_request().
|
static |
Definition at line 1139 of file namestore_plugin.c.
References EgoEntry::ego, ego_head, ego_tail, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_CRYPTO_blindable_public_key_to_string(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_IDENTITY_ego_get_public_key(), 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 REST_namestore_init().
| enum GNUNET_GenericReturnValue REST_namestore_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 1232 of file namestore_plugin.c.
References cleanup_handle(), do_error(), GNUNET_CONTAINER_DLL_insert, GNUNET_EC_NONE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_REST_API_NS_NAMESTORE, GNUNET_REST_API_NS_NAMESTORE_IMPORT, GNUNET_REST_handle_request(), GNUNET_REST_HANDLER_END, GNUNET_SCHEDULER_add_delayed(), GNUNET_strdup, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, handle, handlers, namestore_add(), namestore_delete(), namestore_get(), namestore_import(), namestore_update(), options_cont(), GNUNET_REST_RequestHandler::proc, requests_head, requests_tail, and GNUNET_REST_RequestHandle::url.
Referenced by run().
| void * REST_namestore_init | ( | const struct GNUNET_CONFIGURATION_Handle * | c | ) |
Entry point for the plugin.
| cls | Config info |
Definition at line 1285 of file namestore_plugin.c.
References _, allow_methods, 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_cfg, ns_handle, plugin, and state.
Referenced by run().
| void REST_namestore_done | ( | struct GNUNET_REST_Plugin * | api | ) |
Exit point from the plugin.
| cls | the plugin context (as returned by "init") |
Definition at line 1322 of file namestore_plugin.c.
References allow_methods, Plugin::api, GNUNET_BLOCK_PluginFunctions::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.
Referenced by do_shutdown().
| const struct GNUNET_CONFIGURATION_Handle* ns_cfg |
The configuration handle.
Definition at line 60 of file namestore_plugin.c.
Referenced by namestore_import(), and REST_namestore_init().
|
static |
HTTP methods allows for this plugin.
Definition at line 65 of file namestore_plugin.c.
Referenced by options_cont(), REST_namestore_done(), and REST_namestore_init().
|
static |
Ego list.
Definition at line 70 of file namestore_plugin.c.
Referenced by get_egoentry_namestore(), list_ego(), and REST_namestore_done().
|
static |
|
static |
The processing state.
Definition at line 80 of file namestore_plugin.c.
Referenced by list_ego(), and REST_namestore_init().
|
static |
Handle to NAMESTORE.
Definition at line 85 of file namestore_plugin.c.
Referenced by namestore_add_or_update(), namestore_delete(), namestore_get(), ns_lookup_cb(), REST_namestore_done(), and REST_namestore_init().
|
static |
Handle to Identity service.
Definition at line 90 of file namestore_plugin.c.
Referenced by REST_namestore_done(), and REST_namestore_init().
|
static |
DLL.
Definition at line 269 of file namestore_plugin.c.
Referenced by cleanup_handle(), REST_namestore_done(), and REST_namestore_process_request().
|
static |
DLL.
Definition at line 274 of file namestore_plugin.c.
Referenced by cleanup_handle(), and REST_namestore_process_request().