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: 76.9 % 39 30
Test Date: 2025-11-28 21:09:21 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 mi instance to delete
      32              :  * @param connection the MHD connection to handle
      33              :  * @return MHD result code
      34              :  */
      35              : static MHD_RESULT
      36           17 : delete_instances_ID (struct TMH_HandlerContext *hc,
      37              :                      struct TMH_MerchantInstance *mi,
      38              :                      struct MHD_Connection *connection)
      39              : {
      40              :   const char *purge_s;
      41              :   bool purge;
      42              :   enum GNUNET_DB_QueryStatus qs;
      43              : 
      44           17 :   GNUNET_assert (NULL != mi);
      45              :   {
      46              :     enum GNUNET_GenericReturnValue ret =
      47           17 :       TMH_mfa_check_simple (hc,
      48              :                             TALER_MERCHANT_MFA_CO_INSTANCE_DELETION,
      49              :                             mi);
      50              : 
      51           17 :     if (GNUNET_OK != ret)
      52              :     {
      53              :       return (GNUNET_NO == ret)
      54              :         ? MHD_YES
      55            0 :         : MHD_NO;
      56              :     }
      57              :   }
      58              : 
      59           17 :   purge_s = MHD_lookup_connection_value (connection,
      60              :                                          MHD_GET_ARGUMENT_KIND,
      61              :                                          "purge");
      62           17 :   if (NULL == purge_s)
      63            4 :     purge_s = "no";
      64           17 :   purge = (0 == strcasecmp (purge_s,
      65              :                             "yes"));
      66           17 :   if (purge)
      67           13 :     qs = TMH_db->purge_instance (TMH_db->cls,
      68           13 :                                  mi->settings.id);
      69              :   else
      70            4 :     qs = TMH_db->delete_instance_private_key (TMH_db->cls,
      71            4 :                                               mi->settings.id);
      72              :   {
      73           17 :     struct GNUNET_DB_EventHeaderP es = {
      74           17 :       .size = htons (sizeof (es)),
      75           17 :       .type = htons (TALER_DBEVENT_MERCHANT_ACCOUNTS_CHANGED)
      76              :     };
      77              : 
      78           17 :     TMH_db->event_notify (TMH_db->cls,
      79              :                           &es,
      80              :                           NULL,
      81              :                           0);
      82              :   }
      83           17 :   switch (qs)
      84              :   {
      85            0 :   case GNUNET_DB_STATUS_HARD_ERROR:
      86            0 :     return TALER_MHD_reply_with_error (connection,
      87              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      88              :                                        TALER_EC_GENERIC_DB_STORE_FAILED,
      89              :                                        "delete private key");
      90            0 :   case GNUNET_DB_STATUS_SOFT_ERROR:
      91            0 :     GNUNET_break (0);
      92            0 :     return TALER_MHD_reply_with_error (connection,
      93              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      94              :                                        TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
      95              :                                        NULL);
      96            0 :   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
      97            0 :     return TALER_MHD_reply_with_error (connection,
      98              :                                        MHD_HTTP_NOT_FOUND,
      99              :                                        TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN,
     100              :                                        purge
     101              :                                        ? "Instance unknown"
     102              :                                        : "Private key unknown");
     103           17 :   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     104           17 :     TMH_reload_instances (mi->settings.id);
     105           17 :     return TALER_MHD_reply_static (connection,
     106              :                                    MHD_HTTP_NO_CONTENT,
     107              :                                    NULL,
     108              :                                    NULL,
     109              :                                    0);
     110              :   }
     111            0 :   GNUNET_assert (0);
     112              :   return MHD_NO;
     113              : }
     114              : 
     115              : 
     116              : MHD_RESULT
     117            3 : TMH_private_delete_instances_ID (
     118              :   const struct TMH_RequestHandler *rh,
     119              :   struct MHD_Connection *connection,
     120              :   struct TMH_HandlerContext *hc)
     121              : {
     122            3 :   struct TMH_MerchantInstance *mi = hc->instance;
     123              : 
     124              :   (void) rh;
     125            3 :   return delete_instances_ID (hc,
     126              :                               mi,
     127              :                               connection);
     128              : }
     129              : 
     130              : 
     131              : MHD_RESULT
     132           16 : TMH_private_delete_instances_default_ID (
     133              :   const struct TMH_RequestHandler *rh,
     134              :   struct MHD_Connection *connection,
     135              :   struct TMH_HandlerContext *hc)
     136              : {
     137              :   struct TMH_MerchantInstance *mi;
     138              : 
     139              :   (void) rh;
     140           16 :   mi = TMH_lookup_instance (hc->infix);
     141           16 :   if (NULL == mi)
     142              :   {
     143            2 :     return TALER_MHD_reply_with_error (
     144              :       connection,
     145              :       MHD_HTTP_NOT_FOUND,
     146              :       TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN,
     147            2 :       hc->infix);
     148              :   }
     149           14 :   return delete_instances_ID (hc,
     150              :                               mi,
     151              :                               connection);
     152              : }
     153              : 
     154              : 
     155              : /* end of taler-merchant-httpd_private-delete-instances-ID.c */
        

Generated by: LCOV version 2.0-1