LCOV - code coverage report
Current view: top level - lib - exchange_api_management_auditor_disable.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 71 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-2021 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_auditor_disable.c
      19             :  * @brief functions to disable an auditor
      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             :  * @brief Handle for a POST /management/auditors/$AUDITOR_PUB/disable request.
      33             :  */
      34             : struct TALER_EXCHANGE_ManagementAuditorDisableHandle
      35             : {
      36             : 
      37             :   /**
      38             :    * The url for this request.
      39             :    */
      40             :   char *url;
      41             : 
      42             :   /**
      43             :    * Minor context that holds body and headers.
      44             :    */
      45             :   struct TALER_CURL_PostContext post_ctx;
      46             : 
      47             :   /**
      48             :    * Handle for the request.
      49             :    */
      50             :   struct GNUNET_CURL_Job *job;
      51             : 
      52             :   /**
      53             :    * Function to call with the result.
      54             :    */
      55             :   TALER_EXCHANGE_ManagementAuditorDisableCallback cb;
      56             : 
      57             :   /**
      58             :    * Closure for @a cb.
      59             :    */
      60             :   void *cb_cls;
      61             : 
      62             :   /**
      63             :    * Reference to the execution context.
      64             :    */
      65             :   struct GNUNET_CURL_Context *ctx;
      66             : };
      67             : 
      68             : 
      69             : /**
      70             :  * Function called when we're done processing the
      71             :  * HTTP /management/auditors/%s/disable request.
      72             :  *
      73             :  * @param cls the `struct TALER_EXCHANGE_ManagementAuditorDisableHandle *`
      74             :  * @param response_code HTTP response code, 0 on error
      75             :  * @param response response body, NULL if not in JSON
      76             :  */
      77             : static void
      78           0 : handle_auditor_disable_finished (void *cls,
      79             :                                  long response_code,
      80             :                                  const void *response)
      81             : {
      82           0 :   struct TALER_EXCHANGE_ManagementAuditorDisableHandle *ah = cls;
      83           0 :   const json_t *json = response;
      84           0 :   struct TALER_EXCHANGE_HttpResponse hr = {
      85           0 :     .http_status = (unsigned int) response_code,
      86             :     .reply = json
      87             :   };
      88             : 
      89           0 :   ah->job = NULL;
      90           0 :   switch (response_code)
      91             :   {
      92           0 :   case MHD_HTTP_NO_CONTENT:
      93           0 :     break;
      94           0 :   case MHD_HTTP_FORBIDDEN:
      95           0 :     hr.ec = TALER_JSON_get_error_code (json);
      96           0 :     hr.hint = TALER_JSON_get_error_hint (json);
      97           0 :     break;
      98           0 :   case MHD_HTTP_NOT_FOUND:
      99           0 :     hr.ec = TALER_JSON_get_error_code (json);
     100           0 :     hr.hint = TALER_JSON_get_error_hint (json);
     101           0 :     break;
     102           0 :   case MHD_HTTP_CONFLICT:
     103           0 :     hr.ec = TALER_JSON_get_error_code (json);
     104           0 :     hr.hint = TALER_JSON_get_error_hint (json);
     105           0 :     break;
     106           0 :   default:
     107             :     /* unexpected response code */
     108           0 :     GNUNET_break_op (0);
     109           0 :     hr.ec = TALER_JSON_get_error_code (json);
     110           0 :     hr.hint = TALER_JSON_get_error_hint (json);
     111           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     112             :                 "Unexpected response code %u/%d for exchange management auditor disable\n",
     113             :                 (unsigned int) response_code,
     114             :                 (int) hr.ec);
     115           0 :     break;
     116             :   }
     117           0 :   if (NULL != ah->cb)
     118             :   {
     119           0 :     ah->cb (ah->cb_cls,
     120             :             &hr);
     121           0 :     ah->cb = NULL;
     122             :   }
     123           0 :   TALER_EXCHANGE_management_disable_auditor_cancel (ah);
     124           0 : }
     125             : 
     126             : 
     127             : struct TALER_EXCHANGE_ManagementAuditorDisableHandle *
     128           0 : TALER_EXCHANGE_management_disable_auditor (
     129             :   struct GNUNET_CURL_Context *ctx,
     130             :   const char *url,
     131             :   const struct TALER_AuditorPublicKeyP *auditor_pub,
     132             :   struct GNUNET_TIME_Timestamp validity_end,
     133             :   const struct TALER_MasterSignatureP *master_sig,
     134             :   TALER_EXCHANGE_ManagementAuditorDisableCallback cb,
     135             :   void *cb_cls)
     136             : {
     137             :   struct TALER_EXCHANGE_ManagementAuditorDisableHandle *ah;
     138             :   CURL *eh;
     139             :   json_t *body;
     140             : 
     141           0 :   ah = GNUNET_new (struct TALER_EXCHANGE_ManagementAuditorDisableHandle);
     142           0 :   ah->cb = cb;
     143           0 :   ah->cb_cls = cb_cls;
     144           0 :   ah->ctx = ctx;
     145             :   {
     146             :     char epub_str[sizeof (*auditor_pub) * 2];
     147             :     char arg_str[sizeof (epub_str) + 64];
     148             :     char *end;
     149             : 
     150           0 :     end = GNUNET_STRINGS_data_to_string (auditor_pub,
     151             :                                          sizeof (*auditor_pub),
     152             :                                          epub_str,
     153             :                                          sizeof (epub_str));
     154           0 :     *end = '\0';
     155           0 :     GNUNET_snprintf (arg_str,
     156             :                      sizeof (arg_str),
     157             :                      "management/auditors/%s/disable",
     158             :                      epub_str);
     159           0 :     ah->url = TALER_url_join (url,
     160             :                               arg_str,
     161             :                               NULL);
     162             :   }
     163           0 :   if (NULL == ah->url)
     164             :   {
     165           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     166             :                 "Could not construct request URL.\n");
     167           0 :     GNUNET_free (ah);
     168           0 :     return NULL;
     169             :   }
     170           0 :   body = GNUNET_JSON_PACK (
     171             :     GNUNET_JSON_pack_data_auto ("master_sig",
     172             :                                 master_sig),
     173             :     GNUNET_JSON_pack_timestamp ("validity_end",
     174             :                                 validity_end));
     175           0 :   eh = TALER_EXCHANGE_curl_easy_get_ (ah->url);
     176           0 :   if ( (NULL == eh) ||
     177             :        (GNUNET_OK !=
     178           0 :         TALER_curl_easy_post (&ah->post_ctx,
     179             :                               eh,
     180             :                               body)))
     181             :   {
     182           0 :     GNUNET_break (0);
     183           0 :     if (NULL != eh)
     184           0 :       curl_easy_cleanup (eh);
     185           0 :     json_decref (body);
     186           0 :     GNUNET_free (ah->url);
     187           0 :     return NULL;
     188             :   }
     189           0 :   json_decref (body);
     190           0 :   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     191             :               "Requesting URL '%s'\n",
     192             :               ah->url);
     193           0 :   ah->job = GNUNET_CURL_job_add2 (ctx,
     194             :                                   eh,
     195           0 :                                   ah->post_ctx.headers,
     196             :                                   &handle_auditor_disable_finished,
     197             :                                   ah);
     198           0 :   if (NULL == ah->job)
     199             :   {
     200           0 :     TALER_EXCHANGE_management_disable_auditor_cancel (ah);
     201           0 :     return NULL;
     202             :   }
     203           0 :   return ah;
     204             : }
     205             : 
     206             : 
     207             : void
     208           0 : TALER_EXCHANGE_management_disable_auditor_cancel (
     209             :   struct TALER_EXCHANGE_ManagementAuditorDisableHandle *ah)
     210             : {
     211           0 :   if (NULL != ah->job)
     212             :   {
     213           0 :     GNUNET_CURL_job_cancel (ah->job);
     214           0 :     ah->job = NULL;
     215             :   }
     216           0 :   TALER_curl_easy_post_finished (&ah->post_ctx);
     217           0 :   GNUNET_free (ah->url);
     218           0 :   GNUNET_free (ah);
     219           0 : }

Generated by: LCOV version 1.14