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