version.c 7.2 KB

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