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