CURLOPT_NOSIGNAL might be a MUST to make threaded use work, like on AIX 5.2
[platform/upstream/curl.git] / docs / libcurl / libcurl-tutorial.3
1 .\" **************************************************************************
2 .\" *                                  _   _ ____  _
3 .\" *  Project                     ___| | | |  _ \| |
4 .\" *                             / __| | | | |_) | |
5 .\" *                            | (__| |_| |  _ <| |___
6 .\" *                             \___|\___/|_| \_\_____|
7 .\" *
8 .\" * Copyright (C) 1998 - 2006, 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 .\" * $Id$
22 .\" **************************************************************************
23 .\"
24 .TH libcurl-tutorial 3 "9 May 2005" "libcurl" "libcurl programming"
25 .SH NAME
26 libcurl-tutorial \- libcurl programming tutorial
27 .SH "Objective"
28 This document attempts to describe the general principles and some basic
29 approaches to consider when programming with libcurl. The text will focus
30 mainly on the C interface but might apply fairly well on other interfaces as
31 well as they usually follow the C one pretty closely.
32
33 This document will refer to 'the user' as the person writing the source code
34 that uses libcurl. That would probably be you or someone in your position.
35 What will be generally referred to as 'the program' will be the collected
36 source code that you write that is using libcurl for transfers. The program
37 is outside libcurl and libcurl is outside of the program.
38
39 To get the more details on all options and functions described herein, please
40 refer to their respective man pages.
41
42 .SH "Building"
43 There are many different ways to build C programs. This chapter will assume a
44 unix-style build process. If you use a different build system, you can still
45 read this to get general information that may apply to your environment as
46 well.
47 .IP "Compiling the Program"
48 Your compiler needs to know where the libcurl headers are located. Therefore
49 you must set your compiler's include path to point to the directory where you
50 installed them. The 'curl-config'[3] tool can be used to get this information:
51
52 $ curl-config --cflags
53
54 .IP "Linking the Program with libcurl"
55 When having compiled the program, you need to link your object files to create
56 a single executable. For that to succeed, you need to link with libcurl and
57 possibly also with other libraries that libcurl itself depends on. Like the
58 OpenSSL libraries, but even some standard OS libraries may be needed on the
59 command line. To figure out which flags to use, once again the 'curl-config'
60 tool comes to the rescue:
61
62 $ curl-config --libs
63
64 .IP "SSL or Not"
65 libcurl can be built and customized in many ways. One of the things that
66 varies from different libraries and builds is the support for SSL-based
67 transfers, like HTTPS and FTPS. If OpenSSL was detected properly at
68 build-time, libcurl will be built with SSL support. To figure out if an
69 installed libcurl has been built with SSL support enabled, use 'curl-config'
70 like this:
71
72 $ curl-config --feature
73
74 And if SSL is supported, the keyword 'SSL' will be written to stdout,
75 possibly together with a few other features that can be on and off on
76 different libcurls.
77
78 See also the "Features libcurl Provides" further down.
79 .IP "autoconf macro"
80 When you write your configure script to detect libcurl and setup variables
81 accordingly, we offer a prewritten macro that probably does everything you
82 need in this area. See docs/libcurl/libcurl.m4 file - it includes docs on how
83 to use it.
84
85 .SH "Portable Code in a Portable World"
86 The people behind libcurl have put a considerable effort to make libcurl work
87 on a large amount of different operating systems and environments.
88
89 You program libcurl the same way on all platforms that libcurl runs on. There
90 are only very few minor considerations that differs. If you just make sure to
91 write your code portable enough, you may very well create yourself a very
92 portable program. libcurl shouldn't stop you from that.
93
94 .SH "Global Preparation"
95 The program must initialize some of the libcurl functionality globally. That
96 means it should be done exactly once, no matter how many times you intend to
97 use the library. Once for your program's entire life time. This is done using
98
99  curl_global_init()
100
101 and it takes one parameter which is a bit pattern that tells libcurl what to
102 initialize. Using \fICURL_GLOBAL_ALL\fP will make it initialize all known
103 internal sub modules, and might be a good default option. The current two bits
104 that are specified are:
105 .RS
106 .IP "CURL_GLOBAL_WIN32"
107 which only does anything on Windows machines. When used on
108 a Windows machine, it'll make libcurl initialize the win32 socket
109 stuff. Without having that initialized properly, your program cannot use
110 sockets properly. You should only do this once for each application, so if
111 your program already does this or of another library in use does it, you
112 should not tell libcurl to do this as well.
113 .IP CURL_GLOBAL_SSL
114 which only does anything on libcurls compiled and built
115 SSL-enabled. On these systems, this will make libcurl initialize OpenSSL
116 properly for this application. This is only needed to do once for each
117 application so if your program or another library already does this, this
118 bit should not be needed.
119 .RE
120
121 libcurl has a default protection mechanism that detects if
122 \fIcurl_global_init(3)\fP hasn't been called by the time
123 \fIcurl_easy_perform(3)\fP is called and if that is the case, libcurl runs the
124 function itself with a guessed bit pattern. Please note that depending solely
125 on this is not considered nice nor very good.
126
127 When the program no longer uses libcurl, it should call
128 \fIcurl_global_cleanup(3)\fP, which is the opposite of the init call. It will
129 then do the reversed operations to cleanup the resources the
130 \fIcurl_global_init(3)\fP call initialized.
131
132 Repeated calls to \fIcurl_global_init(3)\fP and \fIcurl_global_cleanup(3)\fP
133 should be avoided. They should only be called once each.
134
135 .SH "Features libcurl Provides"
136 It is considered best-practice to determine libcurl features run-time rather
137 than build-time (if possible of course). By calling curl_version_info() and
138 checking tout he details of the returned struct, your program can figure out
139 exactly what the currently running libcurl supports.
140
141 .SH "Handle the Easy libcurl"
142 libcurl first introduced the so called easy interface. All operations in the
143 easy interface are prefixed with 'curl_easy'.
144
145 Recent libcurl versions also offer the multi interface. More about that
146 interface, what it is targeted for and how to use it is detailed in a separate
147 chapter further down. You still need to understand the easy interface first,
148 so please continue reading for better understanding.
149
150 To use the easy interface, you must first create yourself an easy handle. You
151 need one handle for each easy session you want to perform. Basically, you
152 should use one handle for every thread you plan to use for transferring. You
153 must never share the same handle in multiple threads.
154
155 Get an easy handle with
156
157  easyhandle = curl_easy_init();
158
159 It returns an easy handle. Using that you proceed to the next step: setting
160 up your preferred actions. A handle is just a logic entity for the upcoming
161 transfer or series of transfers.
162
163 You set properties and options for this handle using
164 \fIcurl_easy_setopt(3)\fP. They control how the subsequent transfer or
165 transfers will be made. Options remain set in the handle until set again to
166 something different. Alas, multiple requests using the same handle will use
167 the same options.
168
169 Many of the options you set in libcurl are "strings", pointers to data
170 terminated with a zero byte. Keep in mind that when you set strings with
171 \fIcurl_easy_setopt(3)\fP, libcurl will not copy the data. It will merely
172 point to the data. You MUST make sure that the data remains available for
173 libcurl to use until finished or until you use the same option again to point
174 to something else.
175
176 One of the most basic properties to set in the handle is the URL. You set
177 your preferred URL to transfer with CURLOPT_URL in a manner similar to:
178
179 .nf
180  curl_easy_setopt(handle, CURLOPT_URL, "http://domain.com/");
181 .fi
182
183 Let's assume for a while that you want to receive data as the URL identifies a
184 remote resource you want to get here. Since you write a sort of application
185 that needs this transfer, I assume that you would like to get the data passed
186 to you directly instead of simply getting it passed to stdout. So, you write
187 your own function that matches this prototype:
188
189  size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp);
190
191 You tell libcurl to pass all data to this function by issuing a function
192 similar to this:
193
194  curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, write_data);
195
196 You can control what data your function get in the forth argument by setting
197 another property:
198
199  curl_easy_setopt(easyhandle, CURLOPT_WRITEDATA, &internal_struct);
200
201 Using that property, you can easily pass local data between your application
202 and the function that gets invoked by libcurl. libcurl itself won't touch the
203 data you pass with \fICURLOPT_WRITEDATA\fP.
204
205 libcurl offers its own default internal callback that'll take care of the data
206 if you don't set the callback with \fICURLOPT_WRITEFUNCTION\fP. It will then
207 simply output the received data to stdout. You can have the default callback
208 write the data to a different file handle by passing a 'FILE *' to a file
209 opened for writing with the \fICURLOPT_WRITEDATA\fP option.
210
211 Now, we need to take a step back and have a deep breath. Here's one of those
212 rare platform-dependent nitpicks. Did you spot it? On some platforms[2],
213 libcurl won't be able to operate on files opened by the program. Thus, if you
214 use the default callback and pass in a an open file with
215 \fICURLOPT_WRITEDATA\fP, it will crash. You should therefore avoid this to
216 make your program run fine virtually everywhere.
217
218 (\fICURLOPT_WRITEDATA\fP was formerly known as \fICURLOPT_FILE\fP. Both names
219 still work and do the same thing).
220
221 If you're using libcurl as a win32 DLL, you MUST use the
222 \fICURLOPT_WRITEFUNCTION\fP if you set \fICURLOPT_WRITEDATA\fP - or you will
223 experience crashes.
224
225 There are of course many more options you can set, and we'll get back to a few
226 of them later. Let's instead continue to the actual transfer:
227
228  success = curl_easy_perform(easyhandle);
229
230 \fIcurl_easy_perform(3)\fP will connect to the remote site, do the necessary
231 commands and receive the transfer. Whenever it receives data, it calls the
232 callback function we previously set. The function may get one byte at a time,
233 or it may get many kilobytes at once. libcurl delivers as much as possible as
234 often as possible. Your callback function should return the number of bytes it
235 \&"took care of". If that is not the exact same amount of bytes that was
236 passed to it, libcurl will abort the operation and return with an error code.
237
238 When the transfer is complete, the function returns a return code that informs
239 you if it succeeded in its mission or not. If a return code isn't enough for
240 you, you can use the CURLOPT_ERRORBUFFER to point libcurl to a buffer of yours
241 where it'll store a human readable error message as well.
242
243 If you then want to transfer another file, the handle is ready to be used
244 again. Mind you, it is even preferred that you re-use an existing handle if
245 you intend to make another transfer. libcurl will then attempt to re-use the
246 previous connection.
247
248 .SH "Multi-threading Issues"
249 The first basic rule is that you must \fBnever\fP share a libcurl handle (be
250 it easy or multi or whatever) between multiple threads. Only use one handle in
251 one thread at a time.
252
253 libcurl is completely thread safe, except for two issues: signals and SSL/TLS
254 handlers. Signals are used timeouting name resolves (during DNS lookup) - when
255 built without c-ares support and not on Windows..
256
257 If you are accessing HTTPS or FTPS URLs in a multi-threaded manner, you are
258 then of course using OpenSSL/GnuTLS multi-threaded and those libs have their
259 own requirements on this issue. Basically, you need to provide one or two
260 functions to allow it to function properly. For all details, see this:
261
262 OpenSSL
263
264    http://www.openssl.org/docs/crypto/threads.html#DESCRIPTION
265
266 GnuTLS
267
268  http://www.gnu.org/software/gnutls/manual/html_node/Multi_002dthreaded-applications.html
269
270 When using multiple threads you should set the CURLOPT_NOSIGNAL option to TRUE
271 for all handles. Everything will or might work fine except that timeouts are
272 not honored during the DNS lookup - which you can work around by building
273 libcurl with c-ares support. c-ares is a library that provides asynchronous
274 name resolves. Unfortunately, c-ares does not yet fully support IPv6. On some
275 platforms, libcurl simply will not function properly multi-threaded unless
276 this option is set.
277
278 Also, note that CURLOPT_DNS_USE_GLOBAL_CACHE is not thread-safe.
279
280 .SH "When It Doesn't Work"
281 There will always be times when the transfer fails for some reason. You might
282 have set the wrong libcurl option or misunderstood what the libcurl option
283 actually does, or the remote server might return non-standard replies that
284 confuse the library which then confuses your program.
285
286 There's one golden rule when these things occur: set the CURLOPT_VERBOSE
287 option to TRUE. It'll cause the library to spew out the entire protocol
288 details it sends, some internal info and some received protocol data as well
289 (especially when using FTP). If you're using HTTP, adding the headers in the
290 received output to study is also a clever way to get a better understanding
291 why the server behaves the way it does. Include headers in the normal body
292 output with CURLOPT_HEADER set TRUE.
293
294 Of course there are bugs left. We need to get to know about them to be able
295 to fix them, so we're quite dependent on your bug reports! When you do report
296 suspected bugs in libcurl, please include as much details you possibly can: a
297 protocol dump that CURLOPT_VERBOSE produces, library version, as much as
298 possible of your code that uses libcurl, operating system name and version,
299 compiler name and version etc.
300
301 If CURLOPT_VERBOSE is not enough, you increase the level of debug data your
302 application receive by using the CURLOPT_DEBUGFUNCTION.
303
304 Getting some in-depth knowledge about the protocols involved is never wrong,
305 and if you're trying to do funny things, you might very well understand
306 libcurl and how to use it better if you study the appropriate RFC documents
307 at least briefly.
308
309 .SH "Upload Data to a Remote Site"
310 libcurl tries to keep a protocol independent approach to most transfers, thus
311 uploading to a remote FTP site is very similar to uploading data to a HTTP
312 server with a PUT request.
313
314 Of course, first you either create an easy handle or you re-use one existing
315 one. Then you set the URL to operate on just like before. This is the remote
316 URL, that we now will upload.
317
318 Since we write an application, we most likely want libcurl to get the upload
319 data by asking us for it. To make it do that, we set the read callback and
320 the custom pointer libcurl will pass to our read callback. The read callback
321 should have a prototype similar to:
322
323  size_t function(char *bufptr, size_t size, size_t nitems, void *userp);
324
325 Where bufptr is the pointer to a buffer we fill in with data to upload and
326 size*nitems is the size of the buffer and therefore also the maximum amount
327 of data we can return to libcurl in this call. The 'userp' pointer is the
328 custom pointer we set to point to a struct of ours to pass private data
329 between the application and the callback.
330
331  curl_easy_setopt(easyhandle, CURLOPT_READFUNCTION, read_function);
332
333  curl_easy_setopt(easyhandle, CURLOPT_INFILE, &filedata);
334
335 Tell libcurl that we want to upload:
336
337  curl_easy_setopt(easyhandle, CURLOPT_UPLOAD, TRUE);
338
339 A few protocols won't behave properly when uploads are done without any prior
340 knowledge of the expected file size. So, set the upload file size using the
341 CURLOPT_INFILESIZE_LARGE for all known file sizes like this[1]:
342
343 .nf
344  /* in this example, file_size must be an off_t variable */
345  curl_easy_setopt(easyhandle, CURLOPT_INFILESIZE_LARGE, file_size);
346 .fi
347
348 When you call \fIcurl_easy_perform(3)\fP this time, it'll perform all the
349 necessary operations and when it has invoked the upload it'll call your
350 supplied callback to get the data to upload. The program should return as much
351 data as possible in every invoke, as that is likely to make the upload perform
352 as fast as possible. The callback should return the number of bytes it wrote
353 in the buffer. Returning 0 will signal the end of the upload.
354
355 .SH "Passwords"
356 Many protocols use or even require that user name and password are provided
357 to be able to download or upload the data of your choice. libcurl offers
358 several ways to specify them.
359
360 Most protocols support that you specify the name and password in the URL
361 itself. libcurl will detect this and use them accordingly. This is written
362 like this:
363
364  protocol://user:password@example.com/path/
365
366 If you need any odd letters in your user name or password, you should enter
367 them URL encoded, as %XX where XX is a two-digit hexadecimal number.
368
369 libcurl also provides options to set various passwords. The user name and
370 password as shown embedded in the URL can instead get set with the
371 CURLOPT_USERPWD option. The argument passed to libcurl should be a char * to
372 a string in the format "user:password:". In a manner like this:
373
374  curl_easy_setopt(easyhandle, CURLOPT_USERPWD, "myname:thesecret");
375
376 Another case where name and password might be needed at times, is for those
377 users who need to authenticate themselves to a proxy they use. libcurl offers
378 another option for this, the CURLOPT_PROXYUSERPWD. It is used quite similar
379 to the CURLOPT_USERPWD option like this:
380
381  curl_easy_setopt(easyhandle, CURLOPT_PROXYUSERPWD, "myname:thesecret");
382  
383 There's a long time unix "standard" way of storing ftp user names and
384 passwords, namely in the $HOME/.netrc file. The file should be made private
385 so that only the user may read it (see also the "Security Considerations"
386 chapter), as it might contain the password in plain text. libcurl has the
387 ability to use this file to figure out what set of user name and password to
388 use for a particular host. As an extension to the normal functionality,
389 libcurl also supports this file for non-FTP protocols such as HTTP. To make
390 curl use this file, use the CURLOPT_NETRC option:
391
392  curl_easy_setopt(easyhandle, CURLOPT_NETRC, TRUE);
393
394 And a very basic example of how such a .netrc file may look like:
395
396 .nf
397  machine myhost.mydomain.com
398  login userlogin
399  password secretword
400 .fi
401
402 All these examples have been cases where the password has been optional, or
403 at least you could leave it out and have libcurl attempt to do its job
404 without it. There are times when the password isn't optional, like when
405 you're using an SSL private key for secure transfers.
406
407 To pass the known private key password to libcurl:
408
409  curl_easy_setopt(easyhandle, CURLOPT_SSLKEYPASSWD, "keypassword");
410
411 .SH "HTTP Authentication"
412 The previous chapter showed how to set user name and password for getting
413 URLs that require authentication. When using the HTTP protocol, there are
414 many different ways a client can provide those credentials to the server and
415 you can control what way libcurl will (attempt to) use. The default HTTP
416 authentication method is called 'Basic', which is sending the name and
417 password in clear-text in the HTTP request, base64-encoded. This is insecure.
418
419 At the time of this writing libcurl can be built to use: Basic, Digest, NTLM,
420 Negotiate, GSS-Negotiate and SPNEGO. You can tell libcurl which one to use
421 with CURLOPT_HTTPAUTH as in:
422
423  curl_easy_setopt(easyhandle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
424
425 And when you send authentication to a proxy, you can also set authentication
426 type the same way but instead with CURLOPT_PROXYAUTH:
427
428  curl_easy_setopt(easyhandle, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
429
430 Both these options allow you to set multiple types (by ORing them together),
431 to make libcurl pick the most secure one out of the types the server/proxy
432 claims to support. This method does however add a round-trip since libcurl
433 must first ask the server what it supports:
434
435  curl_easy_setopt(easyhandle, CURLOPT_HTTPAUTH,
436  CURLAUTH_DIGEST|CURLAUTH_BASIC);
437
438 For convenience, you can use the 'CURLAUTH_ANY' define (instead of a list
439 with specific types) which allows libcurl to use whatever method it wants.
440
441 When asking for multiple types, libcurl will pick the available one it
442 considers "best" in its own internal order of preference.
443
444 .SH "HTTP POSTing"
445 We get many questions regarding how to issue HTTP POSTs with libcurl the
446 proper way. This chapter will thus include examples using both different
447 versions of HTTP POST that libcurl supports.
448
449 The first version is the simple POST, the most common version, that most HTML
450 pages using the <form> tag uses. We provide a pointer to the data and tell
451 libcurl to post it all to the remote site:
452
453 .nf
454     char *data="name=daniel&project=curl";
455     curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, data);
456     curl_easy_setopt(easyhandle, CURLOPT_URL, "http://posthere.com/");
457
458     curl_easy_perform(easyhandle); /* post away! */
459 .fi
460
461 Simple enough, huh? Since you set the POST options with the
462 CURLOPT_POSTFIELDS, this automatically switches the handle to use POST in the
463 upcoming request.
464
465 Ok, so what if you want to post binary data that also requires you to set the
466 Content-Type: header of the post? Well, binary posts prevents libcurl from
467 being able to do strlen() on the data to figure out the size, so therefore we
468 must tell libcurl the size of the post data. Setting headers in libcurl
469 requests are done in a generic way, by building a list of our own headers and
470 then passing that list to libcurl.
471
472 .nf
473  struct curl_slist *headers=NULL;
474  headers = curl_slist_append(headers, "Content-Type: text/xml");
475
476  /* post binary data */
477  curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, binaryptr);
478
479  /* set the size of the postfields data */
480  curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDSIZE, 23);
481
482  /* pass our list of custom made headers */
483  curl_easy_setopt(easyhandle, CURLOPT_HTTPHEADER, headers);
484
485  curl_easy_perform(easyhandle); /* post away! */
486
487  curl_slist_free_all(headers); /* free the header list */
488 .fi
489
490 While the simple examples above cover the majority of all cases where HTTP
491 POST operations are required, they don't do multi-part formposts. Multi-part
492 formposts were introduced as a better way to post (possibly large) binary data
493 and was first documented in the RFC1867. They're called multi-part because
494 they're built by a chain of parts, each being a single unit. Each part has its
495 own name and contents. You can in fact create and post a multi-part formpost
496 with the regular libcurl POST support described above, but that would require
497 that you build a formpost yourself and provide to libcurl. To make that
498 easier, libcurl provides \fIcurl_formadd(3)\fP. Using this function, you add
499 parts to the form. When you're done adding parts, you post the whole form.
500
501 The following example sets two simple text parts with plain textual contents,
502 and then a file with binary contents and upload the whole thing.
503
504 .nf
505  struct curl_httppost *post=NULL;
506  struct curl_httppost *last=NULL;
507  curl_formadd(&post, &last,
508               CURLFORM_COPYNAME, "name",
509               CURLFORM_COPYCONTENTS, "daniel", CURLFORM_END);
510  curl_formadd(&post, &last,
511               CURLFORM_COPYNAME, "project",
512               CURLFORM_COPYCONTENTS, "curl", CURLFORM_END);
513  curl_formadd(&post, &last,
514               CURLFORM_COPYNAME, "logotype-image",
515               CURLFORM_FILECONTENT, "curl.png", CURLFORM_END);
516
517  /* Set the form info */
518  curl_easy_setopt(easyhandle, CURLOPT_HTTPPOST, post);
519
520  curl_easy_perform(easyhandle); /* post away! */
521
522  /* free the post data again */
523  curl_formfree(post);
524 .fi
525
526 Multipart formposts are chains of parts using MIME-style separators and
527 headers. It means that each one of these separate parts get a few headers set
528 that describe the individual content-type, size etc. To enable your
529 application to handicraft this formpost even more, libcurl allows you to
530 supply your own set of custom headers to such an individual form part. You can
531 of course supply headers to as many parts you like, but this little example
532 will show how you set headers to one specific part when you add that to the
533 post handle:
534
535 .nf
536  struct curl_slist *headers=NULL;
537  headers = curl_slist_append(headers, "Content-Type: text/xml");
538
539  curl_formadd(&post, &last,
540               CURLFORM_COPYNAME, "logotype-image",
541               CURLFORM_FILECONTENT, "curl.xml",
542               CURLFORM_CONTENTHEADER, headers,
543               CURLFORM_END);
544
545  curl_easy_perform(easyhandle); /* post away! */
546
547  curl_formfree(post); /* free post */
548  curl_slist_free_all(post); /* free custom header list */
549 .fi
550
551 Since all options on an easyhandle are "sticky", they remain the same until
552 changed even if you do call \fIcurl_easy_perform(3)\fP, you may need to tell
553 curl to go back to a plain GET request if you intend to do such a one as your
554 next request. You force an easyhandle to back to GET by using the
555 CURLOPT_HTTPGET option:
556
557  curl_easy_setopt(easyhandle, CURLOPT_HTTPGET, TRUE);
558
559 Just setting CURLOPT_POSTFIELDS to "" or NULL will *not* stop libcurl from
560 doing a POST. It will just make it POST without any data to send!
561
562 .SH "Showing Progress"
563
564 For historical and traditional reasons, libcurl has a built-in progress meter
565 that can be switched on and then makes it presents a progress meter in your
566 terminal.
567
568 Switch on the progress meter by, oddly enough, set CURLOPT_NOPROGRESS to
569 FALSE. This option is set to TRUE by default.
570
571 For most applications however, the built-in progress meter is useless and
572 what instead is interesting is the ability to specify a progress
573 callback. The function pointer you pass to libcurl will then be called on
574 irregular intervals with information about the current transfer.
575
576 Set the progress callback by using CURLOPT_PROGRESSFUNCTION. And pass a
577 pointer to a function that matches this prototype:
578
579 .nf
580  int progress_callback(void *clientp,
581                        double dltotal,
582                        double dlnow,
583                        double ultotal,
584                        double ulnow);
585 .fi
586
587 If any of the input arguments is unknown, a 0 will be passed. The first
588 argument, the 'clientp' is the pointer you pass to libcurl with
589 CURLOPT_PROGRESSDATA. libcurl won't touch it.
590
591 .SH "libcurl with C++"
592
593 There's basically only one thing to keep in mind when using C++ instead of C
594 when interfacing libcurl:
595
596 The callbacks CANNOT be non-static class member functions
597
598 Example C++ code:
599
600 .nf
601 class AClass {
602     static size_t write_data(void *ptr, size_t size, size_t nmemb,
603                              void *ourpointer)
604     {
605       /* do what you want with the data */
606     }
607  }
608 .fi
609
610 .SH "Proxies"
611
612 What "proxy" means according to Merriam-Webster: "a person authorized to act
613 for another" but also "the agency, function, or office of a deputy who acts as
614 a substitute for another".
615
616 Proxies are exceedingly common these days. Companies often only offer
617 Internet access to employees through their HTTP proxies. Network clients or
618 user-agents ask the proxy for documents, the proxy does the actual request
619 and then it returns them.
620
621 libcurl has full support for HTTP proxies, so when a given URL is wanted,
622 libcurl will ask the proxy for it instead of trying to connect to the actual
623 host identified in the URL.
624
625 The fact that the proxy is a HTTP proxy puts certain restrictions on what can
626 actually happen. A requested URL that might not be a HTTP URL will be still
627 be passed to the HTTP proxy to deliver back to libcurl. This happens
628 transparently, and an application may not need to know. I say "may", because
629 at times it is very important to understand that all operations over a HTTP
630 proxy is using the HTTP protocol. For example, you can't invoke your own
631 custom FTP commands or even proper FTP directory listings.
632
633 .IP "Proxy Options"
634
635 To tell libcurl to use a proxy at a given port number:
636
637  curl_easy_setopt(easyhandle, CURLOPT_PROXY, "proxy-host.com:8080");
638
639 Some proxies require user authentication before allowing a request, and you
640 pass that information similar to this:
641
642  curl_easy_setopt(easyhandle, CURLOPT_PROXYUSERPWD, "user:password");
643
644 If you want to, you can specify the host name only in the CURLOPT_PROXY
645 option, and set the port number separately with CURLOPT_PROXYPORT.
646
647 .IP "Environment Variables"
648
649 libcurl automatically checks and uses a set of environment variables to
650 know what proxies to use for certain protocols. The names of the variables
651 are following an ancient de facto standard and are built up as
652 "[protocol]_proxy" (note the lower casing). Which makes the variable
653 'http_proxy' checked for a name of a proxy to use when the input URL is
654 HTTP. Following the same rule, the variable named 'ftp_proxy' is checked
655 for FTP URLs. Again, the proxies are always HTTP proxies, the different
656 names of the variables simply allows different HTTP proxies to be used.
657
658 The proxy environment variable contents should be in the format
659 \&"[protocol://][user:password@]machine[:port]". Where the protocol:// part is
660 simply ignored if present (so http://proxy and bluerk://proxy will do the
661 same) and the optional port number specifies on which port the proxy operates
662 on the host. If not specified, the internal default port number will be used
663 and that is most likely *not* the one you would like it to be.
664
665 There are two special environment variables. 'all_proxy' is what sets proxy
666 for any URL in case the protocol specific variable wasn't set, and
667 \&'no_proxy' defines a list of hosts that should not use a proxy even though a
668 variable may say so. If 'no_proxy' is a plain asterisk ("*") it matches all
669 hosts.
670
671 .IP "SSL and Proxies"
672
673 SSL is for secure point-to-point connections. This involves strong encryption
674 and similar things, which effectively makes it impossible for a proxy to
675 operate as a "man in between" which the proxy's task is, as previously
676 discussed. Instead, the only way to have SSL work over a HTTP proxy is to ask
677 the proxy to tunnel trough everything without being able to check or fiddle
678 with the traffic.
679
680 Opening an SSL connection over a HTTP proxy is therefor a matter of asking the
681 proxy for a straight connection to the target host on a specified port. This
682 is made with the HTTP request CONNECT. ("please mr proxy, connect me to that
683 remote host").
684
685 Because of the nature of this operation, where the proxy has no idea what kind
686 of data that is passed in and out through this tunnel, this breaks some of the
687 very few advantages that come from using a proxy, such as caching.  Many
688 organizations prevent this kind of tunneling to other destination port numbers
689 than 443 (which is the default HTTPS port number).
690
691 .IP "Tunneling Through Proxy"
692 As explained above, tunneling is required for SSL to work and often even
693 restricted to the operation intended for SSL; HTTPS.
694
695 This is however not the only time proxy-tunneling might offer benefits to
696 you or your application.
697
698 As tunneling opens a direct connection from your application to the remote
699 machine, it suddenly also re-introduces the ability to do non-HTTP
700 operations over a HTTP proxy. You can in fact use things such as FTP
701 upload or FTP custom commands this way.
702
703 Again, this is often prevented by the administrators of proxies and is
704 rarely allowed.
705
706 Tell libcurl to use proxy tunneling like this:
707
708  curl_easy_setopt(easyhandle, CURLOPT_HTTPPROXYTUNNEL, TRUE);
709
710 In fact, there might even be times when you want to do plain HTTP
711 operations using a tunnel like this, as it then enables you to operate on
712 the remote server instead of asking the proxy to do so. libcurl will not
713 stand in the way for such innovative actions either!
714
715 .IP "Proxy Auto-Config"
716
717 Netscape first came up with this. It is basically a web page (usually using a
718 \&.pac extension) with a javascript that when executed by the browser with the
719 requested URL as input, returns information to the browser on how to connect
720 to the URL. The returned information might be "DIRECT" (which means no proxy
721 should be used), "PROXY host:port" (to tell the browser where the proxy for
722 this particular URL is) or "SOCKS host:port" (to direct the browser to a SOCKS
723 proxy).
724
725 libcurl has no means to interpret or evaluate javascript and thus it doesn't
726 support this. If you get yourself in a position where you face this nasty
727 invention, the following advice have been mentioned and used in the past:
728
729 - Depending on the javascript complexity, write up a script that translates it
730 to another language and execute that.
731
732 - Read the javascript code and rewrite the same logic in another language.
733
734 - Implement a javascript interpreted, people have successfully used the
735 Mozilla javascript engine in the past.
736
737 - Ask your admins to stop this, for a static proxy setup or similar.
738
739 .SH "Persistence Is The Way to Happiness"
740
741 Re-cycling the same easy handle several times when doing multiple requests is
742 the way to go.
743
744 After each single \fIcurl_easy_perform(3)\fP operation, libcurl will keep the
745 connection alive and open. A subsequent request using the same easy handle to
746 the same host might just be able to use the already open connection! This
747 reduces network impact a lot.
748
749 Even if the connection is dropped, all connections involving SSL to the same
750 host again, will benefit from libcurl's session ID cache that drastically
751 reduces re-connection time.
752
753 FTP connections that are kept alive saves a lot of time, as the command-
754 response round-trips are skipped, and also you don't risk getting blocked
755 without permission to login again like on many FTP servers only allowing N
756 persons to be logged in at the same time.
757
758 libcurl caches DNS name resolving results, to make lookups of a previously
759 looked up name a lot faster.
760
761 Other interesting details that improve performance for subsequent requests
762 may also be added in the future.
763
764 Each easy handle will attempt to keep the last few connections alive for a
765 while in case they are to be used again. You can set the size of this "cache"
766 with the CURLOPT_MAXCONNECTS option. Default is 5. It is very seldom any
767 point in changing this value, and if you think of changing this it is often
768 just a matter of thinking again.
769
770 When the connection cache gets filled, libcurl must close an existing
771 connection in order to get room for the new one. To know which connection to
772 close, libcurl uses a "close policy" that you can affect with the
773 CURLOPT_CLOSEPOLICY option. There's only two polices implemented as of this
774 writing (libcurl 7.9.4) and they are:
775
776 .RS
777 .IP CURLCLOSEPOLICY_LEAST_RECENTLY_USED
778 simply close the one that hasn't been used for the longest time. This is the
779 default behavior.
780 .IP CURLCLOSEPOLICY_OLDEST
781 closes the oldest connection, the one that was created the longest time ago.
782 .RE
783
784 There are, or at least were, plans to support a close policy that would call
785 a user-specified callback to let the user be able to decide which connection
786 to dump when this is necessary and therefor is the CURLOPT_CLOSEFUNCTION an
787 existing option still today. Nothing ever uses this though and this will not
788 be used within the foreseeable future either.
789
790 To force your upcoming request to not use an already existing connection (it
791 will even close one first if there happens to be one alive to the same host
792 you're about to operate on), you can do that by setting CURLOPT_FRESH_CONNECT
793 to TRUE. In a similar spirit, you can also forbid the upcoming request to be
794 "lying" around and possibly get re-used after the request by setting
795 CURLOPT_FORBID_REUSE to TRUE.
796
797 .SH "HTTP Headers Used by libcurl"
798 When you use libcurl to do HTTP requests, it'll pass along a series of headers
799 automatically. It might be good for you to know and understand these ones.
800
801 .IP "Host"
802 This header is required by HTTP 1.1 and even many 1.0 servers and should be
803 the name of the server we want to talk to. This includes the port number if
804 anything but default.
805
806 .IP "Pragma"
807 \&"no-cache". Tells a possible proxy to not grab a copy from the cache but to
808 fetch a fresh one.
809
810 .IP "Accept"
811 \&"*/*".
812
813 .IP "Expect:"
814 When doing multi-part formposts, libcurl will set this header to
815 \&"100-continue" to ask the server for an "OK" message before it proceeds with
816 sending the data part of the post.
817
818 .SH "Customizing Operations"
819 There is an ongoing development today where more and more protocols are built
820 upon HTTP for transport. This has obvious benefits as HTTP is a tested and
821 reliable protocol that is widely deployed and have excellent proxy-support.
822
823 When you use one of these protocols, and even when doing other kinds of
824 programming you may need to change the traditional HTTP (or FTP or...)
825 manners. You may need to change words, headers or various data.
826
827 libcurl is your friend here too.
828
829 .IP CUSTOMREQUEST
830 If just changing the actual HTTP request keyword is what you want, like when
831 GET, HEAD or POST is not good enough for you, CURLOPT_CUSTOMREQUEST is there
832 for you. It is very simple to use:
833
834  curl_easy_setopt(easyhandle, CURLOPT_CUSTOMREQUEST, "MYOWNRUQUEST");
835
836 When using the custom request, you change the request keyword of the actual
837 request you are performing. Thus, by default you make GET request but you can
838 also make a POST operation (as described before) and then replace the POST
839 keyword if you want to. You're the boss.
840
841 .IP "Modify Headers"
842 HTTP-like protocols pass a series of headers to the server when doing the
843 request, and you're free to pass any amount of extra headers that you
844 think fit. Adding headers are this easy:
845
846 .nf
847  struct curl_slist *headers=NULL; /* init to NULL is important */
848
849  headers = curl_slist_append(headers, "Hey-server-hey: how are you?");
850  headers = curl_slist_append(headers, "X-silly-content: yes");
851
852  /* pass our list of custom made headers */
853  curl_easy_setopt(easyhandle, CURLOPT_HTTPHEADER, headers);
854
855  curl_easy_perform(easyhandle); /* transfer http */
856
857  curl_slist_free_all(headers); /* free the header list */
858 .fi
859
860 \&... and if you think some of the internally generated headers, such as
861 Accept: or Host: don't contain the data you want them to contain, you can
862 replace them by simply setting them too:
863
864 .nf
865  headers = curl_slist_append(headers, "Accept: Agent-007");
866  headers = curl_slist_append(headers, "Host: munged.host.line");
867 .fi
868
869 .IP "Delete Headers"
870 If you replace an existing header with one with no contents, you will prevent
871 the header from being sent. Like if you want to completely prevent the
872 \&"Accept:" header to be sent, you can disable it with code similar to this:
873
874  headers = curl_slist_append(headers, "Accept:");
875
876 Both replacing and canceling internal headers should be done with careful
877 consideration and you should be aware that you may violate the HTTP protocol
878 when doing so.
879
880 .IP "Enforcing chunked transfer-encoding"
881
882 By making sure a request uses the custom header "Transfer-Encoding: chunked"
883 when doing a non-GET HTTP operation, libcurl will switch over to "chunked"
884 upload, even though the size of the data to upload might be known. By default,
885 libcurl usually switches over to chunked upload automatically if the upload
886 data size is unknown.
887
888 .IP "HTTP Version"
889
890 There's only one aspect left in the HTTP requests that we haven't yet
891 mentioned how to modify: the version field. All HTTP requests includes the
892 version number to tell the server which version we support. libcurl speak HTTP
893 1.1 by default. Some very old servers don't like getting 1.1-requests and when
894 dealing with stubborn old things like that, you can tell libcurl to use 1.0
895 instead by doing something like this:
896
897  curl_easy_setopt(easyhandle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
898
899 .IP "FTP Custom Commands"
900
901 Not all protocols are HTTP-like, and thus the above may not help you when
902 you want to make for example your FTP transfers to behave differently.
903
904 Sending custom commands to a FTP server means that you need to send the
905 commands exactly as the FTP server expects them (RFC959 is a good guide
906 here), and you can only use commands that work on the control-connection
907 alone. All kinds of commands that requires data interchange and thus needs
908 a data-connection must be left to libcurl's own judgment. Also be aware
909 that libcurl will do its very best to change directory to the target
910 directory before doing any transfer, so if you change directory (with CWD
911 or similar) you might confuse libcurl and then it might not attempt to
912 transfer the file in the correct remote directory.
913
914 A little example that deletes a given file before an operation:
915
916 .nf
917  headers = curl_slist_append(headers, "DELE file-to-remove");
918
919  /* pass the list of custom commands to the handle */
920  curl_easy_setopt(easyhandle, CURLOPT_QUOTE, headers);
921
922  curl_easy_perform(easyhandle); /* transfer ftp data! */
923
924  curl_slist_free_all(headers); /* free the header list */
925 .fi
926
927 If you would instead want this operation (or chain of operations) to happen
928 _after_ the data transfer took place the option to \fIcurl_easy_setopt(3)\fP
929 would instead be called CURLOPT_POSTQUOTE and used the exact same way.
930
931 The custom FTP command will be issued to the server in the same order they are
932 added to the list, and if a command gets an error code returned back from the
933 server, no more commands will be issued and libcurl will bail out with an
934 error code (CURLE_FTP_QUOTE_ERROR). Note that if you use CURLOPT_QUOTE to send
935 commands before a transfer, no transfer will actually take place when a quote
936 command has failed.
937
938 If you set the CURLOPT_HEADER to true, you will tell libcurl to get
939 information about the target file and output "headers" about it. The headers
940 will be in "HTTP-style", looking like they do in HTTP.
941
942 The option to enable headers or to run custom FTP commands may be useful to
943 combine with CURLOPT_NOBODY. If this option is set, no actual file content
944 transfer will be performed.
945
946 .IP "FTP Custom CUSTOMREQUEST"
947 If you do what list the contents of a FTP directory using your own defined FTP
948 command, CURLOPT_CUSTOMREQUEST will do just that. "NLST" is the default one
949 for listing directories but you're free to pass in your idea of a good
950 alternative.
951
952 .SH "Cookies Without Chocolate Chips"
953 In the HTTP sense, a cookie is a name with an associated value. A server sends
954 the name and value to the client, and expects it to get sent back on every
955 subsequent request to the server that matches the particular conditions
956 set. The conditions include that the domain name and path match and that the
957 cookie hasn't become too old.
958
959 In real-world cases, servers send new cookies to replace existing one to
960 update them. Server use cookies to "track" users and to keep "sessions".
961
962 Cookies are sent from server to clients with the header Set-Cookie: and
963 they're sent from clients to servers with the Cookie: header.
964
965 To just send whatever cookie you want to a server, you can use CURLOPT_COOKIE
966 to set a cookie string like this:
967
968  curl_easy_setopt(easyhandle, CURLOPT_COOKIE, "name1=var1; name2=var2;");
969
970 In many cases, that is not enough. You might want to dynamically save
971 whatever cookies the remote server passes to you, and make sure those cookies
972 are then use accordingly on later requests.
973
974 One way to do this, is to save all headers you receive in a plain file and
975 when you make a request, you tell libcurl to read the previous headers to
976 figure out which cookies to use. Set header file to read cookies from with
977 CURLOPT_COOKIEFILE.
978
979 The CURLOPT_COOKIEFILE option also automatically enables the cookie parser in
980 libcurl. Until the cookie parser is enabled, libcurl will not parse or
981 understand incoming cookies and they will just be ignored. However, when the
982 parser is enabled the cookies will be understood and the cookies will be kept
983 in memory and used properly in subsequent requests when the same handle is
984 used. Many times this is enough, and you may not have to save the cookies to
985 disk at all. Note that the file you specify to CURLOPT_COOKIEFILE doesn't
986 have to exist to enable the parser, so a common way to just enable the parser
987 and not read able might be to use a file name you know doesn't exist.
988
989 If you rather use existing cookies that you've previously received with your
990 Netscape or Mozilla browsers, you can make libcurl use that cookie file as
991 input. The CURLOPT_COOKIEFILE is used for that too, as libcurl will
992 automatically find out what kind of file it is and act accordingly.
993
994 The perhaps most advanced cookie operation libcurl offers, is saving the
995 entire internal cookie state back into a Netscape/Mozilla formatted cookie
996 file. We call that the cookie-jar. When you set a file name with
997 CURLOPT_COOKIEJAR, that file name will be created and all received cookies
998 will be stored in it when \fIcurl_easy_cleanup(3)\fP is called. This enabled
999 cookies to get passed on properly between multiple handles without any
1000 information getting lost.
1001
1002 .SH "FTP Peculiarities We Need"
1003
1004 FTP transfers use a second TCP/IP connection for the data transfer. This is
1005 usually a fact you can forget and ignore but at times this fact will come
1006 back to haunt you. libcurl offers several different ways to custom how the
1007 second connection is being made.
1008
1009 libcurl can either connect to the server a second time or tell the server to
1010 connect back to it. The first option is the default and it is also what works
1011 best for all the people behind firewalls, NATs or IP-masquerading setups.
1012 libcurl then tells the server to open up a new port and wait for a second
1013 connection. This is by default attempted with EPSV first, and if that doesn't
1014 work it tries PASV instead. (EPSV is an extension to the original FTP spec
1015 and does not exist nor work on all FTP servers.)
1016
1017 You can prevent libcurl from first trying the EPSV command by setting
1018 CURLOPT_FTP_USE_EPSV to FALSE.
1019
1020 In some cases, you will prefer to have the server connect back to you for the
1021 second connection. This might be when the server is perhaps behind a firewall
1022 or something and only allows connections on a single port. libcurl then
1023 informs the remote server which IP address and port number to connect to.
1024 This is made with the CURLOPT_FTPPORT option. If you set it to "-", libcurl
1025 will use your system's "default IP address". If you want to use a particular
1026 IP, you can set the full IP address, a host name to resolve to an IP address
1027 or even a local network interface name that libcurl will get the IP address
1028 from.
1029
1030 When doing the "PORT" approach, libcurl will attempt to use the EPRT and the
1031 LPRT before trying PORT, as they work with more protocols. You can disable
1032 this behavior by setting CURLOPT_FTP_USE_EPRT to FALSE.
1033
1034 .SH "Headers Equal Fun"
1035
1036 Some protocols provide "headers", meta-data separated from the normal
1037 data. These headers are by default not included in the normal data stream,
1038 but you can make them appear in the data stream by setting CURLOPT_HEADER to
1039 TRUE.
1040
1041 What might be even more useful, is libcurl's ability to separate the headers
1042 from the data and thus make the callbacks differ. You can for example set a
1043 different pointer to pass to the ordinary write callback by setting
1044 CURLOPT_WRITEHEADER.
1045
1046 Or, you can set an entirely separate function to receive the headers, by
1047 using CURLOPT_HEADERFUNCTION.
1048
1049 The headers are passed to the callback function one by one, and you can
1050 depend on that fact. It makes it easier for you to add custom header parsers
1051 etc.
1052
1053 "Headers" for FTP transfers equal all the FTP server responses. They aren't
1054 actually true headers, but in this case we pretend they are! ;-)
1055
1056 .SH "Post Transfer Information"
1057
1058  [ curl_easy_getinfo ]
1059
1060 .SH "Security Considerations"
1061
1062 libcurl is in itself not insecure. If used the right way, you can use libcurl
1063 to transfer data pretty safely.
1064
1065 There are of course many things to consider that may loosen up this
1066 situation:
1067
1068 .IP "Command Lines"
1069 If you use a command line tool (such as curl) that uses libcurl, and you give
1070 option to the tool on the command line those options can very likely get read
1071 by other users of your system when they use 'ps' or other tools to list
1072 currently running processes.
1073
1074 To avoid this problem, never feed sensitive things to programs using command
1075 line options.
1076
1077 .IP ".netrc"
1078 \&.netrc is a pretty handy file/feature that allows you to login quickly and
1079 automatically to frequently visited sites. The file contains passwords in
1080 clear text and is a real security risk. In some cases, your .netrc is also
1081 stored in a home directory that is NFS mounted or used on another network
1082 based file system, so the clear text password will fly through your network
1083 every time anyone reads that file!
1084
1085 To avoid this problem, don't use .netrc files and never store passwords in
1086 plain text anywhere.
1087
1088 .IP "Clear Text Passwords"
1089 Many of the protocols libcurl supports send name and password unencrypted as
1090 clear text (HTTP Basic authentication, FTP, TELNET etc). It is very easy for
1091 anyone on your network or a network nearby yours, to just fire up a network
1092 analyzer tool and eavesdrop on your passwords. Don't let the fact that HTTP
1093 uses base64 encoded passwords fool you. They may not look readable at a first
1094 glance, but they very easily "deciphered" by anyone within seconds.
1095
1096 To avoid this problem, use protocols that don't let snoopers see your
1097 password: HTTPS, FTPS and FTP-kerberos are a few examples. HTTP Digest
1098 authentication allows this too, but isn't supported by libcurl as of this
1099 writing.
1100
1101 .IP "Showing What You Do"
1102 On a related issue, be aware that even in situations like when you have
1103 problems with libcurl and ask someone for help, everything you reveal in order
1104 to get best possible help might also impose certain security related
1105 risks. Host names, user names, paths, operating system specifics etc (not to
1106 mention passwords of course) may in fact be used by intruders to gain
1107 additional information of a potential target.
1108
1109 To avoid this problem, you must of course use your common sense. Often, you
1110 can just edit out the sensitive data or just search/replace your true
1111 information with faked data.
1112
1113 .SH "Multiple Transfers Using the multi Interface"
1114
1115 The easy interface as described in detail in this document is a synchronous
1116 interface that transfers one file at a time and doesn't return until its
1117 done.
1118
1119 The multi interface on the other hand, allows your program to transfer
1120 multiple files in both directions at the same time, without forcing you to
1121 use multiple threads.
1122
1123 To use this interface, you are better off if you first understand the basics
1124 of how to use the easy interface. The multi interface is simply a way to make
1125 multiple transfers at the same time, by adding up multiple easy handles in to
1126 a "multi stack".
1127
1128 You create the easy handles you want and you set all the options just like you
1129 have been told above, and then you create a multi handle with
1130 \fIcurl_multi_init(3)\fP and add all those easy handles to that multi handle
1131 with \fIcurl_multi_add_handle(3)\fP.
1132
1133 When you've added the handles you have for the moment (you can still add new
1134 ones at any time), you start the transfers by call
1135 \fIcurl_multi_perform(3)\fP.
1136
1137 \fIcurl_multi_perform(3)\fP is asynchronous. It will only execute as little as
1138 possible and then return back control to your program. It is designed to never
1139 block. If it returns CURLM_CALL_MULTI_PERFORM you better call it again soon,
1140 as that is a signal that it still has local data to send or remote data to
1141 receive.
1142
1143 The best usage of this interface is when you do a select() on all possible
1144 file descriptors or sockets to know when to call libcurl again. This also
1145 makes it easy for you to wait and respond to actions on your own application's
1146 sockets/handles. You figure out what to select() for by using
1147 \fIcurl_multi_fdset(3)\fP, that fills in a set of fd_set variables for you
1148 with the particular file descriptors libcurl uses for the moment.
1149
1150 When you then call select(), it'll return when one of the file handles signal
1151 action and you then call \fIcurl_multi_perform(3)\fP to allow libcurl to do
1152 what it wants to do. Take note that libcurl does also feature some time-out
1153 code so we advice you to never use very long timeouts on select() before you
1154 call \fIcurl_multi_perform(3)\fP, which thus should be called unconditionally
1155 every now and then even if none of its file descriptors have signaled
1156 ready. Another precaution you should use: always call
1157 \fIcurl_multi_fdset(3)\fP immediately before the select() call since the
1158 current set of file descriptors may change when calling a curl function.
1159
1160 If you want to stop the transfer of one of the easy handles in the stack, you
1161 can use \fIcurl_multi_remove_handle(3)\fP to remove individual easy
1162 handles. Remember that easy handles should be \fIcurl_easy_cleanup(3)\fPed.
1163
1164 When a transfer within the multi stack has finished, the counter of running
1165 transfers (as filled in by \fIcurl_multi_perform(3)\fP) will decrease. When
1166 the number reaches zero, all transfers are done.
1167
1168 \fIcurl_multi_info_read(3)\fP can be used to get information about completed
1169 transfers. It then returns the CURLcode for each easy transfer, to allow you
1170 to figure out success on each individual transfer.
1171
1172 .SH "SSL, Certificates and Other Tricks"
1173
1174  [ seeding, passwords, keys, certificates, ENGINE, ca certs ]
1175
1176 .SH "Sharing Data Between Easy Handles"
1177
1178  [ fill in ]
1179
1180 .SH "Footnotes"
1181
1182 .IP "[1]"
1183 libcurl 7.10.3 and later have the ability to switch over to chunked
1184 Transfer-Encoding in cases were HTTP uploads are done with data of an unknown
1185 size.
1186 .IP "[2]"
1187 This happens on Windows machines when libcurl is built and used as a
1188 DLL. However, you can still do this on Windows if you link with a static
1189 library.
1190 .IP "[3]"
1191 The curl-config tool is generated at build-time (on unix-like systems) and
1192 should be installed with the 'make install' or similar instruction that
1193 installs the library, header files, man pages etc.