GNUnet Namestore REST plugin. More...
#include "platform.h"
#include "gnunet_error_codes.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_API_NS_NAMESTORE_IMPORT "/namestore/import" |
Namestore import API namespace. 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, 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. 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, struct GNUNET_TIME_Absolute expiry) |
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) |
static void | bulk_tx_commit_cb (void *cls, enum GNUNET_ErrorCode ec) |
static void | import_next_cb (void *cls, enum GNUNET_ErrorCode ec) |
static void | bulk_tx_start (void *cls, enum GNUNET_ErrorCode ec) |
void | namestore_import (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Handle namestore POST import. More... | |
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 41 of file plugin_rest_namestore.c.
#define GNUNET_REST_API_NS_NAMESTORE_IMPORT "/namestore/import" |
Namestore import API namespace.
Definition at line 46 of file plugin_rest_namestore.c.
#define ID_REST_STATE_INIT 0 |
State while collecting all egos.
Definition at line 51 of file plugin_rest_namestore.c.
#define ID_REST_STATE_POST_INIT 1 |
Done collecting egos.
Definition at line 56 of file plugin_rest_namestore.c.
enum UpdateStrategy |
Enumerator | |
---|---|
UPDATE_STRATEGY_REPLACE | |
UPDATE_STRATEGY_APPEND |
Definition at line 132 of file plugin_rest_namestore.c.
|
static |
Cleanup lookup handle.
cls | Handle to clean up |
Definition at line 282 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_disconnect(), GNUNET_NAMESTORE_zone_iteration_stop(), GNUNET_SCHEDULER_cancel(), handle, requests_head, and requests_tail.
Referenced by bulk_tx_commit_cb(), 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 330 of file plugin_rest_namestore.c.
References cleanup_handle(), GNUNET_assert, GNUNET_ErrorCode_get_hint(), GNUNET_ErrorCode_get_http_status(), GNUNET_free, GNUNET_REST_create_response(), handle, MHD_HTTP_INTERNAL_SERVER_ERROR, and response.
Referenced by bulk_tx_commit_cb(), bulk_tx_start(), create_finished(), del_finished(), import_next_cb(), libgnunet_plugin_rest_namestore_done(), namestore_add_or_update(), namestore_delete(), namestore_get(), namestore_import(), namestore_iteration_error(), namestore_list_finished(), ns_get_lookup_cb(), 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 367 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(), namestore_get(), and namestore_import().
|
static |
Does internal server error when iteration failed.
cls | the struct RequestHandle |
Definition at line 397 of file plugin_rest_namestore.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 plugin_rest_namestore.c.
References cleanup_handle(), do_error(), GNUNET_EC_NONE, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), handle, and MHD_HTTP_NO_CONTENT.
Referenced by ns_lookup_cb().
|
static |
Definition at line 427 of file plugin_rest_namestore.c.
References cleanup_handle(), do_error(), RequestHandle::ec, GNUNET_EC_NONE, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), handle, and MHD_HTTP_NO_CONTENT.
Referenced by namestore_delete().
|
static |
Iteration over all results finished, build final response.
cls | the struct RequestHandle |
Definition at line 452 of file plugin_rest_namestore.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(), handle, and MHD_HTTP_OK.
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 plugin_rest_namestore.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 533 of file plugin_rest_namestore.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 543 of file plugin_rest_namestore.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().
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 586 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_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.
|
static |
Definition at line 694 of file plugin_rest_namestore.c.
References create_finished(), do_error(), GNUNET_EC_NAMESTORE_UNKNOWN, GNUNET_NAMESTORE_records_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 729 of file plugin_rest_namestore.c.
References cleanup_handle(), do_error(), GNUNET_EC_NONE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), handle, and MHD_HTTP_NO_CONTENT.
Referenced by import_next_cb().
|
static |
Definition at line 750 of file plugin_rest_namestore.c.
References bulk_tx_commit_cb(), do_error(), RequestHandle::ec, GNUNET_EC_NAMESTORE_UNKNOWN, GNUNET_EC_NONE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NAMESTORE_records_store2(), GNUNET_NAMESTORE_transaction_commit(), GNUNET_SCHEDULER_add_now(), handle, and RequestHandle::rd_set_pos.
Referenced by bulk_tx_start().
|
static |
Definition at line 792 of file plugin_rest_namestore.c.
References do_error(), RequestHandle::ec, GNUNET_EC_NAMESTORE_NO_RECORDS_GIVEN, GNUNET_EC_NAMESTORE_RECORD_DATA_INVALID, GNUNET_EC_NAMESTORE_UNKNOWN, GNUNET_EC_NONE, 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_store2(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), handle, import_next_cb(), rd, and value.
Referenced by namestore_import().
void namestore_import | ( | struct GNUNET_REST_RequestHandle * | con_handle, |
const char * | url, | ||
void * | cls | ||
) |
Handle namestore POST import.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 893 of file plugin_rest_namestore.c.
References bulk_tx_start(), cfg, 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_NAMESTORE_transaction_begin(), GNUNET_REST_API_NS_NAMESTORE_IMPORT, GNUNET_SCHEDULER_add_now(), and handle.
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 943 of file plugin_rest_namestore.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().
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 1031 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 1049 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 1067 of file plugin_rest_namestore.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_records_store(), GNUNET_REST_API_NS_NAMESTORE, 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 1129 of file plugin_rest_namestore.c.
References allow_methods, cleanup_handle(), GNUNET_assert, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), handle, and MHD_HTTP_OK.
|
static |
Definition at line 1149 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 1149 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 1294 of file plugin_rest_namestore.c.
References _, allow_methods, 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 1332 of file plugin_rest_namestore.c.
References allow_methods, Plugin::api, 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 60 of file plugin_rest_namestore.c.
Referenced by libgnunet_plugin_rest_namestore_init(), and namestore_import().
|
static |
HTTP methods allows for this plugin.
Definition at line 65 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 70 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 80 of file plugin_rest_namestore.c.
Referenced by libgnunet_plugin_rest_namestore_init(), and list_ego().
|
static |
Handle to NAMESTORE.
Definition at line 85 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 90 of file plugin_rest_namestore.c.
Referenced by libgnunet_plugin_rest_namestore_done(), and libgnunet_plugin_rest_namestore_init().
|
static |
DLL.
Definition at line 269 of file plugin_rest_namestore.c.
Referenced by cleanup_handle(), and libgnunet_plugin_rest_namestore_done().
|
static |