diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2017-10-06 10:04:20 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2017-10-06 10:04:20 +0200 |
commit | fc76f42d3f8df9fc88648ad052f46c7ddf518879 (patch) | |
tree | 05578c1a1e9da8c9abf6e54b7c1c8d33def41568 /src/identity-provider/identity_provider_api.c | |
parent | 407c000bf423dc07f1f12fba9b8a8bcd08886d6c (diff) | |
download | gnunet-fc76f42d3f8df9fc88648ad052f46c7ddf518879.tar.gz gnunet-fc76f42d3f8df9fc88648ad052f46c7ddf518879.zip |
-add ticket iteration
Diffstat (limited to 'src/identity-provider/identity_provider_api.c')
-rw-r--r-- | src/identity-provider/identity_provider_api.c | 293 |
1 files changed, 285 insertions, 8 deletions
diff --git a/src/identity-provider/identity_provider_api.c b/src/identity-provider/identity_provider_api.c index 371dce86d..6ef1d470e 100644 --- a/src/identity-provider/identity_provider_api.c +++ b/src/identity-provider/identity_provider_api.c | |||
@@ -108,6 +108,71 @@ struct GNUNET_IDENTITY_PROVIDER_Operation | |||
108 | }; | 108 | }; |
109 | 109 | ||
110 | /** | 110 | /** |
111 | * Handle for a ticket iterator operation | ||
112 | */ | ||
113 | struct GNUNET_IDENTITY_PROVIDER_TicketIterator | ||
114 | { | ||
115 | |||
116 | /** | ||
117 | * Kept in a DLL. | ||
118 | */ | ||
119 | struct GNUNET_IDENTITY_PROVIDER_TicketIterator *next; | ||
120 | |||
121 | /** | ||
122 | * Kept in a DLL. | ||
123 | */ | ||
124 | struct GNUNET_IDENTITY_PROVIDER_TicketIterator *prev; | ||
125 | |||
126 | /** | ||
127 | * Main handle to access the idp. | ||
128 | */ | ||
129 | struct GNUNET_IDENTITY_PROVIDER_Handle *h; | ||
130 | |||
131 | /** | ||
132 | * Function to call on completion. | ||
133 | */ | ||
134 | GNUNET_SCHEDULER_TaskCallback finish_cb; | ||
135 | |||
136 | /** | ||
137 | * Closure for @e error_cb. | ||
138 | */ | ||
139 | void *finish_cb_cls; | ||
140 | |||
141 | /** | ||
142 | * The continuation to call with the results | ||
143 | */ | ||
144 | GNUNET_IDENTITY_PROVIDER_TicketCallback tr_cb; | ||
145 | |||
146 | /** | ||
147 | * Closure for @e tr_cb. | ||
148 | */ | ||
149 | void *cls; | ||
150 | |||
151 | /** | ||
152 | * Function to call on errors. | ||
153 | */ | ||
154 | GNUNET_SCHEDULER_TaskCallback error_cb; | ||
155 | |||
156 | /** | ||
157 | * Closure for @e error_cb. | ||
158 | */ | ||
159 | void *error_cb_cls; | ||
160 | |||
161 | /** | ||
162 | * Envelope of the message to send to the service, if not yet | ||
163 | * sent. | ||
164 | */ | ||
165 | struct GNUNET_MQ_Envelope *env; | ||
166 | |||
167 | /** | ||
168 | * The operation id this zone iteration operation has | ||
169 | */ | ||
170 | uint32_t r_id; | ||
171 | |||
172 | }; | ||
173 | |||
174 | |||
175 | /** | ||
111 | * Handle for a attribute iterator operation | 176 | * Handle for a attribute iterator operation |
112 | */ | 177 | */ |
113 | struct GNUNET_IDENTITY_PROVIDER_AttributeIterator | 178 | struct GNUNET_IDENTITY_PROVIDER_AttributeIterator |
@@ -218,6 +283,17 @@ struct GNUNET_IDENTITY_PROVIDER_Handle | |||
218 | struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it_tail; | 283 | struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *it_tail; |
219 | 284 | ||
220 | /** | 285 | /** |
286 | * Head of active iterations | ||
287 | */ | ||
288 | struct GNUNET_IDENTITY_PROVIDER_TicketIterator *ticket_it_head; | ||
289 | |||
290 | /** | ||
291 | * Tail of active iterations | ||
292 | */ | ||
293 | struct GNUNET_IDENTITY_PROVIDER_TicketIterator *ticket_it_tail; | ||
294 | |||
295 | |||
296 | /** | ||
221 | * Currently pending transmission request, or NULL for none. | 297 | * Currently pending transmission request, or NULL for none. |
222 | */ | 298 | */ |
223 | struct GNUNET_CLIENT_TransmitHandle *th; | 299 | struct GNUNET_CLIENT_TransmitHandle *th; |
@@ -747,22 +823,54 @@ handle_ticket_result (void *cls, | |||
747 | { | 823 | { |
748 | struct GNUNET_IDENTITY_PROVIDER_Handle *handle = cls; | 824 | struct GNUNET_IDENTITY_PROVIDER_Handle *handle = cls; |
749 | struct GNUNET_IDENTITY_PROVIDER_Operation *op; | 825 | struct GNUNET_IDENTITY_PROVIDER_Operation *op; |
826 | struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it; | ||
750 | const struct GNUNET_IDENTITY_PROVIDER_Ticket2 *ticket; | 827 | const struct GNUNET_IDENTITY_PROVIDER_Ticket2 *ticket; |
751 | uint32_t r_id = ntohl (msg->id); | 828 | uint32_t r_id = ntohl (msg->id); |
829 | size_t msg_len; | ||
752 | 830 | ||
753 | for (op = handle->op_head; NULL != op; op = op->next) | 831 | for (op = handle->op_head; NULL != op; op = op->next) |
754 | if (op->r_id == r_id) | 832 | if (op->r_id == r_id) |
755 | break; | 833 | break; |
756 | if (NULL == op) | 834 | for (it = handle->ticket_it_head; NULL != it; it = it->next) |
835 | if (it->r_id == r_id) | ||
836 | break; | ||
837 | if ((NULL == op) && (NULL == it)) | ||
757 | return; | 838 | return; |
758 | GNUNET_CONTAINER_DLL_remove (handle->op_head, | 839 | msg_len = ntohs (msg->header.size); |
759 | handle->op_tail, | 840 | if (NULL != op) |
760 | op); | 841 | { |
761 | ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket2 *)&msg[1]; | 842 | GNUNET_CONTAINER_DLL_remove (handle->op_head, |
762 | if (NULL != op->tr_cb) | 843 | handle->op_tail, |
763 | op->tr_cb (op->cls, ticket); | 844 | op); |
764 | GNUNET_free (op); | 845 | if (msg_len == sizeof (struct TicketResultMessage)) |
846 | { | ||
847 | if (NULL != op->tr_cb) | ||
848 | op->tr_cb (op->cls, NULL); | ||
849 | } else { | ||
850 | ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket2 *)&msg[1]; | ||
851 | if (NULL != op->tr_cb) | ||
852 | op->tr_cb (op->cls, ticket); | ||
853 | } | ||
854 | GNUNET_free (op); | ||
855 | return; | ||
856 | } else if (NULL != it) { | ||
857 | GNUNET_CONTAINER_DLL_remove (handle->ticket_it_head, | ||
858 | handle->ticket_it_tail, | ||
859 | it); | ||
860 | if (msg_len == sizeof (struct TicketResultMessage)) | ||
861 | { | ||
862 | if (NULL != it->tr_cb) | ||
863 | it->finish_cb (it->finish_cb_cls); | ||
864 | } else { | ||
765 | 865 | ||
866 | ticket = (struct GNUNET_IDENTITY_PROVIDER_Ticket2 *)&msg[1]; | ||
867 | if (NULL != it->tr_cb) | ||
868 | it->tr_cb (it->cls, ticket); | ||
869 | } | ||
870 | GNUNET_free (it); | ||
871 | return; | ||
872 | } | ||
873 | GNUNET_break (0); | ||
766 | } | 874 | } |
767 | 875 | ||
768 | 876 | ||
@@ -1353,6 +1461,175 @@ GNUNET_IDENTITY_PROVIDER_rp_ticket_consume (struct GNUNET_IDENTITY_PROVIDER_Hand | |||
1353 | } | 1461 | } |
1354 | 1462 | ||
1355 | 1463 | ||
1464 | /** | ||
1465 | * Lists all tickets that have been issued to remote | ||
1466 | * identites (relying parties) | ||
1467 | * | ||
1468 | * @param h the identity provider to use | ||
1469 | * @param identity the issuing identity | ||
1470 | * @param error_cb function to call on error (i.e. disconnect), | ||
1471 | * the handle is afterwards invalid | ||
1472 | * @param error_cb_cls closure for @a error_cb | ||
1473 | * @param proc function to call on each ticket; it | ||
1474 | * will be called repeatedly with a value (if available) | ||
1475 | * @param proc_cls closure for @a proc | ||
1476 | * @param finish_cb function to call on completion | ||
1477 | * the handle is afterwards invalid | ||
1478 | * @param finish_cb_cls closure for @a finish_cb | ||
1479 | * @return an iterator handle to use for iteration | ||
1480 | */ | ||
1481 | struct GNUNET_IDENTITY_PROVIDER_TicketIterator * | ||
1482 | GNUNET_IDENTITY_PROVIDER_idp_ticket_iteration_start (struct GNUNET_IDENTITY_PROVIDER_Handle *h, | ||
1483 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | ||
1484 | GNUNET_SCHEDULER_TaskCallback error_cb, | ||
1485 | void *error_cb_cls, | ||
1486 | GNUNET_IDENTITY_PROVIDER_TicketCallback proc, | ||
1487 | void *proc_cls, | ||
1488 | GNUNET_SCHEDULER_TaskCallback finish_cb, | ||
1489 | void *finish_cb_cls) | ||
1490 | { | ||
1491 | struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it; | ||
1492 | struct GNUNET_CRYPTO_EcdsaPublicKey identity_pub; | ||
1493 | struct GNUNET_MQ_Envelope *env; | ||
1494 | struct TicketIterationStartMessage *msg; | ||
1495 | uint32_t rid; | ||
1496 | |||
1497 | GNUNET_CRYPTO_ecdsa_key_get_public (identity, | ||
1498 | &identity_pub); | ||
1499 | rid = h->r_id_gen++; | ||
1500 | it = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_TicketIterator); | ||
1501 | it->h = h; | ||
1502 | it->error_cb = error_cb; | ||
1503 | it->error_cb_cls = error_cb_cls; | ||
1504 | it->finish_cb = finish_cb; | ||
1505 | it->finish_cb_cls = finish_cb_cls; | ||
1506 | it->tr_cb = proc; | ||
1507 | it->cls = proc_cls; | ||
1508 | it->r_id = rid; | ||
1509 | GNUNET_CONTAINER_DLL_insert_tail (h->ticket_it_head, | ||
1510 | h->ticket_it_tail, | ||
1511 | it); | ||
1512 | env = GNUNET_MQ_msg (msg, | ||
1513 | GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_START); | ||
1514 | msg->id = htonl (rid); | ||
1515 | msg->identity = identity_pub; | ||
1516 | msg->is_audience = htonl (GNUNET_NO); | ||
1517 | if (NULL == h->mq) | ||
1518 | it->env = env; | ||
1519 | else | ||
1520 | GNUNET_MQ_send (h->mq, | ||
1521 | env); | ||
1522 | return it; | ||
1523 | |||
1524 | } | ||
1525 | |||
1526 | |||
1527 | /** | ||
1528 | * Lists all tickets that have been issued to remote | ||
1529 | * identites (relying parties) | ||
1530 | * | ||
1531 | * @param id the identity provider to use | ||
1532 | * @param identity the issuing identity | ||
1533 | * @param error_cb function to call on error (i.e. disconnect), | ||
1534 | * the handle is afterwards invalid | ||
1535 | * @param error_cb_cls closure for @a error_cb | ||
1536 | * @param proc function to call on each ticket; it | ||
1537 | * will be called repeatedly with a value (if available) | ||
1538 | * @param proc_cls closure for @a proc | ||
1539 | * @param finish_cb function to call on completion | ||
1540 | * the handle is afterwards invalid | ||
1541 | * @param finish_cb_cls closure for @a finish_cb | ||
1542 | * @return an iterator handle to use for iteration | ||
1543 | */ | ||
1544 | struct GNUNET_IDENTITY_PROVIDER_TicketIterator * | ||
1545 | GNUNET_IDENTITY_PROVIDER_ticket_iteration_start_rp (struct GNUNET_IDENTITY_PROVIDER_Handle *h, | ||
1546 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | ||
1547 | GNUNET_SCHEDULER_TaskCallback error_cb, | ||
1548 | void *error_cb_cls, | ||
1549 | GNUNET_IDENTITY_PROVIDER_TicketCallback proc, | ||
1550 | void *proc_cls, | ||
1551 | GNUNET_SCHEDULER_TaskCallback finish_cb, | ||
1552 | void *finish_cb_cls) | ||
1553 | { | ||
1554 | struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it; | ||
1555 | struct GNUNET_MQ_Envelope *env; | ||
1556 | struct TicketIterationStartMessage *msg; | ||
1557 | uint32_t rid; | ||
1558 | |||
1559 | rid = h->r_id_gen++; | ||
1560 | it = GNUNET_new (struct GNUNET_IDENTITY_PROVIDER_TicketIterator); | ||
1561 | it->h = h; | ||
1562 | it->error_cb = error_cb; | ||
1563 | it->error_cb_cls = error_cb_cls; | ||
1564 | it->finish_cb = finish_cb; | ||
1565 | it->finish_cb_cls = finish_cb_cls; | ||
1566 | it->tr_cb = proc; | ||
1567 | it->cls = proc_cls; | ||
1568 | it->r_id = rid; | ||
1569 | GNUNET_CONTAINER_DLL_insert_tail (h->ticket_it_head, | ||
1570 | h->ticket_it_tail, | ||
1571 | it); | ||
1572 | env = GNUNET_MQ_msg (msg, | ||
1573 | GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_START); | ||
1574 | msg->id = htonl (rid); | ||
1575 | msg->identity = *identity; | ||
1576 | msg->is_audience = htonl (GNUNET_YES); | ||
1577 | if (NULL == h->mq) | ||
1578 | it->env = env; | ||
1579 | else | ||
1580 | GNUNET_MQ_send (h->mq, | ||
1581 | env); | ||
1582 | return it; | ||
1583 | |||
1584 | |||
1585 | } | ||
1586 | |||
1587 | /** | ||
1588 | * Calls the record processor specified in #GNUNET_IDENTITY_PROVIDER_ticket_iteration_start | ||
1589 | * for the next record. | ||
1590 | * | ||
1591 | * @param it the iterator | ||
1592 | */ | ||
1593 | void | ||
1594 | GNUNET_IDENTITY_PROVIDER_ticket_iteration_next (struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it) | ||
1595 | { | ||
1596 | struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h; | ||
1597 | struct TicketIterationNextMessage *msg; | ||
1598 | struct GNUNET_MQ_Envelope *env; | ||
1599 | |||
1600 | env = GNUNET_MQ_msg (msg, | ||
1601 | GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_NEXT); | ||
1602 | msg->id = htonl (it->r_id); | ||
1603 | GNUNET_MQ_send (h->mq, | ||
1604 | env); | ||
1605 | } | ||
1606 | |||
1607 | |||
1608 | /** | ||
1609 | * Stops iteration and releases the idp handle for further calls. Must | ||
1610 | * be called on any iteration that has not yet completed prior to calling | ||
1611 | * #GNUNET_IDENTITY_PROVIDER_disconnect. | ||
1612 | * | ||
1613 | * @param it the iterator | ||
1614 | */ | ||
1615 | void | ||
1616 | GNUNET_IDENTITY_PROVIDER_ticket_iteration_stop (struct GNUNET_IDENTITY_PROVIDER_TicketIterator *it) | ||
1617 | { | ||
1618 | struct GNUNET_IDENTITY_PROVIDER_Handle *h = it->h; | ||
1619 | struct GNUNET_MQ_Envelope *env; | ||
1620 | struct TicketIterationStopMessage *msg; | ||
1621 | |||
1622 | if (NULL != h->mq) | ||
1623 | { | ||
1624 | env = GNUNET_MQ_msg (msg, | ||
1625 | GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_STOP); | ||
1626 | msg->id = htonl (it->r_id); | ||
1627 | GNUNET_MQ_send (h->mq, | ||
1628 | env); | ||
1629 | } | ||
1630 | GNUNET_free (it); | ||
1631 | } | ||
1632 | |||
1356 | 1633 | ||
1357 | 1634 | ||
1358 | /* end of identity_provider_api.c */ | 1635 | /* end of identity_provider_api.c */ |