diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2017-09-15 18:53:10 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2017-09-15 18:53:10 +0200 |
commit | 9e6994a55e64aaf7b45fdad7277c27bf30e3c0f3 (patch) | |
tree | a214a625a9fcaeacf219f2a0072fe318b5462009 /src/identity-provider/identity_provider_api.c | |
parent | 41315cebe1d0a074445f28d915d7d038dea80465 (diff) | |
download | gnunet-9e6994a55e64aaf7b45fdad7277c27bf30e3c0f3.tar.gz gnunet-9e6994a55e64aaf7b45fdad7277c27bf30e3c0f3.zip |
- Add attribute store API to IdP service
Diffstat (limited to 'src/identity-provider/identity_provider_api.c')
-rw-r--r-- | src/identity-provider/identity_provider_api.c | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/src/identity-provider/identity_provider_api.c b/src/identity-provider/identity_provider_api.c index 9a3304334..bbc2bb70a 100644 --- a/src/identity-provider/identity_provider_api.c +++ b/src/identity-provider/identity_provider_api.c | |||
@@ -75,6 +75,11 @@ struct GNUNET_IDENTITY_PROVIDER_Operation | |||
75 | GNUNET_IDENTITY_PROVIDER_IssueCallback iss_cb; | 75 | GNUNET_IDENTITY_PROVIDER_IssueCallback iss_cb; |
76 | 76 | ||
77 | /** | 77 | /** |
78 | * Continuation to invoke after attribute store call | ||
79 | */ | ||
80 | GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus as_cb; | ||
81 | |||
82 | /** | ||
78 | * Envelope with the message for this queue entry. | 83 | * Envelope with the message for this queue entry. |
79 | */ | 84 | */ |
80 | struct GNUNET_MQ_Envelope *env; | 85 | struct GNUNET_MQ_Envelope *env; |
@@ -355,6 +360,53 @@ handle_result (void *cls, | |||
355 | 360 | ||
356 | } | 361 | } |
357 | 362 | ||
363 | |||
364 | |||
365 | /** | ||
366 | * Handle an incoming message of type | ||
367 | * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE | ||
368 | * | ||
369 | * @param cls | ||
370 | * @param msg the message we received | ||
371 | */ | ||
372 | static void | ||
373 | handle_attribute_store_response (void *cls, | ||
374 | const struct AttributeStoreResponseMessage *msg) | ||
375 | { | ||
376 | struct GNUNET_IDENTITY_PROVIDER_Handle *h = cls; | ||
377 | struct GNUNET_IDENTITY_PROVIDER_Operation *op; | ||
378 | uint32_t r_id = ntohl (msg->id); | ||
379 | int res; | ||
380 | const char *emsg; | ||
381 | |||
382 | for (op = h->op_head; NULL != op; op = op->next) | ||
383 | if (op->r_id == r_id) | ||
384 | break; | ||
385 | if (NULL == op) | ||
386 | return; | ||
387 | |||
388 | res = ntohl (msg->op_result); | ||
389 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
390 | "Received ATTRIBUTE_STORE_RESPONSE with result %d\n", | ||
391 | res); | ||
392 | |||
393 | /* TODO: add actual error message to response... */ | ||
394 | if (GNUNET_SYSERR == res) | ||
395 | emsg = _("failed to store record\n"); | ||
396 | else | ||
397 | emsg = NULL; | ||
398 | if (NULL != op->as_cb) | ||
399 | op->as_cb (op->cls, | ||
400 | res, | ||
401 | emsg); | ||
402 | GNUNET_CONTAINER_DLL_remove (h->op_head, | ||
403 | h->op_tail, | ||
404 | op); | ||
405 | GNUNET_free (op); | ||
406 | |||
407 | } | ||
408 | |||
409 | |||
358 | /** | 410 | /** |
359 | * Try again to connect to the service. | 411 | * Try again to connect to the service. |
360 | * | 412 | * |
@@ -364,6 +416,10 @@ static void | |||
364 | reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h) | 416 | reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h) |
365 | { | 417 | { |
366 | struct GNUNET_MQ_MessageHandler handlers[] = { | 418 | struct GNUNET_MQ_MessageHandler handlers[] = { |
419 | GNUNET_MQ_hd_fixed_size (attribute_store_response, | ||
420 | GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE_RESPONSE, | ||
421 | struct AttributeStoreResponseMessage, | ||
422 | h), | ||
367 | GNUNET_MQ_hd_var_size (result, | 423 | GNUNET_MQ_hd_var_size (result, |
368 | GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ISSUE_RESULT, | 424 | GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ISSUE_RESULT, |
369 | struct IssueResultMessage, | 425 | struct IssueResultMessage, |
@@ -372,6 +428,7 @@ reconnect (struct GNUNET_IDENTITY_PROVIDER_Handle *h) | |||
372 | GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_EXCHANGE_RESULT, | 428 | GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_EXCHANGE_RESULT, |
373 | struct ExchangeResultMessage, | 429 | struct ExchangeResultMessage, |
374 | h), | 430 | h), |
431 | |||
375 | GNUNET_MQ_handler_end () | 432 | GNUNET_MQ_handler_end () |
376 | }; | 433 | }; |
377 | struct GNUNET_IDENTITY_PROVIDER_Operation *op; | 434 | struct GNUNET_IDENTITY_PROVIDER_Operation *op; |
@@ -645,6 +702,65 @@ GNUNET_IDENTITY_PROVIDER_ticket_destroy(struct GNUNET_IDENTITY_PROVIDER_Ticket * | |||
645 | GNUNET_free (ticket); | 702 | GNUNET_free (ticket); |
646 | } | 703 | } |
647 | 704 | ||
705 | /** | ||
706 | * Store an attribute. If the attribute is already present, | ||
707 | * it is replaced with the new attribute. | ||
708 | * | ||
709 | * @param h handle to the identity provider | ||
710 | * @param pkey private key of the identity | ||
711 | * @param name the attribute name | ||
712 | * @param value the attribute value | ||
713 | * @param cont continuation to call when done | ||
714 | * @param cont_cls closure for @a cont | ||
715 | * @return handle to abort the request | ||
716 | */ | ||
717 | struct GNUNET_IDENTITY_PROVIDER_Operation * | ||
718 | GNUNET_IDENTITY_PROVIDER_attribute_store (struct GNUNET_IDENTITY_PROVIDER_Handle *h, | ||
719 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | ||
720 | const char* name, | ||
721 | const struct GNUNET_IDENTITY_PROVIDER_Attribute *value, | ||
722 | GNUNET_IDENTITY_PROVIDER_ContinuationWithStatus cont, | ||
723 | void *cont_cls) | ||
724 | { | ||
725 | struct GNUNET_IDENTITY_PROVIDER_Operation *op; | ||
726 | struct AttributeStoreMessage *sam; | ||
727 | size_t name_len; | ||
728 | char *name_tmp; | ||
729 | char *attr_ser; | ||
730 | |||
731 | |||
732 | name_len = strlen (name) + 1; | ||
733 | if (name_len >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct AttributeStoreMessage)) | ||
734 | { | ||
735 | GNUNET_break (0); | ||
736 | return NULL; | ||
737 | } | ||
738 | op = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_Operation); | ||
739 | op->h = h; | ||
740 | op->as_cb = cont; | ||
741 | op->cls = cont_cls; | ||
742 | op->r_id = h->r_id_gen++; | ||
743 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, | ||
744 | h->op_tail, | ||
745 | op); | ||
746 | op->env = GNUNET_MQ_msg_extra (sam, | ||
747 | name_len + value->data_size, | ||
748 | GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ATTRIBUTE_STORE); | ||
749 | sam->identity = *pkey; | ||
750 | sam->id = htonl (op->r_id); | ||
751 | sam->attr_value_len = htons (value->data_size); | ||
752 | sam->name_len = htons (name_len); | ||
753 | name_tmp = (char *) &sam[1]; | ||
754 | GNUNET_memcpy (name_tmp, name, name_len); | ||
755 | attr_ser = &name_tmp[name_len]; | ||
756 | GNUNET_memcpy (attr_ser, value->data, value->data_size); | ||
757 | if (NULL != h->mq) | ||
758 | GNUNET_MQ_send_copy (h->mq, | ||
759 | op->env); | ||
760 | return op; | ||
761 | |||
762 | } | ||
763 | |||
648 | 764 | ||
649 | 765 | ||
650 | 766 | ||