version.c 5.5 KB

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