You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1013 lines
33KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCETICE project - Copyright 2009 by Lucio Asnaghi.
  4. JUCETICE is based around the JUCE library - "Jules' Utility Class Extensions"
  5. Copyright 2007 by Julian Storer.
  6. ------------------------------------------------------------------------------
  7. JUCE and JUCETICE can be redistributed and/or modified under the terms of
  8. the GNU General Public License, as published by the Free Software Foundation;
  9. either version 2 of the License, or (at your option) any later version.
  10. JUCE and JUCETICE are distributed in the hope that they will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with JUCE and JUCETICE; if not, visit www.gnu.org/licenses or write to
  16. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  17. Boston, MA 02111-1307 USA
  18. ==============================================================================
  19. */
  20. #if 0
  21. #if JUCE_MSVC
  22. #pragma warning (push)
  23. #pragma warning (disable: 4273)
  24. #endif
  25. namespace curlNamespace
  26. {
  27. #undef T
  28. #if JUCETICE_INCLUDE_CURL_CODE
  29. #include "../dependancies/curl/include/curl/curl.h"
  30. #include "../dependancies/curl/lib/amigaos.c"
  31. #include "../dependancies/curl/lib/base64.c"
  32. #include "../dependancies/curl/lib/connect.c"
  33. #include "../dependancies/curl/lib/content_encoding.c"
  34. #include "../dependancies/curl/lib/cookie.c"
  35. #include "../dependancies/curl/lib/curl_addrinfo.c"
  36. #include "../dependancies/curl/lib/curl_sspi.c"
  37. #include "../dependancies/curl/lib/dict.c"
  38. #include "../dependancies/curl/lib/easy.c"
  39. #include "../dependancies/curl/lib/escape.c"
  40. #include "../dependancies/curl/lib/file.c"
  41. #include "../dependancies/curl/lib/formdata.c"
  42. #include "../dependancies/curl/lib/ftp.c"
  43. #include "../dependancies/curl/lib/getenv.c"
  44. #include "../dependancies/curl/lib/getinfo.c"
  45. #include "../dependancies/curl/lib/gtls.c"
  46. #include "../dependancies/curl/lib/hash.c"
  47. #include "../dependancies/curl/lib/hostares.c"
  48. #include "../dependancies/curl/lib/hostasyn.c"
  49. #include "../dependancies/curl/lib/hostip.c"
  50. #include "../dependancies/curl/lib/hostip4.c"
  51. #include "../dependancies/curl/lib/hostip6.c"
  52. #include "../dependancies/curl/lib/hostsyn.c"
  53. #include "../dependancies/curl/lib/hostthre.c"
  54. #include "../dependancies/curl/lib/http.c"
  55. #include "../dependancies/curl/lib/http_chunks.c"
  56. #include "../dependancies/curl/lib/http_digest.c"
  57. #include "../dependancies/curl/lib/http_negotiate.c"
  58. #include "../dependancies/curl/lib/http_ntlm.c"
  59. #include "../dependancies/curl/lib/if2ip.c"
  60. #include "../dependancies/curl/lib/inet_ntop.c"
  61. #include "../dependancies/curl/lib/inet_pton.c"
  62. #include "../dependancies/curl/lib/krb4.c"
  63. #include "../dependancies/curl/lib/krb5.c"
  64. #include "../dependancies/curl/lib/ldap.c"
  65. #include "../dependancies/curl/lib/llist.c"
  66. #include "../dependancies/curl/lib/md5.c"
  67. #include "../dependancies/curl/lib/memdebug.c"
  68. #include "../dependancies/curl/lib/mprintf.c"
  69. #include "../dependancies/curl/lib/multi.c"
  70. #include "../dependancies/curl/lib/netrc.c"
  71. #include "../dependancies/curl/lib/nss.c"
  72. #include "../dependancies/curl/lib/nwlib.c"
  73. #include "../dependancies/curl/lib/nwos.c"
  74. #include "../dependancies/curl/lib/parsedate.c"
  75. #include "../dependancies/curl/lib/progress.c"
  76. #include "../dependancies/curl/lib/qssl.c"
  77. #include "../dependancies/curl/lib/rawstr.c"
  78. #include "../dependancies/curl/lib/security.c"
  79. #include "../dependancies/curl/lib/select.c"
  80. #include "../dependancies/curl/lib/sendf.c"
  81. #include "../dependancies/curl/lib/share.c"
  82. #include "../dependancies/curl/lib/socks.c"
  83. #include "../dependancies/curl/lib/socks_gssapi.c"
  84. #include "../dependancies/curl/lib/socks_sspi.c"
  85. #include "../dependancies/curl/lib/speedcheck.c"
  86. #include "../dependancies/curl/lib/splay.c"
  87. #include "../dependancies/curl/lib/ssh.c"
  88. #include "../dependancies/curl/lib/sslgen.c"
  89. #include "../dependancies/curl/lib/ssluse.c"
  90. #include "../dependancies/curl/lib/strdup.c"
  91. #include "../dependancies/curl/lib/strequal.c"
  92. #include "../dependancies/curl/lib/strerror.c"
  93. #include "../dependancies/curl/lib/strtok.c"
  94. #include "../dependancies/curl/lib/strtoofft.c"
  95. #include "../dependancies/curl/lib/telnet.c"
  96. #include "../dependancies/curl/lib/tftp.c"
  97. #include "../dependancies/curl/lib/timeval.c"
  98. #include "../dependancies/curl/lib/transfer.c"
  99. #include "../dependancies/curl/lib/url.c"
  100. #include "../dependancies/curl/lib/version.c"
  101. #else
  102. #include <curl.h>
  103. #endif
  104. #define T(stringLiteral) JUCE_T(stringLiteral)
  105. }
  106. #if JUCE_MSVC
  107. #pragma warning (pop)
  108. #endif
  109. BEGIN_JUCE_NAMESPACE
  110. using namespace curlNamespace;
  111. //==============================================================================
  112. namespace NetWrapperFunctions
  113. {
  114. static int progressCallback (void* data, double dltotal, double dlnow, double ultotal, double ulnow)
  115. {
  116. cURL* url = (cURL*) data;
  117. if (url->threadShouldExit())
  118. {
  119. return (-1);
  120. }
  121. // ScopedLock sl (cs);
  122. for (int i = 0; i < url->getListenersCount(); i++)
  123. {
  124. cURLListener* listener = url->getListener (i);
  125. if (listener)
  126. {
  127. if (listener->progress (dltotal, dlnow, ultotal, ulnow))
  128. {
  129. return (-1);
  130. }
  131. }
  132. }
  133. return (0);
  134. }
  135. static int writeFunction (void *ptr, size_t size, size_t nmemb, void *data)
  136. {
  137. cURL* url = (cURL*) data;
  138. if (url)
  139. {
  140. // ScopedLock sl (cs);
  141. for (int i = 0; i < url->getListenersCount (); i++)
  142. {
  143. cURLListener* listener = url->getListener (i);
  144. if (listener)
  145. {
  146. if (listener->write (MemoryBlock (ptr, (size * nmemb))))
  147. {
  148. MemoryBlock *bl = url->getMemoryBlock();
  149. const int currentPosition = url->getCurrentPosition();
  150. bl->ensureSize ((size*nmemb) + currentPosition);
  151. bl->copyFrom (ptr, currentPosition, (nmemb*size));
  152. url->setCurrentPosition (bl->getSize());
  153. }
  154. }
  155. }
  156. }
  157. return (nmemb * size);
  158. }
  159. CURLoption optionTranscode (const int option)
  160. {
  161. #define WRAP_RETURN_OPTION(a) case a: { return a; }
  162. switch (option) {
  163. WRAP_RETURN_OPTION(CURLOPT_FILE)
  164. WRAP_RETURN_OPTION(CURLOPT_URL)
  165. WRAP_RETURN_OPTION(CURLOPT_PORT)
  166. WRAP_RETURN_OPTION(CURLOPT_PROXY)
  167. WRAP_RETURN_OPTION(CURLOPT_TIMEOUT)
  168. WRAP_RETURN_OPTION(CURLOPT_REFERER)
  169. WRAP_RETURN_OPTION(CURLOPT_FTPPORT)
  170. WRAP_RETURN_OPTION(CURLOPT_USERAGENT)
  171. WRAP_RETURN_OPTION(CURLOPT_USERPWD)
  172. WRAP_RETURN_OPTION(CURLOPT_PROXYUSERPWD)
  173. WRAP_RETURN_OPTION(CURLOPT_RANGE)
  174. WRAP_RETURN_OPTION(CURLOPT_ERRORBUFFER)
  175. WRAP_RETURN_OPTION(CURLOPT_WRITEFUNCTION)
  176. WRAP_RETURN_OPTION(CURLOPT_READFUNCTION)
  177. WRAP_RETURN_OPTION(CURLOPT_INFILE)
  178. WRAP_RETURN_OPTION(CURLOPT_INFILESIZE)
  179. WRAP_RETURN_OPTION(CURLOPT_POSTFIELDS)
  180. WRAP_RETURN_OPTION(CURLOPT_LOW_SPEED_LIMIT)
  181. WRAP_RETURN_OPTION(CURLOPT_LOW_SPEED_TIME)
  182. WRAP_RETURN_OPTION(CURLOPT_RESUME_FROM)
  183. WRAP_RETURN_OPTION(CURLOPT_COOKIE)
  184. WRAP_RETURN_OPTION(CURLOPT_HTTPHEADER)
  185. WRAP_RETURN_OPTION(CURLOPT_HTTPPOST)
  186. WRAP_RETURN_OPTION(CURLOPT_SSLCERT)
  187. WRAP_RETURN_OPTION(CURLOPT_KEYPASSWD)
  188. WRAP_RETURN_OPTION(CURLOPT_CRLF)
  189. WRAP_RETURN_OPTION(CURLOPT_QUOTE)
  190. WRAP_RETURN_OPTION(CURLOPT_WRITEHEADER)
  191. WRAP_RETURN_OPTION(CURLOPT_COOKIEFILE)
  192. WRAP_RETURN_OPTION(CURLOPT_SSLVERSION)
  193. WRAP_RETURN_OPTION(CURLOPT_TIMECONDITION)
  194. WRAP_RETURN_OPTION(CURLOPT_TIMEVALUE)
  195. WRAP_RETURN_OPTION(CURLOPT_CUSTOMREQUEST)
  196. WRAP_RETURN_OPTION(CURLOPT_STDERR)
  197. WRAP_RETURN_OPTION(CURLOPT_POSTQUOTE)
  198. WRAP_RETURN_OPTION(CURLOPT_WRITEINFO)
  199. WRAP_RETURN_OPTION(CURLOPT_VERBOSE)
  200. WRAP_RETURN_OPTION(CURLOPT_HEADER)
  201. WRAP_RETURN_OPTION(CURLOPT_NOPROGRESS)
  202. WRAP_RETURN_OPTION(CURLOPT_NOBODY)
  203. WRAP_RETURN_OPTION(CURLOPT_FAILONERROR)
  204. WRAP_RETURN_OPTION(CURLOPT_UPLOAD)
  205. WRAP_RETURN_OPTION(CURLOPT_POST)
  206. WRAP_RETURN_OPTION(CURLOPT_DIRLISTONLY)
  207. WRAP_RETURN_OPTION(CURLOPT_APPEND)
  208. #if 0
  209. /* Specify whether to read the user+password from the .netrc or the URL.
  210. * This must be one of the CURL_NETRC_* enums below. */
  211. CINIT(NETRC, LONG, 51),
  212. CINIT(FOLLOWLOCATION, LONG, 52), /* use Location: Luke! */
  213. CINIT(TRANSFERTEXT, LONG, 53), /* transfer data in text/ASCII format */
  214. CINIT(PUT, LONG, 54), /* HTTP PUT */
  215. /* 55 = OBSOLETE */
  216. /* Function that will be called instead of the internal progress display
  217. * function. This function should be defined as the curl_progress_callback
  218. * prototype defines. */
  219. CINIT(PROGRESSFUNCTION, FUNCTIONPOINT, 56),
  220. /* Data passed to the progress callback */
  221. CINIT(PROGRESSDATA, OBJECTPOINT, 57),
  222. /* We want the referrer field set automatically when following locations */
  223. CINIT(AUTOREFERER, LONG, 58),
  224. /* Port of the proxy, can be set in the proxy string as well with:
  225. "[host]:[port]" */
  226. CINIT(PROXYPORT, LONG, 59),
  227. /* size of the POST input data, if strlen() is not good to use */
  228. CINIT(POSTFIELDSIZE, LONG, 60),
  229. /* tunnel non-http operations through a HTTP proxy */
  230. CINIT(HTTPPROXYTUNNEL, LONG, 61),
  231. /* Set the interface string to use as outgoing network interface */
  232. CINIT(INTERFACE, OBJECTPOINT, 62),
  233. /* Set the krb4/5 security level, this also enables krb4/5 awareness. This
  234. * is a string, 'clear', 'safe', 'confidential' or 'private'. If the string
  235. * is set but doesn't match one of these, 'private' will be used. */
  236. CINIT(KRBLEVEL, OBJECTPOINT, 63),
  237. /* Set if we should verify the peer in ssl handshake, set 1 to verify. */
  238. CINIT(SSL_VERIFYPEER, LONG, 64),
  239. /* The CApath or CAfile used to validate the peer certificate
  240. this option is used only if SSL_VERIFYPEER is true */
  241. CINIT(CAINFO, OBJECTPOINT, 65),
  242. /* 66 = OBSOLETE */
  243. /* 67 = OBSOLETE */
  244. /* Maximum number of http redirects to follow */
  245. CINIT(MAXREDIRS, LONG, 68),
  246. /* Pass a long set to 1 to get the date of the requested document (if
  247. possible)! Pass a zero to shut it off. */
  248. CINIT(FILETIME, LONG, 69),
  249. /* This points to a linked list of telnet options */
  250. CINIT(TELNETOPTIONS, OBJECTPOINT, 70),
  251. /* Max amount of cached alive connections */
  252. CINIT(MAXCONNECTS, LONG, 71),
  253. /* What policy to use when closing connections when the cache is filled
  254. up */
  255. CINIT(CLOSEPOLICY, LONG, 72),
  256. /* 73 = OBSOLETE */
  257. /* Set to explicitly use a new connection for the upcoming transfer.
  258. Do not use this unless you're absolutely sure of this, as it makes the
  259. operation slower and is less friendly for the network. */
  260. CINIT(FRESH_CONNECT, LONG, 74),
  261. /* Set to explicitly forbid the upcoming transfer's connection to be re-used
  262. when done. Do not use this unless you're absolutely sure of this, as it
  263. makes the operation slower and is less friendly for the network. */
  264. CINIT(FORBID_REUSE, LONG, 75),
  265. /* Set to a file name that contains random data for libcurl to use to
  266. seed the random engine when doing SSL connects. */
  267. CINIT(RANDOM_FILE, OBJECTPOINT, 76),
  268. /* Set to the Entropy Gathering Daemon socket pathname */
  269. CINIT(EGDSOCKET, OBJECTPOINT, 77),
  270. /* Time-out connect operations after this amount of seconds, if connects
  271. are OK within this time, then fine... This only aborts the connect
  272. phase. [Only works on unix-style/SIGALRM operating systems] */
  273. CINIT(CONNECTTIMEOUT, LONG, 78),
  274. /* Function that will be called to store headers (instead of fwrite). The
  275. * parameters will use fwrite() syntax, make sure to follow them. */
  276. CINIT(HEADERFUNCTION, FUNCTIONPOINT, 79),
  277. /* Set this to force the HTTP request to get back to GET. Only really usable
  278. if POST, PUT or a custom request have been used first.
  279. */
  280. CINIT(HTTPGET, LONG, 80),
  281. /* Set if we should verify the Common name from the peer certificate in ssl
  282. * handshake, set 1 to check existence, 2 to ensure that it matches the
  283. * provided hostname. */
  284. CINIT(SSL_VERIFYHOST, LONG, 81),
  285. /* Specify which file name to write all known cookies in after completed
  286. operation. Set file name to "-" (dash) to make it go to stdout. */
  287. CINIT(COOKIEJAR, OBJECTPOINT, 82),
  288. /* Specify which SSL ciphers to use */
  289. CINIT(SSL_CIPHER_LIST, OBJECTPOINT, 83),
  290. /* Specify which HTTP version to use! This must be set to one of the
  291. CURL_HTTP_VERSION* enums set below. */
  292. CINIT(HTTP_VERSION, LONG, 84),
  293. /* Specifically switch on or off the FTP engine's use of the EPSV command. By
  294. default, that one will always be attempted before the more traditional
  295. PASV command. */
  296. CINIT(FTP_USE_EPSV, LONG, 85),
  297. /* type of the file keeping your SSL-certificate ("DER", "PEM", "ENG") */
  298. CINIT(SSLCERTTYPE, OBJECTPOINT, 86),
  299. /* name of the file keeping your private SSL-key */
  300. CINIT(SSLKEY, OBJECTPOINT, 87),
  301. /* type of the file keeping your private SSL-key ("DER", "PEM", "ENG") */
  302. CINIT(SSLKEYTYPE, OBJECTPOINT, 88),
  303. /* crypto engine for the SSL-sub system */
  304. CINIT(SSLENGINE, OBJECTPOINT, 89),
  305. /* set the crypto engine for the SSL-sub system as default
  306. the param has no meaning...
  307. */
  308. CINIT(SSLENGINE_DEFAULT, LONG, 90),
  309. /* Non-zero value means to use the global dns cache */
  310. CINIT(DNS_USE_GLOBAL_CACHE, LONG, 91), /* To become OBSOLETE soon */
  311. /* DNS cache timeout */
  312. CINIT(DNS_CACHE_TIMEOUT, LONG, 92),
  313. /* send linked-list of pre-transfer QUOTE commands */
  314. CINIT(PREQUOTE, OBJECTPOINT, 93),
  315. /* set the debug function */
  316. CINIT(DEBUGFUNCTION, FUNCTIONPOINT, 94),
  317. /* set the data for the debug function */
  318. CINIT(DEBUGDATA, OBJECTPOINT, 95),
  319. /* mark this as start of a cookie session */
  320. CINIT(COOKIESESSION, LONG, 96),
  321. /* The CApath directory used to validate the peer certificate
  322. this option is used only if SSL_VERIFYPEER is true */
  323. CINIT(CAPATH, OBJECTPOINT, 97),
  324. /* Instruct libcurl to use a smaller receive buffer */
  325. CINIT(BUFFERSIZE, LONG, 98),
  326. /* Instruct libcurl to not use any signal/alarm handlers, even when using
  327. timeouts. This option is useful for multi-threaded applications.
  328. See libcurl-the-guide for more background information. */
  329. CINIT(NOSIGNAL, LONG, 99),
  330. /* Provide a CURLShare for mutexing non-ts data */
  331. CINIT(SHARE, OBJECTPOINT, 100),
  332. /* indicates type of proxy. accepted values are CURLPROXY_HTTP (default),
  333. CURLPROXY_SOCKS4, CURLPROXY_SOCKS4A and CURLPROXY_SOCKS5. */
  334. CINIT(PROXYTYPE, LONG, 101),
  335. /* Set the Accept-Encoding string. Use this to tell a server you would like
  336. the response to be compressed. */
  337. CINIT(ENCODING, OBJECTPOINT, 102),
  338. /* Set pointer to private data */
  339. CINIT(PRIVATE, OBJECTPOINT, 103),
  340. /* Set aliases for HTTP 200 in the HTTP Response header */
  341. CINIT(HTTP200ALIASES, OBJECTPOINT, 104),
  342. /* Continue to send authentication (user+password) when following locations,
  343. even when hostname changed. This can potentially send off the name
  344. and password to whatever host the server decides. */
  345. CINIT(UNRESTRICTED_AUTH, LONG, 105),
  346. /* Specifically switch on or off the FTP engine's use of the EPRT command ( it
  347. also disables the LPRT attempt). By default, those ones will always be
  348. attempted before the good old traditional PORT command. */
  349. CINIT(FTP_USE_EPRT, LONG, 106),
  350. /* Set this to a bitmask value to enable the particular authentications
  351. methods you like. Use this in combination with CURLOPT_USERPWD.
  352. Note that setting multiple bits may cause extra network round-trips. */
  353. CINIT(HTTPAUTH, LONG, 107),
  354. /* Set the ssl context callback function, currently only for OpenSSL ssl_ctx
  355. in second argument. The function must be matching the
  356. curl_ssl_ctx_callback proto. */
  357. CINIT(SSL_CTX_FUNCTION, FUNCTIONPOINT, 108),
  358. /* Set the userdata for the ssl context callback function's third
  359. argument */
  360. CINIT(SSL_CTX_DATA, OBJECTPOINT, 109),
  361. /* FTP Option that causes missing dirs to be created on the remote server.
  362. In 7.19.4 we introduced the convenience enums for this option using the
  363. CURLFTP_CREATE_DIR prefix.
  364. */
  365. CINIT(FTP_CREATE_MISSING_DIRS, LONG, 110),
  366. /* Set this to a bitmask value to enable the particular authentications
  367. methods you like. Use this in combination with CURLOPT_PROXYUSERPWD.
  368. Note that setting multiple bits may cause extra network round-trips. */
  369. CINIT(PROXYAUTH, LONG, 111),
  370. /* FTP option that changes the timeout, in seconds, associated with
  371. getting a response. This is different from transfer timeout time and
  372. essentially places a demand on the FTP server to acknowledge commands
  373. in a timely manner. */
  374. CINIT(FTP_RESPONSE_TIMEOUT, LONG, 112),
  375. /* Set this option to one of the CURL_IPRESOLVE_* defines (see below) to
  376. tell libcurl to resolve names to those IP versions only. This only has
  377. affect on systems with support for more than one, i.e IPv4 _and_ IPv6. */
  378. CINIT(IPRESOLVE, LONG, 113),
  379. /* Set this option to limit the size of a file that will be downloaded from
  380. an HTTP or FTP server.
  381. Note there is also _LARGE version which adds large file support for
  382. platforms which have larger off_t sizes. See MAXFILESIZE_LARGE below. */
  383. CINIT(MAXFILESIZE, LONG, 114),
  384. /* See the comment for INFILESIZE above, but in short, specifies
  385. * the size of the file being uploaded. -1 means unknown.
  386. */
  387. CINIT(INFILESIZE_LARGE, OFF_T, 115),
  388. /* Sets the continuation offset. There is also a LONG version of this;
  389. * look above for RESUME_FROM.
  390. */
  391. CINIT(RESUME_FROM_LARGE, OFF_T, 116),
  392. /* Sets the maximum size of data that will be downloaded from
  393. * an HTTP or FTP server. See MAXFILESIZE above for the LONG version.
  394. */
  395. CINIT(MAXFILESIZE_LARGE, OFF_T, 117),
  396. /* Set this option to the file name of your .netrc file you want libcurl
  397. to parse (using the CURLOPT_NETRC option). If not set, libcurl will do
  398. a poor attempt to find the user's home directory and check for a .netrc
  399. file in there. */
  400. CINIT(NETRC_FILE, OBJECTPOINT, 118),
  401. /* Enable SSL/TLS for FTP, pick one of:
  402. CURLFTPSSL_TRY - try using SSL, proceed anyway otherwise
  403. CURLFTPSSL_CONTROL - SSL for the control connection or fail
  404. CURLFTPSSL_ALL - SSL for all communication or fail
  405. */
  406. CINIT(USE_SSL, LONG, 119),
  407. /* The _LARGE version of the standard POSTFIELDSIZE option */
  408. CINIT(POSTFIELDSIZE_LARGE, OFF_T, 120),
  409. /* Enable/disable the TCP Nagle algorithm */
  410. CINIT(TCP_NODELAY, LONG, 121),
  411. /* 122 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */
  412. /* 123 OBSOLETE. Gone in 7.16.0 */
  413. /* 124 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */
  414. /* 125 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */
  415. /* 126 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */
  416. /* 127 OBSOLETE. Gone in 7.16.0 */
  417. /* 128 OBSOLETE. Gone in 7.16.0 */
  418. /* When FTP over SSL/TLS is selected (with CURLOPT_USE_SSL), this option
  419. can be used to change libcurl's default action which is to first try
  420. "AUTH SSL" and then "AUTH TLS" in this order, and proceed when a OK
  421. response has been received.
  422. Available parameters are:
  423. CURLFTPAUTH_DEFAULT - let libcurl decide
  424. CURLFTPAUTH_SSL - try "AUTH SSL" first, then TLS
  425. CURLFTPAUTH_TLS - try "AUTH TLS" first, then SSL
  426. */
  427. CINIT(FTPSSLAUTH, LONG, 129),
  428. CINIT(IOCTLFUNCTION, FUNCTIONPOINT, 130),
  429. CINIT(IOCTLDATA, OBJECTPOINT, 131),
  430. /* 132 OBSOLETE. Gone in 7.16.0 */
  431. /* 133 OBSOLETE. Gone in 7.16.0 */
  432. /* zero terminated string for pass on to the FTP server when asked for
  433. "account" info */
  434. CINIT(FTP_ACCOUNT, OBJECTPOINT, 134),
  435. /* feed cookies into cookie engine */
  436. CINIT(COOKIELIST, OBJECTPOINT, 135),
  437. /* ignore Content-Length */
  438. CINIT(IGNORE_CONTENT_LENGTH, LONG, 136),
  439. /* Set to non-zero to skip the IP address received in a 227 PASV FTP server
  440. response. Typically used for FTP-SSL purposes but is not restricted to
  441. that. libcurl will then instead use the same IP address it used for the
  442. control connection. */
  443. CINIT(FTP_SKIP_PASV_IP, LONG, 137),
  444. /* Select "file method" to use when doing FTP, see the curl_ftpmethod
  445. above. */
  446. CINIT(FTP_FILEMETHOD, LONG, 138),
  447. /* Local port number to bind the socket to */
  448. CINIT(LOCALPORT, LONG, 139),
  449. /* Number of ports to try, including the first one set with LOCALPORT.
  450. Thus, setting it to 1 will make no additional attempts but the first.
  451. */
  452. CINIT(LOCALPORTRANGE, LONG, 140),
  453. /* no transfer, set up connection and let application use the socket by
  454. extracting it with CURLINFO_LASTSOCKET */
  455. CINIT(CONNECT_ONLY, LONG, 141),
  456. /* Function that will be called to convert from the
  457. network encoding (instead of using the iconv calls in libcurl) */
  458. CINIT(CONV_FROM_NETWORK_FUNCTION, FUNCTIONPOINT, 142),
  459. /* Function that will be called to convert to the
  460. network encoding (instead of using the iconv calls in libcurl) */
  461. CINIT(CONV_TO_NETWORK_FUNCTION, FUNCTIONPOINT, 143),
  462. /* Function that will be called to convert from UTF8
  463. (instead of using the iconv calls in libcurl)
  464. Note that this is used only for SSL certificate processing */
  465. CINIT(CONV_FROM_UTF8_FUNCTION, FUNCTIONPOINT, 144),
  466. /* if the connection proceeds too quickly then need to slow it down */
  467. /* limit-rate: maximum number of bytes per second to send or receive */
  468. CINIT(MAX_SEND_SPEED_LARGE, OFF_T, 145),
  469. CINIT(MAX_RECV_SPEED_LARGE, OFF_T, 146),
  470. /* Pointer to command string to send if USER/PASS fails. */
  471. CINIT(FTP_ALTERNATIVE_TO_USER, OBJECTPOINT, 147),
  472. /* callback function for setting socket options */
  473. CINIT(SOCKOPTFUNCTION, FUNCTIONPOINT, 148),
  474. CINIT(SOCKOPTDATA, OBJECTPOINT, 149),
  475. /* set to 0 to disable session ID re-use for this transfer, default is
  476. enabled (== 1) */
  477. CINIT(SSL_SESSIONID_CACHE, LONG, 150),
  478. /* allowed SSH authentication methods */
  479. CINIT(SSH_AUTH_TYPES, LONG, 151),
  480. /* Used by scp/sftp to do public/private key authentication */
  481. CINIT(SSH_PUBLIC_KEYFILE, OBJECTPOINT, 152),
  482. CINIT(SSH_PRIVATE_KEYFILE, OBJECTPOINT, 153),
  483. /* Send CCC (Clear Command Channel) after authentication */
  484. CINIT(FTP_SSL_CCC, LONG, 154),
  485. /* Same as TIMEOUT and CONNECTTIMEOUT, but with ms resolution */
  486. CINIT(TIMEOUT_MS, LONG, 155),
  487. CINIT(CONNECTTIMEOUT_MS, LONG, 156),
  488. /* set to zero to disable the libcurl's decoding and thus pass the raw body
  489. data to the application even when it is encoded/compressed */
  490. CINIT(HTTP_TRANSFER_DECODING, LONG, 157),
  491. CINIT(HTTP_CONTENT_DECODING, LONG, 158),
  492. /* Permission used when creating new files and directories on the remote
  493. server for protocols that support it, SFTP/SCP/FILE */
  494. CINIT(NEW_FILE_PERMS, LONG, 159),
  495. CINIT(NEW_DIRECTORY_PERMS, LONG, 160),
  496. /* Set the behaviour of POST when redirecting. Values must be set to one
  497. of CURL_REDIR* defines below. This used to be called CURLOPT_POST301 */
  498. CINIT(POSTREDIR, LONG, 161),
  499. /* used by scp/sftp to verify the host's public key */
  500. CINIT(SSH_HOST_PUBLIC_KEY_MD5, OBJECTPOINT, 162),
  501. /* Callback function for opening socket (instead of socket(2)). Optionally,
  502. callback is able change the address or refuse to connect returning
  503. CURL_SOCKET_BAD. The callback should have type
  504. curl_opensocket_callback */
  505. CINIT(OPENSOCKETFUNCTION, FUNCTIONPOINT, 163),
  506. CINIT(OPENSOCKETDATA, OBJECTPOINT, 164),
  507. /* POST volatile input fields. */
  508. CINIT(COPYPOSTFIELDS, OBJECTPOINT, 165),
  509. /* set transfer mode (;type=<a|i>) when doing FTP via an HTTP proxy */
  510. CINIT(PROXY_TRANSFER_MODE, LONG, 166),
  511. /* Callback function for seeking in the input stream */
  512. CINIT(SEEKFUNCTION, FUNCTIONPOINT, 167),
  513. CINIT(SEEKDATA, OBJECTPOINT, 168),
  514. /* CRL file */
  515. CINIT(CRLFILE, OBJECTPOINT, 169),
  516. /* Issuer certificate */
  517. CINIT(ISSUERCERT, OBJECTPOINT, 170),
  518. /* (IPv6) Address scope */
  519. CINIT(ADDRESS_SCOPE, LONG, 171),
  520. /* Collect certificate chain info and allow it to get retrievable with
  521. CURLINFO_CERTINFO after the transfer is complete. (Unfortunately) only
  522. working with OpenSSL-powered builds. */
  523. CINIT(CERTINFO, LONG, 172),
  524. /* "name" and "pwd" to use when fetching. */
  525. CINIT(USERNAME, OBJECTPOINT, 173),
  526. CINIT(PASSWORD, OBJECTPOINT, 174),
  527. /* "name" and "pwd" to use with Proxy when fetching. */
  528. CINIT(PROXYUSERNAME, OBJECTPOINT, 175),
  529. CINIT(PROXYPASSWORD, OBJECTPOINT, 176),
  530. /* Comma separated list of hostnames defining no-proxy zones. These should
  531. match both hostnames directly, and hostnames within a domain. For
  532. example, local.com will match local.com and www.local.com, but NOT
  533. notlocal.com or www.notlocal.com. For compatibility with other
  534. implementations of this, .local.com will be considered to be the same as
  535. local.com. A single * is the only valid wildcard, and effectively
  536. disables the use of proxy. */
  537. CINIT(NOPROXY, OBJECTPOINT, 177),
  538. /* block size for TFTP transfers */
  539. CINIT(TFTP_BLKSIZE, LONG, 178),
  540. /* Socks Service */
  541. CINIT(SOCKS5_GSSAPI_SERVICE, LONG, 179),
  542. /* Socks Service */
  543. CINIT(SOCKS5_GSSAPI_NEC, LONG, 180),
  544. /* set the bitmask for the protocols that are allowed to be used for the
  545. transfer, which thus helps the app which takes URLs from users or other
  546. external inputs and want to restrict what protocol(s) to deal
  547. with. Defaults to CURLPROTO_ALL. */
  548. CINIT(PROTOCOLS, LONG, 181),
  549. /* set the bitmask for the protocols that libcurl is allowed to follow to,
  550. as a subset of the CURLOPT_PROTOCOLS ones. That means the protocol needs
  551. to be set in both bitmasks to be allowed to get redirected to. Defaults
  552. to all protocols except FILE and SCP. */
  553. CINIT(REDIR_PROTOCOLS, LONG, 182),
  554. #endif
  555. default:
  556. break;
  557. }
  558. jassertfalse; // should never reach here !
  559. return CURLOPT_FILE;
  560. }
  561. }
  562. //==============================================================================
  563. cURL::cURL (const NetworkOperationMode& newMode)
  564. : Thread (T("CurlThread")),
  565. mode (newMode),
  566. currentError (String()),
  567. curl (0)
  568. {
  569. bl = new MemoryBlock (0);
  570. }
  571. cURL::~cURL()
  572. {
  573. curl_easy_cleanup (curl);
  574. deleteAndZero (bl);
  575. }
  576. //==============================================================================
  577. bool cURL::initialize()
  578. {
  579. #if JUCE_WIN32
  580. curl_global_init (CURL_GLOBAL_WIN32);
  581. #else
  582. curl_global_init (CURL_GLOBAL_ALL);
  583. #endif
  584. curl = curl_easy_init();
  585. CURLcode ret;
  586. if (! curl)
  587. {
  588. return (false);
  589. }
  590. if ((ret = curl_easy_setopt ((CURL*) curl, CURLOPT_NOPROGRESS, FALSE)))
  591. {
  592. currentError = curl_easy_strerror (ret);
  593. return (false);
  594. }
  595. if ((ret = curl_easy_setopt ((CURL*) curl, CURLOPT_PROGRESSFUNCTION, NetWrapperFunctions::progressCallback)))
  596. {
  597. currentError = curl_easy_strerror (ret);
  598. return (false);
  599. }
  600. if ((ret = curl_easy_setopt ((CURL*) curl, CURLOPT_PROGRESSDATA, this)))
  601. {
  602. currentError = curl_easy_strerror(ret);
  603. return (false);
  604. }
  605. if ((ret = curl_easy_setopt ((CURL*) curl, CURLOPT_WRITEFUNCTION, NetWrapperFunctions::writeFunction)))
  606. {
  607. currentError = curl_easy_strerror(ret);
  608. return (false);
  609. }
  610. if ((ret = curl_easy_setopt ((CURL*) curl, CURLOPT_WRITEDATA, this)))
  611. {
  612. currentError = curl_easy_strerror(ret);
  613. return (false);
  614. }
  615. return (true);
  616. }
  617. //==============================================================================
  618. const String cURL::getErrorString()
  619. {
  620. return (currentError);
  621. }
  622. //==============================================================================
  623. bool cURL::setOption (const int curlOption, const int curlValue)
  624. {
  625. CURLcode ret;
  626. if ((ret = curl_easy_setopt ((CURL*) curl, NetWrapperFunctions::optionTranscode (curlOption), curlValue)))
  627. {
  628. currentError = curl_easy_strerror(ret);
  629. return (false);
  630. }
  631. else
  632. {
  633. return (true);
  634. }
  635. }
  636. bool cURL::setOption (const int curlOption, const String curlValue)
  637. {
  638. CURLcode ret;
  639. if ((ret = curl_easy_setopt ((CURL*) curl, NetWrapperFunctions::optionTranscode (curlOption), curlValue.toUTF8())))
  640. {
  641. currentError = curl_easy_strerror(ret);
  642. return (false);
  643. }
  644. else
  645. {
  646. return (true);
  647. }
  648. }
  649. //==============================================================================
  650. void cURL::addListener (cURLListener *ptr)
  651. {
  652. ScopedLock sl (cs);
  653. listeners.addIfNotAlreadyThere (ptr);
  654. }
  655. void cURL::removeListener (cURLListener *ptr)
  656. {
  657. ScopedLock sl (cs);
  658. listeners.removeValue (ptr);
  659. }
  660. cURLListener* cURL::getListener (const int index)
  661. {
  662. ScopedLock sl (cs);
  663. return (cURLListener*) listeners.getUnchecked (index);
  664. }
  665. int cURL::getListenersCount () const
  666. {
  667. ScopedLock sl (cs);
  668. return listeners.size ();
  669. }
  670. //==============================================================================
  671. bool cURL::startTransfer()
  672. {
  673. currentPosition = 0;
  674. bl->setSize (0, false);
  675. notifyTransferStart();
  676. if (mode == AsyncMode && ! isThreadRunning())
  677. {
  678. startThread();
  679. return (true);
  680. }
  681. if (curl)
  682. {
  683. Logger::writeToLog (T("cURL::startTransfer()"));
  684. CURLcode ret;
  685. if ((ret = curl_easy_perform ((CURL*) curl)))
  686. {
  687. currentError = curl_easy_strerror (ret);
  688. notifyTransferEnd (false);
  689. return (false);
  690. }
  691. else
  692. {
  693. notifyTransferEnd (false);
  694. return (true);
  695. }
  696. }
  697. else
  698. {
  699. currentError = T("CURL not initiazlied");
  700. return (false);
  701. }
  702. }
  703. //==============================================================================
  704. void cURL::run()
  705. {
  706. if (mode == AsyncMode)
  707. {
  708. if (curl)
  709. {
  710. CURLcode ret;
  711. if ((ret = curl_easy_perform ((CURL*) curl)))
  712. {
  713. currentError = curl_easy_strerror (ret);
  714. notifyTransferEnd (true);
  715. return;
  716. }
  717. else
  718. {
  719. notifyTransferEnd (false);
  720. return;
  721. }
  722. }
  723. else
  724. {
  725. currentError = T("CURL not initiazlied");
  726. notifyTransferEnd (true);
  727. return;
  728. }
  729. }
  730. else
  731. {
  732. currentError = T("CURL is not in ASYNC mode");
  733. return;
  734. }
  735. }
  736. //==============================================================================
  737. MemoryBlock cURL::getRawData()
  738. {
  739. return (*bl);
  740. }
  741. String cURL::getStringData()
  742. {
  743. return String::fromUTF8 ((uint8*) bl->getData(), bl->getSize());
  744. }
  745. const uint32 cURL::getDataSize()
  746. {
  747. return bl->getSize();
  748. }
  749. //==============================================================================
  750. void cURL::setMode (const cURL::NetworkOperationMode& shouldBeAsync)
  751. {
  752. mode = shouldBeAsync;
  753. }
  754. const cURL::NetworkOperationMode cURL::getMode()
  755. {
  756. return mode;
  757. }
  758. //==============================================================================
  759. /*
  760. bool cURL::getInfo (const int curlOption, String &stringValue)
  761. {
  762. CURLcode ret;
  763. if (ret = curl_easy_getinfo ((CURL*) curl, NetWrapperFunctions::optionTranscode (curlOption), stringValue))
  764. {
  765. currentError = curl_easy_strerror(ret);
  766. return (false);
  767. }
  768. return (true);
  769. }
  770. bool cURL::getInfo (const int curlOption, double &doubleValue)
  771. {
  772. CURLcode ret;
  773. if (ret = curl_easy_getinfo ((CURL*) curl, NetWrapperFunctions::optionTranscode (curlOption), doubleValue))
  774. {
  775. currentError = curl_easy_strerror(ret);
  776. return (false);
  777. }
  778. return (true);
  779. }
  780. bool cURL::getInfo (const int curlOption, long &longValue)
  781. {
  782. CURLcode ret;
  783. if (ret = curl_easy_getinfo ((CURL*) curl, NetWrapperFunctions::optionTranscode (curlOption), longValue))
  784. {
  785. currentError = curl_easy_strerror(ret);
  786. return (false);
  787. }
  788. return (true);
  789. }
  790. */
  791. //==============================================================================
  792. MemoryBlock* cURL::getMemoryBlock()
  793. {
  794. return bl;
  795. }
  796. const uint32 cURL::getCurrentPosition()
  797. {
  798. return currentPosition;
  799. }
  800. void cURL::setCurrentPosition (const uint32 newPosition)
  801. {
  802. currentPosition = newPosition;
  803. }
  804. void cURL::notifyTransferStart ()
  805. {
  806. ScopedLock sl (cs);
  807. for (int i = 0; i < getListenersCount (); i++)
  808. {
  809. cURLListener* listener = getListener (i);
  810. if (listener)
  811. listener->transferStart ();
  812. }
  813. }
  814. void cURL::notifyTransferEnd (const bool errorIndicator)
  815. {
  816. ScopedLock sl (cs);
  817. for (int i = 0; i < getListenersCount (); i++)
  818. {
  819. cURLListener* listener = getListener (i);
  820. if (listener)
  821. listener->transferEnd (errorIndicator);
  822. }
  823. }
  824. END_JUCE_NAMESPACE
  825. #endif