Skip to content

Commit 4a41c4b

Browse files
author
nono303
committed
Use feature_names if available instead of const feats[] and display features as list (like for protocols)
1 parent 72f3931 commit 4a41c4b

File tree

1 file changed

+85
-66
lines changed

1 file changed

+85
-66
lines changed

ext/curl/interface.c

Lines changed: 85 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -276,67 +276,78 @@ PHP_MINFO_FUNCTION(curl)
276276
snprintf(str, sizeof(str), "%d", d->age);
277277
php_info_print_table_row(2, "Age", str);
278278

279-
/* To update on each new cURL release using src/main.c in cURL sources */
280-
/* make sure to sync this list with curl_version as well */
281-
if (d->features) {
282-
struct feat {
283-
const char *name;
284-
int bitmask;
285-
};
286-
287-
unsigned int i;
288-
289-
static const struct feat feats[] = {
290-
{"AsynchDNS", CURL_VERSION_ASYNCHDNS},
291-
{"CharConv", CURL_VERSION_CONV},
292-
{"Debug", CURL_VERSION_DEBUG},
293-
{"MemoryDebug", CURL_VERSION_CURLDEBUG},
294-
{"GSS-Negotiate", CURL_VERSION_GSSNEGOTIATE},
295-
{"IDN", CURL_VERSION_IDN},
296-
{"IPv6", CURL_VERSION_IPV6},
297-
{"krb4", CURL_VERSION_KERBEROS4},
298-
{"Largefile", CURL_VERSION_LARGEFILE},
299-
{"libz", CURL_VERSION_LIBZ},
300-
{"NTLM", CURL_VERSION_NTLM},
301-
{"NTLMWB", CURL_VERSION_NTLM_WB},
302-
{"SPNEGO", CURL_VERSION_SPNEGO},
303-
{"SSL", CURL_VERSION_SSL},
304-
{"SSPI", CURL_VERSION_SSPI},
305-
{"TLS-SRP", CURL_VERSION_TLSAUTH_SRP},
306-
{"HTTP2", CURL_VERSION_HTTP2},
307-
{"GSSAPI", CURL_VERSION_GSSAPI},
308-
{"KERBEROS5", CURL_VERSION_KERBEROS5},
309-
{"UNIX_SOCKETS", CURL_VERSION_UNIX_SOCKETS},
310-
{"PSL", CURL_VERSION_PSL},
311-
{"HTTPS_PROXY", CURL_VERSION_HTTPS_PROXY},
312-
{"MULTI_SSL", CURL_VERSION_MULTI_SSL},
313-
{"BROTLI", CURL_VERSION_BROTLI},
314-
#if LIBCURL_VERSION_NUM >= 0x074001 /* Available since 7.64.1 */
315-
{"ALTSVC", CURL_VERSION_ALTSVC},
316-
#endif
317-
#if LIBCURL_VERSION_NUM >= 0x074200 /* Available since 7.66.0 */
318-
{"HTTP3", CURL_VERSION_HTTP3},
319-
#endif
320-
#if LIBCURL_VERSION_NUM >= 0x074800 /* Available since 7.72.0 */
321-
{"UNICODE", CURL_VERSION_UNICODE},
322-
{"ZSTD", CURL_VERSION_ZSTD},
323-
#endif
324-
#if LIBCURL_VERSION_NUM >= 0x074a00 /* Available since 7.74.0 */
325-
{"HSTS", CURL_VERSION_HSTS},
326-
#endif
327-
#if LIBCURL_VERSION_NUM >= 0x074c00 /* Available since 7.76.0 */
328-
{"GSASL", CURL_VERSION_GSASL},
329-
#endif
330-
#if LIBCURL_VERSION_NUM >= 0x075600 /* Available since 7.86.0 */
331-
{"ThreadSafe", CURL_VERSION_THREADSAFE},
332-
#endif
333-
{NULL, 0}
334-
};
335-
336-
php_info_print_table_row(1, "Features");
337-
for(i=0; i<sizeof(feats)/sizeof(feats[0]); i++) {
338-
if (feats[i].name) {
339-
php_info_print_table_row(2, feats[i].name, d->features & feats[i].bitmask ? "Yes" : "No");
279+
// Features
280+
if (d->age >= CURLVERSION_ELEVENTH && d->feature_names) {
281+
n = 0;
282+
p = (char **) d->feature_names;
283+
while (*p != NULL) {
284+
n += snprintf(str + n, sizeof(str) - n, "%s%s", *p, *(p + 1) != NULL ? ", " : "");
285+
p++;
286+
}
287+
php_info_print_table_row(2, "Features", str);
288+
} else {
289+
/* To update on each new cURL release using src/main.c in cURL sources */
290+
/* make sure to sync this list with curl_version as well */
291+
if (d->features) {
292+
struct feat {
293+
const char *name;
294+
int bitmask;
295+
};
296+
297+
unsigned int i;
298+
299+
static const struct feat feats[] = {
300+
{"AsynchDNS", CURL_VERSION_ASYNCHDNS},
301+
{"CharConv", CURL_VERSION_CONV},
302+
{"Debug", CURL_VERSION_DEBUG},
303+
{"MemoryDebug", CURL_VERSION_CURLDEBUG},
304+
{"GSS-Negotiate", CURL_VERSION_GSSNEGOTIATE},
305+
{"IDN", CURL_VERSION_IDN},
306+
{"IPv6", CURL_VERSION_IPV6},
307+
{"krb4", CURL_VERSION_KERBEROS4},
308+
{"Largefile", CURL_VERSION_LARGEFILE},
309+
{"libz", CURL_VERSION_LIBZ},
310+
{"NTLM", CURL_VERSION_NTLM},
311+
{"NTLMWB", CURL_VERSION_NTLM_WB},
312+
{"SPNEGO", CURL_VERSION_SPNEGO},
313+
{"SSL", CURL_VERSION_SSL},
314+
{"SSPI", CURL_VERSION_SSPI},
315+
{"TLS-SRP", CURL_VERSION_TLSAUTH_SRP},
316+
{"HTTP2", CURL_VERSION_HTTP2},
317+
{"GSSAPI", CURL_VERSION_GSSAPI},
318+
{"KERBEROS5", CURL_VERSION_KERBEROS5},
319+
{"UNIX_SOCKETS", CURL_VERSION_UNIX_SOCKETS},
320+
{"PSL", CURL_VERSION_PSL},
321+
{"HTTPS_PROXY", CURL_VERSION_HTTPS_PROXY},
322+
{"MULTI_SSL", CURL_VERSION_MULTI_SSL},
323+
{"BROTLI", CURL_VERSION_BROTLI},
324+
#if LIBCURL_VERSION_NUM >= 0x074001 /* Available since 7.64.1 */
325+
{"ALTSVC", CURL_VERSION_ALTSVC},
326+
#endif
327+
#if LIBCURL_VERSION_NUM >= 0x074200 /* Available since 7.66.0 */
328+
{"HTTP3", CURL_VERSION_HTTP3},
329+
#endif
330+
#if LIBCURL_VERSION_NUM >= 0x074800 /* Available since 7.72.0 */
331+
{"UNICODE", CURL_VERSION_UNICODE},
332+
{"ZSTD", CURL_VERSION_ZSTD},
333+
#endif
334+
#if LIBCURL_VERSION_NUM >= 0x074a00 /* Available since 7.74.0 */
335+
{"HSTS", CURL_VERSION_HSTS},
336+
#endif
337+
#if LIBCURL_VERSION_NUM >= 0x074c00 /* Available since 7.76.0 */
338+
{"GSASL", CURL_VERSION_GSASL},
339+
#endif
340+
#if LIBCURL_VERSION_NUM >= 0x075600 /* Available since 7.86.0 */
341+
{"ThreadSafe", CURL_VERSION_THREADSAFE},
342+
#endif
343+
{NULL, 0}
344+
};
345+
346+
php_info_print_table_row(1, "Features");
347+
for(i=0; i<sizeof(feats)/sizeof(feats[0]); i++) {
348+
if (feats[i].name) {
349+
php_info_print_table_row(2, feats[i].name, d->features & feats[i].bitmask ? "Yes" : "No");
350+
}
340351
}
341352
}
342353
}
@@ -1034,17 +1045,26 @@ PHP_FUNCTION(curl_version)
10341045

10351046
CAAL("version_number", d->version_num);
10361047
CAAL("age", d->age);
1037-
CAAL("features", d->features);
1048+
10381049
/* Add an array of features */
1050+
zval feature_list;
1051+
array_init(&feature_list);
1052+
if (d->age >= CURLVERSION_ELEVENTH && d->feature_names) {
10391053
{
1054+
char **p = (char **) d->feature_names;
1055+
while (*p != NULL) {
1056+
add_next_index_string(&feature_list, *p);
1057+
p++;
1058+
}
1059+
}
1060+
} else {
1061+
{
10401062
struct feat {
10411063
const char *name;
10421064
int bitmask;
10431065
};
10441066

10451067
unsigned int i;
1046-
zval feature_list;
1047-
array_init(&feature_list);
10481068

10491069
/* Sync this list with PHP_MINFO_FUNCTION(curl) as well */
10501070
static const struct feat feats[] = {
@@ -1098,9 +1118,8 @@ PHP_FUNCTION(curl_version)
10981118
add_assoc_bool(&feature_list, feats[i].name, d->features & feats[i].bitmask ? true : false);
10991119
}
11001120
}
1101-
1102-
CAAZ("feature_list", &feature_list);
11031121
}
1122+
CAAZ("features", &feature_list);
11041123
CAAL("ssl_version_number", d->ssl_version_num);
11051124
CAAS("version", d->version);
11061125
CAAS("host", d->host);

0 commit comments

Comments
 (0)