version.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2015, 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. ***************************************************************************/
  22. #include "curl_setup.h"
  23. #include <curl/curl.h>
  24. #include "urldata.h"
  25. #include "vtls/vtls.h"
  26. #include "http2.h"
  27. #include "curl_printf.h"
  28. #ifdef USE_ARES
  29. # if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && \
  30. (defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__))
  31. # define CARES_STATICLIB
  32. # endif
  33. # include <ares.h>
  34. #endif
  35. #ifdef USE_LIBIDN
  36. #include <stringprep.h>
  37. #endif
  38. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  39. #include <iconv.h>
  40. #endif
  41. #ifdef USE_LIBRTMP
  42. #include <librtmp/rtmp.h>
  43. #endif
  44. #ifdef USE_LIBSSH2
  45. #include <libssh2.h>
  46. #endif
  47. #ifdef HAVE_LIBSSH2_VERSION
  48. /* get it run-time if possible */
  49. #define CURL_LIBSSH2_VERSION libssh2_version(0)
  50. #else
  51. /* use build-time if run-time not possible */
  52. #define CURL_LIBSSH2_VERSION LIBSSH2_VERSION
  53. #endif
  54. char *curl_version(void)
  55. {
  56. static char version[200];
  57. char *ptr = version;
  58. size_t len;
  59. size_t left = sizeof(version);
  60. strcpy(ptr, LIBCURL_NAME "/" LIBCURL_VERSION);
  61. len = strlen(ptr);
  62. left -= len;
  63. ptr += len;
  64. if(left > 1) {
  65. len = Curl_ssl_version(ptr + 1, left - 1);
  66. if(len > 0) {
  67. *ptr = ' ';
  68. left -= ++len;
  69. ptr += len;
  70. }
  71. }
  72. #ifdef HAVE_LIBZ
  73. len = snprintf(ptr, left, " zlib/%s", zlibVersion());
  74. left -= len;
  75. ptr += len;
  76. #endif
  77. #ifdef USE_ARES
  78. /* this function is only present in c-ares, not in the original ares */
  79. len = snprintf(ptr, left, " c-ares/%s", ares_version(NULL));
  80. left -= len;
  81. ptr += len;
  82. #endif
  83. #ifdef USE_LIBIDN
  84. if(stringprep_check_version(LIBIDN_REQUIRED_VERSION)) {
  85. len = snprintf(ptr, left, " libidn/%s", stringprep_check_version(NULL));
  86. left -= len;
  87. ptr += len;
  88. }
  89. #endif
  90. #ifdef USE_WIN32_IDN
  91. len = snprintf(ptr, left, " WinIDN");
  92. left -= len;
  93. ptr += len;
  94. #endif
  95. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  96. #ifdef _LIBICONV_VERSION
  97. len = snprintf(ptr, left, " iconv/%d.%d",
  98. _LIBICONV_VERSION >> 8, _LIBICONV_VERSION & 255);
  99. #else
  100. /* version unknown */
  101. len = snprintf(ptr, left, " iconv");
  102. #endif /* _LIBICONV_VERSION */
  103. left -= len;
  104. ptr += len;
  105. #endif
  106. #ifdef USE_LIBSSH2
  107. len = snprintf(ptr, left, " libssh2/%s", CURL_LIBSSH2_VERSION);
  108. left -= len;
  109. ptr += len;
  110. #endif
  111. #ifdef USE_NGHTTP2
  112. len = Curl_http2_ver(ptr, left);
  113. left -= len;
  114. ptr += len;
  115. #endif
  116. #ifdef USE_LIBRTMP
  117. {
  118. char suff[2];
  119. if(RTMP_LIB_VERSION & 0xff) {
  120. suff[0] = (RTMP_LIB_VERSION & 0xff) + 'a' - 1;
  121. suff[1] = '\0';
  122. }
  123. else
  124. suff[0] = '\0';
  125. snprintf(ptr, left, " librtmp/%d.%d%s",
  126. RTMP_LIB_VERSION >> 16, (RTMP_LIB_VERSION >> 8) & 0xff,
  127. suff);
  128. /*
  129. If another lib version is added below this one, this code would
  130. also have to do:
  131. len = what snprintf() returned
  132. left -= len;
  133. ptr += len;
  134. */
  135. }
  136. #endif
  137. return version;
  138. }
  139. /* data for curl_version_info
  140. Keep the list sorted alphabetically. It is also written so that each
  141. protocol line has its own #if line to make things easier on the eye.
  142. */
  143. static const char * const protocols[] = {
  144. #ifndef CURL_DISABLE_DICT
  145. "dict",
  146. #endif
  147. #ifndef CURL_DISABLE_FILE
  148. "file",
  149. #endif
  150. #ifndef CURL_DISABLE_FTP
  151. "ftp",
  152. #endif
  153. #if defined(USE_SSL) && !defined(CURL_DISABLE_FTP)
  154. "ftps",
  155. #endif
  156. #ifndef CURL_DISABLE_GOPHER
  157. "gopher",
  158. #endif
  159. #ifndef CURL_DISABLE_HTTP
  160. "http",
  161. #endif
  162. #if defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)
  163. "https",
  164. #endif
  165. #ifndef CURL_DISABLE_IMAP
  166. "imap",
  167. #endif
  168. #if defined(USE_SSL) && !defined(CURL_DISABLE_IMAP)
  169. "imaps",
  170. #endif
  171. #ifndef CURL_DISABLE_LDAP
  172. "ldap",
  173. #if !defined(CURL_DISABLE_LDAPS) && \
  174. ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \
  175. (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL)))
  176. "ldaps",
  177. #endif
  178. #endif
  179. #ifndef CURL_DISABLE_POP3
  180. "pop3",
  181. #endif
  182. #if defined(USE_SSL) && !defined(CURL_DISABLE_POP3)
  183. "pop3s",
  184. #endif
  185. #ifdef USE_LIBRTMP
  186. "rtmp",
  187. #endif
  188. #ifndef CURL_DISABLE_RTSP
  189. "rtsp",
  190. #endif
  191. #ifdef USE_LIBSSH2
  192. "scp",
  193. #endif
  194. #ifdef USE_LIBSSH2
  195. "sftp",
  196. #endif
  197. #if !defined(CURL_DISABLE_SMB) && defined(USE_NTLM) && \
  198. (CURL_SIZEOF_CURL_OFF_T > 4) && \
  199. (!defined(USE_WINDOWS_SSPI) || defined(USE_WIN32_CRYPTO))
  200. "smb",
  201. # ifdef USE_SSL
  202. "smbs",
  203. # endif
  204. #endif
  205. #ifndef CURL_DISABLE_SMTP
  206. "smtp",
  207. #endif
  208. #if defined(USE_SSL) && !defined(CURL_DISABLE_SMTP)
  209. "smtps",
  210. #endif
  211. #ifndef CURL_DISABLE_TELNET
  212. "telnet",
  213. #endif
  214. #ifndef CURL_DISABLE_TFTP
  215. "tftp",
  216. #endif
  217. NULL
  218. };
  219. static curl_version_info_data version_info = {
  220. CURLVERSION_NOW,
  221. LIBCURL_VERSION,
  222. LIBCURL_VERSION_NUM,
  223. OS, /* as found by configure or set by hand at build-time */
  224. 0 /* features is 0 by default */
  225. #ifdef ENABLE_IPV6
  226. | CURL_VERSION_IPV6
  227. #endif
  228. #ifdef USE_SSL
  229. | CURL_VERSION_SSL
  230. #endif
  231. #ifdef USE_NTLM
  232. | CURL_VERSION_NTLM
  233. #endif
  234. #if !defined(CURL_DISABLE_HTTP) && defined(USE_NTLM) && \
  235. defined(NTLM_WB_ENABLED)
  236. | CURL_VERSION_NTLM_WB
  237. #endif
  238. #ifdef USE_SPNEGO
  239. | CURL_VERSION_SPNEGO
  240. #endif
  241. #ifdef USE_KERBEROS5
  242. | CURL_VERSION_KERBEROS5
  243. #endif
  244. #ifdef HAVE_GSSAPI
  245. | CURL_VERSION_GSSAPI
  246. #endif
  247. #ifdef USE_WINDOWS_SSPI
  248. | CURL_VERSION_SSPI
  249. #endif
  250. #ifdef HAVE_LIBZ
  251. | CURL_VERSION_LIBZ
  252. #endif
  253. #ifdef DEBUGBUILD
  254. | CURL_VERSION_DEBUG
  255. #endif
  256. #ifdef CURLDEBUG
  257. | CURL_VERSION_CURLDEBUG
  258. #endif
  259. #ifdef CURLRES_ASYNCH
  260. | CURL_VERSION_ASYNCHDNS
  261. #endif
  262. #if (CURL_SIZEOF_CURL_OFF_T > 4) && \
  263. ( (SIZEOF_OFF_T > 4) || defined(USE_WIN32_LARGE_FILES) )
  264. | CURL_VERSION_LARGEFILE
  265. #endif
  266. #if defined(CURL_DOES_CONVERSIONS)
  267. | CURL_VERSION_CONV
  268. #endif
  269. #if defined(USE_TLS_SRP)
  270. | CURL_VERSION_TLSAUTH_SRP
  271. #endif
  272. #if defined(USE_NGHTTP2)
  273. | CURL_VERSION_HTTP2
  274. #endif
  275. #if defined(USE_UNIX_SOCKETS)
  276. | CURL_VERSION_UNIX_SOCKETS
  277. #endif
  278. ,
  279. NULL, /* ssl_version */
  280. 0, /* ssl_version_num, this is kept at zero */
  281. NULL, /* zlib_version */
  282. protocols,
  283. NULL, /* c-ares version */
  284. 0, /* c-ares version numerical */
  285. NULL, /* libidn version */
  286. 0, /* iconv version */
  287. NULL, /* ssh lib version */
  288. };
  289. curl_version_info_data *curl_version_info(CURLversion stamp)
  290. {
  291. #ifdef USE_LIBSSH2
  292. static char ssh_buffer[80];
  293. #endif
  294. #ifdef USE_SSL
  295. static char ssl_buffer[80];
  296. Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
  297. version_info.ssl_version = ssl_buffer;
  298. #endif
  299. #ifdef HAVE_LIBZ
  300. version_info.libz_version = zlibVersion();
  301. /* libz left NULL if non-existing */
  302. #endif
  303. #ifdef USE_ARES
  304. {
  305. int aresnum;
  306. version_info.ares = ares_version(&aresnum);
  307. version_info.ares_num = aresnum;
  308. }
  309. #endif
  310. #ifdef USE_LIBIDN
  311. /* This returns a version string if we use the given version or later,
  312. otherwise it returns NULL */
  313. version_info.libidn = stringprep_check_version(LIBIDN_REQUIRED_VERSION);
  314. if(version_info.libidn)
  315. version_info.features |= CURL_VERSION_IDN;
  316. #elif defined(USE_WIN32_IDN)
  317. version_info.features |= CURL_VERSION_IDN;
  318. #endif
  319. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  320. #ifdef _LIBICONV_VERSION
  321. version_info.iconv_ver_num = _LIBICONV_VERSION;
  322. #else
  323. /* version unknown */
  324. version_info.iconv_ver_num = -1;
  325. #endif /* _LIBICONV_VERSION */
  326. #endif
  327. #ifdef USE_LIBSSH2
  328. snprintf(ssh_buffer, sizeof(ssh_buffer), "libssh2/%s", LIBSSH2_VERSION);
  329. version_info.libssh_version = ssh_buffer;
  330. #endif
  331. (void)stamp; /* avoid compiler warnings, we don't use this */
  332. return &version_info;
  333. }