2
0

version.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2009, 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$
  22. ***************************************************************************/
  23. #include "setup.h"
  24. #include <string.h>
  25. #include <stdio.h>
  26. #include <curl/curl.h>
  27. #include "urldata.h"
  28. #include "sslgen.h"
  29. #define _MPRINTF_REPLACE /* use the internal *printf() functions */
  30. #include <curl/mprintf.h>
  31. #ifdef USE_ARES
  32. #include <ares_version.h>
  33. #endif
  34. #ifdef USE_LIBIDN
  35. #include <stringprep.h>
  36. #endif
  37. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  38. #include <iconv.h>
  39. #endif
  40. #ifdef USE_LIBSSH2
  41. #include <libssh2.h>
  42. #endif
  43. #ifdef HAVE_LIBSSH2_VERSION
  44. /* get it run-time if possible */
  45. #define CURL_LIBSSH2_VERSION libssh2_version(0)
  46. #else
  47. /* use build-time if run-time not possible */
  48. #define CURL_LIBSSH2_VERSION LIBSSH2_VERSION
  49. #endif
  50. char *curl_version(void)
  51. {
  52. static char version[200];
  53. char *ptr=version;
  54. size_t len;
  55. size_t left = sizeof(version);
  56. strcpy(ptr, LIBCURL_NAME "/" LIBCURL_VERSION );
  57. len = strlen(ptr);
  58. left -= len;
  59. ptr += len;
  60. if(left > 1) {
  61. len = Curl_ssl_version(ptr + 1, left - 1);
  62. if(len > 0) {
  63. *ptr = ' ';
  64. left -= ++len;
  65. ptr += len;
  66. }
  67. }
  68. #ifdef HAVE_LIBZ
  69. len = snprintf(ptr, left, " zlib/%s", zlibVersion());
  70. left -= len;
  71. ptr += len;
  72. #endif
  73. #ifdef USE_ARES
  74. /* this function is only present in c-ares, not in the original ares */
  75. len = snprintf(ptr, left, " c-ares/%s", ares_version(NULL));
  76. left -= len;
  77. ptr += len;
  78. #endif
  79. #ifdef USE_LIBIDN
  80. if(stringprep_check_version(LIBIDN_REQUIRED_VERSION)) {
  81. len = snprintf(ptr, left, " libidn/%s", stringprep_check_version(NULL));
  82. left -= len;
  83. ptr += len;
  84. }
  85. #endif
  86. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  87. #ifdef _LIBICONV_VERSION
  88. len = snprintf(ptr, left, " iconv/%d.%d",
  89. _LIBICONV_VERSION >> 8, _LIBICONV_VERSION & 255);
  90. #else
  91. /* version unknown */
  92. len = snprintf(ptr, left, " iconv");
  93. #endif /* _LIBICONV_VERSION */
  94. left -= len;
  95. ptr += len;
  96. #endif
  97. #ifdef USE_LIBSSH2
  98. len = snprintf(ptr, left, " libssh2/%s", CURL_LIBSSH2_VERSION);
  99. left -= len;
  100. ptr += len;
  101. #endif
  102. return version;
  103. }
  104. /* data for curl_version_info */
  105. static const char * const protocols[] = {
  106. #ifndef CURL_DISABLE_TFTP
  107. "tftp",
  108. #endif
  109. #ifndef CURL_DISABLE_FTP
  110. "ftp",
  111. #endif
  112. #ifndef CURL_DISABLE_TELNET
  113. "telnet",
  114. #endif
  115. #ifndef CURL_DISABLE_DICT
  116. "dict",
  117. #endif
  118. #ifndef CURL_DISABLE_LDAP
  119. "ldap",
  120. #ifdef HAVE_LDAP_SSL
  121. "ldaps",
  122. #endif
  123. #endif
  124. #ifndef CURL_DISABLE_HTTP
  125. "http",
  126. #endif
  127. #ifndef CURL_DISABLE_FILE
  128. "file",
  129. #endif
  130. #ifdef USE_SSL
  131. #ifndef CURL_DISABLE_HTTP
  132. "https",
  133. #endif
  134. #ifndef CURL_DISABLE_FTP
  135. "ftps",
  136. #endif
  137. #endif
  138. #ifdef USE_LIBSSH2
  139. "scp",
  140. "sftp",
  141. #endif
  142. NULL
  143. };
  144. static curl_version_info_data version_info = {
  145. CURLVERSION_NOW,
  146. LIBCURL_VERSION,
  147. LIBCURL_VERSION_NUM,
  148. OS, /* as found by configure or set by hand at build-time */
  149. 0 /* features is 0 by default */
  150. #ifdef ENABLE_IPV6
  151. | CURL_VERSION_IPV6
  152. #endif
  153. #ifdef HAVE_KRB4
  154. | CURL_VERSION_KERBEROS4
  155. #endif
  156. #ifdef USE_SSL
  157. | CURL_VERSION_SSL
  158. #endif
  159. #ifdef USE_NTLM
  160. | CURL_VERSION_NTLM
  161. #endif
  162. #ifdef USE_WINDOWS_SSPI
  163. | CURL_VERSION_SSPI
  164. #endif
  165. #ifdef HAVE_LIBZ
  166. | CURL_VERSION_LIBZ
  167. #endif
  168. #ifdef HAVE_GSSAPI
  169. | CURL_VERSION_GSSNEGOTIATE
  170. #endif
  171. #ifdef CURLDEBUG
  172. | CURL_VERSION_DEBUG
  173. #endif
  174. #ifdef USE_ARES
  175. | CURL_VERSION_ASYNCHDNS
  176. #endif
  177. #ifdef HAVE_SPNEGO
  178. | CURL_VERSION_SPNEGO
  179. #endif
  180. #if (CURL_SIZEOF_CURL_OFF_T > 4) && \
  181. ( (SIZEOF_OFF_T > 4) || defined(USE_WIN32_LARGE_FILES) )
  182. | CURL_VERSION_LARGEFILE
  183. #endif
  184. #if defined(CURL_DOES_CONVERSIONS)
  185. | CURL_VERSION_CONV
  186. #endif
  187. ,
  188. NULL, /* ssl_version */
  189. 0, /* ssl_version_num, this is kept at zero */
  190. NULL, /* zlib_version */
  191. protocols,
  192. NULL, /* c-ares version */
  193. 0, /* c-ares version numerical */
  194. NULL, /* libidn version */
  195. 0, /* iconv version */
  196. NULL, /* ssh lib version */
  197. };
  198. curl_version_info_data *curl_version_info(CURLversion stamp)
  199. {
  200. #ifdef USE_LIBSSH2
  201. static char ssh_buffer[80];
  202. #endif
  203. #ifdef USE_SSL
  204. static char ssl_buffer[80];
  205. Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
  206. version_info.ssl_version = ssl_buffer;
  207. #endif
  208. #ifdef HAVE_LIBZ
  209. version_info.libz_version = zlibVersion();
  210. /* libz left NULL if non-existing */
  211. #endif
  212. #ifdef USE_ARES
  213. {
  214. int aresnum;
  215. version_info.ares = ares_version(&aresnum);
  216. version_info.ares_num = aresnum;
  217. }
  218. #endif
  219. #ifdef USE_LIBIDN
  220. /* This returns a version string if we use the given version or later,
  221. otherwise it returns NULL */
  222. version_info.libidn = stringprep_check_version(LIBIDN_REQUIRED_VERSION);
  223. if(version_info.libidn)
  224. version_info.features |= CURL_VERSION_IDN;
  225. #endif
  226. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  227. #ifdef _LIBICONV_VERSION
  228. version_info.iconv_ver_num = _LIBICONV_VERSION;
  229. #else
  230. /* version unknown */
  231. version_info.iconv_ver_num = -1;
  232. #endif /* _LIBICONV_VERSION */
  233. #endif
  234. #ifdef USE_LIBSSH2
  235. snprintf(ssh_buffer, sizeof(ssh_buffer), "libssh2/%s", LIBSSH2_VERSION);
  236. version_info.libssh_version = ssh_buffer;
  237. #endif
  238. (void)stamp; /* avoid compiler warnings, we don't use this */
  239. return &version_info;
  240. }