merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

taler-merchant-httpd_get-private-reports-REPORT_ID.c (4926B)


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