aboutsummaryrefslogtreecommitdiff
path: root/src/identity
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2015-03-26 15:51:56 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2015-03-26 15:51:56 +0000
commit726b28a61c858b4b251e4a0a006e4021b01886c0 (patch)
tree8b8d6dded055f1fefd2cee84dabb59dc889dcfe8 /src/identity
parent9982f58b45230373960cea1fe1fb294602bdd56d (diff)
downloadgnunet-726b28a61c858b4b251e4a0a006e4021b01886c0.tar.gz
gnunet-726b28a61c858b4b251e4a0a006e4021b01886c0.zip
-fix mem corruption
Diffstat (limited to 'src/identity')
-rw-r--r--src/identity/plugin_rest_identity.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c
index d62e56db2..2fb29d87d 100644
--- a/src/identity/plugin_rest_identity.c
+++ b/src/identity/plugin_rest_identity.c
@@ -31,9 +31,7 @@
31#include "microhttpd.h" 31#include "microhttpd.h"
32#include <jansson.h> 32#include <jansson.h>
33 33
34#define API_NAMESPACE "/identity" 34#define GNUNET_REST_API_NS_IDENTITY "/identity"
35
36#define EGO_NAMESPACE "/identity/egos"
37 35
38#define ID_REST_STATE_INIT 0 36#define ID_REST_STATE_INIT 0
39 37
@@ -183,8 +181,6 @@ cleanup_handle (struct RequestHandle *handle)
183 struct EgoEntry *ego_tmp; 181 struct EgoEntry *ego_tmp;
184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
185 "Cleaning up\n"); 183 "Cleaning up\n");
186 if (NULL != handle->json_root)
187 json_decref (handle->json_root);
188 if (NULL != handle->name) 184 if (NULL != handle->name)
189 GNUNET_free (handle->name); 185 GNUNET_free (handle->name);
190 if (NULL != handle->timeout_task) 186 if (NULL != handle->timeout_task)
@@ -301,16 +297,14 @@ ego_info_response (struct RestConnectionDataHandle *con,
301 struct JsonApiObject *json_object; 297 struct JsonApiObject *json_object;
302 struct JsonApiResource *json_resource; 298 struct JsonApiResource *json_resource;
303 json_t *key_str; 299 json_t *key_str;
304 300 if (GNUNET_NO == GNUNET_REST_namespace_match (handle->url, GNUNET_REST_API_NS_IDENTITY))
305 if (GNUNET_NO == GNUNET_REST_namespace_match (handle->url, EGO_NAMESPACE))
306 { 301 {
307 resp = GNUNET_REST_create_json_response (NULL); 302 resp = GNUNET_REST_create_json_response (NULL);
308 handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST); 303 handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
309 cleanup_handle (handle); 304 cleanup_handle (handle);
310 GNUNET_break (0);
311 return; 305 return;
312 } 306 }
313 if ( (strlen (EGO_NAMESPACE) == strlen (handle->url) )) { 307 if ( (strlen (GNUNET_REST_API_NS_IDENTITY) == strlen (handle->url) )) {
314 GNUNET_CRYPTO_hash (URL_PARAM_SUBSYS, strlen (URL_PARAM_SUBSYS), &key); 308 GNUNET_CRYPTO_hash (URL_PARAM_SUBSYS, strlen (URL_PARAM_SUBSYS), &key);
315 if ( GNUNET_YES == 309 if ( GNUNET_YES ==
316 GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map, 310 GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map,
@@ -331,13 +325,12 @@ ego_info_response (struct RestConnectionDataHandle *con,
331 } 325 }
332 } 326 }
333 json_object = GNUNET_REST_jsonapi_object_new (); 327 json_object = GNUNET_REST_jsonapi_object_new ();
334 egoname = &handle->url[strlen (EGO_NAMESPACE)+1]; 328 egoname = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY)+1];
335 329
336 if (strlen (EGO_NAMESPACE) == strlen (handle->url)) 330 if (strlen (GNUNET_REST_API_NS_IDENTITY) == strlen (handle->url))
337 { 331 {
338 egoname = NULL; 332 egoname = NULL;
339 } 333 }
340
341 //Return all egos 334 //Return all egos
342 for (ego_entry = handle->ego_head; 335 for (ego_entry = handle->ego_head;
343 NULL != ego_entry; 336 NULL != ego_entry;
@@ -355,7 +348,12 @@ ego_info_response (struct RestConnectionDataHandle *con,
355 GNUNET_free (keystring); 348 GNUNET_free (keystring);
356 GNUNET_REST_jsonapi_object_resource_add (json_object, json_resource); 349 GNUNET_REST_jsonapi_object_resource_add (json_object, json_resource);
357 } 350 }
358 351 if (0 == GNUNET_REST_jsonapi_object_resource_count (json_object))
352 {
353 GNUNET_REST_jsonapi_object_delete (json_object);
354 GNUNET_SCHEDULER_add_now (&do_error, handle);
355 return;
356 }
359 GNUNET_REST_jsonapi_data_serialize (json_object, &result_str); 357 GNUNET_REST_jsonapi_data_serialize (json_object, &result_str);
360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); 358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
361 resp = GNUNET_REST_create_json_response (result_str); 359 resp = GNUNET_REST_create_json_response (result_str);
@@ -430,7 +428,7 @@ ego_create_cont (struct RestConnectionDataHandle *con,
430 char term_data[handle->data_size+1]; 428 char term_data[handle->data_size+1];
431 const char* egoname; 429 const char* egoname;
432 430
433 if (strlen (API_NAMESPACE) != strlen (handle->url)) 431 if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url))
434 { 432 {
435 GNUNET_SCHEDULER_add_now (&do_error, handle); 433 GNUNET_SCHEDULER_add_now (&do_error, handle);
436 return; 434 return;
@@ -513,13 +511,13 @@ subsys_set_cont (struct RestConnectionDataHandle *con,
513 int ego_exists = GNUNET_NO; 511 int ego_exists = GNUNET_NO;
514 json_t *subsys_json; 512 json_t *subsys_json;
515 513
516 if (strlen (API_NAMESPACE) > strlen (handle->url)) 514 if (strlen (GNUNET_REST_API_NS_IDENTITY) > strlen (handle->url))
517 { 515 {
518 GNUNET_SCHEDULER_add_now (&do_error, handle); 516 GNUNET_SCHEDULER_add_now (&do_error, handle);
519 return; 517 return;
520 } 518 }
521 519
522 egoname = &handle->url[strlen(EGO_NAMESPACE)+1]; 520 egoname = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY)+1];
523 for (ego_entry = handle->ego_head; 521 for (ego_entry = handle->ego_head;
524 NULL != ego_entry; 522 NULL != ego_entry;
525 ego_entry = ego_entry->next) 523 ego_entry = ego_entry->next)
@@ -605,13 +603,13 @@ ego_delete_cont (struct RestConnectionDataHandle *con_handle,
605 struct RequestHandle *handle = cls; 603 struct RequestHandle *handle = cls;
606 int ego_exists = GNUNET_NO; 604 int ego_exists = GNUNET_NO;
607 605
608 if (strlen (API_NAMESPACE) >= strlen (handle->url)) 606 if (strlen (GNUNET_REST_API_NS_IDENTITY) >= strlen (handle->url))
609 { 607 {
610 GNUNET_SCHEDULER_add_now (&do_error, handle); 608 GNUNET_SCHEDULER_add_now (&do_error, handle);
611 return; 609 return;
612 } 610 }
613 611
614 egoname = &handle->url[strlen(API_NAMESPACE)+1]; 612 egoname = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY)+1];
615 for (ego_entry = handle->ego_head; 613 for (ego_entry = handle->ego_head;
616 NULL != ego_entry; 614 NULL != ego_entry;
617 ego_entry = ego_entry->next) 615 ego_entry = ego_entry->next)
@@ -640,10 +638,10 @@ void
640init_cont (struct RequestHandle *handle) 638init_cont (struct RequestHandle *handle)
641{ 639{
642 static const struct GNUNET_REST_RestConnectionHandler handlers[] = { 640 static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
643 {MHD_HTTP_METHOD_GET, API_NAMESPACE, &ego_info_response}, 641 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_info_response},
644 {MHD_HTTP_METHOD_POST, API_NAMESPACE, &ego_create_cont}, 642 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create_cont},
645 {MHD_HTTP_METHOD_PUT, API_NAMESPACE, &subsys_set_cont}, 643 {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY, &subsys_set_cont},
646 {MHD_HTTP_METHOD_DELETE, API_NAMESPACE, &ego_delete_cont}, 644 {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_IDENTITY, &ego_delete_cont},
647 GNUNET_REST_HANDLER_END 645 GNUNET_REST_HANDLER_END
648 }; 646 };
649 647
@@ -775,7 +773,7 @@ libgnunet_plugin_rest_identity_init (void *cls)
775 plugin.cfg = cfg; 773 plugin.cfg = cfg;
776 api = GNUNET_new (struct GNUNET_REST_Plugin); 774 api = GNUNET_new (struct GNUNET_REST_Plugin);
777 api->cls = &plugin; 775 api->cls = &plugin;
778 api->name = API_NAMESPACE; 776 api->name = GNUNET_REST_API_NS_IDENTITY;
779 api->process_request = &rest_identity_process_request; 777 api->process_request = &rest_identity_process_request;
780 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 778 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
781 _("Identity REST API initialized\n")); 779 _("Identity REST API initialized\n"));