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_patch-generic-suppressed.c (4882B)


      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 <gnunet/gnunet_util_lib.h>
     17 #include <gnunet/gnunet_json_lib.h>
     18 #include <jansson.h>
     19 #include <microhttpd.h>
     20 #include <pthread.h>
     21 #include "taler/taler_json_lib.h"
     22 #include "taler/taler_mhd_lib.h"
     23 #include "taler-auditor-httpd.h"
     24 #include "taler-auditor-httpd_patch-generic-suppressed.h"
     25 #include "auditor-database/preflight.h"
     26 #include "auditor-database/update_to_suppressed.h"
     27 
     28 
     29 enum MHD_Result
     30 TAH_patch_generic_suppressed (
     31   struct TAH_RequestHandler *rh,
     32   struct MHD_Connection *connection,
     33   void **connection_cls,
     34   const char *upload_data,
     35   size_t *upload_data_size,
     36   const char *const args[])
     37 {
     38   enum GNUNET_DB_QueryStatus qs;
     39   unsigned long long row_id;
     40   char dummy;
     41   bool suppressed;
     42 
     43   (void) connection_cls;
     44   if (GNUNET_SYSERR ==
     45       TALER_AUDITORDB_preflight (TAH_apg))
     46   {
     47     GNUNET_break (0);
     48     return TALER_MHD_reply_with_error (connection,
     49                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     50                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
     51                                        NULL);
     52   }
     53 
     54   /* The URL is "/monitoring/$TABLE/$ROW_ID", so the row ID is args[2]. */
     55   if ( (NULL == args[2]) ||
     56        (1 != sscanf (args[2],
     57                      "%llu%c",
     58                      &row_id,
     59                      &dummy)) )
     60   {
     61     GNUNET_break_op (0);
     62     return TALER_MHD_reply_with_error (connection,
     63                                        MHD_HTTP_BAD_REQUEST,
     64                                        TALER_EC_GENERIC_PARAMETER_MALFORMED,
     65                                        "no row id specified");
     66   }
     67 
     68   {
     69     enum GNUNET_GenericReturnValue res;
     70     json_t *json;
     71     struct GNUNET_JSON_Specification spec[] = {
     72       GNUNET_JSON_spec_bool ("suppressed", &suppressed),
     73       GNUNET_JSON_spec_end ()
     74     };
     75 
     76     res = TALER_MHD_parse_post_json (connection,
     77                                      connection_cls,
     78                                      upload_data,
     79                                      upload_data_size,
     80                                      &json);
     81     if (GNUNET_SYSERR == res)
     82       return MHD_NO;
     83     if ((GNUNET_NO == res) ||
     84         (NULL == json))
     85       return MHD_YES;
     86     res = TALER_MHD_parse_json_data (connection,
     87                                      json,
     88                                      spec);
     89     if (GNUNET_SYSERR == res)
     90     {
     91       GNUNET_break (0);
     92       json_decref (json);
     93       return MHD_NO;                               /* hard failure */
     94     }
     95     if (GNUNET_NO == res)
     96     {
     97       GNUNET_break_op (0);
     98       json_decref (json);
     99       return MHD_YES;                               /* failure */
    100     }
    101     json_decref (json);
    102   }
    103 
    104   /* execute transaction */
    105   qs = TALER_AUDITORDB_update_to_suppressed (TAH_apg,
    106                                              rh->table,
    107                                              row_id,
    108                                              suppressed);
    109 
    110   switch (qs)
    111   {
    112   case GNUNET_DB_STATUS_HARD_ERROR:
    113     GNUNET_break (0);
    114     return TALER_MHD_reply_with_error (connection,
    115                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
    116                                        TALER_EC_GENERIC_DB_STORE_FAILED,
    117                                        "update_to_suppressed");
    118   case GNUNET_DB_STATUS_SOFT_ERROR:
    119     GNUNET_break (0);
    120     return TALER_MHD_reply_with_error (connection,
    121                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
    122                                        TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
    123                                        "unexpected serialization problem");
    124   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
    125     return TALER_MHD_reply_with_error (connection,
    126                                        MHD_HTTP_NOT_FOUND,
    127                                        TALER_EC_AUDITOR_RESOURCE_NOT_FOUND,
    128                                        "no updates executed");
    129   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
    130     return TALER_MHD_reply_static (connection,
    131                                    MHD_HTTP_NO_CONTENT,
    132                                    NULL,
    133                                    NULL,
    134                                    0);
    135   }
    136   GNUNET_break (0);
    137   return MHD_NO;
    138 }