summaryrefslogtreecommitdiff
path: root/src/namestore/plugin_rest_namestore.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/plugin_rest_namestore.c')
-rw-r--r--src/namestore/plugin_rest_namestore.c618
1 files changed, 311 insertions, 307 deletions
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
index 42fbf8347..07b3840c5 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -87,14 +87,16 @@ static char *allow_methods;
87/** 87/**
88 * @brief struct returned by the initialization function of the plugin 88 * @brief struct returned by the initialization function of the plugin
89 */ 89 */
90struct Plugin { 90struct Plugin
91{
91 const struct GNUNET_CONFIGURATION_Handle *cfg; 92 const struct GNUNET_CONFIGURATION_Handle *cfg;
92}; 93};
93 94
94/** 95/**
95 * The default namestore ego 96 * The default namestore ego
96 */ 97 */
97struct EgoEntry { 98struct EgoEntry
99{
98 /** 100 /**
99 * DLL 101 * DLL
100 */ 102 */
@@ -124,7 +126,8 @@ struct EgoEntry {
124/** 126/**
125 * The request handle 127 * The request handle
126 */ 128 */
127struct RequestHandle { 129struct RequestHandle
130{
128 /** 131 /**
129 * Records to store 132 * Records to store
130 */ 133 */
@@ -241,61 +244,61 @@ struct RequestHandle {
241 * @param handle Handle to clean up 244 * @param handle Handle to clean up
242 */ 245 */
243static void 246static void
244cleanup_handle(void *cls) 247cleanup_handle (void *cls)
245{ 248{
246 struct RequestHandle *handle = cls; 249 struct RequestHandle *handle = cls;
247 struct EgoEntry *ego_entry; 250 struct EgoEntry *ego_entry;
248 struct EgoEntry *ego_tmp; 251 struct EgoEntry *ego_tmp;
249 252
250 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); 253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
251 if (NULL != handle->timeout_task) 254 if (NULL != handle->timeout_task)
252 { 255 {
253 GNUNET_SCHEDULER_cancel(handle->timeout_task); 256 GNUNET_SCHEDULER_cancel (handle->timeout_task);
254 handle->timeout_task = NULL; 257 handle->timeout_task = NULL;
255 } 258 }
256 if (NULL != handle->record_name) 259 if (NULL != handle->record_name)
257 GNUNET_free(handle->record_name); 260 GNUNET_free (handle->record_name);
258 if (NULL != handle->url) 261 if (NULL != handle->url)
259 GNUNET_free(handle->url); 262 GNUNET_free (handle->url);
260 if (NULL != handle->emsg) 263 if (NULL != handle->emsg)
261 GNUNET_free(handle->emsg); 264 GNUNET_free (handle->emsg);
262 if (NULL != handle->rd) 265 if (NULL != handle->rd)
266 {
267 for (int i = 0; i < handle->rd_count; i++)
263 { 268 {
264 for (int i = 0; i < handle->rd_count; i++) 269 if (NULL != handle->rd[i].data)
265 { 270 GNUNET_free ((void *) handle->rd[i].data);
266 if (NULL != handle->rd[i].data)
267 GNUNET_free((void *)handle->rd[i].data);
268 }
269 GNUNET_free(handle->rd);
270 } 271 }
272 GNUNET_free (handle->rd);
273 }
271 if (NULL != handle->timeout_task) 274 if (NULL != handle->timeout_task)
272 GNUNET_SCHEDULER_cancel(handle->timeout_task); 275 GNUNET_SCHEDULER_cancel (handle->timeout_task);
273 if (NULL != handle->list_it) 276 if (NULL != handle->list_it)
274 GNUNET_NAMESTORE_zone_iteration_stop(handle->list_it); 277 GNUNET_NAMESTORE_zone_iteration_stop (handle->list_it);
275 if (NULL != handle->add_qe) 278 if (NULL != handle->add_qe)
276 GNUNET_NAMESTORE_cancel(handle->add_qe); 279 GNUNET_NAMESTORE_cancel (handle->add_qe);
277 if (NULL != handle->identity_handle) 280 if (NULL != handle->identity_handle)
278 GNUNET_IDENTITY_disconnect(handle->identity_handle); 281 GNUNET_IDENTITY_disconnect (handle->identity_handle);
279 if (NULL != handle->ns_handle) 282 if (NULL != handle->ns_handle)
280 { 283 {
281 GNUNET_NAMESTORE_disconnect(handle->ns_handle); 284 GNUNET_NAMESTORE_disconnect (handle->ns_handle);
282 } 285 }
283 286
284 for (ego_entry = handle->ego_head; NULL != ego_entry;) 287 for (ego_entry = handle->ego_head; NULL != ego_entry;)
285 { 288 {
286 ego_tmp = ego_entry; 289 ego_tmp = ego_entry;
287 ego_entry = ego_entry->next; 290 ego_entry = ego_entry->next;
288 GNUNET_free(ego_tmp->identifier); 291 GNUNET_free (ego_tmp->identifier);
289 GNUNET_free(ego_tmp->keystring); 292 GNUNET_free (ego_tmp->keystring);
290 GNUNET_free(ego_tmp); 293 GNUNET_free (ego_tmp);
291 } 294 }
292 295
293 if (NULL != handle->resp_object) 296 if (NULL != handle->resp_object)
294 { 297 {
295 json_decref(handle->resp_object); 298 json_decref (handle->resp_object);
296 } 299 }
297 300
298 GNUNET_free(handle); 301 GNUNET_free (handle);
299} 302}
300 303
301 304
@@ -305,26 +308,26 @@ cleanup_handle(void *cls)
305 * @param cls the `struct RequestHandle` 308 * @param cls the `struct RequestHandle`
306 */ 309 */
307static void 310static void
308do_error(void *cls) 311do_error (void *cls)
309{ 312{
310 struct RequestHandle *handle = cls; 313 struct RequestHandle *handle = cls;
311 struct MHD_Response *resp; 314 struct MHD_Response *resp;
312 json_t *json_error = json_object(); 315 json_t *json_error = json_object ();
313 char *response; 316 char *response;
314 317
315 if (NULL == handle->emsg) 318 if (NULL == handle->emsg)
316 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_ERROR_UNKNOWN); 319 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_ERROR_UNKNOWN);
317 320
318 json_object_set_new(json_error, "error", json_string(handle->emsg)); 321 json_object_set_new (json_error, "error", json_string (handle->emsg));
319 322
320 if (0 == handle->response_code) 323 if (0 == handle->response_code)
321 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; 324 handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
322 response = json_dumps(json_error, 0); 325 response = json_dumps (json_error, 0);
323 resp = GNUNET_REST_create_response(response); 326 resp = GNUNET_REST_create_response (response);
324 handle->proc(handle->proc_cls, resp, handle->response_code); 327 handle->proc (handle->proc_cls, resp, handle->response_code);
325 json_decref(json_error); 328 json_decref (json_error);
326 GNUNET_free(response); 329 GNUNET_free (response);
327 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); 330 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
328} 331}
329 332
330 333
@@ -338,20 +341,20 @@ do_error(void *cls)
338 * @return EgoEntry or NULL if not found 341 * @return EgoEntry or NULL if not found
339 */ 342 */
340struct EgoEntry * 343struct EgoEntry *
341get_egoentry_namestore(struct RequestHandle *handle, char *name) 344get_egoentry_namestore (struct RequestHandle *handle, char *name)
342{ 345{
343 struct EgoEntry *ego_entry; 346 struct EgoEntry *ego_entry;
344 347
345 if (NULL != name) 348 if (NULL != name)
349 {
350 for (ego_entry = handle->ego_head; NULL != ego_entry;
351 ego_entry = ego_entry->next)
346 { 352 {
347 for (ego_entry = handle->ego_head; NULL != ego_entry; 353 if (0 != strcasecmp (name, ego_entry->identifier))
348 ego_entry = ego_entry->next) 354 continue;
349 { 355 return ego_entry;
350 if (0 != strcasecmp(name, ego_entry->identifier))
351 continue;
352 return ego_entry;
353 }
354 } 356 }
357 }
355 return NULL; 358 return NULL;
356} 359}
357 360
@@ -362,12 +365,12 @@ get_egoentry_namestore(struct RequestHandle *handle, char *name)
362 * @param cls the `struct RequestHandle` 365 * @param cls the `struct RequestHandle`
363 */ 366 */
364static void 367static void
365namestore_iteration_error(void *cls) 368namestore_iteration_error (void *cls)
366{ 369{
367 struct RequestHandle *handle = cls; 370 struct RequestHandle *handle = cls;
368 371
369 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); 372 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED);
370 GNUNET_SCHEDULER_add_now(&do_error, handle); 373 GNUNET_SCHEDULER_add_now (&do_error, handle);
371 return; 374 return;
372} 375}
373 376
@@ -380,27 +383,27 @@ namestore_iteration_error(void *cls)
380 * @param emsg the error message (can be NULL) 383 * @param emsg the error message (can be NULL)
381 */ 384 */
382static void 385static void
383create_finished(void *cls, int32_t success, const char *emsg) 386create_finished (void *cls, int32_t success, const char *emsg)
384{ 387{
385 struct RequestHandle *handle = cls; 388 struct RequestHandle *handle = cls;
386 struct MHD_Response *resp; 389 struct MHD_Response *resp;
387 390
388 handle->add_qe = NULL; 391 handle->add_qe = NULL;
389 if (GNUNET_YES != success) 392 if (GNUNET_YES != success)
393 {
394 if (NULL != emsg)
390 { 395 {
391 if (NULL != emsg) 396 handle->emsg = GNUNET_strdup (emsg);
392 { 397 GNUNET_SCHEDULER_add_now (&do_error, handle);
393 handle->emsg = GNUNET_strdup(emsg);
394 GNUNET_SCHEDULER_add_now(&do_error, handle);
395 return;
396 }
397 handle->emsg = GNUNET_strdup("Error storing records");
398 GNUNET_SCHEDULER_add_now(&do_error, handle);
399 return; 398 return;
400 } 399 }
401 resp = GNUNET_REST_create_response(NULL); 400 handle->emsg = GNUNET_strdup ("Error storing records");
402 handle->proc(handle->proc_cls, resp, MHD_HTTP_NO_CONTENT); 401 GNUNET_SCHEDULER_add_now (&do_error, handle);
403 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); 402 return;
403 }
404 resp = GNUNET_REST_create_response (NULL);
405 handle->proc (handle->proc_cls, resp, MHD_HTTP_NO_CONTENT);
406 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
404} 407}
405 408
406 409
@@ -412,34 +415,34 @@ create_finished(void *cls, int32_t success, const char *emsg)
412 * @param emsg the error message (can be NULL) 415 * @param emsg the error message (can be NULL)
413 */ 416 */
414static void 417static void
415del_finished(void *cls, int32_t success, const char *emsg) 418del_finished (void *cls, int32_t success, const char *emsg)
416{ 419{
417 struct RequestHandle *handle = cls; 420 struct RequestHandle *handle = cls;
418 421
419 handle->add_qe = NULL; 422 handle->add_qe = NULL;
420 if (GNUNET_NO == success) 423 if (GNUNET_NO == success)
421 { 424 {
422 handle->response_code = MHD_HTTP_NOT_FOUND; 425 handle->response_code = MHD_HTTP_NOT_FOUND;
423 handle->emsg = GNUNET_strdup("No record found"); 426 handle->emsg = GNUNET_strdup ("No record found");
424 GNUNET_SCHEDULER_add_now(&do_error, handle); 427 GNUNET_SCHEDULER_add_now (&do_error, handle);
425 return; 428 return;
426 } 429 }
427 if (GNUNET_SYSERR == success) 430 if (GNUNET_SYSERR == success)
431 {
432 if (NULL != emsg)
428 { 433 {
429 if (NULL != emsg) 434 handle->emsg = GNUNET_strdup (emsg);
430 { 435 GNUNET_SCHEDULER_add_now (&do_error, handle);
431 handle->emsg = GNUNET_strdup(emsg);
432 GNUNET_SCHEDULER_add_now(&do_error, handle);
433 return;
434 }
435 handle->emsg = GNUNET_strdup("Deleting record failed");
436 GNUNET_SCHEDULER_add_now(&do_error, handle);
437 return; 436 return;
438 } 437 }
439 handle->proc(handle->proc_cls, 438 handle->emsg = GNUNET_strdup ("Deleting record failed");
440 GNUNET_REST_create_response(NULL), 439 GNUNET_SCHEDULER_add_now (&do_error, handle);
441 MHD_HTTP_NO_CONTENT); 440 return;
442 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); 441 }
442 handle->proc (handle->proc_cls,
443 GNUNET_REST_create_response (NULL),
444 MHD_HTTP_NO_CONTENT);
445 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
443} 446}
444 447
445 448
@@ -450,7 +453,7 @@ del_finished(void *cls, int32_t success, const char *emsg)
450 * @param cls the `struct RequestHandle` 453 * @param cls the `struct RequestHandle`
451 */ 454 */
452static void 455static void
453namestore_list_finished(void *cls) 456namestore_list_finished (void *cls)
454{ 457{
455 struct RequestHandle *handle = cls; 458 struct RequestHandle *handle = cls;
456 char *result_str; 459 char *result_str;
@@ -459,14 +462,14 @@ namestore_list_finished(void *cls)
459 handle->list_it = NULL; 462 handle->list_it = NULL;
460 463
461 if (NULL == handle->resp_object) 464 if (NULL == handle->resp_object)
462 handle->resp_object = json_array(); 465 handle->resp_object = json_array ();
463 466
464 result_str = json_dumps(handle->resp_object, 0); 467 result_str = json_dumps (handle->resp_object, 0);
465 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); 468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
466 resp = GNUNET_REST_create_response(result_str); 469 resp = GNUNET_REST_create_response (result_str);
467 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); 470 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
468 GNUNET_free_non_null(result_str); 471 GNUNET_free_non_null (result_str);
469 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); 472 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
470} 473}
471 474
472 475
@@ -476,22 +479,22 @@ namestore_list_finished(void *cls)
476 * @param handle the RequestHandle 479 * @param handle the RequestHandle
477 */ 480 */
478static void 481static void
479namestore_list_iteration(void *cls, 482namestore_list_iteration (void *cls,
480 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 483 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
481 const char *rname, 484 const char *rname,
482 unsigned int rd_len, 485 unsigned int rd_len,
483 const struct GNUNET_GNSRECORD_Data *rd) 486 const struct GNUNET_GNSRECORD_Data *rd)
484{ 487{
485 struct RequestHandle *handle = cls; 488 struct RequestHandle *handle = cls;
486 json_t *record_obj; 489 json_t *record_obj;
487 490
488 if (NULL == handle->resp_object) 491 if (NULL == handle->resp_object)
489 handle->resp_object = json_array(); 492 handle->resp_object = json_array ();
490 record_obj = GNUNET_JSON_from_gnsrecord(rname, 493 record_obj = GNUNET_JSON_from_gnsrecord (rname,
491 rd, 494 rd,
492 rd_len); 495 rd_len);
493 json_array_append_new(handle->resp_object, record_obj); 496 json_array_append_new (handle->resp_object, record_obj);
494 GNUNET_NAMESTORE_zone_iterator_next(handle->list_it, 1); 497 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1);
495} 498}
496 499
497 500
@@ -503,9 +506,9 @@ namestore_list_iteration(void *cls,
503 * @param cls the RequestHandle 506 * @param cls the RequestHandle
504 */ 507 */
505void 508void
506namestore_get(struct GNUNET_REST_RequestHandle *con_handle, 509namestore_get (struct GNUNET_REST_RequestHandle *con_handle,
507 const char *url, 510 const char *url,
508 void *cls) 511 void *cls)
509{ 512{
510 struct RequestHandle *handle = cls; 513 struct RequestHandle *handle = cls;
511 struct EgoEntry *ego_entry; 514 struct EgoEntry *ego_entry;
@@ -515,56 +518,56 @@ namestore_get(struct GNUNET_REST_RequestHandle *con_handle,
515 ego_entry = NULL; 518 ego_entry = NULL;
516 519
517 // set zone to name if given 520 // set zone to name if given
518 if (strlen(GNUNET_REST_API_NS_NAMESTORE) < strlen(handle->url)) 521 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url))
522 {
523 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1];
524 ego_entry = get_egoentry_namestore (handle, egoname);
525
526 if (NULL == ego_entry)
519 { 527 {
520 egoname = &handle->url[strlen(GNUNET_REST_API_NS_NAMESTORE) + 1]; 528 handle->response_code = MHD_HTTP_NOT_FOUND;
521 ego_entry = get_egoentry_namestore(handle, egoname); 529 handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND);
522 530 GNUNET_SCHEDULER_add_now (&do_error, handle);
523 if (NULL == ego_entry) 531 return;
524 {
525 handle->response_code = MHD_HTTP_NOT_FOUND;
526 handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
527 GNUNET_SCHEDULER_add_now(&do_error, handle);
528 return;
529 }
530 } 532 }
533 }
531 if (NULL != ego_entry) 534 if (NULL != ego_entry)
532 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); 535 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
533 536
534 handle->list_it = 537 handle->list_it =
535 GNUNET_NAMESTORE_zone_iteration_start(handle->ns_handle, 538 GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle,
536 handle->zone_pkey, 539 handle->zone_pkey,
537 &namestore_iteration_error, 540 &namestore_iteration_error,
538 handle, 541 handle,
539 &namestore_list_iteration, 542 &namestore_list_iteration,
540 handle, 543 handle,
541 &namestore_list_finished, 544 &namestore_list_finished,
542 handle); 545 handle);
543 if (NULL == handle->list_it) 546 if (NULL == handle->list_it)
544 { 547 {
545 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); 548 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED);
546 GNUNET_SCHEDULER_add_now(&do_error, handle); 549 GNUNET_SCHEDULER_add_now (&do_error, handle);
547 return; 550 return;
548 } 551 }
549} 552}
550 553
551 554
552static void 555static void
553ns_lookup_error_cb(void *cls) 556ns_lookup_error_cb (void *cls)
554{ 557{
555 struct RequestHandle *handle = cls; 558 struct RequestHandle *handle = cls;
556 559
557 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); 560 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED);
558 GNUNET_SCHEDULER_add_now(&do_error, handle); 561 GNUNET_SCHEDULER_add_now (&do_error, handle);
559} 562}
560 563
561 564
562static void 565static void
563ns_lookup_cb(void *cls, 566ns_lookup_cb (void *cls,
564 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 567 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
565 const char *label, 568 const char *label,
566 unsigned int rd_count, 569 unsigned int rd_count,
567 const struct GNUNET_GNSRECORD_Data *rd) 570 const struct GNUNET_GNSRECORD_Data *rd)
568{ 571{
569 struct RequestHandle *handle = cls; 572 struct RequestHandle *handle = cls;
570 struct GNUNET_GNSRECORD_Data rd_new[rd_count + handle->rd_count]; 573 struct GNUNET_GNSRECORD_Data rd_new[rd_count + handle->rd_count];
@@ -573,19 +576,19 @@ ns_lookup_cb(void *cls,
573 rd_new[i] = rd[i]; 576 rd_new[i] = rd[i];
574 for (int j = 0; j < handle->rd_count; j++) 577 for (int j = 0; j < handle->rd_count; j++)
575 rd_new[rd_count + j] = handle->rd[j]; 578 rd_new[rd_count + j] = handle->rd[j];
576 handle->add_qe = GNUNET_NAMESTORE_records_store(handle->ns_handle, 579 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
577 handle->zone_pkey, 580 handle->zone_pkey,
578 handle->record_name, 581 handle->record_name,
579 rd_count + handle->rd_count, 582 rd_count + handle->rd_count,
580 rd_new, 583 rd_new,
581 &create_finished, 584 &create_finished,
582 handle); 585 handle);
583 if (NULL == handle->add_qe) 586 if (NULL == handle->add_qe)
584 { 587 {
585 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); 588 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED);
586 GNUNET_SCHEDULER_add_now(&do_error, handle); 589 GNUNET_SCHEDULER_add_now (&do_error, handle);
587 return; 590 return;
588 } 591 }
589} 592}
590 593
591 594
@@ -597,9 +600,9 @@ ns_lookup_cb(void *cls,
597 * @param cls the RequestHandle 600 * @param cls the RequestHandle
598 */ 601 */
599void 602void
600namestore_add(struct GNUNET_REST_RequestHandle *con_handle, 603namestore_add (struct GNUNET_REST_RequestHandle *con_handle,
601 const char *url, 604 const char *url,
602 void *cls) 605 void *cls)
603{ 606{
604 struct RequestHandle *handle = cls; 607 struct RequestHandle *handle = cls;
605 struct EgoEntry *ego_entry; 608 struct EgoEntry *ego_entry;
@@ -610,67 +613,69 @@ namestore_add(struct GNUNET_REST_RequestHandle *con_handle,
610 char term_data[handle->rest_handle->data_size + 1]; 613 char term_data[handle->rest_handle->data_size + 1];
611 614
612 if (0 >= handle->rest_handle->data_size) 615 if (0 >= handle->rest_handle->data_size)
613 { 616 {
614 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DATA); 617 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_NO_DATA);
615 GNUNET_SCHEDULER_add_now(&do_error, handle); 618 GNUNET_SCHEDULER_add_now (&do_error, handle);
616 return; 619 return;
617 } 620 }
618 term_data[handle->rest_handle->data_size] = '\0'; 621 term_data[handle->rest_handle->data_size] = '\0';
619 GNUNET_memcpy(term_data, 622 GNUNET_memcpy (term_data,
620 handle->rest_handle->data, 623 handle->rest_handle->data,
621 handle->rest_handle->data_size); 624 handle->rest_handle->data_size);
622 data_js = json_loads(term_data, JSON_DECODE_ANY, &err); 625 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
623 struct GNUNET_JSON_Specification gnsspec[] = 626 struct GNUNET_JSON_Specification gnsspec[] =
624 { GNUNET_JSON_spec_gnsrecord(&handle->rd, &handle->rd_count, &handle->record_name), GNUNET_JSON_spec_end() }; 627 { GNUNET_JSON_spec_gnsrecord (&handle->rd, &handle->rd_count,
625 if (GNUNET_OK != GNUNET_JSON_parse(data_js, gnsspec, NULL, NULL)) 628 &handle->record_name),
626 { 629 GNUNET_JSON_spec_end () };
627 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA); 630 if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL))
628 GNUNET_SCHEDULER_add_now(&do_error, handle); 631 {
629 json_decref(data_js); 632 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA);
630 return; 633 GNUNET_SCHEDULER_add_now (&do_error, handle);
631 } 634 json_decref (data_js);
632 GNUNET_JSON_parse_free(gnsspec); 635 return;
633 if (0 >= strlen(handle->record_name)) 636 }
634 { 637 GNUNET_JSON_parse_free (gnsspec);
635 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA); 638 if (0 >= strlen (handle->record_name))
636 GNUNET_SCHEDULER_add_now(&do_error, handle); 639 {
637 json_decref(data_js); 640 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA);
638 return; 641 GNUNET_SCHEDULER_add_now (&do_error, handle);
639 } 642 json_decref (data_js);
640 json_decref(data_js); 643 return;
644 }
645 json_decref (data_js);
641 646
642 egoname = NULL; 647 egoname = NULL;
643 ego_entry = NULL; 648 ego_entry = NULL;
644 649
645 // set zone to name if given 650 // set zone to name if given
646 if (strlen(GNUNET_REST_API_NS_NAMESTORE) < strlen(handle->url)) 651 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url))
652 {
653 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1];
654 ego_entry = get_egoentry_namestore (handle, egoname);
655
656 if (NULL == ego_entry)
647 { 657 {
648 egoname = &handle->url[strlen(GNUNET_REST_API_NS_NAMESTORE) + 1]; 658 handle->response_code = MHD_HTTP_NOT_FOUND;
649 ego_entry = get_egoentry_namestore(handle, egoname); 659 handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND);
650 660 GNUNET_SCHEDULER_add_now (&do_error, handle);
651 if (NULL == ego_entry) 661 return;
652 {
653 handle->response_code = MHD_HTTP_NOT_FOUND;
654 handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
655 GNUNET_SCHEDULER_add_now(&do_error, handle);
656 return;
657 }
658 } 662 }
663 }
659 if (NULL != ego_entry) 664 if (NULL != ego_entry)
660 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); 665 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
661 handle->add_qe = GNUNET_NAMESTORE_records_lookup(handle->ns_handle, 666 handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle,
662 handle->zone_pkey, 667 handle->zone_pkey,
663 handle->record_name, 668 handle->record_name,
664 &ns_lookup_error_cb, 669 &ns_lookup_error_cb,
665 handle, 670 handle,
666 &ns_lookup_cb, 671 &ns_lookup_cb,
667 handle); 672 handle);
668 if (NULL == handle->add_qe) 673 if (NULL == handle->add_qe)
669 { 674 {
670 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); 675 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED);
671 GNUNET_SCHEDULER_add_now(&do_error, handle); 676 GNUNET_SCHEDULER_add_now (&do_error, handle);
672 return; 677 return;
673 } 678 }
674} 679}
675 680
676 681
@@ -682,9 +687,9 @@ namestore_add(struct GNUNET_REST_RequestHandle *con_handle,
682 * @param cls the RequestHandle 687 * @param cls the RequestHandle
683 */ 688 */
684void 689void
685namestore_delete(struct GNUNET_REST_RequestHandle *con_handle, 690namestore_delete (struct GNUNET_REST_RequestHandle *con_handle,
686 const char *url, 691 const char *url,
687 void *cls) 692 void *cls)
688{ 693{
689 struct RequestHandle *handle = cls; 694 struct RequestHandle *handle = cls;
690 struct GNUNET_HashCode key; 695 struct GNUNET_HashCode key;
@@ -695,46 +700,46 @@ namestore_delete(struct GNUNET_REST_RequestHandle *con_handle,
695 ego_entry = NULL; 700 ego_entry = NULL;
696 701
697 // set zone to name if given 702 // set zone to name if given
698 if (strlen(GNUNET_REST_API_NS_NAMESTORE) < strlen(handle->url)) 703 if (strlen (GNUNET_REST_API_NS_NAMESTORE) < strlen (handle->url))
704 {
705 egoname = &handle->url[strlen (GNUNET_REST_API_NS_NAMESTORE) + 1];
706 ego_entry = get_egoentry_namestore (handle, egoname);
707
708 if (NULL == ego_entry)
699 { 709 {
700 egoname = &handle->url[strlen(GNUNET_REST_API_NS_NAMESTORE) + 1]; 710 handle->response_code = MHD_HTTP_NOT_FOUND;
701 ego_entry = get_egoentry_namestore(handle, egoname); 711 handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND);
702 712 GNUNET_SCHEDULER_add_now (&do_error, handle);
703 if (NULL == ego_entry) 713 return;
704 {
705 handle->response_code = MHD_HTTP_NOT_FOUND;
706 handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND);
707 GNUNET_SCHEDULER_add_now(&do_error, handle);
708 return;
709 }
710 } 714 }
715 }
711 if (NULL != ego_entry) 716 if (NULL != ego_entry)
712 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); 717 handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
713 718
714 GNUNET_CRYPTO_hash("record_name", strlen("record_name"), &key); 719 GNUNET_CRYPTO_hash ("record_name", strlen ("record_name"), &key);
715 if (GNUNET_NO == 720 if (GNUNET_NO ==
716 GNUNET_CONTAINER_multihashmap_contains(con_handle->url_param_map, &key)) 721 GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, &key))
717 { 722 {
718 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_INVALID_DATA); 723 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_INVALID_DATA);
719 GNUNET_SCHEDULER_add_now(&do_error, handle); 724 GNUNET_SCHEDULER_add_now (&do_error, handle);
720 return; 725 return;
721 } 726 }
722 handle->record_name = GNUNET_strdup( 727 handle->record_name = GNUNET_strdup (
723 GNUNET_CONTAINER_multihashmap_get(con_handle->url_param_map, &key)); 728 GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key));
724 729
725 handle->add_qe = GNUNET_NAMESTORE_records_store(handle->ns_handle, 730 handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle,
726 handle->zone_pkey, 731 handle->zone_pkey,
727 handle->record_name, 732 handle->record_name,
728 0, 733 0,
729 NULL, 734 NULL,
730 &del_finished, 735 &del_finished,
731 handle); 736 handle);
732 if (NULL == handle->add_qe) 737 if (NULL == handle->add_qe)
733 { 738 {
734 handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); 739 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED);
735 GNUNET_SCHEDULER_add_now(&do_error, handle); 740 GNUNET_SCHEDULER_add_now (&do_error, handle);
736 return; 741 return;
737 } 742 }
738} 743}
739 744
740 745
@@ -746,18 +751,18 @@ namestore_delete(struct GNUNET_REST_RequestHandle *con_handle,
746 * @param cls the RequestHandle 751 * @param cls the RequestHandle
747 */ 752 */
748static void 753static void
749options_cont(struct GNUNET_REST_RequestHandle *con_handle, 754options_cont (struct GNUNET_REST_RequestHandle *con_handle,
750 const char *url, 755 const char *url,
751 void *cls) 756 void *cls)
752{ 757{
753 struct MHD_Response *resp; 758 struct MHD_Response *resp;
754 struct RequestHandle *handle = cls; 759 struct RequestHandle *handle = cls;
755 760
756 // independent of path return all options 761 // independent of path return all options
757 resp = GNUNET_REST_create_response(NULL); 762 resp = GNUNET_REST_create_response (NULL);
758 MHD_add_response_header(resp, "Access-Control-Allow-Methods", allow_methods); 763 MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
759 handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); 764 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
760 GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); 765 GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
761 return; 766 return;
762} 767}
763 768
@@ -768,7 +773,7 @@ options_cont(struct GNUNET_REST_RequestHandle *con_handle,
768 * @param handle the request handle 773 * @param handle the request handle
769 */ 774 */
770static void 775static void
771init_cont(struct RequestHandle *handle) 776init_cont (struct RequestHandle *handle)
772{ 777{
773 struct GNUNET_REST_RequestHandlerError err; 778 struct GNUNET_REST_RequestHandlerError err;
774 static const struct GNUNET_REST_RequestHandler handlers[] = 779 static const struct GNUNET_REST_RequestHandler handlers[] =
@@ -779,11 +784,11 @@ init_cont(struct RequestHandle *handle)
779 GNUNET_REST_HANDLER_END }; 784 GNUNET_REST_HANDLER_END };
780 785
781 if (GNUNET_NO == 786 if (GNUNET_NO ==
782 GNUNET_REST_handle_request(handle->rest_handle, handlers, &err, handle)) 787 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
783 { 788 {
784 handle->response_code = err.error_code; 789 handle->response_code = err.error_code;
785 GNUNET_SCHEDULER_add_now(&do_error, handle); 790 GNUNET_SCHEDULER_add_now (&do_error, handle);
786 } 791 }
787} 792}
788 793
789 794
@@ -819,32 +824,32 @@ init_cont(struct RequestHandle *handle)
819 * must thus no longer be used 824 * must thus no longer be used
820 */ 825 */
821static void 826static void
822id_connect_cb(void *cls, 827id_connect_cb (void *cls,
823 struct GNUNET_IDENTITY_Ego *ego, 828 struct GNUNET_IDENTITY_Ego *ego,
824 void **ctx, 829 void **ctx,
825 const char *name) 830 const char *name)
826{ 831{
827 struct RequestHandle *handle = cls; 832 struct RequestHandle *handle = cls;
828 struct EgoEntry *ego_entry; 833 struct EgoEntry *ego_entry;
829 struct GNUNET_CRYPTO_EcdsaPublicKey pk; 834 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
830 835
831 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) 836 if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state))
832 { 837 {
833 handle->state = ID_REST_STATE_POST_INIT; 838 handle->state = ID_REST_STATE_POST_INIT;
834 init_cont(handle); 839 init_cont (handle);
835 return; 840 return;
836 } 841 }
837 if (ID_REST_STATE_INIT == handle->state) 842 if (ID_REST_STATE_INIT == handle->state)
838 { 843 {
839 ego_entry = GNUNET_new(struct EgoEntry); 844 ego_entry = GNUNET_new (struct EgoEntry);
840 GNUNET_IDENTITY_ego_get_public_key(ego, &pk); 845 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
841 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pk); 846 ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
842 ego_entry->ego = ego; 847 ego_entry->ego = ego;
843 GNUNET_asprintf(&ego_entry->identifier, "%s", name); 848 GNUNET_asprintf (&ego_entry->identifier, "%s", name);
844 GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head, 849 GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head,
845 handle->ego_tail, 850 handle->ego_tail,
846 ego_entry); 851 ego_entry);
847 } 852 }
848} 853}
849 854
850 855
@@ -860,11 +865,11 @@ id_connect_cb(void *cls,
860 * @return GNUNET_OK if request accepted 865 * @return GNUNET_OK if request accepted
861 */ 866 */
862static void 867static void
863rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, 868rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
864 GNUNET_REST_ResultProcessor proc, 869 GNUNET_REST_ResultProcessor proc,
865 void *proc_cls) 870 void *proc_cls)
866{ 871{
867 struct RequestHandle *handle = GNUNET_new(struct RequestHandle); 872 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
868 873
869 handle->response_code = 0; 874 handle->response_code = 0;
870 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 875 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
@@ -873,18 +878,18 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
873 handle->rest_handle = rest_handle; 878 handle->rest_handle = rest_handle;
874 handle->zone_pkey = NULL; 879 handle->zone_pkey = NULL;
875 880
876 handle->url = GNUNET_strdup(rest_handle->url); 881 handle->url = GNUNET_strdup (rest_handle->url);
877 if (handle->url[strlen(handle->url) - 1] == '/') 882 if (handle->url[strlen (handle->url) - 1] == '/')
878 handle->url[strlen(handle->url) - 1] = '\0'; 883 handle->url[strlen (handle->url) - 1] = '\0';
879 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); 884 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
880 885
881 handle->ns_handle = GNUNET_NAMESTORE_connect(cfg); 886 handle->ns_handle = GNUNET_NAMESTORE_connect (cfg);
882 handle->identity_handle = 887 handle->identity_handle =
883 GNUNET_IDENTITY_connect(cfg, &id_connect_cb, handle); 888 GNUNET_IDENTITY_connect (cfg, &id_connect_cb, handle);
884 handle->timeout_task = 889 handle->timeout_task =
885 GNUNET_SCHEDULER_add_delayed(handle->timeout, &do_error, handle); 890 GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_error, handle);
886 891
887 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); 892 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
888} 893}
889 894
890 895
@@ -895,7 +900,7 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
895 * @return NULL on error, otherwise the plugin context 900 * @return NULL on error, otherwise the plugin context
896 */ 901 */
897void * 902void *
898libgnunet_plugin_rest_namestore_init(void *cls) 903libgnunet_plugin_rest_namestore_init (void *cls)
899{ 904{
900 static struct Plugin plugin; 905 static struct Plugin plugin;
901 struct GNUNET_REST_Plugin *api; 906 struct GNUNET_REST_Plugin *api;
@@ -903,21 +908,21 @@ libgnunet_plugin_rest_namestore_init(void *cls)
903 cfg = cls; 908 cfg = cls;
904 if (NULL != plugin.cfg) 909 if (NULL != plugin.cfg)
905 return NULL; /* can only initialize once! */ 910 return NULL; /* can only initialize once! */
906 memset(&plugin, 0, sizeof(struct Plugin)); 911 memset (&plugin, 0, sizeof(struct Plugin));
907 plugin.cfg = cfg; 912 plugin.cfg = cfg;
908 api = GNUNET_new(struct GNUNET_REST_Plugin); 913 api = GNUNET_new (struct GNUNET_REST_Plugin);
909 api->cls = &plugin; 914 api->cls = &plugin;
910 api->name = GNUNET_REST_API_NS_NAMESTORE; 915 api->name = GNUNET_REST_API_NS_NAMESTORE;
911 api->process_request = &rest_process_request; 916 api->process_request = &rest_process_request;
912 GNUNET_asprintf(&allow_methods, 917 GNUNET_asprintf (&allow_methods,
913 "%s, %s, %s, %s, %s", 918 "%s, %s, %s, %s, %s",
914 MHD_HTTP_METHOD_GET, 919 MHD_HTTP_METHOD_GET,
915 MHD_HTTP_METHOD_POST, 920 MHD_HTTP_METHOD_POST,
916 MHD_HTTP_METHOD_PUT, 921 MHD_HTTP_METHOD_PUT,
917 MHD_HTTP_METHOD_DELETE, 922 MHD_HTTP_METHOD_DELETE,
918 MHD_HTTP_METHOD_OPTIONS); 923 MHD_HTTP_METHOD_OPTIONS);
919 924
920 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Namestore REST API initialized\n")); 925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Namestore REST API initialized\n"));
921 return api; 926 return api;
922} 927}
923 928
@@ -929,18 +934,17 @@ libgnunet_plugin_rest_namestore_init(void *cls)
929 * @return always NULL 934 * @return always NULL
930 */ 935 */
931void * 936void *
932libgnunet_plugin_rest_namestore_done(void *cls) 937libgnunet_plugin_rest_namestore_done (void *cls)
933{ 938{
934 struct GNUNET_REST_Plugin *api = cls; 939 struct GNUNET_REST_Plugin *api = cls;
935 struct Plugin *plugin = api->cls; 940 struct Plugin *plugin = api->cls;
936 941
937 plugin->cfg = NULL; 942 plugin->cfg = NULL;
938 943
939 GNUNET_free_non_null(allow_methods); 944 GNUNET_free_non_null (allow_methods);
940 GNUNET_free(api); 945 GNUNET_free (api);
941 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Namestore REST plugin is finished\n"); 946 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore REST plugin is finished\n");
942 return NULL; 947 return NULL;
943} 948}
944 949
945/* end of plugin_rest_namestore.c */ 950/* end of plugin_rest_namestore.c */
946