LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-get-instances-ID-tokens.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 17 23 73.9 %
Date: 2025-07-10 12:24:40 Functions: 2 2 100.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 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_private-get-instances-ID-tokens.c
      18             :  * @brief implement GET /tokens
      19             :  * @author Martin Schanzenbach
      20             :  */
      21             : #include "platform.h"
      22             : #include "taler-merchant-httpd_private-get-instances-ID-tokens.h"
      23             : 
      24             : 
      25             : /**
      26             :  * Add token details to our JSON array.
      27             :  *
      28             :  * @param cls a `json_t *` JSON array to build
      29             :  * @param product_serial serial (row) number of the product in the database
      30             :  * @param product_id ID of the product
      31             :  */
      32             : static void
      33           2 : add_token (void *cls,
      34             :            struct GNUNET_TIME_Timestamp creation_time,
      35             :            struct GNUNET_TIME_Timestamp expiration_time,
      36             :            uint32_t scope,
      37             :            const char *description,
      38             :            uint64_t serial)
      39             : {
      40           2 :   json_t *pa = cls;
      41             :   bool refreshable;
      42             :   const char*as;
      43             : 
      44           2 :   as = TMH_get_name_by_scope (scope, &refreshable);
      45           2 :   if (NULL == as)
      46             :   {
      47           0 :     GNUNET_break (0);
      48           0 :     return;
      49             :   }
      50           2 :   GNUNET_assert (0 ==
      51             :                  json_array_append_new (
      52             :                    pa,
      53             :                    GNUNET_JSON_PACK (
      54             :                      GNUNET_JSON_pack_timestamp ("creation_time",
      55             :                                                  creation_time),
      56             :                      GNUNET_JSON_pack_timestamp ("expiration_time",
      57             :                                                  expiration_time),
      58             :                      GNUNET_JSON_pack_string ("scope",
      59             :                                               as),
      60             :                      GNUNET_JSON_pack_bool ("refreshable",
      61             :                                             refreshable),
      62             :                      GNUNET_JSON_pack_string ("description",
      63             :                                               description),
      64             :                      GNUNET_JSON_pack_uint64 ("serial",
      65             :                                               serial))));
      66             : }
      67             : 
      68             : 
      69             : MHD_RESULT
      70           1 : TMH_private_get_instances_ID_tokens (const struct TMH_RequestHandler *rh,
      71             :                                      struct MHD_Connection *connection,
      72             :                                      struct TMH_HandlerContext *hc)
      73             : {
      74             :   json_t *ta;
      75             :   enum GNUNET_DB_QueryStatus qs;
      76             :   int64_t limit;
      77             :   uint64_t offset;
      78             : 
      79           1 :   limit = -20; /* default */
      80           1 :   TALER_MHD_parse_request_snumber (connection,
      81             :                                    "limit",
      82             :                                    &limit);
      83           1 :   if (limit < 0)
      84           0 :     offset = INT64_MAX;
      85             :   else
      86           1 :     offset = 0;
      87           1 :   TALER_MHD_parse_request_number (connection,
      88             :                                   "offset",
      89             :                                   &offset);
      90           1 :   ta = json_array ();
      91           1 :   GNUNET_assert (NULL != ta);
      92           1 :   qs = TMH_db->lookup_login_tokens (TMH_db->cls,
      93           1 :                                     hc->instance->settings.id,
      94             :                                     offset,
      95             :                                     limit,
      96             :                                     &add_token,
      97             :                                     ta);
      98           1 :   if (0 > qs)
      99             :   {
     100           0 :     GNUNET_break (0);
     101           0 :     json_decref (ta);
     102           0 :     return TALER_MHD_reply_with_error (connection,
     103             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     104             :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     105             :                                        NULL);
     106             :   }
     107           1 :   return TALER_MHD_REPLY_JSON_PACK (connection,
     108             :                                     MHD_HTTP_OK,
     109             :                                     GNUNET_JSON_pack_array_steal ("tokens",
     110             :                                                                   ta));
     111             : }
     112             : 
     113             : 
     114             : /* end of taler-merchant-httpd_private-get-products.c */

Generated by: LCOV version 1.16