33 #define GNUNET_REST_API_NS_CONFIG "/config" 104 if (NULL != handle->
url)
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;
188 result = json_object ();
193 result = json_object ();
200 response = json_dumps (result, 0);
202 MHD_add_response_header (resp,
"Content-Type",
"application/json");
206 json_decref (result);
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))
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)
289 out =
set_value (out, section, option, value);
294 json_decref (data_json);
305 json_object_foreach (data_json, option, value)
307 out =
set_value (out, section, option, value);
312 json_decref (data_json);
317 json_decref (data_json);
322 const char *xdg =
getenv (
"XDG_CONFIG_HOME");
351 struct MHD_Response *resp;
355 MHD_add_response_header (resp,
356 "Access-Control-Allow-Methods",
357 MHD_HTTP_METHOD_GET);
392 if (handle->
url[strlen (handle->
url) - 1] ==
'/')
393 handle->
url[strlen (handle->
url) - 1] =
'\0';
416 static struct Plugin plugin;
421 memset (&plugin, 0,
sizeof(
struct Plugin));
444 while (NULL != requests_head)
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void(* GNUNET_REST_ResultProcessor)(void *cls, struct MHD_Response *resp, int status)
Iterator called on obtained result for a REST result.
#define GNUNET_REST_API_NS_CONFIG
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_insert(head, tail, element)
Insert an element at the head of a DLL.
static struct RequestHandle * requests_head
DLL.
void * cls
The closure of the plugin.
size_t data_size
The POST data size.
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the configuration.
GNUNET_REST_ResultProcessor proc
The plugin result processor.
static char * config_file
Set to the name of the config file used.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct returned by the initialization function of the plugin
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.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void * proc_cls
The closure of the result processor.
#define GNUNET_REST_HANDLER_END
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
static char * section
Name of the section.
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 struct RequestHandle * requests_tail
DLL.
static char * value
Value of the record to add/remove.
const char * url
The url as string.
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.
static char * option
Name of the option.
static void do_error(void *cls)
Task run on shutdown.
static const struct GNUNET_CONFIGURATION_Handle * config
static void get_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle rest request.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static int result
Global testing status.
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.
int GNUNET_REST_handle_request(struct GNUNET_REST_RequestHandle *conn, const struct GNUNET_REST_RequestHandler *handlers, struct GNUNET_REST_RequestHandlerError *err, void *cls)
static void add_section_contents(void *cls, const char *section, const char *option, const char *value)
struct GNUNET_REST_RequestHandle * rest_handle
Rest connection.
int response_code
Response code.
static char * plugin
Solver plugin name as string.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
const char * data
The POST data.
struct RequestHandle * next
DLL.
void * libgnunet_plugin_rest_config_init(void *cls)
Entry point for the plugin.
struct RequestHandle * prev
DLL.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
static void set_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle REST POST request.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
#define GNUNET_log(kind,...)
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
static struct MHD_Response * response
Our canonical response.
static void add_sections(void *cls, const char *section, const char *option, const char *value)
void * libgnunet_plugin_rest_config_done(void *cls)
Exit point from the plugin.
struct GNUNET_CONFIGURATION_Handle * set_value(struct GNUNET_CONFIGURATION_Handle *config, const char *section, const char *option, json_t *value)
enum GNUNET_GenericReturnValue(* process_request)(struct GNUNET_REST_RequestHandle *handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function to process a REST call.
static void cleanup_handle(struct RequestHandle *handle)
Cleanup request handle.
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle rest request.
#define GNUNET_free(ptr)
Wrapper around free.