2
0

version.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2013, 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. #ifndef CURL_DISABLE_SMTP
  199. "smtp",
  200. #endif
  201. #if defined(USE_SSL) && !defined(CURL_DISABLE_SMTP)
  202. "smtps",
  203. #endif
  204. #ifndef CURL_DISABLE_TELNET
  205. "telnet",
  206. #endif
  207. #ifndef CURL_DISABLE_TFTP
  208. "tftp",
  209. #endif
  210. NULL
  211. };
  212. static curl_version_info_data version_info = {
  213. CURLVERSION_NOW,
  214. LIBCURL_VERSION,
  215. LIBCURL_VERSION_NUM,
  216. OS, /* as found by configure or set by hand at build-time */
  217. 0 /* features is 0 by default */
  218. #ifdef ENABLE_IPV6
  219. | CURL_VERSION_IPV6
  220. #endif
  221. #ifdef USE_SSL
  222. | CURL_VERSION_SSL
  223. #endif
  224. #ifdef USE_NTLM
  225. | CURL_VERSION_NTLM
  226. #endif
  227. #if defined(USE_NTLM) && defined(NTLM_WB_ENABLED)
  228. | CURL_VERSION_NTLM_WB
  229. #endif
  230. #ifdef USE_SPNEGO
  231. | CURL_VERSION_SPNEGO
  232. #endif
  233. #ifdef HAVE_GSSAPI
  234. | CURL_VERSION_GSSAPI
  235. #endif
  236. #ifdef USE_WINDOWS_SSPI
  237. | CURL_VERSION_SSPI
  238. #endif
  239. #ifdef HAVE_LIBZ
  240. | CURL_VERSION_LIBZ
  241. #endif
  242. #ifdef DEBUGBUILD
  243. | CURL_VERSION_DEBUG
  244. #endif
  245. #ifdef CURLDEBUG
  246. | CURL_VERSION_CURLDEBUG
  247. #endif
  248. #ifdef CURLRES_ASYNCH
  249. | CURL_VERSION_ASYNCHDNS
  250. #endif
  251. #if (CURL_SIZEOF_CURL_OFF_T > 4) && \
  252. ( (SIZEOF_OFF_T > 4) || defined(USE_WIN32_LARGE_FILES) )
  253. | CURL_VERSION_LARGEFILE
  254. #endif
  255. #if defined(CURL_DOES_CONVERSIONS)
  256. | CURL_VERSION_CONV
  257. #endif
  258. #if defined(USE_TLS_SRP)
  259. | CURL_VERSION_TLSAUTH_SRP
  260. #endif
  261. #if defined(USE_NGHTTP2)
  262. | CURL_VERSION_HTTP2
  263. #endif
  264. ,
  265. NULL, /* ssl_version */
  266. 0, /* ssl_version_num, this is kept at zero */
  267. NULL, /* zlib_version */
  268. protocols,
  269. NULL, /* c-ares version */
  270. 0, /* c-ares version numerical */
  271. NULL, /* libidn version */
  272. 0, /* iconv version */
  273. NULL, /* ssh lib version */
  274. };
  275. curl_version_info_data *curl_version_info(CURLversion stamp)
  276. {
  277. #ifdef USE_LIBSSH2
  278. static char ssh_buffer[80];
  279. #endif
  280. #ifdef USE_SSL
  281. static char ssl_buffer[80];
  282. Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
  283. version_info.ssl_version = ssl_buffer;
  284. #endif
  285. #ifdef HAVE_LIBZ
  286. version_info.libz_version = zlibVersion();
  287. /* libz left NULL if non-existing */
  288. #endif
  289. #ifdef USE_ARES
  290. {
  291. int aresnum;
  292. version_info.ares = ares_version(&aresnum);
  293. version_info.ares_num = aresnum;
  294. }
  295. #endif
  296. #ifdef USE_LIBIDN
  297. /* This returns a version string if we use the given version or later,
  298. otherwise it returns NULL */
  299. version_info.libidn = stringprep_check_version(LIBIDN_REQUIRED_VERSION);
  300. if(version_info.libidn)
  301. version_info.features |= CURL_VERSION_IDN;
  302. #elif defined(USE_WIN32_IDN)
  303. version_info.features |= CURL_VERSION_IDN;
  304. #endif
  305. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  306. #ifdef _LIBICONV_VERSION
  307. version_info.iconv_ver_num = _LIBICONV_VERSION;
  308. #else
  309. /* version unknown */
  310. version_info.iconv_ver_num = -1;
  311. #endif /* _LIBICONV_VERSION */
  312. #endif
  313. #ifdef USE_LIBSSH2
  314. snprintf(ssh_buffer, sizeof(ssh_buffer), "libssh2/%s", LIBSSH2_VERSION);
  315. version_info.libssh_version = ssh_buffer;
  316. #endif
  317. (void)stamp; /* avoid compiler warnings, we don't use this */
  318. return &version_info;
  319. }