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