version.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2002, Daniel Stenberg, <[email protected]>, 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. #include "setup.h"
  24. #include <string.h>
  25. #include <stdio.h>
  26. #include <curl/curl.h>
  27. #include "urldata.h"
  28. #ifdef USE_SSLEAY
  29. static void getssl_version(char *ptr, long *num)
  30. {
  31. #if (SSLEAY_VERSION_NUMBER >= 0x905000)
  32. {
  33. char sub[2];
  34. unsigned long ssleay_value;
  35. sub[1]='\0';
  36. ssleay_value=SSLeay();
  37. *num = ssleay_value;
  38. if(ssleay_value < 0x906000) {
  39. ssleay_value=SSLEAY_VERSION_NUMBER;
  40. sub[0]='\0';
  41. }
  42. else {
  43. if(ssleay_value&0xff0) {
  44. sub[0]=((ssleay_value>>4)&0xff) + 'a' -1;
  45. }
  46. else
  47. sub[0]='\0';
  48. }
  49. sprintf(ptr, " OpenSSL/%lx.%lx.%lx%s",
  50. (ssleay_value>>28)&0xf,
  51. (ssleay_value>>20)&0xff,
  52. (ssleay_value>>12)&0xff,
  53. sub);
  54. }
  55. #else
  56. *num = SSLEAY_VERSION_NUMBER;
  57. #if (SSLEAY_VERSION_NUMBER >= 0x900000)
  58. sprintf(ptr, " OpenSSL/%lx.%lx.%lx",
  59. (SSLEAY_VERSION_NUMBER>>28)&0xff,
  60. (SSLEAY_VERSION_NUMBER>>20)&0xff,
  61. (SSLEAY_VERSION_NUMBER>>12)&0xf);
  62. #else
  63. {
  64. char sub[2];
  65. sub[1]='\0';
  66. if(SSLEAY_VERSION_NUMBER&0x0f) {
  67. sub[0]=(SSLEAY_VERSION_NUMBER&0x0f) + 'a' -1;
  68. }
  69. else
  70. sub[0]='\0';
  71. sprintf(ptr, " SSL/%x.%x.%x%s",
  72. (SSLEAY_VERSION_NUMBER>>12)&0xff,
  73. (SSLEAY_VERSION_NUMBER>>8)&0xf,
  74. (SSLEAY_VERSION_NUMBER>>4)&0xf, sub);
  75. }
  76. #endif
  77. #endif
  78. }
  79. #endif
  80. char *curl_version(void)
  81. {
  82. static char version[200];
  83. char *ptr;
  84. long num;
  85. strcpy(version, LIBCURL_NAME "/" LIBCURL_VERSION );
  86. ptr=strchr(version, '\0');
  87. #ifdef USE_SSLEAY
  88. getssl_version(ptr, &num);
  89. ptr=strchr(version, '\0');
  90. #else
  91. (void)num; /* no compiler warning please */
  92. #endif
  93. #ifdef KRB4
  94. sprintf(ptr, " krb4");
  95. ptr += strlen(ptr);
  96. #endif
  97. #ifdef ENABLE_IPV6
  98. sprintf(ptr, " ipv6");
  99. ptr += strlen(ptr);
  100. #endif
  101. #ifdef HAVE_LIBZ
  102. sprintf(ptr, " zlib/%s", zlibVersion());
  103. ptr += strlen(ptr);
  104. #endif
  105. return version;
  106. }
  107. /* data for curl_version_info */
  108. static const char *protocols[] = {
  109. #ifndef CURL_DISABLE_FTP
  110. "ftp",
  111. #endif
  112. #ifndef CURL_DISABLE_GOPHER
  113. "gopher",
  114. #endif
  115. #ifndef CURL_DISABLE_TELNET
  116. "telnet",
  117. #endif
  118. #ifndef CURL_DISABLE_DICT
  119. "dict",
  120. #endif
  121. #ifndef CURL_DISABLE_LDAP
  122. "ldap",
  123. #endif
  124. #ifndef CURL_DISABLE_HTTP
  125. "http",
  126. #endif
  127. #ifndef CURL_DISABLE_FILE
  128. "file",
  129. #endif
  130. #ifdef USE_SSLEAY
  131. #ifndef CURL_DISABLE_HTTP
  132. "https",
  133. #endif
  134. #ifndef CURL_DISABLE_FTP
  135. "ftps",
  136. #endif
  137. #endif
  138. NULL
  139. };
  140. static curl_version_info_data version_info = {
  141. CURLVERSION_FIRST,
  142. LIBCURL_VERSION,
  143. LIBCURL_VERSION_NUM,
  144. OS, /* as found by configure or set by hand at build-time */
  145. 0 /* features is 0 by default */
  146. #ifdef ENABLE_IPV6
  147. | CURL_VERSION_IPV6
  148. #endif
  149. #ifdef KRB4
  150. | CURL_VERSION_KERBEROS4
  151. #endif
  152. #ifdef USE_SSLEAY
  153. | CURL_VERSION_SSL
  154. #endif
  155. #ifdef HAVE_LIBZ
  156. | CURL_VERSION_LIBZ
  157. #endif
  158. ,
  159. NULL, /* ssl_version */
  160. 0, /* ssl_version_num */
  161. NULL, /* zlib_version */
  162. protocols
  163. };
  164. curl_version_info_data *curl_version_info(CURLversion stamp)
  165. {
  166. #ifdef USE_SSLEAY
  167. static char ssl_buffer[80];
  168. long num;
  169. getssl_version(ssl_buffer, &num);
  170. version_info.ssl_version = ssl_buffer;
  171. version_info.ssl_version_num = num;
  172. /* SSL stuff is left zero if undefined */
  173. #endif
  174. #ifdef HAVE_LIBZ
  175. version_info.libz_version = zlibVersion();
  176. /* libz left NULL if non-existing */
  177. #endif
  178. (void)stamp; /* avoid compiler warnings, we don't use this */
  179. return &version_info;
  180. }
  181. /*
  182. * local variables:
  183. * eval: (load-file "../curl-mode.el")
  184. * end:
  185. * vim600: fdm=marker
  186. * vim: et sw=2 ts=2 sts=2 tw=78
  187. */