LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-patch-pot-ID.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 28 0
Test Date: 2025-12-29 21:26:17 Functions: 0.0 % 1 0

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   (C) 2025 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 Affero General Public License for more
      12              :   details.
      13              : 
      14              :   You should have received a copy of the GNU Affero General Public License
      15              :   along with TALER; see the file COPYING.  If not, see
      16              :   <http://www.gnu.org/licenses/>
      17              : */
      18              : /**
      19              :  * @file merchant/backend/taler-merchant-httpd_private-patch-pot.c
      20              :  * @brief implementation of PATCH /private/pots/$POT_ID
      21              :  * @author Christian Grothoff
      22              :  */
      23              : #include "platform.h"
      24              : #include "taler-merchant-httpd_private-patch-pot-ID.h"
      25              : #include <taler/taler_json_lib.h>
      26              : 
      27              : 
      28              : MHD_RESULT
      29            0 : TMH_private_patch_pot (const struct TMH_RequestHandler *rh,
      30              :                        struct MHD_Connection *connection,
      31              :                        struct TMH_HandlerContext *hc)
      32              : {
      33            0 :   const char *pot_id_str = hc->infix;
      34              :   unsigned long long pot_id;
      35              :   const char *pot_name;
      36              :   const char *description;
      37              :   size_t expected_pot_total_len;
      38              :   struct TALER_Amount *expected_pot_totals;
      39              :   bool no_expected_total;
      40              :   size_t new_pot_total_len;
      41              :   struct TALER_Amount *new_pot_totals;
      42              :   bool no_new_total;
      43              :   enum GNUNET_DB_QueryStatus qs;
      44              :   bool conflict_total;
      45              :   bool conflict_name;
      46              :   struct GNUNET_JSON_Specification spec[] = {
      47            0 :     GNUNET_JSON_spec_string ("pot_name",
      48              :                              &pot_name),
      49            0 :     GNUNET_JSON_spec_string ("description",
      50              :                              &description),
      51            0 :     GNUNET_JSON_spec_mark_optional (
      52              :       TALER_JSON_spec_amount_any_array ("expected_pot_total",
      53              :                                         &expected_pot_total_len,
      54              :                                         &expected_pot_totals),
      55              :       &no_expected_total),
      56            0 :     GNUNET_JSON_spec_mark_optional (
      57              :       TALER_JSON_spec_amount_any_array ("new_pot_totals",
      58              :                                         &new_pot_total_len,
      59              :                                         &new_pot_totals),
      60              :       &no_new_total),
      61            0 :     GNUNET_JSON_spec_end ()
      62              :   };
      63              : 
      64              :   (void) rh;
      65              :   {
      66              :     char dummy;
      67              : 
      68            0 :     if (1 != sscanf (pot_id_str,
      69              :                      "%llu%c",
      70              :                      &pot_id,
      71              :                      &dummy))
      72              :     {
      73            0 :       GNUNET_break_op (0);
      74            0 :       return TALER_MHD_reply_with_error (connection,
      75              :                                          MHD_HTTP_BAD_REQUEST,
      76              :                                          TALER_EC_GENERIC_PARAMETER_MALFORMED,
      77              :                                          "pot_id");
      78              :     }
      79              :   }
      80              : 
      81              :   {
      82              :     enum GNUNET_GenericReturnValue res;
      83              : 
      84            0 :     res = TALER_MHD_parse_json_data (connection,
      85            0 :                                      hc->request_body,
      86              :                                      spec);
      87            0 :     if (GNUNET_OK != res)
      88              :     {
      89            0 :       GNUNET_break_op (0);
      90              :       return (GNUNET_NO == res)
      91              :              ? MHD_YES
      92            0 :              : MHD_NO;
      93              :     }
      94              :   }
      95              : 
      96            0 :   qs = TMH_db->update_money_pot (TMH_db->cls,
      97            0 :                                  hc->instance->settings.id,
      98              :                                  pot_id,
      99              :                                  pot_name,
     100              :                                  description,
     101              :                                  expected_pot_total_len,
     102              :                                  no_expected_total
     103              :                                  ? NULL
     104              :                                  : expected_pot_totals,
     105              :                                  new_pot_total_len,
     106              :                                  no_new_total
     107              :                                  ? NULL
     108              :                                  : new_pot_totals,
     109              :                                  &conflict_total,
     110              :                                  &conflict_name);
     111            0 :   GNUNET_JSON_parse_free (spec);
     112            0 :   if (qs < 0)
     113              :   {
     114            0 :     GNUNET_break (0);
     115            0 :     return TALER_MHD_reply_with_error (connection,
     116              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     117              :                                        TALER_EC_GENERIC_DB_STORE_FAILED,
     118              :                                        "update_money_pot");
     119              :   }
     120            0 :   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
     121              :   {
     122            0 :     return TALER_MHD_reply_with_error (
     123              :       connection,
     124              :       MHD_HTTP_NOT_FOUND,
     125              :       TALER_EC_MERCHANT_GENERIC_MONEY_POT_UNKNOWN,
     126              :       pot_id_str);
     127              :   }
     128            0 :   if (conflict_total)
     129              :   {
     130              :     /* Pot total mismatch - expected_pot_total didn't match current value */
     131            0 :     return TALER_MHD_reply_with_error (
     132              :       connection,
     133              :       MHD_HTTP_CONFLICT,
     134              :       TALER_EC_MERCHANT_PRIVATE_MONEY_POT_CONFLICTING_TOTAL,
     135              :       NULL);
     136              :   }
     137            0 :   if (conflict_name)
     138              :   {
     139              :     /* Pot name conflict - name exists */
     140            0 :     return TALER_MHD_reply_with_error (
     141              :       connection,
     142              :       MHD_HTTP_CONFLICT,
     143              :       TALER_EC_MERCHANT_PRIVATE_MONEY_POT_CONFLICTING_NAME,
     144              :       pot_name);
     145              :   }
     146              : 
     147            0 :   return TALER_MHD_reply_static (connection,
     148              :                                  MHD_HTTP_NO_CONTENT,
     149              :                                  NULL,
     150              :                                  NULL,
     151              :                                  0);
     152              : }
        

Generated by: LCOV version 2.0-1