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