|
37 | 37 | #include "curl_form.h"
|
38 | 38 | #include "curl_easy_info.h"
|
39 | 39 |
|
40 |
| - |
41 | 40 | #define CURLCPP_DEFINE_OPTION(opt, value_type)\
|
42 | 41 | template <> struct option_t<opt> {\
|
43 | 42 | using type = value_type;\
|
44 | 43 | }
|
45 | 44 |
|
| 45 | +#define CURLCPP_DEFINE_INFO(info,value_type)\ |
| 46 | + template <> struct info_t<info> {\ |
| 47 | + using type = value_type;\ |
| 48 | + } |
| 49 | + |
46 | 50 | namespace curl {
|
| 51 | + // Definition of CURLINFO_* constants) |
| 52 | + namespace detail_info { |
| 53 | + template <CURLINFO> struct info_t; |
| 54 | + template <CURLINFO info> using Info_type = typename info_t<info>::type; |
| 55 | + // Last URL used |
| 56 | + CURLCPP_DEFINE_INFO(CURLINFO_EFFECTIVE_URL,char *); |
| 57 | + // Response code |
| 58 | + CURLCPP_DEFINE_INFO(CURLINFO_RESPONSE_CODE,long); |
| 59 | + // Last proxy connect response code |
| 60 | + CURLCPP_DEFINE_INFO(CURLINFO_HTTP_CONNECTCODE,long); |
| 61 | + // Remote time of the retrieved document. |
| 62 | + CURLCPP_DEFINE_INFO(CURLINFO_FILETIME,long); |
| 63 | + // Total time of previous transfer. |
| 64 | + CURLCPP_DEFINE_INFO(CURLINFO_TOTAL_TIME,double); |
| 65 | + // Time from start until name resolving completed. |
| 66 | + CURLCPP_DEFINE_INFO(CURLINFO_NAMELOOKUP_TIME,double); |
| 67 | + // Time from start until remote hosst proxy completed. |
| 68 | + CURLCPP_DEFINE_INFO(CURLINFO_CONNECT_TIME,double); |
| 69 | + // Time fron start until SSL/SSH handshake completed. |
| 70 | + CURLCPP_DEFINE_INFO(CURLINFO_APPCONNECT_TIME,double); |
| 71 | + // Time from start until just before the transfter begins. |
| 72 | + CURLCPP_DEFINE_INFO(CURLINFO_PRETRANSFER_TIME,double); |
| 73 | + // Time from start until just when the first byte is received. |
| 74 | + CURLCPP_DEFINE_INFO(CURLINFO_STARTTRANSFER_TIME,double); |
| 75 | + // Time taken for all redirect steps before the final transfer. |
| 76 | + CURLCPP_DEFINE_INFO(CURLINFO_REDIRECT_TIME,double); |
| 77 | + // Total number of redirects that were followed. |
| 78 | + CURLCPP_DEFINE_INFO(CURLINFO_REDIRECT_COUNT,long); |
| 79 | + // URL a redirect would take you to, had you enabled redirects. |
| 80 | + CURLCPP_DEFINE_INFO(CURLINFO_REDIRECT_URL,char *); |
| 81 | + // Number of bytes uploaded. |
| 82 | + CURLCPP_DEFINE_INFO(CURLINFO_SIZE_UPLOAD,double); |
| 83 | + // Number of bytes downloaded. |
| 84 | + CURLCPP_DEFINE_INFO(CURLINFO_SIZE_DOWNLOAD,double); |
| 85 | + // Average download speed. |
| 86 | + CURLCPP_DEFINE_INFO(CURLINFO_SPEED_DOWNLOAD,double); |
| 87 | + // Average upload speed. |
| 88 | + CURLCPP_DEFINE_INFO(CURLINFO_SPEED_UPLOAD,double); |
| 89 | + // Number of bytes of all headers received. |
| 90 | + CURLCPP_DEFINE_INFO(CURLINFO_HEADER_SIZE,long); |
| 91 | + // Number of bytes sent in the issued HTTP requests. |
| 92 | + CURLCPP_DEFINE_INFO(CURLINFO_REQUEST_SIZE,long); |
| 93 | + // Certificate verification result. |
| 94 | + CURLCPP_DEFINE_INFO(CURLINFO_SSL_VERIFYRESULT,long); |
| 95 | + // A list of OpenSSL crypto engines. |
| 96 | + CURLCPP_DEFINE_INFO(CURLINFO_SSL_ENGINES,struct curl_slist *); |
| 97 | + // Content length from the Content-Length header. |
| 98 | + CURLCPP_DEFINE_INFO(CURLINFO_CONTENT_LENGTH_DOWNLOAD,long); |
| 99 | + // Upload size. |
| 100 | + CURLCPP_DEFINE_INFO(CURLINFO_CONTENT_LENGTH_UPLOAD,long); |
| 101 | + // Content type from the Content-Type header. |
| 102 | + CURLCPP_DEFINE_INFO(CURLINFO_CONTENT_TYPE,char *); |
| 103 | + // User's private data pointer. |
| 104 | + CURLCPP_DEFINE_INFO(CURLINFO_PRIVATE,char *); |
| 105 | + // Avaiable HTTP authentication methods. |
| 106 | + CURLCPP_DEFINE_INFO(CURLINFO_HTTPAUTH_AVAIL,long); |
| 107 | + // Avaiable HTTP proxy authentication methods. |
| 108 | + CURLCPP_DEFINE_INFO(CURLINFO_PROXYAUTH_AVAIL,long); |
| 109 | + // The errno from the las failure to connect. |
| 110 | + CURLCPP_DEFINE_INFO(CURLINFO_OS_ERRNO,long); |
| 111 | + // Number of new succesful connections used for previous trasnfer. |
| 112 | + CURLCPP_DEFINE_INFO(CURLINFO_NUM_CONNECTS,long); |
| 113 | + // IP Address of the last connection. |
| 114 | + CURLCPP_DEFINE_INFO(CURLINFO_PRIMARY_IP,char *); |
| 115 | + // Port of the last connection. |
| 116 | + CURLCPP_DEFINE_INFO(CURLINFO_PRIMARY_PORT,long); |
| 117 | + // Local-end IP address of last connection. |
| 118 | + CURLCPP_DEFINE_INFO(CURLINFO_LOCAL_IP,char *); |
| 119 | + // Local-end port of last connection. |
| 120 | + CURLCPP_DEFINE_INFO(CURLINFO_LOCAL_PORT,long); |
| 121 | + // List of all known cookies. |
| 122 | + CURLCPP_DEFINE_INFO(CURLINFO_COOKIELIST,struct curl_slist *); |
| 123 | + // Last socket used. |
| 124 | + CURLCPP_DEFINE_INFO(CURLINFO_LASTSOCKET,long); |
| 125 | + // This option is avaiable in libcurl 7.45 or greater. |
| 126 | +#if defined(LIBCURL_VERSION_NUM) && LIBCURL_VERSION_NUM >= 0x072D00 |
| 127 | + // The session's active socket. |
| 128 | + CURLCPP_DEFINE_INFO(CURLINFO_ACTIVE_SOCKET,curl_socket_t *); |
| 129 | +#endif |
| 130 | + // The entry path after logging in to an FTP server. |
| 131 | + CURLCPP_DEFINE_INFO(CURLINFO_FTP_ENTRY_PATH,char *); |
| 132 | + // Certificate chain |
| 133 | + CURLCPP_DEFINE_INFO(CURLINFO_CERTINFO,struct curl_certinfo *); |
| 134 | + // This costant is avaiable with libcurl < 7.48 |
| 135 | +#if defined(LIBCURL_VERSION_NUM) && LIBCURL_VERSION_NUM < 0x073000 |
| 136 | + // TSL session info that can be used for further processing. |
| 137 | + CURLCPP_DEFINE_INFO(CURLINFO_TLS_SESSION,struct curl_tlssessioninfo *); |
| 138 | +#else |
| 139 | + // TSL session info that can be used for further processing. |
| 140 | + CURLCPP_DEFINE_INFO(CURLINFO_TSL_SSL_PTR,struct curl_tlssessioninfo *); |
| 141 | +#endif |
| 142 | + // Whether or not a time conditional was met. |
| 143 | + CURLCPP_DEFINE_INFO(CURLINFO_CONDITION_UNMET,long); |
| 144 | + // RTSP session ID. |
| 145 | + CURLCPP_DEFINE_INFO(CURLINFO_RTSP_SESSION_ID,char *); |
| 146 | + // RTSP CSeq that will next be used. |
| 147 | + CURLCPP_DEFINE_INFO(CURLINFO_RTSP_CLIENT_CSEQ,long); |
| 148 | + // RTPS CSeq that will next be expected. |
| 149 | + CURLCPP_DEFINE_INFO(CURLINFO_RTSP_SERVER_CSEQ,long); |
| 150 | + // RTSP CSeq last received. |
| 151 | + CURLCPP_DEFINE_INFO(CURLINFO_RTSP_CSEQ_RECV,long); |
| 152 | + } |
| 153 | + |
47 | 154 | // Detail namespace
|
48 | 155 | namespace detail {
|
49 | 156 | template <CURLoption> struct option_t;
|
50 | 157 | template <CURLoption opt> using Option_type = typename option_t<opt>::type;
|
51 |
| - |
52 | 158 | CURLCPP_DEFINE_OPTION(CURLOPT_WRITEDATA, void*);
|
53 |
| - |
54 | 159 | /* The full URL to get/put */
|
55 | 160 | CURLCPP_DEFINE_OPTION(CURLOPT_URL, const char*);
|
56 |
| - |
57 | 161 | /* Port number to connect to, if other than default. */
|
58 | 162 | CURLCPP_DEFINE_OPTION(CURLOPT_PORT, long);
|
59 |
| - |
60 | 163 | /* Name of proxy to use. */
|
61 | 164 | CURLCPP_DEFINE_OPTION(CURLOPT_PROXY, const char*);
|
62 |
| - |
63 | 165 | /* "user:password;options" to use when fetching. */
|
64 | 166 | CURLCPP_DEFINE_OPTION(CURLOPT_USERPWD, const char*);
|
65 |
| - |
66 | 167 | /* "user:password" to use with proxy. */
|
67 | 168 | CURLCPP_DEFINE_OPTION(CURLOPT_PROXYUSERPWD, const char*);
|
68 |
| - |
69 | 169 | /* Range to get, specified as an ASCII string. */
|
70 | 170 | CURLCPP_DEFINE_OPTION(CURLOPT_RANGE, const char*);
|
71 |
| - |
72 |
| - /* not used */ |
73 |
| - |
74 | 171 | /* Specified file stream to upload from (use as input): */
|
75 | 172 | CURLCPP_DEFINE_OPTION(CURLOPT_READDATA, void*);
|
76 |
| - |
77 | 173 | /* Buffer to receive error messages in, must be at least CURL_ERROR_SIZE
|
78 |
| - * bytes big. If this is not used, error messages go to stderr instead: */ |
| 174 | + * bytes big. If this is not used, error messages go to stderr instead: */ |
79 | 175 | CURLCPP_DEFINE_OPTION(CURLOPT_ERRORBUFFER, char*);
|
80 |
| - |
81 | 176 | /* Function that will be called to store the output (instead of fwrite). The
|
82 | 177 | * parameters will use fwrite() syntax, make sure to follow them. */
|
83 | 178 | CURLCPP_DEFINE_OPTION(CURLOPT_WRITEFUNCTION, size_t(*)(void *ptr, size_t size, size_t nmemb, void *userdata));
|
84 |
| - |
85 | 179 | /* Function that will be called to read the input (instead of fread). The
|
86 | 180 | * parameters will use fread() syntax, make sure to follow them. */
|
87 | 181 | CURLCPP_DEFINE_OPTION(CURLOPT_READFUNCTION, size_t(*)(void *buffer, size_t size, size_t nitems, void *instream));
|
88 |
| - |
89 | 182 | /* Time-out the read operation after this amount of seconds */
|
90 | 183 | CURLCPP_DEFINE_OPTION(CURLOPT_TIMEOUT, long);
|
91 |
| - |
92 | 184 | /* If the CURLOPT_INFILE is used, this can be used to inform libcurl about
|
93 |
| - * how large the file being sent really is. That allows better error |
94 |
| - * checking and better verifies that the upload was successful. -1 means |
95 |
| - * unknown size. |
96 |
| - * |
97 |
| - * For large file support, there is also a _LARGE version of the key |
98 |
| - * which takes an off_t type, allowing platforms with larger off_t |
99 |
| - * sizes to handle larger files. See below for INFILESIZE_LARGE. |
100 |
| - */ |
| 185 | + * how large the file being sent really is. That allows better error |
| 186 | + * checking and better verifies that the upload was successful. -1 means |
| 187 | + * unknown size. |
| 188 | + * |
| 189 | + * For large file support, there is also a _LARGE version of the key |
| 190 | + * which takes an off_t type, allowing platforms with larger off_t |
| 191 | + * sizes to handle larger files. See below for INFILESIZE_LARGE. */ |
101 | 192 | CURLCPP_DEFINE_OPTION(CURLOPT_INFILESIZE, long);
|
102 |
| - |
103 | 193 | /* POST static input fields. */
|
104 | 194 | CURLCPP_DEFINE_OPTION(CURLOPT_POSTFIELDS, const char*);
|
105 |
| - |
106 | 195 | /* Set the referrer page (needed by some CGIs) */
|
107 | 196 | CURLCPP_DEFINE_OPTION(CURLOPT_REFERER, const char*);
|
108 |
| - |
109 | 197 | /* Set the FTP PORT string (interface name, named or numerical IP address)
|
110 | 198 | Use i.e '-' to use default address. */
|
111 | 199 | CURLCPP_DEFINE_OPTION(CURLOPT_FTPPORT, const char*);
|
112 |
| - |
113 | 200 | /* Set the User-Agent string (examined by some CGIs) */
|
114 | 201 | CURLCPP_DEFINE_OPTION(CURLOPT_USERAGENT, const char*);
|
115 |
| - |
116 | 202 | /* If the download receives less than "low speed limit" bytes/second
|
117 |
| - * during "low speed time" seconds, the operations is aborted. |
118 |
| - * You could i.e if you have a pretty high speed connection, abort if |
119 |
| - * it is less than 2000 bytes/sec during 20 seconds. |
120 |
| - */ |
121 |
| - |
| 203 | + * during "low speed time" seconds, the operations is aborted. |
| 204 | + * You could i.e if you have a pretty high speed connection, abort if |
| 205 | + * it is less than 2000 bytes/sec during 20 seconds. |
| 206 | + */ |
122 | 207 | /* Set the "low speed limit" */
|
123 | 208 | CURLCPP_DEFINE_OPTION(CURLOPT_LOW_SPEED_LIMIT, long);
|
124 | 209 |
|
@@ -960,7 +1045,7 @@ namespace curl {
|
960 | 1045 | /**
|
961 | 1046 | * This method allows to get information about the current curl session.
|
962 | 1047 | */
|
963 |
| - template<typename T> curl::curl_easy_info<T> get_info(const CURLINFO); |
| 1048 | + template<CURLINFO Info> const curl_easy_info<detail_info::Info_type<Info>> get_info(); |
964 | 1049 | /**
|
965 | 1050 | * Simple getter method used to return the easy handle.
|
966 | 1051 | */
|
@@ -1013,11 +1098,14 @@ namespace curl {
|
1013 | 1098 | }
|
1014 | 1099 |
|
1015 | 1100 | // Implementation of get_info method.
|
1016 |
| - template<typename T> curl::curl_easy_info<T> curl_easy::get_info(const CURLINFO info) { |
1017 |
| - T *pointer; |
1018 |
| - const CURLcode code = curl_easy_getinfo(this->curl,info,&pointer); |
1019 |
| - curl::curl_easy_info<T> inf(code,pointer); |
1020 |
| - return inf; |
| 1101 | + template<CURLINFO Info> const curl_easy_info<detail_info::Info_type<Info>> curl_easy::get_info() { |
| 1102 | + detail_info::Info_type<Info> val; |
| 1103 | + const CURLcode code = curl_easy_getinfo(this->curl,Info,&val); |
| 1104 | + if (code != CURLE_OK) { |
| 1105 | + throw curl_easy_exception(code,__FUNCTION__); |
| 1106 | + } |
| 1107 | + curl_easy_info<detail_info::Info_type<Info>> easy_info(val); |
| 1108 | + return easy_info; |
1021 | 1109 | }
|
1022 | 1110 |
|
1023 | 1111 | // Implementation of get_curl method.
|
|
0 commit comments