1
0

version.c 6.0 KB

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