aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorPhil <phil.buschmann@tum.de>2018-06-25 00:17:06 +0200
committerPhil <phil.buschmann@tum.de>2018-06-25 00:17:06 +0200
commit4e6cb01843318385cfad41aec4cde5791f51cde2 (patch)
tree5759d9767f06c668d453f2c2e7fb646199be2a1b /src/gns
parent688bd873c3cb463090039f64b9f13b9a029695dc (diff)
downloadgnunet-4e6cb01843318385cfad41aec4cde5791f51cde2.tar.gz
gnunet-4e6cb01843318385cfad41aec4cde5791f51cde2.zip
Identity+GNS Rest changed and fixed
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/plugin_rest_gns.c72
1 files changed, 36 insertions, 36 deletions
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c
index 57fdfc1d5..22c908275 100644
--- a/src/gns/plugin_rest_gns.c
+++ b/src/gns/plugin_rest_gns.c
@@ -19,26 +19,24 @@
19 */ 19 */
20/** 20/**
21 * @author Philippe Buschmann 21 * @author Philippe Buschmann
22 * @file gns1/plugin_rest_gns1.c 22 * @file gns/plugin_rest_gns.c
23 * @brief GNUnet Gns1 REST plugin 23 * @brief GNUnet Gns REST plugin
24 */ 24 */
25 25
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_rest_plugin.h" 27#include "gnunet_rest_plugin.h"
28#include "gnunet_rest_lib.h" 28#include "gnunet_rest_lib.h"
29#include "gnunet_gnsrecord_lib.h" 29#include "gnunet_gnsrecord_lib.h"
30#include "gnunet_gns_service.h"
30#include "microhttpd.h" 31#include "microhttpd.h"
31#include <jansson.h> 32#include <jansson.h>
32 33
33#define GNUNET_REST_API_NS_GNS "/gns" 34#define GNUNET_REST_API_NS_GNS "/gns"
34 35
35//TODO define other variables
36#define GNUNET_REST_PARAMETER_GNS_NAME "name" 36#define GNUNET_REST_PARAMETER_GNS_NAME "name"
37 37
38#define GNUNET_REST_PARAMETER_GNS_RECORD_TYPE "record_type" 38#define GNUNET_REST_PARAMETER_GNS_RECORD_TYPE "record_type"
39 39
40#define GNUNET_REST_PARAMETER_GNS_NAME "name"
41
42/** 40/**
43 * The configuration handle 41 * The configuration handle
44 */ 42 */
@@ -57,13 +55,10 @@ struct Plugin
57 const struct GNUNET_CONFIGURATION_Handle *cfg; 55 const struct GNUNET_CONFIGURATION_Handle *cfg;
58}; 56};
59 57
60//TODO add specific structs
61
62 58
63 59
64struct RequestHandle 60struct RequestHandle
65{ 61{
66 //TODO add specific entries
67 62
68 /** 63 /**
69 * Connection to GNS 64 * Connection to GNS
@@ -160,8 +155,6 @@ cleanup_handle (struct RequestHandle *handle)
160 GNUNET_free (handle->name); 155 GNUNET_free (handle->name);
161 if (NULL != handle->emsg) 156 if (NULL != handle->emsg)
162 GNUNET_free (handle->emsg); 157 GNUNET_free (handle->emsg);
163
164 //TODO add specific cleanup
165 158
166 GNUNET_free (handle); 159 GNUNET_free (handle);
167} 160}
@@ -212,6 +205,10 @@ handle_gns_response (void *cls,
212 struct MHD_Response *resp; 205 struct MHD_Response *resp;
213 json_t *result_array; 206 json_t *result_array;
214 json_t *record_obj; 207 json_t *record_obj;
208 char *record_value;
209 char *result;
210
211 handle->gns_lookup = NULL;
215 212
216 if (GNUNET_NO == was_gns) 213 if (GNUNET_NO == was_gns)
217 { 214 {
@@ -219,7 +216,6 @@ handle_gns_response (void *cls,
219 GNUNET_SCHEDULER_add_now (&do_error, handle); 216 GNUNET_SCHEDULER_add_now (&do_error, handle);
220 return; 217 return;
221 } 218 }
222
223 if (0 == rd_count) 219 if (0 == rd_count)
224 { 220 {
225 handle->emsg = GNUNET_strdup("No result found"); 221 handle->emsg = GNUNET_strdup("No result found");
@@ -228,10 +224,6 @@ handle_gns_response (void *cls,
228 } 224 }
229 225
230 result_array = json_array(); 226 result_array = json_array();
231 //TODO test break!
232 GNUNET_break (NULL != handle->gns_lookup);
233 handle->gns_lookup = NULL;
234
235 for (uint32_t i=0;i<rd_count;i++) 227 for (uint32_t i=0;i<rd_count;i++)
236 { 228 {
237 if ((rd[i].record_type != handle->record_type) && 229 if ((rd[i].record_type != handle->record_type) &&
@@ -240,7 +232,10 @@ handle_gns_response (void *cls,
240 continue; 232 continue;
241 } 233 }
242 234
243 record_obj = gnsrecord_to_json (&(rd[i])); 235 record_value = GNUNET_GNSRECORD_value_to_string (rd->record_type,
236 rd->data,
237 rd->data_size);
238 record_obj = json_string(record_value);
244 json_array_append (result_array, record_obj); 239 json_array_append (result_array, record_obj);
245 json_decref (record_obj); 240 json_decref (record_obj);
246 } 241 }
@@ -256,7 +251,7 @@ handle_gns_response (void *cls,
256 251
257 252
258/** 253/**
259 * Handle gns1 GET request 254 * Handle gns GET request
260 * 255 *
261 * @param con_handle the connection handle 256 * @param con_handle the connection handle
262 * @param url the url 257 * @param url the url
@@ -269,6 +264,7 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
269{ 264{
270 struct RequestHandle *handle = cls; 265 struct RequestHandle *handle = cls;
271 struct GNUNET_HashCode key; 266 struct GNUNET_HashCode key;
267 int conversion_state;
272 268
273 GNUNET_CRYPTO_hash (GNUNET_REST_PARAMETER_GNS_NAME, 269 GNUNET_CRYPTO_hash (GNUNET_REST_PARAMETER_GNS_NAME,
274 strlen (GNUNET_REST_PARAMETER_GNS_NAME), 270 strlen (GNUNET_REST_PARAMETER_GNS_NAME),
@@ -295,8 +291,22 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
295 GNUNET_SCHEDULER_add_now (&do_error, handle); 291 GNUNET_SCHEDULER_add_now (&do_error, handle);
296 return; 292 return;
297 } 293 }
298 handle->record_type = GNUNET_strdup( 294 conversion_state = sscanf (
299 GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,&key)); 295 GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key),"%u",
296 &(handle->record_type));
297
298 if((EOF == conversion_state) || (0 == conversion_state))
299 {
300 handle->record_type = GNUNET_GNSRECORD_TYPE_ANY;
301 }
302
303 handle->gns = GNUNET_GNS_connect (cfg);
304 if (NULL == handle->gns)
305 {
306 handle->emsg = GNUNET_strdup ("GNS not available");
307 GNUNET_SCHEDULER_add_now (&do_error, handle);
308 return;
309 }
300 310
301 handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns, 311 handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns,
302 handle->name, 312 handle->name,
@@ -304,6 +314,7 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
304 GNUNET_NO, 314 GNUNET_NO,
305 &handle_gns_response, 315 &handle_gns_response,
306 handle); 316 handle);
317
307 if (NULL == handle->gns_lookup) 318 if (NULL == handle->gns_lookup)
308 { 319 {
309 handle->emsg = GNUNET_strdup("GNS lookup failed"); 320 handle->emsg = GNUNET_strdup("GNS lookup failed");
@@ -395,19 +406,8 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
395 handle->url[strlen (handle->url)-1] = '\0'; 406 handle->url[strlen (handle->url)-1] = '\0';
396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); 407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
397 408
398
399 handle->gns = GNUNET_GNS_connect (cfg);
400 if (NULL == handle->gns)
401 {
402 handle->emsg = GNUNET_strdup ("GNS not available");
403 GNUNET_SCHEDULER_add_now (&do_error, handle);
404 return;
405 }
406
407 init_cont(handle); 409 init_cont(handle);
408 //TODO connect to specific service 410
409 //connect ( cfg, [..., &callback_function, handle]);
410 //TODO callback then init_cont(handle)
411 handle->timeout_task = 411 handle->timeout_task =
412 GNUNET_SCHEDULER_add_delayed (handle->timeout, 412 GNUNET_SCHEDULER_add_delayed (handle->timeout,
413 &do_error, 413 &do_error,
@@ -424,7 +424,7 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
424 * @return NULL on error, otherwise the plugin context 424 * @return NULL on error, otherwise the plugin context
425 */ 425 */
426void * 426void *
427libgnunet_plugin_rest_gns1_init (void *cls) 427libgnunet_plugin_rest_gns_init (void *cls)
428{ 428{
429 static struct Plugin plugin; 429 static struct Plugin plugin;
430 struct GNUNET_REST_Plugin *api; 430 struct GNUNET_REST_Plugin *api;
@@ -447,7 +447,7 @@ libgnunet_plugin_rest_gns1_init (void *cls)
447 MHD_HTTP_METHOD_OPTIONS); 447 MHD_HTTP_METHOD_OPTIONS);
448 448
449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
450 _("Gns1 REST API initialized\n")); 450 _("Gns REST API initialized\n"));
451 return api; 451 return api;
452} 452}
453 453
@@ -459,7 +459,7 @@ libgnunet_plugin_rest_gns1_init (void *cls)
459 * @return always NULL 459 * @return always NULL
460 */ 460 */
461void * 461void *
462libgnunet_plugin_rest_gns1_done (void *cls) 462libgnunet_plugin_rest_gns_done (void *cls)
463{ 463{
464 struct GNUNET_REST_Plugin *api = cls; 464 struct GNUNET_REST_Plugin *api = cls;
465 struct Plugin *plugin = api->cls; 465 struct Plugin *plugin = api->cls;
@@ -468,9 +468,9 @@ libgnunet_plugin_rest_gns1_done (void *cls)
468 GNUNET_free_non_null (allow_methods); 468 GNUNET_free_non_null (allow_methods);
469 GNUNET_free (api); 469 GNUNET_free (api);
470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
471 "Gns1 REST plugin is finished\n"); 471 "Gns REST plugin is finished\n");
472 return NULL; 472 return NULL;
473} 473}
474 474
475/* end of plugin_rest_gns1.c */ 475/* end of plugin_rest_gns.c */
476 476