version.c 5.2 KB

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