merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

taler-merchant-httpd_get-private-otp-devices.c (2830B)


      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 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 src/backend/taler-merchant-httpd_get-private-otp-devices.c
     18  * @brief implement GET /otp-devices
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include "taler-merchant-httpd_get-private-otp-devices.h"
     23 #include "merchant-database/lookup_otp_devices.h"
     24 
     25 
     26 /**
     27  * Add OTP device details to our JSON array.
     28  *
     29  * @param cls a `json_t *` JSON array to build
     30  * @param otp_id ID of the OTP device
     31  * @param otp_description human-readable description for the OTP device
     32  */
     33 static void
     34 add_otp (void *cls,
     35          const char *otp_id,
     36          const char *otp_description)
     37 {
     38   json_t *pa = cls;
     39 
     40   GNUNET_assert (0 ==
     41                  json_array_append_new (
     42                    pa,
     43                    GNUNET_JSON_PACK (
     44                      GNUNET_JSON_pack_string ("otp_device_id",
     45                                               otp_id),
     46                      GNUNET_JSON_pack_string ("device_description",
     47                                               otp_description))));
     48 }
     49 
     50 
     51 enum MHD_Result
     52 TMH_private_get_otp_devices (const struct TMH_RequestHandler *rh,
     53                              struct MHD_Connection *connection,
     54                              struct TMH_HandlerContext *hc)
     55 {
     56   json_t *pa;
     57   enum GNUNET_DB_QueryStatus qs;
     58 
     59   pa = json_array ();
     60   GNUNET_assert (NULL != pa);
     61   qs = TALER_MERCHANTDB_lookup_otp_devices (TMH_db,
     62                                             hc->instance->settings.id,
     63                                             &add_otp,
     64                                             pa);
     65   if (0 > qs)
     66   {
     67     GNUNET_break (0);
     68     json_decref (pa);
     69     return TALER_MHD_reply_with_error (connection,
     70                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     71                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     72                                        NULL);
     73   }
     74   return TALER_MHD_REPLY_JSON_PACK (connection,
     75                                     MHD_HTTP_OK,
     76                                     GNUNET_JSON_pack_array_steal ("otp_devices",
     77                                                                   pa));
     78 }
     79 
     80 
     81 /* end of taler-merchant-httpd_get-private-otp-devices.c */