LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-get-tips-ID.c (source / functions) Hit Total Coverage
Test: GNU Taler merchant coverage report Lines: 0 46 0.0 %
Date: 2022-08-25 06:17:04 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   (C) 2017-2021 Taler Systems SA
       4             : 
       5             :   TALER is free software; you can redistribute it and/or modify it under the
       6             :   terms of the GNU 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 General Public License for more details.
      12             : 
      13             :   You should have received a copy of the GNU General Public License along with
      14             :   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
      15             : */
      16             : /**
      17             :  * @file taler-merchant-httpd_get-tips-ID.c
      18             :  * @brief implementation of a GET /tips/ID handler
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "platform.h"
      22             : #include <microhttpd.h>
      23             : #include <jansson.h>
      24             : #include <taler/taler_json_lib.h>
      25             : #include <taler/taler_signatures.h>
      26             : #include "taler-merchant-httpd.h"
      27             : #include "taler-merchant-httpd_mhd.h"
      28             : #include "taler-merchant-httpd_exchanges.h"
      29             : 
      30             : 
      31             : MHD_RESULT
      32           0 : TMH_private_get_tips_ID (const struct TMH_RequestHandler *rh,
      33             :                          struct MHD_Connection *connection,
      34             :                          struct TMH_HandlerContext *hc)
      35             : {
      36             :   struct TALER_TipIdentifierP tip_id;
      37             :   struct TALER_Amount total_authorized;
      38             :   struct TALER_Amount total_picked_up;
      39             :   char *reason;
      40             :   struct GNUNET_TIME_Timestamp expiration;
      41             :   struct TALER_ReservePublicKeyP reserve_pub;
      42           0 :   unsigned int pickups_length = 0;
      43           0 :   struct TALER_MERCHANTDB_PickupDetails *pickups = NULL;
      44             :   enum GNUNET_DB_QueryStatus qs;
      45             :   bool fpu;
      46           0 :   json_t *pickups_json = NULL;
      47             : 
      48             :   (void) rh;
      49           0 :   GNUNET_assert (NULL != hc->infix);
      50             :   // FIXME: support long-polling (client-side already implemented)
      51           0 :   if (GNUNET_OK !=
      52           0 :       GNUNET_CRYPTO_hash_from_string (hc->infix,
      53             :                                       &tip_id.hash))
      54             :   {
      55             :     /* tip_id has wrong encoding */
      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           0 :                                        hc->infix);
      61             :   }
      62             :   {
      63             :     const char *pstr;
      64             : 
      65           0 :     pstr = MHD_lookup_connection_value (connection,
      66             :                                         MHD_GET_ARGUMENT_KIND,
      67             :                                         "pickups");
      68           0 :     fpu = (NULL != pstr)
      69           0 :           ? 0 == strcasecmp (pstr, "yes")
      70           0 :           : false;
      71             :   }
      72           0 :   TMH_db->preflight (TMH_db->cls);
      73           0 :   qs = TMH_db->lookup_tip_details (TMH_db->cls,
      74           0 :                                    hc->instance->settings.id,
      75             :                                    &tip_id,
      76             :                                    fpu,
      77             :                                    &total_authorized,
      78             :                                    &total_picked_up,
      79             :                                    &reason,
      80             :                                    &expiration,
      81             :                                    &reserve_pub,
      82             :                                    &pickups_length,
      83             :                                    &pickups);
      84           0 :   if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
      85             :   {
      86             :     unsigned int response_code;
      87             :     enum TALER_ErrorCode ec;
      88             : 
      89           0 :     switch (qs)
      90             :     {
      91           0 :     case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
      92           0 :       ec = TALER_EC_MERCHANT_GENERIC_TIP_ID_UNKNOWN;
      93           0 :       response_code = MHD_HTTP_NOT_FOUND;
      94           0 :       break;
      95           0 :     case GNUNET_DB_STATUS_SOFT_ERROR:
      96           0 :       ec = TALER_EC_GENERIC_DB_SOFT_FAILURE;
      97           0 :       response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
      98           0 :       break;
      99           0 :     case GNUNET_DB_STATUS_HARD_ERROR:
     100           0 :       ec = TALER_EC_GENERIC_DB_COMMIT_FAILED;
     101           0 :       response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
     102           0 :       break;
     103           0 :     default:
     104           0 :       GNUNET_break (0);
     105           0 :       ec = TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
     106           0 :       response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
     107           0 :       break;
     108             :     }
     109           0 :     return TALER_MHD_reply_with_error (connection,
     110             :                                        response_code,
     111             :                                        ec,
     112             :                                        NULL);
     113             :   }
     114           0 :   if (fpu)
     115             :   {
     116           0 :     pickups_json = json_array ();
     117           0 :     GNUNET_assert (NULL != pickups_json);
     118           0 :     for (unsigned int i = 0; i<pickups_length; i++)
     119             :     {
     120           0 :       GNUNET_assert (0 ==
     121             :                      json_array_append_new (
     122             :                        pickups_json,
     123             :                        GNUNET_JSON_PACK (
     124             :                          GNUNET_JSON_pack_data_auto ("pickup_id",
     125             :                                                      &pickups[i].pickup_id),
     126             :                          GNUNET_JSON_pack_uint64 ("num_planchets",
     127             :                                                   pickups[i].num_planchets),
     128             :                          TALER_JSON_pack_amount ("requested_amount",
     129             :                                                  &pickups[i].requested_amount))));
     130             :     }
     131             :   }
     132           0 :   GNUNET_array_grow (pickups,
     133             :                      pickups_length,
     134             :                      0);
     135             :   {
     136             :     MHD_RESULT ret;
     137             : 
     138           0 :     ret = TALER_MHD_REPLY_JSON_PACK (
     139             :       connection,
     140             :       MHD_HTTP_OK,
     141             :       TALER_JSON_pack_amount ("total_authorized",
     142             :                               &total_authorized),
     143             :       TALER_JSON_pack_amount ("total_picked_up",
     144             :                               &total_picked_up),
     145             :       GNUNET_JSON_pack_string ("reason",
     146             :                                reason),
     147             :       GNUNET_JSON_pack_timestamp ("expiration",
     148             :                                   expiration),
     149             :       GNUNET_JSON_pack_data_auto ("reserve_pub",
     150             :                                   &reserve_pub),
     151             :       GNUNET_JSON_pack_allow_null (
     152             :         GNUNET_JSON_pack_array_steal ("pickups",
     153             :                                       pickups_json)));
     154           0 :     GNUNET_free (reason);
     155           0 :     return ret;
     156             :   }
     157             : }

Generated by: LCOV version 1.14