LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_patch-private-reports-REPORT_ID.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 34 0
Test Date: 2026-09-04 23:42:01 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 src/backend/taler-merchant-httpd_patch-private-reports-REPORT_ID.c
      20              :  * @brief implementation of PATCH /private/reports/$REPORT_ID
      21              :  * @author Christian Grothoff
      22              :  */
      23              : #include "platform.h"
      24              : #include "taler-merchant-httpd_patch-private-reports-REPORT_ID.h"
      25              : #include <taler/taler_json_lib.h>
      26              : #include <taler/taler_dbevents.h>
      27              : #include "merchant-database/update_report.h"
      28              : #include "merchant-database/event_notify.h"
      29              : 
      30              : 
      31              : enum MHD_Result
      32            0 : TMH_private_patch_report (const struct TMH_RequestHandler *rh,
      33              :                           struct MHD_Connection *connection,
      34              :                           struct TMH_HandlerContext *hc)
      35              : {
      36            0 :   const char *report_id_str = hc->infix;
      37              :   unsigned long long report_id;
      38              :   const char *description;
      39              :   const char *program_section;
      40              :   const char *mime_type;
      41              :   const char *data_source;
      42              :   const char *target_address;
      43              :   struct GNUNET_TIME_Relative frequency;
      44            0 :   struct GNUNET_TIME_Relative frequency_shift
      45              :     = GNUNET_TIME_UNIT_ZERO;
      46              :   enum GNUNET_DB_QueryStatus qs;
      47              :   struct GNUNET_JSON_Specification spec[] = {
      48            0 :     GNUNET_JSON_spec_string ("description",
      49              :                              &description),
      50            0 :     GNUNET_JSON_spec_string ("program_section",
      51              :                              &program_section),
      52            0 :     GNUNET_JSON_spec_string ("mime_type",
      53              :                              &mime_type),
      54            0 :     GNUNET_JSON_spec_string ("data_source",
      55              :                              &data_source),
      56            0 :     GNUNET_JSON_spec_string ("target_address",
      57              :                              &target_address),
      58            0 :     GNUNET_JSON_spec_relative_time ("report_frequency",
      59              :                                     &frequency),
      60            0 :     GNUNET_JSON_spec_mark_optional (
      61              :       GNUNET_JSON_spec_relative_time ("report_frequency_shift",
      62              :                                       &frequency_shift),
      63              :       NULL),
      64            0 :     GNUNET_JSON_spec_end ()
      65              :   };
      66              : 
      67              :   (void) rh;
      68              :   {
      69              :     char dummy;
      70              : 
      71            0 :     if (1 != sscanf (report_id_str,
      72              :                      "%llu%c",
      73              :                      &report_id,
      74              :                      &dummy))
      75              :     {
      76            0 :       GNUNET_break_op (0);
      77            0 :       return TALER_MHD_reply_with_error (connection,
      78              :                                          MHD_HTTP_BAD_REQUEST,
      79              :                                          TALER_EC_GENERIC_PARAMETER_MALFORMED,
      80              :                                          "report_id");
      81              :     }
      82              :   }
      83              : 
      84              :   {
      85              :     enum GNUNET_GenericReturnValue res;
      86              : 
      87            0 :     res = TALER_MHD_parse_json_data (connection,
      88            0 :                                      hc->request_body,
      89              :                                      spec);
      90            0 :     if (GNUNET_OK != res)
      91              :     {
      92            0 :       GNUNET_break_op (0);
      93              :       return (GNUNET_NO == res)
      94              :              ? MHD_YES
      95            0 :              : MHD_NO;
      96              :     }
      97              :   }
      98            0 :   if ('/' != data_source[0])
      99              :   {
     100            0 :     GNUNET_break_op (0);
     101            0 :     return TALER_MHD_reply_with_error (connection,
     102              :                                        MHD_HTTP_BAD_REQUEST,
     103              :                                        TALER_EC_GENERIC_PARAMETER_MALFORMED,
     104              :                                        "data_source");
     105              : 
     106              :   }
     107              : 
     108            0 :   qs = TALER_MERCHANTDB_update_report (TMH_db,
     109            0 :                                        hc->instance->settings.id,
     110              :                                        report_id,
     111              :                                        program_section,
     112              :                                        description,
     113              :                                        mime_type,
     114              :                                        data_source,
     115              :                                        target_address,
     116              :                                        frequency,
     117              :                                        frequency_shift);
     118            0 :   if (qs < 0)
     119              :   {
     120            0 :     GNUNET_break (0);
     121            0 :     return TALER_MHD_reply_with_error (connection,
     122              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     123              :                                        TALER_EC_GENERIC_DB_STORE_FAILED,
     124              :                                        "update_report");
     125              :   }
     126            0 :   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
     127              :   {
     128            0 :     return TALER_MHD_reply_with_error (connection,
     129              :                                        MHD_HTTP_NOT_FOUND,
     130              :                                        TALER_EC_MERCHANT_GENERIC_REPORT_UNKNOWN,
     131              :                                        report_id_str);
     132              :   }
     133              : 
     134              :   /* FIXME-Optimization: Trigger MERCHANT_REPORT_UPDATE event inside of UPDATE transaction */
     135              :   {
     136            0 :     struct GNUNET_DB_EventHeaderP ev = {
     137            0 :       .size = htons (sizeof (ev)),
     138            0 :       .type = htons (TALER_DBEVENT_MERCHANT_REPORT_UPDATE)
     139              :     };
     140              : 
     141            0 :     TALER_MERCHANTDB_event_notify (TMH_db,
     142              :                                    &ev,
     143              :                                    NULL,
     144              :                                    0);
     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