merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

taler-merchant-httpd_delete-management-instances-INSTANCE.c (5180B)


      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_delete-management-instances-INSTANCE.c
     18  * @brief implement DELETE /instances/$ID
     19  * @author Christian Grothoff
     20  */
     21 #include "taler/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 
     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 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   GNUNET_assert (NULL != mi);
     46   if (mfa_check)
     47   {
     48     enum GNUNET_GenericReturnValue ret =
     49       TMH_mfa_check_simple (hc,
     50                             TALER_MERCHANT_MFA_CO_INSTANCE_DELETION,
     51                             mi);
     52 
     53     if (GNUNET_OK != ret)
     54     {
     55       return (GNUNET_NO == ret)
     56         ? MHD_YES
     57         : MHD_NO;
     58     }
     59   }
     60 
     61   {
     62     const char *purge_s;
     63 
     64     purge_s = MHD_lookup_connection_value (connection,
     65                                            MHD_GET_ARGUMENT_KIND,
     66                                            "purge");
     67     if (NULL == purge_s)
     68       purge_s = "no";
     69     purge = (0 == strcasecmp (purge_s,
     70                               "yes"));
     71   }
     72   if (purge)
     73     qs = TMH_db->purge_instance (TMH_db->cls,
     74                                  mi->settings.id);
     75   else
     76     qs = TMH_db->delete_instance_private_key (TMH_db->cls,
     77                                               mi->settings.id);
     78   {
     79     struct GNUNET_DB_EventHeaderP es = {
     80       .size = htons (sizeof (es)),
     81       .type = htons (TALER_DBEVENT_MERCHANT_ACCOUNTS_CHANGED)
     82     };
     83 
     84     TMH_db->event_notify (TMH_db->cls,
     85                           &es,
     86                           NULL,
     87                           0);
     88   }
     89   switch (qs)
     90   {
     91   case GNUNET_DB_STATUS_HARD_ERROR:
     92     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   case GNUNET_DB_STATUS_SOFT_ERROR:
     97     GNUNET_break (0);
     98     return TALER_MHD_reply_with_error (connection,
     99                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
    100                                        TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
    101                                        NULL);
    102   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
    103     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   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
    110     TMH_reload_instances (mi->settings.id);
    111     return TALER_MHD_reply_static (connection,
    112                                    MHD_HTTP_NO_CONTENT,
    113                                    NULL,
    114                                    NULL,
    115                                    0);
    116   }
    117   GNUNET_assert (0);
    118   return MHD_NO;
    119 }
    120 
    121 
    122 MHD_RESULT
    123 TMH_private_delete_instances_ID (
    124   const struct TMH_RequestHandler *rh,
    125   struct MHD_Connection *connection,
    126   struct TMH_HandlerContext *hc)
    127 {
    128   struct TMH_MerchantInstance *mi = hc->instance;
    129 
    130   (void) rh;
    131   return delete_instances_ID (hc,
    132                               true,
    133                               mi,
    134                               connection);
    135 }
    136 
    137 
    138 MHD_RESULT
    139 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   mi = TMH_lookup_instance (hc->infix);
    148   if (NULL == mi)
    149   {
    150     return TALER_MHD_reply_with_error (
    151       connection,
    152       MHD_HTTP_NOT_FOUND,
    153       TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN,
    154       hc->infix);
    155   }
    156   return delete_instances_ID (hc,
    157                               false,
    158                               mi,
    159                               connection);
    160 }
    161 
    162 
    163 /* end of taler-merchant-httpd_delete-management-instances-INSTANCE.c */