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