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