1*6236dae4SAndroid Build Coastguard Worker /***************************************************************************
2*6236dae4SAndroid Build Coastguard Worker * _ _ ____ _
3*6236dae4SAndroid Build Coastguard Worker * Project ___| | | | _ \| |
4*6236dae4SAndroid Build Coastguard Worker * / __| | | | |_) | |
5*6236dae4SAndroid Build Coastguard Worker * | (__| |_| | _ <| |___
6*6236dae4SAndroid Build Coastguard Worker * \___|\___/|_| \_\_____|
7*6236dae4SAndroid Build Coastguard Worker *
8*6236dae4SAndroid Build Coastguard Worker * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9*6236dae4SAndroid Build Coastguard Worker *
10*6236dae4SAndroid Build Coastguard Worker * This software is licensed as described in the file COPYING, which
11*6236dae4SAndroid Build Coastguard Worker * you should have received as part of this distribution. The terms
12*6236dae4SAndroid Build Coastguard Worker * are also available at https://curl.se/docs/copyright.html.
13*6236dae4SAndroid Build Coastguard Worker *
14*6236dae4SAndroid Build Coastguard Worker * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15*6236dae4SAndroid Build Coastguard Worker * copies of the Software, and permit persons to whom the Software is
16*6236dae4SAndroid Build Coastguard Worker * furnished to do so, under the terms of the COPYING file.
17*6236dae4SAndroid Build Coastguard Worker *
18*6236dae4SAndroid Build Coastguard Worker * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19*6236dae4SAndroid Build Coastguard Worker * KIND, either express or implied.
20*6236dae4SAndroid Build Coastguard Worker *
21*6236dae4SAndroid Build Coastguard Worker * SPDX-License-Identifier: curl
22*6236dae4SAndroid Build Coastguard Worker *
23*6236dae4SAndroid Build Coastguard Worker ***************************************************************************/
24*6236dae4SAndroid Build Coastguard Worker #include "tool_setup.h"
25*6236dae4SAndroid Build Coastguard Worker
26*6236dae4SAndroid Build Coastguard Worker #include "strcase.h"
27*6236dae4SAndroid Build Coastguard Worker
28*6236dae4SAndroid Build Coastguard Worker #include "curlx.h"
29*6236dae4SAndroid Build Coastguard Worker
30*6236dae4SAndroid Build Coastguard Worker #include "tool_libinfo.h"
31*6236dae4SAndroid Build Coastguard Worker
32*6236dae4SAndroid Build Coastguard Worker #include "memdebug.h" /* keep this as LAST include */
33*6236dae4SAndroid Build Coastguard Worker
34*6236dae4SAndroid Build Coastguard Worker /* global variable definitions, for libcurl runtime info */
35*6236dae4SAndroid Build Coastguard Worker
36*6236dae4SAndroid Build Coastguard Worker static const char *no_protos = NULL;
37*6236dae4SAndroid Build Coastguard Worker
38*6236dae4SAndroid Build Coastguard Worker curl_version_info_data *curlinfo = NULL;
39*6236dae4SAndroid Build Coastguard Worker const char * const *built_in_protos = &no_protos;
40*6236dae4SAndroid Build Coastguard Worker
41*6236dae4SAndroid Build Coastguard Worker size_t proto_count = 0;
42*6236dae4SAndroid Build Coastguard Worker
43*6236dae4SAndroid Build Coastguard Worker const char *proto_file = NULL;
44*6236dae4SAndroid Build Coastguard Worker const char *proto_ftp = NULL;
45*6236dae4SAndroid Build Coastguard Worker const char *proto_ftps = NULL;
46*6236dae4SAndroid Build Coastguard Worker const char *proto_http = NULL;
47*6236dae4SAndroid Build Coastguard Worker const char *proto_https = NULL;
48*6236dae4SAndroid Build Coastguard Worker const char *proto_rtsp = NULL;
49*6236dae4SAndroid Build Coastguard Worker const char *proto_scp = NULL;
50*6236dae4SAndroid Build Coastguard Worker const char *proto_sftp = NULL;
51*6236dae4SAndroid Build Coastguard Worker const char *proto_tftp = NULL;
52*6236dae4SAndroid Build Coastguard Worker #ifndef CURL_DISABLE_IPFS
53*6236dae4SAndroid Build Coastguard Worker const char *proto_ipfs = "ipfs";
54*6236dae4SAndroid Build Coastguard Worker const char *proto_ipns = "ipns";
55*6236dae4SAndroid Build Coastguard Worker #endif /* !CURL_DISABLE_IPFS */
56*6236dae4SAndroid Build Coastguard Worker
57*6236dae4SAndroid Build Coastguard Worker static struct proto_name_tokenp {
58*6236dae4SAndroid Build Coastguard Worker const char *proto_name;
59*6236dae4SAndroid Build Coastguard Worker const char **proto_tokenp;
60*6236dae4SAndroid Build Coastguard Worker } const possibly_built_in[] = {
61*6236dae4SAndroid Build Coastguard Worker { "file", &proto_file },
62*6236dae4SAndroid Build Coastguard Worker { "ftp", &proto_ftp },
63*6236dae4SAndroid Build Coastguard Worker { "ftps", &proto_ftps },
64*6236dae4SAndroid Build Coastguard Worker { "http", &proto_http },
65*6236dae4SAndroid Build Coastguard Worker { "https", &proto_https },
66*6236dae4SAndroid Build Coastguard Worker { "rtsp", &proto_rtsp },
67*6236dae4SAndroid Build Coastguard Worker { "scp", &proto_scp },
68*6236dae4SAndroid Build Coastguard Worker { "sftp", &proto_sftp },
69*6236dae4SAndroid Build Coastguard Worker { "tftp", &proto_tftp },
70*6236dae4SAndroid Build Coastguard Worker { NULL, NULL }
71*6236dae4SAndroid Build Coastguard Worker };
72*6236dae4SAndroid Build Coastguard Worker
73*6236dae4SAndroid Build Coastguard Worker bool feature_altsvc = FALSE;
74*6236dae4SAndroid Build Coastguard Worker bool feature_brotli = FALSE;
75*6236dae4SAndroid Build Coastguard Worker bool feature_hsts = FALSE;
76*6236dae4SAndroid Build Coastguard Worker bool feature_http2 = FALSE;
77*6236dae4SAndroid Build Coastguard Worker bool feature_http3 = FALSE;
78*6236dae4SAndroid Build Coastguard Worker bool feature_httpsproxy = FALSE;
79*6236dae4SAndroid Build Coastguard Worker bool feature_libz = FALSE;
80*6236dae4SAndroid Build Coastguard Worker bool feature_ntlm = FALSE;
81*6236dae4SAndroid Build Coastguard Worker bool feature_ntlm_wb = FALSE;
82*6236dae4SAndroid Build Coastguard Worker bool feature_spnego = FALSE;
83*6236dae4SAndroid Build Coastguard Worker bool feature_ssl = FALSE;
84*6236dae4SAndroid Build Coastguard Worker bool feature_tls_srp = FALSE;
85*6236dae4SAndroid Build Coastguard Worker bool feature_zstd = FALSE;
86*6236dae4SAndroid Build Coastguard Worker bool feature_ech = FALSE;
87*6236dae4SAndroid Build Coastguard Worker
88*6236dae4SAndroid Build Coastguard Worker static struct feature_name_presentp {
89*6236dae4SAndroid Build Coastguard Worker const char *feature_name;
90*6236dae4SAndroid Build Coastguard Worker bool *feature_presentp;
91*6236dae4SAndroid Build Coastguard Worker int feature_bitmask;
92*6236dae4SAndroid Build Coastguard Worker } const maybe_feature[] = {
93*6236dae4SAndroid Build Coastguard Worker /* Keep alphabetically sorted. */
94*6236dae4SAndroid Build Coastguard Worker {"alt-svc", &feature_altsvc, CURL_VERSION_ALTSVC},
95*6236dae4SAndroid Build Coastguard Worker {"AsynchDNS", NULL, CURL_VERSION_ASYNCHDNS},
96*6236dae4SAndroid Build Coastguard Worker {"brotli", &feature_brotli, CURL_VERSION_BROTLI},
97*6236dae4SAndroid Build Coastguard Worker {"CharConv", NULL, CURL_VERSION_CONV},
98*6236dae4SAndroid Build Coastguard Worker {"Debug", NULL, CURL_VERSION_DEBUG},
99*6236dae4SAndroid Build Coastguard Worker {"ECH", &feature_ech, 0},
100*6236dae4SAndroid Build Coastguard Worker {"gsasl", NULL, CURL_VERSION_GSASL},
101*6236dae4SAndroid Build Coastguard Worker {"GSS-API", NULL, CURL_VERSION_GSSAPI},
102*6236dae4SAndroid Build Coastguard Worker {"HSTS", &feature_hsts, CURL_VERSION_HSTS},
103*6236dae4SAndroid Build Coastguard Worker {"HTTP2", &feature_http2, CURL_VERSION_HTTP2},
104*6236dae4SAndroid Build Coastguard Worker {"HTTP3", &feature_http3, CURL_VERSION_HTTP3},
105*6236dae4SAndroid Build Coastguard Worker {"HTTPS-proxy", &feature_httpsproxy, CURL_VERSION_HTTPS_PROXY},
106*6236dae4SAndroid Build Coastguard Worker {"IDN", NULL, CURL_VERSION_IDN},
107*6236dae4SAndroid Build Coastguard Worker {"IPv6", NULL, CURL_VERSION_IPV6},
108*6236dae4SAndroid Build Coastguard Worker {"Kerberos", NULL, CURL_VERSION_KERBEROS5},
109*6236dae4SAndroid Build Coastguard Worker {"Largefile", NULL, CURL_VERSION_LARGEFILE},
110*6236dae4SAndroid Build Coastguard Worker {"libz", &feature_libz, CURL_VERSION_LIBZ},
111*6236dae4SAndroid Build Coastguard Worker {"MultiSSL", NULL, CURL_VERSION_MULTI_SSL},
112*6236dae4SAndroid Build Coastguard Worker {"NTLM", &feature_ntlm, CURL_VERSION_NTLM},
113*6236dae4SAndroid Build Coastguard Worker {"NTLM_WB", &feature_ntlm_wb, CURL_VERSION_NTLM_WB},
114*6236dae4SAndroid Build Coastguard Worker {"PSL", NULL, CURL_VERSION_PSL},
115*6236dae4SAndroid Build Coastguard Worker {"SPNEGO", &feature_spnego, CURL_VERSION_SPNEGO},
116*6236dae4SAndroid Build Coastguard Worker {"SSL", &feature_ssl, CURL_VERSION_SSL},
117*6236dae4SAndroid Build Coastguard Worker {"SSPI", NULL, CURL_VERSION_SSPI},
118*6236dae4SAndroid Build Coastguard Worker {"threadsafe", NULL, CURL_VERSION_THREADSAFE},
119*6236dae4SAndroid Build Coastguard Worker {"TLS-SRP", &feature_tls_srp, CURL_VERSION_TLSAUTH_SRP},
120*6236dae4SAndroid Build Coastguard Worker {"TrackMemory", NULL, CURL_VERSION_CURLDEBUG},
121*6236dae4SAndroid Build Coastguard Worker {"Unicode", NULL, CURL_VERSION_UNICODE},
122*6236dae4SAndroid Build Coastguard Worker {"UnixSockets", NULL, CURL_VERSION_UNIX_SOCKETS},
123*6236dae4SAndroid Build Coastguard Worker {"zstd", &feature_zstd, CURL_VERSION_ZSTD},
124*6236dae4SAndroid Build Coastguard Worker {NULL, NULL, 0}
125*6236dae4SAndroid Build Coastguard Worker };
126*6236dae4SAndroid Build Coastguard Worker
127*6236dae4SAndroid Build Coastguard Worker static const char *fnames[sizeof(maybe_feature) / sizeof(maybe_feature[0])];
128*6236dae4SAndroid Build Coastguard Worker const char * const *feature_names = fnames;
129*6236dae4SAndroid Build Coastguard Worker size_t feature_count;
130*6236dae4SAndroid Build Coastguard Worker
131*6236dae4SAndroid Build Coastguard Worker /*
132*6236dae4SAndroid Build Coastguard Worker * libcurl_info_init: retrieves runtime information about libcurl,
133*6236dae4SAndroid Build Coastguard Worker * setting a global pointer 'curlinfo' to libcurl's runtime info
134*6236dae4SAndroid Build Coastguard Worker * struct, count protocols and flag those we are interested in.
135*6236dae4SAndroid Build Coastguard Worker * Global pointer feature_names is set to the feature names array. If
136*6236dae4SAndroid Build Coastguard Worker * the latter is not returned by curl_version_info(), it is built from
137*6236dae4SAndroid Build Coastguard Worker * the returned features bit mask.
138*6236dae4SAndroid Build Coastguard Worker */
139*6236dae4SAndroid Build Coastguard Worker
get_libcurl_info(void)140*6236dae4SAndroid Build Coastguard Worker CURLcode get_libcurl_info(void)
141*6236dae4SAndroid Build Coastguard Worker {
142*6236dae4SAndroid Build Coastguard Worker CURLcode result = CURLE_OK;
143*6236dae4SAndroid Build Coastguard Worker const char *const *builtin;
144*6236dae4SAndroid Build Coastguard Worker
145*6236dae4SAndroid Build Coastguard Worker /* Pointer to libcurl's runtime version information */
146*6236dae4SAndroid Build Coastguard Worker curlinfo = curl_version_info(CURLVERSION_NOW);
147*6236dae4SAndroid Build Coastguard Worker if(!curlinfo)
148*6236dae4SAndroid Build Coastguard Worker return CURLE_FAILED_INIT;
149*6236dae4SAndroid Build Coastguard Worker
150*6236dae4SAndroid Build Coastguard Worker if(curlinfo->protocols) {
151*6236dae4SAndroid Build Coastguard Worker const struct proto_name_tokenp *p;
152*6236dae4SAndroid Build Coastguard Worker
153*6236dae4SAndroid Build Coastguard Worker built_in_protos = curlinfo->protocols;
154*6236dae4SAndroid Build Coastguard Worker
155*6236dae4SAndroid Build Coastguard Worker for(builtin = built_in_protos; !result && *builtin; builtin++) {
156*6236dae4SAndroid Build Coastguard Worker /* Identify protocols we are interested in. */
157*6236dae4SAndroid Build Coastguard Worker for(p = possibly_built_in; p->proto_name; p++)
158*6236dae4SAndroid Build Coastguard Worker if(curl_strequal(p->proto_name, *builtin)) {
159*6236dae4SAndroid Build Coastguard Worker *p->proto_tokenp = *builtin;
160*6236dae4SAndroid Build Coastguard Worker break;
161*6236dae4SAndroid Build Coastguard Worker }
162*6236dae4SAndroid Build Coastguard Worker }
163*6236dae4SAndroid Build Coastguard Worker proto_count = builtin - built_in_protos;
164*6236dae4SAndroid Build Coastguard Worker }
165*6236dae4SAndroid Build Coastguard Worker
166*6236dae4SAndroid Build Coastguard Worker if(curlinfo->age >= CURLVERSION_ELEVENTH && curlinfo->feature_names)
167*6236dae4SAndroid Build Coastguard Worker feature_names = curlinfo->feature_names;
168*6236dae4SAndroid Build Coastguard Worker else {
169*6236dae4SAndroid Build Coastguard Worker const struct feature_name_presentp *p;
170*6236dae4SAndroid Build Coastguard Worker const char **cpp = fnames;
171*6236dae4SAndroid Build Coastguard Worker
172*6236dae4SAndroid Build Coastguard Worker for(p = maybe_feature; p->feature_name; p++)
173*6236dae4SAndroid Build Coastguard Worker if(curlinfo->features & p->feature_bitmask)
174*6236dae4SAndroid Build Coastguard Worker *cpp++ = p->feature_name;
175*6236dae4SAndroid Build Coastguard Worker *cpp = NULL;
176*6236dae4SAndroid Build Coastguard Worker }
177*6236dae4SAndroid Build Coastguard Worker
178*6236dae4SAndroid Build Coastguard Worker /* Identify features we are interested in. */
179*6236dae4SAndroid Build Coastguard Worker for(builtin = feature_names; *builtin; builtin++) {
180*6236dae4SAndroid Build Coastguard Worker const struct feature_name_presentp *p;
181*6236dae4SAndroid Build Coastguard Worker
182*6236dae4SAndroid Build Coastguard Worker for(p = maybe_feature; p->feature_name; p++)
183*6236dae4SAndroid Build Coastguard Worker if(curl_strequal(p->feature_name, *builtin)) {
184*6236dae4SAndroid Build Coastguard Worker if(p->feature_presentp)
185*6236dae4SAndroid Build Coastguard Worker *p->feature_presentp = TRUE;
186*6236dae4SAndroid Build Coastguard Worker break;
187*6236dae4SAndroid Build Coastguard Worker }
188*6236dae4SAndroid Build Coastguard Worker ++feature_count;
189*6236dae4SAndroid Build Coastguard Worker }
190*6236dae4SAndroid Build Coastguard Worker
191*6236dae4SAndroid Build Coastguard Worker return CURLE_OK;
192*6236dae4SAndroid Build Coastguard Worker }
193*6236dae4SAndroid Build Coastguard Worker
194*6236dae4SAndroid Build Coastguard Worker /* Tokenize a protocol name.
195*6236dae4SAndroid Build Coastguard Worker * Return the address of the protocol name listed by the library, or NULL if
196*6236dae4SAndroid Build Coastguard Worker * not found.
197*6236dae4SAndroid Build Coastguard Worker * Although this may seem useless, this always returns the same address for
198*6236dae4SAndroid Build Coastguard Worker * a given protocol and thus allows comparing pointers rather than strings.
199*6236dae4SAndroid Build Coastguard Worker * In addition, the returned pointer is not deallocated until the program ends.
200*6236dae4SAndroid Build Coastguard Worker */
201*6236dae4SAndroid Build Coastguard Worker
proto_token(const char * proto)202*6236dae4SAndroid Build Coastguard Worker const char *proto_token(const char *proto)
203*6236dae4SAndroid Build Coastguard Worker {
204*6236dae4SAndroid Build Coastguard Worker const char * const *builtin;
205*6236dae4SAndroid Build Coastguard Worker
206*6236dae4SAndroid Build Coastguard Worker if(!proto)
207*6236dae4SAndroid Build Coastguard Worker return NULL;
208*6236dae4SAndroid Build Coastguard Worker for(builtin = built_in_protos; *builtin; builtin++)
209*6236dae4SAndroid Build Coastguard Worker if(curl_strequal(*builtin, proto))
210*6236dae4SAndroid Build Coastguard Worker break;
211*6236dae4SAndroid Build Coastguard Worker return *builtin;
212*6236dae4SAndroid Build Coastguard Worker }
213