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

Generated by: LCOV version 2.0-1