aboutsummaryrefslogtreecommitdiff
path: root/src/identity/gnunet-service-identity.c
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-06 22:46:29 +0000
committerng0 <ng0@n0.is>2019-09-06 22:46:29 +0000
commit6e599264ad13e8fc105493d74d7c11d46f8739ed (patch)
tree169bef1ecbade5a659831fb169f3ae6943af127f /src/identity/gnunet-service-identity.c
parent4f13bc15113021ebf71d5d81e99bc29f8a07fc9c (diff)
downloadgnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.tar.gz
gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.zip
first step to remove plibc
Diffstat (limited to 'src/identity/gnunet-service-identity.c')
-rw-r--r--src/identity/gnunet-service-identity.c394
1 files changed, 167 insertions, 227 deletions
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index 3e92a04cd..34fad3272 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -64,7 +64,6 @@ struct Ego
64 * String identifier for the ego. 64 * String identifier for the ego.
65 */ 65 */
66 char *identifier; 66 char *identifier;
67
68}; 67};
69 68
70 69
@@ -122,10 +121,10 @@ get_ego_filename (struct Ego *ego)
122 char *filename; 121 char *filename;
123 122
124 GNUNET_asprintf (&filename, 123 GNUNET_asprintf (&filename,
125 "%s%s%s", 124 "%s%s%s",
126 ego_directory, 125 ego_directory,
127 DIR_SEPARATOR_STR, 126 DIR_SEPARATOR_STR,
128 ego->identifier); 127 ego->identifier);
129 return filename; 128 return filename;
130} 129}
131 130
@@ -141,9 +140,7 @@ client_disconnect_cb (void *cls,
141 struct GNUNET_SERVICE_Client *client, 140 struct GNUNET_SERVICE_Client *client,
142 void *app_ctx) 141 void *app_ctx)
143{ 142{
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client);
145 "Client %p disconnected\n",
146 client);
147} 144}
148 145
149 146
@@ -208,8 +205,8 @@ shutdown_task (void *cls)
208 */ 205 */
209static void 206static void
210send_result_code (struct GNUNET_SERVICE_Client *client, 207send_result_code (struct GNUNET_SERVICE_Client *client,
211 uint32_t result_code, 208 uint32_t result_code,
212 const char *emsg) 209 const char *emsg)
213{ 210{
214 struct ResultCodeMessage *rcm; 211 struct ResultCodeMessage *rcm;
215 struct GNUNET_MQ_Envelope *env; 212 struct GNUNET_MQ_Envelope *env;
@@ -219,9 +216,8 @@ send_result_code (struct GNUNET_SERVICE_Client *client,
219 elen = 0; 216 elen = 0;
220 else 217 else
221 elen = strlen (emsg) + 1; 218 elen = strlen (emsg) + 1;
222 env = GNUNET_MQ_msg_extra (rcm, 219 env =
223 elen, 220 GNUNET_MQ_msg_extra (rcm, elen, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE);
224 GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE);
225 rcm->result_code = htonl (result_code); 221 rcm->result_code = htonl (result_code);
226 if (0 < elen) 222 if (0 < elen)
227 GNUNET_memcpy (&rcm[1], emsg, elen); 223 GNUNET_memcpy (&rcm[1], emsg, elen);
@@ -247,9 +243,7 @@ create_update_message (struct Ego *ego)
247 size_t name_len; 243 size_t name_len;
248 244
249 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1); 245 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
250 env = GNUNET_MQ_msg_extra (um, 246 env = GNUNET_MQ_msg_extra (um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
251 name_len,
252 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
253 um->name_len = htons (name_len); 247 um->name_len = htons (name_len);
254 um->end_of_list = htons (GNUNET_NO); 248 um->end_of_list = htons (GNUNET_NO);
255 um->private_key = *ego->pk; 249 um->private_key = *ego->pk;
@@ -266,8 +260,7 @@ create_update_message (struct Ego *ego)
266 * @return corresponding set default message 260 * @return corresponding set default message
267 */ 261 */
268static struct GNUNET_MQ_Envelope * 262static struct GNUNET_MQ_Envelope *
269create_set_default_message (struct Ego *ego, 263create_set_default_message (struct Ego *ego, const char *servicename)
270 const char *servicename)
271{ 264{
272 struct SetDefaultMessage *sdm; 265 struct SetDefaultMessage *sdm;
273 struct GNUNET_MQ_Envelope *env; 266 struct GNUNET_MQ_Envelope *env;
@@ -295,31 +288,26 @@ create_set_default_message (struct Ego *ego,
295 * @param message the message received 288 * @param message the message received
296 */ 289 */
297static void 290static void
298handle_start_message (void *cls, 291handle_start_message (void *cls, const struct GNUNET_MessageHeader *message)
299 const struct GNUNET_MessageHeader *message)
300{ 292{
301 struct GNUNET_SERVICE_Client *client = cls; 293 struct GNUNET_SERVICE_Client *client = cls;
302 struct UpdateMessage *ume; 294 struct UpdateMessage *ume;
303 struct GNUNET_MQ_Envelope *env; 295 struct GNUNET_MQ_Envelope *env;
304 struct Ego *ego; 296 struct Ego *ego;
305 297
306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n");
307 "Received START message from client\n");
308 GNUNET_SERVICE_client_mark_monitor (client); 299 GNUNET_SERVICE_client_mark_monitor (client);
309 GNUNET_SERVICE_client_disable_continue_warning (client); 300 GNUNET_SERVICE_client_disable_continue_warning (client);
310 GNUNET_notification_context_add (nc, 301 GNUNET_notification_context_add (nc, GNUNET_SERVICE_client_get_mq (client));
311 GNUNET_SERVICE_client_get_mq(client));
312 for (ego = ego_head; NULL != ego; ego = ego->next) 302 for (ego = ego_head; NULL != ego; ego = ego->next)
313 { 303 {
314 env = create_update_message (ego); 304 env = create_update_message (ego);
315 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(client), env); 305 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
316 } 306 }
317 env = GNUNET_MQ_msg_extra (ume, 307 env = GNUNET_MQ_msg_extra (ume, 0, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
318 0,
319 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
320 ume->end_of_list = htons (GNUNET_YES); 308 ume->end_of_list = htons (GNUNET_YES);
321 ume->name_len = htons (0); 309 ume->name_len = htons (0);
322 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(client), env); 310 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
323 GNUNET_SERVICE_client_continue (client); 311 GNUNET_SERVICE_client_continue (client);
324} 312}
325 313
@@ -333,8 +321,7 @@ handle_start_message (void *cls,
333 * @return #GNUNET_SYSERR if message was ill-formed 321 * @return #GNUNET_SYSERR if message was ill-formed
334 */ 322 */
335static int 323static int
336check_lookup_message (void *cls, 324check_lookup_message (void *cls, const struct LookupMessage *message)
337 const struct LookupMessage *message)
338{ 325{
339 GNUNET_MQ_check_zero_termination (message); 326 GNUNET_MQ_check_zero_termination (message);
340 return GNUNET_OK; 327 return GNUNET_OK;
@@ -349,30 +336,25 @@ check_lookup_message (void *cls,
349 * @param message the message received 336 * @param message the message received
350 */ 337 */
351static void 338static void
352handle_lookup_message (void *cls, 339handle_lookup_message (void *cls, const struct LookupMessage *message)
353 const struct LookupMessage *message)
354{ 340{
355 struct GNUNET_SERVICE_Client *client = cls; 341 struct GNUNET_SERVICE_Client *client = cls;
356 const char *name; 342 const char *name;
357 struct GNUNET_MQ_Envelope *env; 343 struct GNUNET_MQ_Envelope *env;
358 struct Ego *ego; 344 struct Ego *ego;
359 345
360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received LOOKUP message from client\n");
361 "Received LOOKUP message from client\n");
362 name = (const char *) &message[1]; 347 name = (const char *) &message[1];
363 for (ego = ego_head; NULL != ego; ego = ego->next) 348 for (ego = ego_head; NULL != ego; ego = ego->next)
364 { 349 {
365 if (0 != strcasecmp (name, 350 if (0 != strcasecmp (name, ego->identifier))
366 ego->identifier))
367 continue; 351 continue;
368 env = create_update_message (ego); 352 env = create_update_message (ego);
369 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); 353 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
370 GNUNET_SERVICE_client_continue (client); 354 GNUNET_SERVICE_client_continue (client);
371 return; 355 return;
372 } 356 }
373 send_result_code (client, 357 send_result_code (client, 0, "ego not found");
374 0,
375 "ego not found");
376 GNUNET_SERVICE_client_continue (client); 358 GNUNET_SERVICE_client_continue (client);
377} 359}
378 360
@@ -386,8 +368,7 @@ handle_lookup_message (void *cls,
386 * @return #GNUNET_SYSERR if message was ill-formed 368 * @return #GNUNET_SYSERR if message was ill-formed
387 */ 369 */
388static int 370static int
389check_lookup_by_suffix_message (void *cls, 371check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
390 const struct LookupMessage *message)
391{ 372{
392 GNUNET_MQ_check_zero_termination (message); 373 GNUNET_MQ_check_zero_termination (message);
393 return GNUNET_OK; 374 return GNUNET_OK;
@@ -402,8 +383,7 @@ check_lookup_by_suffix_message (void *cls,
402 * @param message the message received 383 * @param message the message received
403 */ 384 */
404static void 385static void
405handle_lookup_by_suffix_message (void *cls, 386handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
406 const struct LookupMessage *message)
407{ 387{
408 struct GNUNET_SERVICE_Client *client = cls; 388 struct GNUNET_SERVICE_Client *client = cls;
409 const char *name; 389 const char *name;
@@ -419,10 +399,9 @@ handle_lookup_by_suffix_message (void *cls,
419 399
420 if ((strlen (ego->identifier) <= strlen (name)) && 400 if ((strlen (ego->identifier) <= strlen (name)) &&
421 (0 == strcmp (ego->identifier, 401 (0 == strcmp (ego->identifier,
422 &name[strlen (name) - strlen (ego->identifier)])) && 402 &name[strlen (name) - strlen (ego->identifier)])) &&
423 ((strlen (name) == strlen (ego->identifier)) || 403 ((strlen (name) == strlen (ego->identifier)) ||
424 ('.' == name[strlen (name) - 404 ('.' == name[strlen (name) - strlen (ego->identifier) - 1])) &&
425 strlen (ego->identifier) - 1])) &&
426 ((NULL == lprefix) || 405 ((NULL == lprefix) ||
427 (strlen (ego->identifier) > strlen (lprefix->identifier)))) 406 (strlen (ego->identifier) > strlen (lprefix->identifier))))
428 { 407 {
@@ -437,9 +416,7 @@ handle_lookup_by_suffix_message (void *cls,
437 GNUNET_SERVICE_client_continue (client); 416 GNUNET_SERVICE_client_continue (client);
438 return; 417 return;
439 } 418 }
440 send_result_code (client, 419 send_result_code (client, 0, "ego not found");
441 0,
442 "ego not found");
443 GNUNET_SERVICE_client_continue (client); 420 GNUNET_SERVICE_client_continue (client);
444} 421}
445 422
@@ -452,8 +429,7 @@ handle_lookup_by_suffix_message (void *cls,
452 * @return #GNUNET_OK if @a msg is well-formed 429 * @return #GNUNET_OK if @a msg is well-formed
453 */ 430 */
454static int 431static int
455check_get_default_message (void *cls, 432check_get_default_message (void *cls, const struct GetDefaultMessage *msg)
456 const struct GetDefaultMessage *msg)
457{ 433{
458 uint16_t size; 434 uint16_t size;
459 uint16_t name_len; 435 uint16_t name_len;
@@ -467,9 +443,8 @@ check_get_default_message (void *cls,
467 } 443 }
468 name = (const char *) &msg[1]; 444 name = (const char *) &msg[1];
469 name_len = ntohs (msg->name_len); 445 name_len = ntohs (msg->name_len);
470 if ( (name_len + sizeof (struct GetDefaultMessage) != size) || 446 if ((name_len + sizeof (struct GetDefaultMessage) != size) ||
471 (0 != ntohs (msg->reserved)) || 447 (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1]))
472 ('\0' != name[name_len - 1]) )
473 { 448 {
474 GNUNET_break (0); 449 GNUNET_break (0);
475 return GNUNET_SYSERR; 450 return GNUNET_SYSERR;
@@ -487,8 +462,7 @@ check_get_default_message (void *cls,
487 * @param message the message received 462 * @param message the message received
488 */ 463 */
489static void 464static void
490handle_get_default_message (void *cls, 465handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm)
491 const struct GetDefaultMessage *gdm)
492{ 466{
493 struct GNUNET_MQ_Envelope *env; 467 struct GNUNET_MQ_Envelope *env;
494 struct GNUNET_SERVICE_Client *client = cls; 468 struct GNUNET_SERVICE_Client *client = cls;
@@ -502,11 +476,10 @@ handle_get_default_message (void *cls,
502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
503 "Received GET_DEFAULT for service `%s' from client\n", 477 "Received GET_DEFAULT for service `%s' from client\n",
504 name); 478 name);
505 if (GNUNET_OK != 479 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
506 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, 480 name,
507 name, 481 "DEFAULT_IDENTIFIER",
508 "DEFAULT_IDENTIFIER", 482 &identifier))
509 &identifier))
510 { 483 {
511 send_result_code (client, 1, gettext_noop ("no default known")); 484 send_result_code (client, 1, gettext_noop ("no default known"));
512 GNUNET_SERVICE_client_continue (client); 485 GNUNET_SERVICE_client_continue (client);
@@ -515,11 +488,9 @@ handle_get_default_message (void *cls,
515 } 488 }
516 for (ego = ego_head; NULL != ego; ego = ego->next) 489 for (ego = ego_head; NULL != ego; ego = ego->next)
517 { 490 {
518 if (0 == strcmp (ego->identifier, 491 if (0 == strcmp (ego->identifier, identifier))
519 identifier))
520 { 492 {
521 env = create_set_default_message (ego, 493 env = create_set_default_message (ego, name);
522 name);
523 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); 494 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
524 GNUNET_SERVICE_client_continue (client); 495 GNUNET_SERVICE_client_continue (client);
525 GNUNET_free (identifier); 496 GNUNET_free (identifier);
@@ -528,12 +499,12 @@ handle_get_default_message (void *cls,
528 } 499 }
529 } 500 }
530 GNUNET_free (identifier); 501 GNUNET_free (identifier);
531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to find ego `%s'\n", name);
532 "Failed to find ego `%s'\n",
533 name);
534 GNUNET_free (name); 503 GNUNET_free (name);
535 send_result_code (client, 1, 504 send_result_code (client,
536 gettext_noop ("default configured, but ego unknown (internal error)")); 505 1,
506 gettext_noop (
507 "default configured, but ego unknown (internal error)"));
537 GNUNET_SERVICE_client_continue (client); 508 GNUNET_SERVICE_client_continue (client);
538} 509}
539 510
@@ -560,8 +531,7 @@ key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1,
560 * @return #GNUNET_OK if @a msg is well-formed 531 * @return #GNUNET_OK if @a msg is well-formed
561 */ 532 */
562static int 533static int
563check_set_default_message (void *cls, 534check_set_default_message (void *cls, const struct SetDefaultMessage *msg)
564 const struct SetDefaultMessage *msg)
565{ 535{
566 uint16_t size; 536 uint16_t size;
567 uint16_t name_len; 537 uint16_t name_len;
@@ -598,8 +568,7 @@ check_set_default_message (void *cls,
598 * @param message the message received 568 * @param message the message received
599 */ 569 */
600static void 570static void
601handle_set_default_message (void *cls, 571handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm)
602 const struct SetDefaultMessage *sdm)
603{ 572{
604 struct Ego *ego; 573 struct Ego *ego;
605 struct GNUNET_SERVICE_Client *client = cls; 574 struct GNUNET_SERVICE_Client *client = cls;
@@ -613,26 +582,27 @@ handle_set_default_message (void *cls,
613 str); 582 str);
614 for (ego = ego_head; NULL != ego; ego = ego->next) 583 for (ego = ego_head; NULL != ego; ego = ego->next)
615 { 584 {
616 if (0 == key_cmp (ego->pk, 585 if (0 == key_cmp (ego->pk, &sdm->private_key))
617 &sdm->private_key))
618 { 586 {
619 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, 587 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
620 str, 588 str,
621 "DEFAULT_IDENTIFIER", 589 "DEFAULT_IDENTIFIER",
622 ego->identifier); 590 ego->identifier);
623 if (GNUNET_OK != 591 if (GNUNET_OK !=
624 GNUNET_CONFIGURATION_write (subsystem_cfg, 592 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
625 subsystem_cfg_file)) 593 GNUNET_log (
626 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 594 GNUNET_ERROR_TYPE_ERROR,
627 _("Failed to write subsystem default identifier map to `%s'.\n"), 595 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
628 subsystem_cfg_file); 596 subsystem_cfg_file);
629 send_result_code (client, 0, NULL); 597 send_result_code (client, 0, NULL);
630 GNUNET_SERVICE_client_continue (client); 598 GNUNET_SERVICE_client_continue (client);
631 GNUNET_free (str); 599 GNUNET_free (str);
632 return; 600 return;
633 } 601 }
634 } 602 }
635 send_result_code (client, 1, _("Unknown ego specified for service (internal error)")); 603 send_result_code (client,
604 1,
605 _ ("Unknown ego specified for service (internal error)"));
636 GNUNET_free (str); 606 GNUNET_free (str);
637 GNUNET_SERVICE_client_continue (client); 607 GNUNET_SERVICE_client_continue (client);
638} 608}
@@ -657,9 +627,7 @@ notify_listeners (struct Ego *ego)
657 um->end_of_list = htons (GNUNET_NO); 627 um->end_of_list = htons (GNUNET_NO);
658 um->private_key = *ego->pk; 628 um->private_key = *ego->pk;
659 GNUNET_memcpy (&um[1], ego->identifier, name_len); 629 GNUNET_memcpy (&um[1], ego->identifier, name_len);
660 GNUNET_notification_context_broadcast (nc, 630 GNUNET_notification_context_broadcast (nc, &um->header, GNUNET_NO);
661 &um->header,
662 GNUNET_NO);
663 GNUNET_free (um); 631 GNUNET_free (um);
664} 632}
665 633
@@ -671,10 +639,9 @@ notify_listeners (struct Ego *ego)
671 * @return #GNUNET_OK if @a msg is well-formed 639 * @return #GNUNET_OK if @a msg is well-formed
672 */ 640 */
673static int 641static int
674check_create_message (void *cls, 642check_create_message (void *cls, const struct CreateRequestMessage *msg)
675 const struct CreateRequestMessage *msg)
676{ 643{
677 644
678 uint16_t size; 645 uint16_t size;
679 uint16_t name_len; 646 uint16_t name_len;
680 const char *str; 647 const char *str;
@@ -699,7 +666,7 @@ check_create_message (void *cls,
699 return GNUNET_SYSERR; 666 return GNUNET_SYSERR;
700 } 667 }
701 return GNUNET_OK; 668 return GNUNET_OK;
702} 669}
703 670
704/** 671/**
705 * Handler for CREATE message from client, creates 672 * Handler for CREATE message from client, creates
@@ -710,24 +677,24 @@ check_create_message (void *cls,
710 * @param message the message received 677 * @param message the message received
711 */ 678 */
712static void 679static void
713handle_create_message (void *cls, 680handle_create_message (void *cls, const struct CreateRequestMessage *crm)
714 const struct CreateRequestMessage *crm)
715{ 681{
716 struct GNUNET_SERVICE_Client *client = cls; 682 struct GNUNET_SERVICE_Client *client = cls;
717 struct Ego *ego; 683 struct Ego *ego;
718 char *str; 684 char *str;
719 char *fn; 685 char *fn;
720 686
721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n");
722 "Received CREATE message from client\n");
723 str = GNUNET_strdup ((const char *) &crm[1]); 688 str = GNUNET_strdup ((const char *) &crm[1]);
724 GNUNET_STRINGS_utf8_tolower ((const char *) &crm[1], str); 689 GNUNET_STRINGS_utf8_tolower ((const char *) &crm[1], str);
725 for (ego = ego_head; NULL != ego; ego = ego->next) 690 for (ego = ego_head; NULL != ego; ego = ego->next)
726 { 691 {
727 if (0 == strcmp (ego->identifier, 692 if (0 == strcmp (ego->identifier, str))
728 str))
729 { 693 {
730 send_result_code (client, 1, gettext_noop ("identifier already in use for another ego")); 694 send_result_code (client,
695 1,
696 gettext_noop (
697 "identifier already in use for another ego"));
731 GNUNET_SERVICE_client_continue (client); 698 GNUNET_SERVICE_client_continue (client);
732 GNUNET_free (str); 699 GNUNET_free (str);
733 return; 700 return;
@@ -737,9 +704,7 @@ handle_create_message (void *cls,
737 ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); 704 ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey);
738 *ego->pk = crm->private_key; 705 *ego->pk = crm->private_key;
739 ego->identifier = GNUNET_strdup (str); 706 ego->identifier = GNUNET_strdup (str);
740 GNUNET_CONTAINER_DLL_insert (ego_head, 707 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
741 ego_tail,
742 ego);
743 send_result_code (client, 0, NULL); 708 send_result_code (client, 0, NULL);
744 fn = get_ego_filename (ego); 709 fn = get_ego_filename (ego);
745 (void) GNUNET_DISK_directory_create_for_file (fn); 710 (void) GNUNET_DISK_directory_create_for_file (fn);
@@ -748,9 +713,8 @@ handle_create_message (void *cls,
748 &crm->private_key, 713 &crm->private_key,
749 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 714 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
750 GNUNET_DISK_PERM_USER_READ | 715 GNUNET_DISK_PERM_USER_READ |
751 GNUNET_DISK_PERM_USER_WRITE)) 716 GNUNET_DISK_PERM_USER_WRITE))
752 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 717 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn);
753 "write", fn);
754 GNUNET_free (fn); 718 GNUNET_free (fn);
755 GNUNET_free (str); 719 GNUNET_free (str);
756 notify_listeners (ego); 720 notify_listeners (ego);
@@ -782,17 +746,15 @@ struct RenameContext
782 * @param section a section in the configuration to process 746 * @param section a section in the configuration to process
783 */ 747 */
784static void 748static void
785handle_ego_rename (void *cls, 749handle_ego_rename (void *cls, const char *section)
786 const char *section)
787{ 750{
788 struct RenameContext *rc = cls; 751 struct RenameContext *rc = cls;
789 char *id; 752 char *id;
790 753
791 if (GNUNET_OK != 754 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
792 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, 755 section,
793 section, 756 "DEFAULT_IDENTIFIER",
794 "DEFAULT_IDENTIFIER", 757 &id))
795 &id))
796 return; 758 return;
797 if (0 != strcmp (id, rc->old_name)) 759 if (0 != strcmp (id, rc->old_name))
798 { 760 {
@@ -814,8 +776,7 @@ handle_ego_rename (void *cls,
814 * @return #GNUNET_OK if @a msg is well-formed 776 * @return #GNUNET_OK if @a msg is well-formed
815 */ 777 */
816static int 778static int
817check_rename_message (void *cls, 779check_rename_message (void *cls, const struct RenameMessage *msg)
818 const struct RenameMessage *msg)
819{ 780{
820 uint16_t size; 781 uint16_t size;
821 uint16_t old_name_len; 782 uint16_t old_name_len;
@@ -833,9 +794,9 @@ check_rename_message (void *cls,
833 new_name_len = ntohs (msg->new_name_len); 794 new_name_len = ntohs (msg->new_name_len);
834 old_name = (const char *) &msg[1]; 795 old_name = (const char *) &msg[1];
835 new_name = &old_name[old_name_len]; 796 new_name = &old_name[old_name_len];
836 if ( (old_name_len + new_name_len + sizeof (struct RenameMessage) != size) || 797 if ((old_name_len + new_name_len + sizeof (struct RenameMessage) != size) ||
837 ('\0' != old_name[old_name_len - 1]) || 798 ('\0' != old_name[old_name_len - 1]) ||
838 ('\0' != new_name[new_name_len - 1]) ) 799 ('\0' != new_name[new_name_len - 1]))
839 { 800 {
840 GNUNET_break (0); 801 GNUNET_break (0);
841 return GNUNET_SYSERR; 802 return GNUNET_SYSERR;
@@ -843,7 +804,7 @@ check_rename_message (void *cls,
843 804
844 return GNUNET_OK; 805 return GNUNET_OK;
845} 806}
846 807
847 808
848/** 809/**
849 * Handler for RENAME message from client, creates 810 * Handler for RENAME message from client, creates
@@ -854,8 +815,7 @@ check_rename_message (void *cls,
854 * @param message the message received 815 * @param message the message received
855 */ 816 */
856static void 817static void
857handle_rename_message (void *cls, 818handle_rename_message (void *cls, const struct RenameMessage *rm)
858 const struct RenameMessage *rm)
859{ 819{
860 uint16_t old_name_len; 820 uint16_t old_name_len;
861 struct Ego *ego; 821 struct Ego *ego;
@@ -867,8 +827,7 @@ handle_rename_message (void *cls,
867 char *fn_new; 827 char *fn_new;
868 const char *old_name_tmp; 828 const char *old_name_tmp;
869 829
870 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 830 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n");
871 "Received RENAME message from client\n");
872 old_name_len = ntohs (rm->old_name_len); 831 old_name_len = ntohs (rm->old_name_len);
873 old_name_tmp = (const char *) &rm[1]; 832 old_name_tmp = (const char *) &rm[1];
874 old_name = GNUNET_strdup (old_name_tmp); 833 old_name = GNUNET_strdup (old_name_tmp);
@@ -879,8 +838,7 @@ handle_rename_message (void *cls,
879 /* check if new name is already in use */ 838 /* check if new name is already in use */
880 for (ego = ego_head; NULL != ego; ego = ego->next) 839 for (ego = ego_head; NULL != ego; ego = ego->next)
881 { 840 {
882 if (0 == strcmp (ego->identifier, 841 if (0 == strcmp (ego->identifier, new_name))
883 new_name))
884 { 842 {
885 send_result_code (client, 1, gettext_noop ("target name already exists")); 843 send_result_code (client, 1, gettext_noop ("target name already exists"));
886 GNUNET_SERVICE_client_continue (client); 844 GNUNET_SERVICE_client_continue (client);
@@ -893,8 +851,7 @@ handle_rename_message (void *cls,
893 /* locate old name and, if found, perform rename */ 851 /* locate old name and, if found, perform rename */
894 for (ego = ego_head; NULL != ego; ego = ego->next) 852 for (ego = ego_head; NULL != ego; ego = ego->next)
895 { 853 {
896 if (0 == strcmp (ego->identifier, 854 if (0 == strcmp (ego->identifier, old_name))
897 old_name))
898 { 855 {
899 fn_old = get_ego_filename (ego); 856 fn_old = get_ego_filename (ego);
900 GNUNET_free (ego->identifier); 857 GNUNET_free (ego->identifier);
@@ -904,14 +861,14 @@ handle_rename_message (void *cls,
904 &handle_ego_rename, 861 &handle_ego_rename,
905 &rename_ctx); 862 &rename_ctx);
906 if (GNUNET_OK != 863 if (GNUNET_OK !=
907 GNUNET_CONFIGURATION_write (subsystem_cfg, 864 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
908 subsystem_cfg_file)) 865 GNUNET_log (
909 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 866 GNUNET_ERROR_TYPE_ERROR,
910 _("Failed to write subsystem default identifier map to `%s'.\n"), 867 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
911 subsystem_cfg_file); 868 subsystem_cfg_file);
912 ego->identifier = GNUNET_strdup (new_name); 869 ego->identifier = GNUNET_strdup (new_name);
913 fn_new = get_ego_filename (ego); 870 fn_new = get_ego_filename (ego);
914 if (0 != RENAME (fn_old, fn_new)) 871 if (0 != rename (fn_old, fn_new))
915 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old); 872 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old);
916 GNUNET_free (fn_old); 873 GNUNET_free (fn_old);
917 GNUNET_free (fn_new); 874 GNUNET_free (fn_new);
@@ -940,17 +897,15 @@ handle_rename_message (void *cls,
940 * @param section a section in the configuration to process 897 * @param section a section in the configuration to process
941 */ 898 */
942static void 899static void
943handle_ego_delete (void *cls, 900handle_ego_delete (void *cls, const char *section)
944 const char *section)
945{ 901{
946 const char *identifier = cls; 902 const char *identifier = cls;
947 char *id; 903 char *id;
948 904
949 if (GNUNET_OK != 905 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
950 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, 906 section,
951 section, 907 "DEFAULT_IDENTIFIER",
952 "DEFAULT_IDENTIFIER", 908 &id))
953 &id))
954 return; 909 return;
955 if (0 != strcmp (id, identifier)) 910 if (0 != strcmp (id, identifier))
956 { 911 {
@@ -972,8 +927,7 @@ handle_ego_delete (void *cls,
972 * @return #GNUNET_OK if @a msg is well-formed 927 * @return #GNUNET_OK if @a msg is well-formed
973 */ 928 */
974static int 929static int
975check_delete_message (void *cls, 930check_delete_message (void *cls, const struct DeleteMessage *msg)
976 const struct DeleteMessage *msg)
977{ 931{
978 uint16_t size; 932 uint16_t size;
979 uint16_t name_len; 933 uint16_t name_len;
@@ -987,9 +941,8 @@ check_delete_message (void *cls,
987 } 941 }
988 name = (const char *) &msg[1]; 942 name = (const char *) &msg[1];
989 name_len = ntohs (msg->name_len); 943 name_len = ntohs (msg->name_len);
990 if ( (name_len + sizeof (struct DeleteMessage) != size) || 944 if ((name_len + sizeof (struct DeleteMessage) != size) ||
991 (0 != ntohs (msg->reserved)) || 945 (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1]))
992 ('\0' != name[name_len - 1]) )
993 { 946 {
994 GNUNET_break (0); 947 GNUNET_break (0);
995 return GNUNET_SYSERR; 948 return GNUNET_SYSERR;
@@ -1007,38 +960,33 @@ check_delete_message (void *cls,
1007 * @param message the message received 960 * @param message the message received
1008 */ 961 */
1009static void 962static void
1010handle_delete_message (void *cls, 963handle_delete_message (void *cls, const struct DeleteMessage *dm)
1011 const struct DeleteMessage *dm)
1012{ 964{
1013 struct Ego *ego; 965 struct Ego *ego;
1014 char *name; 966 char *name;
1015 char *fn; 967 char *fn;
1016 struct GNUNET_SERVICE_Client *client = cls; 968 struct GNUNET_SERVICE_Client *client = cls;
1017 969
1018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 970 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n");
1019 "Received DELETE message from client\n");
1020 name = GNUNET_strdup ((const char *) &dm[1]); 971 name = GNUNET_strdup ((const char *) &dm[1]);
1021 GNUNET_STRINGS_utf8_tolower ((const char *) &dm[1], name); 972 GNUNET_STRINGS_utf8_tolower ((const char *) &dm[1], name);
1022 973
1023 for (ego = ego_head; NULL != ego; ego = ego->next) 974 for (ego = ego_head; NULL != ego; ego = ego->next)
1024 { 975 {
1025 if (0 == strcmp (ego->identifier, 976 if (0 == strcmp (ego->identifier, name))
1026 name))
1027 { 977 {
1028 GNUNET_CONTAINER_DLL_remove (ego_head, 978 GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, ego);
1029 ego_tail,
1030 ego);
1031 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg, 979 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
1032 &handle_ego_delete, 980 &handle_ego_delete,
1033 ego->identifier); 981 ego->identifier);
1034 if (GNUNET_OK != 982 if (GNUNET_OK !=
1035 GNUNET_CONFIGURATION_write (subsystem_cfg, 983 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
1036 subsystem_cfg_file)) 984 GNUNET_log (
1037 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 985 GNUNET_ERROR_TYPE_ERROR,
1038 _("Failed to write subsystem default identifier map to `%s'.\n"), 986 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
1039 subsystem_cfg_file); 987 subsystem_cfg_file);
1040 fn = get_ego_filename (ego); 988 fn = get_ego_filename (ego);
1041 if (0 != UNLINK (fn)) 989 if (0 != unlink (fn))
1042 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); 990 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
1043 GNUNET_free (fn); 991 GNUNET_free (fn);
1044 GNUNET_free (ego->identifier); 992 GNUNET_free (ego->identifier);
@@ -1070,8 +1018,7 @@ handle_delete_message (void *cls,
1070 * #GNUNET_SYSERR to abort iteration with error! 1018 * #GNUNET_SYSERR to abort iteration with error!
1071 */ 1019 */
1072static int 1020static int
1073process_ego_file (void *cls, 1021process_ego_file (void *cls, const char *filename)
1074 const char *filename)
1075{ 1022{
1076 struct Ego *ego; 1023 struct Ego *ego;
1077 const char *fn; 1024 const char *fn;
@@ -1088,17 +1035,13 @@ process_ego_file (void *cls,
1088 { 1035 {
1089 GNUNET_free (ego); 1036 GNUNET_free (ego);
1090 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1037 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1091 _("Failed to parse ego information in `%s'\n"), 1038 _ ("Failed to parse ego information in `%s'\n"),
1092 filename); 1039 filename);
1093 return GNUNET_OK; 1040 return GNUNET_OK;
1094 } 1041 }
1095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1042 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded ego `%s'\n", fn + 1);
1096 "Loaded ego `%s'\n",
1097 fn + 1);
1098 ego->identifier = GNUNET_strdup (fn + 1); 1043 ego->identifier = GNUNET_strdup (fn + 1);
1099 GNUNET_CONTAINER_DLL_insert (ego_head, 1044 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
1100 ego_tail,
1101 ego);
1102 return GNUNET_OK; 1045 return GNUNET_OK;
1103} 1046}
1104 1047
@@ -1117,21 +1060,24 @@ run (void *cls,
1117{ 1060{
1118 cfg = c; 1061 cfg = c;
1119 nc = GNUNET_notification_context_create (1); 1062 nc = GNUNET_notification_context_create (1);
1120 if (GNUNET_OK != 1063 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
1121 GNUNET_CONFIGURATION_get_value_filename (cfg, "identity", 1064 "identity",
1122 "EGODIR", 1065 "EGODIR",
1123 &ego_directory)) 1066 &ego_directory))
1124 { 1067 {
1125 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR"); 1068 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR");
1126 GNUNET_SCHEDULER_shutdown (); 1069 GNUNET_SCHEDULER_shutdown ();
1127 return; 1070 return;
1128 } 1071 }
1129 if (GNUNET_OK != 1072 if (GNUNET_OK !=
1130 GNUNET_CONFIGURATION_get_value_filename (cfg, "identity", 1073 GNUNET_CONFIGURATION_get_value_filename (cfg,
1074 "identity",
1131 "SUBSYSTEM_CFG", 1075 "SUBSYSTEM_CFG",
1132 &subsystem_cfg_file)) 1076 &subsystem_cfg_file))
1133 { 1077 {
1134 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "SUBSYSTEM_CFG"); 1078 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1079 "identity",
1080 "SUBSYSTEM_CFG");
1135 GNUNET_SCHEDULER_shutdown (); 1081 GNUNET_SCHEDULER_shutdown ();
1136 return; 1082 return;
1137 } 1083 }
@@ -1139,78 +1085,72 @@ run (void *cls,
1139 "Loading subsystem configuration `%s'\n", 1085 "Loading subsystem configuration `%s'\n",
1140 subsystem_cfg_file); 1086 subsystem_cfg_file);
1141 subsystem_cfg = GNUNET_CONFIGURATION_create (); 1087 subsystem_cfg = GNUNET_CONFIGURATION_create ();
1142 if ( (GNUNET_YES == 1088 if ((GNUNET_YES == GNUNET_DISK_file_test (subsystem_cfg_file)) &&
1143 GNUNET_DISK_file_test (subsystem_cfg_file)) && 1089 (GNUNET_OK !=
1144 (GNUNET_OK != 1090 GNUNET_CONFIGURATION_parse (subsystem_cfg, subsystem_cfg_file)))
1145 GNUNET_CONFIGURATION_parse (subsystem_cfg,
1146 subsystem_cfg_file)) )
1147 { 1091 {
1148 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1092 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1149 _("Failed to parse subsystem identity configuration file `%s'\n"), 1093 _ (
1094 "Failed to parse subsystem identity configuration file `%s'\n"),
1150 subsystem_cfg_file); 1095 subsystem_cfg_file);
1151 GNUNET_SCHEDULER_shutdown (); 1096 GNUNET_SCHEDULER_shutdown ();
1152 return; 1097 return;
1153 } 1098 }
1154 stats = GNUNET_STATISTICS_create ("identity", cfg); 1099 stats = GNUNET_STATISTICS_create ("identity", cfg);
1155 if (GNUNET_OK != 1100 if (GNUNET_OK != GNUNET_DISK_directory_create (ego_directory))
1156 GNUNET_DISK_directory_create (ego_directory))
1157 { 1101 {
1158 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1102 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1159 _("Failed to create directory `%s' for storing egos\n"), 1103 _ ("Failed to create directory `%s' for storing egos\n"),
1160 ego_directory); 1104 ego_directory);
1161 } 1105 }
1162 GNUNET_DISK_directory_scan (ego_directory, 1106 GNUNET_DISK_directory_scan (ego_directory, &process_ego_file, NULL);
1163 &process_ego_file, 1107 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1164 NULL);
1165 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
1166 NULL);
1167} 1108}
1168 1109
1169 1110
1170/** 1111/**
1171 * Define "main" method using service macro. 1112 * Define "main" method using service macro.
1172 */ 1113 */
1173GNUNET_SERVICE_MAIN 1114GNUNET_SERVICE_MAIN (
1174("identity", 1115 "identity",
1175 GNUNET_SERVICE_OPTION_NONE, 1116 GNUNET_SERVICE_OPTION_NONE,
1176 &run, 1117 &run,
1177 &client_connect_cb, 1118 &client_connect_cb,
1178 &client_disconnect_cb, 1119 &client_disconnect_cb,
1179 NULL, 1120 NULL,
1180 GNUNET_MQ_hd_fixed_size (start_message, 1121 GNUNET_MQ_hd_fixed_size (start_message,
1181 GNUNET_MESSAGE_TYPE_IDENTITY_START, 1122 GNUNET_MESSAGE_TYPE_IDENTITY_START,
1182 struct GNUNET_MessageHeader, 1123 struct GNUNET_MessageHeader,
1183 NULL), 1124 NULL),
1184 GNUNET_MQ_hd_var_size (lookup_message, 1125 GNUNET_MQ_hd_var_size (lookup_message,
1185 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP, 1126 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP,
1186 struct LookupMessage, 1127 struct LookupMessage,
1187 NULL), 1128 NULL),
1188 GNUNET_MQ_hd_var_size (lookup_by_suffix_message, 1129 GNUNET_MQ_hd_var_size (lookup_by_suffix_message,
1189 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX, 1130 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX,
1190 struct LookupMessage, 1131 struct LookupMessage,
1191 NULL), 1132 NULL),
1192 GNUNET_MQ_hd_var_size (get_default_message, 1133 GNUNET_MQ_hd_var_size (get_default_message,
1193 GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT, 1134 GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT,
1194 struct GetDefaultMessage, 1135 struct GetDefaultMessage,
1195 NULL), 1136 NULL),
1196 GNUNET_MQ_hd_var_size (set_default_message, 1137 GNUNET_MQ_hd_var_size (set_default_message,
1197 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, 1138 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
1198 struct SetDefaultMessage, 1139 struct SetDefaultMessage,
1199 NULL), 1140 NULL),
1200 GNUNET_MQ_hd_var_size (create_message, 1141 GNUNET_MQ_hd_var_size (create_message,
1201 GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, 1142 GNUNET_MESSAGE_TYPE_IDENTITY_CREATE,
1202 struct CreateRequestMessage, 1143 struct CreateRequestMessage,
1203 NULL), 1144 NULL),
1204 GNUNET_MQ_hd_var_size (rename_message, 1145 GNUNET_MQ_hd_var_size (rename_message,
1205 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME, 1146 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME,
1206 struct RenameMessage, 1147 struct RenameMessage,
1207 NULL), 1148 NULL),
1208 GNUNET_MQ_hd_var_size (delete_message, 1149 GNUNET_MQ_hd_var_size (delete_message,
1209 GNUNET_MESSAGE_TYPE_IDENTITY_DELETE, 1150 GNUNET_MESSAGE_TYPE_IDENTITY_DELETE,
1210 struct DeleteMessage, 1151 struct DeleteMessage,
1211 NULL), 1152 NULL),
1212 GNUNET_MQ_handler_end()); 1153 GNUNET_MQ_handler_end ());
1213
1214 1154
1215 1155
1216/* end of gnunet-service-identity.c */ 1156/* end of gnunet-service-identity.c */