version.c 7.7 KB

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