Remove leading space in curl_version_info ss_version field.
[platform/upstream/curl.git] / lib / version.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2006, 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  * $Id$
22  ***************************************************************************/
23
24 #include "setup.h"
25
26 #include <string.h>
27 #include <stdio.h>
28
29 #include <curl/curl.h>
30 #include "urldata.h"
31 #include "sslgen.h"
32
33 #define _MPRINTF_REPLACE /* use the internal *printf() functions */
34 #include <curl/mprintf.h>
35
36 #ifdef USE_ARES
37 #include <ares_version.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_LIBSSH2
49 #include <libssh2.h>
50 #endif
51
52
53 char *curl_version(void)
54 {
55   static char version[200];
56   char *ptr=version;
57   size_t len;
58   size_t left = sizeof(version);
59   strcpy(ptr, LIBCURL_NAME "/" LIBCURL_VERSION );
60   len = strlen(ptr);
61   left -= len;
62   ptr += len;
63
64   if (left > 1) {
65     len = Curl_ssl_version(ptr + 1, left - 1);
66
67     if (len > 0) {
68       *ptr = ' ';
69       left -= ++len;
70       ptr += len;
71     }
72   }
73
74 #ifdef HAVE_LIBZ
75   len = snprintf(ptr, left, " zlib/%s", zlibVersion());
76   left -= len;
77   ptr += len;
78 #endif
79 #ifdef USE_ARES
80   /* this function is only present in c-ares, not in the original ares */
81   len = snprintf(ptr, left, " c-ares/%s", ares_version(NULL));
82   left -= len;
83   ptr += len;
84 #endif
85 #ifdef USE_LIBIDN
86   if(stringprep_check_version(LIBIDN_REQUIRED_VERSION)) {
87     len = snprintf(ptr, left, " libidn/%s", stringprep_check_version(NULL));
88     left -= len;
89     ptr += len;
90   }
91 #endif
92 #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
93 #ifdef _LIBICONV_VERSION
94   len = snprintf(ptr, left, " iconv/%d.%d",
95                  _LIBICONV_VERSION >> 8, _LIBICONV_VERSION & 255);
96 #else
97   /* version unknown */
98   len = snprintf(ptr, left, " iconv");
99 #endif /* _LIBICONV_VERSION */
100   left -= len;
101   ptr += len;
102 #endif
103 #ifdef USE_LIBSSH2
104   len = snprintf(ptr, left, " libssh2/%s", LIBSSH2_VERSION);
105   left -= len;
106   ptr += len;
107 #endif
108
109   return version;
110 }
111
112 /* data for curl_version_info */
113
114 static const char * const protocols[] = {
115 #ifndef CURL_DISABLE_TFTP
116   "tftp",
117 #endif
118 #ifndef CURL_DISABLE_FTP
119   "ftp",
120 #endif
121 #ifndef CURL_DISABLE_TELNET
122   "telnet",
123 #endif
124 #ifndef CURL_DISABLE_DICT
125   "dict",
126 #endif
127 #ifndef CURL_DISABLE_LDAP
128   "ldap",
129 #ifdef HAVE_LDAP_SSL
130   "ldaps",
131 #endif
132 #endif
133 #ifndef CURL_DISABLE_HTTP
134   "http",
135 #endif
136 #ifndef CURL_DISABLE_FILE
137   "file",
138 #endif
139
140 #ifdef USE_SSL
141 #ifndef CURL_DISABLE_HTTP
142   "https",
143 #endif
144 #ifndef CURL_DISABLE_FTP
145   "ftps",
146 #endif
147 #endif
148
149 #ifdef USE_LIBSSH2
150   "scp",
151   "sftp",
152 #endif
153
154   NULL
155 };
156
157 static curl_version_info_data version_info = {
158   CURLVERSION_NOW,
159   LIBCURL_VERSION,
160   LIBCURL_VERSION_NUM,
161   OS, /* as found by configure or set by hand at build-time */
162   0 /* features is 0 by default */
163 #ifdef ENABLE_IPV6
164   | CURL_VERSION_IPV6
165 #endif
166 #ifdef HAVE_KRB4
167   | CURL_VERSION_KERBEROS4
168 #endif
169 #ifdef USE_SSL
170   | CURL_VERSION_SSL
171 #endif
172 #ifdef USE_NTLM
173   | CURL_VERSION_NTLM
174 #endif
175 #ifdef USE_WINDOWS_SSPI
176   | CURL_VERSION_SSPI
177 #endif
178 #ifdef HAVE_LIBZ
179   | CURL_VERSION_LIBZ
180 #endif
181 #ifdef HAVE_GSSAPI
182   | CURL_VERSION_GSSNEGOTIATE
183 #endif
184 #ifdef CURLDEBUG
185   | CURL_VERSION_DEBUG
186 #endif
187 #ifdef USE_ARES
188   | CURL_VERSION_ASYNCHDNS
189 #endif
190 #ifdef HAVE_SPNEGO
191   | CURL_VERSION_SPNEGO
192 #endif
193 #if defined(ENABLE_64BIT) && (SIZEOF_CURL_OFF_T > 4)
194   | CURL_VERSION_LARGEFILE
195 #endif
196 #if defined(CURL_DOES_CONVERSIONS)
197   | CURL_VERSION_CONV
198 #endif
199   ,
200   NULL, /* ssl_version */
201   0,    /* ssl_version_num, this is kept at zero */
202   NULL, /* zlib_version */
203   protocols,
204   NULL, /* c-ares version */
205   0,    /* c-ares version numerical */
206   NULL, /* libidn version */
207   0,    /* iconv version */
208   NULL, /* ssh lib version */
209 };
210
211 curl_version_info_data *curl_version_info(CURLversion stamp)
212 {
213 #ifdef USE_LIBSSH2
214   static char ssh_buffer[80];
215 #endif
216
217 #ifdef USE_SSL
218   static char ssl_buffer[80];
219   Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
220   version_info.ssl_version = ssl_buffer;
221 #endif
222
223 #ifdef HAVE_LIBZ
224   version_info.libz_version = zlibVersion();
225   /* libz left NULL if non-existing */
226 #endif
227 #ifdef USE_ARES
228   {
229     int aresnum;
230     version_info.ares = ares_version(&aresnum);
231     version_info.ares_num = aresnum;
232   }
233 #endif
234 #ifdef USE_LIBIDN
235   /* This returns a version string if we use the given version or later,
236      otherwise it returns NULL */
237   version_info.libidn = stringprep_check_version(LIBIDN_REQUIRED_VERSION);
238   if(version_info.libidn)
239     version_info.features |= CURL_VERSION_IDN;
240 #endif
241
242 #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
243 #ifdef _LIBICONV_VERSION
244   version_info.iconv_ver_num = _LIBICONV_VERSION;
245 #else
246   /* version unknown */
247   version_info.iconv_ver_num = -1;
248 #endif /* _LIBICONV_VERSION */
249 #endif
250
251 #ifdef USE_LIBSSH2
252   snprintf(ssh_buffer, sizeof(ssh_buffer), "libssh2/%s", LIBSSH2_VERSION);
253   version_info.libssh_version = ssh_buffer;
254 #endif
255
256   (void)stamp; /* avoid compiler warnings, we don't use this */
257
258   return &version_info;
259 }