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