LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_private-patch-otp-devices-ID.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 35 0
Test Date: 2025-11-06 19:31:41 Functions: 0.0 % 1 0

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   (C) 2022 Taler Systems SA
       4              : 
       5              :   TALER is free software; you can redistribute it and/or modify
       6              :   it under the terms of the GNU Affero General Public License as
       7              :   published by the Free Software Foundation; either version 3,
       8              :   or (at your option) any later version.
       9              : 
      10              :   TALER is distributed in the hope that it will be useful, but
      11              :   WITHOUT ANY WARRANTY; without even the implied warranty of
      12              :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13              :   GNU General Public License for more details.
      14              : 
      15              :   You should have received a copy of the GNU General Public
      16              :   License along with TALER; see the file COPYING.  If not,
      17              :   see <http://www.gnu.org/licenses/>
      18              : */
      19              : 
      20              : /**
      21              :  * @file taler-merchant-httpd_private-patch-otp-devices-ID.c
      22              :  * @brief implementing PATCH /otp-devices/$ID request handling
      23              :  * @author Christian Grothoff
      24              :  */
      25              : #include "platform.h"
      26              : #include "taler-merchant-httpd_private-patch-otp-devices-ID.h"
      27              : #include "taler-merchant-httpd_helper.h"
      28              : #include <taler/taler_json_lib.h>
      29              : 
      30              : 
      31              : MHD_RESULT
      32            0 : TMH_private_patch_otp_devices_ID (const struct TMH_RequestHandler *rh,
      33              :                                   struct MHD_Connection *connection,
      34              :                                   struct TMH_HandlerContext *hc)
      35              : {
      36            0 :   struct TMH_MerchantInstance *mi = hc->instance;
      37            0 :   const char *device_id = hc->infix;
      38            0 :   struct TALER_MERCHANTDB_OtpDeviceDetails tp = {0};
      39              :   enum GNUNET_DB_QueryStatus qs;
      40              :   struct GNUNET_JSON_Specification spec[] = {
      41            0 :     GNUNET_JSON_spec_string ("otp_device_description",
      42              :                              (const char **) &tp.otp_description),
      43            0 :     TALER_JSON_spec_otp_type ("otp_algorithm",
      44              :                               &tp.otp_algorithm),
      45            0 :     GNUNET_JSON_spec_mark_optional (
      46              :       GNUNET_JSON_spec_uint64 ("otp_ctr",
      47              :                                &tp.otp_ctr),
      48              :       NULL),
      49            0 :     GNUNET_JSON_spec_mark_optional(
      50              : 
      51              :       TALER_JSON_spec_otp_key ("otp_key",
      52              :                                (const char **) &tp.otp_key),
      53              :       NULL),
      54            0 :     GNUNET_JSON_spec_end ()
      55              :   };
      56              : 
      57            0 :   GNUNET_assert (NULL != mi);
      58            0 :   GNUNET_assert (NULL != device_id);
      59              :   {
      60              :     enum GNUNET_GenericReturnValue res;
      61              : 
      62            0 :     res = TALER_MHD_parse_json_data (connection,
      63            0 :                                      hc->request_body,
      64              :                                      spec);
      65            0 :     if (GNUNET_OK != res)
      66              :       return (GNUNET_NO == res)
      67              :              ? MHD_YES
      68            0 :              : MHD_NO;
      69              :   }
      70              : 
      71            0 :   qs = TMH_db->update_otp (TMH_db->cls,
      72            0 :                            mi->settings.id,
      73              :                            device_id,
      74              :                            &tp);
      75              :   {
      76            0 :     MHD_RESULT ret = MHD_NO;
      77              : 
      78            0 :     switch (qs)
      79              :     {
      80            0 :     case GNUNET_DB_STATUS_HARD_ERROR:
      81            0 :       GNUNET_break (0);
      82            0 :       ret = TALER_MHD_reply_with_error (connection,
      83              :                                         MHD_HTTP_INTERNAL_SERVER_ERROR,
      84              :                                         TALER_EC_GENERIC_DB_STORE_FAILED,
      85              :                                         "update_pos");
      86            0 :       break;
      87            0 :     case GNUNET_DB_STATUS_SOFT_ERROR:
      88            0 :       GNUNET_break (0);
      89            0 :       ret = TALER_MHD_reply_with_error (connection,
      90              :                                         MHD_HTTP_INTERNAL_SERVER_ERROR,
      91              :                                         TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
      92              :                                         "unexpected serialization problem");
      93            0 :       break;
      94            0 :     case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
      95            0 :       ret = TALER_MHD_reply_with_error (connection,
      96              :                                         MHD_HTTP_NOT_FOUND,
      97              :                                         TALER_EC_MERCHANT_GENERIC_OTP_DEVICE_UNKNOWN,
      98              :                                         device_id);
      99            0 :       break;
     100            0 :     case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     101            0 :       ret = TALER_MHD_reply_static (connection,
     102              :                                     MHD_HTTP_NO_CONTENT,
     103              :                                     NULL,
     104              :                                     NULL,
     105              :                                     0);
     106            0 :       break;
     107              :     }
     108            0 :     GNUNET_JSON_parse_free (spec);
     109            0 :     return ret;
     110              :   }
     111              : }
     112              : 
     113              : 
     114              : /* end of taler-merchant-httpd_private-patch-otp-devices-ID.c */
        

Generated by: LCOV version 2.0-1