guide.tex 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. \LoadClass[12pt,letterpaper]{article}
  2. \documentclass{article}
  3. \usepackage{verbatim}
  4. \author{Jean-Philippe Barrette-LaPierre}
  5. \title{Programming with cURLpp}
  6. \begin{document}
  7. \maketitle
  8. \section{About this Document}
  9. \newcommand{\Cpp}{C{\tt ++}}
  10. This document attempts to describe the general principles and some basic
  11. approaches to consider when programming with cURLpp. Don't forget that cURLpp
  12. is a \Cpp wrapper of libcurl, so cURLpp needs libcurl to be installed already.
  13. This document will refer to 'the user' as the person writing the source code
  14. that uses cURLpp. That would probably be you or someone in a similar position.
  15. What will be generally refered to as 'the program' will be the collective
  16. source code that you write and that is using cURLpp for transfers. The program
  17. is outside cURLpp and cURLpp is outside of the program.
  18. To get more details on all options and functions described herein, please
  19. refer to their respective man pages. You should always have in mind that this
  20. is a \Cpp wrapper of libcurl. It would be unproductive to duplicate libcurl's
  21. documentation here, so this document will show you how to interact with cURLpp,
  22. but you should read the libcurl programming tutorial, which this document is
  23. strongly inspired from, and the libcurl man pages.
  24. \section{Building}
  25. There are many different ways to build C++ programs. This chapter will assume a
  26. unix-style build process. If you use a different build system, you can still
  27. read this to get general information that may apply to your environment as
  28. well. Note that cURLpp need libcurl to be already installed.
  29. \subsection{Compiling the Program}
  30. Your compiler needs to know where cURLpp's and libcurl's headers are
  31. located. Therefore you must set your compiler's include path to point to
  32. the directory where you installed them. The 'curlpp-config'\footnote{
  33. The curlpp-config tool, which wraps all functions of curl-config,
  34. is generated at build-time (on unix-like systems) and should be installed
  35. with the 'make install' or similar instruction that installs the library,
  36. header files, man pages etc.} tool can be
  37. used to get this information:
  38. \begin{verbatim} # curlpp-config --cflags\end{verbatim}
  39. If pkg-config is installed, you can use it this way:
  40. \begin{verbatim} # pkg-config --cflags curlpp\end{verbatim}
  41. But, if you're using \verb+autoconf+ for your project you can use
  42. \verb+pkg-config+ macros. See \verb+pkg-config+ man pages for more
  43. details.
  44. \subsection{Linking the Program with cURLpp}
  45. When having compiled the program, you need to link your object files to
  46. create a single executable. For that to succeed, you need to link with
  47. cURLpp and possibly also with other libraries that cURLpp itself depends
  48. on (such as libcurl). This may include OpenSSL libraries and even some standard
  49. OS libraries may be needed on the command line. To figure out which flags to use,
  50. the 'curlpp-config' tool comes to the rescue once again:
  51. \begin{verbatim} # curlpp-config --libs\end{verbatim}
  52. Again, if pkg-config is installed, you can use it this way:
  53. \begin{verbatim} # pkg-config --libs curlpp\end{verbatim}
  54. \subsection{SSL or Not}
  55. cURLpp, like libcurl, can be built and customized in many ways. One of the things that
  56. varies between different libraries and builds is the support for SSL-based
  57. transfers, like HTTPS and FTPS. If OpenSSL was detected properly by libcurl
  58. at build-time, cURLpp will be built with SSL support. To figure out if an
  59. installed cURLpp has been built with SSL support enabled, use
  60. 'curlpp-config' like this:
  61. \begin{verbatim} # curlpp-config --feature\end{verbatim}
  62. If SSL is supported, the keyword 'SSL' will be written to stdout,
  63. possibly together with a few other features that can be on and off on
  64. different cURLpps.
  65. \subsection{Portable Code in a Portable World}
  66. The people behind libcurl have put a considerable effort to make libcurl work
  67. on a large number of different operating systems and environments.
  68. You program cURLpp the same way on all platforms that cURLpp runs on. There
  69. are only very few minor considerations that differ. If you make sure just to
  70. write your code portably enough, you may very well create yourself a very
  71. portable program. cURLpp shouldn't stop you from that.
  72. \section{Global Preparation}
  73. The program must initialize some of the cURLpp functionality globally. That
  74. means it should be done exactly once, no matter how many times you intend to
  75. use the library. Once for your program's entire lifetime. This is done using
  76. \begin{verbatim}
  77. cURLpp::initialize( long flags = cURLpp::CURL_GLOBAL_ALL )
  78. \end{verbatim}
  79. and it takes one parameter which is a bit pattern that tells cURLpp what to
  80. intialize. Check the man page of \verb+curl_global_init+ for more details on flags.
  81. When the program no longer uses cURLpp, it should call \verb+cURLpp::terminate()+,
  82. which is the opposite of the init call. It will then do the operations needed
  83. to cleanup the resources that the \verb+cURLpp::initialize()+ call initialized.
  84. Repeated calls to \verb+cURLpp::initialize()+ and \verb+cURLpp::terminate()+ must not be made.
  85. They must only be called once each. The cURLpp::Cleanup class can be used to do this. It will
  86. call the \verb+cURLpp::initialize()+ function in its constructor and \verb+cURLpp::terminate()+
  87. in its destructor. Check example01.cpp in the examples/ directory of
  88. the source distribution for an example.
  89. \section{Handle the Easy cURLpp}
  90. To use the easy interface, you must first create yourself an easy handle. You
  91. need one handle for each easy session you want to perform. Basically, you
  92. should use one handle for every thread you plan to use for transferring. You
  93. must never share the same handle in multiple threads.
  94. Get an easy handle with
  95. \begin{verbatim} cURLpp::Easy easyhandle;\end{verbatim}
  96. This creates an easy handle. Using that you proceed to the next step: setting
  97. up your preferred actions. A handle is just a logic entity for the upcoming
  98. transfer or series of transfers. You can use it to do HTTP or FTP
  99. requests.
  100. You set properties and options for this handle using \verb+cURLpp::Options+,
  101. or \verb+cURLpp::OptionList+ classes; we will discuss \verb+cURLpp::OptionList+
  102. later. They control how the subsequent transfer or transfers will be made.
  103. Options remain set in the handle until set again to something different.
  104. Alas, multiple requests using the same handle will use the same options.
  105. Many of the informationals you set in cURLpp are \Cpp standard library strings.
  106. Keep in mind that when you set strings with member functions, cURLpp will copy
  107. the data. It will not merely point to the data. You don't need to make sure
  108. that the data remains available for cURLpp.
  109. One of the most basic properties to set in the handle is the URL. You set
  110. your preferred URL to transfer with a
  111. \verb+void cURLpp::Options::Url(const char *link)+
  112. option class, in a manner similar to:
  113. \begin{verbatim}
  114. easyhandle.setOpt(cURLpp::Options::Url("http://example.com/"));
  115. \end{verbatim}
  116. There are of course many more options you can set, and we'll get back to a
  117. few of them later. Let's instead continue to the actual transfer:
  118. \begin{verbatim}
  119. easyhandle.perform();
  120. \end{verbatim}
  121. The \verb+cURLpp::Easy::perform()+ will connect to the remote site, do the necessary
  122. commands and receive the transfer. Whenever it receives data, it calls the
  123. trait function we previously set. The function may get one byte at a time,
  124. or it may get many kilobytes at once. cURLpp delivers as much as possible as
  125. often as possible. Your trait function should return the number of bytes
  126. it "took care of". If that is not the exact same amount of bytes that was
  127. passed to it, cURLpp will abort the operation and throw an exception.
  128. When the transfer is complete, the function throws a
  129. \verb+cURLpp::Exception+ if it
  130. doesn't succeed in its mission. the \verb+const char *cURLpp::Exception::what()+ will
  131. return the human readable reason of failure.
  132. \section{Wrapping libcurl}
  133. As previously said, \verb+cURLpp+ is just a \Cpp libcurl wrapper. It wouldn't be a good
  134. idea to reproduce here, in this project, all the libcurl documentation. This means
  135. that when you will be programming with \verb+cURLpp+, you will refer more to libcurl's
  136. documentation than to \verb+cURLpp+'s. We will explain here how \verb+cURLpp+ wraps libcurl, so
  137. you will able to use it, without constantly refering to its manual.
  138. First, you must know that there are two main things that constitute \verb+cURLpp+: There are
  139. its options value setting/retrieving behavior and its utilities that helps you to use
  140. libcurl's options more easily.
  141. \subsection{Option setting/retrieving}
  142. The main feature of \verb+cURLpp+ is that you can retrieve options previously set on handles.
  143. \verb+cURLpp+ gives you the opportunity to retrieve options values that were previously set
  144. on a specific handle and then use them again for other handles. But first, let's show
  145. you how to set an option on a handle, in comparison to libcurl's way of setting an option.
  146. libcurl sets options on handles with this function:
  147. \begin{verbatim}
  148. curl_easy_setopt(CURL *handle, CURLoption option, parameter)
  149. \end{verbatim}
  150. Here's a part of the documentation taken from the man pages:
  151. \begin{quote}
  152. \verb+curl_easy_setopt()+ is used to tell libcurl how to behave. By using the appropriate options to
  153. \verb+curl_easy_setopt()+, you can change libcurl's behavior. All options are set with the option
  154. followed by a parameter. That parameter can be a long, a function pointer or an object pointer,
  155. all depending on what the specific option expects.
  156. \end{quote}
  157. Lets code a simple example:
  158. \begin{verbatim}
  159. CURL *handle = curl_easy_init();
  160. if(handle == NULL) {
  161. //something went wrong.
  162. }
  163. CURLcode code = curl_easy_setopt(handle,
  164. CURLOPT_URL, ``http://www.example.com'');
  165. if(code != CURLE_OK) {
  166. //something went wrong
  167. }
  168. \end{verbatim}
  169. The code below does the same thing but with \verb+cURLpp+:
  170. \begin{verbatim}
  171. cURLpp::Easy handle;
  172. handle.setOpt(cURLpp::Options::Url(``http://www.example.com'');
  173. \end{verbatim}
  174. If a problem occur, \verb+cURLpp+ will throw an exception, for more detail on this subject,
  175. see the next section named \textit{Exception issues}. As you see, the equivalent
  176. of the \verb+curl_easy_setopt+ function is the cURLpp::Easy::setOpt member function.
  177. \subsubsection{cURLpp::Options}
  178. The question that you might ask you at this moment is: ``what exactly is the
  179. \verb+cURLpp::Options::Url+ class mentioned in the previous example?'' In fact,
  180. this class is used to store values of options, but also to retrieve them, as shown
  181. below:
  182. \begin{verbatim}
  183. cURLpp::Easy handle;
  184. handle.setOpt(cURLpp::Options::Url(``http://www.example.com'');
  185. cURLpp::Options::Url myUrl;
  186. handle.getOpt(myUrl);
  187. std::cout << myUrl.getValue() << std::endl;
  188. \end{verbatim}
  189. This piece of code should print the URL on the standard output. Here's the
  190. code of the \verb+examples/example01.cpp+ file.
  191. \begin{verbatim}
  192. #include <string>
  193. #include <iostream>
  194. #include <curlpp/cURLpp.hpp>
  195. #include <curlpp/Options.hpp>
  196. #define MY_PORT 8080
  197. /**
  198. * This example is made to show you how you can use the Options.
  199. */
  200. int main()
  201. {
  202. try
  203. {
  204. cURLpp::Cleanup myCleanup;
  205. // Creation of the URL option.
  206. cURLpp::Options::Url myUrl(
  207. std::string("http://example.com"));
  208. // Copy construct from the other URL.
  209. cURLpp::Options::Url myUrl2(myUrl);
  210. // Creation of the port option.
  211. cURLpp::Options::Port myPort(MY_PORT);
  212. // Creation of the request.
  213. cURLpp::Easy myRequest;
  214. // Creation of an option that contain a copy
  215. // of the URL option.
  216. cURLpp::OptionBase *mytest = myUrl.clone();
  217. myRequest.setOpt(*mytest);
  218. // You can reuse the base option for other type of option
  219. // and set the option to the request. but first, don't forget
  220. // to delete the previous memory. You can delete it since the
  221. // option is internally duplicated for the request.
  222. delete mytest;
  223. mytest = myPort.clone();
  224. myRequest.setOpt(*mytest);
  225. delete mytest;
  226. // You can clone an option directly to the same type of
  227. // option.
  228. cURLpp::Options::Url *myUrl3 = myUrl.clone();
  229. myRequest.setOpt(myUrl3);
  230. // Now myUrl3 is owned by the request we will NOT use
  231. // it anymore.
  232. // You don't need to declare an option if you just want
  233. // to use it once.
  234. myRequest.setOpt(cURLpp::Options::Url("example.com"));
  235. // Note that the previous line wasn't really efficient
  236. // because we create the option, this option is duplicated
  237. // for the request and then the option destructor is called.
  238. // You can use this instead:
  239. myRequest.setOpt(new cURLpp::Options::Url("example.com"));
  240. // Note that with this the request will use directly this
  241. // instance we just created. Be aware that if you pass an
  242. // Option pointer to the setOpt function, it will consider
  243. // the instance has its own instance. The Option instance
  244. // will be deleted when the request will be deleted, so
  245. // don't use the instance further in your code.
  246. // Doing the previous line is efficient as this:
  247. myRequest.setOpt(myUrl.clone());
  248. // You can retrieve the value of a specific option.
  249. std::cout << myUrl2.getValue() << std::endl;
  250. // You can see what are the options set for a request
  251. // with this function. This function will print the option
  252. // to the stdout.
  253. myRequest.print();
  254. // Perform the transaction with the options set.
  255. myRequest.perform();
  256. }
  257. catch( cURLpp::RuntimeError &e )
  258. {
  259. std::cout << e.what() << std::endl;
  260. }
  261. catch( cURLpp::LogicError &e )
  262. {
  263. std::cout << e.what() << std::endl;
  264. }
  265. return 0;
  266. }
  267. \end{verbatim}
  268. \subsection{cURLpp::Option types}
  269. This section will explain the use of the types that we use for
  270. some options that differ from types that libcurl uses for the
  271. same option.
  272. \subsubsection{The bool type}
  273. A true value is binded to a non-zero long value, a false value
  274. is binded to a zero long value.
  275. \subsubsection{The std::string type}
  276. The \verb+std::string::c_str()+ function is passed to libcurl.
  277. \subsubsection{The std::list template of std::string type}
  278. This type is used when libcurl's option need a \verb+curl_slist+. Instead of
  279. using this homemade struct, cURLpp allow you to use a known type, the
  280. \verb+std::list+. cURLpp this transform internally the \verb+std::list+
  281. to a \verb+curl_slist+.
  282. \subsection{cURLpp::Options}
  283. This section just list how each libcurl's option is binded by cURLpp.
  284. Some options might not be there, if it's the case and you want to use them,
  285. see the ``how to enhance cURLpp'' section.
  286. \subsubsection{Behavior options}
  287. \begin{verbatim}
  288. typedef cURLpp::OptionTrait< bool,
  289. CURLOPT_VERBOSE > Verbose;
  290. typedef cURLpp::OptionTrait< bool,
  291. CURLOPT_HEADER > Header;
  292. typedef cURLpp::OptionTrait< bool,
  293. CURLOPT_NOSIGNAL > NoSignal;
  294. typedef cURLpp::OptionTrait< bool,
  295. CURLOPT_NOPROGRESS > NoProgress;
  296. \end{verbatim}
  297. \subsubsection{Callback options}
  298. \begin{verbatim}
  299. typedef cURLpp::OptionTrait< cURL::curl_write_callback,
  300. CURLOPT_WRITEFUNCTION > WriteFunction;
  301. typedef cURLpp::OptionTrait< void *,
  302. CURLOPT_WRITEDATA > WriteData;
  303. typedef cURLpp::OptionTrait< cURL::curl_read_callback,
  304. CURLOPT_READFUNCTION > ReadFunction;
  305. typedef cURLpp::OptionTrait< void *,
  306. CURLOPT_READDATA > ReadData;
  307. typedef cURLpp::OptionTrait< cURL::curl_progress_callback,
  308. CURLOPT_PROGRESSFUNCTION > ProgressFunction;
  309. typedef cURLpp::OptionTrait< void *,
  310. CURLOPT_PROGRESSDATA > ProgressData;
  311. typedef cURLpp::OptionTrait< cURL::curl_write_callback,
  312. CURLOPT_HEADERFUNCTION > HeaderFunction;
  313. typedef cURLpp::OptionTrait< void *,
  314. CURLOPT_HEADERDATA > HeaderData;
  315. typedef cURLpp::OptionTrait< cURL::curl_debug_callback,
  316. CURLOPT_DEBUGFUNCTION > DebugFunction;
  317. typedef cURLpp::OptionTrait< void *,
  318. CURLOPT_DEBUGDATA > DebugData;
  319. #ifdef CURLOPT_SSL_CTX_FUNCTION
  320. typedef cURLpp::OptionTrait< cURL::curl_ssl_ctx_callback,
  321. CURLOPT_SSL_CTX_FUNCTION > SslCtxFunction;
  322. typedef cURLpp::OptionTrait< void *,
  323. cURL::CURLOPT_SSL_CTX_DATA > SslCtxData;
  324. #endif
  325. \end{verbatim}
  326. \subsubsection{Error options}
  327. \begin{verbatim}
  328. typedef cURLpp::OptionTrait< char *,
  329. cURL::CURLOPT_ERRORBUFFER > ErrorBuffer;
  330. typedef cURLpp::OptionTrait< FILE *,
  331. cURL::CURLOPT_STDERR > StdErr;
  332. typedef cURLpp::OptionTrait< bool,
  333. cURL::CURLOPT_FAILONERROR > FailOnError;
  334. \end{verbatim}
  335. \subsubsection{Network options}
  336. \begin{verbatim}
  337. typedef cURLpp::OptionTrait< std::string,
  338. cURL::CURLOPT_URL > Url;
  339. typedef cURLpp::OptionTrait< std::string,
  340. cURL::CURLOPT_PROXY > Proxy;
  341. typedef cURLpp::OptionTrait< long,
  342. cURL::CURLOPT_PROXYPORT > ProxyPort;
  343. typedef cURLpp::OptionTrait< curl_proxytype,
  344. cURL::CURLOPT_PROXYTYPE > ProxyType;
  345. typedef cURLpp::OptionTrait< bool,
  346. cURL::CURLOPT_HTTPPROXYTUNNEL > HttpProxyTunnel;
  347. typedef cURLpp::OptionTrait< std::string,
  348. cURL::CURLOPT_INTERFACE > Interface;
  349. typedef cURLpp::OptionTrait< long,
  350. cURL::CURLOPT_DNS_CACHE_TIMEOUT > DnsCacheTimeout;
  351. typedef cURLpp::OptionTrait< bool,
  352. cURL::CURLOPT_DNS_USE_GLOBAL_CACHE > DnsUseGlobalCache;
  353. typedef cURLpp::OptionTrait< long,
  354. cURL::CURLOPT_BUFFERSIZE > BufferSize;
  355. typedef cURLpp::OptionTrait< long,
  356. cURL::CURLOPT_PORT > Port;
  357. #ifdef cURL::CURLOPT_TCP_NODELAY
  358. typedef cURLpp::OptionTrait< bool,
  359. cURL::CURLOPT_TCP_NODELAY > TcpNoDelay;
  360. #endif
  361. \end{verbatim}
  362. \subsubsection{Names and passwords options}
  363. \begin{verbatim}
  364. typedef cURLpp::OptionTrait< long,
  365. cURL::CURLOPT_NETRC > Netrc;
  366. #ifdef cURL::CURLOPT_NETRC_FILE
  367. typedef cURLpp::OptionTrait< std::string,
  368. cURL::CURLOPT_NETRC_FILE > NetrcFile;
  369. #endif
  370. typedef cURLpp::OptionTrait< std::string,
  371. cURL::CURLOPT_USERPWD > UserPwd;
  372. typedef cURLpp::OptionTrait< std::string,
  373. cURL::CURLOPT_PROXYUSERPWD > ProxyUserPwd;
  374. typedef cURLpp::OptionTrait< long,
  375. cURL::CURLOPT_HTTPAUTH > HttpAuth;
  376. typedef cURLpp::OptionTrait< long,
  377. cURL::CURLOPT_PROXYAUTH > ProxyAuth;
  378. \end{verbatim}
  379. \subsubsection{HTTP options}
  380. \begin{verbatim}
  381. typedef cURLpp::OptionTrait< bool,
  382. cURL::CURLOPT_AUTOREFERER > AutoReferer;
  383. typedef cURLpp::OptionTrait< std::string,
  384. cURL::CURLOPT_ENCODING > Encoding;
  385. typedef cURLpp::OptionTrait< bool,
  386. cURL::CURLOPT_FOLLOWLOCATION > FollowLocation;
  387. #ifdef cURL::CURLOPT_UNRESTRICTED_AUTH
  388. typedef cURLpp::OptionTrait< bool,
  389. cURL::CURLOPT_UNRESTRICTED_AUTH > UnrestrictedAuth;
  390. #endif
  391. typedef cURLpp::OptionTrait< long,
  392. cURL::CURLOPT_MAXREDIRS > MaxRedirs;
  393. #ifndef cURL::CURLOPT_UPLOAD
  394. typedef cURLpp::OptionTrait< bool,
  395. cURL::CURLOPT_PUT > Put;
  396. #else
  397. typedef cURLpp::OptionTrait< bool,
  398. cURL::CURLOPT_UPLOAD > Put;
  399. #endif
  400. typedef cURLpp::OptionTrait< bool,
  401. cURL::CURLOPT_POST > Post;
  402. typedef cURLpp::OptionTrait< std::string,
  403. cURL::CURLOPT_POSTFIELDS > PostFields;
  404. typedef cURLpp::OptionTrait< std::string,
  405. cURL::CURLOPT_POSTFIELDSIZE > PostFieldSize;
  406. #ifdef cURL::CURLOPT_POSTFIELDSIZE_LARGE
  407. typedef cURLpp::OptionTrait< std::string,
  408. cURL::CURLOPT_POSTFIELDSIZE_LARGE > PostFieldSizeLarge;
  409. #endif
  410. typedef cURLpp::OptionTrait< struct cURLpp::cURL::HttpPost *,
  411. cURL::CURLOPT_HTTPPOST > HttpPost;
  412. typedef cURLpp::OptionTrait< std::string,
  413. cURL::CURLOPT_REFERER > Referer;
  414. typedef cURLpp::OptionTrait< std::string,
  415. cURL::CURLOPT_USERAGENT > UserAgent;
  416. typedef cURLpp::OptionTrait< std::list< std::string >,
  417. cURL::CURLOPT_HTTPHEADER > HttpHeader;
  418. typedef cURLpp::OptionTrait< std::list< std::string >,
  419. cURL::CURLOPT_HTTP200ALIASES > Http200Aliases;
  420. typedef cURLpp::OptionTrait< std::string,
  421. cURL::CURLOPT_COOKIE > Cookie;
  422. typedef cURLpp::OptionTrait< std::string,
  423. cURL::CURLOPT_COOKIEFILE > CookieFile;
  424. typedef cURLpp::OptionTrait< std::string,
  425. cURL::CURLOPT_COOKIEJAR > CookieJar;
  426. typedef cURLpp::OptionTrait< std::string,
  427. cURL::CURLOPT_COOKIESESSION > CookieSession;
  428. typedef cURLpp::OptionTrait< std::string,
  429. cURL::CURLOPT_HTTPGET > HttpGet;
  430. typedef cURLpp::OptionTrait< long,
  431. cURL::CURLOPT_HTTP_VERSION > HttpVersion;
  432. \end{verbatim}
  433. \subsubsection{FTP options}
  434. \begin{verbatim}
  435. typedef cURLpp::OptionTrait< std::string,
  436. cURL::CURLOPT_FTPPORT > FtpPort;
  437. typedef cURLpp::OptionTrait< long,
  438. cURL::CURLOPT_QUOTE > Quote;
  439. typedef cURLpp::OptionTrait< long,
  440. cURL::CURLOPT_POSTQUOTE > PostQuote;
  441. typedef cURLpp::OptionTrait< long,
  442. cURL::CURLOPT_PREQUOTE > PreQuote;
  443. typedef cURLpp::OptionTrait< bool,
  444. cURL::CURLOPT_FTPLISTONLY > FtpListOnly;
  445. typedef cURLpp::OptionTrait< bool,
  446. cURL::CURLOPT_FTPAPPEND > FtpAppend;
  447. typedef cURLpp::OptionTrait< bool,
  448. cURL::CURLOPT_FTP_USE_EPSV > FtpUseEpsv;
  449. #ifdef cURL::CURLOPT_FTP_CREATE_MISSING_DIRS
  450. typedef cURLpp::OptionTrait< bool,
  451. cURL::CURLOPT_FTP_CREATE_MISSING_DIRS > FtpCreateMissingDirs;
  452. #endif
  453. #ifdef cURL::CURLOPT_FTP_RESPONSE_TIMEOUT
  454. typedef cURLpp::OptionTrait< bool,
  455. cURL::CURLOPT_FTP_RESPONSE_TIMEOUT > FtpResponseTimeout;
  456. #endif
  457. #ifdef cURL::CURLOPT_FTP_SSL
  458. typedef cURLpp::OptionTrait< cURLpp::curl_ftpssl,
  459. cURL::CURLOPT_FTP_SSL > FtpSsl;
  460. #endif
  461. #ifdef cURL::CURLOPT_FTP_AUTH
  462. typedef cURLpp::OptionTrait< cURLpp::curl_ftpauth,
  463. cURL::CURLOPT_FTP_AUTH > FtpAuth;
  464. #endif
  465. \end{verbatim}
  466. \subsubsection{Protocol options}
  467. \begin{verbatim}
  468. typedef cURLpp::OptionTrait< bool,
  469. cURL::CURLOPT_TRANSFERTEXT > TransferText;
  470. typedef cURLpp::OptionTrait< bool,
  471. cURL::CURLOPT_CRLF > Crlf;
  472. typedef cURLpp::OptionTrait< std::string,
  473. cURL::CURLOPT_RANGE > Range;
  474. typedef cURLpp::OptionTrait< long,
  475. cURL::CURLOPT_RESUME_FROM > ResumeFrom;
  476. #ifdef cURL::CURLOPT_RESUME_FROM_LARGE
  477. typedef cURLpp::OptionTrait< curl_off_t,
  478. cURL::CURLOPT_RESUME_FROM_LARGE > ResumeFromLarge;
  479. #endif
  480. typedef cURLpp::OptionTrait< std::string,
  481. cURL::CURLOPT_CUSTOMREQUEST > CustomRequest;
  482. typedef cURLpp::OptionTrait< bool,
  483. cURL::CURLOPT_FILETIME > FileTime;
  484. typedef cURLpp::OptionTrait< bool,
  485. cURL::CURLOPT_NOBODY > NoBody;
  486. typedef cURLpp::OptionTrait< long,
  487. cURL::CURLOPT_INFILESIZE > InfileSize;
  488. #ifdef cURL::CURLOPT_INFILESIZE_LARGE
  489. typedef cURLpp::OptionTrait< cURL::curl_off_t,
  490. cURL::CURLOPT_INFILESIZE_LARGE > InfileSizeLarge;
  491. #endif
  492. #ifdef cURL::CURLOPT_UPLOAD
  493. typedef cURLpp::OptionTrait< bool,
  494. cURL::CURLOPT_UPLOAD > Upload;
  495. #else
  496. typedef cURLpp::OptionTrait< bool,
  497. cURL::CURLOPT_PUT > Upload;
  498. #endif
  499. #ifdef cURL::CURLOPT_MAXFILESIZE
  500. typedef cURLpp::OptionTrait< long,
  501. cURL::CURLOPT_MAXFILESIZE > MaxFileSize;
  502. #endif
  503. #ifdef cURL::CURLOPT_MAXFILESIZE_LARGE
  504. typedef cURLpp::OptionTrait< cURL::curl_off_t,
  505. cURL::CURLOPT_MAXFILESIZE_LARGE > MaxFileSizeLarge;
  506. #endif
  507. typedef cURLpp::OptionTrait< bool,
  508. cURL::CURLOPT_TIMECONDITION > TimeCondition;
  509. typedef cURLpp::OptionTrait< bool,
  510. cURL::CURLOPT_TIMECONDITION > TimeValue;
  511. \end{verbatim}
  512. \subsubsection{Connection options}
  513. \begin{verbatim}
  514. typedef cURLpp::OptionTrait< long,
  515. cURL::CURLOPT_TIMEOUT > Timeout;
  516. typedef cURLpp::OptionTrait< long,
  517. cURL::CURLOPT_LOW_SPEED_LIMIT > LowSpeedLimit;
  518. typedef cURLpp::OptionTrait< long,
  519. cURL::CURLOPT_LOW_SPEED_TIME > LowSpeedTime;
  520. typedef cURLpp::OptionTrait< long,
  521. cURL::CURLOPT_MAXCONNECTS > MaxConnects;
  522. typedef cURLpp::OptionTrait< cURL::curl_closepolicy,
  523. cURL::CURLOPT_CLOSEPOLICY > ClosePolicy;
  524. typedef cURLpp::OptionTrait< bool,
  525. cURL::CURLOPT_FRESH_CONNECT > FreshConnect;
  526. typedef cURLpp::OptionTrait< bool,
  527. cURL::CURLOPT_FORBID_REUSE > ForbidReuse;
  528. typedef cURLpp::OptionTrait< long,
  529. cURL::CURLOPT_CONNECTTIMEOUT > ConnectTimeout;
  530. #ifdef cURL::CURLOPT_IPRESOLVE
  531. typedef cURLpp::OptionTrait< long,
  532. cURL::CURLOPT_IPRESOLVE > IpResolve;
  533. #endif
  534. \end{verbatim}
  535. \subsubsection{SSL and security options}
  536. \begin{verbatim}
  537. typedef cURLpp::OptionTrait< std::string,
  538. cURL::CURLOPT_SSLCERT > SslCert;
  539. typedef cURLpp::OptionTrait< std::string,
  540. cURL::CURLOPT_SSLCERTTYPE > SslCertType;
  541. typedef cURLpp::OptionTrait< std::string,
  542. cURL::CURLOPT_SSLCERTPASSWD > SslCertPasswd;
  543. typedef cURLpp::OptionTrait< std::string,
  544. cURL::CURLOPT_SSLKEY > SslKey;
  545. typedef cURLpp::OptionTrait< std::string,
  546. cURL::CURLOPT_SSLKEYTYPE > SslKeyType;
  547. typedef cURLpp::OptionTrait< std::string,
  548. cURL::CURLOPT_SSLKEYPASSWD > SslKeyPasswd;
  549. typedef cURLpp::OptionTrait< std::string,
  550. cURL::CURLOPT_SSLENGINE > SslEngine;
  551. typedef cURLpp::OptionTrait< long,
  552. cURL::CURLOPT_SSLVERSION > SslVersion;
  553. typedef cURLpp::OptionTrait< bool,
  554. cURL::CURLOPT_SSL_VERIFYPEER > SslVerifyPeer;
  555. typedef cURLpp::OptionTrait< std::string,
  556. cURL::CURLOPT_CAINFO > CaInfo;
  557. typedef cURLpp::OptionTrait< std::string,
  558. cURL::CURLOPT_CAPATH > CaPath;
  559. typedef cURLpp::OptionTrait< std::string,
  560. cURL::CURLOPT_RANDOM_FILE > RandomFile;
  561. typedef cURLpp::OptionTrait< std::string,
  562. cURL::CURLOPT_EGDSOCKET > EgdSocket;
  563. typedef cURLpp::OptionTrait< long,
  564. cURL::CURLOPT_SSL_VERIFYHOST > SslVerifyHost;
  565. typedef cURLpp::OptionTrait< std::string,
  566. cURL::CURLOPT_SSL_CIPHER_LIST > SslCipherList;
  567. typedef cURLpp::OptionTrait< std::string,
  568. cURL::CURLOPT_KRB4LEVEL > Krb4Level;
  569. \end{verbatim}
  570. \subsubsection{Others options}
  571. \begin{verbatim}
  572. typedef cURLpp::OptionTrait< std::string,
  573. cURL::CURLOPT_KRB4LEVEL > Krb4Level;
  574. \end{verbatim}
  575. \section{How the enhance cURLpp}
  576. Need to be written.
  577. \section{Exceptions issues}
  578. As previously said, cURLpp (libcurl in fact) offer the possibility to reimplement the data
  579. writing/reading functions. Those functions called from within libcurl might
  580. raise exceptions. Raising an exception in C code might cause problems. cURLpp
  581. protect you from doing so\footnote{This feature will be added only in the
  582. 0.6.0 version}. All exceptions are caught by cURLpp before they could
  583. cause damage to libcurl. If you want to raise an exception within traits, you need
  584. to do this:
  585. \begin{verbatim}
  586. cURLpp::raiseException(MyException(``Exception Raised'');
  587. \end{verbatim}
  588. Then, the \verb+cURLpp::Easy::perform()+ will raise your exception at the end of
  589. the process. If an exception is raised but not by this mechanism, a
  590. \verb+cURLpp::UnknownExceptionError+ will be raised.
  591. \end{document}