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

Generated by: LCOV version 2.0-1