Install curl-7.25.0.tar.bz2
[msysgit.git] / mingw / share / man / man3 / libcurl.3
blobd2dcd7838882d665890c5243a07b38aa4bcf4d83
1 .\" **************************************************************************
2 .\" *                                  _   _ ____  _
3 .\" *  Project                     ___| | | |  _ \| |
4 .\" *                             / __| | | | |_) | |
5 .\" *                            | (__| |_| |  _ <| |___
6 .\" *                             \___|\___/|_| \_\_____|
7 .\" *
8 .\" * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
9 .\" *
10 .\" * This software is licensed as described in the file COPYING, which
11 .\" * you should have received as part of this distribution. The terms
12 .\" * are also available at http://curl.haxx.se/docs/copyright.html.
13 .\" *
14 .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 .\" * copies of the Software, and permit persons to whom the Software is
16 .\" * furnished to do so, under the terms of the COPYING file.
17 .\" *
18 .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 .\" * KIND, either express or implied.
20 .\" *
21 .\" **************************************************************************
22 .TH libcurl 3 "19 March 2002" "libcurl 7.9.6" "libcurl overview"
23 .SH NAME
24 libcurl \- client-side URL transfers
25 .SH DESCRIPTION
26 This is a short overview on how to use libcurl in your C programs. There are
27 specific man pages for each function mentioned in here. There are also the
28 \fIlibcurl-easy(3)\fP man page, the \fIlibcurl-multi(3)\fP man page, the
29 \fIlibcurl-share(3)\fP man page and the \fIlibcurl-tutorial(3)\fP man page for
30 in-depth understanding on how to program with libcurl.
32 There are more than thirty custom bindings available that bring libcurl access
33 to your favourite language. Look elsewhere for documentation on those.
35 libcurl has a global constant environment that you must set up and
36 maintain while using libcurl.  This essentially means you call
37 \fIcurl_global_init(3)\fP at the start of your program and
38 \fIcurl_global_cleanup(3)\fP at the end.  See GLOBAL CONSTANTS below
39 for details.
41 To transfer files, you always set up an "easy handle" using
42 \fIcurl_easy_init(3)\fP, but when you want the file(s) transferred you have
43 the option of using the "easy" interface, or the "multi" interface.
45 The easy interface is a synchronous interface with which you call
46 \fIcurl_easy_perform(3)\fP and let it perform the transfer. When it is
47 completed, the function returns and you can continue. More details are found in
48 the \fIlibcurl-easy(3)\fP man page.
50 The multi interface on the other hand is an asynchronous interface, that you
51 call and that performs only a little piece of the transfer on each invoke. It
52 is perfect if you want to do things while the transfer is in progress, or
53 similar. The multi interface allows you to select() on libcurl action, and
54 even to easily download multiple files simultaneously using a single thread. See further details in the \fIlibcurl-multi(3)\fP man page.
56 You can have multiple easy handles share certain data, even if they are used
57 in different threads. This magic is setup using the share interface, as
58 described in the \fIlibcurl-share(3)\fP man page.
60 There is also a series of other helpful functions to use, including these:
61 .RS
62 .IP curl_version_info()
63 gets detailed libcurl (and other used libraries) version info
64 .IP curl_getdate()
65 converts a date string to time_t
66 .IP curl_easy_getinfo()
67 get information about a performed transfer
68 .IP curl_formadd()
69 helps building an HTTP form POST
70 .IP curl_formfree()
71 free a list built with \fIcurl_formadd(3)\fP
72 .IP curl_slist_append()
73 builds a linked list
74 .IP curl_slist_free_all()
75 frees a whole curl_slist
76 .RE
78 .SH "LINKING WITH LIBCURL"
79 On unix-like machines, there's a tool named curl-config that gets installed
80 with the rest of the curl stuff when 'make install' is performed.
82 curl-config is added to make it easier for applications to link with libcurl
83 and developers to learn about libcurl and how to use it.
85 Run 'curl-config --libs' to get the (additional) linker options you need to
86 link with the particular version of libcurl you've installed. See the
87 \fIcurl-config(1)\fP man page for further details.
89 Unix-like operating system that ship libcurl as part of their distributions
90 often don't provide the curl-config tool, but simply install the library and
91 headers in the common path for this purpose.
93 .SH "LIBCURL SYMBOL NAMES"
94 All public functions in the libcurl interface are prefixed with 'curl_' (with
95 a lowercase c). You can find other functions in the library source code, but
96 other prefixes indicate that the functions are private and may change without
97 further notice in the next release.
99 Only use documented functions and functionality!
100 .SH "PORTABILITY"
101 libcurl works
102 .B exactly
103 the same, on any of the platforms it compiles and builds on.
104 .SH "THREADS"
105 Never ever call curl-functions simultaneously using the same handle from
106 several threads. libcurl is thread-safe and can be used in any number of
107 threads, but you must use separate curl handles if you want to use libcurl in
108 more than one thread simultaneously.
110 The global environment functions are not thread-safe.  See GLOBAL CONSTANTS
111 below for details.
113 .SH "PERSISTENT CONNECTIONS"
114 Persistent connections means that libcurl can re-use the same connection for
115 several transfers, if the conditions are right.
117 libcurl will \fBalways\fP attempt to use persistent connections. Whenever you
118 use \fIcurl_easy_perform(3)\fP or \fIcurl_multi_perform(3)\fP, libcurl will
119 attempt to use an existing connection to do the transfer, and if none exists
120 it'll open a new one that will be subject for re-use on a possible following
121 call to \fIcurl_easy_perform(3)\fP or \fIcurl_multi_perform(3)\fP.
123 To allow libcurl to take full advantage of persistent connections, you should
124 do as many of your file transfers as possible using the same curl handle. When
125 you call \fIcurl_easy_cleanup(3)\fP, all the possibly open connections held by
126 libcurl will be closed and forgotten.
128 Note that the options set with \fIcurl_easy_setopt(3)\fP will be used on
129 every repeated \fIcurl_easy_perform(3)\fP call.
131 .SH "GLOBAL CONSTANTS"
132 There are a variety of constants that libcurl uses, mainly through its
133 internal use of other libraries, which are too complicated for the
134 library loader to set up.  Therefore, a program must call a library
135 function after the program is loaded and running to finish setting up
136 the library code.  For example, when libcurl is built for SSL
137 capability via the GNU TLS library, there is an elaborate tree inside
138 that library that describes the SSL protocol.
140 \fIcurl_global_init()\fP is the function that you must call.  This may
141 allocate resources (e.g. the memory for the GNU TLS tree mentioned
142 above), so the companion function \fIcurl_global_cleanup()\fP releases
143 them.
145 The basic rule for constructing a program that uses libcurl is this:
146 Call \fIcurl_global_init()\fP, with a \fICURL_GLOBAL_ALL\fP argument,
147 immediately after the program starts, while it is still only one
148 thread and before it uses libcurl at all.  Call
149 \fIcurl_global_cleanup()\fP immediately before the program exits, when
150 the program is again only one thread and after its last use of
151 libcurl.
153 You can call both of these multiple times, as long as all calls meet
154 these requirements and the number of calls to each is the same.
156 It isn't actually required that the functions be called at the beginning
157 and end of the program -- that's just usually the easiest way to do it.
158 It \fIis\fP required that the functions be called when no other thread
159 in the program is running.
161 These global constant functions are \fInot thread safe\fP, so you must
162 not call them when any other thread in the program is running.  It
163 isn't good enough that no other thread is using libcurl at the time,
164 because these functions internally call similar functions of other
165 libraries, and those functions are similarly thread-unsafe.  You can't
166 generally know what these libraries are, or whether other threads are
167 using them.
169 The global constant situation merits special consideration when the
170 code you are writing to use libcurl is not the main program, but rather
171 a modular piece of a program, e.g. another library.  As a module,
172 your code doesn't know about other parts of the program -- it doesn't
173 know whether they use libcurl or not.  And its code doesn't necessarily
174 run at the start and end of the whole program.
176 A module like this must have global constant functions of its own,
177 just like \fIcurl_global_init()\fP and \fIcurl_global_cleanup()\fP.
178 The module thus has control at the beginning and end of the program
179 and has a place to call the libcurl functions.  Note that if multiple
180 modules in the program use libcurl, they all will separately call the
181 libcurl functions, and that's OK because only the first
182 \fIcurl_global_init()\fP and the last \fIcurl_global_cleanup()\fP in a
183 program change anything.  (libcurl uses a reference count in static
184 memory).
186 In a C++ module, it is common to deal with the global constant
187 situation by defining a special class that represents the global
188 constant environment of the module.  A program always has exactly one
189 object of the class, in static storage.  That way, the program
190 automatically calls the constructor of the object as the program
191 starts up and the destructor as it terminates.  As the author of this
192 libcurl-using module, you can make the constructor call
193 \fIcurl_global_init()\fP and the destructor call
194 \fIcurl_global_cleanup()\fP and satisfy libcurl's requirements without
195 your user having to think about it.
197 \fIcurl_global_init()\fP has an argument that tells what particular
198 parts of the global constant environment to set up.  In order to
199 successfully use any value except \fICURL_GLOBAL_ALL\fP (which says to
200 set up the whole thing), you must have specific knowledge of internal
201 workings of libcurl and all other parts of the program of which it is
202 part.
204 A special part of the global constant environment is the identity of
205 the memory allocator.  \fIcurl_global_init()\fP selects the system
206 default memory allocator, but you can use \fIcurl_global_init_mem()\fP
207 to supply one of your own.  However, there is no way to use
208 \fIcurl_global_init_mem()\fP in a modular program -- all modules in
209 the program that might use libcurl would have to agree on one
210 allocator.
212 There is a failsafe in libcurl that makes it usable in simple
213 situations without you having to worry about the global constant
214 environment at all: \fIcurl_easy_init()\fP sets up the environment
215 itself if it hasn't been done yet.  The resources it acquires to do so
216 get released by the operating system automatically when the program
217 exits.
219 This failsafe feature exists mainly for backward compatibility because
220 there was a time when the global functions didn't exist.  Because it
221 is sufficient only in the simplest of programs, it is not recommended
222 for any program to rely on it.