LCOV - code coverage report
Current view: top level - lib - merchant_api_delete-private-tokens-SERIAL.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 63 0
Test Date: 2026-04-12 12:58:13 Functions: 0.0 % 4 0

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2025-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 Lesser General Public License as published by the Free Software
       7              :   Foundation; either version 2.1, 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 Lesser General Public License for more details.
      12              : 
      13              :   You should have received a copy of the GNU Lesser General Public License along with
      14              :   TALER; see the file COPYING.LGPL.  If not, see
      15              :   <http://www.gnu.org/licenses/>
      16              : */
      17              : /**
      18              :  * @file merchant_api_delete-private-tokens-SERIAL.c
      19              :  * @brief Implementation of the DELETE /private/tokens/$SERIAL request
      20              :  * @author Christian Grothoff
      21              :  */
      22              : #include "taler/platform.h"
      23              : #include <curl/curl.h>
      24              : #include <jansson.h>
      25              : #include <microhttpd.h> /* just for HTTP status codes */
      26              : #include <gnunet/gnunet_util_lib.h>
      27              : #include <gnunet/gnunet_curl_lib.h>
      28              : #include <taler/merchant/delete-private-tokens-SERIAL.h>
      29              : #include "merchant_api_curl_defaults.h"
      30              : #include <taler/taler_json_lib.h>
      31              : 
      32              : 
      33              : /**
      34              :  * Handle for a DELETE /private/tokens/$SERIAL operation.
      35              :  */
      36              : struct TALER_MERCHANT_DeletePrivateTokensSerialHandle
      37              : {
      38              :   /**
      39              :    * Base URL of the merchant backend.
      40              :    */
      41              :   char *base_url;
      42              : 
      43              :   /**
      44              :    * The full URL for this request.
      45              :    */
      46              :   char *url;
      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_MERCHANT_DeletePrivateTokensSerialCallback cb;
      57              : 
      58              :   /**
      59              :    * Closure for @a cb.
      60              :    */
      61              :   TALER_MERCHANT_DELETE_PRIVATE_TOKENS_SERIAL_RESULT_CLOSURE *cb_cls;
      62              : 
      63              :   /**
      64              :    * Reference to the execution context.
      65              :    */
      66              :   struct GNUNET_CURL_Context *ctx;
      67              : 
      68              :   /**
      69              :    * Identifier of the instance.
      70              :    */
      71              :   char *instance_id;
      72              : 
      73              :   /**
      74              :    * Serial number of the token to delete.
      75              :    */
      76              :   uint64_t serial;
      77              : };
      78              : 
      79              : 
      80              : /**
      81              :  * Function called when we're done processing the
      82              :  * HTTP DELETE /private/tokens/$SERIAL request.
      83              :  *
      84              :  * @param cls the `struct TALER_MERCHANT_DeletePrivateTokensSerialHandle`
      85              :  * @param response_code HTTP response code, 0 on error
      86              :  * @param response response body, NULL if not in JSON
      87              :  */
      88              : static void
      89            0 : handle_delete_tokens_serial_finished (void *cls,
      90              :                                       long response_code,
      91              :                                       const void *response)
      92              : {
      93            0 :   struct TALER_MERCHANT_DeletePrivateTokensSerialHandle *dtsh = cls;
      94            0 :   const json_t *json = response;
      95            0 :   struct TALER_MERCHANT_DeletePrivateTokensSerialResponse dtsr = {
      96            0 :     .hr.http_status = (unsigned int) response_code,
      97              :     .hr.reply = json
      98              :   };
      99              : 
     100            0 :   dtsh->job = NULL;
     101            0 :   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     102              :               "Got DELETE /instances/$ID/private/tokens/$SERIAL response with status code %u\n",
     103              :               (unsigned int) response_code);
     104            0 :   switch (response_code)
     105              :   {
     106            0 :   case MHD_HTTP_NO_CONTENT:
     107            0 :     break;
     108            0 :   case MHD_HTTP_UNAUTHORIZED:
     109            0 :     dtsr.hr.ec = TALER_JSON_get_error_code (json);
     110            0 :     dtsr.hr.hint = TALER_JSON_get_error_hint (json);
     111            0 :     break;
     112            0 :   case MHD_HTTP_FORBIDDEN:
     113            0 :     dtsr.hr.ec = TALER_JSON_get_error_code (json);
     114            0 :     dtsr.hr.hint = TALER_JSON_get_error_hint (json);
     115            0 :     break;
     116            0 :   case MHD_HTTP_NOT_FOUND:
     117            0 :     dtsr.hr.ec = TALER_JSON_get_error_code (json);
     118            0 :     dtsr.hr.hint = TALER_JSON_get_error_hint (json);
     119            0 :     break;
     120            0 :   default:
     121            0 :     dtsr.hr.ec = TALER_JSON_get_error_code (json);
     122            0 :     dtsr.hr.hint = TALER_JSON_get_error_hint (json);
     123            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     124              :                 "Unexpected response code %u/%d for DELETE /instances/$ID/private/tokens/$SERIAL\n",
     125              :                 (unsigned int) response_code,
     126              :                 (int) dtsr.hr.ec);
     127            0 :     break;
     128              :   }
     129            0 :   dtsh->cb (dtsh->cb_cls,
     130              :             &dtsr);
     131            0 :   TALER_MERCHANT_delete_private_tokens_serial_cancel (dtsh);
     132            0 : }
     133              : 
     134              : 
     135              : struct TALER_MERCHANT_DeletePrivateTokensSerialHandle *
     136            0 : TALER_MERCHANT_delete_private_tokens_serial_create (
     137              :   struct GNUNET_CURL_Context *ctx,
     138              :   const char *url,
     139              :   const char *instance_id,
     140              :   uint64_t serial)
     141              : {
     142              :   struct TALER_MERCHANT_DeletePrivateTokensSerialHandle *dtsh;
     143              : 
     144            0 :   dtsh = GNUNET_new (struct TALER_MERCHANT_DeletePrivateTokensSerialHandle);
     145            0 :   dtsh->ctx = ctx;
     146            0 :   dtsh->base_url = GNUNET_strdup (url);
     147            0 :   dtsh->instance_id = GNUNET_strdup (instance_id);
     148            0 :   dtsh->serial = serial;
     149            0 :   return dtsh;
     150              : }
     151              : 
     152              : 
     153              : enum TALER_ErrorCode
     154            0 : TALER_MERCHANT_delete_private_tokens_serial_start (
     155              :   struct TALER_MERCHANT_DeletePrivateTokensSerialHandle *dtsh,
     156              :   TALER_MERCHANT_DeletePrivateTokensSerialCallback cb,
     157              :   TALER_MERCHANT_DELETE_PRIVATE_TOKENS_SERIAL_RESULT_CLOSURE *cb_cls)
     158              : {
     159              :   CURL *eh;
     160              : 
     161            0 :   dtsh->cb = cb;
     162            0 :   dtsh->cb_cls = cb_cls;
     163              :   {
     164              :     char *path;
     165              : 
     166            0 :     GNUNET_asprintf (&path,
     167              :                      "instances/%s/private/tokens/%llu",
     168              :                      dtsh->instance_id,
     169            0 :                      (unsigned long long) dtsh->serial);
     170            0 :     dtsh->url = TALER_url_join (dtsh->base_url,
     171              :                                 path,
     172              :                                 NULL);
     173            0 :     GNUNET_free (path);
     174              :   }
     175            0 :   if (NULL == dtsh->url)
     176            0 :     return TALER_EC_GENERIC_CONFIGURATION_INVALID;
     177            0 :   eh = TALER_MERCHANT_curl_easy_get_ (dtsh->url);
     178            0 :   if (NULL == eh)
     179            0 :     return TALER_EC_GENERIC_CONFIGURATION_INVALID;
     180            0 :   GNUNET_assert (CURLE_OK ==
     181              :                  curl_easy_setopt (eh,
     182              :                                    CURLOPT_CUSTOMREQUEST,
     183              :                                    MHD_HTTP_METHOD_DELETE));
     184            0 :   dtsh->job = GNUNET_CURL_job_add (dtsh->ctx,
     185              :                                    eh,
     186              :                                    &handle_delete_tokens_serial_finished,
     187              :                                    dtsh);
     188            0 :   if (NULL == dtsh->job)
     189            0 :     return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
     190            0 :   return TALER_EC_NONE;
     191              : }
     192              : 
     193              : 
     194              : void
     195            0 : TALER_MERCHANT_delete_private_tokens_serial_cancel (
     196              :   struct TALER_MERCHANT_DeletePrivateTokensSerialHandle *dtsh)
     197              : {
     198            0 :   if (NULL != dtsh->job)
     199              :   {
     200            0 :     GNUNET_CURL_job_cancel (dtsh->job);
     201            0 :     dtsh->job = NULL;
     202              :   }
     203            0 :   GNUNET_free (dtsh->url);
     204            0 :   GNUNET_free (dtsh->instance_id);
     205            0 :   GNUNET_free (dtsh->base_url);
     206            0 :   GNUNET_free (dtsh);
     207            0 : }
     208              : 
     209              : 
     210              : /* end of merchant_api_delete-private-tokens-SERIAL.c */
        

Generated by: LCOV version 2.0-1