LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_get-private-reports-REPORT_ID.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 22 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_get-private-reports-REPORT_ID.c
      20              :  * @brief implementation of GET /private/reports/$REPORT_ID
      21              :  * @author Christian Grothoff
      22              :  */
      23              : #include "platform.h"
      24              : #include "taler-merchant-httpd_get-private-reports-REPORT_ID.h"
      25              : #include <taler/taler_json_lib.h>
      26              : #include "merchant-database/get_report.h"
      27              : 
      28              : 
      29              : enum MHD_Result
      30            0 : TMH_private_get_report (const struct TMH_RequestHandler *rh,
      31              :                         struct MHD_Connection *connection,
      32              :                         struct TMH_HandlerContext *hc)
      33              : {
      34            0 :   const char *report_id_str = hc->infix;
      35              :   unsigned long long report_id;
      36              :   char *report_program_section;
      37              :   char *report_description;
      38              :   char *mime_type;
      39              :   char *data_source;
      40              :   char *target_address;
      41              :   struct GNUNET_TIME_Relative frequency;
      42              :   struct GNUNET_TIME_Relative frequency_shift;
      43              :   struct GNUNET_TIME_Absolute next_transmission;
      44              :   enum TALER_ErrorCode last_error_code;
      45              :   char *last_error_detail;
      46              :   enum GNUNET_DB_QueryStatus qs;
      47              : 
      48              :   (void) rh;
      49              : 
      50              :   {
      51              :     char dummy;
      52              : 
      53            0 :     if (1 != sscanf (report_id_str,
      54              :                      "%llu%c",
      55              :                      &report_id,
      56              :                      &dummy))
      57              :     {
      58            0 :       GNUNET_break_op (0);
      59            0 :       return TALER_MHD_reply_with_error (connection,
      60              :                                          MHD_HTTP_BAD_REQUEST,
      61              :                                          TALER_EC_GENERIC_PARAMETER_MALFORMED,
      62              :                                          "report_id");
      63              :     }
      64              :   }
      65              : 
      66            0 :   qs = TALER_MERCHANTDB_get_report (TMH_db,
      67            0 :                                     hc->instance->settings.id,
      68              :                                     (uint64_t) report_id,
      69              :                                     &report_program_section,
      70              :                                     &report_description,
      71              :                                     &mime_type,
      72              :                                     &data_source,
      73              :                                     &target_address,
      74              :                                     &frequency,
      75              :                                     &frequency_shift,
      76              :                                     &next_transmission,
      77              :                                     &last_error_code,
      78              :                                     &last_error_detail);
      79              : 
      80            0 :   if (qs < 0)
      81              :   {
      82            0 :     GNUNET_break (0);
      83            0 :     return TALER_MHD_reply_with_error (connection,
      84              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      85              :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
      86              :                                        "get_report");
      87              :   }
      88            0 :   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
      89              :   {
      90            0 :     return TALER_MHD_reply_with_error (connection,
      91              :                                        MHD_HTTP_NOT_FOUND,
      92              :                                        TALER_EC_MERCHANT_GENERIC_REPORT_UNKNOWN,
      93              :                                        report_id_str);
      94              :   }
      95              : 
      96              :   {
      97              :     json_t *response;
      98              : 
      99            0 :     response = GNUNET_JSON_PACK (
     100              :       GNUNET_JSON_pack_uint64 ("report_serial",
     101              :                                report_id),
     102              :       GNUNET_JSON_pack_string ("description",
     103              :                                report_description),
     104              :       GNUNET_JSON_pack_string ("program_section",
     105              :                                report_program_section),
     106              :       GNUNET_JSON_pack_string ("mime_type",
     107              :                                mime_type),
     108              :       GNUNET_JSON_pack_string ("data_source",
     109              :                                data_source),
     110              :       GNUNET_JSON_pack_string ("target_address",
     111              :                                target_address),
     112              :       GNUNET_JSON_pack_allow_null (
     113              :         GNUNET_JSON_pack_string ("last_error_detail",
     114              :                                  last_error_detail)),
     115              :       GNUNET_JSON_pack_time_rel ("report_frequency",
     116              :                                  frequency),
     117              :       GNUNET_JSON_pack_time_rel ("report_frequency_shift",
     118              :                                  frequency_shift),
     119              :       GNUNET_JSON_pack_timestamp (
     120              :         "next_transmission",
     121              :         GNUNET_TIME_absolute_to_timestamp (next_transmission)));
     122            0 :     GNUNET_free (report_program_section);
     123            0 :     GNUNET_free (report_description);
     124            0 :     GNUNET_free (mime_type);
     125            0 :     GNUNET_free (data_source);
     126            0 :     GNUNET_free (target_address);
     127            0 :     GNUNET_free (last_error_detail);
     128            0 :     if (TALER_EC_NONE != last_error_code)
     129              :     {
     130            0 :       GNUNET_assert (0 ==
     131              :                      json_object_set_new (response,
     132              :                                           "last_error_code",
     133              :                                           json_integer (last_error_code)));
     134              :     }
     135            0 :     return TALER_MHD_reply_json_steal (connection,
     136              :                                        response,
     137              :                                        MHD_HTTP_OK);
     138              :   }
     139              : }
        

Generated by: LCOV version 2.0-1