Line data Source code
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 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-get-webhooks-ID.c 18 : * @brief implement GET /webhooks/$ID 19 : * @author Priscilla HUANG 20 : */ 21 : #include "platform.h" 22 : #include "taler-merchant-httpd_private-get-webhooks-ID.h" 23 : #include <taler/taler_json_lib.h> 24 : 25 : 26 : /** 27 : * Handle a GET "/webhooks/$ID" request. 28 : * 29 : * @param rh context of the handler 30 : * @param connection the MHD connection to handle 31 : * @param[in,out] hc context with further information about the request 32 : * @return MHD result code 33 : */ 34 : MHD_RESULT 35 6 : TMH_private_get_webhooks_ID (const struct TMH_RequestHandler *rh, 36 : struct MHD_Connection *connection, 37 : struct TMH_HandlerContext *hc) 38 : { 39 6 : struct TMH_MerchantInstance *mi = hc->instance; 40 6 : struct TALER_MERCHANTDB_WebhookDetails wb = { 0 }; 41 : enum GNUNET_DB_QueryStatus qs; 42 : 43 6 : GNUNET_assert (NULL != mi); 44 6 : qs = TMH_db->lookup_webhook (TMH_db->cls, 45 6 : mi->settings.id, 46 6 : hc->infix, 47 : &wb); 48 6 : if (0 > qs) 49 : { 50 0 : GNUNET_break (0); 51 0 : return TALER_MHD_reply_with_error (connection, 52 : MHD_HTTP_INTERNAL_SERVER_ERROR, 53 : TALER_EC_GENERIC_DB_FETCH_FAILED, 54 : "lookup_webhook"); 55 : } 56 6 : if (0 == qs) 57 : { 58 2 : return TALER_MHD_reply_with_error (connection, 59 : MHD_HTTP_NOT_FOUND, 60 : TALER_EC_MERCHANT_GENERIC_WEBHOOK_UNKNOWN, 61 2 : hc->infix); 62 : } 63 : { 64 : MHD_RESULT ret; 65 : 66 4 : ret = TALER_MHD_REPLY_JSON_PACK ( 67 : connection, 68 : MHD_HTTP_OK, 69 : GNUNET_JSON_pack_string ("event_type", 70 : wb.event_type), 71 : GNUNET_JSON_pack_string ("url", 72 : wb.url), 73 : GNUNET_JSON_pack_string ("http_method", 74 : wb.http_method), 75 : GNUNET_JSON_pack_allow_null ( 76 : GNUNET_JSON_pack_string ("header_template", 77 : wb.header_template)), 78 : GNUNET_JSON_pack_allow_null ( 79 : GNUNET_JSON_pack_string ("body_template", 80 : wb.body_template))); 81 4 : GNUNET_free (wb.event_type); 82 4 : GNUNET_free (wb.url); 83 4 : GNUNET_free (wb.http_method); 84 4 : GNUNET_free (wb.header_template); 85 4 : GNUNET_free (wb.body_template); 86 : 87 4 : return ret; 88 : } 89 : } 90 : 91 : 92 : /* end of taler-merchant-httpd_private-get-webhooks-ID.c */