Revert "Imported Upstream version 7.53.1"
[platform/upstream/curl.git] / src / tool_libinfo.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2014, 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.haxx.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 "rawstr.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
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     { "http",   CURLPROTO_HTTP   },
59     { "https",  CURLPROTO_HTTPS  },
60     { "imap",   CURLPROTO_IMAP   },
61     { "imaps",  CURLPROTO_IMAPS  },
62     { "ldap",   CURLPROTO_LDAP   },
63     { "ldaps",  CURLPROTO_LDAPS  },
64     { "pop3",   CURLPROTO_POP3   },
65     { "pop3s",  CURLPROTO_POP3S  },
66     { "rtmp",   CURLPROTO_RTMP   },
67     { "rtsp",   CURLPROTO_RTSP   },
68     { "scp",    CURLPROTO_SCP    },
69     { "sftp",   CURLPROTO_SFTP   },
70     { "smb",    CURLPROTO_SMB    },
71     { "smbs",   CURLPROTO_SMBS   },
72     { "smtp",   CURLPROTO_SMTP   },
73     { "smtps",  CURLPROTO_SMTPS  },
74     { "telnet", CURLPROTO_TELNET },
75     { "tftp",   CURLPROTO_TFTP   },
76     {  NULL,    0                }
77   };
78
79   struct proto_name_pattern const *p;
80   const char *const *proto;
81
82   /* Pointer to libcurl's run-time version information */
83   curlinfo = curl_version_info(CURLVERSION_NOW);
84   if(!curlinfo)
85     return CURLE_FAILED_INIT;
86
87   /* Build CURLPROTO_* bit pattern with libcurl's built-in protocols */
88   built_in_protos = 0;
89   if(curlinfo->protocols) {
90     for(proto = curlinfo->protocols; *proto; proto++) {
91       for(p = possibly_built_in; p->proto_name; p++) {
92         if(curlx_raw_equal(*proto, p->proto_name)) {
93           built_in_protos |= p->proto_pattern;
94           break;
95         }
96       }
97     }
98   }
99
100   return CURLE_OK;
101 }
102