version.c 5.7 KB

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