LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_post-reports-ID.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 35 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_post-reports-ID.c
      20              :  * @brief implementation of POST /reports/$REPORT_ID
      21              :  * @author Christian Grothoff
      22              :  */
      23              : #include "platform.h"
      24              : #include "taler-merchant-httpd_dispatcher.h"
      25              : #include "taler-merchant-httpd_post-reports-ID.h"
      26              : #include <taler/taler_json_lib.h>
      27              : 
      28              : 
      29              : MHD_RESULT
      30            0 : TMH_post_reports_ID (
      31              :   const struct TMH_RequestHandler *rh,
      32              :   struct MHD_Connection *connection,
      33              :   struct TMH_HandlerContext *hc)
      34              : {
      35            0 :   const char *report_id_str = hc->infix;
      36              :   unsigned long long report_id;
      37              :   const char *mime_type;
      38              :   struct TALER_MERCHANT_ReportToken report_token;
      39              :   struct GNUNET_JSON_Specification spec[] = {
      40            0 :     GNUNET_JSON_spec_fixed_auto ("report_token",
      41              :                                  &report_token),
      42            0 :     GNUNET_JSON_spec_end ()
      43              :   };
      44              :   enum GNUNET_DB_QueryStatus qs;
      45              :   char *instance_id;
      46              :   char *data_source;
      47              : 
      48              :   {
      49              :     char dummy;
      50              : 
      51            0 :     if (1 != sscanf (report_id_str,
      52              :                      "%llu%c",
      53              :                      &report_id,
      54              :                      &dummy))
      55              :     {
      56            0 :       GNUNET_break_op (0);
      57            0 :       return TALER_MHD_reply_with_error (connection,
      58              :                                          MHD_HTTP_BAD_REQUEST,
      59              :                                          TALER_EC_GENERIC_PARAMETER_MALFORMED,
      60              :                                          "report_id");
      61              :     }
      62              :   }
      63              : 
      64              :   {
      65              :     enum GNUNET_GenericReturnValue res;
      66              : 
      67            0 :     res = TALER_MHD_parse_json_data (connection,
      68            0 :                                      hc->request_body,
      69              :                                      spec);
      70            0 :     if (GNUNET_OK != res)
      71              :     {
      72            0 :       GNUNET_break_op (0);
      73              :       return (GNUNET_NO == res)
      74              :         ? MHD_YES
      75            0 :         : MHD_NO;
      76              :     }
      77              :   }
      78              : 
      79            0 :   mime_type = MHD_lookup_connection_value (connection,
      80              :                                            MHD_HEADER_KIND,
      81              :                                            MHD_HTTP_HEADER_ACCEPT);
      82            0 :   if (NULL == mime_type)
      83            0 :     mime_type = "application/json";
      84            0 :   qs = TMH_db->check_report (TMH_db->cls,
      85              :                              report_id,
      86              :                              &report_token,
      87              :                              mime_type,
      88              :                              &instance_id,
      89              :                              &data_source);
      90            0 :   if (qs < 0)
      91              :   {
      92            0 :     GNUNET_break (0);
      93            0 :     return TALER_MHD_reply_with_error (connection,
      94              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      95              :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
      96              :                                        "check_report");
      97              :   }
      98            0 :   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
      99              :   {
     100            0 :     return TALER_MHD_reply_with_error (connection,
     101              :                                        MHD_HTTP_NOT_FOUND,
     102              :                                        TALER_EC_MERCHANT_GENERIC_REPORT_UNKNOWN,
     103              :                                        report_id_str);
     104              :   }
     105              : 
     106              :   {
     107              :     struct TMH_MerchantInstance *mi;
     108              : 
     109            0 :     mi = TMH_lookup_instance (instance_id);
     110            0 :     if (NULL == mi)
     111              :     {
     112              :       /* Strange, we found the report but the instance of the
     113              :          report is not known. This should basically be impossible
     114              :          modulo maybe some transactional issue where the
     115              :          instance was created, the report added *and* triggered
     116              :          before this process was able to process the notification
     117              :          about the new instance. Wild. */
     118            0 :       GNUNET_break (0);
     119            0 :       return TALER_MHD_reply_with_error (connection,
     120              :                                          MHD_HTTP_NOT_FOUND,
     121              :                                          TALER_EC_MERCHANT_GENERIC_REPORT_UNKNOWN,
     122              :                                          report_id_str);
     123              :     }
     124              :     /* Rewrite request: force instance to match report */
     125            0 :     hc->instance = mi;
     126              :   }
     127              :   {
     128              :     enum GNUNET_GenericReturnValue ret;
     129              :     bool is_public; /* ignored: access control never applies for reports */
     130              : 
     131              :     /* This rewrite request: force request handler to match report! */
     132            0 :     hc->rh = NULL; /* just to make it clear: current one will NOT remain */
     133            0 :     ret = TMH_dispatch_request (hc,
     134              :                                 data_source,
     135              :                                 MHD_HTTP_METHOD_GET,
     136            0 :                                 0 == strcmp ("admin",
     137              :                                              instance_id),
     138              :                                 &is_public);
     139            0 :     if (GNUNET_OK != ret)
     140            0 :       return (GNUNET_NO == ret) ? MHD_YES : MHD_NO;
     141            0 :     GNUNET_break (NULL != hc->rh);
     142              :   }
     143            0 :   GNUNET_free (instance_id);
     144            0 :   GNUNET_free (data_source);
     145              :   /* MHD will call the main handler again, which will now
     146              :      dispatch into the _new_ handler callback we just installed! */
     147            0 :   return MHD_YES;
     148              : }
        

Generated by: LCOV version 2.0-1