1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ***************************************************************************/
22 #include "tool_setup.h"
23
24 #include "strcase.h"
25
26 #define ENABLE_CURLX_PRINTF
27 /* use our own printf() functions */
28 #include "curlx.h"
29
30 #include "tool_libinfo.h"
31
32 #include "memdebug.h" /* keep this as LAST include */
33
34 /* global variable definitions, for libcurl run-time info */
35
36 curl_version_info_data *curlinfo = NULL;
37 long built_in_protos = 0;
38
39 /*
40 * libcurl_info_init: retrieves run-time information about libcurl,
41 * setting a global pointer 'curlinfo' to libcurl's run-time info
42 * struct, and a global bit pattern 'built_in_protos' composed of
43 * CURLPROTO_* bits indicating which protocols are actually built
44 * into library being used.
45 */
46
get_libcurl_info(void)47 CURLcode get_libcurl_info(void)
48 {
49 static struct proto_name_pattern {
50 const char *proto_name;
51 long proto_pattern;
52 } const possibly_built_in[] = {
53 { "dict", CURLPROTO_DICT },
54 { "file", CURLPROTO_FILE },
55 { "ftp", CURLPROTO_FTP },
56 { "ftps", CURLPROTO_FTPS },
57 { "gopher", CURLPROTO_GOPHER },
58 { "gophers",CURLPROTO_GOPHERS},
59 { "http", CURLPROTO_HTTP },
60 { "https", CURLPROTO_HTTPS },
61 { "imap", CURLPROTO_IMAP },
62 { "imaps", CURLPROTO_IMAPS },
63 { "ldap", CURLPROTO_LDAP },
64 { "ldaps", CURLPROTO_LDAPS },
65 { "mqtt", CURLPROTO_MQTT },
66 { "pop3", CURLPROTO_POP3 },
67 { "pop3s", CURLPROTO_POP3S },
68 { "rtmp", CURLPROTO_RTMP },
69 { "rtmps", CURLPROTO_RTMPS },
70 { "rtsp", CURLPROTO_RTSP },
71 { "scp", CURLPROTO_SCP },
72 { "sftp", CURLPROTO_SFTP },
73 { "smb", CURLPROTO_SMB },
74 { "smbs", CURLPROTO_SMBS },
75 { "smtp", CURLPROTO_SMTP },
76 { "smtps", CURLPROTO_SMTPS },
77 { "telnet", CURLPROTO_TELNET },
78 { "tftp", CURLPROTO_TFTP },
79 { NULL, 0 }
80 };
81
82 const char *const *proto;
83
84 /* Pointer to libcurl's run-time version information */
85 curlinfo = curl_version_info(CURLVERSION_NOW);
86 if(!curlinfo)
87 return CURLE_FAILED_INIT;
88
89 /* Build CURLPROTO_* bit pattern with libcurl's built-in protocols */
90 built_in_protos = 0;
91 if(curlinfo->protocols) {
92 for(proto = curlinfo->protocols; *proto; proto++) {
93 struct proto_name_pattern const *p;
94 for(p = possibly_built_in; p->proto_name; p++) {
95 if(curl_strequal(*proto, p->proto_name)) {
96 built_in_protos |= p->proto_pattern;
97 break;
98 }
99 }
100 }
101 }
102
103 return CURLE_OK;
104 }
105