~ubuntu-branches/ubuntu/jaunty/cmake/jaunty-security

« back to all changes in this revision

Viewing changes to Source/CTest/Curl/version.c

  • Committer: Bazaar Package Importer
  • Author(s): A. Maitland Bottoms
  • Date: 2006-06-18 16:34:11 UTC
  • mfrom: (1.4.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060618163411-pi234s3v6jwlcmof
Tags: 2.4.2-1
* New upstream release (Closes: #338324)
* Put cmake .vim files into /usr/share/vim/addons/plugin/
  where they can be used. (Closes: #366663)
* Install cmake-mode.el so it can be used. (Closes: #366664)
* Ensure cmake FindKDE locates KDE libraries on Debian
  based distributions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *                                  _   _ ____  _
 
3
 *  Project                     ___| | | |  _ \| |
 
4
 *                             / __| | | | |_) | |
 
5
 *                            | (__| |_| |  _ <| |___
 
6
 *                             \___|\___/|_| \_\_____|
 
7
 *
 
8
 * Copyright (C) 1998 - 2004, 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: version.c,v 1.7 2004/10/13 14:45:30 andy Exp $
 
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
#define _MPRINTF_REPLACE /* use the internal *printf() functions */
 
33
#include <curl/mprintf.h>
 
34
 
 
35
#ifdef USE_ARES
 
36
#include <ares_version.h>
 
37
#endif
 
38
 
 
39
#ifdef USE_LIBIDN
 
40
#include <stringprep.h>
 
41
#endif
 
42
 
 
43
#ifdef USE_SSLEAY
 
44
static int getssl_version(char *ptr, size_t left, long *num)
 
45
{
 
46
 
 
47
#if (SSLEAY_VERSION_NUMBER >= 0x905000)
 
48
  {
 
49
    char sub[2];
 
50
    unsigned long ssleay_value;
 
51
    sub[1]='\0';
 
52
    ssleay_value=SSLeay();
 
53
    *num = (long)ssleay_value;
 
54
    if(ssleay_value < 0x906000) {
 
55
      ssleay_value=SSLEAY_VERSION_NUMBER;
 
56
      sub[0]='\0';
 
57
    }
 
58
    else {
 
59
      if(ssleay_value&0xff0) {
 
60
        sub[0]=(char)((ssleay_value>>4)&0xff) + 'a' -1;
 
61
      }
 
62
      else
 
63
        sub[0]='\0';
 
64
    }
 
65
 
 
66
    return snprintf(ptr, left, " OpenSSL/%lx.%lx.%lx%s",
 
67
                    (ssleay_value>>28)&0xf,
 
68
                    (ssleay_value>>20)&0xff,
 
69
                    (ssleay_value>>12)&0xff,
 
70
                    sub);
 
71
  }
 
72
 
 
73
#else
 
74
  *num = SSLEAY_VERSION_NUMBER;
 
75
#if (SSLEAY_VERSION_NUMBER >= 0x900000)
 
76
  return snprintf(ptr, left, " OpenSSL/%lx.%lx.%lx",
 
77
                  (SSLEAY_VERSION_NUMBER>>28)&0xff,
 
78
                  (SSLEAY_VERSION_NUMBER>>20)&0xff,
 
79
                  (SSLEAY_VERSION_NUMBER>>12)&0xf);
 
80
#else
 
81
  {
 
82
    char sub[2];
 
83
    sub[1]='\0';
 
84
    if(SSLEAY_VERSION_NUMBER&0x0f) {
 
85
      sub[0]=(SSLEAY_VERSION_NUMBER&0x0f) + 'a' -1;
 
86
    }
 
87
    else
 
88
      sub[0]='\0';
 
89
 
 
90
    return snprintf(ptr, left, " SSL/%x.%x.%x%s",
 
91
                    (SSLEAY_VERSION_NUMBER>>12)&0xff,
 
92
                    (SSLEAY_VERSION_NUMBER>>8)&0xf,
 
93
                    (SSLEAY_VERSION_NUMBER>>4)&0xf, sub);
 
94
  }
 
95
#endif
 
96
#endif
 
97
}
 
98
 
 
99
#endif
 
100
 
 
101
char *curl_version(void)
 
102
{
 
103
  static char version[200];
 
104
  char *ptr=version;
 
105
  /* to prevent compier warnings, we only declare len if we have code
 
106
     that uses it */
 
107
#if defined(USE_SSLEAY) || defined(HAVE_LIBZ) || defined(USE_ARES) || \
 
108
  defined(USE_LIBIDN)
 
109
  int len;
 
110
#endif
 
111
  size_t left = sizeof(version);
 
112
  strcpy(ptr, LIBCURL_NAME "/" LIBCURL_VERSION );
 
113
  ptr=strchr(ptr, '\0');
 
114
  left -= strlen(ptr);
 
115
  (void)left;
 
116
 
 
117
#ifdef USE_SSLEAY
 
118
  {
 
119
    long num;
 
120
    len = getssl_version(ptr, left, &num);
 
121
    left -= len;
 
122
    ptr += len;
 
123
  }
 
124
#endif
 
125
 
 
126
#ifdef HAVE_LIBZ
 
127
  len = snprintf(ptr, left, " zlib/%s", zlibVersion());
 
128
  left -= len;
 
129
  ptr += len;
 
130
#endif
 
131
#ifdef USE_ARES
 
132
  /* this function is only present in c-ares, not in the original ares */
 
133
  len = snprintf(ptr, left, " c-ares/%s", ares_version(NULL));
 
134
  left -= len;
 
135
  ptr += len;
 
136
#endif
 
137
#ifdef USE_LIBIDN
 
138
  if(stringprep_check_version(LIBIDN_REQUIRED_VERSION)) {
 
139
    len = snprintf(ptr, left, " libidn/%s", stringprep_check_version(NULL));
 
140
    left -= len;
 
141
    ptr += len;
 
142
  }
 
143
#endif
 
144
 
 
145
  return version;
 
146
}
 
147
 
 
148
/* data for curl_version_info */
 
149
 
 
150
static const char *protocols[] = {
 
151
#ifndef CURL_DISABLE_FTP
 
152
  "ftp",
 
153
#endif
 
154
#ifndef CURL_DISABLE_GOPHER
 
155
  "gopher",
 
156
#endif
 
157
#ifndef CURL_DISABLE_TELNET
 
158
  "telnet",
 
159
#endif
 
160
#ifndef CURL_DISABLE_DICT
 
161
  "dict",
 
162
#endif
 
163
#ifndef CURL_DISABLE_LDAP
 
164
  "ldap",
 
165
#endif
 
166
#ifndef CURL_DISABLE_HTTP
 
167
  "http",
 
168
#endif
 
169
#ifndef CURL_DISABLE_FILE
 
170
  "file",
 
171
#endif
 
172
 
 
173
#ifdef USE_SSLEAY
 
174
#ifndef CURL_DISABLE_HTTP
 
175
  "https",
 
176
#endif
 
177
#ifndef CURL_DISABLE_FTP
 
178
  "ftps",
 
179
#endif
 
180
#endif
 
181
  NULL
 
182
};
 
183
 
 
184
static curl_version_info_data version_info = {
 
185
  CURLVERSION_NOW,
 
186
  LIBCURL_VERSION,
 
187
  LIBCURL_VERSION_NUM,
 
188
  OS, /* as found by configure or set by hand at build-time */
 
189
  0 /* features is 0 by default */
 
190
#ifdef ENABLE_IPV6
 
191
  | CURL_VERSION_IPV6
 
192
#endif
 
193
#ifdef HAVE_KRB4
 
194
  | CURL_VERSION_KERBEROS4
 
195
#endif
 
196
#ifdef USE_SSLEAY
 
197
  | CURL_VERSION_SSL
 
198
  | CURL_VERSION_NTLM /* since this requires OpenSSL */
 
199
#endif
 
200
#ifdef HAVE_LIBZ
 
201
  | CURL_VERSION_LIBZ
 
202
#endif
 
203
#ifdef HAVE_GSSAPI
 
204
  | CURL_VERSION_GSSNEGOTIATE
 
205
#endif
 
206
#ifdef CURLDEBUG
 
207
  | CURL_VERSION_DEBUG
 
208
#endif
 
209
#ifdef USE_ARES
 
210
  | CURL_VERSION_ASYNCHDNS
 
211
#endif
 
212
#ifdef HAVE_SPNEGO
 
213
  | CURL_VERSION_SPNEGO
 
214
#endif
 
215
#if defined(ENABLE_64BIT) && (SIZEOF_CURL_OFF_T > 4)
 
216
  | CURL_VERSION_LARGEFILE
 
217
#endif
 
218
  ,
 
219
  NULL, /* ssl_version */
 
220
  0,    /* ssl_version_num */
 
221
  NULL, /* zlib_version */
 
222
  protocols,
 
223
  NULL, /* c-ares version */
 
224
  0,    /* c-ares version numerical */
 
225
  NULL, /* libidn version */
 
226
};
 
227
 
 
228
curl_version_info_data *curl_version_info(CURLversion stamp)
 
229
{
 
230
#ifdef USE_SSLEAY
 
231
  static char ssl_buffer[80];
 
232
  long num;
 
233
  getssl_version(ssl_buffer, sizeof(ssl_buffer), &num);
 
234
 
 
235
  version_info.ssl_version = ssl_buffer;
 
236
  version_info.ssl_version_num = num;
 
237
  /* SSL stuff is left zero if undefined */
 
238
#endif
 
239
 
 
240
#ifdef HAVE_LIBZ
 
241
  version_info.libz_version = zlibVersion();
 
242
  /* libz left NULL if non-existing */
 
243
#endif
 
244
#ifdef USE_ARES
 
245
  {
 
246
    int aresnum;
 
247
    version_info.ares = ares_version(&aresnum);
 
248
    version_info.ares_num = aresnum;
 
249
  }
 
250
#endif
 
251
#ifdef USE_LIBIDN
 
252
  /* This returns a version string if we use the given version or later,
 
253
     otherwise it returns NULL */
 
254
  version_info.libidn = stringprep_check_version(LIBIDN_REQUIRED_VERSION);
 
255
  if(version_info.libidn)
 
256
    version_info.features |= CURL_VERSION_IDN;
 
257
#endif
 
258
  (void)stamp; /* avoid compiler warnings, we don't use this */
 
259
 
 
260
  return &version_info;
 
261
}