Revert "Update to 7.40.1"
[platform/upstream/curl.git] / docs / libcurl / libcurl.3
1 .\" **************************************************************************
2 .\" *                                  _   _ ____  _
3 .\" *  Project                     ___| | | |  _ \| |
4 .\" *                             / __| | | | |_) | |
5 .\" *                            | (__| |_| |  _ <| |___
6 .\" *                             \___|\___/|_| \_\_____|
7 .\" *
8 .\" * Copyright (C) 1998 - 2014, 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.
31
32 There are many bindings available that bring libcurl access to your favourite
33 language. Look elsewhere for documentation on those.
34
35 libcurl has a global constant environment that you must set up and maintain
36 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 \fBGLOBAL CONSTANTS\fP below for
39 details.
40
41 To transfer files, you create an "easy handle" using \fIcurl_easy_init(3)\fP
42 for a single individual transfer (in either direction). You then set your
43 desired set of options in that handle with \fIcurk_easy_setopt(3)\fP. Options
44 you set with \fIcurl_easy_setopt(3)\fP stick. They will be used on every
45 repeated use of this handle until you either change the option, or you reset
46 them all with \fIcurl_easy_reset(3)\fP.
47
48 To actually transfer data you have the option of using the "easy" interface,
49 or the "multi" interface.
50
51 The easy interface is a synchronous interface with which you call
52 \fIcurl_easy_perform(3)\fP and let it perform the transfer. When it is
53 completed, the function returns and you can continue. More details are found in
54 the \fIlibcurl-easy(3)\fP man page.
55
56 The multi interface on the other hand is an asynchronous interface, that you
57 call and that performs only a little piece of the transfer on each invoke. It
58 is perfect if you want to do things while the transfer is in progress, or
59 similar. The multi interface allows you to select() on libcurl action, and
60 even to easily download multiple files simultaneously using a single
61 thread. See further details in the \fIlibcurl-multi(3)\fP man page.
62
63 You can have multiple easy handles share certain data, even if they are used
64 in different threads. This magic is setup using the share interface, as
65 described in the \fIlibcurl-share(3)\fP man page.
66
67 There is also a series of other helpful functions to use, including these:
68 .RS
69 .IP curl_version_info()
70 gets detailed libcurl (and other used libraries) version info
71 .IP curl_getdate()
72 converts a date string to time_t
73 .IP curl_easy_getinfo()
74 get information about a performed transfer
75 .IP curl_formadd()
76 helps building an HTTP form POST
77 .IP curl_formfree()
78 free a list built with \fIcurl_formadd(3)\fP
79 .IP curl_slist_append()
80 builds a linked list
81 .IP curl_slist_free_all()
82 frees a whole curl_slist
83 .RE
84
85 .SH "LINKING WITH LIBCURL"
86 On unix-like machines, there's a tool named curl-config that gets installed
87 with the rest of the curl stuff when 'make install' is performed.
88
89 curl-config is added to make it easier for applications to link with libcurl
90 and developers to learn about libcurl and how to use it.
91
92 Run 'curl-config --libs' to get the (additional) linker options you need to
93 link with the particular version of libcurl you've installed. See the
94 \fIcurl-config(1)\fP man page for further details.
95
96 Unix-like operating system that ship libcurl as part of their distributions
97 often don't provide the curl-config tool, but simply install the library and
98 headers in the common path for this purpose.
99
100 Many Linux and similar sytems use pkg-config to provide build and link options
101 about libraries and libcurl supports that as well.
102 .SH "LIBCURL SYMBOL NAMES"
103 All public functions in the libcurl interface are prefixed with 'curl_' (with
104 a lowercase c). You can find other functions in the library source code, but
105 other prefixes indicate that the functions are private and may change without
106 further notice in the next release.
107
108 Only use documented functions and functionality!
109 .SH "PORTABILITY"
110 libcurl works
111 .B exactly
112 the same, on any of the platforms it compiles and builds on.
113 .SH "THREADS"
114 Never ever call curl-functions simultaneously using the same handle from
115 several threads. libcurl is thread-safe and can be used in any number of
116 threads, but you must use separate curl handles if you want to use libcurl in
117 more than one thread simultaneously.
118
119 The global environment functions are not thread-safe.  See \fBGLOBAL
120 CONSTANTS\fP below for details.
121
122 .SH "PERSISTENT CONNECTIONS"
123 Persistent connections means that libcurl can re-use the same connection for
124 several transfers, if the conditions are right.
125
126 libcurl will \fBalways\fP attempt to use persistent connections. Whenever you
127 use \fIcurl_easy_perform(3)\fP or \fIcurl_multi_perform(3)\fP etc, libcurl
128 will attempt to use an existing connection to do the transfer, and if none
129 exists it'll open a new one that will be subject for re-use on a possible
130 following call to \fIcurl_easy_perform(3)\fP or \fIcurl_multi_perform(3)\fP.
131
132 To allow libcurl to take full advantage of persistent connections, you should
133 do as many of your file transfers as possible using the same handle.
134
135 If you use the easy interface, and you call \fIcurl_easy_cleanup(3)\fP, all
136 the possibly open connections held by libcurl will be closed and forgotten.
137
138 When you've created a multi handle and are using the multi interface, the
139 connection pool is instead kept in the multi handle so closing and creating
140 new easy handles to do transfers will not affect them. Instead all added easy
141 handles can take advantage of the single shared pool.
142 .SH "GLOBAL CONSTANTS"
143 There are a variety of constants that libcurl uses, mainly through its
144 internal use of other libraries, which are too complicated for the
145 library loader to set up.  Therefore, a program must call a library
146 function after the program is loaded and running to finish setting up
147 the library code.  For example, when libcurl is built for SSL
148 capability via the GNU TLS library, there is an elaborate tree inside
149 that library that describes the SSL protocol.
150
151 \fIcurl_global_init()\fP is the function that you must call.  This may
152 allocate resources (e.g. the memory for the GNU TLS tree mentioned
153 above), so the companion function \fIcurl_global_cleanup()\fP releases
154 them.
155
156 The basic rule for constructing a program that uses libcurl is this:
157 Call \fIcurl_global_init()\fP, with a \fICURL_GLOBAL_ALL\fP argument,
158 immediately after the program starts, while it is still only one
159 thread and before it uses libcurl at all.  Call
160 \fIcurl_global_cleanup()\fP immediately before the program exits, when
161 the program is again only one thread and after its last use of
162 libcurl.
163
164 You can call both of these multiple times, as long as all calls meet
165 these requirements and the number of calls to each is the same.
166
167 It isn't actually required that the functions be called at the beginning
168 and end of the program -- that's just usually the easiest way to do it.
169 It \fIis\fP required that the functions be called when no other thread
170 in the program is running.
171
172 These global constant functions are \fInot thread safe\fP, so you must
173 not call them when any other thread in the program is running.  It
174 isn't good enough that no other thread is using libcurl at the time,
175 because these functions internally call similar functions of other
176 libraries, and those functions are similarly thread-unsafe.  You can't
177 generally know what these libraries are, or whether other threads are
178 using them.
179
180 The global constant situation merits special consideration when the
181 code you are writing to use libcurl is not the main program, but rather
182 a modular piece of a program, e.g. another library.  As a module,
183 your code doesn't know about other parts of the program -- it doesn't
184 know whether they use libcurl or not.  And its code doesn't necessarily
185 run at the start and end of the whole program.
186
187 A module like this must have global constant functions of its own,
188 just like \fIcurl_global_init()\fP and \fIcurl_global_cleanup()\fP.
189 The module thus has control at the beginning and end of the program
190 and has a place to call the libcurl functions.  Note that if multiple
191 modules in the program use libcurl, they all will separately call the
192 libcurl functions, and that's OK because only the first
193 \fIcurl_global_init()\fP and the last \fIcurl_global_cleanup()\fP in a
194 program change anything.  (libcurl uses a reference count in static
195 memory).
196
197 In a C++ module, it is common to deal with the global constant
198 situation by defining a special class that represents the global
199 constant environment of the module.  A program always has exactly one
200 object of the class, in static storage.  That way, the program
201 automatically calls the constructor of the object as the program
202 starts up and the destructor as it terminates.  As the author of this
203 libcurl-using module, you can make the constructor call
204 \fIcurl_global_init()\fP and the destructor call
205 \fIcurl_global_cleanup()\fP and satisfy libcurl's requirements without
206 your user having to think about it.
207
208 \fIcurl_global_init()\fP has an argument that tells what particular
209 parts of the global constant environment to set up.  In order to
210 successfully use any value except \fICURL_GLOBAL_ALL\fP (which says to
211 set up the whole thing), you must have specific knowledge of internal
212 workings of libcurl and all other parts of the program of which it is
213 part.
214
215 A special part of the global constant environment is the identity of
216 the memory allocator.  \fIcurl_global_init()\fP selects the system
217 default memory allocator, but you can use \fIcurl_global_init_mem()\fP
218 to supply one of your own.  However, there is no way to use
219 \fIcurl_global_init_mem()\fP in a modular program -- all modules in
220 the program that might use libcurl would have to agree on one
221 allocator.
222
223 There is a failsafe in libcurl that makes it usable in simple
224 situations without you having to worry about the global constant
225 environment at all: \fIcurl_easy_init()\fP sets up the environment
226 itself if it hasn't been done yet.  The resources it acquires to do so
227 get released by the operating system automatically when the program
228 exits.
229
230 This failsafe feature exists mainly for backward compatibility because
231 there was a time when the global functions didn't exist.  Because it
232 is sufficient only in the simplest of programs, it is not recommended
233 for any program to rely on it.