exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

taler-auditor-httpd_closure-lags-get.c (4287B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2024 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 #include "taler/platform.h"
     17 #include <gnunet/gnunet_util_lib.h>
     18 #include <gnunet/gnunet_json_lib.h>
     19 #include <jansson.h>
     20 #include <microhttpd.h>
     21 #include <pthread.h>
     22 #include "taler/taler_json_lib.h"
     23 #include "taler/taler_mhd_lib.h"
     24 #include "taler-auditor-httpd.h"
     25 #include "taler-auditor-httpd_closure-lags-get.h"
     26 
     27 
     28 /**
     29  * Add closure-lags to the list.
     30  *
     31  * @param[in,out] cls a `json_t *` array to extend
     32  * @param dc struct of inconsistencies
     33  * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
     34  */
     35 static enum GNUNET_GenericReturnValue
     36 process_closure_lags (
     37   void *cls,
     38   const struct TALER_AUDITORDB_ClosureLags *dc)
     39 {
     40   json_t *list = cls;
     41   json_t *obj;
     42 
     43   obj = GNUNET_JSON_PACK (
     44     GNUNET_JSON_pack_uint64 ("row_id",
     45                              dc->row_id),
     46     GNUNET_JSON_pack_uint64 ("problem_row_id",
     47                              dc->problem_row_id),
     48     TALER_JSON_pack_amount ("amount",
     49                             &dc->amount),
     50     TALER_JSON_pack_time_abs_human ("deadline",
     51                                     dc->deadline),
     52     GNUNET_JSON_pack_data_auto ("wtid",
     53                                 &dc->wtid),
     54     TALER_JSON_pack_full_payto ("account",
     55                                 dc->account),
     56     GNUNET_JSON_pack_bool ("suppressed",
     57                            dc->suppressed)
     58     );
     59   GNUNET_break (0 ==
     60                 json_array_append_new (list,
     61                                        obj));
     62 
     63 
     64   return GNUNET_OK;
     65 }
     66 
     67 
     68 MHD_RESULT
     69 TAH_CLOSURE_LAGS_handler_get (
     70   struct TAH_RequestHandler *rh,
     71   struct MHD_Connection *connection,
     72   void **connection_cls,
     73   const char *upload_data,
     74   size_t *upload_data_size,
     75   const char *const args[])
     76 {
     77   json_t *ja;
     78   enum GNUNET_DB_QueryStatus qs;
     79   int64_t limit = -20;
     80   uint64_t offset;
     81   bool return_suppressed = false;
     82 
     83   if (GNUNET_SYSERR ==
     84       TAH_plugin->preflight (TAH_plugin->cls))
     85   {
     86     GNUNET_break (0);
     87     return TALER_MHD_reply_with_error (connection,
     88                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     89                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
     90                                        NULL);
     91   }
     92   TALER_MHD_parse_request_snumber (connection,
     93                                    "limit",
     94                                    &limit);
     95   if (limit < 0)
     96     offset = INT64_MAX;
     97   else
     98     offset = 0;
     99   TALER_MHD_parse_request_number (connection,
    100                                   "offset",
    101                                   &offset);
    102   {
    103     const char *ret_s
    104       = MHD_lookup_connection_value (connection,
    105                                      MHD_GET_ARGUMENT_KIND,
    106                                      "return_suppressed");
    107     if (ret_s != NULL && strcmp (ret_s, "true") == 0)
    108     {
    109       return_suppressed = true;
    110     }
    111   }
    112   ja = json_array ();
    113   GNUNET_break (NULL != ja);
    114   qs = TAH_plugin->get_auditor_closure_lags (
    115     TAH_plugin->cls,
    116     limit,
    117     offset,
    118     return_suppressed,
    119     &process_closure_lags,
    120     ja);
    121   if (0 > qs)
    122   {
    123     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
    124     json_decref (ja);
    125     TALER_LOG_WARNING (
    126       "Failed to handle GET /closure-lags\n");
    127     return TALER_MHD_reply_with_error (connection,
    128                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
    129                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
    130                                        "get_auditor_closure_lags");
    131   }
    132   return TALER_MHD_REPLY_JSON_PACK (
    133     connection,
    134     MHD_HTTP_OK,
    135     GNUNET_JSON_pack_array_steal ("closure_lags",
    136                                   ja));
    137 }