Line data Source code
1 : /* 2 : This file is part of TALER 3 : (C) 2020-2021 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 : 25 : 26 : /** 27 : * Handle a DELETE "/instances/$ID" request. 28 : * 29 : * @param mi instance to delete 30 : * @param connection the MHD connection to handle 31 : * @return MHD result code 32 : */ 33 : static MHD_RESULT 34 0 : delete_instances_ID (struct TMH_MerchantInstance *mi, 35 : struct MHD_Connection *connection) 36 : { 37 : const char *purge_s; 38 : bool purge; 39 : enum GNUNET_DB_QueryStatus qs; 40 : 41 0 : GNUNET_assert (NULL != mi); 42 0 : purge_s = MHD_lookup_connection_value (connection, 43 : MHD_GET_ARGUMENT_KIND, 44 : "purge"); 45 0 : if (NULL == purge_s) 46 0 : purge_s = "no"; 47 0 : purge = (0 == strcasecmp (purge_s, 48 : "yes")); 49 0 : if (purge) 50 0 : qs = TMH_db->purge_instance (TMH_db->cls, 51 0 : mi->settings.id); 52 : else 53 0 : qs = TMH_db->delete_instance_private_key (TMH_db->cls, 54 0 : mi->settings.id); 55 0 : switch (qs) 56 : { 57 0 : case GNUNET_DB_STATUS_HARD_ERROR: 58 0 : return TALER_MHD_reply_with_error (connection, 59 : MHD_HTTP_INTERNAL_SERVER_ERROR, 60 : TALER_EC_GENERIC_DB_STORE_FAILED, 61 : "delete private key"); 62 0 : case GNUNET_DB_STATUS_SOFT_ERROR: 63 0 : GNUNET_break (0); 64 0 : return TALER_MHD_reply_with_error (connection, 65 : MHD_HTTP_INTERNAL_SERVER_ERROR, 66 : TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, 67 : NULL); 68 0 : case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 69 0 : return TALER_MHD_reply_with_error (connection, 70 : MHD_HTTP_NOT_FOUND, 71 : TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN, 72 : purge 73 : ? "Instance unknown" 74 : : "Private key unknown"); 75 0 : case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 76 0 : TMH_reload_instances (mi->settings.id); 77 0 : return TALER_MHD_reply_static (connection, 78 : MHD_HTTP_NO_CONTENT, 79 : NULL, 80 : NULL, 81 : 0); 82 : } 83 0 : GNUNET_assert (0); 84 : return MHD_NO; 85 : } 86 : 87 : 88 : MHD_RESULT 89 0 : TMH_private_delete_instances_ID (const struct TMH_RequestHandler *rh, 90 : struct MHD_Connection *connection, 91 : struct TMH_HandlerContext *hc) 92 : { 93 0 : struct TMH_MerchantInstance *mi = hc->instance; 94 : 95 : (void) rh; 96 0 : return delete_instances_ID (mi, 97 : connection); 98 : } 99 : 100 : 101 : MHD_RESULT 102 0 : TMH_private_delete_instances_default_ID (const struct TMH_RequestHandler *rh, 103 : struct MHD_Connection *connection, 104 : struct TMH_HandlerContext *hc) 105 : { 106 : struct TMH_MerchantInstance *mi; 107 : 108 : (void) rh; 109 0 : mi = TMH_lookup_instance (hc->infix); 110 0 : if (NULL == mi) 111 : { 112 0 : return TALER_MHD_reply_with_error (connection, 113 : MHD_HTTP_NOT_FOUND, 114 : TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN, 115 0 : hc->infix); 116 : } 117 0 : return delete_instances_ID (mi, 118 : connection); 119 : } 120 : 121 : 122 : /* end of taler-merchant-httpd_private-delete-instances-ID.c */