LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-delete-instances-ID.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 77.5 % 40 31
Test Date: 2026-01-01 16:44:56 Functions: 100.0 % 3 3

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   (C) 2020-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 Affero 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 <http://www.gnu.org/licenses/>
      15              : */
      16              : /**
      17              :  * @file taler-merchant-httpd_private-delete-instances-ID.c
      18              :  * @brief implement DELETE /instances/$ID
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "platform.h"
      22              : #include "taler-merchant-httpd_private-delete-instances-ID.h"
      23              : #include <taler/taler_json_lib.h>
      24              : #include <taler/taler_dbevents.h>
      25              : #include "taler-merchant-httpd_mfa.h"
      26              : 
      27              : /**
      28              :  * Handle a DELETE "/instances/$ID" request.
      29              :  *
      30              :  * @param[in,out] hc http request context
      31              :  * @param mfa_check true if a MFA check is required
      32              :  * @param mi instance to delete
      33              :  * @param connection the MHD connection to handle
      34              :  * @return MHD result code
      35              :  */
      36              : static MHD_RESULT
      37           17 : delete_instances_ID (struct TMH_HandlerContext *hc,
      38              :                      bool mfa_check,
      39              :                      struct TMH_MerchantInstance *mi,
      40              :                      struct MHD_Connection *connection)
      41              : {
      42              :   bool purge;
      43              :   enum GNUNET_DB_QueryStatus qs;
      44              : 
      45           17 :   GNUNET_assert (NULL != mi);
      46           17 :   if (mfa_check)
      47              :   {
      48              :     enum GNUNET_GenericReturnValue ret =
      49            3 :       TMH_mfa_check_simple (hc,
      50              :                             TALER_MERCHANT_MFA_CO_INSTANCE_DELETION,
      51              :                             mi);
      52              : 
      53            3 :     if (GNUNET_OK != ret)
      54              :     {
      55              :       return (GNUNET_NO == ret)
      56              :         ? MHD_YES
      57            0 :         : MHD_NO;
      58              :     }
      59              :   }
      60              : 
      61              :   {
      62              :     const char *purge_s;
      63              : 
      64           17 :     purge_s = MHD_lookup_connection_value (connection,
      65              :                                            MHD_GET_ARGUMENT_KIND,
      66              :                                            "purge");
      67           17 :     if (NULL == purge_s)
      68            4 :       purge_s = "no";
      69           17 :     purge = (0 == strcasecmp (purge_s,
      70              :                               "yes"));
      71              :   }
      72           17 :   if (purge)
      73           13 :     qs = TMH_db->purge_instance (TMH_db->cls,
      74           13 :                                  mi->settings.id);
      75              :   else
      76            4 :     qs = TMH_db->delete_instance_private_key (TMH_db->cls,
      77            4 :                                               mi->settings.id);
      78              :   {
      79           17 :     struct GNUNET_DB_EventHeaderP es = {
      80           17 :       .size = htons (sizeof (es)),
      81           17 :       .type = htons (TALER_DBEVENT_MERCHANT_ACCOUNTS_CHANGED)
      82              :     };
      83              : 
      84           17 :     TMH_db->event_notify (TMH_db->cls,
      85              :                           &es,
      86              :                           NULL,
      87              :                           0);
      88              :   }
      89           17 :   switch (qs)
      90              :   {
      91            0 :   case GNUNET_DB_STATUS_HARD_ERROR:
      92            0 :     return TALER_MHD_reply_with_error (connection,
      93              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      94              :                                        TALER_EC_GENERIC_DB_STORE_FAILED,
      95              :                                        "delete private key");
      96            0 :   case GNUNET_DB_STATUS_SOFT_ERROR:
      97            0 :     GNUNET_break (0);
      98            0 :     return TALER_MHD_reply_with_error (connection,
      99              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     100              :                                        TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
     101              :                                        NULL);
     102            0 :   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     103            0 :     return TALER_MHD_reply_with_error (connection,
     104              :                                        MHD_HTTP_NOT_FOUND,
     105              :                                        TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN,
     106              :                                        purge
     107              :                                        ? "Instance unknown"
     108              :                                        : "Private key unknown");
     109           17 :   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     110           17 :     TMH_reload_instances (mi->settings.id);
     111           17 :     return TALER_MHD_reply_static (connection,
     112              :                                    MHD_HTTP_NO_CONTENT,
     113              :                                    NULL,
     114              :                                    NULL,
     115              :                                    0);
     116              :   }
     117            0 :   GNUNET_assert (0);
     118              :   return MHD_NO;
     119              : }
     120              : 
     121              : 
     122              : MHD_RESULT
     123            3 : TMH_private_delete_instances_ID (
     124              :   const struct TMH_RequestHandler *rh,
     125              :   struct MHD_Connection *connection,
     126              :   struct TMH_HandlerContext *hc)
     127              : {
     128            3 :   struct TMH_MerchantInstance *mi = hc->instance;
     129              : 
     130              :   (void) rh;
     131            3 :   return delete_instances_ID (hc,
     132              :                               true,
     133              :                               mi,
     134              :                               connection);
     135              : }
     136              : 
     137              : 
     138              : MHD_RESULT
     139           16 : TMH_private_delete_instances_default_ID (
     140              :   const struct TMH_RequestHandler *rh,
     141              :   struct MHD_Connection *connection,
     142              :   struct TMH_HandlerContext *hc)
     143              : {
     144              :   struct TMH_MerchantInstance *mi;
     145              : 
     146              :   (void) rh;
     147           16 :   mi = TMH_lookup_instance (hc->infix);
     148           16 :   if (NULL == mi)
     149              :   {
     150            2 :     return TALER_MHD_reply_with_error (
     151              :       connection,
     152              :       MHD_HTTP_NOT_FOUND,
     153              :       TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN,
     154            2 :       hc->infix);
     155              :   }
     156           14 :   return delete_instances_ID (hc,
     157              :                               false,
     158              :                               mi,
     159              :                               connection);
     160              : }
     161              : 
     162              : 
     163              : /* end of taler-merchant-httpd_private-delete-instances-ID.c */
        

Generated by: LCOV version 2.0-1