taler-merchant-httpd_private-delete-donau-instance-ID.c (3487B)
1 /* 2 This file is part of TALER 3 (C) 2024 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-donau-instance-ID.c 18 * @brief implement DELETE /private/donau/$donau_serial_id 19 * @author Bohdan Potuzhnyi 20 * @author Vlada Svirsh 21 */ 22 23 #include "platform.h" 24 #include "taler-merchant-httpd_private-delete-donau-instance-ID.h" 25 #include <taler/taler_json_lib.h> 26 #include <taler/taler_error_codes.h> 27 #include <taler/taler_dbevents.h> 28 29 /** 30 * Handle a DELETE "/donau/$donau_serial_id/" request. 31 * 32 * @param rh context of the handler 33 * @param connection the MHD connection to handle 34 * @param[in,out] hc context with further information about the request 35 * @return MHD result code 36 */ 37 MHD_RESULT 38 TMH_private_delete_donau_instance_ID (const struct TMH_RequestHandler *rh, 39 struct MHD_Connection *connection, 40 struct TMH_HandlerContext *hc) 41 { 42 struct TMH_MerchantInstance *mi = hc->instance; 43 enum GNUNET_DB_QueryStatus qs; 44 uint64_t donau_serial_id; 45 char dummy; 46 47 GNUNET_assert (NULL != mi); 48 49 if (1 != sscanf (hc->infix, 50 "%lu%c", 51 &donau_serial_id, 52 &dummy)) 53 { 54 return TALER_MHD_reply_with_error (connection, 55 MHD_HTTP_BAD_REQUEST, 56 TALER_EC_GENERIC_PARAMETER_MALFORMED, 57 hc->infix); 58 } 59 60 qs = TMH_db->delete_donau_instance (TMH_db->cls, 61 hc->instance->settings.id, 62 donau_serial_id); 63 switch (qs) 64 { 65 case GNUNET_DB_STATUS_HARD_ERROR: 66 return TALER_MHD_reply_with_error (connection, 67 MHD_HTTP_INTERNAL_SERVER_ERROR, 68 TALER_EC_GENERIC_DB_STORE_FAILED, 69 "delete_donau_instance"); 70 71 case GNUNET_DB_STATUS_SOFT_ERROR: 72 GNUNET_break (0); 73 return TALER_MHD_reply_with_error (connection, 74 MHD_HTTP_INTERNAL_SERVER_ERROR, 75 TALER_EC_GENERIC_DB_SOFT_FAILURE, 76 "delete_donau_instance (soft)"); 77 78 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 79 return TALER_MHD_reply_with_error (connection, 80 MHD_HTTP_NOT_FOUND, 81 TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN, 82 hc->infix); 83 84 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 85 return TALER_MHD_reply_static (connection, 86 MHD_HTTP_NO_CONTENT, 87 NULL, 88 NULL, 89 0); 90 } 91 GNUNET_assert (0); 92 return MHD_NO; 93 }