taler-merchant-httpd_private-patch-otp-devices-ID.c (3991B)
1 /* 2 This file is part of TALER 3 (C) 2022 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify 6 it under the terms of the GNU Affero General Public License as 7 published by the Free Software Foundation; either version 3, 8 or (at your option) any later version. 9 10 TALER is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public 16 License along with TALER; see the file COPYING. If not, 17 see <http://www.gnu.org/licenses/> 18 */ 19 20 /** 21 * @file taler-merchant-httpd_private-patch-otp-devices-ID.c 22 * @brief implementing PATCH /otp-devices/$ID request handling 23 * @author Christian Grothoff 24 */ 25 #include "platform.h" 26 #include "taler-merchant-httpd_private-patch-otp-devices-ID.h" 27 #include "taler-merchant-httpd_helper.h" 28 #include <taler/taler_json_lib.h> 29 30 31 MHD_RESULT 32 TMH_private_patch_otp_devices_ID (const struct TMH_RequestHandler *rh, 33 struct MHD_Connection *connection, 34 struct TMH_HandlerContext *hc) 35 { 36 struct TMH_MerchantInstance *mi = hc->instance; 37 const char *device_id = hc->infix; 38 struct TALER_MERCHANTDB_OtpDeviceDetails tp = {0}; 39 enum GNUNET_DB_QueryStatus qs; 40 struct GNUNET_JSON_Specification spec[] = { 41 GNUNET_JSON_spec_string ("otp_device_description", 42 (const char **) &tp.otp_description), 43 TALER_JSON_spec_otp_type ("otp_algorithm", 44 &tp.otp_algorithm), 45 GNUNET_JSON_spec_mark_optional ( 46 GNUNET_JSON_spec_uint64 ("otp_ctr", 47 &tp.otp_ctr), 48 NULL), 49 GNUNET_JSON_spec_mark_optional( 50 51 TALER_JSON_spec_otp_key ("otp_key", 52 (const char **) &tp.otp_key), 53 NULL), 54 GNUNET_JSON_spec_end () 55 }; 56 57 GNUNET_assert (NULL != mi); 58 GNUNET_assert (NULL != device_id); 59 { 60 enum GNUNET_GenericReturnValue res; 61 62 res = TALER_MHD_parse_json_data (connection, 63 hc->request_body, 64 spec); 65 if (GNUNET_OK != res) 66 return (GNUNET_NO == res) 67 ? MHD_YES 68 : MHD_NO; 69 } 70 71 qs = TMH_db->update_otp (TMH_db->cls, 72 mi->settings.id, 73 device_id, 74 &tp); 75 { 76 MHD_RESULT ret = MHD_NO; 77 78 switch (qs) 79 { 80 case GNUNET_DB_STATUS_HARD_ERROR: 81 GNUNET_break (0); 82 ret = TALER_MHD_reply_with_error (connection, 83 MHD_HTTP_INTERNAL_SERVER_ERROR, 84 TALER_EC_GENERIC_DB_STORE_FAILED, 85 "update_pos"); 86 break; 87 case GNUNET_DB_STATUS_SOFT_ERROR: 88 GNUNET_break (0); 89 ret = TALER_MHD_reply_with_error (connection, 90 MHD_HTTP_INTERNAL_SERVER_ERROR, 91 TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE, 92 "unexpected serialization problem"); 93 break; 94 case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: 95 ret = TALER_MHD_reply_with_error (connection, 96 MHD_HTTP_NOT_FOUND, 97 TALER_EC_MERCHANT_GENERIC_OTP_DEVICE_UNKNOWN, 98 device_id); 99 break; 100 case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: 101 ret = TALER_MHD_reply_static (connection, 102 MHD_HTTP_NO_CONTENT, 103 NULL, 104 NULL, 105 0); 106 break; 107 } 108 GNUNET_JSON_parse_free (spec); 109 return ret; 110 } 111 } 112 113 114 /* end of taler-merchant-httpd_private-patch-otp-devices-ID.c */