LCOV - code coverage report
Current view: top level - lib - exchange_api_post-management-denominations-H_DENOM_PUB-revoke.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 76 0
Test Date: 2026-03-10 12:10:57 Functions: 0.0 % 4 0

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2015-2026 Taler Systems SA
       4              : 
       5              :   TALER is free software; you can redistribute it and/or modify it under the
       6              :   terms of the GNU 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 General Public License for more details.
      12              : 
      13              :   You should have received a copy of the GNU General Public License along with
      14              :   TALER; see the file COPYING.  If not, see
      15              :   <http://www.gnu.org/licenses/>
      16              : */
      17              : /**
      18              :  * @file lib/exchange_api_post-management-denominations-H_DENOM_PUB-revoke.c
      19              :  * @brief functions to revoke an exchange denomination key
      20              :  * @author Christian Grothoff
      21              :  */
      22              : #include "taler/platform.h"
      23              : #include "taler/taler_json_lib.h"
      24              : #include <gnunet/gnunet_curl_lib.h>
      25              : #include <microhttpd.h>
      26              : #include "taler/taler_exchange_service.h"
      27              : #include \
      28              :   "taler/taler-exchange/post-management-denominations-H_DENOM_PUB-revoke.h"
      29              : #include "exchange_api_curl_defaults.h"
      30              : #include "taler/taler_signatures.h"
      31              : #include "taler/taler_curl_lib.h"
      32              : 
      33              : 
      34              : /**
      35              :  * @brief Handle for a POST /management/denominations/$H_DENOM_PUB/revoke request.
      36              :  */
      37              : struct TALER_EXCHANGE_PostManagementDenominationsRevokeHandle
      38              : {
      39              : 
      40              :   /**
      41              :    * The base URL for this request.
      42              :    */
      43              :   char *base_url;
      44              : 
      45              :   /**
      46              :    * The full URL for this request, set during _start.
      47              :    */
      48              :   char *url;
      49              : 
      50              :   /**
      51              :    * Minor context that holds body and headers.
      52              :    */
      53              :   struct TALER_CURL_PostContext post_ctx;
      54              : 
      55              :   /**
      56              :    * Handle for the request.
      57              :    */
      58              :   struct GNUNET_CURL_Job *job;
      59              : 
      60              :   /**
      61              :    * Function to call with the result.
      62              :    */
      63              :   TALER_EXCHANGE_PostManagementDenominationsRevokeCallback cb;
      64              : 
      65              :   /**
      66              :    * Closure for @a cb.
      67              :    */
      68              :   TALER_EXCHANGE_POST_MANAGEMENT_DENOMINATIONS_REVOKE_RESULT_CLOSURE *cb_cls;
      69              : 
      70              :   /**
      71              :    * Reference to the execution context.
      72              :    */
      73              :   struct GNUNET_CURL_Context *ctx;
      74              : 
      75              :   /**
      76              :    * Hash of the denomination public key to revoke.
      77              :    */
      78              :   struct TALER_DenominationHashP h_denom_pub;
      79              : 
      80              :   /**
      81              :    * Signature affirming the revocation.
      82              :    */
      83              :   struct TALER_MasterSignatureP master_sig;
      84              : 
      85              : };
      86              : 
      87              : 
      88              : /**
      89              :  * Function called when we're done processing the
      90              :  * HTTP POST /management/denominations/$H_DENOM_PUB/revoke request.
      91              :  *
      92              :  * @param cls the `struct TALER_EXCHANGE_PostManagementDenominationsRevokeHandle`
      93              :  * @param response_code HTTP response code, 0 on error
      94              :  * @param response response body, NULL if not in JSON
      95              :  */
      96              : static void
      97            0 : handle_denominations_revoke_finished (void *cls,
      98              :                                       long response_code,
      99              :                                       const void *response)
     100              : {
     101            0 :   struct TALER_EXCHANGE_PostManagementDenominationsRevokeHandle *pmdrh = cls;
     102            0 :   const json_t *json = response;
     103            0 :   struct TALER_EXCHANGE_PostManagementDenominationsRevokeResponse res = {
     104            0 :     .hr.http_status = (unsigned int) response_code,
     105              :     .hr.reply = json
     106              :   };
     107              : 
     108            0 :   pmdrh->job = NULL;
     109            0 :   switch (response_code)
     110              :   {
     111            0 :   case 0:
     112              :     /* no reply */
     113            0 :     res.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
     114            0 :     res.hr.hint = "server offline?";
     115            0 :     break;
     116            0 :   case MHD_HTTP_NO_CONTENT:
     117            0 :     break;
     118            0 :   case MHD_HTTP_FORBIDDEN:
     119            0 :     res.hr.ec = TALER_JSON_get_error_code (json);
     120            0 :     res.hr.hint = TALER_JSON_get_error_hint (json);
     121            0 :     break;
     122            0 :   default:
     123              :     /* unexpected response code */
     124            0 :     GNUNET_break_op (0);
     125            0 :     res.hr.ec = TALER_JSON_get_error_code (json);
     126            0 :     res.hr.hint = TALER_JSON_get_error_hint (json);
     127            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     128              :                 "Unexpected response code %u/%d for exchange management revoke denomination\n",
     129              :                 (unsigned int) response_code,
     130              :                 (int) res.hr.ec);
     131            0 :     break;
     132              :   }
     133            0 :   if (NULL != pmdrh->cb)
     134              :   {
     135            0 :     pmdrh->cb (pmdrh->cb_cls,
     136              :                &res);
     137            0 :     pmdrh->cb = NULL;
     138              :   }
     139            0 :   TALER_EXCHANGE_post_management_denominations_revoke_cancel (pmdrh);
     140            0 : }
     141              : 
     142              : 
     143              : struct TALER_EXCHANGE_PostManagementDenominationsRevokeHandle *
     144            0 : TALER_EXCHANGE_post_management_denominations_revoke_create (
     145              :   struct GNUNET_CURL_Context *ctx,
     146              :   const char *url,
     147              :   const struct TALER_DenominationHashP *h_denom_pub,
     148              :   const struct TALER_MasterSignatureP *master_sig)
     149              : {
     150              :   struct TALER_EXCHANGE_PostManagementDenominationsRevokeHandle *pmdrh;
     151              : 
     152            0 :   pmdrh = GNUNET_new (
     153              :     struct TALER_EXCHANGE_PostManagementDenominationsRevokeHandle);
     154            0 :   pmdrh->ctx = ctx;
     155            0 :   pmdrh->base_url = GNUNET_strdup (url);
     156            0 :   pmdrh->h_denom_pub = *h_denom_pub;
     157            0 :   pmdrh->master_sig = *master_sig;
     158            0 :   return pmdrh;
     159              : }
     160              : 
     161              : 
     162              : enum TALER_ErrorCode
     163            0 : TALER_EXCHANGE_post_management_denominations_revoke_start (
     164              :   struct TALER_EXCHANGE_PostManagementDenominationsRevokeHandle *pmdrh,
     165              :   TALER_EXCHANGE_PostManagementDenominationsRevokeCallback cb,
     166              :   TALER_EXCHANGE_POST_MANAGEMENT_DENOMINATIONS_REVOKE_RESULT_CLOSURE *cb_cls)
     167              : {
     168              :   CURL *eh;
     169              :   json_t *body;
     170              : 
     171            0 :   pmdrh->cb = cb;
     172            0 :   pmdrh->cb_cls = cb_cls;
     173              :   {
     174              :     char epub_str[sizeof (pmdrh->h_denom_pub) * 2];
     175              :     char arg_str[sizeof (epub_str) + 64];
     176              :     char *end;
     177              : 
     178            0 :     end = GNUNET_STRINGS_data_to_string (&pmdrh->h_denom_pub,
     179              :                                          sizeof (pmdrh->h_denom_pub),
     180              :                                          epub_str,
     181              :                                          sizeof (epub_str));
     182            0 :     *end = '\0';
     183            0 :     GNUNET_snprintf (arg_str,
     184              :                      sizeof (arg_str),
     185              :                      "management/denominations/%s/revoke",
     186              :                      epub_str);
     187            0 :     pmdrh->url = TALER_url_join (pmdrh->base_url,
     188              :                                  arg_str,
     189              :                                  NULL);
     190              :   }
     191            0 :   if (NULL == pmdrh->url)
     192              :   {
     193            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     194              :                 "Could not construct request URL.\n");
     195            0 :     return TALER_EC_GENERIC_CONFIGURATION_INVALID;
     196              :   }
     197            0 :   body = GNUNET_JSON_PACK (
     198              :     GNUNET_JSON_pack_data_auto ("master_sig",
     199              :                                 &pmdrh->master_sig));
     200            0 :   eh = TALER_EXCHANGE_curl_easy_get_ (pmdrh->url);
     201            0 :   if ( (NULL == eh) ||
     202              :        (GNUNET_OK !=
     203            0 :         TALER_curl_easy_post (&pmdrh->post_ctx,
     204              :                               eh,
     205              :                               body)) )
     206              :   {
     207            0 :     GNUNET_break (0);
     208            0 :     if (NULL != eh)
     209            0 :       curl_easy_cleanup (eh);
     210            0 :     json_decref (body);
     211            0 :     GNUNET_free (pmdrh->url);
     212            0 :     pmdrh->url = NULL;
     213            0 :     return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
     214              :   }
     215            0 :   json_decref (body);
     216            0 :   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     217              :               "Requesting URL '%s'\n",
     218              :               pmdrh->url);
     219            0 :   pmdrh->job = GNUNET_CURL_job_add2 (pmdrh->ctx,
     220              :                                      eh,
     221            0 :                                      pmdrh->post_ctx.headers,
     222              :                                      &handle_denominations_revoke_finished,
     223              :                                      pmdrh);
     224            0 :   if (NULL == pmdrh->job)
     225              :   {
     226            0 :     GNUNET_break (0);
     227            0 :     TALER_curl_easy_post_finished (&pmdrh->post_ctx);
     228            0 :     GNUNET_free (pmdrh->url);
     229            0 :     pmdrh->url = NULL;
     230            0 :     return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
     231              :   }
     232            0 :   return TALER_EC_NONE;
     233              : }
     234              : 
     235              : 
     236              : void
     237            0 : TALER_EXCHANGE_post_management_denominations_revoke_cancel (
     238              :   struct TALER_EXCHANGE_PostManagementDenominationsRevokeHandle *pmdrh)
     239              : {
     240            0 :   if (NULL != pmdrh->job)
     241              :   {
     242            0 :     GNUNET_CURL_job_cancel (pmdrh->job);
     243            0 :     pmdrh->job = NULL;
     244              :   }
     245            0 :   TALER_curl_easy_post_finished (&pmdrh->post_ctx);
     246            0 :   GNUNET_free (pmdrh->url);
     247            0 :   GNUNET_free (pmdrh->base_url);
     248            0 :   GNUNET_free (pmdrh);
     249            0 : }
     250              : 
     251              : 
     252              : /* end of exchange_api_post-management-denominations-H_DENOM_PUB-revoke.c */
        

Generated by: LCOV version 2.0-1