taler-auditor-httpd_patch-generic-suppressed.c (4821B)
1 /* 2 This file is part of TALER 3 Copyright (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 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 #include <gnunet/gnunet_util_lib.h> 17 #include <gnunet/gnunet_json_lib.h> 18 #include <jansson.h> 19 #include <microhttpd.h> 20 #include <pthread.h> 21 #include "taler/taler_json_lib.h" 22 #include "taler/taler_mhd_lib.h" 23 #include "taler-auditor-httpd.h" 24 #include "taler-auditor-httpd_patch-generic-suppressed.h" 25 #include "auditor-database/preflight.h" 26 #include "auditor-database/update_generic_suppressed.h" 27 28 29 MHD_RESULT 30 TAH_patch_generic_suppressed ( 31 struct TAH_RequestHandler *rh, 32 struct MHD_Connection *connection, 33 void **connection_cls, 34 const char *upload_data, 35 size_t *upload_data_size, 36 const char *const args[]) 37 { 38 enum GNUNET_DB_QueryStatus qs; 39 unsigned long long row_id; 40 char dummy; 41 bool suppressed; 42 43 (void) connection_cls; 44 if (GNUNET_SYSERR == 45 TALER_AUDITORDB_preflight (TAH_apg)) 46 { 47 GNUNET_break (0); 48 return TALER_MHD_reply_with_error (connection, 49 MHD_HTTP_INTERNAL_SERVER_ERROR, 50 TALER_EC_GENERIC_DB_SETUP_FAILED, 51 NULL); 52 } 53 54 if ( (NULL == args[1]) || 55 (1 != sscanf (args[1], 56 "%llu%c", 57 &row_id, 58 &dummy)) ) 59 { 60 GNUNET_break_op (0); 61 return TALER_MHD_reply_with_error (connection, 62 MHD_HTTP_BAD_REQUEST, 63 TALER_EC_GENERIC_PARAMETER_MALFORMED, 64 "no row id specified"); 65 } 66 67 { 68 enum GNUNET_GenericReturnValue res; 69 json_t *json; 70 struct GNUNET_JSON_Specification spec[] = { 71 GNUNET_JSON_spec_bool ("suppressed", &suppressed), 72 GNUNET_JSON_spec_end () 73 }; 74 75 res = TALER_MHD_parse_post_json (connection, 76 connection_cls, 77 upload_data, 78 upload_data_size, 79 &json); 80 if (GNUNET_SYSERR == res) 81 return MHD_NO; 82 if ((GNUNET_NO == res) || 83 (NULL == json)) 84 return MHD_YES; 85 res = TALER_MHD_parse_json_data (connection, 86 json, 87 spec); 88 if (GNUNET_SYSERR == res) 89 { 90 GNUNET_break (0); 91 json_decref (json); 92 return MHD_NO; /* hard failure */ 93 } 94 if (GNUNET_NO == res) 95 { 96 GNUNET_break_op (0); 97 json_decref (json); 98 return MHD_YES; /* failure */ 99 } 100 json_decref (json); 101 } 102 103 /* execute transaction */ 104 qs = TALER_AUDITORDB_update_generic_suppressed (TAH_apg, 105 rh->table, 106 row_id, 107 suppressed); 108 109 switch (qs) 110 { 111 case GNUNET_DB_STATUS_HARD_ERROR: 112 GNUNET_break (0); 113 return TALER_MHD_reply_with_error (connection, 114 MHD_HTTP_INTERNAL_SERVER_ERROR, 115 TALER_EC_GENERIC_DB_STORE_FAILED, 116 "update_account"); 117 case GNUNET_DB_STATUS_SOFT_ERROR: 118 GNUNET_break (0); 119 return TALER_MHD_reply_with_error (connection, 120 MHD_HTTP_INTERNAL_SERVER_ERROR, 121 TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, 122 "unexpected serialization problem"); 123 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 124 return TALER_MHD_reply_with_error (connection, 125 MHD_HTTP_NOT_FOUND, 126 TALER_EC_AUDITOR_RESOURCE_NOT_FOUND, 127 "no updates executed"); 128 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 129 return TALER_MHD_reply_static (connection, 130 MHD_HTTP_NO_CONTENT, 131 NULL, 132 NULL, 133 0); 134 } 135 GNUNET_break (0); 136 return MHD_NO; 137 }