merchant

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

testing_api_helpers.c (1719B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2014-2018 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify
      6   it under the terms of the GNU General Public License as
      7   published by the Free Software Foundation; either version 3, or
      8   (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, see
     17   <http://www.gnu.org/licenses/>
     18 */
     19 
     20 /**
     21  * @file testing_api_helpers.c
     22  * @brief helper functions for test library.
     23  * @author Christian Grothoff
     24  */
     25 #include "platform.h"
     26 #include <taler/taler_exchange_service.h>
     27 #include <taler/taler_testing_lib.h>
     28 #include "taler_merchant_testing_lib.h"
     29 
     30 
     31 char *
     32 TALER_MERCHANT_TESTING_extract_host (const char *merchant_url)
     33 {
     34   const char *hosts = strchr (merchant_url, '/');
     35   const char *hend;
     36   const char *pstr;
     37   const char *pend;
     38   char *host;
     39 
     40   if (NULL == hosts)
     41   {
     42     GNUNET_break (0);
     43     return NULL;
     44   }
     45   if (hosts[1] != '/')
     46   {
     47     GNUNET_break (0);
     48     return NULL;
     49   }
     50   hosts += 2;
     51   pstr = strchr (hosts, ':');
     52   if (NULL == pstr)
     53   {
     54     hend = &hosts[strlen (hosts)];
     55     pstr = "80";
     56     pend = &pstr[2];
     57   }
     58   else
     59   {
     60     hend = pstr;
     61     pstr++;
     62     pend = strchr (pstr, '/');
     63   }
     64   GNUNET_asprintf (&host,
     65                    "%.*s:%.*s",
     66                    (int) (hend - hosts),
     67                    hosts,
     68                    (int) (pend - pstr),
     69                    pstr);
     70   return host;
     71 }