33 #define GNUNET_REST_API_NS_CONFIG "/config"
122 struct MHD_Response *resp;
136 json_t *sections_obj = cls;
139 sec_obj = json_object_get (sections_obj, section);
142 json_object_set_new (sec_obj, option, json_string (
value));
145 sec_obj = json_object ();
146 json_object_set_new (sec_obj, option, json_string (
value));
147 json_object_set_new (sections_obj, section, sec_obj);
157 json_t *section_obj = cls;
159 json_object_set_new (section_obj, option, json_string (
value));
173 struct MHD_Response *resp;
181 handle->response_code = MHD_HTTP_BAD_REQUEST;
203 "application/json"));
217 if (json_is_string (
value))
219 json_string_value (
value));
220 else if (json_is_number (
value))
222 json_integer_value (
value));
223 else if (json_is_null (
value))
225 else if (json_is_true (
value))
227 else if (json_is_false (
value))
246 char term_data[
handle->rest_handle->data_size + 1];
260 handle->response_code = MHD_HTTP_BAD_REQUEST;
266 term_data[
handle->rest_handle->data_size] =
'\0';
268 handle->rest_handle->data,
269 handle->rest_handle->data_size);
270 data_json = json_loads (term_data, JSON_DECODE_ANY, &err);
272 if (NULL == data_json)
275 "Unable to parse JSON Object from %s\n",
285 json_object_foreach (data_json, section, sec_obj)
288 json_object_foreach (sec_obj, option,
value)
293 handle->response_code = MHD_HTTP_BAD_REQUEST;
295 json_decref (data_json);
306 json_object_foreach (data_json, option,
value)
311 handle->response_code = MHD_HTTP_BAD_REQUEST;
313 json_decref (data_json);
318 json_decref (data_json);
323 const char *xdg =
getenv (
"XDG_CONFIG_HOME");
353 struct MHD_Response *resp;
358 "Access-Control-Allow-Methods",
359 MHD_HTTP_METHOD_GET));
390 handle->proc_cls = proc_cls;
392 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 Plugin * 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
#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.
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_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.
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.