File: curlhelper_p.h

package info (click to toggle)
libzypp 17.36.7-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 26,380 kB
  • sloc: cpp: 132,576; xml: 2,587; sh: 486; makefile: 26; python: 23
file content (109 lines) | stat: -rw-r--r-- 3,554 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*---------------------------------------------------------------------\
|                          ____ _   __ __ ___                          |
|                         |__  / \ / / . \ . \                         |
|                           / / \ V /|  _/  _/                         |
|                          / /__ | | | | | |                           |
|                         /_____||_| |_| |_|                           |
|                                                                      |
----------------------------------------------------------------------/
*
* This file contains private API, this might break at any time between releases.
* You have been warned!
*
*/
#ifndef ZYPP_MEDIA_PRIVATE_CURLHELPER_P_H_INCLUDED
#define ZYPP_MEDIA_PRIVATE_CURLHELPER_P_H_INCLUDED

#include <curl/curl.h>
#include <zypp-core/Url.h>
#include <zypp-curl/TransferSettings>

#include <optional>

#define EXPLICITLY_NO_PROXY "_none_"

#undef CURLVERSION_AT_LEAST
#define CURLVERSION_AT_LEAST(M,N,O) LIBCURL_VERSION_NUM >= ((((M)<<8)+(N))<<8)+(O)

using GPollFD = struct _GPollFD;

namespace zypp
{
  namespace env
  {
    /** \c const long& for setting CURLOPT_DEBUGDATA
     * Returns a reference to a static variable, so it's
     * safe to pass it's address to CURLOPT_DEBUGDATA.
     */
    const long & ZYPP_MEDIA_CURL_DEBUG();

    /** 4/6 to force IPv4/v6 */
    int ZYPP_MEDIA_CURL_IPRESOLVE();
  } // namespace env
} //namespace zypp

//do not export
namespace internal {

void globalInitCurlOnce();

uint curlVersion();

/** Setup CURLOPT_VERBOSE and CURLOPT_DEBUGFUNCTION according to env::ZYPP_MEDIA_CURL_DEBUG. */
void setupZYPP_MEDIA_CURL_DEBUG( CURL *curl );
size_t log_redirects_curl( char *ptr, size_t size, size_t nmemb, void *userdata);

void fillSettingsFromUrl( const zypp::Url &url, zypp::media::TransferSettings &s );
void fillSettingsSystemProxy( const zypp::Url& url, zypp::media::TransferSettings &s );

void curlEscape( std::string & str_r,  const char char_r, const std::string & escaped_r );
std::string curlEscapedPath( std::string path_r );
std::string curlUnEscape( const std::string& text_r );

zypp::Url clearQueryString(const zypp::Url &url);
zypp::Url propagateQueryParams( zypp::Url url_r, const zypp::Url & template_r );

CURLcode setCurlRedirProtocols(CURL *curl);

/*!
 * Helper class to simplify using the curl multi API, takes
 * care of remembering the registered sockets and the required curl timeout.
 */
struct CurlPollHelper
{
  struct CurlPoll {
    CURLM *_multi = nullptr;
  };

  CurlPollHelper( CurlPoll &p );
  ~CurlPollHelper();

  /*!
   * Iterator over the passed in poll fd's and call curl_multi_socket_action on them if one of
   * them signals that events have happened
   */
  CURLMcode handleSocketActions( const std::vector<GPollFD> &actionsFds, int first = 0 );

  /*!
   * Tells libcurl that the requested timeout was reached.
   */
  CURLMcode handleTimout ();

  /*!
   * Callback for libcurl when it wants us to track or stop us from tracking a socket
   */
  static int socketcb (CURL * easy, curl_socket_t s, int what, CurlPollHelper *userp, void *sockp );

  /*!
   * Callback for libcurl when it wants us to start/update/remove a timer
   */
  static int timercb( CURLM *, long timeout_ms, CurlPollHelper *thatPtr );

  CurlPoll &_parent;
  std::vector<GPollFD> socks; //< This is the list of fd's we need to track, events have been set by curl
  std::optional<long> timeout_ms = 0; //if set curl wants a timeout
};

}

#endif //ZYPP_MEDIA_PRIVATE_CURLHELPER_P_H_INCLUDED