version.c 8.2 KB

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