aboutsummaryrefslogtreecommitdiff
path: root/src/gns/plugin_rest_gns.c
diff options
context:
space:
mode:
authorPhil <phil.buschmann@tum.de>2018-08-12 23:11:10 +0200
committerPhil <phil.buschmann@tum.de>2018-08-12 23:11:10 +0200
commit4df7069dcd17ac39c786ee6f21455c96e6a6dbf4 (patch)
tree80fe63630f82dd79f73f24cbb954c0703cd873f3 /src/gns/plugin_rest_gns.c
parent89485145a0f33984a70bffdf0f766667b4a3e75e (diff)
downloadgnunet-4df7069dcd17ac39c786ee6f21455c96e6a6dbf4.tar.gz
gnunet-4df7069dcd17ac39c786ee6f21455c96e6a6dbf4.zip
Changed Namestore API, changed error handling, changed gns record json
Diffstat (limited to 'src/gns/plugin_rest_gns.c')
-rw-r--r--src/gns/plugin_rest_gns.c62
1 files changed, 35 insertions, 27 deletions
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c
index fd2469577..0bf4198fc 100644
--- a/src/gns/plugin_rest_gns.c
+++ b/src/gns/plugin_rest_gns.c
@@ -30,15 +30,27 @@
30#include "microhttpd.h" 30#include "microhttpd.h"
31#include <jansson.h> 31#include <jansson.h>
32 32
33/**
34 * Rest API GNS Namespace
35 */
33#define GNUNET_REST_API_NS_GNS "/gns" 36#define GNUNET_REST_API_NS_GNS "/gns"
34 37
35 38/**
36#define GNUNET_REST_GNS_PARAM_NAME "name" 39 * Rest API GNS Parameter record_type
37 40 */
38#define GNUNET_REST_GNS_PARAM_RECORD_TYPE "record_type" 41#define GNUNET_REST_GNS_PARAM_RECORD_TYPE "record_type"
42
43/**
44 * Rest API GNS ERROR Unknown Error
45 */
39#define GNUNET_REST_GNS_ERROR_UNKNOWN "Unknown Error" 46#define GNUNET_REST_GNS_ERROR_UNKNOWN "Unknown Error"
40 47
41/** 48/**
49 * Rest API GNS ERROR Record not found
50 */
51#define GNUNET_REST_GNS_NOT_FOUND "Record not found"
52
53/**
42 * The configuration handle 54 * The configuration handle
43 */ 55 */
44const struct GNUNET_CONFIGURATION_Handle *cfg; 56const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -56,7 +68,9 @@ struct Plugin
56 const struct GNUNET_CONFIGURATION_Handle *cfg; 68 const struct GNUNET_CONFIGURATION_Handle *cfg;
57}; 69};
58 70
59 71/**
72 * The request handle
73 */
60struct RequestHandle 74struct RequestHandle
61{ 75{
62 76
@@ -116,7 +130,7 @@ struct RequestHandle
116 char *emsg; 130 char *emsg;
117 131
118 /** 132 /**
119 * Reponse code 133 * Response code
120 */ 134 */
121 int response_code; 135 int response_code;
122 136
@@ -214,7 +228,8 @@ handle_gns_response (void *cls,
214 228
215 if (GNUNET_NO == was_gns) 229 if (GNUNET_NO == was_gns)
216 { 230 {
217 handle->emsg = GNUNET_strdup("Name not found in GNS"); 231 handle->response_code = MHD_HTTP_NOT_FOUND;
232 handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND);
218 GNUNET_SCHEDULER_add_now (&do_error, handle); 233 GNUNET_SCHEDULER_add_now (&do_error, handle);
219 return; 234 return;
220 } 235 }
@@ -260,21 +275,24 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
260 char *record_type; 275 char *record_type;
261 char *name; 276 char *name;
262 277
263 GNUNET_CRYPTO_hash (GNUNET_REST_GNS_PARAM_NAME, 278 name = NULL;
264 strlen (GNUNET_REST_GNS_PARAM_NAME), 279 handle->name = NULL;
265 &key); 280 if (strlen (GNUNET_REST_API_NS_GNS) < strlen (handle->url))
266 if ( GNUNET_NO 281 {
267 == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, 282 name = &handle->url[strlen (GNUNET_REST_API_NS_GNS) + 1];
268 &key)) 283 }
284
285 if (NULL == name)
269 { 286 {
270 handle->emsg = GNUNET_strdup("Parameter name is missing"); 287 handle->response_code = MHD_HTTP_NOT_FOUND;
288 handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND);
271 GNUNET_SCHEDULER_add_now (&do_error, handle); 289 GNUNET_SCHEDULER_add_now (&do_error, handle);
272 return; 290 return;
273 } 291 }
274 name = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,&key); 292 if (0 >= strlen (name))
275 if(0 >= strlen (name))
276 { 293 {
277 handle->emsg = GNUNET_strdup("Length of parameter name is zero"); 294 handle->response_code = MHD_HTTP_NOT_FOUND;
295 handle->emsg = GNUNET_strdup(GNUNET_REST_GNS_NOT_FOUND);
278 GNUNET_SCHEDULER_add_now (&do_error, handle); 296 GNUNET_SCHEDULER_add_now (&do_error, handle);
279 return; 297 return;
280 } 298 }
@@ -292,27 +310,17 @@ get_gns_cont (struct GNUNET_REST_RequestHandle *con_handle,
292 handle->record_type = GNUNET_GNSRECORD_typename_to_number(record_type); 310 handle->record_type = GNUNET_GNSRECORD_typename_to_number(record_type);
293 } 311 }
294 312
295
296 if(UINT32_MAX == handle->record_type) 313 if(UINT32_MAX == handle->record_type)
297 { 314 {
298 handle->record_type = GNUNET_GNSRECORD_TYPE_ANY; 315 handle->record_type = GNUNET_GNSRECORD_TYPE_ANY;
299 } 316 }
300 317
301 handle->gns = GNUNET_GNS_connect (cfg);
302 if (NULL == handle->gns)
303 {
304 handle->emsg = GNUNET_strdup ("GNS not available");
305 GNUNET_SCHEDULER_add_now (&do_error, handle);
306 return;
307 }
308
309 handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns, 318 handle->gns_lookup = GNUNET_GNS_lookup_with_tld (handle->gns,
310 handle->name, 319 handle->name,
311 handle->record_type, 320 handle->record_type,
312 GNUNET_NO, 321 GNUNET_NO,
313 &handle_gns_response, 322 &handle_gns_response,
314 handle); 323 handle);
315 return;
316} 324}
317 325
318 326
@@ -397,7 +405,7 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
397 if (handle->url[strlen (handle->url)-1] == '/') 405 if (handle->url[strlen (handle->url)-1] == '/')
398 handle->url[strlen (handle->url)-1] = '\0'; 406 handle->url[strlen (handle->url)-1] = '\0';
399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); 407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
400 408 handle->gns = GNUNET_GNS_connect (cfg);
401 init_cont(handle); 409 init_cont(handle);
402 410
403 handle->timeout_task = 411 handle->timeout_task =