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