LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_patch_generic_suppressed.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 41 0.0 %
Date: 2025-06-05 21:03:14 Functions: 0 1 0.0 %

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

Generated by: LCOV version 1.16