diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-25 23:43:37 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-25 23:43:37 +0200 |
commit | 1a94233aed0b6f195c1c9cb8827d7fd5ae9b8b30 (patch) | |
tree | f75f1cef4a1adf0b3561d4942ee63f29ebf847f3 /src/namestore | |
parent | a9921bf3acffe86beacd4f40819f44a1e719c42f (diff) | |
download | gnunet-1a94233aed0b6f195c1c9cb8827d7fd5ae9b8b30.tar.gz gnunet-1a94233aed0b6f195c1c9cb8827d7fd5ae9b8b30.zip |
NAMESTORE/REST: fix add record
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/plugin_rest_namestore.c | 402 |
1 files changed, 213 insertions, 189 deletions
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c index b25b10493..46e5a590f 100644 --- a/src/namestore/plugin_rest_namestore.c +++ b/src/namestore/plugin_rest_namestore.c | |||
@@ -86,7 +86,7 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
86 | /** | 86 | /** |
87 | * HTTP methods allows for this plugin | 87 | * HTTP methods allows for this plugin |
88 | */ | 88 | */ |
89 | static char* allow_methods; | 89 | static char *allow_methods; |
90 | 90 | ||
91 | /** | 91 | /** |
92 | * @brief struct returned by the initialization function of the plugin | 92 | * @brief struct returned by the initialization function of the plugin |
@@ -236,7 +236,6 @@ struct RequestHandle | |||
236 | * Response code | 236 | * Response code |
237 | */ | 237 | */ |
238 | int response_code; | 238 | int response_code; |
239 | |||
240 | }; | 239 | }; |
241 | 240 | ||
242 | /** | 241 | /** |
@@ -250,51 +249,49 @@ cleanup_handle (void *cls) | |||
250 | struct EgoEntry *ego_entry; | 249 | struct EgoEntry *ego_entry; |
251 | struct EgoEntry *ego_tmp; | 250 | struct EgoEntry *ego_tmp; |
252 | 251 | ||
253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); |
254 | "Cleaning up\n"); | ||
255 | if (NULL != handle->timeout_task) | 253 | if (NULL != handle->timeout_task) |
256 | { | 254 | { |
257 | GNUNET_SCHEDULER_cancel (handle->timeout_task); | 255 | GNUNET_SCHEDULER_cancel (handle->timeout_task); |
258 | handle->timeout_task = NULL; | 256 | handle->timeout_task = NULL; |
259 | } | 257 | } |
260 | if (NULL != handle->record_name) | 258 | if (NULL != handle->record_name) |
261 | GNUNET_free(handle->record_name); | 259 | GNUNET_free (handle->record_name); |
262 | if (NULL != handle->url) | 260 | if (NULL != handle->url) |
263 | GNUNET_free(handle->url); | 261 | GNUNET_free (handle->url); |
264 | if (NULL != handle->emsg) | 262 | if (NULL != handle->emsg) |
265 | GNUNET_free(handle->emsg); | 263 | GNUNET_free (handle->emsg); |
266 | if (NULL != handle->rd) | 264 | if (NULL != handle->rd) |
267 | { | 265 | { |
268 | if (NULL != handle->rd->data) | 266 | if (NULL != handle->rd->data) |
269 | GNUNET_free((void*)handle->rd->data); | 267 | GNUNET_free ((void *) handle->rd->data); |
270 | GNUNET_free(handle->rd); | 268 | GNUNET_free (handle->rd); |
271 | } | 269 | } |
272 | if (NULL != handle->timeout_task) | 270 | if (NULL != handle->timeout_task) |
273 | GNUNET_SCHEDULER_cancel(handle->timeout_task); | 271 | GNUNET_SCHEDULER_cancel (handle->timeout_task); |
274 | if (NULL != handle->list_it) | 272 | if (NULL != handle->list_it) |
275 | GNUNET_NAMESTORE_zone_iteration_stop(handle->list_it); | 273 | GNUNET_NAMESTORE_zone_iteration_stop (handle->list_it); |
276 | if (NULL != handle->add_qe) | 274 | if (NULL != handle->add_qe) |
277 | GNUNET_NAMESTORE_cancel(handle->add_qe); | 275 | GNUNET_NAMESTORE_cancel (handle->add_qe); |
278 | if (NULL != handle->identity_handle) | 276 | if (NULL != handle->identity_handle) |
279 | GNUNET_IDENTITY_disconnect(handle->identity_handle); | 277 | GNUNET_IDENTITY_disconnect (handle->identity_handle); |
280 | if (NULL != handle->ns_handle) | 278 | if (NULL != handle->ns_handle) |
281 | { | 279 | { |
282 | GNUNET_NAMESTORE_disconnect(handle->ns_handle); | 280 | GNUNET_NAMESTORE_disconnect (handle->ns_handle); |
283 | } | 281 | } |
284 | 282 | ||
285 | for (ego_entry = handle->ego_head; | 283 | for (ego_entry = handle->ego_head; NULL != ego_entry;) |
286 | NULL != ego_entry;) | ||
287 | { | 284 | { |
288 | ego_tmp = ego_entry; | 285 | ego_tmp = ego_entry; |
289 | ego_entry = ego_entry->next; | 286 | ego_entry = ego_entry->next; |
290 | GNUNET_free(ego_tmp->identifier); | 287 | GNUNET_free (ego_tmp->identifier); |
291 | GNUNET_free(ego_tmp->keystring); | 288 | GNUNET_free (ego_tmp->keystring); |
292 | GNUNET_free(ego_tmp); | 289 | GNUNET_free (ego_tmp); |
293 | } | 290 | } |
294 | 291 | ||
295 | if(NULL != handle->resp_object) | 292 | if (NULL != handle->resp_object) |
296 | { | 293 | { |
297 | json_decref(handle->resp_object); | 294 | json_decref (handle->resp_object); |
298 | } | 295 | } |
299 | 296 | ||
300 | GNUNET_free (handle); | 297 | GNUNET_free (handle); |
@@ -311,21 +308,21 @@ do_error (void *cls) | |||
311 | { | 308 | { |
312 | struct RequestHandle *handle = cls; | 309 | struct RequestHandle *handle = cls; |
313 | struct MHD_Response *resp; | 310 | struct MHD_Response *resp; |
314 | json_t *json_error = json_object(); | 311 | json_t *json_error = json_object (); |
315 | char *response; | 312 | char *response; |
316 | 313 | ||
317 | if (NULL == handle->emsg) | 314 | if (NULL == handle->emsg) |
318 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_ERROR_UNKNOWN); | 315 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_ERROR_UNKNOWN); |
319 | 316 | ||
320 | json_object_set_new(json_error,"error", json_string(handle->emsg)); | 317 | json_object_set_new (json_error, "error", json_string (handle->emsg)); |
321 | 318 | ||
322 | if (0 == handle->response_code) | 319 | if (0 == handle->response_code) |
323 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; | 320 | handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; |
324 | response = json_dumps (json_error, 0); | 321 | response = json_dumps (json_error, 0); |
325 | resp = GNUNET_REST_create_response (response); | 322 | resp = GNUNET_REST_create_response (response); |
326 | handle->proc (handle->proc_cls, resp, handle->response_code); | 323 | handle->proc (handle->proc_cls, resp, handle->response_code); |
327 | json_decref(json_error); | 324 | json_decref (json_error); |
328 | GNUNET_free(response); | 325 | GNUNET_free (response); |
329 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 326 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
330 | } | 327 | } |
331 | 328 | ||
@@ -339,18 +336,17 @@ do_error (void *cls) | |||
339 | * @param name the name of an identity (only one can be NULL) | 336 | * @param name the name of an identity (only one can be NULL) |
340 | * @return EgoEntry or NULL if not found | 337 | * @return EgoEntry or NULL if not found |
341 | */ | 338 | */ |
342 | struct EgoEntry* | 339 | struct EgoEntry * |
343 | get_egoentry_namestore(struct RequestHandle *handle, char *name) | 340 | get_egoentry_namestore (struct RequestHandle *handle, char *name) |
344 | { | 341 | { |
345 | struct EgoEntry *ego_entry; | 342 | struct EgoEntry *ego_entry; |
346 | if (NULL != name) | 343 | if (NULL != name) |
347 | { | 344 | { |
348 | for (ego_entry = handle->ego_head; | 345 | for (ego_entry = handle->ego_head; NULL != ego_entry; |
349 | NULL != ego_entry; | 346 | ego_entry = ego_entry->next) |
350 | ego_entry = ego_entry->next) | ||
351 | { | 347 | { |
352 | if (0 != strcasecmp (name, ego_entry->identifier)) | 348 | if (0 != strcasecmp (name, ego_entry->identifier)) |
353 | continue; | 349 | continue; |
354 | return ego_entry; | 350 | return ego_entry; |
355 | } | 351 | } |
356 | } | 352 | } |
@@ -367,7 +363,7 @@ static void | |||
367 | namestore_iteration_error (void *cls) | 363 | namestore_iteration_error (void *cls) |
368 | { | 364 | { |
369 | struct RequestHandle *handle = cls; | 365 | struct RequestHandle *handle = cls; |
370 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | 366 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); |
371 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 367 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
372 | return; | 368 | return; |
373 | } | 369 | } |
@@ -391,11 +387,11 @@ create_finished (void *cls, int32_t success, const char *emsg) | |||
391 | { | 387 | { |
392 | if (NULL != emsg) | 388 | if (NULL != emsg) |
393 | { | 389 | { |
394 | handle->emsg = GNUNET_strdup(emsg); | 390 | handle->emsg = GNUNET_strdup (emsg); |
395 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 391 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
396 | return; | 392 | return; |
397 | } | 393 | } |
398 | handle->emsg = GNUNET_strdup("Error storing records"); | 394 | handle->emsg = GNUNET_strdup ("Error storing records"); |
399 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 395 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
400 | return; | 396 | return; |
401 | } | 397 | } |
@@ -421,7 +417,7 @@ del_finished (void *cls, int32_t success, const char *emsg) | |||
421 | if (GNUNET_NO == success) | 417 | if (GNUNET_NO == success) |
422 | { | 418 | { |
423 | handle->response_code = MHD_HTTP_NOT_FOUND; | 419 | handle->response_code = MHD_HTTP_NOT_FOUND; |
424 | handle->emsg = GNUNET_strdup("No record found"); | 420 | handle->emsg = GNUNET_strdup ("No record found"); |
425 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 421 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
426 | return; | 422 | return; |
427 | } | 423 | } |
@@ -429,11 +425,11 @@ del_finished (void *cls, int32_t success, const char *emsg) | |||
429 | { | 425 | { |
430 | if (NULL != emsg) | 426 | if (NULL != emsg) |
431 | { | 427 | { |
432 | handle->emsg = GNUNET_strdup(emsg); | 428 | handle->emsg = GNUNET_strdup (emsg); |
433 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 429 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
434 | return; | 430 | return; |
435 | } | 431 | } |
436 | handle->emsg = GNUNET_strdup("Deleting record failed"); | 432 | handle->emsg = GNUNET_strdup ("Deleting record failed"); |
437 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 433 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
438 | return; | 434 | return; |
439 | } | 435 | } |
@@ -460,10 +456,10 @@ namestore_list_finished (void *cls) | |||
460 | handle->list_it = NULL; | 456 | handle->list_it = NULL; |
461 | 457 | ||
462 | if (NULL == handle->resp_object) | 458 | if (NULL == handle->resp_object) |
463 | handle->resp_object = json_array(); | 459 | handle->resp_object = json_array (); |
464 | 460 | ||
465 | result_str = json_dumps (handle->resp_object, 0); | 461 | result_str = json_dumps (handle->resp_object, 0); |
466 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 462 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
467 | resp = GNUNET_REST_create_response (result_str); | 463 | resp = GNUNET_REST_create_response (result_str); |
468 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 464 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
469 | GNUNET_free_non_null (result_str); | 465 | GNUNET_free_non_null (result_str); |
@@ -478,26 +474,26 @@ namestore_list_finished (void *cls) | |||
478 | */ | 474 | */ |
479 | static void | 475 | static void |
480 | namestore_list_iteration (void *cls, | 476 | namestore_list_iteration (void *cls, |
481 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 477 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
482 | const char *rname, | 478 | const char *rname, |
483 | unsigned int rd_len, | 479 | unsigned int rd_len, |
484 | const struct GNUNET_GNSRECORD_Data *rd) | 480 | const struct GNUNET_GNSRECORD_Data *rd) |
485 | { | 481 | { |
486 | struct RequestHandle *handle = cls; | 482 | struct RequestHandle *handle = cls; |
487 | json_t *record_obj; | 483 | json_t *record_obj; |
488 | 484 | ||
489 | if (NULL == handle->resp_object) | 485 | if (NULL == handle->resp_object) |
490 | handle->resp_object = json_array(); | 486 | handle->resp_object = json_array (); |
491 | 487 | ||
492 | for (unsigned int i = 0; i < rd_len; i++) | 488 | for (unsigned int i = 0; i < rd_len; i++) |
493 | { | 489 | { |
494 | if ( (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) && | 490 | if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) && |
495 | (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT)) ) | 491 | (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT))) |
496 | continue; | 492 | continue; |
497 | 493 | ||
498 | record_obj = GNUNET_JSON_from_gns_record (rname, &rd[i]); | 494 | record_obj = GNUNET_JSON_from_gns_record (rname, &rd[i]); |
499 | 495 | ||
500 | if(NULL == record_obj) | 496 | if (NULL == record_obj) |
501 | continue; | 497 | continue; |
502 | 498 | ||
503 | json_array_append (handle->resp_object, record_obj); | 499 | json_array_append (handle->resp_object, record_obj); |
@@ -518,32 +514,33 @@ namestore_list_iteration (void *cls, | |||
518 | */ | 514 | */ |
519 | static void | 515 | static void |
520 | default_ego_get (void *cls, | 516 | default_ego_get (void *cls, |
521 | struct GNUNET_IDENTITY_Ego *ego, | 517 | struct GNUNET_IDENTITY_Ego *ego, |
522 | void **ctx, | 518 | void **ctx, |
523 | const char *identifier) | 519 | const char *identifier) |
524 | { | 520 | { |
525 | struct RequestHandle *handle = cls; | 521 | struct RequestHandle *handle = cls; |
526 | handle->op = NULL; | 522 | handle->op = NULL; |
527 | 523 | ||
528 | if (ego == NULL) | 524 | if (ego == NULL) |
529 | { | 525 | { |
530 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); | 526 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); |
531 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 527 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
532 | return; | 528 | return; |
533 | } | 529 | } |
534 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego); | 530 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego); |
535 | 531 | ||
536 | handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, | 532 | handle->list_it = |
537 | handle->zone_pkey, | 533 | GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, |
538 | &namestore_iteration_error, | 534 | handle->zone_pkey, |
539 | handle, | 535 | &namestore_iteration_error, |
540 | &namestore_list_iteration, | 536 | handle, |
541 | handle, | 537 | &namestore_list_iteration, |
542 | &namestore_list_finished, | 538 | handle, |
543 | handle); | 539 | &namestore_list_finished, |
540 | handle); | ||
544 | if (NULL == handle->list_it) | 541 | if (NULL == handle->list_it) |
545 | { | 542 | { |
546 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | 543 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); |
547 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 544 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
548 | return; | 545 | return; |
549 | } | 546 | } |
@@ -559,8 +556,8 @@ default_ego_get (void *cls, | |||
559 | */ | 556 | */ |
560 | void | 557 | void |
561 | namestore_get (struct GNUNET_REST_RequestHandle *con_handle, | 558 | namestore_get (struct GNUNET_REST_RequestHandle *con_handle, |
562 | const char* url, | 559 | const char *url, |
563 | void *cls) | 560 | void *cls) |
564 | { | 561 | { |
565 | struct RequestHandle *handle = cls; | 562 | struct RequestHandle *handle = cls; |
566 | struct EgoEntry *ego_entry; | 563 | struct EgoEntry *ego_entry; |
@@ -569,44 +566,45 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle, | |||
569 | egoname = NULL; | 566 | egoname = NULL; |
570 | ego_entry = NULL; | 567 | ego_entry = NULL; |
571 | 568 | ||
572 | //set zone to name if given | 569 | // set zone to name if given |
573 | if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) | 570 | if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) |
574 | { | 571 | { |
575 | egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1]; | 572 | egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1]; |
576 | ego_entry = get_egoentry_namestore(handle, egoname); | 573 | ego_entry = get_egoentry_namestore (handle, egoname); |
577 | 574 | ||
578 | if (NULL == ego_entry) | 575 | if (NULL == ego_entry) |
579 | { | 576 | { |
580 | handle->response_code = MHD_HTTP_NOT_FOUND; | 577 | handle->response_code = MHD_HTTP_NOT_FOUND; |
581 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | 578 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); |
582 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 579 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
583 | return; | 580 | return; |
584 | } | 581 | } |
585 | } | 582 | } |
586 | if ( NULL != ego_entry ) | 583 | if (NULL != ego_entry) |
587 | { | 584 | { |
588 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); | 585 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
589 | } | 586 | } |
590 | 587 | ||
591 | if (NULL == handle->zone_pkey) | 588 | if (NULL == handle->zone_pkey) |
592 | { | 589 | { |
593 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, | 590 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, |
594 | "namestore", | 591 | "namestore", |
595 | &default_ego_get, | 592 | &default_ego_get, |
596 | handle); | 593 | handle); |
597 | return; | 594 | return; |
598 | } | 595 | } |
599 | handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, | 596 | handle->list_it = |
600 | handle->zone_pkey, | 597 | GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, |
601 | &namestore_iteration_error, | 598 | handle->zone_pkey, |
602 | handle, | 599 | &namestore_iteration_error, |
603 | &namestore_list_iteration, | 600 | handle, |
604 | handle, | 601 | &namestore_list_iteration, |
605 | &namestore_list_finished, | 602 | handle, |
606 | handle); | 603 | &namestore_list_finished, |
604 | handle); | ||
607 | if (NULL == handle->list_it) | 605 | if (NULL == handle->list_it) |
608 | { | 606 | { |
609 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | 607 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); |
610 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 608 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
611 | return; | 609 | return; |
612 | } | 610 | } |
@@ -624,31 +622,68 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle, | |||
624 | */ | 622 | */ |
625 | static void | 623 | static void |
626 | default_ego_post (void *cls, | 624 | default_ego_post (void *cls, |
627 | struct GNUNET_IDENTITY_Ego *ego, | 625 | struct GNUNET_IDENTITY_Ego *ego, |
628 | void **ctx, | 626 | void **ctx, |
629 | const char *identifier) | 627 | const char *identifier) |
630 | { | 628 | { |
631 | struct RequestHandle *handle = cls; | 629 | struct RequestHandle *handle = cls; |
632 | handle->op = NULL; | 630 | handle->op = NULL; |
633 | 631 | ||
634 | if (ego == NULL) | 632 | if (ego == NULL) |
635 | { | 633 | { |
636 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); | 634 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); |
637 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 635 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
638 | return; | 636 | return; |
639 | } | 637 | } |
640 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego); | 638 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego); |
641 | 639 | ||
642 | handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, | 640 | handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, |
643 | handle->zone_pkey, | 641 | handle->zone_pkey, |
644 | handle->record_name, | 642 | handle->record_name, |
645 | 1, | 643 | 1, |
646 | handle->rd, | 644 | handle->rd, |
647 | &create_finished, | 645 | &create_finished, |
648 | handle); | 646 | handle); |
647 | if (NULL == handle->add_qe) | ||
648 | { | ||
649 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); | ||
650 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
651 | return; | ||
652 | } | ||
653 | } | ||
654 | |||
655 | |||
656 | static void | ||
657 | ns_lookup_error_cb (void *cls) | ||
658 | { | ||
659 | struct RequestHandle *handle = cls; | ||
660 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); | ||
661 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
662 | } | ||
663 | |||
664 | |||
665 | static void | ||
666 | ns_lookup_cb (void *cls, | ||
667 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | ||
668 | const char *label, | ||
669 | unsigned int rd_count, | ||
670 | const struct GNUNET_GNSRECORD_Data *rd) | ||
671 | { | ||
672 | struct RequestHandle *handle = cls; | ||
673 | struct GNUNET_GNSRECORD_Data rd_new[rd_count + 1]; | ||
674 | for (int i = 0; i < rd_count; i++) | ||
675 | rd_new[i] = rd[i]; | ||
676 | rd_new[rd_count] = *handle->rd; | ||
677 | handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, | ||
678 | handle->zone_pkey, | ||
679 | handle->record_name, | ||
680 | rd_count + 1, | ||
681 | rd_new, | ||
682 | &create_finished, | ||
683 | handle); | ||
649 | if (NULL == handle->add_qe) | 684 | if (NULL == handle->add_qe) |
650 | { | 685 | { |
651 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | 686 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); |
652 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 687 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
653 | return; | 688 | return; |
654 | } | 689 | } |
@@ -664,8 +699,8 @@ default_ego_post (void *cls, | |||
664 | */ | 699 | */ |
665 | void | 700 | void |
666 | namestore_add (struct GNUNET_REST_RequestHandle *con_handle, | 701 | namestore_add (struct GNUNET_REST_RequestHandle *con_handle, |
667 | const char* url, | 702 | const char *url, |
668 | void *cls) | 703 | void *cls) |
669 | { | 704 | { |
670 | struct RequestHandle *handle = cls; | 705 | struct RequestHandle *handle = cls; |
671 | struct GNUNET_GNSRECORD_Data *gns_record; | 706 | struct GNUNET_GNSRECORD_Data *gns_record; |
@@ -676,50 +711,49 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle, | |||
676 | json_error_t err; | 711 | json_error_t err; |
677 | char term_data[handle->rest_handle->data_size + 1]; | 712 | char term_data[handle->rest_handle->data_size + 1]; |
678 | 713 | ||
679 | struct GNUNET_JSON_Specification gnsspec[] = { | 714 | struct GNUNET_JSON_Specification gnsspec[] = |
680 | GNUNET_JSON_spec_gnsrecord_data(&gns_record), | 715 | {GNUNET_JSON_spec_gnsrecord_data (&gns_record), GNUNET_JSON_spec_end ()}; |
681 | GNUNET_JSON_spec_end () | ||
682 | }; | ||
683 | 716 | ||
684 | if (0 >= handle->rest_handle->data_size) | 717 | if (0 >= handle->rest_handle->data_size) |
685 | { | 718 | { |
686 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DATA); | 719 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_NO_DATA); |
687 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 720 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
688 | return; | 721 | return; |
689 | } | 722 | } |
690 | term_data[handle->rest_handle->data_size] = '\0'; | 723 | term_data[handle->rest_handle->data_size] = '\0'; |
691 | GNUNET_memcpy(term_data, handle->rest_handle->data, | 724 | GNUNET_memcpy (term_data, |
692 | handle->rest_handle->data_size); | 725 | handle->rest_handle->data, |
726 | handle->rest_handle->data_size); | ||
693 | data_js = json_loads (term_data, JSON_DECODE_ANY, &err); | 727 | data_js = json_loads (term_data, JSON_DECODE_ANY, &err); |
694 | if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL)) | 728 | if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL)) |
695 | { | 729 | { |
696 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA); | 730 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); |
697 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 731 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
698 | GNUNET_JSON_parse_free(gnsspec); | 732 | GNUNET_JSON_parse_free (gnsspec); |
699 | json_decref (data_js); | 733 | json_decref (data_js); |
700 | return; | 734 | return; |
701 | } | 735 | } |
702 | handle->rd = gns_record; | 736 | handle->rd = gns_record; |
703 | 737 | ||
704 | name_json = json_object_get(data_js, "record_name"); | 738 | name_json = json_object_get (data_js, "record_name"); |
705 | if (!json_is_string(name_json)) | 739 | if (! json_is_string (name_json)) |
706 | { | 740 | { |
707 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA); | 741 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); |
708 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 742 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
709 | json_decref (data_js); | 743 | json_decref (data_js); |
710 | return; | 744 | return; |
711 | } | 745 | } |
712 | handle->record_name = GNUNET_strdup(json_string_value(name_json)); | 746 | handle->record_name = GNUNET_strdup (json_string_value (name_json)); |
713 | if(NULL == handle->record_name) | 747 | if (NULL == handle->record_name) |
714 | { | 748 | { |
715 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA); | 749 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); |
716 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 750 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
717 | json_decref (data_js); | 751 | json_decref (data_js); |
718 | return; | 752 | return; |
719 | } | 753 | } |
720 | if (0 >= strlen(handle->record_name)) | 754 | if (0 >= strlen (handle->record_name)) |
721 | { | 755 | { |
722 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA); | 756 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); |
723 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 757 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
724 | json_decref (data_js); | 758 | json_decref (data_js); |
725 | return; | 759 | return; |
@@ -729,42 +763,42 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle, | |||
729 | egoname = NULL; | 763 | egoname = NULL; |
730 | ego_entry = NULL; | 764 | ego_entry = NULL; |
731 | 765 | ||
732 | //set zone to name if given | 766 | // set zone to name if given |
733 | if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) | 767 | if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) |
734 | { | 768 | { |
735 | egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1]; | 769 | egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1]; |
736 | ego_entry = get_egoentry_namestore(handle, egoname); | 770 | ego_entry = get_egoentry_namestore (handle, egoname); |
737 | 771 | ||
738 | if (NULL == ego_entry) | 772 | if (NULL == ego_entry) |
739 | { | 773 | { |
740 | handle->response_code = MHD_HTTP_NOT_FOUND; | 774 | handle->response_code = MHD_HTTP_NOT_FOUND; |
741 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | 775 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); |
742 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 776 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
743 | return; | 777 | return; |
744 | } | 778 | } |
745 | } | 779 | } |
746 | if (NULL != ego_entry) | 780 | if (NULL != ego_entry) |
747 | { | 781 | { |
748 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); | 782 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
749 | } | 783 | } |
750 | if (NULL == handle->zone_pkey) | 784 | if (NULL == handle->zone_pkey) |
751 | { | 785 | { |
752 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, | 786 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, |
753 | "namestore", | 787 | "namestore", |
754 | &default_ego_post, | 788 | &default_ego_post, |
755 | handle); | 789 | handle); |
756 | return; | 790 | return; |
757 | } | 791 | } |
758 | handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, | 792 | handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, |
759 | handle->zone_pkey, | 793 | handle->zone_pkey, |
760 | handle->record_name, | 794 | handle->record_name, |
761 | 1, | 795 | &ns_lookup_error_cb, |
762 | handle->rd, | 796 | handle, |
763 | &create_finished, | 797 | &ns_lookup_cb, |
764 | handle); | 798 | handle); |
765 | if (NULL == handle->add_qe) | 799 | if (NULL == handle->add_qe) |
766 | { | 800 | { |
767 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | 801 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); |
768 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 802 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
769 | return; | 803 | return; |
770 | } | 804 | } |
@@ -782,16 +816,16 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle, | |||
782 | */ | 816 | */ |
783 | static void | 817 | static void |
784 | default_ego_delete (void *cls, | 818 | default_ego_delete (void *cls, |
785 | struct GNUNET_IDENTITY_Ego *ego, | 819 | struct GNUNET_IDENTITY_Ego *ego, |
786 | void **ctx, | 820 | void **ctx, |
787 | const char *identifier) | 821 | const char *identifier) |
788 | { | 822 | { |
789 | struct RequestHandle *handle = cls; | 823 | struct RequestHandle *handle = cls; |
790 | handle->op = NULL; | 824 | handle->op = NULL; |
791 | 825 | ||
792 | if (ego == NULL) | 826 | if (ego == NULL) |
793 | { | 827 | { |
794 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); | 828 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); |
795 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 829 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
796 | return; | 830 | return; |
797 | } | 831 | } |
@@ -801,12 +835,12 @@ default_ego_delete (void *cls, | |||
801 | handle->zone_pkey, | 835 | handle->zone_pkey, |
802 | handle->record_name, | 836 | handle->record_name, |
803 | 0, | 837 | 0, |
804 | NULL, | 838 | NULL, |
805 | &del_finished, | 839 | &del_finished, |
806 | handle); | 840 | handle); |
807 | if (NULL == handle->add_qe) | 841 | if (NULL == handle->add_qe) |
808 | { | 842 | { |
809 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | 843 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); |
810 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 844 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
811 | return; | 845 | return; |
812 | } | 846 | } |
@@ -822,8 +856,8 @@ default_ego_delete (void *cls, | |||
822 | */ | 856 | */ |
823 | void | 857 | void |
824 | namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, | 858 | namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, |
825 | const char* url, | 859 | const char *url, |
826 | void *cls) | 860 | void *cls) |
827 | { | 861 | { |
828 | struct RequestHandle *handle = cls; | 862 | struct RequestHandle *handle = cls; |
829 | struct GNUNET_HashCode key; | 863 | struct GNUNET_HashCode key; |
@@ -833,43 +867,42 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, | |||
833 | egoname = NULL; | 867 | egoname = NULL; |
834 | ego_entry = NULL; | 868 | ego_entry = NULL; |
835 | 869 | ||
836 | //set zone to name if given | 870 | // set zone to name if given |
837 | if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) | 871 | if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url)) |
838 | { | 872 | { |
839 | egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE)+1]; | 873 | egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1]; |
840 | ego_entry = get_egoentry_namestore(handle, egoname); | 874 | ego_entry = get_egoentry_namestore (handle, egoname); |
841 | 875 | ||
842 | if (NULL == ego_entry) | 876 | if (NULL == ego_entry) |
843 | { | 877 | { |
844 | handle->response_code = MHD_HTTP_NOT_FOUND; | 878 | handle->response_code = MHD_HTTP_NOT_FOUND; |
845 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | 879 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); |
846 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 880 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
847 | return; | 881 | return; |
848 | } | 882 | } |
849 | } | 883 | } |
850 | if ( NULL != ego_entry ) | 884 | if (NULL != ego_entry) |
851 | { | 885 | { |
852 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); | 886 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
853 | } | 887 | } |
854 | 888 | ||
855 | GNUNET_CRYPTO_hash ("record_name", strlen ("record_name"), &key); | 889 | GNUNET_CRYPTO_hash ("record_name", strlen ("record_name"), &key); |
856 | if ( GNUNET_NO | 890 | if (GNUNET_NO == |
857 | == GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, | 891 | GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, &key)) |
858 | &key)) | ||
859 | { | 892 | { |
860 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA); | 893 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA); |
861 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 894 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
862 | return; | 895 | return; |
863 | } | 896 | } |
864 | handle->record_name = GNUNET_strdup( | 897 | handle->record_name = GNUNET_strdup ( |
865 | GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key)); | 898 | GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key)); |
866 | 899 | ||
867 | if (NULL == handle->zone_pkey) | 900 | if (NULL == handle->zone_pkey) |
868 | { | 901 | { |
869 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, | 902 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, |
870 | "namestore", | 903 | "namestore", |
871 | &default_ego_delete, | 904 | &default_ego_delete, |
872 | handle); | 905 | handle); |
873 | return; | 906 | return; |
874 | } | 907 | } |
875 | 908 | ||
@@ -877,19 +910,18 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, | |||
877 | handle->zone_pkey, | 910 | handle->zone_pkey, |
878 | handle->record_name, | 911 | handle->record_name, |
879 | 0, | 912 | 0, |
880 | NULL, | 913 | NULL, |
881 | &del_finished, | 914 | &del_finished, |
882 | handle); | 915 | handle); |
883 | if (NULL == handle->add_qe) | 916 | if (NULL == handle->add_qe) |
884 | { | 917 | { |
885 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | 918 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); |
886 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 919 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
887 | return; | 920 | return; |
888 | } | 921 | } |
889 | } | 922 | } |
890 | 923 | ||
891 | 924 | ||
892 | |||
893 | /** | 925 | /** |
894 | * Respond to OPTIONS request | 926 | * Respond to OPTIONS request |
895 | * | 927 | * |
@@ -899,17 +931,15 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, | |||
899 | */ | 931 | */ |
900 | static void | 932 | static void |
901 | options_cont (struct GNUNET_REST_RequestHandle *con_handle, | 933 | options_cont (struct GNUNET_REST_RequestHandle *con_handle, |
902 | const char* url, | 934 | const char *url, |
903 | void *cls) | 935 | void *cls) |
904 | { | 936 | { |
905 | struct MHD_Response *resp; | 937 | struct MHD_Response *resp; |
906 | struct RequestHandle *handle = cls; | 938 | struct RequestHandle *handle = cls; |
907 | 939 | ||
908 | //independent of path return all options | 940 | // independent of path return all options |
909 | resp = GNUNET_REST_create_response (NULL); | 941 | resp = GNUNET_REST_create_response (NULL); |
910 | MHD_add_response_header (resp, | 942 | MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); |
911 | "Access-Control-Allow-Methods", | ||
912 | allow_methods); | ||
913 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 943 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
914 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 944 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); |
915 | return; | 945 | return; |
@@ -925,18 +955,15 @@ static void | |||
925 | init_cont (struct RequestHandle *handle) | 955 | init_cont (struct RequestHandle *handle) |
926 | { | 956 | { |
927 | struct GNUNET_REST_RequestHandlerError err; | 957 | struct GNUNET_REST_RequestHandlerError err; |
928 | static const struct GNUNET_REST_RequestHandler handlers[] = { | 958 | static const struct GNUNET_REST_RequestHandler handlers[] = |
929 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_get}, | 959 | {{MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_get}, |
930 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_add}, | 960 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_add}, |
931 | {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE, &namestore_delete}, | 961 | {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_NAMESTORE, &namestore_delete}, |
932 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_NAMESTORE, &options_cont}, | 962 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_NAMESTORE, &options_cont}, |
933 | GNUNET_REST_HANDLER_END | 963 | GNUNET_REST_HANDLER_END}; |
934 | }; | 964 | |
935 | 965 | if (GNUNET_NO == | |
936 | if (GNUNET_NO == GNUNET_REST_handle_request (handle->rest_handle, | 966 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) |
937 | handlers, | ||
938 | &err, | ||
939 | handle)) | ||
940 | { | 967 | { |
941 | handle->response_code = err.error_code; | 968 | handle->response_code = err.error_code; |
942 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 969 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
@@ -988,20 +1015,20 @@ id_connect_cb (void *cls, | |||
988 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) | 1015 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) |
989 | { | 1016 | { |
990 | handle->state = ID_REST_STATE_POST_INIT; | 1017 | handle->state = ID_REST_STATE_POST_INIT; |
991 | init_cont(handle); | 1018 | init_cont (handle); |
992 | return; | 1019 | return; |
993 | } | 1020 | } |
994 | if (ID_REST_STATE_INIT == handle->state) | 1021 | if (ID_REST_STATE_INIT == handle->state) |
995 | { | 1022 | { |
996 | ego_entry = GNUNET_new(struct EgoEntry); | 1023 | ego_entry = GNUNET_new (struct EgoEntry); |
997 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 1024 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
998 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 1025 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); |
999 | ego_entry->ego = ego; | 1026 | ego_entry->ego = ego; |
1000 | GNUNET_asprintf (&ego_entry->identifier, "%s", name); | 1027 | GNUNET_asprintf (&ego_entry->identifier, "%s", name); |
1001 | GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head, handle->ego_tail, | 1028 | GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, |
1002 | ego_entry); | 1029 | handle->ego_tail, |
1030 | ego_entry); | ||
1003 | } | 1031 | } |
1004 | |||
1005 | } | 1032 | } |
1006 | 1033 | ||
1007 | 1034 | ||
@@ -1017,9 +1044,9 @@ id_connect_cb (void *cls, | |||
1017 | * @return GNUNET_OK if request accepted | 1044 | * @return GNUNET_OK if request accepted |
1018 | */ | 1045 | */ |
1019 | static void | 1046 | static void |
1020 | rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, | 1047 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, |
1021 | GNUNET_REST_ResultProcessor proc, | 1048 | GNUNET_REST_ResultProcessor proc, |
1022 | void *proc_cls) | 1049 | void *proc_cls) |
1023 | { | 1050 | { |
1024 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | 1051 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); |
1025 | 1052 | ||
@@ -1031,16 +1058,15 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, | |||
1031 | handle->zone_pkey = NULL; | 1058 | handle->zone_pkey = NULL; |
1032 | 1059 | ||
1033 | handle->url = GNUNET_strdup (rest_handle->url); | 1060 | handle->url = GNUNET_strdup (rest_handle->url); |
1034 | if (handle->url[strlen (handle->url)-1] == '/') | 1061 | if (handle->url[strlen (handle->url) - 1] == '/') |
1035 | handle->url[strlen (handle->url)-1] = '\0'; | 1062 | handle->url[strlen (handle->url) - 1] = '\0'; |
1036 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 1063 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); |
1037 | 1064 | ||
1038 | handle->ns_handle = GNUNET_NAMESTORE_connect (cfg); | 1065 | handle->ns_handle = GNUNET_NAMESTORE_connect (cfg); |
1039 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, handle); | 1066 | handle->identity_handle = |
1067 | GNUNET_IDENTITY_connect (cfg, &id_connect_cb, handle); | ||
1040 | handle->timeout_task = | 1068 | handle->timeout_task = |
1041 | GNUNET_SCHEDULER_add_delayed (handle->timeout, | 1069 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_error, handle); |
1042 | &do_error, | ||
1043 | handle); | ||
1044 | 1070 | ||
1045 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); | 1071 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); |
1046 | } | 1072 | } |
@@ -1060,7 +1086,7 @@ libgnunet_plugin_rest_namestore_init (void *cls) | |||
1060 | 1086 | ||
1061 | cfg = cls; | 1087 | cfg = cls; |
1062 | if (NULL != plugin.cfg) | 1088 | if (NULL != plugin.cfg) |
1063 | return NULL; /* can only initialize once! */ | 1089 | return NULL; /* can only initialize once! */ |
1064 | memset (&plugin, 0, sizeof (struct Plugin)); | 1090 | memset (&plugin, 0, sizeof (struct Plugin)); |
1065 | plugin.cfg = cfg; | 1091 | plugin.cfg = cfg; |
1066 | api = GNUNET_new (struct GNUNET_REST_Plugin); | 1092 | api = GNUNET_new (struct GNUNET_REST_Plugin); |
@@ -1075,8 +1101,7 @@ libgnunet_plugin_rest_namestore_init (void *cls) | |||
1075 | MHD_HTTP_METHOD_DELETE, | 1101 | MHD_HTTP_METHOD_DELETE, |
1076 | MHD_HTTP_METHOD_OPTIONS); | 1102 | MHD_HTTP_METHOD_OPTIONS); |
1077 | 1103 | ||
1078 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Namestore REST API initialized\n")); |
1079 | _("Namestore REST API initialized\n")); | ||
1080 | return api; | 1105 | return api; |
1081 | } | 1106 | } |
1082 | 1107 | ||
@@ -1096,8 +1121,7 @@ libgnunet_plugin_rest_namestore_done (void *cls) | |||
1096 | 1121 | ||
1097 | GNUNET_free_non_null (allow_methods); | 1122 | GNUNET_free_non_null (allow_methods); |
1098 | GNUNET_free (api); | 1123 | GNUNET_free (api); |
1099 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore REST plugin is finished\n"); |
1100 | "Namestore REST plugin is finished\n"); | ||
1101 | return NULL; | 1125 | return NULL; |
1102 | } | 1126 | } |
1103 | 1127 | ||