LCOV - code coverage report
Current view: top level - backend - taler-merchant-httpd_patch-private-otp-devices-DEVICE_ID.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 35 0
Test Date: 2026-09-04 23:42:01 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 src/backend/taler-merchant-httpd_patch-private-otp-devices-DEVICE_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_patch-private-otp-devices-DEVICE_ID.h"
      27              : #include "taler-merchant-httpd_helper.h"
      28              : #include <taler/taler_json_lib.h>
      29              : #include "merchant-database/update_otp_device.h"
      30              : 
      31              : 
      32              : enum MHD_Result
      33            0 : TMH_private_patch_otp_devices_ID (const struct TMH_RequestHandler *rh,
      34              :                                   struct MHD_Connection *connection,
      35              :                                   struct TMH_HandlerContext *hc)
      36              : {
      37            0 :   struct TMH_MerchantInstance *mi = hc->instance;
      38            0 :   const char *device_id = hc->infix;
      39            0 :   struct TALER_MERCHANTDB_OtpDeviceDetails tp = {0};
      40              :   enum GNUNET_DB_QueryStatus qs;
      41              :   struct GNUNET_JSON_Specification spec[] = {
      42            0 :     GNUNET_JSON_spec_string ("otp_device_description",
      43              :                              (const char **) &tp.otp_description),
      44            0 :     TALER_JSON_spec_otp_type ("otp_algorithm",
      45              :                               &tp.otp_algorithm),
      46            0 :     GNUNET_JSON_spec_mark_optional (
      47              :       GNUNET_JSON_spec_uint64 ("otp_ctr",
      48              :                                &tp.otp_ctr),
      49              :       NULL),
      50            0 :     GNUNET_JSON_spec_mark_optional (
      51              : 
      52              :       TALER_JSON_spec_otp_key ("otp_key",
      53              :                                (const char **) &tp.otp_key),
      54              :       NULL),
      55            0 :     GNUNET_JSON_spec_end ()
      56              :   };
      57              : 
      58            0 :   GNUNET_assert (NULL != mi);
      59            0 :   GNUNET_assert (NULL != device_id);
      60              :   {
      61              :     enum GNUNET_GenericReturnValue res;
      62              : 
      63            0 :     res = TALER_MHD_parse_json_data (connection,
      64            0 :                                      hc->request_body,
      65              :                                      spec);
      66            0 :     if (GNUNET_OK != res)
      67              :       return (GNUNET_NO == res)
      68              :              ? MHD_YES
      69            0 :              : MHD_NO;
      70              :   }
      71              : 
      72            0 :   qs = TALER_MERCHANTDB_update_otp_device (TMH_db,
      73            0 :                                            mi->settings.id,
      74              :                                            device_id,
      75              :                                            &tp);
      76              :   {
      77            0 :     enum MHD_Result ret = MHD_NO;
      78              : 
      79            0 :     switch (qs)
      80              :     {
      81            0 :     case GNUNET_DB_STATUS_HARD_ERROR:
      82            0 :       GNUNET_break (0);
      83            0 :       ret = TALER_MHD_reply_with_error (connection,
      84              :                                         MHD_HTTP_INTERNAL_SERVER_ERROR,
      85              :                                         TALER_EC_GENERIC_DB_STORE_FAILED,
      86              :                                         "update_pos");
      87            0 :       break;
      88            0 :     case GNUNET_DB_STATUS_SOFT_ERROR:
      89            0 :       GNUNET_break (0);
      90            0 :       ret = TALER_MHD_reply_with_error (connection,
      91              :                                         MHD_HTTP_INTERNAL_SERVER_ERROR,
      92              :                                         TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
      93              :                                         "unexpected serialization problem");
      94            0 :       break;
      95            0 :     case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
      96            0 :       ret = TALER_MHD_reply_with_error (connection,
      97              :                                         MHD_HTTP_NOT_FOUND,
      98              :                                         TALER_EC_MERCHANT_GENERIC_OTP_DEVICE_UNKNOWN,
      99              :                                         device_id);
     100            0 :       break;
     101            0 :     case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     102            0 :       ret = TALER_MHD_reply_static (connection,
     103              :                                     MHD_HTTP_NO_CONTENT,
     104              :                                     NULL,
     105              :                                     NULL,
     106              :                                     0);
     107            0 :       break;
     108              :     }
     109            0 :     GNUNET_JSON_parse_free (spec);
     110            0 :     return ret;
     111              :   }
     112              : }
     113              : 
     114              : 
     115              : /* end of taler-merchant-httpd_patch-private-otp-devices-DEVICE_ID.c */
        

Generated by: LCOV version 2.0-1