LCOV - code coverage report
Current view: top level - lib - exchange_api_management_revoke_denomination_key.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 72 0.0 %
Date: 2022-08-25 06:15:09 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2015-2020 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_management_revoke_denomination_key.c
      19             :  * @brief functions to revoke an exchange denomination key
      20             :  * @author Christian Grothoff
      21             :  */
      22             : #include "platform.h"
      23             : #include "taler_json_lib.h"
      24             : #include <gnunet/gnunet_curl_lib.h>
      25             : #include "taler_exchange_service.h"
      26             : #include "exchange_api_curl_defaults.h"
      27             : #include "taler_signatures.h"
      28             : #include "taler_curl_lib.h"
      29             : #include "taler_json_lib.h"
      30             : 
      31             : 
      32             : /**
      33             :  * @brief Handle for a POST /management/denominations/$H_DENOM_PUB/revoke request.
      34             :  */
      35             : struct TALER_EXCHANGE_ManagementRevokeDenominationKeyHandle
      36             : {
      37             : 
      38             :   /**
      39             :    * The url for this request.
      40             :    */
      41             :   char *url;
      42             : 
      43             :   /**
      44             :    * Minor context that holds body and headers.
      45             :    */
      46             :   struct TALER_CURL_PostContext post_ctx;
      47             : 
      48             :   /**
      49             :    * Handle for the request.
      50             :    */
      51             :   struct GNUNET_CURL_Job *job;
      52             : 
      53             :   /**
      54             :    * Function to call with the result.
      55             :    */
      56             :   TALER_EXCHANGE_ManagementRevokeDenominationKeyCallback cb;
      57             : 
      58             :   /**
      59             :    * Closure for @a cb.
      60             :    */
      61             :   void *cb_cls;
      62             : 
      63             :   /**
      64             :    * Reference to the execution context.
      65             :    */
      66             :   struct GNUNET_CURL_Context *ctx;
      67             : };
      68             : 
      69             : 
      70             : /**
      71             :  * Function called when we're done processing the
      72             :  * HTTP /management/denominations/$H_DENOM_PUB/revoke request.
      73             :  *
      74             :  * @param cls the `struct TALER_EXCHANGE_ManagementRevokeDenominationKeyHandle *`
      75             :  * @param response_code HTTP response code, 0 on error
      76             :  * @param response response body, NULL if not in JSON
      77             :  */
      78             : static void
      79           0 : handle_revoke_denomination_finished (void *cls,
      80             :                                      long response_code,
      81             :                                      const void *response)
      82             : {
      83           0 :   struct TALER_EXCHANGE_ManagementRevokeDenominationKeyHandle *rh = cls;
      84           0 :   const json_t *json = response;
      85           0 :   struct TALER_EXCHANGE_HttpResponse hr = {
      86           0 :     .http_status = (unsigned int) response_code,
      87             :     .reply = json
      88             :   };
      89             : 
      90           0 :   rh->job = NULL;
      91           0 :   switch (response_code)
      92             :   {
      93           0 :   case 0:
      94             :     /* no reply */
      95           0 :     hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
      96           0 :     hr.hint = "server offline?";
      97           0 :     break;
      98           0 :   case MHD_HTTP_NO_CONTENT:
      99           0 :     break;
     100           0 :   case MHD_HTTP_FORBIDDEN:
     101           0 :     hr.ec = TALER_JSON_get_error_code (json);
     102           0 :     hr.hint = TALER_JSON_get_error_hint (json);
     103           0 :     break;
     104           0 :   default:
     105             :     /* unexpected response code */
     106           0 :     GNUNET_break_op (0);
     107           0 :     hr.ec = TALER_JSON_get_error_code (json);
     108           0 :     hr.hint = TALER_JSON_get_error_hint (json);
     109           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     110             :                 "Unexpected response code %u/%d for exchange management revoke denomination\n",
     111             :                 (unsigned int) response_code,
     112             :                 (int) hr.ec);
     113           0 :     break;
     114             :   }
     115           0 :   if (NULL != rh->cb)
     116             :   {
     117           0 :     rh->cb (rh->cb_cls,
     118             :             &hr);
     119           0 :     rh->cb = NULL;
     120             :   }
     121           0 :   TALER_EXCHANGE_management_revoke_denomination_key_cancel (rh);
     122           0 : }
     123             : 
     124             : 
     125             : struct TALER_EXCHANGE_ManagementRevokeDenominationKeyHandle *
     126           0 : TALER_EXCHANGE_management_revoke_denomination_key (
     127             :   struct GNUNET_CURL_Context *ctx,
     128             :   const char *url,
     129             :   const struct TALER_DenominationHashP *h_denom_pub,
     130             :   const struct TALER_MasterSignatureP *master_sig,
     131             :   TALER_EXCHANGE_ManagementRevokeDenominationKeyCallback cb,
     132             :   void *cb_cls)
     133             : {
     134             :   struct TALER_EXCHANGE_ManagementRevokeDenominationKeyHandle *rh;
     135             :   CURL *eh;
     136             :   json_t *body;
     137             : 
     138           0 :   rh = GNUNET_new (struct TALER_EXCHANGE_ManagementRevokeDenominationKeyHandle);
     139           0 :   rh->cb = cb;
     140           0 :   rh->cb_cls = cb_cls;
     141           0 :   rh->ctx = ctx;
     142             :   {
     143             :     char epub_str[sizeof (*h_denom_pub) * 2];
     144             :     char arg_str[sizeof (epub_str) + 64];
     145             :     char *end;
     146             : 
     147           0 :     end = GNUNET_STRINGS_data_to_string (h_denom_pub,
     148             :                                          sizeof (*h_denom_pub),
     149             :                                          epub_str,
     150             :                                          sizeof (epub_str));
     151           0 :     *end = '\0';
     152           0 :     GNUNET_snprintf (arg_str,
     153             :                      sizeof (arg_str),
     154             :                      "management/denominations/%s/revoke",
     155             :                      epub_str);
     156           0 :     rh->url = TALER_url_join (url,
     157             :                               arg_str,
     158             :                               NULL);
     159             :   }
     160           0 :   if (NULL == rh->url)
     161             :   {
     162           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     163             :                 "Could not construct request URL.\n");
     164           0 :     GNUNET_free (rh);
     165           0 :     return NULL;
     166             :   }
     167           0 :   body = GNUNET_JSON_PACK (
     168             :     GNUNET_JSON_pack_data_auto ("master_sig",
     169             :                                 master_sig));
     170           0 :   if (NULL == body)
     171             :   {
     172           0 :     GNUNET_break (0);
     173           0 :     GNUNET_free (rh->url);
     174           0 :     GNUNET_free (rh);
     175           0 :     return NULL;
     176             :   }
     177           0 :   eh = TALER_EXCHANGE_curl_easy_get_ (rh->url);
     178           0 :   if ( (NULL == eh) ||
     179             :        (GNUNET_OK !=
     180           0 :         TALER_curl_easy_post (&rh->post_ctx,
     181             :                               eh,
     182             :                               body)) )
     183             :   {
     184           0 :     GNUNET_break (0);
     185           0 :     if (NULL != eh)
     186           0 :       curl_easy_cleanup (eh);
     187           0 :     json_decref (body);
     188           0 :     GNUNET_free (rh->url);
     189           0 :     return NULL;
     190             :   }
     191           0 :   json_decref (body);
     192           0 :   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     193             :               "Requesting URL '%s'\n",
     194             :               rh->url);
     195           0 :   rh->job = GNUNET_CURL_job_add2 (ctx,
     196             :                                   eh,
     197           0 :                                   rh->post_ctx.headers,
     198             :                                   &handle_revoke_denomination_finished,
     199             :                                   rh);
     200           0 :   if (NULL == rh->job)
     201             :   {
     202           0 :     TALER_EXCHANGE_management_revoke_denomination_key_cancel (rh);
     203           0 :     return NULL;
     204             :   }
     205           0 :   return rh;
     206             : }
     207             : 
     208             : 
     209             : void
     210           0 : TALER_EXCHANGE_management_revoke_denomination_key_cancel (
     211             :   struct TALER_EXCHANGE_ManagementRevokeDenominationKeyHandle *rh)
     212             : {
     213           0 :   if (NULL != rh->job)
     214             :   {
     215           0 :     GNUNET_CURL_job_cancel (rh->job);
     216           0 :     rh->job = NULL;
     217             :   }
     218           0 :   TALER_curl_easy_post_finished (&rh->post_ctx);
     219           0 :   GNUNET_free (rh->url);
     220           0 :   GNUNET_free (rh);
     221           0 : }

Generated by: LCOV version 1.14