donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

donau_api_curl_defaults.c (2491B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2014-2018, 2021 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 lib/donau_api_curl_defaults.c
     19  * @brief curl easy handle defaults
     20  * @author Florian Dold
     21  * @author Lukas Matyja
     22  */
     23 
     24 #include <taler/taler_curl_lib.h>
     25 #include "donau_service.h"
     26 #include "donau_api_curl_defaults.h"
     27 
     28 
     29 /**
     30  * Global options for HTTP requests.
     31  */
     32 static enum DONAU_GlobalOptions dglobal_options;
     33 
     34 
     35 void
     36 DONAU_setup (enum DONAU_GlobalOptions go)
     37 {
     38   dglobal_options = go;
     39 }
     40 
     41 
     42 CURL *
     43 DONAU_curl_easy_get_ (const char *url)
     44 {
     45   CURL *eh;
     46 
     47   eh = curl_easy_init ();
     48   if (NULL == eh)
     49   {
     50     GNUNET_break (0);
     51     return NULL;
     52   }
     53   GNUNET_assert (CURLE_OK ==
     54                  curl_easy_setopt (eh,
     55                                    CURLOPT_URL,
     56                                    url));
     57   GNUNET_assert (CURLE_OK ==
     58                  curl_easy_setopt (eh,
     59                                    CURLOPT_FOLLOWLOCATION,
     60                                    1L));
     61   /* Enable compression (using whatever curl likes), see
     62      https://curl.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html  */
     63   GNUNET_break (CURLE_OK ==
     64                 curl_easy_setopt (eh,
     65                                   CURLOPT_ACCEPT_ENCODING,
     66                                   ""));
     67   /* limit MAXREDIRS to 5 as a simple security measure against
     68      a potential infinite loop caused by a malicious target */
     69   GNUNET_assert (CURLE_OK ==
     70                  curl_easy_setopt (eh,
     71                                    CURLOPT_MAXREDIRS,
     72                                    5L));
     73   GNUNET_assert (CURLE_OK ==
     74                  curl_easy_setopt (eh,
     75                                    CURLOPT_TCP_FASTOPEN,
     76                                    1L));
     77   TALER_curl_set_http_version (
     78     eh,
     79     (0 != (DONAU_GO_ENABLE_HTTP3 & dglobal_options)) &&
     80     (0 == (DONAU_GO_FORCE_HTTP1_1 & dglobal_options)));
     81   return eh;
     82 }