Imported Upstream version 7.40.0
[platform/upstream/curl.git] / lib / version.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 http://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
23 #include "curl_setup.h"
24
25 #include <curl/curl.h>
26 #include "urldata.h"
27 #include "vtls/vtls.h"
28 #include "http2.h"
29
30 #define _MPRINTF_REPLACE /* use the internal *printf() functions */
31 #include <curl/mprintf.h>
32
33 #ifdef USE_ARES
34 #  if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && \
35      (defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__))
36 #    define CARES_STATICLIB
37 #  endif
38 #  include <ares.h>
39 #endif
40
41 #ifdef USE_LIBIDN
42 #include <stringprep.h>
43 #endif
44
45 #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
46 #include <iconv.h>
47 #endif
48
49 #ifdef USE_LIBRTMP
50 #include <librtmp/rtmp.h>
51 #endif
52
53 #ifdef USE_LIBSSH2
54 #include <libssh2.h>
55 #endif
56
57 #ifdef HAVE_LIBSSH2_VERSION
58 /* get it run-time if possible */
59 #define CURL_LIBSSH2_VERSION libssh2_version(0)
60 #else
61 /* use build-time if run-time not possible */
62 #define CURL_LIBSSH2_VERSION LIBSSH2_VERSION
63 #endif
64
65 char *curl_version(void)
66 {
67   static char version[200];
68   char *ptr = version;
69   size_t len;
70   size_t left = sizeof(version);
71
72   strcpy(ptr, LIBCURL_NAME "/" LIBCURL_VERSION);
73   len = strlen(ptr);
74   left -= len;
75   ptr += len;
76
77   if(left > 1) {
78     len = Curl_ssl_version(ptr + 1, left - 1);
79
80     if(len > 0) {
81       *ptr = ' ';
82       left -= ++len;
83       ptr += len;
84     }
85   }
86
87 #ifdef HAVE_LIBZ
88   len = snprintf(ptr, left, " zlib/%s", zlibVersion());
89   left -= len;
90   ptr += len;
91 #endif
92 #ifdef USE_ARES
93   /* this function is only present in c-ares, not in the original ares */
94   len = snprintf(ptr, left, " c-ares/%s", ares_version(NULL));
95   left -= len;
96   ptr += len;
97 #endif
98 #ifdef USE_LIBIDN
99   if(stringprep_check_version(LIBIDN_REQUIRED_VERSION)) {
100     len = snprintf(ptr, left, " libidn/%s", stringprep_check_version(NULL));
101     left -= len;
102     ptr += len;
103   }
104 #endif
105 #ifdef USE_WIN32_IDN
106   len = snprintf(ptr, left, " WinIDN");
107   left -= len;
108   ptr += len;
109 #endif
110 #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
111 #ifdef _LIBICONV_VERSION
112   len = snprintf(ptr, left, " iconv/%d.%d",
113                  _LIBICONV_VERSION >> 8, _LIBICONV_VERSION & 255);
114 #else
115   /* version unknown */
116   len = snprintf(ptr, left, " iconv");
117 #endif /* _LIBICONV_VERSION */
118   left -= len;
119   ptr += len;
120 #endif
121 #ifdef USE_LIBSSH2
122   len = snprintf(ptr, left, " libssh2/%s", CURL_LIBSSH2_VERSION);
123   left -= len;
124   ptr += len;
125 #endif
126 #ifdef USE_NGHTTP2
127   len = Curl_http2_ver(ptr, left);
128   left -= len;
129   ptr += len;
130 #endif
131 #ifdef USE_LIBRTMP
132   {
133     char suff[2];
134     if(RTMP_LIB_VERSION & 0xff) {
135       suff[0] = (RTMP_LIB_VERSION & 0xff) + 'a' - 1;
136       suff[1] = '\0';
137     }
138     else
139       suff[0] = '\0';
140
141     snprintf(ptr, left, " librtmp/%d.%d%s",
142              RTMP_LIB_VERSION >> 16, (RTMP_LIB_VERSION >> 8) & 0xff,
143              suff);
144 /*
145   If another lib version is added below this one, this code would
146   also have to do:
147
148     len = what snprintf() returned
149
150     left -= len;
151     ptr += len;
152 */
153   }
154 #endif
155
156   return version;
157 }
158
159 /* data for curl_version_info
160
161    Keep the list sorted alphabetically. It is also written so that each
162    protocol line has its own #if line to make things easier on the eye.
163  */
164
165 static const char * const protocols[] = {
166 #ifndef CURL_DISABLE_DICT
167   "dict",
168 #endif
169 #ifndef CURL_DISABLE_FILE
170   "file",
171 #endif
172 #ifndef CURL_DISABLE_FTP
173   "ftp",
174 #endif
175 #if defined(USE_SSL) && !defined(CURL_DISABLE_FTP)
176   "ftps",
177 #endif
178 #ifndef CURL_DISABLE_GOPHER
179   "gopher",
180 #endif
181 #ifndef CURL_DISABLE_HTTP
182   "http",
183 #endif
184 #if defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)
185   "https",
186 #endif
187 #ifndef CURL_DISABLE_IMAP
188   "imap",
189 #endif
190 #if defined(USE_SSL) && !defined(CURL_DISABLE_IMAP)
191   "imaps",
192 #endif
193 #ifndef CURL_DISABLE_LDAP
194   "ldap",
195 #if !defined(CURL_DISABLE_LDAPS) && \
196     ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \
197      (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL)))
198   "ldaps",
199 #endif
200 #endif
201 #ifndef CURL_DISABLE_POP3
202   "pop3",
203 #endif
204 #if defined(USE_SSL) && !defined(CURL_DISABLE_POP3)
205   "pop3s",
206 #endif
207 #ifdef USE_LIBRTMP
208   "rtmp",
209 #endif
210 #ifndef CURL_DISABLE_RTSP
211   "rtsp",
212 #endif
213 #ifdef USE_LIBSSH2
214   "scp",
215 #endif
216 #ifdef USE_LIBSSH2
217   "sftp",
218 #endif
219 #if !defined(CURL_DISABLE_SMB) && defined(USE_NTLM) && \
220    (CURL_SIZEOF_CURL_OFF_T > 4) && \
221    (!defined(USE_WINDOWS_SSPI) || defined(USE_WIN32_CRYPTO))
222   "smb",
223 #  ifdef USE_SSL
224   "smbs",
225 #  endif
226 #endif
227 #ifndef CURL_DISABLE_SMTP
228   "smtp",
229 #endif
230 #if defined(USE_SSL) && !defined(CURL_DISABLE_SMTP)
231   "smtps",
232 #endif
233 #ifndef CURL_DISABLE_TELNET
234   "telnet",
235 #endif
236 #ifndef CURL_DISABLE_TFTP
237   "tftp",
238 #endif
239
240   NULL
241 };
242
243 static curl_version_info_data version_info = {
244   CURLVERSION_NOW,
245   LIBCURL_VERSION,
246   LIBCURL_VERSION_NUM,
247   OS, /* as found by configure or set by hand at build-time */
248   0 /* features is 0 by default */
249 #ifdef ENABLE_IPV6
250   | CURL_VERSION_IPV6
251 #endif
252 #ifdef USE_SSL
253   | CURL_VERSION_SSL
254 #endif
255 #ifdef USE_NTLM
256   | CURL_VERSION_NTLM
257 #endif
258 #if !defined(CURL_DISABLE_HTTP) && defined(USE_NTLM) && \
259   defined(NTLM_WB_ENABLED)
260   | CURL_VERSION_NTLM_WB
261 #endif
262 #ifdef USE_SPNEGO
263   | CURL_VERSION_SPNEGO
264 #endif
265 #ifdef USE_KERBEROS5
266   | CURL_VERSION_KERBEROS5
267 #endif
268 #ifdef HAVE_GSSAPI
269   | CURL_VERSION_GSSAPI
270 #endif
271 #ifdef USE_WINDOWS_SSPI
272   | CURL_VERSION_SSPI
273 #endif
274 #ifdef HAVE_LIBZ
275   | CURL_VERSION_LIBZ
276 #endif
277 #ifdef DEBUGBUILD
278   | CURL_VERSION_DEBUG
279 #endif
280 #ifdef CURLDEBUG
281   | CURL_VERSION_CURLDEBUG
282 #endif
283 #ifdef CURLRES_ASYNCH
284   | CURL_VERSION_ASYNCHDNS
285 #endif
286 #if (CURL_SIZEOF_CURL_OFF_T > 4) && \
287     ( (SIZEOF_OFF_T > 4) || defined(USE_WIN32_LARGE_FILES) )
288   | CURL_VERSION_LARGEFILE
289 #endif
290 #if defined(CURL_DOES_CONVERSIONS)
291   | CURL_VERSION_CONV
292 #endif
293 #if defined(USE_TLS_SRP)
294   | CURL_VERSION_TLSAUTH_SRP
295 #endif
296 #if defined(USE_NGHTTP2)
297   | CURL_VERSION_HTTP2
298 #endif
299 #if defined(USE_UNIX_SOCKETS)
300   | CURL_VERSION_UNIX_SOCKETS
301 #endif
302   ,
303   NULL, /* ssl_version */
304   0,    /* ssl_version_num, this is kept at zero */
305   NULL, /* zlib_version */
306   protocols,
307   NULL, /* c-ares version */
308   0,    /* c-ares version numerical */
309   NULL, /* libidn version */
310   0,    /* iconv version */
311   NULL, /* ssh lib version */
312 };
313
314 curl_version_info_data *curl_version_info(CURLversion stamp)
315 {
316 #ifdef USE_LIBSSH2
317   static char ssh_buffer[80];
318 #endif
319
320 #ifdef USE_SSL
321   static char ssl_buffer[80];
322   Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
323   version_info.ssl_version = ssl_buffer;
324 #endif
325
326 #ifdef HAVE_LIBZ
327   version_info.libz_version = zlibVersion();
328   /* libz left NULL if non-existing */
329 #endif
330 #ifdef USE_ARES
331   {
332     int aresnum;
333     version_info.ares = ares_version(&aresnum);
334     version_info.ares_num = aresnum;
335   }
336 #endif
337 #ifdef USE_LIBIDN
338   /* This returns a version string if we use the given version or later,
339      otherwise it returns NULL */
340   version_info.libidn = stringprep_check_version(LIBIDN_REQUIRED_VERSION);
341   if(version_info.libidn)
342     version_info.features |= CURL_VERSION_IDN;
343 #elif defined(USE_WIN32_IDN)
344   version_info.features |= CURL_VERSION_IDN;
345 #endif
346
347 #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
348 #ifdef _LIBICONV_VERSION
349   version_info.iconv_ver_num = _LIBICONV_VERSION;
350 #else
351   /* version unknown */
352   version_info.iconv_ver_num = -1;
353 #endif /* _LIBICONV_VERSION */
354 #endif
355
356 #ifdef USE_LIBSSH2
357   snprintf(ssh_buffer, sizeof(ssh_buffer), "libssh2/%s", LIBSSH2_VERSION);
358   version_info.libssh_version = ssh_buffer;
359 #endif
360
361   (void)stamp; /* avoid compiler warnings, we don't use this */
362
363   return &version_info;
364 }