LCOV - code coverage report
Current view: top level - lib - exchange_api_post-management-auditors-AUDITOR_PUB-disable.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 63.8 % 80 51
Test Date: 2026-03-10 12:10:57 Functions: 100.0 % 4 4

            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-auditors-AUDITOR_PUB-disable.c
      19              :  * @brief functions to disable an auditor
      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 "taler/taler-exchange/post-management-auditors-AUDITOR_PUB-disable.h"
      28              : #include "exchange_api_curl_defaults.h"
      29              : #include "taler/taler_signatures.h"
      30              : #include "taler/taler_curl_lib.h"
      31              : 
      32              : 
      33              : /**
      34              :  * @brief Handle for a POST /management/auditors/$AUDITOR_PUB/disable request.
      35              :  */
      36              : struct TALER_EXCHANGE_PostManagementAuditorsDisableHandle
      37              : {
      38              : 
      39              :   /**
      40              :    * The base URL for this request.
      41              :    */
      42              :   char *base_url;
      43              : 
      44              :   /**
      45              :    * The full URL for this request, set during _start.
      46              :    */
      47              :   char *url;
      48              : 
      49              :   /**
      50              :    * Minor context that holds body and headers.
      51              :    */
      52              :   struct TALER_CURL_PostContext post_ctx;
      53              : 
      54              :   /**
      55              :    * Handle for the request.
      56              :    */
      57              :   struct GNUNET_CURL_Job *job;
      58              : 
      59              :   /**
      60              :    * Function to call with the result.
      61              :    */
      62              :   TALER_EXCHANGE_PostManagementAuditorsDisableCallback cb;
      63              : 
      64              :   /**
      65              :    * Closure for @a cb.
      66              :    */
      67              :   TALER_EXCHANGE_POST_MANAGEMENT_AUDITORS_DISABLE_RESULT_CLOSURE *cb_cls;
      68              : 
      69              :   /**
      70              :    * Reference to the execution context.
      71              :    */
      72              :   struct GNUNET_CURL_Context *ctx;
      73              : 
      74              :   /**
      75              :    * Public signing key of the auditor.
      76              :    */
      77              :   struct TALER_AuditorPublicKeyP auditor_pub;
      78              : 
      79              :   /**
      80              :    * When was this decided?
      81              :    */
      82              :   struct GNUNET_TIME_Timestamp validity_end;
      83              : 
      84              :   /**
      85              :    * Signature affirming the auditor disablement.
      86              :    */
      87              :   struct TALER_MasterSignatureP master_sig;
      88              : 
      89              : };
      90              : 
      91              : 
      92              : /**
      93              :  * Function called when we're done processing the
      94              :  * HTTP POST /management/auditors/$AUDITOR_PUB/disable request.
      95              :  *
      96              :  * @param cls the `struct TALER_EXCHANGE_PostManagementAuditorsDisableHandle`
      97              :  * @param response_code HTTP response code, 0 on error
      98              :  * @param response response body, NULL if not in JSON
      99              :  */
     100              : static void
     101            8 : handle_auditors_disable_finished (void *cls,
     102              :                                   long response_code,
     103              :                                   const void *response)
     104              : {
     105            8 :   struct TALER_EXCHANGE_PostManagementAuditorsDisableHandle *pmadh = cls;
     106            8 :   const json_t *json = response;
     107            8 :   struct TALER_EXCHANGE_PostManagementAuditorsDisableResponse res = {
     108            8 :     .hr.http_status = (unsigned int) response_code,
     109              :     .hr.reply = json
     110              :   };
     111              : 
     112            8 :   pmadh->job = NULL;
     113            8 :   switch (response_code)
     114              :   {
     115            6 :   case MHD_HTTP_NO_CONTENT:
     116            6 :     break;
     117            2 :   case MHD_HTTP_FORBIDDEN:
     118            2 :     res.hr.ec = TALER_JSON_get_error_code (json);
     119            2 :     res.hr.hint = TALER_JSON_get_error_hint (json);
     120            2 :     break;
     121            0 :   case MHD_HTTP_NOT_FOUND:
     122            0 :     res.hr.ec = TALER_JSON_get_error_code (json);
     123            0 :     res.hr.hint = TALER_JSON_get_error_hint (json);
     124            0 :     break;
     125            0 :   case MHD_HTTP_CONFLICT:
     126            0 :     res.hr.ec = TALER_JSON_get_error_code (json);
     127            0 :     res.hr.hint = TALER_JSON_get_error_hint (json);
     128            0 :     break;
     129            0 :   default:
     130              :     /* unexpected response code */
     131            0 :     GNUNET_break_op (0);
     132            0 :     res.hr.ec = TALER_JSON_get_error_code (json);
     133            0 :     res.hr.hint = TALER_JSON_get_error_hint (json);
     134            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     135              :                 "Unexpected response code %u/%d for exchange management auditor disable\n",
     136              :                 (unsigned int) response_code,
     137              :                 (int) res.hr.ec);
     138            0 :     break;
     139              :   }
     140            8 :   if (NULL != pmadh->cb)
     141              :   {
     142            8 :     pmadh->cb (pmadh->cb_cls,
     143              :                &res);
     144            8 :     pmadh->cb = NULL;
     145              :   }
     146            8 :   TALER_EXCHANGE_post_management_auditors_disable_cancel (pmadh);
     147            8 : }
     148              : 
     149              : 
     150              : struct TALER_EXCHANGE_PostManagementAuditorsDisableHandle *
     151            8 : TALER_EXCHANGE_post_management_auditors_disable_create (
     152              :   struct GNUNET_CURL_Context *ctx,
     153              :   const char *url,
     154              :   const struct TALER_AuditorPublicKeyP *auditor_pub,
     155              :   struct GNUNET_TIME_Timestamp validity_end,
     156              :   const struct TALER_MasterSignatureP *master_sig)
     157              : {
     158              :   struct TALER_EXCHANGE_PostManagementAuditorsDisableHandle *pmadh;
     159              : 
     160            8 :   pmadh = GNUNET_new (
     161              :     struct TALER_EXCHANGE_PostManagementAuditorsDisableHandle);
     162            8 :   pmadh->ctx = ctx;
     163            8 :   pmadh->base_url = GNUNET_strdup (url);
     164            8 :   pmadh->auditor_pub = *auditor_pub;
     165            8 :   pmadh->validity_end = validity_end;
     166            8 :   pmadh->master_sig = *master_sig;
     167            8 :   return pmadh;
     168              : }
     169              : 
     170              : 
     171              : enum TALER_ErrorCode
     172            8 : TALER_EXCHANGE_post_management_auditors_disable_start (
     173              :   struct TALER_EXCHANGE_PostManagementAuditorsDisableHandle *pmadh,
     174              :   TALER_EXCHANGE_PostManagementAuditorsDisableCallback cb,
     175              :   TALER_EXCHANGE_POST_MANAGEMENT_AUDITORS_DISABLE_RESULT_CLOSURE *cb_cls)
     176              : {
     177              :   CURL *eh;
     178              :   json_t *body;
     179              : 
     180            8 :   pmadh->cb = cb;
     181            8 :   pmadh->cb_cls = cb_cls;
     182              :   {
     183              :     char epub_str[sizeof (pmadh->auditor_pub) * 2];
     184              :     char arg_str[sizeof (epub_str) + 64];
     185              :     char *end;
     186              : 
     187            8 :     end = GNUNET_STRINGS_data_to_string (&pmadh->auditor_pub,
     188              :                                          sizeof (pmadh->auditor_pub),
     189              :                                          epub_str,
     190              :                                          sizeof (epub_str));
     191            8 :     *end = '\0';
     192            8 :     GNUNET_snprintf (arg_str,
     193              :                      sizeof (arg_str),
     194              :                      "management/auditors/%s/disable",
     195              :                      epub_str);
     196            8 :     pmadh->url = TALER_url_join (pmadh->base_url,
     197              :                                  arg_str,
     198              :                                  NULL);
     199              :   }
     200            8 :   if (NULL == pmadh->url)
     201              :   {
     202            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     203              :                 "Could not construct request URL.\n");
     204            0 :     return TALER_EC_GENERIC_CONFIGURATION_INVALID;
     205              :   }
     206            8 :   body = GNUNET_JSON_PACK (
     207              :     GNUNET_JSON_pack_data_auto ("master_sig",
     208              :                                 &pmadh->master_sig),
     209              :     GNUNET_JSON_pack_timestamp ("validity_end",
     210              :                                 pmadh->validity_end));
     211            8 :   eh = TALER_EXCHANGE_curl_easy_get_ (pmadh->url);
     212           16 :   if ( (NULL == eh) ||
     213              :        (GNUNET_OK !=
     214            8 :         TALER_curl_easy_post (&pmadh->post_ctx,
     215              :                               eh,
     216              :                               body)) )
     217              :   {
     218            0 :     GNUNET_break (0);
     219            0 :     if (NULL != eh)
     220            0 :       curl_easy_cleanup (eh);
     221            0 :     json_decref (body);
     222            0 :     GNUNET_free (pmadh->url);
     223            0 :     pmadh->url = NULL;
     224            0 :     return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
     225              :   }
     226            8 :   json_decref (body);
     227            8 :   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     228              :               "Requesting URL '%s'\n",
     229              :               pmadh->url);
     230           16 :   pmadh->job = GNUNET_CURL_job_add2 (pmadh->ctx,
     231              :                                      eh,
     232            8 :                                      pmadh->post_ctx.headers,
     233              :                                      &handle_auditors_disable_finished,
     234              :                                      pmadh);
     235            8 :   if (NULL == pmadh->job)
     236              :   {
     237            0 :     TALER_curl_easy_post_finished (&pmadh->post_ctx);
     238            0 :     GNUNET_free (pmadh->url);
     239            0 :     pmadh->url = NULL;
     240            0 :     return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
     241              :   }
     242            8 :   return TALER_EC_NONE;
     243              : }
     244              : 
     245              : 
     246              : void
     247            8 : TALER_EXCHANGE_post_management_auditors_disable_cancel (
     248              :   struct TALER_EXCHANGE_PostManagementAuditorsDisableHandle *pmadh)
     249              : {
     250            8 :   if (NULL != pmadh->job)
     251              :   {
     252            0 :     GNUNET_CURL_job_cancel (pmadh->job);
     253            0 :     pmadh->job = NULL;
     254              :   }
     255            8 :   TALER_curl_easy_post_finished (&pmadh->post_ctx);
     256            8 :   GNUNET_free (pmadh->url);
     257            8 :   GNUNET_free (pmadh->base_url);
     258            8 :   GNUNET_free (pmadh);
     259            8 : }
     260              : 
     261              : 
     262              : /* end of exchange_api_post-management-auditors-AUDITOR_PUB-disable.c */
        

Generated by: LCOV version 2.0-1