34#define GNUNET_REST_API_NS_CONFIG "/config"
123 struct MHD_Response *resp;
137 json_t *sections_obj = cls;
140 sec_obj = json_object_get (sections_obj, section);
143 json_object_set_new (sec_obj, option, json_string (
value));
146 sec_obj = json_object ();
147 json_object_set_new (sec_obj, option, json_string (
value));
148 json_object_set_new (sections_obj, section, sec_obj);
158 json_t *section_obj = cls;
160 json_object_set_new (section_obj, option, json_string (
value));
174 struct MHD_Response *resp;
204 "application/json"));
218 if (json_is_string (
value))
220 json_string_value (
value));
221 else if (json_is_number (
value))
223 json_integer_value (
value));
224 else if (json_is_null (
value))
226 else if (json_is_true (
value))
228 else if (json_is_false (
value))
247 char term_data[
handle->rest_handle->data_size + 1];
268 term_data[
handle->rest_handle->data_size] =
'\0';
270 handle->rest_handle->data,
271 handle->rest_handle->data_size);
272 data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
274 if (NULL == data_json)
277 "Unable to parse JSON Object from %s\n",
287 json_object_foreach (data_json, section, sec_obj)
290 json_object_foreach (sec_obj, option,
value)
297 json_decref (data_json);
308 json_object_foreach (data_json, option,
value)
315 json_decref (data_json);
320 json_decref (data_json);
326 const char *xdg =
getenv (
"XDG_CONFIG_HOME");
358 struct MHD_Response *resp;
363 "Access-Control-Allow-Methods",
364 MHD_HTTP_METHOD_GET));
386 handle->proc_cls = proc_cls;
388 handle->rest_handle = conndata_handle;
struct GNUNET_MQ_MessageHandlers handlers[]
void * REST_config_init(const struct GNUNET_CONFIGURATION_Handle *c)
Entry point for the plugin.
static struct GNUNET_CONFIGURATION_Handle * set_value(struct GNUNET_CONFIGURATION_Handle *config, const char *section, const char *option, json_t *value)
static void add_section_contents(void *cls, const char *section, const char *option, const char *value)
static struct RequestHandle * requests_head
DLL.
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle rest request.
static void set_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle REST POST request.
const struct GNUNET_CONFIGURATION_Handle * config_cfg
enum GNUNET_GenericReturnValue REST_config_process_request(void *plugin, struct GNUNET_REST_RequestHandle *conndata_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function processing the REST call.
static void cleanup_handle(struct RequestHandle *handle)
Cleanup request handle.
#define GNUNET_REST_API_NS_CONFIG
static void add_sections(void *cls, const char *section, const char *option, const char *value)
static struct RequestHandle * requests_tail
DLL.
static void get_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle rest request.
static void do_error(void *cls)
Task run on shutdown.
void REST_config_done(struct GNUNET_REST_Plugin *api)
Exit point from the plugin.
static char * config_file
Set to the name of the config file used.
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
static struct MHD_Response * response
Our canonical response.
const struct GNUNET_CONFIGURATION_Handle * config
static char * value
Value of the record to add/remove.
static int result
Global testing status.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
API for helper library to parse/create REST.
GNUnet service REST plugin header.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the configuration.
void GNUNET_CONFIGURATION_set_value_number(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long number)
Set a configuration value that should be a number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
void GNUNET_CONFIGURATION_iterate_section_values(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over values of a section in the configuration.
#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.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_ERROR
@ 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.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
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.
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.
@ MHD_HTTP_BAD_REQUEST
Bad Request [RFC7231, Section 6.5.1].
@ MHD_HTTP_OK
OK [RFC7231, Section 6.3.1].
void * cls
Closure for all of the callbacks.
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.
void(* proc)(struct GNUNET_REST_RequestHandle *handle, const char *url, void *cls)
Namespace to handle.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct RequestHandle * prev
DLL.
int response_code
HTTP response code.
void * proc_cls
The closure of the result processor.
GNUNET_REST_ResultProcessor proc
The plugin result processor.
struct RequestHandle * next
DLL.
struct GNUNET_REST_RequestHandle * rest_handle
Handle to rest request.