From: Alexia Pagkopoulou Date: Mon, 19 Aug 2019 15:36:48 +0000 (+0200) Subject: made the rest config editable X-Git-Tag: v0.11.7~185 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7c484d98416b489072cb728f614e17186a12c81c;p=oweals%2Fgnunet.git made the rest config editable --- diff --git a/src/rest/plugin_rest_config.c b/src/rest/plugin_rest_config.c index fe8d9bf7f..7f1d0eedf 100644 --- a/src/rest/plugin_rest_config.c +++ b/src/rest/plugin_rest_config.c @@ -134,7 +134,6 @@ add_section_contents (void *cls, json_object_set_new (section_obj, option, json_string (value)); } - /** * Handle rest request * @@ -179,6 +178,132 @@ get_cont (struct GNUNET_REST_RequestHandle *con_handle, json_decref (result); } +struct GNUNET_CONFIGURATION_Handle * +set_value (struct GNUNET_CONFIGURATION_Handle *config, + const char *section, + const char *option, + json_t *value) +{ + if (json_is_string (value)) + GNUNET_CONFIGURATION_set_value_string (config, section, option, json_string_value (value)); + else if (json_is_number (value)) + GNUNET_CONFIGURATION_set_value_number (config, section, option, json_integer_value (value)); + else if (json_is_null (value)) + GNUNET_CONFIGURATION_set_value_string (config, section, option, NULL); + else if (json_is_true (value)) + GNUNET_CONFIGURATION_set_value_string (config, section, option, "yes"); + else if (json_is_false (value)) + GNUNET_CONFIGURATION_set_value_string (config, section, option, "no"); + else + return NULL; + return config; // for error handling (0 -> success, 1 -> error) +} + +/** + * Handle REST POST request + * + * @param handle the lookup handle + */ +static void +set_cont (struct GNUNET_REST_RequestHandle *con_handle, + const char *url, + void *cls) +{ + struct RequestHandle *handle = cls; + char term_data[handle->rest_handle->data_size + 1]; + struct GNUNET_CONFIGURATION_Handle *out = GNUNET_CONFIGURATION_dup (cfg); + + json_error_t err; + json_t *data_json; + const char *section; + const char *option; + json_t *sec_obj; + json_t *value; + char *cfg_fn; + + // invalid url + if (strlen (GNUNET_REST_API_NS_CONFIG) > strlen (handle->url)) + { + handle->response_code = MHD_HTTP_BAD_REQUEST; + GNUNET_SCHEDULER_add_now (&do_error, handle); + return; + } + + // extract data from handle + term_data[handle->rest_handle->data_size] = '\0'; + GNUNET_memcpy (term_data, + handle->rest_handle->data, + handle->rest_handle->data_size); + data_json = json_loads (term_data, JSON_DECODE_ANY, &err); + + if (NULL == data_json) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unable to parse JSON Object from %s\n", + term_data); + GNUNET_SCHEDULER_add_now (&do_error, handle); + return; + } + + // POST /config => {
: {