version.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2012, 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 "setup.h"
  23. #include <curl/curl.h>
  24. #include "urldata.h"
  25. #include "sslgen.h"
  26. #define _MPRINTF_REPLACE /* use the internal *printf() functions */
  27. #include <curl/mprintf.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_LIBRTMP
  112. {
  113. char suff[2];
  114. if(RTMP_LIB_VERSION & 0xff) {
  115. suff[0] = (RTMP_LIB_VERSION & 0xff) + 'a' - 1;
  116. suff[1] = '\0';
  117. }
  118. else
  119. suff[0] = '\0';
  120. snprintf(ptr, left, " librtmp/%d.%d%s",
  121. RTMP_LIB_VERSION >> 16, (RTMP_LIB_VERSION >> 8) & 0xff,
  122. suff);
  123. /*
  124. If another lib version is added below this one, this code would
  125. also have to do:
  126. len = what snprintf() returned
  127. left -= len;
  128. ptr += len;
  129. */
  130. }
  131. #endif
  132. return version;
  133. }
  134. /* data for curl_version_info
  135. Keep the list sorted alphabetically. It is also written so that each
  136. protocol line has its own #if line to make things easier on the eye.
  137. */
  138. static const char * const protocols[] = {
  139. #ifndef CURL_DISABLE_DICT
  140. "dict",
  141. #endif
  142. #ifndef CURL_DISABLE_FILE
  143. "file",
  144. #endif
  145. #ifndef CURL_DISABLE_FTP
  146. "ftp",
  147. #endif
  148. #if defined(USE_SSL) && !defined(CURL_DISABLE_FTP)
  149. "ftps",
  150. #endif
  151. #ifndef CURL_DISABLE_GOPHER
  152. "gopher",
  153. #endif
  154. #ifndef CURL_DISABLE_HTTP
  155. "http",
  156. #endif
  157. #if defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)
  158. "https",
  159. #endif
  160. #ifndef CURL_DISABLE_IMAP
  161. "imap",
  162. #endif
  163. #if defined(USE_SSL) && !defined(CURL_DISABLE_IMAP)
  164. "imaps",
  165. #endif
  166. #ifndef CURL_DISABLE_LDAP
  167. "ldap",
  168. #if !defined(CURL_DISABLE_LDAPS) && \
  169. ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \
  170. (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL)))
  171. "ldaps",
  172. #endif
  173. #endif
  174. #ifndef CURL_DISABLE_POP3
  175. "pop3",
  176. #endif
  177. #if defined(USE_SSL) && !defined(CURL_DISABLE_POP3)
  178. "pop3s",
  179. #endif
  180. #ifdef USE_LIBRTMP
  181. "rtmp",
  182. #endif
  183. #ifndef CURL_DISABLE_RTSP
  184. "rtsp",
  185. #endif
  186. #ifdef USE_LIBSSH2
  187. "scp",
  188. #endif
  189. #ifdef USE_LIBSSH2
  190. "sftp",
  191. #endif
  192. #ifndef CURL_DISABLE_SMTP
  193. "smtp",
  194. #endif
  195. #if defined(USE_SSL) && !defined(CURL_DISABLE_SMTP)
  196. "smtps",
  197. #endif
  198. #ifndef CURL_DISABLE_TELNET
  199. "telnet",
  200. #endif
  201. #ifndef CURL_DISABLE_TFTP
  202. "tftp",
  203. #endif
  204. NULL
  205. };
  206. static curl_version_info_data version_info = {
  207. CURLVERSION_NOW,
  208. LIBCURL_VERSION,
  209. LIBCURL_VERSION_NUM,
  210. OS, /* as found by configure or set by hand at build-time */
  211. 0 /* features is 0 by default */
  212. #ifdef ENABLE_IPV6
  213. | CURL_VERSION_IPV6
  214. #endif
  215. #ifdef HAVE_KRB4
  216. | CURL_VERSION_KERBEROS4
  217. #endif
  218. #ifdef USE_SSL
  219. | CURL_VERSION_SSL
  220. #endif
  221. #ifdef USE_NTLM
  222. | CURL_VERSION_NTLM
  223. #endif
  224. #if defined(USE_NTLM) && defined(NTLM_WB_ENABLED)
  225. | CURL_VERSION_NTLM_WB
  226. #endif
  227. #ifdef USE_WINDOWS_SSPI
  228. | CURL_VERSION_SSPI
  229. #endif
  230. #ifdef HAVE_LIBZ
  231. | CURL_VERSION_LIBZ
  232. #endif
  233. #ifdef USE_HTTP_NEGOTIATE
  234. | CURL_VERSION_GSSNEGOTIATE
  235. #endif
  236. #ifdef DEBUGBUILD
  237. | CURL_VERSION_DEBUG
  238. #endif
  239. #ifdef CURLDEBUG
  240. | CURL_VERSION_CURLDEBUG
  241. #endif
  242. #ifdef CURLRES_ASYNCH
  243. | CURL_VERSION_ASYNCHDNS
  244. #endif
  245. #ifdef HAVE_SPNEGO
  246. | CURL_VERSION_SPNEGO
  247. #endif
  248. #if (CURL_SIZEOF_CURL_OFF_T > 4) && \
  249. ( (SIZEOF_OFF_T > 4) || defined(USE_WIN32_LARGE_FILES) )
  250. | CURL_VERSION_LARGEFILE
  251. #endif
  252. #if defined(CURL_DOES_CONVERSIONS)
  253. | CURL_VERSION_CONV
  254. #endif
  255. #if defined(USE_TLS_SRP)
  256. | CURL_VERSION_TLSAUTH_SRP
  257. #endif
  258. ,
  259. NULL, /* ssl_version */
  260. 0, /* ssl_version_num, this is kept at zero */
  261. NULL, /* zlib_version */
  262. protocols,
  263. NULL, /* c-ares version */
  264. 0, /* c-ares version numerical */
  265. NULL, /* libidn version */
  266. 0, /* iconv version */
  267. NULL, /* ssh lib version */
  268. };
  269. curl_version_info_data *curl_version_info(CURLversion stamp)
  270. {
  271. #ifdef USE_LIBSSH2
  272. static char ssh_buffer[80];
  273. #endif
  274. #ifdef USE_SSL
  275. static char ssl_buffer[80];
  276. Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
  277. version_info.ssl_version = ssl_buffer;
  278. #endif
  279. #ifdef HAVE_LIBZ
  280. version_info.libz_version = zlibVersion();
  281. /* libz left NULL if non-existing */
  282. #endif
  283. #ifdef USE_ARES
  284. {
  285. int aresnum;
  286. version_info.ares = ares_version(&aresnum);
  287. version_info.ares_num = aresnum;
  288. }
  289. #endif
  290. #ifdef USE_LIBIDN
  291. /* This returns a version string if we use the given version or later,
  292. otherwise it returns NULL */
  293. version_info.libidn = stringprep_check_version(LIBIDN_REQUIRED_VERSION);
  294. if(version_info.libidn)
  295. version_info.features |= CURL_VERSION_IDN;
  296. #elif defined(USE_WIN32_IDN)
  297. version_info.features |= CURL_VERSION_IDN;
  298. #endif
  299. #if defined(HAVE_ICONV) && defined(CURL_DOES_CONVERSIONS)
  300. #ifdef _LIBICONV_VERSION
  301. version_info.iconv_ver_num = _LIBICONV_VERSION;
  302. #else
  303. /* version unknown */
  304. version_info.iconv_ver_num = -1;
  305. #endif /* _LIBICONV_VERSION */
  306. #endif
  307. #ifdef USE_LIBSSH2
  308. snprintf(ssh_buffer, sizeof(ssh_buffer), "libssh2/%s", LIBSSH2_VERSION);
  309. version_info.libssh_version = ssh_buffer;
  310. #endif
  311. (void)stamp; /* avoid compiler warnings, we don't use this */
  312. return &version_info;
  313. }