33 #define GNUNET_REST_API_NS_CONFIG "/config"
121 struct MHD_Response *resp;
135 json_t *sections_obj = cls;
138 sec_obj = json_object_get (sections_obj, section);
141 json_object_set_new (sec_obj, option, json_string (
value));
144 sec_obj = json_object ();
145 json_object_set_new (sec_obj, option, json_string (
value));
146 json_object_set_new (sections_obj, section, sec_obj);
156 json_t *section_obj = cls;
158 json_object_set_new (section_obj, option, json_string (
value));
172 struct MHD_Response *resp;
202 "application/json"));
216 if (json_is_string (
value))
218 json_string_value (
value));
219 else if (json_is_number (
value))
221 json_integer_value (
value));
222 else if (json_is_null (
value))
224 else if (json_is_true (
value))
226 else if (json_is_false (
value))
245 char term_data[
handle->rest_handle->data_size + 1];
265 term_data[
handle->rest_handle->data_size] =
'\0';
267 handle->rest_handle->data,
268 handle->rest_handle->data_size);
269 data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
271 if (NULL == data_json)
274 "Unable to parse JSON Object from %s\n",
284 json_object_foreach (data_json, section, sec_obj)
287 json_object_foreach (sec_obj, option,
value)
294 json_decref (data_json);
305 json_object_foreach (data_json, option,
value)
312 json_decref (data_json);
317 json_decref (data_json);
322 const char *xdg =
getenv (
"XDG_CONFIG_HOME");
352 struct MHD_Response *resp;
357 "Access-Control-Allow-Methods",
358 MHD_HTTP_METHOD_GET));
389 handle->proc_cls = proc_cls;
391 handle->rest_handle = conndata_handle;
static char * config_file
Set to the name of the config file used.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
struct TestcasePlugin * plugin
The process handle to the testbed service.
static struct MHD_Response * response
Our canonical response.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static char * value
Value of the record to add/remove.
static int result
Global testing status.
static const struct GNUNET_CONFIGURATION_Handle * config
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.
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.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
#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_get(void)
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
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 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].
struct GNUNET_CONFIGURATION_Handle * set_value(struct GNUNET_CONFIGURATION_Handle *config, const char *section, const char *option, json_t *value)
void * libgnunet_plugin_rest_config_init(void *cls)
Entry point for the plugin.
const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to our configuration.
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 enum GNUNET_GenericReturnValue rest_config_process_request(struct GNUNET_REST_RequestHandle *conndata_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function processing the REST call.
static void set_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle REST POST request.
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 * libgnunet_plugin_rest_config_done(void *cls)
Exit point from the plugin.
void * cls
Closure for all of the callbacks.
struct returned by the initialization function of the plugin
void * cls
The closure of the plugin.
enum GNUNET_GenericReturnValue(* process_request)(struct GNUNET_REST_RequestHandle *handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function to process a REST call.
const char * url
The url as string.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct RequestHandle * prev
DLL.
int response_code
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
Rest connection.