merchant

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

taler-merchant-httpd_delete-private-token.c (3926B)


      1 /*
      2   This file is part of GNU Taler
      3   (C) 2023 Taler Systems SA
      4 
      5   GNU 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   GNU 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_delete-private-token.c
     22  * @brief implementing DELETE /instances/$ID/token request handling
     23  * @author Christian Grothoff
     24  */
     25 #include "taler/platform.h"
     26 #include "taler-merchant-httpd_delete-private-token.h"
     27 #include "taler-merchant-httpd_helper.h"
     28 #include <taler/taler_json_lib.h>
     29 
     30 
     31 MHD_RESULT
     32 TMH_private_delete_instances_ID_token (const struct TMH_RequestHandler *rh,
     33                                        struct MHD_Connection *connection,
     34                                        struct TMH_HandlerContext *hc)
     35 {
     36   const char *bearer = "Bearer ";
     37   struct TMH_MerchantInstance *mi = hc->instance;
     38   const char *tok;
     39   struct TALER_MERCHANTDB_LoginTokenP btoken;
     40   enum GNUNET_DB_QueryStatus qs;
     41 
     42   tok = MHD_lookup_connection_value (connection,
     43                                      MHD_HEADER_KIND,
     44                                      MHD_HTTP_HEADER_AUTHORIZATION);
     45   /* This was presumably checked before... */
     46   if (0 !=
     47       strncmp (tok,
     48                bearer,
     49                strlen (bearer)))
     50   {
     51     GNUNET_break_op (0);
     52     return TALER_MHD_reply_with_ec (connection,
     53                                     TALER_EC_GENERIC_PARAMETER_MALFORMED,
     54                                     "login token (in 'Authorization' header)");
     55   }
     56   tok += strlen (bearer);
     57   while (' ' == *tok)
     58     tok++;
     59   if (0 != strncasecmp (tok,
     60                         RFC_8959_PREFIX,
     61                         strlen (RFC_8959_PREFIX)))
     62   {
     63     GNUNET_break_op (0);
     64     return TALER_MHD_reply_with_ec (connection,
     65                                     TALER_EC_GENERIC_PARAMETER_MALFORMED,
     66                                     "login token (in 'Authorization' header)");
     67   }
     68   tok += strlen (RFC_8959_PREFIX);
     69 
     70   if (GNUNET_OK !=
     71       GNUNET_STRINGS_string_to_data (tok,
     72                                      strlen (tok),
     73                                      &btoken,
     74                                      sizeof (btoken)))
     75   {
     76     GNUNET_break_op (0);
     77     return TALER_MHD_reply_with_ec (connection,
     78                                     TALER_EC_GENERIC_PARAMETER_MALFORMED,
     79                                     "login token (in 'Authorization' header)");
     80   }
     81   qs = TMH_db->delete_login_token (TMH_db->cls,
     82                                    mi->settings.id,
     83                                    &btoken);
     84   switch (qs)
     85   {
     86   case GNUNET_DB_STATUS_HARD_ERROR:
     87   case GNUNET_DB_STATUS_SOFT_ERROR:
     88     GNUNET_break (0);
     89     return TALER_MHD_reply_with_ec (connection,
     90                                     TALER_EC_GENERIC_DB_STORE_FAILED,
     91                                     "delete_login_token");
     92   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     93   /* No 404, as the login token must have existed
     94      when we got the request as it was accepted as
     95      valid. So we can only get here due to concurrent
     96      modification, and then the client should still
     97      simply see the success. Hence, fall-through! */
     98   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     99     return TALER_MHD_reply_static (connection,
    100                                    MHD_HTTP_NO_CONTENT,
    101                                    NULL,
    102                                    NULL,
    103                                    0);
    104   }
    105   GNUNET_break (0);
    106   return MHD_NO;
    107 }