donau_service.h (35388B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2023 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Affero General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. 12 13 You should have received a copy of the GNU Affero General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file include/donau_service.h 18 * @brief C interface of libdonau, a C library to use donau's HTTP API 19 * @author Sree Harsha Totakura <sreeharsha@totakura.in> 20 * @author Christian Grothoff 21 * @author Özgür Kesim 22 * @author Lukas Matyja 23 */ 24 #ifndef _DONAU_SERVICE_H 25 #define _DONAU_SERVICE_H 26 27 #include <jansson.h> 28 #include <taler/taler_util.h> 29 #include "donau_util.h" 30 #include <taler/taler_error_codes.h> 31 #include <gnunet/gnunet_curl_lib.h> 32 33 34 /* ********************* /keys *********************** */ 35 36 37 /** 38 * @brief Donau's statement signing public key 39 */ 40 struct DONAU_SigningPublicKeyAndValidity 41 { 42 /** 43 * The signing public key 44 */ 45 struct DONAU_DonauPublicKeyP key; 46 47 /** 48 * Start time of the validity period for this key. 49 */ 50 struct GNUNET_TIME_Timestamp valid_from; 51 52 /** 53 * The donau will sign messages with this key between @e start and this time. 54 */ 55 struct GNUNET_TIME_Timestamp expire_sign; 56 57 }; 58 59 /** 60 * @brief Public information about a donau's donation unit signing key 61 */ 62 struct DONAU_DonationUnitInformation 63 { 64 /** 65 * The public key 66 */ 67 struct DONAU_DonationUnitPublicKey key; 68 69 /** 70 * amount of the donation 71 */ 72 struct TALER_Amount value; 73 74 /** 75 * Year of validity 76 */ 77 uint64_t year; 78 79 /** 80 * Set to true if the private donation unit key has been 81 * lost by the donau and thus the key cannot be 82 * used for issuing receipts at this time. 83 */ 84 bool lost; 85 }; 86 87 88 /** 89 * @brief Information about keys from the donau. 90 */ 91 struct DONAU_Keys 92 { 93 94 /** 95 * Array of the donau's online signing keys. 96 */ 97 struct DONAU_SigningPublicKeyAndValidity *sign_keys; 98 99 /** 100 * Array of the donau's donation unit keys. 101 */ 102 struct DONAU_DonationUnitInformation *donation_unit_keys; 103 104 /** 105 * Supported protocol version by the donau. 106 * String in the format current:revision:age using the 107 * semantics of GNU libtool. See 108 * https://www.gnu.org/software/libtool/manual/html_node/Versioning.html#Versioning 109 */ 110 char *version; 111 112 /** 113 * Financial domain. 114 */ 115 char *domain; 116 117 /** 118 * Supported currency of the donau. 119 */ 120 char *currency; 121 122 /** 123 * What is the base URL of the donau that returned 124 * these keys? 125 */ 126 char *donau_url; 127 128 /** 129 * Specifies how an amount's fractional digits should be rendered. 130 * More details in DD51. 131 */ 132 struct TALER_CurrencySpecification currency_specification; 133 134 /** 135 * Length of the @e sign_keys array (number of valid entries). 136 */ 137 unsigned int num_sign_keys; 138 139 /** 140 * Length of the @e donation_unit_keys array. 141 */ 142 unsigned int num_donation_unit_keys; 143 144 /** 145 * Actual length of the @e donation_unit_keys array (size of allocation). 146 */ 147 unsigned int donation_unit_keys_size; 148 149 /** 150 * Reference counter for this structure. 151 * Freed when it reaches 0. 152 */ 153 unsigned int rc; 154 155 }; 156 157 158 /** 159 * How compatible are the protocol version of the donau and this 160 * client? The bits (1,2,4) can be used to test if the donau's 161 * version is incompatible, older or newer respectively. 162 */ 163 enum DONAU_VersionCompatibility 164 { 165 166 /** 167 * The donau runs exactly the same protocol version. 168 */ 169 DONAU_VC_MATCH = 0, 170 171 /** 172 * The donau is too old or too new to be compatible with this 173 * implementation (bit) 174 */ 175 DONAU_VC_INCOMPATIBLE = 1, 176 177 /** 178 * The donau is older than this implementation (bit) 179 */ 180 DONAU_VC_OLDER = 2, 181 182 /** 183 * The donau is too old to be compatible with 184 * this implementation. 185 */ 186 DONAU_VC_INCOMPATIBLE_OUTDATED 187 = DONAU_VC_INCOMPATIBLE 188 | DONAU_VC_OLDER, 189 190 /** 191 * The donau is more recent than this implementation (bit). 192 */ 193 DONAU_VC_NEWER = 4, 194 195 /** 196 * The donau is too recent for this implementation. 197 */ 198 DONAU_VC_INCOMPATIBLE_NEWER 199 = DONAU_VC_INCOMPATIBLE 200 | DONAU_VC_NEWER, 201 202 /** 203 * We could not even parse the version data. 204 */ 205 DONAU_VC_PROTOCOL_ERROR = 8 206 207 }; 208 209 210 /** 211 * General information about the HTTP response we obtained 212 * from the donau for a request. 213 */ 214 struct DONAU_HttpResponse 215 { 216 217 /** 218 * The complete JSON reply. NULL if we failed to parse the 219 * reply (too big, invalid JSON). 220 */ 221 const json_t *reply; 222 223 /** 224 * Set to the human-readable 'hint' that is optionally 225 * provided by the donau together with errors. NULL 226 * if no hint was provided or if there was no error. 227 */ 228 const char *hint; 229 230 /** 231 * HTTP status code for the response. 0 if the 232 * HTTP request failed and we did not get any answer, or 233 * if the answer was invalid and we set @a ec to a 234 * client-side error code. 235 */ 236 unsigned int http_status; 237 238 /** 239 * Taler error code. #TALER_EC_NONE if everything was 240 * OK. Usually set to the "code" field of an error 241 * response, but may be set to values created at the 242 * client side, for example when the response was 243 * not in JSON format or was otherwise ill-formed. 244 */ 245 enum TALER_ErrorCode ec; 246 247 }; 248 249 250 /** 251 * Response from /keys. 252 */ 253 struct DONAU_KeysResponse 254 { 255 /** 256 * HTTP response dataclosure 257 */ 258 struct DONAU_HttpResponse hr; 259 260 /** 261 * Details depending on the HTTP status code. 262 */ 263 union 264 { 265 266 /** 267 * Details on #MHD_HTTP_OK. 268 */ 269 struct 270 { 271 /** 272 * Information about the various keys used by the donau. 273 */ 274 const struct DONAU_Keys *keys; 275 276 /** 277 * Protocol compatibility information 278 */ 279 enum DONAU_VersionCompatibility compat; 280 } ok; 281 } details; 282 283 }; 284 285 286 /** 287 * Function called with information about 288 * a particular donau and what keys the donau is using. 289 * The ownership over the @a keys object is passed to 290 * the callee, thus it is given explicitly and not 291 * (only) via @a kr. 292 * 293 * @param cls closure 294 * @param kr response from /keys 295 * @param[in] keys keys object passed to callback with 296 * reference counter of 1. Must be freed by callee 297 * using #DONAU_keys_decref(). NULL on failure. 298 */ 299 typedef void 300 (*DONAU_GetKeysCallback) ( 301 void *cls, 302 const struct DONAU_KeysResponse *kr, 303 struct DONAU_Keys *keys); 304 305 306 /** 307 * @brief Handle for a GET /keys request. 308 */ 309 struct DONAU_GetKeysHandle; 310 311 312 /** 313 * Fetch the main /keys resources from an donau. Does an incremental 314 * fetch if @a last_keys is given. The obtained information will be passed to 315 * the @a cert_cb (possibly after first merging it with @a last_keys to 316 * produce a full picture; expired keys will be removed from @a 317 * last_keys if there are any). 318 * 319 * @param ctx the context 320 * @param url HTTP base URL for the donau 321 * @param cert_cb function to call with the donau's certification information, 322 * possibly called repeatedly if the information changes 323 * @param cert_cb_cls closure for @a cert_cb 324 * @return the donau handle; NULL upon error 325 */ 326 struct DONAU_GetKeysHandle * 327 DONAU_get_keys ( 328 struct GNUNET_CURL_Context *ctx, 329 const char *url, 330 DONAU_GetKeysCallback cert_cb, 331 void *cert_cb_cls); 332 333 334 /** 335 * Serialize the latest data from @a keys to be persisted 336 * (for example, to be used as @a last_keys later). 337 * 338 * @param kd the key data to serialize 339 * @return NULL on error; otherwise JSON object owned by the caller 340 */ 341 json_t * 342 DONAU_keys_to_json (const struct DONAU_Keys *kd); 343 344 345 /** 346 * Deserialize keys data stored in @a j. 347 * 348 * @param j JSON keys data previously returned from #DONAU_keys_to_json() 349 * @return NULL on error (i.e. invalid JSON); otherwise 350 * keys object with reference counter 1 owned by the caller 351 */ 352 struct DONAU_Keys * 353 DONAU_keys_from_json (const json_t *j); 354 355 356 /** 357 * Cancel GET /keys operation. 358 * 359 * @param[in] gkh the GET /keys handle 360 */ 361 void 362 DONAU_get_keys_cancel (struct DONAU_GetKeysHandle *gkh); 363 364 365 /** 366 * Increment reference counter for @a keys 367 * 368 * @param[in,out] keys object to increment reference counter for 369 * @return keys, with incremented reference counter 370 */ 371 struct DONAU_Keys * 372 DONAU_keys_incref (struct DONAU_Keys *keys); 373 374 375 /** 376 * Decrement reference counter for @a keys. 377 * Frees @a keys if reference counter becomes zero. 378 * 379 * @param[in,out] keys object to decrement reference counter for 380 */ 381 void 382 DONAU_keys_decref (struct DONAU_Keys *keys); 383 384 /** 385 * Obtain the donation unit key details from the donau. 386 * 387 * @param keys the donau's key set 388 * @param pk public key of the donation unit to lookup 389 * @return details about the given donation unit key, NULL if the key is not 390 * found 391 */ 392 const struct DONAU_DonationUnitInformation * 393 DONAU_get_donation_unit_key ( 394 const struct DONAU_Keys *keys, 395 const struct DONAU_DonationUnitPublicKey *pk); 396 397 398 /** 399 * Compute the salted donor tax-id hash (SHA-512). 400 * 401 * @param donor_tax_id cleartext donor tax id (ASCII/UTF-8) 402 * @param salt ASCII/UTF-8 salt 403 * @param[out] out_hash buffer of size 512/8 bytes 404 * @return true on success, false on invalid inputs 405 */ 406 bool 407 DONAU_compute_salted_tax_id_hash (const char *donor_tax_id, 408 const char *salt, 409 unsigned char out_hash[512 / 8]); 410 411 412 /** 413 * Greedily build a multiset of donation-unit public keys that sums EXACTLY to 414 * @a requested_amount, using donation units from @a keys for the given @a year. 415 * 416 * @param keys Donau keys (must match requested_amount currency) 417 * @param requested_amount target amount 418 * @param year only consider donation units for this year 419 * @param[out] out_keys array of selected public keys (owned by caller) 420 * @param[out] out_len length of @a out_keys 421 * @return #GNUNET_OK on exact match; 422 * #GNUNET_NO if exact match not possible; 423 * #GNUNET_SYSERR on invalid input/currency mismatch. 424 */ 425 enum GNUNET_GenericReturnValue 426 DONAU_select_donation_unit_keys_for_amount ( 427 const struct DONAU_Keys *keys, 428 const struct TALER_Amount *requested_amount, 429 uint64_t year, 430 struct DONAU_DonationUnitPublicKey **out_keys, 431 uint32_t *out_len); 432 433 434 /** 435 * Obtain the donation unit key details from the donau. 436 * 437 * @param keys the donau's key set 438 * @param hc hash of the public key of the donation unit to lookup 439 * @return details about the given donation unit key, returns NULL 440 * if the key is not available or deprecated. 441 */ 442 const struct DONAU_DonationUnitInformation * 443 DONAU_get_donation_unit_key_by_hash ( 444 const struct DONAU_Keys *keys, 445 const struct DONAU_DonationUnitHashP *hc); 446 447 448 /** 449 * Obtain the donation amount for the given array of #DONAU_BlindedUniqueDonorIdentifierKeyPair 450 * 451 * @param keys the donau's key set 452 * @param bkps array of blinded unique donor identifiers 453 * @param num_bkps length of the @a bkps array 454 * @param year year of the donation 455 * @param[out] sum_out result amount (initialized to zero in @a keys->currency) 456 * @return #GNUNET_OK on success; 457 * #GNUNET_NO on invalid input, duplication, year mismatch; 458 * #GNUNET_SYSERR on math errors. 459 */ 460 enum GNUNET_GenericReturnValue 461 DONAU_get_donation_amount_from_bkps ( 462 const struct DONAU_Keys *keys, 463 const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkps, 464 size_t num_bkps, 465 uint64_t year, 466 struct TALER_Amount *sum_out); 467 468 469 /** 470 * Get confirmation that the given array of the #DONAU_BlindedUniqueDonorIdentifierKeyPair 471 * does not contain duplicates. 472 * 473 * @return #GNUNET_OK if the @a bkps array does not contain duplicates 474 */ 475 bool 476 DONAU_check_bkps_duplication ( 477 const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkps, 478 const size_t num_bkps 479 ); 480 481 482 /** 483 * Obtain meta data about an donau (online) signing 484 * key. 485 * 486 * @param keys from where to obtain the meta data 487 * @param donau_pub public key to lookup 488 * @return NULL on error (@a donau_pub not known) 489 */ 490 const struct DONAU_SigningPublicKeyAndValidity * 491 DONAU_get_signing_key_info ( 492 const struct DONAU_Keys *keys, 493 const struct DONAU_DonauPublicKeyP *donau_pub); 494 495 496 /* ********************* POST / issue receipt *********************** */ 497 498 499 /** 500 * @brief A Batch Submit Handle 501 */ 502 struct DONAU_BatchIssueReceiptHandle; 503 504 /** 505 * Structure with information about a batch 506 * of issue receipts. 507 */ 508 struct DONAU_BatchIssueResponse 509 { 510 /** 511 * HTTP response data 512 */ 513 struct DONAU_HttpResponse hr; 514 515 union 516 { 517 518 /** 519 * Information returned if the HTTP status is 520 * #MHD_HTTP_OK. 521 */ 522 struct 523 { 524 525 /** 526 * Blind signature provided by the donau 527 */ 528 struct DONAU_BlindedDonationUnitSignature *blinded_sigs; 529 530 /** 531 * Number of blinded signatures in @a blinded_sigs. 532 */ 533 size_t num_blinded_sigs; 534 535 /** 536 * total issued amount over all donation receipts of a donation specified 537 * by the request (confirmation). 538 */ 539 struct TALER_Amount issued_amount; 540 541 } ok; 542 543 struct 544 { 545 /* FIXME: returning full details is not implemented */ 546 } conflict; 547 548 } details; 549 }; 550 551 552 /** 553 * Callbacks of this type are used to serve the result of submitting a 554 * permission request to a donau. 555 * 556 * @param cls closure 557 * @param dr response details 558 */ 559 typedef void 560 (*DONAU_BatchIssueReceiptsCallback) ( 561 void *cls, 562 const struct DONAU_BatchIssueResponse*dr); 563 564 565 /** 566 * Submit a batch of issue receipts to the donau and get the 567 * donau's response. This API is typically used by a charity. Note that 568 * while we return the response verbatim to the caller for further processing, 569 * we do already verify that the response is well-formed (i.e. that signatures 570 * included in the response are all valid). If the donau's reply is not 571 * well-formed, we return an HTTP status code of zero to @a cb. 572 * 573 * We also verify that the signature of the charity is valid for this 574 * request. Also, the donau must be ready to operate (i.e. have 575 * finished processing the /keys reply). If either check fails, we do 576 * NOT initiate the receipts with the donau and instead return NULL. 577 * 578 * @param ctx curl context 579 * @param url donau base URL 580 * @param charity_priv private key of the charity 581 * @param charity_id unique (row ID) of the charity at the DONAU 582 * @param year donation year for which receipts are issued 583 * @param num_bkp length of the @a bkp array 584 * @param bkp array with details about the blinded donation envelopes 585 * @param cb the callback to call when a reply for this request is available 586 * @param cb_cls closure for the above callback 587 * @return a handle for this request; NULL if the inputs are invalid (i.e. 588 * signatures fail to verify). In this case, the callback is not called. 589 */ 590 struct DONAU_BatchIssueReceiptHandle * 591 DONAU_charity_issue_receipt ( 592 struct GNUNET_CURL_Context *ctx, 593 const char *url, 594 const struct DONAU_CharityPrivateKeyP *charity_priv, 595 uint64_t charity_id, 596 uint64_t year, 597 size_t num_bkp, 598 const struct DONAU_BlindedUniqueDonorIdentifierKeyPair *bkp, 599 DONAU_BatchIssueReceiptsCallback cb, 600 void *cb_cls); 601 602 /** 603 * Cancel a batch issue receipt request. This function cannot be used 604 * on a request handle if a response is already served for it. 605 * 606 * @param[in] birh the issue receipt request handle 607 */ 608 void 609 DONAU_charity_issue_receipt_cancel ( 610 struct DONAU_BatchIssueReceiptHandle *birh); 611 612 /** 613 * unblinded donation unit signature from Donau 614 */ 615 struct TALER_DonationUnitSignature 616 { 617 /** 618 * The unblinded signature 619 */ 620 struct TALER_DenominationSignature sig; 621 622 }; 623 624 625 /* ********************* POST / submit receipts *********************** */ 626 627 628 /** 629 * @brief A Batch Submit receipts Handle 630 */ 631 struct DONAU_DonorReceiptsToStatementHandle; 632 633 634 /** 635 * Structure with information about a batch 636 * operation's result. 637 */ 638 struct DONAU_DonorReceiptsToStatementResult 639 { 640 /** 641 * HTTP response data 642 */ 643 struct DONAU_HttpResponse hr; 644 645 }; 646 647 648 /** 649 * Callbacks of this type are used to serve the result of submitting a 650 * permission request to a donau. 651 * 652 * @param cls closure 653 * @param dr response details 654 */ 655 typedef void 656 (*DONAU_DonorReceiptsToStatementResultCallback) ( 657 void *cls, 658 const struct DONAU_DonorReceiptsToStatementResult *dr); 659 660 661 /** 662 * Submit a batch of receipts to the donau and get the 663 * donau's response. This API is typically used by a donor. Note that 664 * while we return the response verbatim to the caller for further processing, 665 * we do already verify that the response is well-formed (i.e. that signatures 666 * included in the response are all valid). If the donau's reply is not 667 * well-formed, we return an HTTP status code of zero to @a cb. 668 * 669 * We also verify that the signature of the charity is valid for this 670 * request. Also, the @a donau must be ready to operate (i.e. have 671 * finished processing the /keys reply). If either check fails, we do 672 * NOT initiate the receipts with the donau and instead return NULL. 673 * 674 * @param ctx curl context 675 * @param url donau base URL 676 * @param num_drs length of the @a drs array 677 * @param drs array with details about the donation receipts 678 * @param year corresponding year 679 * @param h_donor_tax_id salted and hashed tax id 680 * @param cb the callback to call when a reply for this request is available 681 * @param cls closure for the above callback 682 * @return a handle for this request; NULL if the inputs are invalid (i.e. 683 * signatures fail to verify). In this case, the callback is not called. 684 */ 685 struct DONAU_DonorReceiptsToStatementHandle * 686 DONAU_donor_receipts_to_statement ( 687 struct GNUNET_CURL_Context *ctx, 688 const char *url, 689 const size_t num_drs, 690 const struct DONAU_DonationReceipt drs[num_drs], 691 const uint64_t year, 692 const struct DONAU_HashDonorTaxId *h_donor_tax_id, 693 DONAU_DonorReceiptsToStatementResultCallback cb, 694 void *cls); 695 696 /** 697 * Cancel a batch permission request. This function cannot be used 698 * on a request handle if a response is already served for it. 699 * 700 * @param[in] drsh the Batch Submit receipts handle 701 */ 702 void 703 DONAU_donor_receipts_to_statement_cancel ( 704 struct DONAU_DonorReceiptsToStatementHandle *drsh); 705 706 707 /* ********************* GET /donation-statement *********************** */ 708 709 710 /** 711 * @brief A get donation statement Handle 712 */ 713 struct DONAU_DonationStatementGetHandle; 714 715 716 /** 717 * Structure with information about a 718 * operation's result. 719 */ 720 struct DONAU_DonationStatementResponse 721 { 722 /** 723 * HTTP response data 724 */ 725 struct DONAU_HttpResponse hr; 726 727 union 728 { 729 730 /** 731 * Information returned if the HTTP status is 732 * #MHD_HTTP_OK. 733 */ 734 struct 735 { 736 /** 737 * total amount of the donation statement for the requested year 738 */ 739 struct TALER_Amount total_amount; 740 741 /** 742 * The donation statement for a requested year. Signature over the total amount, 743 * the year, the unique identifier hash 744 */ 745 struct DONAU_DonauSignatureP donation_statement_sig; 746 747 /** 748 * The donau public to verify the signature. 749 */ 750 struct DONAU_DonauPublicKeyP donau_pub; 751 752 } ok; 753 754 } details; 755 }; 756 757 758 /** 759 * Callbacks of this type are used to serve the result of submitting a 760 * permission request to a donau. 761 * 762 * @param cls closure 763 * @param dr response details 764 */ 765 typedef void 766 (*DONAU_GetDonationStatmentResponseCallback) ( 767 void *cls, 768 const struct DONAU_DonationStatementResponse *dr); 769 770 771 /** 772 * Get a specific donation statement from the donau. This API is typically used by a donor. 773 * Note that while we return the response verbatim to the caller for further processing, 774 * we do already verify that the response is well-formed (i.e. that signatures 775 * included in the response are all valid). If the donau's reply is not 776 * well-formed, we return an HTTP status code of zero to @a cb. 777 * 778 * @param ctx curl context 779 * @param url donau base URL 780 * @param year corresponding year 781 * @param h_donor_tax_id salted and hashed tax id 782 * @param cb the callback to call when a reply for this request is available 783 * @param cb_cls closure for the above callback 784 * @return a handle for this request; NULL if the inputs are invalid (i.e. 785 * signatures fail to verify). In this case, the callback is not called. 786 */ 787 struct DONAU_DonationStatementGetHandle * 788 DONAU_donation_statement_get ( 789 struct GNUNET_CURL_Context *ctx, 790 const char *url, 791 const uint64_t year, 792 const struct DONAU_HashDonorTaxId *h_donor_tax_id, 793 DONAU_GetDonationStatmentResponseCallback cb, 794 void *cb_cls); 795 796 /** 797 * Cancel a batch permission request. This function cannot be used 798 * on a request handle if a response is already served for it. 799 * 800 * @param[in] dsgh the Batch Submit receipts handle 801 */ 802 void 803 DONAU_donation_statement_get_cancel ( 804 struct DONAU_DonationStatementGetHandle *dsgh); 805 806 807 /* ********************* POST /csr batch-issue *********************** */ 808 809 810 /** 811 * @brief A /csr-batch-issue Handle 812 */ 813 struct DONAU_CsRBatchIssueHandle; 814 815 816 /** 817 * Details about a response for a CS R request. 818 */ 819 struct DONAU_CsRBatchIssueResponse 820 { 821 /** 822 * HTTP response data. 823 */ 824 struct DONAU_HttpResponse hr; 825 826 /** 827 * Details about the response. 828 */ 829 union 830 { 831 /** 832 * Details if the status is #MHD_HTTP_OK. 833 */ 834 struct 835 { 836 /** 837 * Values contributed by the donau for the 838 * respective donation receipts's batch-issue operation. 839 */ 840 struct DONAU_BatchIssueValues alg_values; 841 842 } ok; 843 844 /** 845 * Details if the status is #MHD_HTTP_GONE. 846 */ 847 struct 848 { 849 /* FIXME: returning full details is not implemented */ 850 } gone; 851 852 } details; 853 }; 854 855 856 /** 857 * Callbacks of this type are used to serve the result of submitting a 858 * CS R batch-issue request to a donau. 859 * 860 * @param cls closure 861 * @param csrr response details 862 */ 863 typedef void 864 (*DONAU_CsRBatchIssueCallback) ( 865 void *cls, 866 const struct DONAU_CsRBatchIssueResponse *csrr); 867 868 869 /** 870 * Get a CS R using a /csr-batch-issue request. 871 * 872 * @param ctx The curl context to use for the requests 873 * @param url Base-URL to the donau 874 * @param pk Which donation unit key is the /csr request for 875 * @param nonce client nonce for the request 876 * @param cb the callback to call when the final result for this request is available 877 * @param cb_cls closure for the above callback 878 * @return handle for the operation on success, NULL on error, i.e. 879 * if the inputs are invalid (i.e.donation unit key not with this donau). 880 * In this case, the callback is not called. 881 */ 882 struct DONAU_CsRBatchIssueHandle * 883 DONAU_csr_issue ( 884 struct GNUNET_CURL_Context *ctx, 885 const char *url, 886 const struct DONAU_DonationUnitPublicKey *pk, 887 const struct GNUNET_CRYPTO_CsSessionNonce *nonce, 888 DONAU_CsRBatchIssueCallback cb, 889 void *cb_cls); 890 891 892 /** 893 * 894 * Cancel a CS R batch-issue request. This function cannot be used 895 * on a request handle if a response is already served for it. 896 * 897 * @param csrh the batch-issue handle 898 */ 899 void 900 DONAU_csr_cancel ( 901 struct DONAU_CsRBatchIssueHandle *csrh); 902 903 904 /* ********************* GET /charities/ *********************** */ 905 906 /** 907 * A Charity 908 */ 909 struct DONAU_CharitySummary 910 { 911 /** 912 * charity id 913 */ 914 uint64_t charity_id; 915 916 /** 917 * charity name 918 */ 919 const char *name; 920 921 /** 922 * Max donation amount for this charitiy and year. 923 */ 924 struct TALER_Amount max_per_year; 925 926 /** 927 * Current donation amount for this charity and year. 928 */ 929 struct TALER_Amount receipts_to_date; 930 931 }; 932 933 934 /** 935 * @brief A /charities/ GET Handle 936 */ 937 struct DONAU_CharitiesGetHandle; 938 939 940 /** 941 * @brief summary of every charity 942 */ 943 struct DONAU_GetCharitiesResponse 944 { 945 946 /** 947 * High-level HTTP response details. 948 */ 949 struct DONAU_HttpResponse hr; 950 951 /** 952 * Details depending on @e hr.http_status. 953 */ 954 union 955 { 956 957 /** 958 * Information returned on success, if 959 * @e hr.http_status is #MHD_HTTP_OK 960 */ 961 struct 962 { 963 964 /** 965 * Charity status information. 966 */ 967 struct DONAU_CharitySummary *charities; 968 969 /** 970 * Length of the @e charities array. 971 */ 972 size_t num_charities; 973 974 } ok; 975 976 } details; 977 978 }; 979 980 981 /** 982 * Callbacks of this type are used to serve the result of 983 * charities status request to a donau. 984 * 985 * @param cls closure 986 * @param rs HTTP response data 987 */ 988 typedef void 989 (*DONAU_GetCharitiesResponseCallback) ( 990 void *cls, 991 const struct DONAU_GetCharitiesResponse *rs); 992 993 994 /** 995 * Submit a request to obtain the transaction history of a charity 996 * from the donau. Note that while we return the full response to the 997 * caller for further processing, we do already verify that the 998 * response is well-formed (i.e. that signatures included in the 999 * response are all valid). If the donau's reply is not well-formed, 1000 * we return an HTTP status code of zero to @a cb. 1001 * 1002 * @param ctx curl context 1003 * @param url donau base URL 1004 * @param bearer for authorization 1005 * @param cb the callback to call when a reply for this request is available 1006 * @param cb_cls closure for the above callback 1007 * @return a handle for this request; NULL if the inputs are invalid (i.e. 1008 * signatures fail to verify). In this case, the callback is not called. 1009 */ 1010 struct DONAU_CharitiesGetHandle * 1011 DONAU_charities_get ( 1012 struct GNUNET_CURL_Context *ctx, 1013 const char *url, 1014 const struct DONAU_BearerToken *bearer, 1015 DONAU_GetCharitiesResponseCallback cb, 1016 void *cb_cls); 1017 1018 1019 /** 1020 * Cancel a charity GET request. This function cannot be used 1021 * on a request handle if a response is already served for it. 1022 * 1023 * @param rgh the charity request handle 1024 */ 1025 void 1026 DONAU_charities_get_cancel ( 1027 struct DONAU_CharitiesGetHandle *rgh); 1028 1029 1030 /* ********************* GET /charities/$CHARITY_ID *********************** */ 1031 1032 /** 1033 * Information about a charity 1034 */ 1035 struct DONAU_Charity 1036 { 1037 /** 1038 * name of the charity 1039 */ 1040 const char *name; 1041 1042 /** 1043 * charity url 1044 */ 1045 const char *charity_url; 1046 1047 /** 1048 * public key of the charity 1049 */ 1050 struct DONAU_CharityPublicKeyP charity_pub; 1051 1052 /** 1053 * Max donation amount for this charitiy and @e current_year. 1054 */ 1055 struct TALER_Amount max_per_year; 1056 1057 /** 1058 * Current amount of donation receipts for @e current_year. 1059 */ 1060 struct TALER_Amount receipts_to_date; 1061 1062 /** 1063 * current year 1064 */ 1065 uint64_t current_year; 1066 1067 }; 1068 1069 1070 /** 1071 * @brief A /charities/$CHARITY_ID GET Handle 1072 */ 1073 struct DONAU_CharityGetHandle; 1074 1075 1076 /** 1077 * @brief summary of a charity 1078 */ 1079 struct DONAU_GetCharityResponse 1080 { 1081 1082 /** 1083 * High-level HTTP response details. 1084 */ 1085 struct DONAU_HttpResponse hr; 1086 1087 /** 1088 * Details depending on @e hr.http_status. 1089 */ 1090 union 1091 { 1092 1093 /** 1094 * Information returned on success, if 1095 * @e hr.http_status is #MHD_HTTP_OK 1096 */ 1097 struct 1098 { 1099 1100 /** 1101 * Charity status information. 1102 */ 1103 struct DONAU_Charity charity; 1104 1105 1106 } ok; 1107 1108 } details; 1109 1110 }; 1111 1112 1113 /** 1114 * Callbacks of this type are used to serve the result of a 1115 * charity status request to a donau. 1116 * 1117 * @param cls closure 1118 * @param rs HTTP response data 1119 */ 1120 typedef void 1121 (*DONAU_GetCharityResponseCallback) ( 1122 void *cls, 1123 const struct DONAU_GetCharityResponse *rs); 1124 1125 1126 /** 1127 * Submit a GET request to obtain the information about a single charity 1128 * from the donau. Note that while we return the full response to the 1129 * caller for further processing, we do already verify that the 1130 * response is well-formed (i.e. that signatures included in the 1131 * response are all valid). If the donau's reply is not well-formed, 1132 * we return an HTTP status code of zero to @a cb. 1133 * 1134 * @param ctx curl context 1135 * @param url donau base URL 1136 * @param id of the requested charity 1137 * @param charity_priv private key of the charity, for authorization 1138 * @param cb the callback to call when a reply for this request is available 1139 * @param cb_cls closure for the above callback 1140 * @return a handle for this request; NULL if the inputs are invalid (i.e. 1141 * signatures fail to verify). In this case, the callback is not called. 1142 */ 1143 struct DONAU_CharityGetHandle * 1144 DONAU_charity_get ( 1145 struct GNUNET_CURL_Context *ctx, 1146 const char *url, 1147 uint64_t id, 1148 const struct DONAU_CharityPrivateKeyP *charity_priv, 1149 DONAU_GetCharityResponseCallback cb, 1150 void *cb_cls); 1151 1152 1153 /** 1154 * Cancel a charity GET request. This function cannot be used 1155 * on a request handle if a response is already served for it. 1156 * 1157 * @param rgh the charity request handle 1158 */ 1159 void 1160 DONAU_charity_get_cancel ( 1161 struct DONAU_CharityGetHandle *rgh); 1162 1163 1164 /* ********************* POST /charities/ *********************** */ 1165 1166 /** 1167 * @brief A /charities Post Handle 1168 */ 1169 struct DONAU_CharityPostHandle; 1170 1171 1172 /** 1173 * @brief new charity ID Response 1174 */ 1175 struct DONAU_PostCharityResponse 1176 { 1177 1178 /** 1179 * High-level HTTP response details. 1180 */ 1181 struct DONAU_HttpResponse hr; 1182 1183 /** 1184 * Details depending on @e hr.http_status. 1185 */ 1186 union 1187 { 1188 1189 /** 1190 * Information returned on success, if 1191 * @e hr.http_status is #MHD_HTTP_CREATED 1192 */ 1193 struct 1194 { 1195 1196 /** 1197 * charity id 1198 */ 1199 uint64_t charity_id; 1200 1201 } ok; 1202 1203 } details; 1204 1205 }; 1206 1207 1208 /** 1209 * Callbacks of this type are used to serve the result of a 1210 * charity post request to a donau. 1211 * 1212 * @param cls closure 1213 * @param rs HTTP response data 1214 */ 1215 typedef void 1216 (*DONAU_PostCharityResponseCallback) ( 1217 void *cls, 1218 const struct DONAU_PostCharityResponse *rs); 1219 1220 1221 /** 1222 * Submit a POST request to add a new charity to the donau. Note that 1223 * while we return the full response to the caller for further processing, 1224 * we do already verify that the response is well-formed (i.e. that 1225 * signatures included in the response are all valid). If the donau's 1226 * reply is not well-formed, we return an HTTP status code of zero to 1227 * @a cb. 1228 * 1229 * @param ctx curl context 1230 * @param url donau base URL 1231 * @param charity_name human readable name of the charity 1232 * @param charity_url Web site of the charity 1233 * @param max_per_year max donation amount allowed for the charity per year 1234 * @param charity_pub public key of the charity 1235 * @param bearer for authorization 1236 * @param cb the callback to call when a reply for this request is available 1237 * @param cb_cls closure for the above callback 1238 * @return a handle for this request; NULL if the inputs are invalid (i.e. 1239 * signatures fail to verify). In this case, the callback is not called. 1240 */ 1241 struct DONAU_CharityPostHandle * 1242 DONAU_charity_post ( 1243 struct GNUNET_CURL_Context *ctx, 1244 const char *url, 1245 const char *charity_name, 1246 const char *charity_url, 1247 const struct TALER_Amount *max_per_year, 1248 const struct DONAU_CharityPublicKeyP *charity_pub, 1249 const struct DONAU_BearerToken *bearer, 1250 DONAU_PostCharityResponseCallback cb, 1251 void *cb_cls); 1252 1253 /** 1254 * Cancel a charity Post request. This function cannot be used 1255 * on a request handle if a response is already served for it. 1256 * 1257 * @param rgh the charity post handle 1258 */ 1259 void 1260 DONAU_charity_post_cancel ( 1261 struct DONAU_CharityPostHandle *rgh); 1262 1263 1264 /* ********************* PATCH /charities/$CHARITY_ID *********************** */ 1265 1266 1267 /** 1268 * @brief A /charities/$CHARITY_ID Patch Handle 1269 */ 1270 struct DONAU_CharityPatchHandle; 1271 1272 1273 /** 1274 * @brief charity patch response 1275 */ 1276 struct DONAU_PatchCharityResponse 1277 { 1278 1279 /** 1280 * High-level HTTP response details. 1281 */ 1282 struct DONAU_HttpResponse hr; 1283 1284 }; 1285 1286 1287 /** 1288 * Callbacks of this type are used to serve the result of a 1289 * charity post request to a donau. 1290 * 1291 * @param cls closure 1292 * @param rs HTTP response data 1293 */ 1294 typedef void 1295 (*DONAU_PatchCharityResponseCallback) ( 1296 void *cls, 1297 const struct DONAU_PatchCharityResponse *rs); 1298 1299 1300 /** 1301 * Submit a PATCH request to change data about a charity 1302 * from the donau. Note that while we return the full response to the 1303 * caller for further processing, we do already verify that the 1304 * response is well-formed (i.e. that signatures included in the 1305 * response are all valid). If the donau's reply is not well-formed, 1306 * we return an HTTP status code of zero to @a cb. 1307 * 1308 * @param ctx curl context 1309 * @param url donau base URL 1310 * @param charity_id of the charity 1311 * @param charity_name human readable name of the charity 1312 * @param charity_url Web site of the charity 1313 * @param max_per_year max donation amount allowed for the charity per year 1314 * @param charity_pub public key of the charity 1315 * @param bearer bearer token authorizing the request 1316 * @param cb the callback to call when a reply for this request is available 1317 * @param cb_cls closure for the above callback 1318 * @return a handle for this request; NULL if the inputs are invalid (i.e. 1319 * signatures fail to verify). In this case, the callback is not called. 1320 */ 1321 struct DONAU_CharityPatchHandle * 1322 DONAU_charity_patch ( 1323 struct GNUNET_CURL_Context *ctx, 1324 const char *url, 1325 const uint64_t charity_id, 1326 const char *charity_name, 1327 const char *charity_url, 1328 const struct TALER_Amount *max_per_year, 1329 const struct DONAU_CharityPublicKeyP *charity_pub, 1330 const struct DONAU_BearerToken *bearer, 1331 DONAU_PatchCharityResponseCallback cb, 1332 void *cb_cls); 1333 1334 /** 1335 * Cancel a charity Patch request. This function cannot be used 1336 * on a request handle if a response is already served for it. 1337 * 1338 * @param rgh the charity patch handle 1339 */ 1340 void 1341 DONAU_charity_patch_cancel ( 1342 struct DONAU_CharityPatchHandle *rgh); 1343 1344 1345 /* ********************* DELETE /charities/$CHARITY_ID *********************** */ 1346 1347 /** 1348 * @brief A /charities/$CHARITY_ID Delete Handle 1349 */ 1350 struct DONAU_CharityDeleteHandle; 1351 1352 1353 /** 1354 * @brief new charity ID Response 1355 */ 1356 struct DONAU_DeleteCharityResponse 1357 { 1358 1359 /** 1360 * High-level HTTP response details. 1361 */ 1362 struct DONAU_HttpResponse hr; 1363 1364 }; 1365 1366 1367 /** 1368 * Callbacks of this type are used to serve the result of a 1369 * charity post request to a donau. 1370 * 1371 * @param cls closure 1372 * @param rs HTTP response data 1373 */ 1374 typedef void 1375 (*DONAU_DeleteCharityResponseCallback) ( 1376 void *cls, 1377 const struct DONAU_DeleteCharityResponse *rs); 1378 1379 1380 /** 1381 * Submit a DELETE request to delete a charity 1382 * from the donau. Note that while we return the full response to the 1383 * caller for further processing, we do already verify that the 1384 * response is well-formed (i.e. that signatures included in the 1385 * response are all valid). If the donau's reply is not well-formed, 1386 * we return an HTTP status code of zero to @a cb. 1387 * 1388 * @param ctx curl context 1389 * @param url donau base URL 1390 * @param id of the charity 1391 * @param bearer for authorization 1392 * @param cb the callback to call when a reply for this request is available 1393 * @param cb_cls closure for the above callback 1394 * @return a handle for this request; NULL if the inputs are invalid (i.e. 1395 * signatures fail to verify). In this case, the callback is not called. 1396 */ 1397 struct DONAU_CharityDeleteHandle * 1398 DONAU_charity_delete ( 1399 struct GNUNET_CURL_Context *ctx, 1400 const char *url, 1401 const uint64_t id, 1402 const struct DONAU_BearerToken *bearer, 1403 DONAU_DeleteCharityResponseCallback cb, 1404 void *cb_cls); 1405 1406 /** 1407 * Cancel a charity Delete request. This function cannot be used 1408 * on a request handle if a response is already served for it. 1409 * 1410 * @param rgh the charity request handle 1411 */ 1412 void 1413 DONAU_charity_delete_cancel ( 1414 struct DONAU_CharityDeleteHandle *rgh); 1415 1416 #endif