merchant_api_curl_defaults.c (2562B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2014-2018, 2021, 2026 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU 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 15 <http://www.gnu.org/licenses/> 16 */ 17 /** 18 * @file src/lib/merchant_api_curl_defaults.c 19 * @brief curl easy handle defaults 20 * @author Florian Dold 21 */ 22 #include "platform.h" 23 #include <taler/taler_curl_lib.h> 24 #include "taler/merchant/common.h" 25 #include "merchant_api_curl_defaults.h" 26 27 /** 28 * UNIX path to use to connect to the merchant backend, 29 * NULL to use TCP. 30 */ 31 static char *glob_unixpath; 32 33 34 bool 35 TALER_MERCHANT_global_set_unixpath (const char *unix_path) 36 { 37 GNUNET_free (glob_unixpath); 38 if (NULL == unix_path) 39 return true; 40 if (strlen (unix_path) > 107) 41 { 42 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 43 "Unixpath `%s' exceeds length limit of 107 characters\n", 44 unix_path); 45 return false; 46 } 47 glob_unixpath = GNUNET_strdup (unix_path); 48 return true; 49 } 50 51 52 CURL * 53 TALER_MERCHANT_curl_easy_get_ (const char *url) 54 { 55 CURL *eh; 56 57 eh = curl_easy_init (); 58 if (NULL == eh) 59 { 60 GNUNET_break (0); 61 return NULL; 62 } 63 GNUNET_assert (CURLE_OK == 64 curl_easy_setopt (eh, 65 CURLOPT_URL, 66 url)); 67 if (NULL != glob_unixpath) 68 GNUNET_break (CURLE_OK == 69 curl_easy_setopt (eh, 70 CURLOPT_UNIX_SOCKET_PATH, 71 glob_unixpath)); 72 TALER_curl_set_secure_redirect_policy (eh, 73 url); 74 /* Enable compression (using whatever curl likes), see 75 https://curl.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html */ 76 GNUNET_break (CURLE_OK == 77 curl_easy_setopt (eh, 78 CURLOPT_ACCEPT_ENCODING, 79 "")); 80 GNUNET_assert (CURLE_OK == 81 curl_easy_setopt (eh, 82 CURLOPT_TCP_FASTOPEN, 83 1L)); 84 return eh; 85 }