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=0;
  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. (void)ptr;
  106. return version;
  107. }
  108. /* data for curl_version_info */
  109. static const char *protocols[] = {
  110. #ifndef CURL_DISABLE_FTP
  111. "ftp",
  112. #endif
  113. #ifndef CURL_DISABLE_GOPHER
  114. "gopher",
  115. #endif
  116. #ifndef CURL_DISABLE_TELNET
  117. "telnet",
  118. #endif
  119. #ifndef CURL_DISABLE_DICT
  120. "dict",
  121. #endif
  122. #ifndef CURL_DISABLE_LDAP
  123. "ldap",
  124. #endif
  125. #ifndef CURL_DISABLE_HTTP
  126. "http",
  127. #endif
  128. #ifndef CURL_DISABLE_FILE
  129. "file",
  130. #endif
  131. #ifdef USE_SSLEAY
  132. #ifndef CURL_DISABLE_HTTP
  133. "https",
  134. #endif
  135. #ifndef CURL_DISABLE_FTP
  136. "ftps",
  137. #endif
  138. #endif
  139. NULL
  140. };
  141. static curl_version_info_data version_info = {
  142. CURLVERSION_FIRST,
  143. LIBCURL_VERSION,
  144. LIBCURL_VERSION_NUM,
  145. OS, /* as found by configure or set by hand at build-time */
  146. 0 /* features is 0 by default */
  147. #ifdef ENABLE_IPV6
  148. | CURL_VERSION_IPV6
  149. #endif
  150. #ifdef KRB4
  151. | CURL_VERSION_KERBEROS4
  152. #endif
  153. #ifdef USE_SSLEAY
  154. | CURL_VERSION_SSL
  155. #endif
  156. #ifdef HAVE_LIBZ
  157. | CURL_VERSION_LIBZ
  158. #endif
  159. ,
  160. NULL, /* ssl_version */
  161. 0, /* ssl_version_num */
  162. NULL, /* zlib_version */
  163. protocols
  164. };
  165. curl_version_info_data *curl_version_info(CURLversion stamp)
  166. {
  167. #ifdef USE_SSLEAY
  168. static char ssl_buffer[80];
  169. long num;
  170. getssl_version(ssl_buffer, &num);
  171. version_info.ssl_version = ssl_buffer;
  172. version_info.ssl_version_num = num;
  173. /* SSL stuff is left zero if undefined */
  174. #endif
  175. #ifdef HAVE_LIBZ
  176. version_info.libz_version = zlibVersion();
  177. /* libz left NULL if non-existing */
  178. #endif
  179. (void)stamp; /* avoid compiler warnings, we don't use this */
  180. return &version_info;
  181. }
  182. /*
  183. * local variables:
  184. * eval: (load-file "../curl-mode.el")
  185. * end:
  186. * vim600: fdm=marker
  187. * vim: et sw=2 ts=2 sts=2 tw=78
  188. */