LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-delete-instances-ID.c (source / functions) Hit Total Coverage
Test: GNU Taler merchant coverage report Lines: 24 32 75.0 %
Date: 2021-08-30 06:54:17 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   (C) 2020-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 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-delete-instances-ID.c
      18             :  * @brief implement DELETE /instances/$ID
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "platform.h"
      22             : #include "taler-merchant-httpd_private-delete-instances-ID.h"
      23             : #include <taler/taler_json_lib.h>
      24             : 
      25             : 
      26             : /**
      27             :  * Handle a DELETE "/instances/$ID" request.
      28             :  *
      29             :  * @param mi instance to delete
      30             :  * @param connection the MHD connection to handle
      31             :  * @return MHD result code
      32             :  */
      33             : static MHD_RESULT
      34           7 : delete_instances_ID (struct TMH_MerchantInstance *mi,
      35             :                      struct MHD_Connection *connection)
      36             : {
      37             :   const char *purge_s;
      38             :   bool purge;
      39             :   enum GNUNET_DB_QueryStatus qs;
      40             : 
      41           7 :   GNUNET_assert (NULL != mi);
      42           7 :   purge_s = MHD_lookup_connection_value (connection,
      43             :                                          MHD_GET_ARGUMENT_KIND,
      44             :                                          "purge");
      45           7 :   if (NULL == purge_s)
      46           1 :     purge_s = "no";
      47           7 :   purge = (0 == strcasecmp (purge_s,
      48             :                             "yes"));
      49           7 :   if (purge)
      50           6 :     qs = TMH_db->purge_instance (TMH_db->cls,
      51           6 :                                  mi->settings.id);
      52             :   else
      53           1 :     qs = TMH_db->delete_instance_private_key (TMH_db->cls,
      54           1 :                                               mi->settings.id);
      55           7 :   switch (qs)
      56             :   {
      57           0 :   case GNUNET_DB_STATUS_HARD_ERROR:
      58           0 :     return TALER_MHD_reply_with_error (connection,
      59             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      60             :                                        TALER_EC_GENERIC_DB_STORE_FAILED,
      61             :                                        "delete private key");
      62           0 :   case GNUNET_DB_STATUS_SOFT_ERROR:
      63           0 :     GNUNET_break (0);
      64           0 :     return TALER_MHD_reply_with_error (connection,
      65             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      66             :                                        TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
      67             :                                        NULL);
      68           0 :   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
      69           0 :     return TALER_MHD_reply_with_error (connection,
      70             :                                        MHD_HTTP_NOT_FOUND,
      71             :                                        TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN,
      72             :                                        purge
      73             :                                        ? "Instance unknown"
      74             :                                        : "Private key unknown");
      75           7 :   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
      76           7 :     TMH_reload_instances (mi->settings.id);
      77           7 :     return TALER_MHD_reply_static (connection,
      78             :                                    MHD_HTTP_NO_CONTENT,
      79             :                                    NULL,
      80             :                                    NULL,
      81             :                                    0);
      82             :   }
      83           0 :   GNUNET_assert (0);
      84             :   return MHD_NO;
      85             : }
      86             : 
      87             : 
      88             : MHD_RESULT
      89           1 : TMH_private_delete_instances_ID (const struct TMH_RequestHandler *rh,
      90             :                                  struct MHD_Connection *connection,
      91             :                                  struct TMH_HandlerContext *hc)
      92             : {
      93           1 :   struct TMH_MerchantInstance *mi = hc->instance;
      94             : 
      95           1 :   return delete_instances_ID (mi,
      96             :                               connection);
      97             : }
      98             : 
      99             : 
     100             : MHD_RESULT
     101           7 : TMH_private_delete_instances_default_ID (const struct TMH_RequestHandler *rh,
     102             :                                          struct MHD_Connection *connection,
     103             :                                          struct TMH_HandlerContext *hc)
     104             : {
     105             :   struct TMH_MerchantInstance *mi;
     106             : 
     107           7 :   mi = TMH_lookup_instance (hc->infix);
     108           7 :   if (NULL == mi)
     109             :   {
     110           1 :     return TALER_MHD_reply_with_error (connection,
     111             :                                        MHD_HTTP_NOT_FOUND,
     112             :                                        TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN,
     113           1 :                                        hc->infix);
     114             :   }
     115           6 :   return delete_instances_ID (mi,
     116             :                               connection);
     117             : }
     118             : 
     119             : 
     120             : /* end of taler-merchant-httpd_private-delete-instances-ID.c */

Generated by: LCOV version 1.14