typecase to please the compiler gods
[platform/upstream/curl.git] / lib / version.c
1 /***************************************************************************
2  *                                  _   _ ____  _     
3  *  Project                     ___| | | |  _ \| |    
4  *                             / __| | | | |_) | |    
5  *                            | (__| |_| |  _ <| |___ 
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2003, 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
32 #ifdef USE_SSLEAY
33 static void getssl_version(char *ptr, long *num)
34 {
35
36 #if (SSLEAY_VERSION_NUMBER >= 0x905000)
37   {
38     char sub[2];
39     unsigned long ssleay_value;
40     sub[1]='\0';
41     ssleay_value=SSLeay();
42     *num = ssleay_value;
43     if(ssleay_value < 0x906000) {
44       ssleay_value=SSLEAY_VERSION_NUMBER;
45       sub[0]='\0';
46     }
47     else {
48       if(ssleay_value&0xff0) {
49         sub[0]=(char)((ssleay_value>>4)&0xff) + 'a' -1;
50       }
51       else
52         sub[0]='\0';
53     }
54
55     sprintf(ptr, " OpenSSL/%lx.%lx.%lx%s",
56             (ssleay_value>>28)&0xf,
57             (ssleay_value>>20)&0xff,
58             (ssleay_value>>12)&0xff,
59             sub);
60   }
61
62 #else
63   *num = SSLEAY_VERSION_NUMBER;
64 #if (SSLEAY_VERSION_NUMBER >= 0x900000)
65   sprintf(ptr, " OpenSSL/%lx.%lx.%lx",
66           (SSLEAY_VERSION_NUMBER>>28)&0xff,
67           (SSLEAY_VERSION_NUMBER>>20)&0xff,
68           (SSLEAY_VERSION_NUMBER>>12)&0xf);
69 #else
70   {
71     char sub[2];
72     sub[1]='\0';
73     if(SSLEAY_VERSION_NUMBER&0x0f) {
74       sub[0]=(SSLEAY_VERSION_NUMBER&0x0f) + 'a' -1;
75     }
76     else
77       sub[0]='\0';
78
79     sprintf(ptr, " SSL/%x.%x.%x%s",
80             (SSLEAY_VERSION_NUMBER>>12)&0xff,
81             (SSLEAY_VERSION_NUMBER>>8)&0xf,
82             (SSLEAY_VERSION_NUMBER>>4)&0xf, sub);
83   }
84 #endif
85 #endif
86 }
87
88 #endif
89
90 char *curl_version(void)
91 {
92   static char version[200];
93   char *ptr;
94   long num;
95   strcpy(version, LIBCURL_NAME "/" LIBCURL_VERSION );
96   ptr=strchr(version, '\0');
97
98 #ifdef USE_SSLEAY
99   getssl_version(ptr, &num);
100   ptr=strchr(version, '\0');
101 #else
102   (void)num; /* no compiler warning please */
103 #endif
104
105 #ifdef KRB4
106   sprintf(ptr, " krb4");
107   ptr += strlen(ptr);
108 #endif
109 #ifdef ENABLE_IPV6
110   sprintf(ptr, " ipv6");
111   ptr += strlen(ptr);
112 #endif
113 #ifdef HAVE_LIBZ
114   sprintf(ptr, " zlib/%s", zlibVersion());
115   ptr += strlen(ptr);
116 #endif
117 #ifdef GSSAPI
118   sprintf(ptr, " GSS");
119   ptr += strlen(ptr);
120 #endif
121
122   return version;
123 }
124
125 /* data for curl_version_info */
126
127 static const char *protocols[] = {
128 #ifndef CURL_DISABLE_FTP
129   "ftp",
130 #endif
131 #ifndef CURL_DISABLE_GOPHER
132   "gopher",
133 #endif
134 #ifndef CURL_DISABLE_TELNET
135   "telnet",
136 #endif
137 #ifndef CURL_DISABLE_DICT
138   "dict",
139 #endif
140 #ifndef CURL_DISABLE_LDAP
141   "ldap",
142 #endif
143 #ifndef CURL_DISABLE_HTTP
144   "http",
145 #endif
146 #ifndef CURL_DISABLE_FILE
147   "file",
148 #endif
149
150 #ifdef USE_SSLEAY
151 #ifndef CURL_DISABLE_HTTP
152   "https",
153 #endif
154 #ifndef CURL_DISABLE_FTP
155   "ftps",
156 #endif
157 #endif
158   NULL
159 };
160
161 static curl_version_info_data version_info = {
162   CURLVERSION_FIRST,
163   LIBCURL_VERSION,
164   LIBCURL_VERSION_NUM,
165   OS, /* as found by configure or set by hand at build-time */
166   0 /* features is 0 by default */
167 #ifdef ENABLE_IPV6
168   | CURL_VERSION_IPV6
169 #endif
170 #ifdef KRB4
171   | CURL_VERSION_KERBEROS4
172 #endif
173 #ifdef USE_SSLEAY
174   | CURL_VERSION_SSL
175   | CURL_VERSION_NTLM /* since this requires OpenSSL */
176 #endif
177 #ifdef HAVE_LIBZ
178   | CURL_VERSION_LIBZ
179 #endif
180 #ifdef GSSAPI
181   | CURL_VERSION_GSSNEGOTIATE
182 #endif
183 #ifdef CURLDEBUG
184   | CURL_VERSION_DEBUG
185 #endif
186 #ifdef USE_ARES
187   | CURL_VERSION_ASYNCHDNS
188 #endif
189   ,
190   NULL, /* ssl_version */
191   0,    /* ssl_version_num */
192   NULL, /* zlib_version */
193   protocols
194 };
195
196 curl_version_info_data *curl_version_info(CURLversion stamp)
197 {
198 #ifdef USE_SSLEAY
199   static char ssl_buffer[80];
200   long num;
201   getssl_version(ssl_buffer, &num);
202
203   version_info.ssl_version = ssl_buffer;
204   version_info.ssl_version_num = num;
205   /* SSL stuff is left zero if undefined */
206 #endif
207
208 #ifdef HAVE_LIBZ
209   version_info.libz_version = zlibVersion();
210   /* libz left NULL if non-existing */
211 #endif
212   (void)stamp; /* avoid compiler warnings, we don't use this */
213
214   return &version_info;
215 }