Line data Source code
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 18 : TALER_MERCHANT_TESTING_extract_host (const char *merchant_url) 33 : { 34 18 : const char *hosts = strchr (merchant_url, '/'); 35 : const char *hend; 36 : const char *pstr; 37 : const char *pend; 38 : char *host; 39 : 40 18 : if (NULL == hosts) 41 : { 42 0 : GNUNET_break (0); 43 0 : return NULL; 44 : } 45 18 : if (hosts[1] != '/') 46 : { 47 0 : GNUNET_break (0); 48 0 : return NULL; 49 : } 50 18 : hosts += 2; 51 18 : pstr = strchr (hosts, ':'); 52 18 : if (NULL == pstr) 53 : { 54 0 : hend = &hosts[strlen (hosts)]; 55 0 : pstr = "80"; 56 0 : pend = &pstr[2]; 57 : } 58 : else 59 : { 60 18 : hend = pstr; 61 18 : pstr++; 62 18 : pend = strchr (pstr, '/'); 63 : } 64 18 : GNUNET_asprintf (&host, 65 : "%.*s:%.*s", 66 18 : (int) (hend - hosts), 67 : hosts, 68 18 : (int) (pend - pstr), 69 : pstr); 70 18 : return host; 71 : }