mirror of
https://github.com/curl/curl.git
synced 2025-03-31 16:00:35 +08:00
parent
3c4fba8cf5
commit
cb521d1f9a
2
.github/scripts/verify-examples.pl
vendored
2
.github/scripts/verify-examples.pl
vendored
@ -50,8 +50,6 @@ sub extract {
|
||||
open(F, "<$f");
|
||||
open(O, ">$cfile");
|
||||
print O "#include <curl/curl.h>\n";
|
||||
print O "extern struct CURLM *multi;\n";
|
||||
print O "extern struct CURL *easy;\n";
|
||||
while(<F>) {
|
||||
$iline++;
|
||||
if(/^.SH EXAMPLE/) {
|
||||
|
@ -57,12 +57,17 @@ Passing in a NULL pointer in \fIhandle\fP makes this function return
|
||||
immediately with no action.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
res = curl_easy_perform(curl);
|
||||
if(res)
|
||||
printf("error: %s\\n", curl_easy_strerror(res));
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -52,15 +52,18 @@ In multi-threaded programs, this function must be called in a synchronous way,
|
||||
the input handle may not be in use when cloned.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
CURL *nother;
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
nother = curl_easy_duphandle(curl);
|
||||
res = curl_easy_perform(nother);
|
||||
curl_easy_cleanup(nother);
|
||||
curl_easy_cleanup(curl);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
CURL *nother;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
nother = curl_easy_duphandle(curl);
|
||||
res = curl_easy_perform(nother);
|
||||
curl_easy_cleanup(nother);
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -57,14 +57,17 @@ The caller of \fIcurl_easy_escape(3)\fP must make sure that the data passed in
|
||||
to the function is encoded correctly.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
char *output = curl_easy_escape(curl, "data to convert", 15);
|
||||
if(output) {
|
||||
printf("Encoded: %s\\n", output);
|
||||
curl_free(output);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
char *output = curl_easy_escape(curl, "data to convert", 15);
|
||||
if(output) {
|
||||
printf("Encoded: %s\\n", output);
|
||||
curl_free(output);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -298,8 +298,11 @@ pretransfer and transfer before final transaction was started. So, this is
|
||||
zero if no redirection took place.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl = curl_easy_init();
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
@ -315,6 +318,7 @@ zero if no redirection took place.
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.4.1
|
||||
|
@ -127,9 +127,18 @@ response that might happen before the "real" response.
|
||||
The header is an HTTP/2 or HTTP/3 pseudo header
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
struct curl_header *type;
|
||||
CURLHcode h =
|
||||
curl_easy_header(easy, "Content-Type", 0, CURLH_HEADER, -1, &type);
|
||||
int main(void)
|
||||
{
|
||||
struct curl_header *type;
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLHcode h;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
curl_easy_perform(curl);
|
||||
h = curl_easy_header(curl, "Content-Type", 0, CURLH_HEADER, -1, &type);
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.83.0. Officially supported since 7.84.0.
|
||||
|
@ -57,12 +57,15 @@ this function.
|
||||
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -68,20 +68,29 @@ is associated with the easy handle. Applications must copy the data if they
|
||||
want it to survive subsequent API calls or the life-time of the easy handle.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
struct curl_header *prev = NULL;
|
||||
struct curl_header *h;
|
||||
int main(void)
|
||||
{
|
||||
struct curl_header *prev = NULL;
|
||||
struct curl_header *h;
|
||||
|
||||
/* extract the normal headers from the first request */
|
||||
while((h = curl_easy_nextheader(easy, CURLH_HEADER, 0, prev))) {
|
||||
printf("%s: %s\\n", h->name, h->value);
|
||||
prev = h;
|
||||
}
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
curl_easy_perform(curl);
|
||||
|
||||
/* extract the normal headers + 1xx + trailers from the last request */
|
||||
unsigned int origin = CURLH_HEADER| CURLH_1XX | CURLH_TRAILER;
|
||||
while((h = curl_easy_nextheader(easy, origin, -1, prev))) {
|
||||
printf("%s: %s\\n", h->name, h->value);
|
||||
prev = h;
|
||||
/* extract the normal headers from the first request */
|
||||
while((h = curl_easy_nextheader(curl, CURLH_HEADER, 0, prev))) {
|
||||
printf("%s: %s\\n", h->name, h->value);
|
||||
prev = h;
|
||||
}
|
||||
|
||||
/* extract the normal headers + 1xx + trailers from the last request */
|
||||
unsigned int origin = CURLH_HEADER| CURLH_1XX | CURLH_TRAILER;
|
||||
while((h = curl_easy_nextheader(curl, origin, -1, prev))) {
|
||||
printf("%s: %s\\n", h->name, h->value);
|
||||
prev = h;
|
||||
}
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -41,9 +41,12 @@ well.
|
||||
If libcurl has no option with the given id, this function returns NULL.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
const struct curl_easyoption *opt = curl_easy_option_by_id(CURLOPT_URL);
|
||||
if(opt) {
|
||||
printf("This option wants type %x\\n", opt->type);
|
||||
int main(void)
|
||||
{
|
||||
const struct curl_easyoption *opt = curl_easy_option_by_id(CURLOPT_URL);
|
||||
if(opt) {
|
||||
printf("This option wants type %x\\n", opt->type);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -40,9 +40,12 @@ insensitive.
|
||||
If libcurl has no option with the given name, this function returns NULL.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
const struct curl_easyoption *opt = curl_easy_option_by_name("URL");
|
||||
if(opt) {
|
||||
printf("This option wants CURLoption %x\\n", (int)opt->id);
|
||||
int main(void)
|
||||
{
|
||||
const struct curl_easyoption *opt = curl_easy_option_by_name("URL");
|
||||
if(opt) {
|
||||
printf("This option wants CURLoption %x\\n", (int)opt->id);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -70,12 +70,15 @@ struct curl_easyoption {
|
||||
.fi
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
/* iterate over all available options */
|
||||
const struct curl_easyoption *opt;
|
||||
opt = curl_easy_option_next(NULL);
|
||||
while(opt) {
|
||||
printf("Name: %s\\n", opt->name);
|
||||
opt = curl_easy_option_next(opt);
|
||||
int main(void)
|
||||
{
|
||||
/* iterate over all available options */
|
||||
const struct curl_easyoption *opt;
|
||||
opt = curl_easy_option_next(NULL);
|
||||
while(opt) {
|
||||
printf("Name: %s\\n", opt->name);
|
||||
opt = curl_easy_option_next(opt);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -92,8 +92,15 @@ When such a paused stream is unpaused again, any buffered data is delivered
|
||||
first.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
/* pause a transfer in both directions */
|
||||
curl_easy_pause(curl, CURL_READFUNC_PAUSE | CURL_WRITEFUNC_PAUSE);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
/* pause a transfer in both directions */
|
||||
curl_easy_pause(curl, CURL_READFUNC_PAUSE | CURL_WRITEFUNC_PAUSE);
|
||||
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH "MEMORY USE"
|
||||
When pausing a download transfer by returning the magic return code from a
|
||||
|
@ -63,12 +63,15 @@ While the \fBeasy_handle\fP is added to a multi handle, it cannot be used by
|
||||
\fIcurl_easy_perform(3)\fP.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -63,18 +63,29 @@ Furthermore if you wait on the socket and it tells you there is data to read,
|
||||
read was for internal SSL processing, and no other data is available.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
/* Do not do the transfer - only connect to host */
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
|
||||
res = curl_easy_perform(curl);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
/* Do not do the transfer - only connect to host */
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if(res == CURLE_OK) {
|
||||
/* Extract the socket from the curl handle - we need it for waiting. */
|
||||
res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
|
||||
if(res == CURLE_OK) {
|
||||
char buf[256];
|
||||
size_t nread;
|
||||
long sockfd;
|
||||
|
||||
/* read data */
|
||||
res = curl_easy_recv(curl, buf, sizeof(buf), &nread);
|
||||
}
|
||||
/* Extract the socket from the curl handle - we need it for waiting. */
|
||||
res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
|
||||
|
||||
/* read data */
|
||||
res = curl_easy_recv(curl, buf, sizeof(buf), &nread);
|
||||
}
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.18.2.
|
||||
|
@ -40,11 +40,15 @@ connections, the Session ID cache, the DNS cache, the cookies, the shares or
|
||||
the alt-svc cache.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
|
||||
/* ... the handle is used and options are set ... */
|
||||
|
||||
curl_easy_reset(curl);
|
||||
/* ... the handle is used and options are set ... */
|
||||
curl_easy_reset(curl);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
This function was added in libcurl 7.12.1
|
||||
|
@ -58,18 +58,27 @@ Furthermore if you wait on the socket and it tells you it's writable,
|
||||
sent was for internal SSL processing, and no other data could be sent.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
/* Do not do the transfer - only connect to host */
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
|
||||
res = curl_easy_perform(curl);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
/* Do not do the transfer - only connect to host */
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if(res == CURLE_OK) {
|
||||
/* Extract the socket from the curl handle - we need it for waiting. */
|
||||
res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
|
||||
if(res == CURLE_OK) {
|
||||
long sockfd;
|
||||
size_t sent;
|
||||
/* Extract the socket from the curl handle - we need it for waiting. */
|
||||
res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
|
||||
|
||||
/* send data */
|
||||
res = curl_easy_send(curl, "hello", 5, &sent);
|
||||
}
|
||||
/* send data */
|
||||
res = curl_easy_send(curl, "hello", 5, &sent);
|
||||
}
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.18.2.
|
||||
|
@ -709,12 +709,15 @@ To be set by toplevel tools like "curl" to skip lengthy cleanups when they are a
|
||||
TELNET options. See \fICURLOPT_TELNETOPTIONS(3)\fP
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -38,12 +38,20 @@ Typically applications also appreciate \fICURLOPT_ERRORBUFFER(3)\fP for more
|
||||
specific error descriptions generated at runtime.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
/* Perform the entire transfer */
|
||||
res = curl_easy_perform(curl);
|
||||
/* Check for errors */
|
||||
if(res != CURLE_OK)
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\\n",
|
||||
curl_easy_strerror(res));
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
/* set options */
|
||||
/* Perform the entire transfer */
|
||||
res = curl_easy_perform(curl);
|
||||
/* Check for errors */
|
||||
if(res != CURLE_OK)
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\\n",
|
||||
curl_easy_strerror(res));
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
This function was added in libcurl 7.12.0
|
||||
|
@ -54,17 +54,20 @@ TPF, but it was otherwise ignored.
|
||||
You must \fIcurl_free(3)\fP the returned string when you are done with it.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
int decodelen;
|
||||
char *decoded = curl_easy_unescape(curl, "%63%75%72%6c", 12, &decodelen);
|
||||
if(decoded) {
|
||||
/* do not assume printf() works on the decoded data! */
|
||||
printf("Decoded: ");
|
||||
/* ... */
|
||||
curl_free(decoded);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
int decodelen;
|
||||
char *decoded = curl_easy_unescape(curl, "%63%75%72%6c", 12, &decodelen);
|
||||
if(decoded) {
|
||||
/* do not assume printf() works on the decoded data! */
|
||||
printf("Decoded: ");
|
||||
/* ... */
|
||||
curl_free(decoded);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -47,27 +47,30 @@ The connection upkeep interval is set with
|
||||
\fICURLOPT_UPKEEP_INTERVAL_MS(3)\fP.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
/* Make a connection to an HTTP/2 server. */
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
/* Make a connection to an HTTP/2 server. */
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
|
||||
/* Set the interval to 30000ms / 30s */
|
||||
curl_easy_setopt(curl, CURLOPT_UPKEEP_INTERVAL_MS, 30000L);
|
||||
/* Set the interval to 30000ms / 30s */
|
||||
curl_easy_setopt(curl, CURLOPT_UPKEEP_INTERVAL_MS, 30000L);
|
||||
|
||||
curl_easy_perform(curl);
|
||||
curl_easy_perform(curl);
|
||||
|
||||
/* Perform more work here. */
|
||||
/* Perform more work here. */
|
||||
|
||||
/* While the connection is being held open, curl_easy_upkeep() can be
|
||||
called. If curl_easy_upkeep() is called and the time since the last
|
||||
upkeep exceeds the interval, then an HTTP/2 PING is sent. */
|
||||
curl_easy_upkeep(curl);
|
||||
/* While the connection is being held open, curl_easy_upkeep() can be
|
||||
called. If curl_easy_upkeep() is called and the time since the last
|
||||
upkeep exceeds the interval, then an HTTP/2 PING is sent. */
|
||||
curl_easy_upkeep(curl);
|
||||
|
||||
/* Perform more work here. */
|
||||
/* Perform more work here. */
|
||||
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -44,10 +44,13 @@ on \fBstring\fP to find out the size.
|
||||
You must \fIcurl_free(3)\fP the returned string when you are done with it.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
char *output = curl_escape("data to convert", 15);
|
||||
if(output) {
|
||||
printf("Encoded: %s\\n", output);
|
||||
curl_free(output);
|
||||
int main(void)
|
||||
{
|
||||
char *output = curl_escape("data to convert", 15);
|
||||
if(output) {
|
||||
printf("Encoded: %s\\n", output);
|
||||
curl_free(output);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -175,82 +175,99 @@ for the curl handle.
|
||||
See example below.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
struct curl_httppost *post = NULL;
|
||||
struct curl_httppost *last = NULL;
|
||||
char namebuffer[] = "name buffer";
|
||||
long namelength = strlen(namebuffer);
|
||||
char buffer[] = "test buffer";
|
||||
char htmlbuffer[] = "<HTML>test buffer</HTML>";
|
||||
long htmlbufferlength = strlen(htmlbuffer);
|
||||
struct curl_forms forms[3];
|
||||
char file1[] = "my-face.jpg";
|
||||
char file2[] = "your-face.jpg";
|
||||
/* add null character into htmlbuffer, to demonstrate that
|
||||
transfers of buffers containing null characters actually work
|
||||
*/
|
||||
htmlbuffer[8] = '\\0';
|
||||
#include <string.h> /* for strlen */
|
||||
|
||||
/* Add simple name/content section */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "name",
|
||||
CURLFORM_COPYCONTENTS, "content", CURLFORM_END);
|
||||
static const char record[]="data in a buffer";
|
||||
|
||||
/* Add simple name/content/contenttype section */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "htmlcode",
|
||||
CURLFORM_COPYCONTENTS, "<HTML></HTML>",
|
||||
CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
struct curl_httppost *post = NULL;
|
||||
struct curl_httppost *last = NULL;
|
||||
char namebuffer[] = "name buffer";
|
||||
long namelength = strlen(namebuffer);
|
||||
char buffer[] = "test buffer";
|
||||
char htmlbuffer[] = "<HTML>test buffer</HTML>";
|
||||
long htmlbufferlength = strlen(htmlbuffer);
|
||||
struct curl_forms forms[3];
|
||||
char file1[] = "my-face.jpg";
|
||||
char file2[] = "your-face.jpg";
|
||||
/* add null character into htmlbuffer, to demonstrate that
|
||||
transfers of buffers containing null characters actually work
|
||||
*/
|
||||
htmlbuffer[8] = '\\0';
|
||||
|
||||
/* Add name/ptrcontent section */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "name_for_ptrcontent",
|
||||
CURLFORM_PTRCONTENTS, buffer, CURLFORM_END);
|
||||
/* Add simple name/content section */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "name",
|
||||
CURLFORM_COPYCONTENTS, "content", CURLFORM_END);
|
||||
|
||||
/* Add ptrname/ptrcontent section */
|
||||
curl_formadd(&post, &last, CURLFORM_PTRNAME, namebuffer,
|
||||
CURLFORM_PTRCONTENTS, buffer, CURLFORM_NAMELENGTH,
|
||||
namelength, CURLFORM_END);
|
||||
/* Add simple name/content/contenttype section */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "htmlcode",
|
||||
CURLFORM_COPYCONTENTS, "<HTML></HTML>",
|
||||
CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
|
||||
|
||||
/* Add name/ptrcontent/contenttype section */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "html_code_with_hole",
|
||||
CURLFORM_PTRCONTENTS, htmlbuffer,
|
||||
CURLFORM_CONTENTSLENGTH, htmlbufferlength,
|
||||
CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
|
||||
/* Add name/ptrcontent section */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "name_for_ptrcontent",
|
||||
CURLFORM_PTRCONTENTS, buffer, CURLFORM_END);
|
||||
|
||||
/* Add simple file section */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "picture",
|
||||
CURLFORM_FILE, "my-face.jpg", CURLFORM_END);
|
||||
/* Add ptrname/ptrcontent section */
|
||||
curl_formadd(&post, &last, CURLFORM_PTRNAME, namebuffer,
|
||||
CURLFORM_PTRCONTENTS, buffer, CURLFORM_NAMELENGTH,
|
||||
namelength, CURLFORM_END);
|
||||
|
||||
/* Add file/contenttype section */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "picture",
|
||||
CURLFORM_FILE, "my-face.jpg",
|
||||
CURLFORM_CONTENTTYPE, "image/jpeg", CURLFORM_END);
|
||||
/* Add name/ptrcontent/contenttype section */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "html_code_with_hole",
|
||||
CURLFORM_PTRCONTENTS, htmlbuffer,
|
||||
CURLFORM_CONTENTSLENGTH, htmlbufferlength,
|
||||
CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
|
||||
|
||||
/* Add two file section */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "pictures",
|
||||
CURLFORM_FILE, "my-face.jpg",
|
||||
CURLFORM_FILE, "your-face.jpg", CURLFORM_END);
|
||||
/* Add simple file section */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "picture",
|
||||
CURLFORM_FILE, "my-face.jpg", CURLFORM_END);
|
||||
|
||||
/* Add two file section using CURLFORM_ARRAY */
|
||||
forms[0].option = CURLFORM_FILE;
|
||||
forms[0].value = file1;
|
||||
forms[1].option = CURLFORM_FILE;
|
||||
forms[1].value = file2;
|
||||
forms[2].option = CURLFORM_END;
|
||||
/* Add file/contenttype section */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "picture",
|
||||
CURLFORM_FILE, "my-face.jpg",
|
||||
CURLFORM_CONTENTTYPE, "image/jpeg", CURLFORM_END);
|
||||
|
||||
/* Add a buffer to upload */
|
||||
curl_formadd(&post, &last,
|
||||
CURLFORM_COPYNAME, "name",
|
||||
CURLFORM_BUFFER, "data",
|
||||
CURLFORM_BUFFERPTR, record,
|
||||
CURLFORM_BUFFERLENGTH, record_length,
|
||||
CURLFORM_END);
|
||||
/* Add two file section */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "pictures",
|
||||
CURLFORM_FILE, "my-face.jpg",
|
||||
CURLFORM_FILE, "your-face.jpg", CURLFORM_END);
|
||||
|
||||
/* no option needed for the end marker */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "pictures",
|
||||
CURLFORM_ARRAY, forms, CURLFORM_END);
|
||||
/* Add the content of a file as a normal post text value */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "filecontent",
|
||||
CURLFORM_FILECONTENT, ".bashrc", CURLFORM_END);
|
||||
/* Set the form info */
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
|
||||
/* Add two file section using CURLFORM_ARRAY */
|
||||
forms[0].option = CURLFORM_FILE;
|
||||
forms[0].value = file1;
|
||||
forms[1].option = CURLFORM_FILE;
|
||||
forms[1].value = file2;
|
||||
forms[2].option = CURLFORM_END;
|
||||
|
||||
/* Add a buffer to upload */
|
||||
curl_formadd(&post, &last,
|
||||
CURLFORM_COPYNAME, "name",
|
||||
CURLFORM_BUFFER, "data",
|
||||
CURLFORM_BUFFERPTR, record,
|
||||
CURLFORM_BUFFERLENGTH, sizeof(record),
|
||||
CURLFORM_END);
|
||||
|
||||
/* no option needed for the end marker */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "pictures",
|
||||
CURLFORM_ARRAY, forms, CURLFORM_END);
|
||||
/* Add the content of a file as a normal post text value */
|
||||
curl_formadd(&post, &last, CURLFORM_COPYNAME, "filecontent",
|
||||
CURLFORM_FILECONTENT, ".bashrc", CURLFORM_END);
|
||||
/* Set the form info */
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
|
||||
|
||||
curl_easy_perform(curl);
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
curl_formfree(post);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Deprecated in 7.56.0. Before this release, field names were allowed to
|
||||
contain zero-valued bytes. The pseudo-filename "-" to read stdin is
|
||||
|
@ -48,19 +48,28 @@ Passing in a NULL pointer in \fIform\fP makes this function return immediately
|
||||
with no action.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
/* Fill in a file upload field */
|
||||
curl_formadd(&formpost,
|
||||
&lastptr,
|
||||
CURLFORM_COPYNAME, "file",
|
||||
CURLFORM_FILE, "nice-image.jpg",
|
||||
CURLFORM_END);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
struct curl_httppost *formpost;
|
||||
struct curl_httppost *lastptr;
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
|
||||
/* Fill in a file upload field */
|
||||
curl_formadd(&formpost,
|
||||
&lastptr,
|
||||
CURLFORM_COPYNAME, "file",
|
||||
CURLFORM_FILE, "nice-image.jpg",
|
||||
CURLFORM_END);
|
||||
|
||||
curl_easy_perform(curl);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
|
||||
|
||||
/* then cleanup the formpost chain */
|
||||
curl_formfree(formpost);
|
||||
curl_easy_perform(curl);
|
||||
|
||||
/* then cleanup the formpost chain */
|
||||
curl_formfree(formpost);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Deprecated in 7.56.0.
|
||||
|
@ -50,21 +50,22 @@ request. This, because first then does libcurl known which actual read
|
||||
callback to use!
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
size_t print_httppost_callback(void *arg, const char *buf, size_t len)
|
||||
{
|
||||
fwrite(buf, len, 1, stdout);
|
||||
(*(size_t *) arg) += len;
|
||||
return len;
|
||||
}
|
||||
size_t print_httppost_callback(void *arg, const char *buf, size_t len)
|
||||
{
|
||||
fwrite(buf, len, 1, stdout);
|
||||
(*(size_t *) arg) += len;
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t print_httppost(struct curl_httppost *post)
|
||||
{
|
||||
size_t total_size = 0;
|
||||
if(curl_formget(post, &total_size, print_httppost_callback)) {
|
||||
return (size_t) -1;
|
||||
}
|
||||
return total_size;
|
||||
}
|
||||
size_t print_httppost(struct curl_httppost *post)
|
||||
{
|
||||
size_t total_size = 0;
|
||||
if(curl_formget(post, &total_size, print_httppost_callback)) {
|
||||
return (size_t) -1;
|
||||
}
|
||||
return total_size;
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
This function was added in libcurl 7.15.5. The form API is deprecated in
|
||||
libcurl 7.56.0.
|
||||
|
@ -39,11 +39,14 @@ Passing in a NULL pointer in \fIptr\fP makes this function return immediately
|
||||
with no action.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int main(void)
|
||||
{
|
||||
char *width = curl_getenv("COLUMNS");
|
||||
if(width) {
|
||||
/* it was set! */
|
||||
curl_free(width);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Always
|
||||
|
@ -70,29 +70,32 @@ year, MM as the month number and DD as the day of the month, for the specified
|
||||
calendar date.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
time_t t;
|
||||
t = curl_getdate("Sun, 06 Nov 1994 08:49:37 GMT", NULL);
|
||||
t = curl_getdate("Sunday, 06-Nov-94 08:49:37 GMT", NULL);
|
||||
t = curl_getdate("Sun Nov 6 08:49:37 1994", NULL);
|
||||
t = curl_getdate("06 Nov 1994 08:49:37 GMT", NULL);
|
||||
t = curl_getdate("06-Nov-94 08:49:37 GMT", NULL);
|
||||
t = curl_getdate("Nov 6 08:49:37 1994", NULL);
|
||||
t = curl_getdate("06 Nov 1994 08:49:37", NULL);
|
||||
t = curl_getdate("06-Nov-94 08:49:37", NULL);
|
||||
t = curl_getdate("1994 Nov 6 08:49:37", NULL);
|
||||
t = curl_getdate("GMT 08:49:37 06-Nov-94 Sunday", NULL);
|
||||
t = curl_getdate("94 6 Nov 08:49:37", NULL);
|
||||
t = curl_getdate("1994 Nov 6", NULL);
|
||||
t = curl_getdate("06-Nov-94", NULL);
|
||||
t = curl_getdate("Sun Nov 6 94", NULL);
|
||||
t = curl_getdate("1994.Nov.6", NULL);
|
||||
t = curl_getdate("Sun/Nov/6/94/GMT", NULL);
|
||||
t = curl_getdate("Sun, 06 Nov 1994 08:49:37 CET", NULL);
|
||||
t = curl_getdate("06 Nov 1994 08:49:37 EST", NULL);
|
||||
t = curl_getdate("Sun, 12 Sep 2004 15:05:58 -0700", NULL);
|
||||
t = curl_getdate("Sat, 11 Sep 2004 21:32:11 +0200", NULL);
|
||||
t = curl_getdate("20040912 15:05:58 -0700", NULL);
|
||||
t = curl_getdate("20040911 +0200", NULL);
|
||||
int main(void)
|
||||
{
|
||||
time_t t;
|
||||
t = curl_getdate("Sun, 06 Nov 1994 08:49:37 GMT", NULL);
|
||||
t = curl_getdate("Sunday, 06-Nov-94 08:49:37 GMT", NULL);
|
||||
t = curl_getdate("Sun Nov 6 08:49:37 1994", NULL);
|
||||
t = curl_getdate("06 Nov 1994 08:49:37 GMT", NULL);
|
||||
t = curl_getdate("06-Nov-94 08:49:37 GMT", NULL);
|
||||
t = curl_getdate("Nov 6 08:49:37 1994", NULL);
|
||||
t = curl_getdate("06 Nov 1994 08:49:37", NULL);
|
||||
t = curl_getdate("06-Nov-94 08:49:37", NULL);
|
||||
t = curl_getdate("1994 Nov 6 08:49:37", NULL);
|
||||
t = curl_getdate("GMT 08:49:37 06-Nov-94 Sunday", NULL);
|
||||
t = curl_getdate("94 6 Nov 08:49:37", NULL);
|
||||
t = curl_getdate("1994 Nov 6", NULL);
|
||||
t = curl_getdate("06-Nov-94", NULL);
|
||||
t = curl_getdate("Sun Nov 6 94", NULL);
|
||||
t = curl_getdate("1994.Nov.6", NULL);
|
||||
t = curl_getdate("Sun/Nov/6/94/GMT", NULL);
|
||||
t = curl_getdate("Sun, 06 Nov 1994 08:49:37 CET", NULL);
|
||||
t = curl_getdate("06 Nov 1994 08:49:37 EST", NULL);
|
||||
t = curl_getdate("Sun, 12 Sep 2004 15:05:58 -0700", NULL);
|
||||
t = curl_getdate("Sat, 11 Sep 2004 21:32:11 +0200", NULL);
|
||||
t = curl_getdate("20040912 15:05:58 -0700", NULL);
|
||||
t = curl_getdate("20040911 +0200", NULL);
|
||||
}
|
||||
.fi
|
||||
.SH STANDARDS
|
||||
This parser handles date formats specified in RFC 822 (including the update in
|
||||
|
@ -38,11 +38,14 @@ systems libcurl builds on (including win32).
|
||||
You must \fIcurl_free(3)\fP the returned string when you are done with it.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int main(void)
|
||||
{
|
||||
char *width = curl_getenv("COLUMNS");
|
||||
if(width) {
|
||||
/* it was set! */
|
||||
curl_free(width);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Always
|
||||
|
@ -58,11 +58,14 @@ recommend you do not run libcurl from any module that may be unloaded
|
||||
dynamically. This behavior may be addressed in the future.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
int main(void)
|
||||
{
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
|
||||
/* use libcurl, then before exiting... */
|
||||
/* use libcurl, then before exiting... */
|
||||
|
||||
curl_global_cleanup();
|
||||
curl_global_cleanup();
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.8
|
||||
|
@ -101,11 +101,14 @@ connecting or when waiting for data. Otherwise, curl waits until full timeout
|
||||
elapses. (Added in 7.30.0)
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
int main(void)
|
||||
{
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
|
||||
/* use libcurl, then before exiting... */
|
||||
/* use libcurl, then before exiting... */
|
||||
|
||||
curl_global_cleanup();
|
||||
curl_global_cleanup();
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.8
|
||||
|
@ -65,9 +65,18 @@ Manipulating these gives considerable powers to the application to severely
|
||||
screw things up for libcurl. Take care!
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl_global_init_mem(CURL_GLOBAL_DEFAULT, curl_malloc_cb,
|
||||
curl_free_cb, curl_realloc_cb,
|
||||
curl_strdup_cb, curl_calloc_cb);
|
||||
extern void *malloc_cb(size_t);
|
||||
extern void free_cb(void *);
|
||||
extern void *realloc_cb(void *, size_t);
|
||||
extern char *strdup_cb(const char *);
|
||||
extern void *calloc_cb(size_t, size_t);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
curl_global_init_mem(CURL_GLOBAL_DEFAULT, malloc_cb,
|
||||
free_cb, realloc_cb,
|
||||
strdup_cb, calloc_cb);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.12.0
|
||||
|
@ -103,6 +103,9 @@ typedef enum {
|
||||
.fi
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
/* choose a specific backend */
|
||||
curl_global_sslset(CURLSSLBACKEND_WOLFSSL, NULL, NULL);
|
||||
|
||||
@ -113,6 +116,7 @@ typedef enum {
|
||||
for(i = 0; list[i]; i++)
|
||||
printf("SSL backend #%d: '%s' (ID: %d)\\n",
|
||||
i, list[i]->name, list[i]->id);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
This function was added in libcurl 7.56.0. Before this version, there was no
|
||||
|
@ -91,11 +91,14 @@ trace.
|
||||
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
/* log details of HTTP/2 and SSL handling */
|
||||
curl_global_trace("http/2,ssl");
|
||||
int main(void)
|
||||
{
|
||||
/* log details of HTTP/2 and SSL handling */
|
||||
curl_global_trace("http/2,ssl");
|
||||
|
||||
/* log all details, except SSL handling */
|
||||
curl_global_trace("all,-ssl");
|
||||
/* log all details, except SSL handling */
|
||||
curl_global_trace("all,-ssl");
|
||||
}
|
||||
.fi
|
||||
|
||||
Below is a trace sample where "http/2" was configured. The trace output
|
||||
|
@ -39,18 +39,24 @@ subsequently be populated using functions from the mime API.
|
||||
appended.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
int main(void)
|
||||
{
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
|
||||
/* create a mime handle */
|
||||
mime = curl_mime_init(easy);
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
/* create a mime handle */
|
||||
mime = curl_mime_init(curl);
|
||||
|
||||
/* add a part */
|
||||
part = curl_mime_addpart(mime);
|
||||
/* add a part */
|
||||
part = curl_mime_addpart(mime);
|
||||
|
||||
/* continue and set name + data to the part */
|
||||
curl_mime_data(part, "This is the field data", CURL_ZERO_TERMINATED);
|
||||
curl_mime_name(part, "data");
|
||||
/* continue and set name + data to the part */
|
||||
curl_mime_data(part, "This is the field data", CURL_ZERO_TERMINATED);
|
||||
curl_mime_name(part, "data");
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
|
||||
|
@ -52,17 +52,23 @@ Setting large data is memory consuming: one might consider using
|
||||
\fIcurl_mime_data_cb(3)\fP in such a case.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
int main(void)
|
||||
{
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
|
||||
/* create a mime handle */
|
||||
mime = curl_mime_init(easy);
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
/* create a mime handle */
|
||||
mime = curl_mime_init(curl);
|
||||
|
||||
/* add a part */
|
||||
part = curl_mime_addpart(mime);
|
||||
/* add a part */
|
||||
part = curl_mime_addpart(mime);
|
||||
|
||||
/* add data to the part */
|
||||
curl_mime_data(part, "raw contents to send", CURL_ZERO_TERMINATED);
|
||||
/* add data to the part */
|
||||
curl_mime_data(part, "raw contents to send", CURL_ZERO_TERMINATED);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
|
||||
|
@ -104,7 +104,7 @@ to avoid overhead resources consumption, one might want to use a callback
|
||||
source to avoid data duplication. In this case, original data must be retained
|
||||
until after the transfer terminates.
|
||||
.nf
|
||||
|
||||
#include <string.h> /* for memcpy */
|
||||
char hugedata[512000];
|
||||
|
||||
struct ctl {
|
||||
@ -146,17 +146,22 @@ int seek_callback(void *arg, curl_off_t offset, int origin)
|
||||
return CURL_SEEKFUNC_OK;
|
||||
}
|
||||
|
||||
CURL *easy = curl_easy_init();
|
||||
curl_mime *mime = curl_mime_init(easy);
|
||||
curl_mimepart *part = curl_mime_addpart(mime);
|
||||
struct ctl hugectl;
|
||||
|
||||
hugectl.buffer = hugedata;
|
||||
hugectl.size = sizeof hugedata;
|
||||
hugectl.position = 0;
|
||||
curl_mime_data_cb(part, hugectl.size, read_callback, seek_callback, NULL,
|
||||
&hugectl);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_mime *mime = curl_mime_init(curl);
|
||||
curl_mimepart *part = curl_mime_addpart(mime);
|
||||
struct ctl hugectl;
|
||||
|
||||
hugectl.buffer = hugedata;
|
||||
hugectl.size = sizeof(hugedata);
|
||||
hugectl.position = 0;
|
||||
curl_mime_data_cb(part, hugectl.size, read_callback, seek_callback, NULL,
|
||||
&hugectl);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
|
||||
.SH RETURN VALUE
|
||||
|
@ -74,20 +74,26 @@ a part with content set with \fIcurl_mime_subparts(3)\fP is strongly
|
||||
discouraged.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
int main(void)
|
||||
{
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
|
||||
/* create a mime handle */
|
||||
mime = curl_mime_init(easy);
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
/* create a mime handle */
|
||||
mime = curl_mime_init(curl);
|
||||
|
||||
/* add a part */
|
||||
part = curl_mime_addpart(mime);
|
||||
/* add a part */
|
||||
part = curl_mime_addpart(mime);
|
||||
|
||||
/* send a file */
|
||||
curl_mime_filedata(part, "image.png");
|
||||
/* send a file */
|
||||
curl_mime_filedata(part, "image.png");
|
||||
|
||||
/* encode file data in base64 for transfer */
|
||||
curl_mime_encoder(part, "base64");
|
||||
/* encode file data in base64 for transfer */
|
||||
curl_mime_encoder(part, "base64");
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
|
||||
|
@ -58,20 +58,26 @@ Setting a part's contents multiple times is valid: only the value set by the
|
||||
last call is retained.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
int main(void)
|
||||
{
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
|
||||
/* create a mime handle */
|
||||
mime = curl_mime_init(easy);
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
/* create a mime handle */
|
||||
mime = curl_mime_init(curl);
|
||||
|
||||
/* add a part */
|
||||
part = curl_mime_addpart(mime);
|
||||
/* add a part */
|
||||
part = curl_mime_addpart(mime);
|
||||
|
||||
/* send data from this file */
|
||||
curl_mime_filedata(part, "image.png");
|
||||
/* send data from this file */
|
||||
curl_mime_filedata(part, "image.png");
|
||||
|
||||
/* set name */
|
||||
curl_mime_name(part, "data");
|
||||
/* set name */
|
||||
curl_mime_name(part, "data");
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
|
||||
|
@ -47,23 +47,32 @@ storage may safely be released or reused after call. Setting a part's file
|
||||
name multiple times is valid: only the value set by the last call is retained.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
|
||||
/* create a mime handle */
|
||||
mime = curl_mime_init(easy);
|
||||
static char imagebuf[]="imagedata";
|
||||
|
||||
/* add a part */
|
||||
part = curl_mime_addpart(mime);
|
||||
int main(void)
|
||||
{
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
|
||||
/* send image data from memory */
|
||||
curl_mime_data(part, imagebuf, imagebuf_len);
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
/* create a mime handle */
|
||||
mime = curl_mime_init(curl);
|
||||
|
||||
/* set a file name to make it look like a file upload */
|
||||
curl_mime_filename(part, "image.png");
|
||||
/* add a part */
|
||||
part = curl_mime_addpart(mime);
|
||||
|
||||
/* set name */
|
||||
curl_mime_name(part, "data");
|
||||
/* send image data from memory */
|
||||
curl_mime_data(part, imagebuf, sizeof(imagebuf));
|
||||
|
||||
/* set a file name to make it look like a file upload */
|
||||
curl_mime_filename(part, "image.png");
|
||||
|
||||
/* set name */
|
||||
curl_mime_name(part, "data");
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
|
||||
|
@ -47,13 +47,19 @@ Passing in a NULL pointer in \fImime\fP makes this function return immediately
|
||||
with no action.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
/* Build the mime message. */
|
||||
mime = curl_mime_init(curl);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
/* Build the mime message. */
|
||||
curl_mime *mime = curl_mime_init(curl);
|
||||
|
||||
/* ... */
|
||||
/* send off the transfer */
|
||||
|
||||
/* Free multipart message. */
|
||||
curl_mime_free(mime);
|
||||
/* Free multipart message. */
|
||||
curl_mime_free(mime);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
|
||||
|
@ -47,18 +47,32 @@ Setting a part's custom headers list multiple times is valid: only the value
|
||||
set by the last call is retained.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
struct curl_slist *headers = NULL;
|
||||
int main(void)
|
||||
{
|
||||
struct curl_slist *headers = NULL;
|
||||
CURL *easy = curl_easy_init();
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
|
||||
headers = curl_slist_append(headers, "Custom-Header: mooo");
|
||||
headers = curl_slist_append(headers, "Custom-Header: mooo");
|
||||
|
||||
/* use these headers, please take ownership */
|
||||
curl_mime_headers(part, headers, TRUE);
|
||||
mime = curl_mime_init(easy);
|
||||
part = curl_mime_addpart(mime);
|
||||
|
||||
/* pass on this data */
|
||||
curl_mime_data(part, "12345679", CURL_ZERO_TERMINATED);
|
||||
/* use these headers in the part, takes ownership */
|
||||
curl_mime_headers(part, headers, 1);
|
||||
|
||||
/* set name */
|
||||
curl_mime_name(part, "numbers");
|
||||
/* pass on this data */
|
||||
curl_mime_data(part, "12345679", CURL_ZERO_TERMINATED);
|
||||
|
||||
/* set name */
|
||||
curl_mime_name(part, "numbers");
|
||||
|
||||
/* Post and send it. */
|
||||
curl_easy_setopt(easy, CURLOPT_MIMEPOST, mime);
|
||||
curl_easy_setopt(easy, CURLOPT_URL, "https://example.com");
|
||||
curl_easy_perform(easy);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
|
||||
|
@ -44,24 +44,28 @@ Using a mime handle is the recommended way to post an HTTP form, format and
|
||||
send a multi-part email with SMTP or upload such an email to an IMAP server.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *easy = curl_easy_init();
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
int main(void)
|
||||
{
|
||||
CURL *easy = curl_easy_init();
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
|
||||
/* Build an HTTP form with a single field named "data", */
|
||||
mime = curl_mime_init(easy);
|
||||
part = curl_mime_addpart(mime);
|
||||
curl_mime_data(part, "This is the field data", CURL_ZERO_TERMINATED);
|
||||
curl_mime_name(part, "data");
|
||||
/* Build an HTTP form with a single field named "data", */
|
||||
mime = curl_mime_init(easy);
|
||||
part = curl_mime_addpart(mime);
|
||||
curl_mime_data(part, "This is the field data", CURL_ZERO_TERMINATED);
|
||||
curl_mime_name(part, "data");
|
||||
|
||||
/* Post and send it. */
|
||||
curl_easy_setopt(easy, CURLOPT_MIMEPOST, mime);
|
||||
curl_easy_setopt(easy, CURLOPT_URL, "https://example.com");
|
||||
curl_easy_perform(easy);
|
||||
/* Post and send it. */
|
||||
curl_easy_setopt(easy, CURLOPT_MIMEPOST, mime);
|
||||
curl_easy_setopt(easy, CURLOPT_URL, "https://example.com");
|
||||
curl_easy_perform(easy);
|
||||
|
||||
/* Clean-up. */
|
||||
curl_easy_cleanup(easy);
|
||||
curl_mime_free(mime);
|
||||
/* Clean-up. */
|
||||
curl_easy_cleanup(easy);
|
||||
curl_mime_free(mime);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
|
||||
.SH RETURN VALUE
|
||||
|
@ -44,17 +44,23 @@ is valid: only the value set by the last call is retained. It is possible to
|
||||
reset the name of a part by setting \fIname\fP to NULL.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
int main(void)
|
||||
{
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
|
||||
/* create a mime handle */
|
||||
mime = curl_mime_init(easy);
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
/* create a mime handle */
|
||||
mime = curl_mime_init(curl);
|
||||
|
||||
/* add a part */
|
||||
part = curl_mime_addpart(mime);
|
||||
/* add a part */
|
||||
part = curl_mime_addpart(mime);
|
||||
|
||||
/* give the part a name */
|
||||
curl_mime_name(part, "shoe_size");
|
||||
/* give the part a name */
|
||||
curl_mime_name(part, "shoe_size");
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
|
||||
|
@ -46,25 +46,38 @@ last call is retained. It is possible to unassign previous part's contents by
|
||||
setting \fIsubparts\fP to NULL.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
/* The inline part is an alternative proposing the html and the text
|
||||
versions of the email. */
|
||||
alt = curl_mime_init(curl);
|
||||
|
||||
/* HTML message. */
|
||||
part = curl_mime_addpart(alt);
|
||||
curl_mime_data(part, inline_html, CURL_ZERO_TERMINATED);
|
||||
curl_mime_type(part, "text/html");
|
||||
static char *inline_html = "<title>example</title>";
|
||||
static char *inline_text = "once upon the time";
|
||||
|
||||
/* Text message. */
|
||||
part = curl_mime_addpart(alt);
|
||||
curl_mime_data(part, inline_text, CURL_ZERO_TERMINATED);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
struct curl_slist *slist;
|
||||
|
||||
/* Create the inline part. */
|
||||
part = curl_mime_addpart(mime);
|
||||
curl_mime_subparts(part, alt);
|
||||
curl_mime_type(part, "multipart/alternative");
|
||||
slist = curl_slist_append(NULL, "Content-Disposition: inline");
|
||||
curl_mime_headers(part, slist, 1);
|
||||
/* The inline part is an alternative proposing the html and the text
|
||||
versions of the email. */
|
||||
curl_mime *alt = curl_mime_init(curl);
|
||||
curl_mimepart *part;
|
||||
|
||||
/* HTML message. */
|
||||
part = curl_mime_addpart(alt);
|
||||
curl_mime_data(part, inline_html, CURL_ZERO_TERMINATED);
|
||||
curl_mime_type(part, "text/html");
|
||||
|
||||
/* Text message. */
|
||||
part = curl_mime_addpart(alt);
|
||||
curl_mime_data(part, inline_text, CURL_ZERO_TERMINATED);
|
||||
|
||||
/* Create the inline part. */
|
||||
part = curl_mime_addpart(alt);
|
||||
curl_mime_subparts(part, alt);
|
||||
curl_mime_type(part, "multipart/alternative");
|
||||
slist = curl_slist_append(NULL, "Content-Disposition: inline");
|
||||
curl_mime_headers(part, slist, 1);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
|
||||
|
@ -57,23 +57,29 @@ extension, or application/octet-stream by default.
|
||||
- text/plain in other cases.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
int main(void)
|
||||
{
|
||||
curl_mime *mime;
|
||||
curl_mimepart *part;
|
||||
|
||||
/* create a mime handle */
|
||||
mime = curl_mime_init(easy);
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
/* create a mime handle */
|
||||
mime = curl_mime_init(curl);
|
||||
|
||||
/* add a part */
|
||||
part = curl_mime_addpart(mime);
|
||||
/* add a part */
|
||||
part = curl_mime_addpart(mime);
|
||||
|
||||
/* get data from this file */
|
||||
curl_mime_filedata(part, "image.png");
|
||||
/* get data from this file */
|
||||
curl_mime_filedata(part, "image.png");
|
||||
|
||||
/* content-type for this part */
|
||||
curl_mime_type(part, "image/png");
|
||||
/* content-type for this part */
|
||||
curl_mime_type(part, "image/png");
|
||||
|
||||
/* set name */
|
||||
curl_mime_name(part, "image");
|
||||
/* set name */
|
||||
curl_mime_name(part, "image");
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0.
|
||||
|
@ -237,8 +237,13 @@ by the corresponding argument.
|
||||
A '%' is written. No argument is converted.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
const char *name = "John";
|
||||
|
||||
int main(void)
|
||||
{
|
||||
curl_mprintf("My name is %s\\n", name);
|
||||
curl_mprintf("Pi is almost %f\\n", 25/8);
|
||||
curl_mprintf("Pi is almost %f\\n", (double)25.0/8);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
These functions might be removed from the public libcurl API in the future. Do
|
||||
|
@ -67,12 +67,19 @@ first the easy handle and then the multi handle:
|
||||
3 - \fIcurl_multi_cleanup(3)\fP
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int main(void)
|
||||
{
|
||||
/* init a multi stack */
|
||||
multi_handle = curl_multi_init();
|
||||
CURLM *multi = curl_multi_init();
|
||||
|
||||
/* create two easy handles */
|
||||
CURL *http_handle = curl_easy_init();
|
||||
CURL *http_handle2 = curl_easy_init();
|
||||
|
||||
/* add individual transfers */
|
||||
curl_multi_add_handle(multi_handle, http_handle);
|
||||
curl_multi_add_handle(multi_handle, http_handle2);
|
||||
curl_multi_add_handle(multi, http_handle);
|
||||
curl_multi_add_handle(multi, http_handle2);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.9.6
|
||||
|
@ -54,8 +54,17 @@ functionality.
|
||||
It is acceptable to call this function from your multi callback functions.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
/* make our struct pointer associated with socket fd */
|
||||
mc = curl_multi_assign(multi_handle, fd, ourstructp);
|
||||
int main(void)
|
||||
{
|
||||
CURLM *multi = curl_multi_init();
|
||||
void *ourstructp; /* pointer to our data */
|
||||
curl_socket_t fd; /* file descriptor to associate our data with */
|
||||
|
||||
/* make our struct pointer associated with socket fd */
|
||||
CURLMcode mc = curl_multi_assign(multi, fd, ourstructp);
|
||||
if(mc)
|
||||
printf("error: %s\\n", curl_multi_strerror(mc));
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.15.5
|
||||
|
@ -48,10 +48,15 @@ Passing in a NULL pointer in \fImulti_handle\fP makes this function return
|
||||
CURLM_BAD_HANDLE immediately with no other action.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
/* when the multi transfer is done ... */
|
||||
int main(void)
|
||||
{
|
||||
CURLM *multi = curl_multi_init();
|
||||
|
||||
/* remove all easy handles, then: */
|
||||
curl_multi_cleanup(multi_handle);
|
||||
/* when the multi transfer is done ... */
|
||||
|
||||
/* remove all easy handles, then: */
|
||||
curl_multi_cleanup(multi);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.9.6
|
||||
|
@ -80,16 +80,35 @@ save you from the crash, but makes your program NOT wait for sockets it should
|
||||
wait for...
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
/* get file descriptors from the transfers */
|
||||
mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
|
||||
int main(void)
|
||||
{
|
||||
fd_set fdread;
|
||||
fd_set fdwrite;
|
||||
fd_set fdexcep;
|
||||
int maxfd;
|
||||
int rc;
|
||||
CURLMcode mc;
|
||||
struct timeval timeout = {1, 0};
|
||||
|
||||
if(mc != CURLM_OK) {
|
||||
fprintf(stderr, "curl_multi_fdset() failed, code %d.\\n", mc);
|
||||
break;
|
||||
}
|
||||
CURLM *multi = curl_multi_init();
|
||||
|
||||
/* wait for activity on one of the sockets */
|
||||
rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
|
||||
do {
|
||||
|
||||
/* call curl_multi_perform() */
|
||||
|
||||
/* get file descriptors from the transfers */
|
||||
mc = curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
|
||||
|
||||
if(mc != CURLM_OK) {
|
||||
fprintf(stderr, "curl_multi_fdset() failed, code %d.\\n", mc);
|
||||
break;
|
||||
}
|
||||
|
||||
/* wait for activity on one of the sockets */
|
||||
rc = select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
|
||||
|
||||
} while(!mc);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.9.6
|
||||
|
@ -47,22 +47,29 @@ The order of the easy handles within the array is not guaranteed.
|
||||
The returned array must be freed with a call to \fIcurl_free(3)\fP after use.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int main(void)
|
||||
{
|
||||
/* init a multi stack */
|
||||
multi_handle = curl_multi_init();
|
||||
CURLM *multi = curl_multi_init();
|
||||
CURL *curl = curl_easy_init();
|
||||
|
||||
/* add a transfer */
|
||||
curl_multi_add_handle(multi_handle, http_handle);
|
||||
if(curl) {
|
||||
/* add the transfer */
|
||||
curl_multi_add_handle(multi, curl);
|
||||
|
||||
/* extract all added handles */
|
||||
CURL **list = curl_multi_get_handles(multi_handle);
|
||||
/* extract all added handles */
|
||||
CURL **list = curl_multi_get_handles(multi);
|
||||
|
||||
if(list) {
|
||||
/* remove all added handles */
|
||||
for(i = 0; list[i]; i++) {
|
||||
curl_multi_remove_handle(multi_handle, list[i]);
|
||||
if(list) {
|
||||
int i;
|
||||
/* remove all added handles */
|
||||
for(i = 0; list[i]; i++) {
|
||||
curl_multi_remove_handle(multi, list[i]);
|
||||
}
|
||||
curl_free(list);
|
||||
}
|
||||
curl_free(list);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 8.4.0
|
||||
|
@ -72,21 +72,28 @@ that just completed.
|
||||
At this point, there are no other \fBmsg\fP types defined.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
struct CURLMsg *m;
|
||||
int main(void)
|
||||
{
|
||||
CURLM *multi = curl_multi_init();
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
struct CURLMsg *m;
|
||||
|
||||
/* call curl_multi_perform or curl_multi_socket_action first, then loop
|
||||
through and check if there are any transfers that have completed */
|
||||
/* call curl_multi_perform or curl_multi_socket_action first, then loop
|
||||
through and check if there are any transfers that have completed */
|
||||
|
||||
do {
|
||||
int msgq = 0;
|
||||
m = curl_multi_info_read(multi_handle, &msgq);
|
||||
if(m && (m->msg == CURLMSG_DONE)) {
|
||||
CURL *e = m->easy_handle;
|
||||
transfers--;
|
||||
curl_multi_remove_handle(multi_handle, e);
|
||||
curl_easy_cleanup(e);
|
||||
do {
|
||||
int msgq = 0;
|
||||
m = curl_multi_info_read(multi, &msgq);
|
||||
if(m && (m->msg == CURLMSG_DONE)) {
|
||||
CURL *e = m->easy_handle;
|
||||
/* m->data.result holds the error code for the transfer */
|
||||
curl_multi_remove_handle(multi, e);
|
||||
curl_easy_cleanup(e);
|
||||
}
|
||||
} while(m);
|
||||
}
|
||||
} while(m);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.9.6
|
||||
|
@ -37,12 +37,17 @@ places in the documentation. This init call MUST have a corresponding call to
|
||||
\fIcurl_multi_cleanup(3)\fP when the operation is complete.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
/* init a multi stack */
|
||||
multi_handle = curl_multi_init();
|
||||
int main(void)
|
||||
{
|
||||
/* init a multi stack */
|
||||
CURLM *multi = curl_multi_init();
|
||||
CURL *curl = curl_easy_init();
|
||||
CURL *curl2 = curl_easy_init();
|
||||
|
||||
/* add individual transfers */
|
||||
curl_multi_add_handle(multi_handle, http_handle);
|
||||
curl_multi_add_handle(multi_handle, http_handle2);
|
||||
/* add individual transfers */
|
||||
curl_multi_add_handle(multi, curl);
|
||||
curl_multi_add_handle(multi, curl2);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.9.6
|
||||
|
@ -62,21 +62,29 @@ again on the same multi handle after an error has been returned, unless first
|
||||
removing all the handles and adding new ones.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int still_running;
|
||||
do {
|
||||
CURLMcode mc = curl_multi_perform(multi_handle, &still_running);
|
||||
int main(void)
|
||||
{
|
||||
int still_running;
|
||||
CURL *multi = curl_multi_init();
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_multi_add_handle(multi, curl);
|
||||
do {
|
||||
CURLMcode mc = curl_multi_perform(multi, &still_running);
|
||||
|
||||
if(!mc && still_running)
|
||||
/* wait for activity, timeout or "nothing" */
|
||||
mc = curl_multi_poll(multi_handle, NULL, 0, 1000, NULL);
|
||||
if(!mc && still_running)
|
||||
/* wait for activity, timeout or "nothing" */
|
||||
mc = curl_multi_poll(multi, NULL, 0, 1000, NULL);
|
||||
|
||||
if(mc) {
|
||||
fprintf(stderr, "curl_multi_poll() failed, code %d.\\n", (int)mc);
|
||||
break;
|
||||
if(mc) {
|
||||
fprintf(stderr, "curl_multi_poll() failed, code %d.\\n", (int)mc);
|
||||
break;
|
||||
}
|
||||
|
||||
/* if there are still transfers, loop! */
|
||||
} while(still_running);
|
||||
}
|
||||
|
||||
/* if there are still transfers, loop! */
|
||||
} while(still_running);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.9.6
|
||||
|
@ -83,31 +83,35 @@ Bit flag to curl_waitfd.events indicating the socket should poll on write
|
||||
events such as the socket being clear to write without blocking.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *easy_handle;
|
||||
CURLM *multi_handle;
|
||||
int main(void)
|
||||
{
|
||||
CURL *easy_handle;
|
||||
CURLM *multi_handle;
|
||||
int still_running = 0;
|
||||
|
||||
/* add the individual easy handle */
|
||||
curl_multi_add_handle(multi_handle, easy_handle);
|
||||
/* add the individual easy handle */
|
||||
curl_multi_add_handle(multi_handle, easy_handle);
|
||||
|
||||
do {
|
||||
CURLMcode mc;
|
||||
int numfds;
|
||||
do {
|
||||
CURLMcode mc;
|
||||
int numfds;
|
||||
|
||||
mc = curl_multi_perform(multi_handle, &still_running);
|
||||
mc = curl_multi_perform(multi_handle, &still_running);
|
||||
|
||||
if(mc == CURLM_OK) {
|
||||
/* wait for activity or timeout */
|
||||
mc = curl_multi_poll(multi_handle, NULL, 0, 1000, &numfds);
|
||||
}
|
||||
if(mc == CURLM_OK) {
|
||||
/* wait for activity or timeout */
|
||||
mc = curl_multi_poll(multi_handle, NULL, 0, 1000, &numfds);
|
||||
}
|
||||
|
||||
if(mc != CURLM_OK) {
|
||||
fprintf(stderr, "curl_multi failed, code %d.\\n", mc);
|
||||
break;
|
||||
}
|
||||
if(mc != CURLM_OK) {
|
||||
fprintf(stderr, "curl_multi failed, code %d.\\n", mc);
|
||||
break;
|
||||
}
|
||||
|
||||
} while(still_running);
|
||||
} while(still_running);
|
||||
|
||||
curl_multi_remove_handle(multi_handle, easy_handle);
|
||||
curl_multi_remove_handle(multi_handle, easy_handle);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.66.0.
|
||||
|
@ -52,13 +52,19 @@ multi handle, ready to get reused for a future transfer using this multi
|
||||
handle.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
/* when an easy handle has completed, remove it */
|
||||
msg = curl_multi_info_read(multi_handle, &queued);
|
||||
if(msg) {
|
||||
if(msg->msg == CURLMSG_DONE) {
|
||||
/* a transfer ended */
|
||||
fprintf(stderr, "Transfer completed\\n");
|
||||
curl_multi_remove_handle(multi_handle, msg->easy_handle);
|
||||
int main(void)
|
||||
{
|
||||
CURLM *multi = curl_multi_init();
|
||||
int queued = 0;
|
||||
|
||||
/* when an easy handle has completed, remove it */
|
||||
CURLMsg *msg = curl_multi_info_read(multi, &queued);
|
||||
if(msg) {
|
||||
if(msg->msg == CURLMSG_DONE) {
|
||||
/* a transfer ended */
|
||||
fprintf(stderr, "Transfer completed\\n");
|
||||
curl_multi_remove_handle(multi, msg->easy_handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
.fi
|
||||
|
@ -74,10 +74,17 @@ See \fICURLMOPT_TIMERDATA(3)\fP
|
||||
.IP CURLMOPT_MAX_CONCURRENT_STREAMS
|
||||
See \fICURLMOPT_MAX_CONCURRENT_STREAMS(3)\fP
|
||||
.SH EXAMPLE
|
||||
.fi
|
||||
/* Limit the amount of simultaneous connections curl should allow: */
|
||||
curl_multi_setopt(handle, CURLMOPT_MAXCONNECTS, (long)MAX_PARALLEL);
|
||||
.nf
|
||||
|
||||
#define MAX_PARALLEL 45
|
||||
|
||||
int main(void)
|
||||
{
|
||||
CURLM *multi;
|
||||
/* Limit the amount of simultaneous connections curl should allow: */
|
||||
curl_multi_setopt(multi, CURLMOPT_MAXCONNECTS, (long)MAX_PARALLEL);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.15.4
|
||||
.SH RETURN VALUE
|
||||
|
@ -70,10 +70,16 @@ just a single one by calling \fIcurl_multi_socket_all(3)\fP. Note that there
|
||||
should not be any reason to use this function.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
/* the event-library gets told when there activity on the socket 'fd',
|
||||
which we translate to a call to curl_multi_socket_action() */
|
||||
int running;
|
||||
rc = curl_multi_socket(multi_handle, fd, &running);
|
||||
int main(void)
|
||||
{
|
||||
/* the event-library gets told when there activity on the socket 'fd',
|
||||
which we translate to a call to curl_multi_socket_action() */
|
||||
int running;
|
||||
int rc;
|
||||
int fd;
|
||||
CURLM *multi;
|
||||
rc = curl_multi_socket(multi, fd, &running);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
This function was added in libcurl 7.15.4, and is deemed stable since
|
||||
|
@ -97,11 +97,18 @@ socket(s) that got action. If no activity is detected and the timeout expires,
|
||||
call \fIcurl_multi_socket_action(3)\fP with \fICURL_SOCKET_TIMEOUT\fP.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
/* the event-library gets told when there activity on the socket 'fd',
|
||||
which we translate to a call to curl_multi_socket_action() */
|
||||
int running;
|
||||
rc = curl_multi_socket_action(multi_handle, fd, EVENT,
|
||||
&running);
|
||||
int main(void)
|
||||
{
|
||||
/* the event-library gets told when there activity on the socket 'fd',
|
||||
which we translate to a call to curl_multi_socket_action() */
|
||||
int running;
|
||||
CURLM *multi; /* the stack we work with */
|
||||
int fd; /* the descriptor that had action */
|
||||
int bitmask; /* what activity that happened */
|
||||
CURLMcode mc = curl_multi_socket_action(multi, fd, bitmask, &running);
|
||||
if(mc)
|
||||
printf("error: %s\\n", curl_multi_strerror(mc));
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
This function was added in libcurl 7.15.4, and is deemed stable since 7.16.0.
|
||||
|
@ -35,11 +35,15 @@ This function returns a string describing the \fICURLMcode\fP error code
|
||||
passed in the argument \fIerrornum\fP.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int still_running;
|
||||
int main(void)
|
||||
{
|
||||
int still_running;
|
||||
CURLM *multi = curl_multi_init();
|
||||
|
||||
CURLMcode mc = curl_multi_perform(multi_handle, &still_running);
|
||||
if(mc)
|
||||
printf("error: %s\\n", curl_multi_strerror(mc));
|
||||
CURLMcode mc = curl_multi_perform(multi, &still_running);
|
||||
if(mc)
|
||||
printf("error: %s\\n", curl_multi_strerror(mc));
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
This function was added in libcurl 7.12.0
|
||||
|
@ -54,19 +54,27 @@ currently has no stored timeout value. You must not wait too long (more than a
|
||||
few seconds perhaps) before you call \fIcurl_multi_perform(3)\fP again.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
struct timeval timeout;
|
||||
long timeo;
|
||||
int main(void)
|
||||
{
|
||||
struct timeval timeout;
|
||||
long timeo;
|
||||
fd_set fdread;
|
||||
fd_set fdwrite;
|
||||
fd_set fdexcep;
|
||||
int maxfd;
|
||||
CURLM *multi = curl_multi_init();
|
||||
|
||||
curl_multi_timeout(multi_handle, &timeo);
|
||||
if(timeo < 0)
|
||||
/* no set timeout, use a default */
|
||||
timeo = 980;
|
||||
curl_multi_timeout(multi, &timeo);
|
||||
if(timeo < 0)
|
||||
/* no set timeout, use a default */
|
||||
timeo = 980;
|
||||
|
||||
timeout.tv_sec = timeo / 1000;
|
||||
timeout.tv_usec = (timeo % 1000) * 1000;
|
||||
timeout.tv_sec = timeo / 1000;
|
||||
timeout.tv_usec = (timeo % 1000) * 1000;
|
||||
|
||||
/* wait for activities no longer than the set timeout */
|
||||
select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
|
||||
/* wait for activities no longer than the set timeout */
|
||||
select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
|
||||
}
|
||||
.fi
|
||||
.SH TYPICAL USAGE
|
||||
Call \fIcurl_multi_timeout(3)\fP, then wait for action on the sockets. Figure
|
||||
|
@ -77,45 +77,35 @@ Bit flag to \fIcurl_waitfd.events\fP indicating the socket should poll on
|
||||
write events such as the socket being clear to write without blocking.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *easy_handle;
|
||||
CURLM *multi_handle;
|
||||
int main(void)
|
||||
{
|
||||
CURL *easy;
|
||||
CURLM *multi = curl_multi_init();
|
||||
int still_running;
|
||||
|
||||
/* add the individual easy handle */
|
||||
curl_multi_add_handle(multi_handle, easy_handle);
|
||||
/* add the individual easy handle */
|
||||
curl_multi_add_handle(multi, easy);
|
||||
|
||||
do {
|
||||
CURLMcode mc;
|
||||
int numfds;
|
||||
do {
|
||||
CURLMcode mc;
|
||||
int numfds;
|
||||
|
||||
mc = curl_multi_perform(multi_handle, &still_running);
|
||||
mc = curl_multi_perform(multi, &still_running);
|
||||
|
||||
if(mc == CURLM_OK ) {
|
||||
/* wait for activity, timeout or "nothing" */
|
||||
mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
|
||||
}
|
||||
|
||||
if(mc != CURLM_OK) {
|
||||
fprintf(stderr, "curl_multi failed, code %d.\\n", mc);
|
||||
break;
|
||||
}
|
||||
|
||||
/* 'numfds' being zero means either a timeout or no file descriptors to
|
||||
wait for. Try timeout on first occurrence, then assume no file
|
||||
descriptors and no file descriptors to wait for means wait for 100
|
||||
milliseconds. */
|
||||
|
||||
if(!numfds) {
|
||||
repeats++; /* count number of repeated zero numfds */
|
||||
if(repeats > 1) {
|
||||
WAITMS(100); /* sleep 100 milliseconds */
|
||||
if(mc == CURLM_OK) {
|
||||
/* wait for activity, timeout or "nothing" */
|
||||
mc = curl_multi_wait(multi, NULL, 0, 1000, &numfds);
|
||||
}
|
||||
}
|
||||
else
|
||||
repeats = 0;
|
||||
|
||||
} while(still_running);
|
||||
if(mc != CURLM_OK) {
|
||||
fprintf(stderr, "curl_multi failed, code %d.\\n", mc);
|
||||
break;
|
||||
}
|
||||
|
||||
curl_multi_remove_handle(multi_handle, easy_handle);
|
||||
} while(still_running);
|
||||
|
||||
curl_multi_remove_handle(multi, easy);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
This function was added in libcurl 7.28.0.
|
||||
|
@ -45,40 +45,47 @@ that multiple calls to this function wake up the same waiting operation.
|
||||
This function has no effect on \fIcurl_multi_wait(3)\fP calls.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *easy_handle;
|
||||
CURLM *multi_handle;
|
||||
extern int time_to_die(void);
|
||||
extern int set_something_to_signal_thread_1_to_exit(void);
|
||||
extern int decide_to_stop_thread1();
|
||||
|
||||
/* add the individual easy handle */
|
||||
curl_multi_add_handle(multi_handle, easy_handle);
|
||||
int main(void)
|
||||
{
|
||||
CURL *easy;
|
||||
CURLM *multi;
|
||||
int still_running;
|
||||
|
||||
/* this is thread 1 */
|
||||
do {
|
||||
CURLMcode mc;
|
||||
int numfds;
|
||||
/* add the individual easy handle */
|
||||
curl_multi_add_handle(multi, easy);
|
||||
|
||||
mc = curl_multi_perform(multi_handle, &still_running);
|
||||
/* this is thread 1 */
|
||||
do {
|
||||
CURLMcode mc;
|
||||
int numfds;
|
||||
|
||||
if(mc == CURLM_OK) {
|
||||
/* wait for activity, timeout or wakeup */
|
||||
mc = curl_multi_poll(multi_handle, NULL, 0, 10000, &numfds);
|
||||
mc = curl_multi_perform(multi, &still_running);
|
||||
|
||||
if(mc == CURLM_OK) {
|
||||
/* wait for activity, timeout or wakeup */
|
||||
mc = curl_multi_poll(multi, NULL, 0, 10000, &numfds);
|
||||
}
|
||||
|
||||
if(time_to_die())
|
||||
return 1;
|
||||
|
||||
} while(still_running);
|
||||
|
||||
curl_multi_remove_handle(multi, easy);
|
||||
|
||||
/* this is thread 2 */
|
||||
|
||||
if(decide_to_stop_thread1()) {
|
||||
|
||||
set_something_to_signal_thread_1_to_exit();
|
||||
|
||||
curl_multi_wakeup(multi);
|
||||
}
|
||||
|
||||
if(time_to_die())
|
||||
exit(1);
|
||||
|
||||
} while(still_running);
|
||||
|
||||
curl_multi_remove_handle(multi_handle, easy_handle);
|
||||
|
||||
/* this is thread 2 */
|
||||
|
||||
if(something makes us decide to stop thread 1) {
|
||||
|
||||
set_something_to_signal_thread_1_to_exit();
|
||||
|
||||
curl_multi_wakeup(multi_handle);
|
||||
}
|
||||
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.68.0
|
||||
|
@ -43,11 +43,13 @@ one header field use the same name, this returns only the first one.
|
||||
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int curl_push_callback(CURL *parent,
|
||||
CURL *easy,
|
||||
size_t num_headers,
|
||||
struct curl_pushheaders *headers,
|
||||
void *clientp)
|
||||
#include <string.h> /* for strncmp */
|
||||
|
||||
static int push_cb(CURL *parent,
|
||||
CURL *easy,
|
||||
size_t num_headers,
|
||||
struct curl_pushheaders *headers,
|
||||
void *clientp)
|
||||
{
|
||||
char *headp;
|
||||
int *transfers = (int *)clientp;
|
||||
@ -69,8 +71,13 @@ int curl_push_callback(CURL *parent,
|
||||
return CURL_PUSH_DENY;
|
||||
}
|
||||
|
||||
curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, curl_push_callback);
|
||||
curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &counter);
|
||||
int main(void)
|
||||
{
|
||||
int counter;
|
||||
CURLM *multi = curl_multi_init();
|
||||
curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, push_cb);
|
||||
curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &counter);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.44.0
|
||||
|
@ -43,13 +43,13 @@ libcurl when this callback returns. The returned pointer points to a
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
/* output all the incoming push request headers */
|
||||
int curl_push_callback(CURL *parent,
|
||||
CURL *easy,
|
||||
size_t num_headers,
|
||||
struct curl_pushheaders *headers,
|
||||
void *clientp)
|
||||
static int push_cb(CURL *parent,
|
||||
CURL *easy,
|
||||
size_t num_headers,
|
||||
struct curl_pushheaders *headers,
|
||||
void *clientp)
|
||||
{
|
||||
sizt_t i = 0;
|
||||
int i = 0;
|
||||
char *field;
|
||||
do {
|
||||
field = curl_pushheader_bynum(headers, i);
|
||||
@ -60,7 +60,11 @@ int curl_push_callback(CURL *parent,
|
||||
return CURL_PUSH_OK; /* permission granted */
|
||||
}
|
||||
|
||||
curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, curl_push_callback);
|
||||
int main(void)
|
||||
{
|
||||
CURLM *multi = curl_multi_init();
|
||||
curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, push_cb);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.44.0
|
||||
|
@ -38,11 +38,14 @@ Passing in a NULL pointer in \fIshare_handle\fP makes this function return
|
||||
immediately with no action.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int main(void)
|
||||
{
|
||||
CURLSHcode sh;
|
||||
share = curl_share_init();
|
||||
CURLSH *share = curl_share_init();
|
||||
sh = curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
|
||||
/* use the share, then ... */
|
||||
curl_share_cleanup(share);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.10
|
||||
|
@ -42,11 +42,14 @@ This \fIshare handle\fP is what you pass to curl using the
|
||||
specific curl handle use the data in this share.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int main(void)
|
||||
{
|
||||
CURLSHcode sh;
|
||||
share = curl_share_init();
|
||||
CURLSH *share = curl_share_init();
|
||||
sh = curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
|
||||
if(sh)
|
||||
printf("Error: %s\\n", curl_share_strerror(sh));
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.10
|
||||
|
@ -45,11 +45,14 @@ See \fICURLSHOPT_UNSHARE(3)\fP.
|
||||
See \fICURLSHOPT_USERDATA(3)\fP.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int main(void)
|
||||
{
|
||||
CURLSHcode sh;
|
||||
share = curl_share_init();
|
||||
CURLSH *share = curl_share_init();
|
||||
sh = curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
|
||||
if(sh)
|
||||
printf("Error: %s\\n", curl_share_strerror(sh));
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.10
|
||||
|
@ -35,11 +35,14 @@ The \fIcurl_share_strerror(3)\fP function returns a string describing the
|
||||
\fICURLSHcode\fP error code passed in the argument \fIerrornum\fP.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int main(void)
|
||||
{
|
||||
CURLSHcode sh;
|
||||
share = curl_share_init();
|
||||
CURLSH *share = curl_share_init();
|
||||
sh = curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
|
||||
if(sh)
|
||||
printf("Error: %s\\n", curl_share_strerror(sh));
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
This function was added in libcurl 7.12.0
|
||||
|
@ -42,29 +42,32 @@ The list should be freed again (after usage) with
|
||||
\fIcurl_slist_free_all(3)\fP.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *handle;
|
||||
struct curl_slist *slist=NULL;
|
||||
struct curl_slist *temp=NULL;
|
||||
int main(void)
|
||||
{
|
||||
CURL *handle;
|
||||
struct curl_slist *slist = NULL;
|
||||
struct curl_slist *temp = NULL;
|
||||
|
||||
slist = curl_slist_append(slist, "pragma:");
|
||||
slist = curl_slist_append(slist, "pragma:");
|
||||
|
||||
if (slist == NULL)
|
||||
return -1;
|
||||
if(!slist)
|
||||
return -1;
|
||||
|
||||
temp = curl_slist_append(slist, "Accept:")
|
||||
temp = curl_slist_append(slist, "Accept:");
|
||||
|
||||
if (temp == NULL) {
|
||||
curl_slist_free_all(slist);
|
||||
return -1;
|
||||
if(!temp) {
|
||||
curl_slist_free_all(slist);
|
||||
return -1;
|
||||
}
|
||||
|
||||
slist = temp;
|
||||
|
||||
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);
|
||||
|
||||
curl_easy_perform(handle);
|
||||
|
||||
curl_slist_free_all(slist); /* free the list again */
|
||||
}
|
||||
|
||||
slist = temp;
|
||||
|
||||
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);
|
||||
|
||||
curl_easy_perform(handle);
|
||||
|
||||
curl_slist_free_all(slist); /* free the list again */
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Always
|
||||
|
@ -38,19 +38,22 @@ Passing in a NULL pointer in \fIlist\fP makes this function return immediately
|
||||
with no action.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *handle;
|
||||
struct curl_slist *slist=NULL;
|
||||
int main(void)
|
||||
{
|
||||
CURL *handle;
|
||||
struct curl_slist *slist = NULL;
|
||||
|
||||
slist = curl_slist_append(slist, "X-libcurl: coolness");
|
||||
slist = curl_slist_append(slist, "X-libcurl: coolness");
|
||||
|
||||
if (slist == NULL)
|
||||
return -1;
|
||||
if(!slist)
|
||||
return -1;
|
||||
|
||||
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);
|
||||
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);
|
||||
|
||||
curl_easy_perform(handle);
|
||||
curl_easy_perform(handle);
|
||||
|
||||
curl_slist_free_all(slist); /* free the list again */
|
||||
curl_slist_free_all(slist); /* free the list again */
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Always
|
||||
|
@ -46,10 +46,14 @@ strings in a truly portable manner. There are no standard portable case
|
||||
insensitive string comparison functions. These two work on all platforms.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
if(curl_strequal(name, input))
|
||||
printf("Name and input matches\\n");
|
||||
if(curl_strnequal(name, input, 5))
|
||||
printf("Name and input matches in the 5 first bytes\\n");
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *name = "compare";
|
||||
if(curl_strequal(name, argv[1]))
|
||||
printf("Name and input matches\\n");
|
||||
if(curl_strnequal(name, argv[1], 5))
|
||||
printf("Name and input matches in the 5 first bytes\\n");
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Always
|
||||
|
@ -44,15 +44,17 @@ strlen() on \fBinput\fP to find out the size.
|
||||
You must \fIcurl_free(3)\fP the returned string when you are done with it.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
int decodelen;
|
||||
char *decoded = curl_unescape("%63%75%72%6c", 12, &decodelen);
|
||||
if(decoded) {
|
||||
/* do not assume printf() works on the decoded data! */
|
||||
printf("Decoded: ");
|
||||
/* ... */
|
||||
curl_free(decoded);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
char *decoded = curl_unescape("%63%75%72%6c", 12);
|
||||
if(decoded) {
|
||||
/* do not assume printf() works on the decoded data! */
|
||||
printf("Decoded: ");
|
||||
/* ... */
|
||||
curl_free(decoded);
|
||||
}
|
||||
}
|
||||
}
|
||||
.fi
|
||||
|
@ -40,6 +40,8 @@ stored. They are then set in the object with the \fIcurl_url_set(3)\fP
|
||||
function.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int main(void)
|
||||
{
|
||||
CURLUcode rc;
|
||||
CURLU *url = curl_url();
|
||||
rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
|
||||
@ -52,6 +54,7 @@ function.
|
||||
}
|
||||
curl_url_cleanup(url);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.62.0
|
||||
|
@ -37,9 +37,12 @@ Passing in a NULL pointer in \fIhandle\fP makes this function return
|
||||
immediately with no action.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int main(void)
|
||||
{
|
||||
CURLU *url = curl_url();
|
||||
curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
|
||||
curl_url_cleanup(url);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.62.0
|
||||
|
@ -36,6 +36,8 @@ returns a pointer to the copy as a new \fICURLU\fP handle. The new handle also
|
||||
needs to be freed with \fIcurl_url_cleanup(3)\fP.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int main(void)
|
||||
{
|
||||
CURLUcode rc;
|
||||
CURLU *url = curl_url();
|
||||
CURLU *url2;
|
||||
@ -45,6 +47,7 @@ needs to be freed with \fIcurl_url_cleanup(3)\fP.
|
||||
curl_url_cleanup(url2);
|
||||
}
|
||||
curl_url_cleanup(url);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.62.0
|
||||
|
@ -145,6 +145,8 @@ The initial hash sign that denotes the beginning of the fragment is a
|
||||
delimiter only. It is not part of the fragment contents.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int main(void)
|
||||
{
|
||||
CURLUcode rc;
|
||||
CURLU *url = curl_url();
|
||||
rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
|
||||
@ -157,6 +159,7 @@ delimiter only. It is not part of the fragment contents.
|
||||
}
|
||||
curl_url_cleanup(url);
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.62.0. CURLUPART_ZONEID was added in 7.65.0.
|
||||
|
@ -179,15 +179,17 @@ If set, the URL parser does not accept embedded credentials for the
|
||||
such URLs.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int main(void)
|
||||
{
|
||||
CURLUcode rc;
|
||||
CURLU *url = curl_url();
|
||||
rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
|
||||
if(!rc) {
|
||||
char *scheme;
|
||||
/* change it to an FTP URL */
|
||||
rc = curl_url_set(url, CURLUPART_SCHEME, "ftp", 0);
|
||||
}
|
||||
curl_url_cleanup(url);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.62.0. CURLUPART_ZONEID was added in 7.65.0.
|
||||
|
@ -35,14 +35,16 @@ This function returns a string describing the CURLUcode error code passed in
|
||||
the argument \fIerrornum\fP.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int main(void)
|
||||
{
|
||||
CURLUcode rc;
|
||||
CURLU *url = curl_url();
|
||||
rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
|
||||
if(rc)
|
||||
printf("URL error: %s\\n", curl_url_strerror(rc));
|
||||
curl_url_cleanup(url);
|
||||
}
|
||||
.fi
|
||||
|
||||
.SH AVAILABILITY
|
||||
Added in 7.80.0
|
||||
.SH RETURN VALUE
|
||||
|
@ -37,7 +37,10 @@ its important components (like OpenSSL version).
|
||||
We recommend using \fIcurl_version_info(3)\fP instead!
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
printf("libcurl version %s\\n", curl_version());
|
||||
int main(void)
|
||||
{
|
||||
printf("libcurl version %s\\n", curl_version());
|
||||
}
|
||||
.fi
|
||||
|
||||
.SH AVAILABILITY
|
||||
|
@ -306,11 +306,14 @@ names are the same as would be used in URLs. The array is terminated by a NULL
|
||||
entry.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
|
||||
printf("libcurl version %u.%u.%u\\n",
|
||||
(ver->version_num >> 16) & 0xff,
|
||||
(ver->version_num >> 8) & 0xff,
|
||||
ver->version_num & 0xff);
|
||||
int main(void)
|
||||
{
|
||||
curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
|
||||
printf("libcurl version %u.%u.%u\\n",
|
||||
(ver->version_num >> 16) & 0xff,
|
||||
(ver->version_num >> 8) & 0xff,
|
||||
ver->version_num & 0xff);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.10
|
||||
|
@ -96,15 +96,22 @@ static size_t writecb(unsigned char *buffer,
|
||||
struct customdata *c = (struct customdata *)p;
|
||||
const struct curl_ws_frame *m = curl_ws_meta(c->easy);
|
||||
|
||||
/* m->flags tells us about the traffic */
|
||||
printf("flags: %x\\n", m->flags);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct customdata custom;
|
||||
custom.easy = easy;
|
||||
custom.ptr = NULL;
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &custom);
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
struct customdata custom;
|
||||
custom.easy = curl;
|
||||
custom.ptr = NULL;
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &custom);
|
||||
|
||||
curl_easy_perform(curl);
|
||||
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -48,10 +48,18 @@ that contains information about the received data. See the
|
||||
\fIcurl_ws_meta(3)\fP for details on that struct.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int main(void)
|
||||
{
|
||||
size_t rlen;
|
||||
const struct curl_ws_frame *meta;
|
||||
char buffer[256];
|
||||
CURLcode result = curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta);
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res = curl_ws_recv(curl, buffer, sizeof(buffer), &rlen, &meta);
|
||||
if(res)
|
||||
printf("error: %s\\n", curl_easy_strerror(res));
|
||||
}
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
Added in 7.86.0.
|
||||
|
@ -79,13 +79,22 @@ expected fragment size in the first call and it needs to be zero in subsequent
|
||||
calls.
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
int ping(CURL *curl, const char *send_payload)
|
||||
#include <string.h> /* for strlen */
|
||||
|
||||
const char *send_payload = "magic";
|
||||
|
||||
int main(void)
|
||||
{
|
||||
size_t sent;
|
||||
CURLcode result =
|
||||
curl_ws_send(curl, send_payload, strlen(send_payload), &sent, 0,
|
||||
CURLWS_PING);
|
||||
return (int)result;
|
||||
CURLcode res;
|
||||
CURL *curl = curl_easy_init();
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "wss://example.com/");
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L);
|
||||
curl_easy_perform(curl);
|
||||
res = curl_ws_send(curl, send_payload, strlen(send_payload), &sent, 0,
|
||||
CURLWS_PING);
|
||||
curl_easy_cleanup(curl);
|
||||
return (int)res;
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -48,21 +48,25 @@ is complete, and is typically used in combination with
|
||||
All
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_socket_t sockfd;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_socket_t sockfd;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
|
||||
/* Do not do the transfer - only connect to host */
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
|
||||
res = curl_easy_perform(curl);
|
||||
/* Do not do the transfer - only connect to host */
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
/* Extract the socket from the curl handle */
|
||||
res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
|
||||
/* Extract the socket from the curl handle */
|
||||
res = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
|
||||
|
||||
if(res != CURLE_OK) {
|
||||
printf("Error: %s\\n", curl_easy_strerror(res));
|
||||
return 1;
|
||||
if(res != CURLE_OK) {
|
||||
printf("Error: %s\\n", curl_easy_strerror(res));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
.fi
|
||||
|
@ -46,19 +46,23 @@ See also the TIMES overview in the \fIcurl_easy_getinfo(3)\fP man page.
|
||||
All
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
double connect;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
res = curl_easy_perform(curl);
|
||||
if(CURLE_OK == res) {
|
||||
res = curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME, &connect);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
double connect;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
|
||||
res = curl_easy_perform(curl);
|
||||
if(CURLE_OK == res) {
|
||||
printf("Time: %.1f", connect);
|
||||
res = curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME, &connect);
|
||||
if(CURLE_OK == res) {
|
||||
printf("Time: %.1f", connect);
|
||||
}
|
||||
}
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -47,20 +47,24 @@ See also the TIMES overview in the \fIcurl_easy_getinfo(3)\fP man page.
|
||||
All
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_off_t connect;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
res = curl_easy_perform(curl);
|
||||
if(CURLE_OK == res) {
|
||||
res = curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME_T, &connect);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_off_t connect;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
|
||||
res = curl_easy_perform(curl);
|
||||
if(CURLE_OK == res) {
|
||||
printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", connect / 1000000,
|
||||
(long)(connect % 1000000));
|
||||
res = curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME_T, &connect);
|
||||
if(CURLE_OK == res) {
|
||||
printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", connect / 1000000,
|
||||
(long)(connect % 1000000));
|
||||
}
|
||||
}
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -47,15 +47,17 @@ The \fBpath\fP pointer is set to NULL if there is no default path.
|
||||
All
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
char *cainfo = NULL;
|
||||
curl_easy_getinfo(curl, CURLINFO_CAINFO, &cainfo);
|
||||
if(cainfo)
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
char *cainfo = NULL;
|
||||
curl_easy_getinfo(curl, CURLINFO_CAINFO, &cainfo);
|
||||
if(cainfo) {
|
||||
printf("default ca info path: %s\\n", cainfo);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -47,15 +47,17 @@ The \fBpath\fP pointer is set to NULL if there is no default path.
|
||||
All
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
char *capath = NULL;
|
||||
curl_easy_getinfo(curl, CURLINFO_CAPATH, &capath);
|
||||
if(capath)
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
char *capath = NULL;
|
||||
curl_easy_getinfo(curl, CURLINFO_CAPATH, &capath);
|
||||
if(capath) {
|
||||
printf("default ca path: %s\\n", capath);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -54,34 +54,39 @@ the SSL backend and the certificate.
|
||||
All TLS-based
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
|
||||
|
||||
/* connect to any HTTPS site, trusted or not */
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
/* connect to any HTTPS site, trusted or not */
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if (!res) {
|
||||
struct curl_certinfo *ci;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &ci);
|
||||
if(!res) {
|
||||
int i;
|
||||
struct curl_certinfo *ci;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &ci);
|
||||
|
||||
if (!res) {
|
||||
printf("%d certs!\\n", ci->num_of_certs);
|
||||
if(!res) {
|
||||
printf("%d certs!\\n", ci->num_of_certs);
|
||||
|
||||
for(i = 0; i < ci->num_of_certs; i++) {
|
||||
struct curl_slist *slist;
|
||||
for(i = 0; i < ci->num_of_certs; i++) {
|
||||
struct curl_slist *slist;
|
||||
|
||||
for(slist = ci->certinfo[i]; slist; slist = slist->next)
|
||||
printf("%s\\n", slist->data);
|
||||
for(slist = ci->certinfo[i]; slist; slist = slist->next)
|
||||
printf("%s\\n", slist->data);
|
||||
}
|
||||
}
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
.fi
|
||||
|
||||
|
@ -44,26 +44,31 @@ custom "If-Match-*" header.
|
||||
HTTP and some
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
|
||||
/* January 1, 2020 is 1577833200 */
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEVALUE, 1577833200L);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
|
||||
/* If-Modified-Since the above time stamp */
|
||||
curl_easy_setopt(curl, CURLOPT_TIMECONDITION,
|
||||
(long)CURL_TIMECOND_IFMODSINCE);
|
||||
/* January 1, 2020 is 1577833200 */
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEVALUE, 1577833200L);
|
||||
|
||||
/* Perform the request */
|
||||
res = curl_easy_perform(curl);
|
||||
/* If-Modified-Since the above time stamp */
|
||||
curl_easy_setopt(curl, CURLOPT_TIMECONDITION,
|
||||
(long)CURL_TIMECOND_IFMODSINCE);
|
||||
|
||||
/* Perform the request */
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if(!res) {
|
||||
/* check the time condition */
|
||||
long unmet;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &unmet);
|
||||
if(!res) {
|
||||
printf("The time condition was %sfulfilled\\n", unmet?"NOT":"");
|
||||
/* check the time condition */
|
||||
long unmet;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &unmet);
|
||||
if(!res) {
|
||||
printf("The time condition was %sfulfilled\\n", unmet?"NOT":"");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,19 +42,23 @@ See also the TIMES overview in the \fIcurl_easy_getinfo(3)\fP man page.
|
||||
All
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
double connect;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
res = curl_easy_perform(curl);
|
||||
if(CURLE_OK == res) {
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &connect);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
double connect;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
res = curl_easy_perform(curl);
|
||||
if(CURLE_OK == res) {
|
||||
printf("Time: %.1f", connect);
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &connect);
|
||||
if(CURLE_OK == res) {
|
||||
printf("Time: %.1f", connect);
|
||||
}
|
||||
}
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -43,20 +43,24 @@ See also the TIMES overview in the \fIcurl_easy_getinfo(3)\fP man page.
|
||||
All
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_off_t connect;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
res = curl_easy_perform(curl);
|
||||
if(CURLE_OK == res) {
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME_T, &connect);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_off_t connect;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
res = curl_easy_perform(curl);
|
||||
if(CURLE_OK == res) {
|
||||
printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", connect / 1000000,
|
||||
(long)(connect % 1000000));
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME_T, &connect);
|
||||
if(CURLE_OK == res) {
|
||||
printf("Time: %" CURL_FORMAT_CURL_OFF_T ".%06ld", connect / 1000000,
|
||||
(long)(connect % 1000000));
|
||||
}
|
||||
}
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -44,18 +44,23 @@ same multi handle.
|
||||
All
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
|
||||
/* Perform the request */
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
|
||||
/* Perform the request */
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if(!res) {
|
||||
curl_off_t conn_id;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONN_ID, &conn_id);
|
||||
if(!res) {
|
||||
printf("Connection used: %" CURL_FORMAT_CURL_OFF_T "\\n", conn_id);
|
||||
curl_off_t conn_id;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONN_ID, &conn_id);
|
||||
if(!res) {
|
||||
printf("Connection used: %" CURL_FORMAT_CURL_OFF_T "\\n", conn_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,19 +43,23 @@ sensible variable type.
|
||||
HTTP(S)
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
|
||||
/* Perform the request */
|
||||
res = curl_easy_perform(curl);
|
||||
/* Perform the request */
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if(!res) {
|
||||
/* check the size */
|
||||
double cl;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &cl);
|
||||
if(!res) {
|
||||
printf("Size: %.0f\\n", cl);
|
||||
/* check the size */
|
||||
double cl;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &cl);
|
||||
if(!res) {
|
||||
printf("Size: %.0f\\n", cl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,19 +40,23 @@ the size is not known.
|
||||
HTTP(S)
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
|
||||
/* Perform the request */
|
||||
res = curl_easy_perform(curl);
|
||||
/* Perform the request */
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if(!res) {
|
||||
/* check the size */
|
||||
curl_off_t cl;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &cl);
|
||||
if(!res) {
|
||||
printf("Download size: %" CURL_FORMAT_CURL_OFF_T "\\n", cl);
|
||||
/* check the size */
|
||||
curl_off_t cl;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &cl);
|
||||
if(!res) {
|
||||
printf("Download size: %" CURL_FORMAT_CURL_OFF_T "\\n", cl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,19 +42,23 @@ more sensible variable type.
|
||||
All
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
|
||||
/* Perform the upload */
|
||||
res = curl_easy_perform(curl);
|
||||
/* Perform the upload */
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if(!res) {
|
||||
/* check the size */
|
||||
double cl;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_UPLOAD, &cl);
|
||||
if(!res) {
|
||||
printf("Size: %.0f\\n", cl);
|
||||
/* check the size */
|
||||
double cl;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_UPLOAD, &cl);
|
||||
if(!res) {
|
||||
printf("Size: %.0f\\n", cl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,19 +39,23 @@ upload. Stores -1 if the size is not known.
|
||||
All
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
|
||||
/* Perform the upload */
|
||||
res = curl_easy_perform(curl);
|
||||
/* Perform the upload */
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if(!res) {
|
||||
/* check the size */
|
||||
curl_off_t cl;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_UPLOAD_T, &cl);
|
||||
if(!res) {
|
||||
printf("Upload size: %" CURL_FORMAT_CURL_OFF_T "\\n", cl);
|
||||
/* check the size */
|
||||
curl_off_t cl;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_UPLOAD_T, &cl);
|
||||
if(!res) {
|
||||
printf("Upload size: %" CURL_FORMAT_CURL_OFF_T "\\n", cl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,21 +47,25 @@ The modern way to get this header from a response is to instead use the
|
||||
HTTP(S)
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if(!res) {
|
||||
/* extract the content-type */
|
||||
char *ct = NULL;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
|
||||
if(!res && ct) {
|
||||
printf("Content-Type: %s\\n", ct);
|
||||
if(!res) {
|
||||
/* extract the content-type */
|
||||
char *ct = NULL;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
|
||||
if(!res && ct) {
|
||||
printf("Content-Type: %s\\n", ct);
|
||||
}
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -45,31 +45,35 @@ domain name are not exported by this option.
|
||||
HTTP(S)
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
|
||||
/* enable the cookie engine */
|
||||
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
|
||||
/* enable the cookie engine */
|
||||
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if(!res) {
|
||||
/* extract all known cookies */
|
||||
struct curl_slist *cookies = NULL;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
|
||||
if(!res && cookies) {
|
||||
/* a linked list of cookies in cookie file format */
|
||||
struct curl_slist *each = cookies;
|
||||
while(each) {
|
||||
printf("%s\\n", each->data);
|
||||
each = each->next;
|
||||
if(!res) {
|
||||
/* extract all known cookies */
|
||||
struct curl_slist *cookies = NULL;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
|
||||
if(!res && cookies) {
|
||||
/* a linked list of cookies in cookie file format */
|
||||
struct curl_slist *each = cookies;
|
||||
while(each) {
|
||||
printf("%s\\n", each->data);
|
||||
each = each->next;
|
||||
}
|
||||
/* we must free these cookies when we are done */
|
||||
curl_slist_free_all(cookies);
|
||||
}
|
||||
/* we must free these cookies when we are done */
|
||||
curl_slist_free_all(cookies);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
@ -46,20 +46,23 @@ corresponding CURL handle.
|
||||
HTTP(S)
|
||||
.SH EXAMPLE
|
||||
.nf
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data");
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
res = curl_easy_perform(curl);
|
||||
if(res == CURLE_OK) {
|
||||
char *method = NULL;
|
||||
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_METHOD, &method);
|
||||
if(method)
|
||||
printf("Redirected to method: %s\\n", method);
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data");
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
res = curl_easy_perform(curl);
|
||||
if(res == CURLE_OK) {
|
||||
char *method = NULL;
|
||||
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_METHOD, &method);
|
||||
if(method)
|
||||
printf("Redirected to method: %s\\n", method);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
.fi
|
||||
.SH AVAILABILITY
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user