LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_patch-private-webhooks-WEBHOOK_ID.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 75.0 % 36 27
Test Date: 2026-09-04 23:42:01 Functions: 100.0 % 1 1

            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
       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 src/backend/taler-merchant-httpd_patch-private-webhooks-WEBHOOK_ID.c
      22              :  * @brief implementing PATCH /webhooks/$ID request handling
      23              :  * @author Priscilla HUANG
      24              :  */
      25              : #include "platform.h"
      26              : #include "taler-merchant-httpd_patch-private-webhooks-WEBHOOK_ID.h"
      27              : #include "taler-merchant-httpd_helper.h"
      28              : #include <taler/taler_json_lib.h>
      29              : #include "merchant-database/update_webhook.h"
      30              : 
      31              : 
      32              : /**
      33              :  * PATCH configuration of an existing instance, given its configuration.
      34              :  *
      35              :  * @param rh context of the handler
      36              :  * @param connection the MHD connection to handle
      37              :  * @param[in,out] hc context with further information about the request
      38              :  * @return MHD result code
      39              :  */
      40              : enum MHD_Result
      41            4 : TMH_private_patch_webhooks_ID (const struct TMH_RequestHandler *rh,
      42              :                                struct MHD_Connection *connection,
      43              :                                struct TMH_HandlerContext *hc)
      44              : {
      45            4 :   struct TMH_MerchantInstance *mi = hc->instance;
      46            4 :   const char *webhook_id = hc->infix;
      47            4 :   struct TALER_MERCHANTDB_WebhookDetails wb = {0};
      48              :   enum GNUNET_DB_QueryStatus qs;
      49              :   struct GNUNET_JSON_Specification spec[] = {
      50            4 :     GNUNET_JSON_spec_string ("event_type",
      51              :                              (const char **) &wb.event_type),
      52            4 :     TALER_JSON_spec_web_url ("url",
      53              :                              (const char **) &wb.url),
      54            4 :     GNUNET_JSON_spec_string ("http_method",
      55              :                              (const char **) &wb.http_method),
      56            4 :     GNUNET_JSON_spec_mark_optional (
      57              :       GNUNET_JSON_spec_string ("header_template",
      58              :                                (const char **) &wb.header_template),
      59              :       NULL),
      60            4 :     GNUNET_JSON_spec_mark_optional (
      61              :       GNUNET_JSON_spec_string ("body_template",
      62              :                                (const char **) &wb.body_template),
      63              :       NULL),
      64            4 :     GNUNET_JSON_spec_end ()
      65              :   };
      66              : 
      67            4 :   GNUNET_assert (NULL != mi);
      68            4 :   GNUNET_assert (NULL != webhook_id);
      69              :   {
      70              :     enum GNUNET_GenericReturnValue res;
      71              : 
      72            4 :     res = TALER_MHD_parse_json_data (connection,
      73            4 :                                      hc->request_body,
      74              :                                      spec);
      75            4 :     if (GNUNET_OK != res)
      76              :       return (GNUNET_NO == res)
      77              :              ? MHD_YES
      78            0 :              : MHD_NO;
      79              :   }
      80              : 
      81            4 :   qs = TALER_MERCHANTDB_update_webhook (TMH_db,
      82            4 :                                         mi->settings.id,
      83              :                                         webhook_id,
      84              :                                         &wb);
      85              :   {
      86            4 :     enum MHD_Result ret = MHD_NO;
      87              : 
      88            4 :     switch (qs)
      89              :     {
      90            0 :     case GNUNET_DB_STATUS_HARD_ERROR:
      91            0 :       GNUNET_break (0);
      92            0 :       ret = TALER_MHD_reply_with_error (
      93              :         connection,
      94              :         MHD_HTTP_INTERNAL_SERVER_ERROR,
      95              :         TALER_EC_GENERIC_DB_STORE_FAILED,
      96              :         NULL);
      97            0 :       break;
      98            0 :     case GNUNET_DB_STATUS_SOFT_ERROR:
      99            0 :       GNUNET_break (0);
     100            0 :       ret = TALER_MHD_reply_with_error (
     101              :         connection,
     102              :         MHD_HTTP_INTERNAL_SERVER_ERROR,
     103              :         TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
     104              :         "unexpected serialization problem");
     105            0 :       break;
     106            2 :     case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     107            2 :       ret = TALER_MHD_reply_with_error (
     108              :         connection,
     109              :         MHD_HTTP_NOT_FOUND,
     110              :         TALER_EC_MERCHANT_GENERIC_WEBHOOK_UNKNOWN,
     111              :         webhook_id);
     112            2 :       break;
     113            2 :     case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     114            2 :       ret = TALER_MHD_reply_static (connection,
     115              :                                     MHD_HTTP_NO_CONTENT,
     116              :                                     NULL,
     117              :                                     NULL,
     118              :                                     0);
     119            2 :       break;
     120              :     }
     121            4 :     GNUNET_JSON_parse_free (spec);
     122            4 :     return ret;
     123              :   }
     124              : }
     125              : 
     126              : 
     127              : /* end of taler-merchant-httpd_patch-private-webhooks-WEBHOOK_ID.c */
        

Generated by: LCOV version 2.0-1