mirror of
https://github.com/curl/curl.git
synced 2026-04-11 12:01:42 +08:00
examples: improve global init, error checks and returning errors
- add `curl_global_init()` and `curl_global_cleanup()` where missing. - check the result of `curl_global_init()` where missing. - return the last curl error from `main()`. - drop Win32-specific socket initialization in favor of `curl_global_init()`. - rename some outliers to `res` for curl result code. - fix cleanup in some error cases. Inspired by Joshua's report on examples. Closes #19053
This commit is contained in:
parent
3049c8e0a0
commit
4c7507daf9
@ -109,7 +109,10 @@ int main(void)
|
||||
int msgs_left = -1;
|
||||
int left = 0;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
cm = curl_multi_init();
|
||||
|
||||
/* Limit the amount of simultaneous connections curl should allow: */
|
||||
|
||||
@ -37,7 +37,10 @@ int main(void)
|
||||
#if !defined(_WIN32) && !defined(MSDOS) && !defined(__AMIGA__)
|
||||
/* Windows/MS-DOS users need to find how to use if_nametoindex() */
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -57,6 +60,9 @@ int main(void)
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
#endif
|
||||
curl_global_cleanup();
|
||||
return (int)res;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -31,7 +31,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -54,5 +57,6 @@ int main(void)
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
return 0;
|
||||
curl_global_cleanup();
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -111,7 +111,11 @@ int main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
/* In Windows, this inits the Winsock stuff */
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res) {
|
||||
fclose(fp);
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
/* get a curl handle */
|
||||
curl = curl_easy_init();
|
||||
@ -161,5 +165,5 @@ int main(int argc, char **argv)
|
||||
fclose(fp); /* close the local file */
|
||||
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -301,9 +301,10 @@ int main(void)
|
||||
if(!filter)
|
||||
return 1;
|
||||
|
||||
if(curl_global_init(CURL_GLOBAL_DEFAULT)) {
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res) {
|
||||
free(filter);
|
||||
return 1;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
curl = curl_easy_init();
|
||||
|
||||
@ -56,8 +56,6 @@ static size_t writefunction(void *ptr, size_t size, size_t nmemb, void *stream)
|
||||
|
||||
static CURLcode sslctx_function(CURL *curl, void *sslctx, void *pointer)
|
||||
{
|
||||
CURLcode rv = CURLE_ABORTED_BY_CALLBACK;
|
||||
|
||||
/** This example uses two (fake) certificates **/
|
||||
/* replace the XXX with the actual CA certificates */
|
||||
static const char mypem[] =
|
||||
@ -89,14 +87,14 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *pointer)
|
||||
(void)pointer;
|
||||
|
||||
if(!cts || !cbio) {
|
||||
return rv;
|
||||
return CURLE_ABORTED_BY_CALLBACK;
|
||||
}
|
||||
|
||||
inf = PEM_X509_INFO_read_bio(cbio, NULL, NULL, NULL);
|
||||
|
||||
if(!inf) {
|
||||
BIO_free(cbio);
|
||||
return rv;
|
||||
return CURLE_ABORTED_BY_CALLBACK;
|
||||
}
|
||||
|
||||
for(i = 0; i < sk_X509_INFO_num(inf); i++) {
|
||||
@ -112,16 +110,18 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *pointer)
|
||||
sk_X509_INFO_pop_free(inf, X509_INFO_free);
|
||||
BIO_free(cbio);
|
||||
|
||||
rv = CURLE_OK;
|
||||
return rv;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
CURL *ch;
|
||||
CURLcode rv;
|
||||
CURLcode res;
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
ch = curl_easy_init();
|
||||
curl_easy_setopt(ch, CURLOPT_VERBOSE, 0L);
|
||||
curl_easy_setopt(ch, CURLOPT_HEADER, 0L);
|
||||
@ -145,8 +145,8 @@ int main(void)
|
||||
/* first try: retrieve page without ca certificates -> should fail
|
||||
* unless libcurl was built --with-ca-fallback enabled at build-time
|
||||
*/
|
||||
rv = curl_easy_perform(ch);
|
||||
if(rv == CURLE_OK)
|
||||
res = curl_easy_perform(ch);
|
||||
if(res == CURLE_OK)
|
||||
printf("*** transfer succeeded ***\n");
|
||||
else
|
||||
printf("*** transfer failed ***\n");
|
||||
@ -166,13 +166,13 @@ int main(void)
|
||||
* "modifications" to the SSL CONTEXT just before link init
|
||||
*/
|
||||
curl_easy_setopt(ch, CURLOPT_SSL_CTX_FUNCTION, sslctx_function);
|
||||
rv = curl_easy_perform(ch);
|
||||
if(rv == CURLE_OK)
|
||||
res = curl_easy_perform(ch);
|
||||
if(res == CURLE_OK)
|
||||
printf("*** transfer succeeded ***\n");
|
||||
else
|
||||
printf("*** transfer failed ***\n");
|
||||
|
||||
curl_easy_cleanup(ch);
|
||||
curl_global_cleanup();
|
||||
return (int)rv;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -41,7 +41,9 @@ int main(void)
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -83,5 +85,5 @@ int main(void)
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -156,7 +156,9 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* init libcurl */
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
/* init the curl session */
|
||||
curl_handle = curl_easy_init();
|
||||
|
||||
@ -30,8 +30,12 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct curl_slist *host;
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
/*
|
||||
Each single string should be written using the format
|
||||
@ -41,8 +45,7 @@ int main(void)
|
||||
*/
|
||||
/* instead of curl.se:443, it resolves and uses example.com:443 but in other
|
||||
aspects work as if it still is curl.se */
|
||||
struct curl_slist *host = curl_slist_append(NULL,
|
||||
"curl.se:443:example.com:443");
|
||||
host = curl_slist_append(NULL, "curl.se:443:example.com:443");
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -66,5 +69,7 @@ int main(void)
|
||||
|
||||
curl_slist_free_all(host);
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -72,7 +72,10 @@ main(void)
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
char nline[512];
|
||||
|
||||
@ -182,10 +182,14 @@ int main(void)
|
||||
int pending;
|
||||
int complete;
|
||||
int still_running;
|
||||
CURLcode res;
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
signal(SIGINT, sighandler);
|
||||
LIBXML_TEST_VERSION
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
multi_handle = curl_multi_init();
|
||||
curl_multi_setopt(multi_handle, CURLMOPT_MAX_TOTAL_CONNECTIONS, max_con);
|
||||
curl_multi_setopt(multi_handle, CURLMOPT_MAX_HOST_CONNECTIONS, 6L);
|
||||
|
||||
@ -128,6 +128,10 @@ int main(void)
|
||||
CURLcode res;
|
||||
struct data config;
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
config.trace_ascii = 1; /* enable ASCII tracing */
|
||||
|
||||
curl = curl_easy_init();
|
||||
@ -151,5 +155,6 @@ int main(void)
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
return 0;
|
||||
curl_global_cleanup();
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -33,6 +33,10 @@ int main(void)
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "example.com");
|
||||
@ -53,5 +57,6 @@ int main(void)
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
return 0;
|
||||
curl_global_cleanup();
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -449,6 +449,7 @@ void sigint_handler(int signo)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
CURLcode res;
|
||||
struct GlobalInfo g;
|
||||
struct itimerspec its;
|
||||
struct epoll_event ev;
|
||||
@ -456,6 +457,10 @@ int main(int argc, char **argv)
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
g_should_exit_ = 0;
|
||||
signal(SIGINT, sigint_handler);
|
||||
|
||||
@ -463,12 +468,14 @@ int main(int argc, char **argv)
|
||||
g.epfd = epoll_create1(EPOLL_CLOEXEC);
|
||||
if(g.epfd == -1) {
|
||||
perror("epoll_create1 failed");
|
||||
curl_global_cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
g.tfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
|
||||
if(g.tfd == -1) {
|
||||
perror("timerfd_create failed");
|
||||
curl_global_cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -481,8 +488,10 @@ int main(int argc, char **argv)
|
||||
ev.data.fd = g.tfd;
|
||||
epoll_ctl(g.epfd, EPOLL_CTL_ADD, g.tfd, &ev);
|
||||
|
||||
if(init_fifo(&g))
|
||||
if(init_fifo(&g)) {
|
||||
curl_global_cleanup();
|
||||
return 1;
|
||||
}
|
||||
g.multi = curl_multi_init();
|
||||
|
||||
/* setup the generic multi interface options we want */
|
||||
@ -508,6 +517,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
else {
|
||||
perror("epoll_wait");
|
||||
curl_global_cleanup();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -530,5 +540,6 @@ int main(int argc, char **argv)
|
||||
|
||||
curl_multi_cleanup(g.multi);
|
||||
clean_fifo(&g);
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -415,10 +415,15 @@ static int init_fifo(struct GlobalInfo *g)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
CURLcode res;
|
||||
struct GlobalInfo g;
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
memset(&g, 0, sizeof(g));
|
||||
g.loop = ev_default_loop(0);
|
||||
|
||||
@ -439,5 +444,6 @@ int main(int argc, char **argv)
|
||||
|
||||
ev_loop(g.loop, 0);
|
||||
curl_multi_cleanup(g.multi);
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -103,14 +103,9 @@ int main(void)
|
||||
struct sockaddr_in servaddr; /* socket address structure */
|
||||
curl_socket_t sockfd;
|
||||
|
||||
#ifdef _WIN32
|
||||
WSADATA wsaData;
|
||||
int initwsa = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
if(initwsa) {
|
||||
printf("WSAStartup failed: %d\n", initwsa);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -175,8 +170,7 @@ int main(void)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -46,9 +46,15 @@ int main(void)
|
||||
curl_off_t speed_upload, total_time;
|
||||
FILE *fd;
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
fd = fopen("debugit", "rb"); /* open file to upload */
|
||||
if(!fd)
|
||||
if(!fd) {
|
||||
curl_global_cleanup();
|
||||
return 1; /* cannot continue */
|
||||
}
|
||||
|
||||
/* to get the file size */
|
||||
#ifdef UNDER_CE
|
||||
@ -58,6 +64,7 @@ int main(void)
|
||||
if(fstat(fileno(fd), &file_info) != 0) {
|
||||
#endif
|
||||
fclose(fd);
|
||||
curl_global_cleanup();
|
||||
return 1; /* cannot continue */
|
||||
}
|
||||
|
||||
@ -100,5 +107,6 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
fclose(fd);
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -37,14 +37,15 @@ static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
struct curl_slist *headerlist = NULL;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -80,5 +81,5 @@ int main(void)
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -32,67 +32,6 @@ struct callback_data {
|
||||
FILE *output;
|
||||
};
|
||||
|
||||
static long file_is_coming(struct curl_fileinfo *finfo,
|
||||
void *data,
|
||||
int remains);
|
||||
|
||||
static long file_is_downloaded(void *data);
|
||||
|
||||
static size_t write_it(char *buff, size_t size, size_t nmemb,
|
||||
void *cb_data);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/* curl easy handle */
|
||||
CURL *handle;
|
||||
|
||||
/* help data */
|
||||
struct callback_data data = { 0 };
|
||||
|
||||
/* global initialization */
|
||||
CURLcode rc = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(rc)
|
||||
return (int)rc;
|
||||
|
||||
/* initialization of easy handle */
|
||||
handle = curl_easy_init();
|
||||
if(!handle) {
|
||||
curl_global_cleanup();
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
/* turn on wildcard matching */
|
||||
curl_easy_setopt(handle, CURLOPT_WILDCARDMATCH, 1L);
|
||||
|
||||
/* callback is called before download of concrete file started */
|
||||
curl_easy_setopt(handle, CURLOPT_CHUNK_BGN_FUNCTION, file_is_coming);
|
||||
|
||||
/* callback is called after data from the file have been transferred */
|
||||
curl_easy_setopt(handle, CURLOPT_CHUNK_END_FUNCTION, file_is_downloaded);
|
||||
|
||||
/* this callback writes contents into files */
|
||||
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_it);
|
||||
|
||||
/* put transfer data into callbacks */
|
||||
curl_easy_setopt(handle, CURLOPT_CHUNK_DATA, &data);
|
||||
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &data);
|
||||
|
||||
/* curl_easy_setopt(handle, CURLOPT_VERBOSE, 1L); */
|
||||
|
||||
/* set a URL containing wildcard pattern (only in the last part) */
|
||||
if(argc == 2)
|
||||
curl_easy_setopt(handle, CURLOPT_URL, argv[1]);
|
||||
else
|
||||
curl_easy_setopt(handle, CURLOPT_URL, "ftp://example.com/test/*");
|
||||
|
||||
/* and start transfer! */
|
||||
rc = curl_easy_perform(handle);
|
||||
|
||||
curl_easy_cleanup(handle);
|
||||
curl_global_cleanup();
|
||||
return (int)rc;
|
||||
}
|
||||
|
||||
static long file_is_coming(struct curl_fileinfo *finfo, void *input,
|
||||
int remains)
|
||||
{
|
||||
@ -151,3 +90,55 @@ static size_t write_it(char *buff, size_t size, size_t nmemb,
|
||||
written = fwrite(buff, size, nmemb, stdout);
|
||||
return written;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/* curl easy handle */
|
||||
CURL *handle;
|
||||
|
||||
/* help data */
|
||||
struct callback_data data = { 0 };
|
||||
|
||||
/* global initialization */
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
/* initialization of easy handle */
|
||||
handle = curl_easy_init();
|
||||
if(!handle) {
|
||||
curl_global_cleanup();
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
/* turn on wildcard matching */
|
||||
curl_easy_setopt(handle, CURLOPT_WILDCARDMATCH, 1L);
|
||||
|
||||
/* callback is called before download of concrete file started */
|
||||
curl_easy_setopt(handle, CURLOPT_CHUNK_BGN_FUNCTION, file_is_coming);
|
||||
|
||||
/* callback is called after data from the file have been transferred */
|
||||
curl_easy_setopt(handle, CURLOPT_CHUNK_END_FUNCTION, file_is_downloaded);
|
||||
|
||||
/* this callback writes contents into files */
|
||||
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_it);
|
||||
|
||||
/* put transfer data into callbacks */
|
||||
curl_easy_setopt(handle, CURLOPT_CHUNK_DATA, &data);
|
||||
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &data);
|
||||
|
||||
/* curl_easy_setopt(handle, CURLOPT_VERBOSE, 1L); */
|
||||
|
||||
/* set a URL containing wildcard pattern (only in the last part) */
|
||||
if(argc == 2)
|
||||
curl_easy_setopt(handle, CURLOPT_URL, argv[1]);
|
||||
else
|
||||
curl_easy_setopt(handle, CURLOPT_URL, "ftp://example.com/test/*");
|
||||
|
||||
/* and start transfer! */
|
||||
res = curl_easy_perform(handle);
|
||||
|
||||
curl_easy_cleanup(handle);
|
||||
curl_global_cleanup();
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -57,7 +57,9 @@ int main(void)
|
||||
NULL
|
||||
};
|
||||
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -90,5 +92,5 @@ int main(void)
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -49,7 +49,9 @@ int main(void)
|
||||
curl_off_t filesize = 0;
|
||||
const char *filename = strrchr(ftpurl, '/') + 1;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -89,5 +91,5 @@ int main(void)
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -47,15 +47,22 @@ int main(void)
|
||||
FILE *ftpfile;
|
||||
FILE *respfile;
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
/* local filename to store the file as */
|
||||
ftpfile = fopen(FTPBODY, "wb"); /* b is binary, needed on Windows */
|
||||
if(!ftpfile)
|
||||
if(!ftpfile) {
|
||||
curl_global_cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* local filename to store the FTP server's response lines in */
|
||||
respfile = fopen(FTPHEADERS, "wb"); /* b is binary, needed on Windows */
|
||||
if(!respfile) {
|
||||
fclose(ftpfile);
|
||||
curl_global_cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -81,5 +88,5 @@ int main(void)
|
||||
fclose(ftpfile); /* close the local file */
|
||||
fclose(respfile); /* close the response file */
|
||||
|
||||
return 0;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -59,7 +59,9 @@ int main(void)
|
||||
NULL
|
||||
};
|
||||
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -97,5 +99,5 @@ int main(void)
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -109,7 +109,11 @@ int main(void)
|
||||
printf("Local file size: %lu bytes.\n", (unsigned long)fsize);
|
||||
|
||||
/* In Windows, this inits the Winsock stuff */
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res) {
|
||||
fclose(hd_src);
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
/* get a curl handle */
|
||||
curl = curl_easy_init();
|
||||
@ -155,5 +159,5 @@ int main(void)
|
||||
fclose(hd_src); /* close the local file */
|
||||
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -122,5 +122,5 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -154,7 +154,10 @@ int main(void)
|
||||
{
|
||||
CURL *curlhandle = NULL;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curlhandle = curl_easy_init();
|
||||
|
||||
upload(curlhandle, "ftp://user:pass@example.com/path/file", "C:\\file",
|
||||
|
||||
@ -31,7 +31,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -50,5 +53,6 @@ int main(void)
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
return 0;
|
||||
curl_global_cleanup();
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -66,11 +66,13 @@ int main(void)
|
||||
|
||||
struct MemoryStruct chunk;
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
chunk.memory = malloc(1); /* grown as needed by the realloc above */
|
||||
chunk.size = 0; /* no data at this point */
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
/* init the curl session */
|
||||
curl_handle = curl_easy_init();
|
||||
|
||||
@ -114,5 +116,5 @@ int main(void)
|
||||
/* we are done with libcurl, so clean it up */
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -35,6 +35,10 @@ int main(void)
|
||||
char *location;
|
||||
long response_code;
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
@ -68,5 +72,6 @@ int main(void)
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
return 0;
|
||||
curl_global_cleanup();
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -32,10 +32,12 @@ int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
curl_easy_setopt(curl, CURLOPT_REFERER, "https://example.org/referrer");
|
||||
|
||||
@ -55,5 +57,6 @@ int main(void)
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -421,9 +421,15 @@ int main(void)
|
||||
int fd;
|
||||
GIOChannel* ch;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
fd = init_fifo();
|
||||
if(fd == CURL_SOCKET_BAD)
|
||||
if(fd == CURL_SOCKET_BAD) {
|
||||
curl_global_cleanup();
|
||||
return 1;
|
||||
}
|
||||
ch = g_io_channel_unix_new(fd);
|
||||
g_io_add_watch(ch, G_IO_IN, fifo_cb, g);
|
||||
gmain = g_main_loop_new(NULL, FALSE);
|
||||
@ -438,5 +444,6 @@ int main(void)
|
||||
|
||||
g_main_loop_run(gmain);
|
||||
curl_multi_cleanup(g->multi);
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -40,9 +40,12 @@ int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
struct curl_header *header;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||
/* example.com is redirected, so we tell libcurl to follow redirection */
|
||||
@ -77,5 +80,6 @@ int main(void)
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -414,14 +414,21 @@ static void clean_fifo(struct GlobalInfo *g)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
CURLcode res;
|
||||
struct GlobalInfo g;
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
memset(&g, 0, sizeof(g));
|
||||
g.evbase = event_base_new();
|
||||
if(init_fifo(&g))
|
||||
if(init_fifo(&g)) {
|
||||
curl_global_cleanup();
|
||||
return 1;
|
||||
}
|
||||
g.multi = curl_multi_init();
|
||||
evtimer_assign(&g.timer_event, g.evbase, timer_cb, &g);
|
||||
|
||||
@ -443,5 +450,6 @@ int main(int argc, char **argv)
|
||||
event_del(&g.timer_event);
|
||||
event_base_free(g.evbase);
|
||||
curl_multi_cleanup(g.multi);
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -80,7 +80,10 @@ static CURLSTScode hstswrite(CURL *easy, struct curl_hstsentry *e,
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -114,5 +117,6 @@ int main(void)
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
return 0;
|
||||
curl_global_cleanup();
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -76,55 +76,58 @@ void dumpNode(TidyDoc doc, TidyNode tnod, int indent)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if(argc == 2) {
|
||||
CURL *curl;
|
||||
char curl_errbuf[CURL_ERROR_SIZE];
|
||||
TidyDoc tdoc;
|
||||
TidyBuffer docbuf = {0};
|
||||
TidyBuffer tidy_errbuf = {0};
|
||||
int err;
|
||||
CURL *curl;
|
||||
char curl_errbuf[CURL_ERROR_SIZE];
|
||||
TidyDoc tdoc;
|
||||
TidyBuffer docbuf = {0};
|
||||
TidyBuffer tidy_errbuf = {0};
|
||||
CURLcode res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
|
||||
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf);
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
|
||||
if(argc != 2) {
|
||||
printf("usage: %s <url>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
tdoc = tidyCreate();
|
||||
tidyOptSetBool(tdoc, TidyForceOutput, yes); /* try harder */
|
||||
tidyOptSetInt(tdoc, TidyWrapLen, 4096);
|
||||
tidySetErrorBuffer(tdoc, &tidy_errbuf);
|
||||
tidyBufInit(&docbuf);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &docbuf);
|
||||
err = curl_easy_perform(curl);
|
||||
if(!err) {
|
||||
err = tidyParseBuffer(tdoc, &docbuf); /* parse the input */
|
||||
if(err >= 0) {
|
||||
err = tidyCleanAndRepair(tdoc); /* fix any problems */
|
||||
if(err >= 0) {
|
||||
err = tidyRunDiagnostics(tdoc); /* load tidy error buffer */
|
||||
if(err >= 0) {
|
||||
dumpNode(tdoc, tidyGetRoot(tdoc), 0); /* walk the tree */
|
||||
fprintf(stderr, "%s\n", tidy_errbuf.bp); /* show errors */
|
||||
}
|
||||
curl = curl_easy_init();
|
||||
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
|
||||
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf);
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
|
||||
|
||||
tdoc = tidyCreate();
|
||||
tidyOptSetBool(tdoc, TidyForceOutput, yes); /* try harder */
|
||||
tidyOptSetInt(tdoc, TidyWrapLen, 4096);
|
||||
tidySetErrorBuffer(tdoc, &tidy_errbuf);
|
||||
tidyBufInit(&docbuf);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &docbuf);
|
||||
res = curl_easy_perform(curl);
|
||||
if(!res) {
|
||||
res = tidyParseBuffer(tdoc, &docbuf); /* parse the input */
|
||||
if(res >= 0) {
|
||||
res = tidyCleanAndRepair(tdoc); /* fix any problems */
|
||||
if(res >= 0) {
|
||||
res = tidyRunDiagnostics(tdoc); /* load tidy error buffer */
|
||||
if(res >= 0) {
|
||||
dumpNode(tdoc, tidyGetRoot(tdoc), 0); /* walk the tree */
|
||||
fprintf(stderr, "%s\n", tidy_errbuf.bp); /* show errors */
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "%s\n", curl_errbuf);
|
||||
|
||||
/* clean-up */
|
||||
curl_easy_cleanup(curl);
|
||||
tidyBufFree(&docbuf);
|
||||
tidyBufFree(&tidy_errbuf);
|
||||
tidyRelease(tdoc);
|
||||
return err;
|
||||
|
||||
}
|
||||
else
|
||||
printf("usage: %s <url>\n", argv[0]);
|
||||
fprintf(stderr, "%s\n", curl_errbuf);
|
||||
|
||||
return 0;
|
||||
/* clean-up */
|
||||
curl_easy_cleanup(curl);
|
||||
curl_global_cleanup();
|
||||
tidyBufFree(&docbuf);
|
||||
tidyBufFree(&tidy_errbuf);
|
||||
tidyRelease(tdoc);
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -263,7 +263,7 @@ static void parseHtml(const std::string &html,
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
CURL *conn = NULL;
|
||||
CURLcode code;
|
||||
CURLcode res;
|
||||
std::string title;
|
||||
|
||||
// Ensure one argument is given
|
||||
@ -273,21 +273,24 @@ int main(int argc, char *argv[])
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
// Initialize CURL connection
|
||||
|
||||
if(!init(conn, argv[1])) {
|
||||
fprintf(stderr, "Connection initialization failed\n");
|
||||
curl_global_cleanup();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Retrieve content for the URL
|
||||
|
||||
code = curl_easy_perform(conn);
|
||||
res = curl_easy_perform(conn);
|
||||
curl_easy_cleanup(conn);
|
||||
|
||||
if(code != CURLE_OK) {
|
||||
if(res != CURLE_OK) {
|
||||
fprintf(stderr, "Failed to get '%s' [%s]\n", argv[1], errorBuffer);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@ -298,5 +301,5 @@ int main(int argc, char *argv[])
|
||||
// Display the extracted title
|
||||
printf("Title: %s\n", title.c_str());
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -31,7 +31,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -55,5 +58,6 @@ int main(void)
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -34,7 +34,9 @@ int main(void)
|
||||
CURLcode res;
|
||||
|
||||
/* In Windows, this inits the Winsock stuff */
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
/* get a curl handle */
|
||||
curl = curl_easy_init();
|
||||
@ -57,5 +59,5 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -190,11 +190,13 @@ static int setup(struct transfer *t, int num)
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
CURLcode res;
|
||||
struct transfer trans[NUM_HANDLES];
|
||||
CURLM *multi_handle;
|
||||
int i;
|
||||
int still_running = 0; /* keep number of running handles */
|
||||
int num_transfers;
|
||||
|
||||
if(argc > 1) {
|
||||
/* if given a number, do that many transfers */
|
||||
num_transfers = atoi(argv[1]);
|
||||
@ -204,12 +206,18 @@ int main(int argc, char **argv)
|
||||
else
|
||||
num_transfers = 3; /* suitable default */
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
/* init a multi stack */
|
||||
multi_handle = curl_multi_init();
|
||||
|
||||
for(i = 0; i < num_transfers; i++) {
|
||||
if(setup(&trans[i], i))
|
||||
if(setup(&trans[i], i)) {
|
||||
curl_global_cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* add the individual transfer */
|
||||
curl_multi_add_handle(multi_handle, trans[i].easy);
|
||||
|
||||
@ -130,6 +130,10 @@ int main(void)
|
||||
int i;
|
||||
struct CURLMsg *m;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
/* init a multi stack */
|
||||
multi = curl_multi_init();
|
||||
|
||||
@ -155,7 +159,6 @@ int main(void)
|
||||
if(mcode)
|
||||
break;
|
||||
|
||||
|
||||
/*
|
||||
* When doing server push, libcurl itself created and added one or more
|
||||
* easy handles but *we* need to clean them up when they are done.
|
||||
@ -173,8 +176,8 @@ int main(void)
|
||||
|
||||
}
|
||||
|
||||
|
||||
curl_multi_cleanup(multi);
|
||||
curl_global_cleanup();
|
||||
|
||||
/* 'pushindex' is now the number of received transfers */
|
||||
for(i = 0; i < pushindex; i++) {
|
||||
|
||||
@ -212,6 +212,7 @@ static int server_push_callback(CURL *parent,
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
CURLcode res;
|
||||
CURL *easy;
|
||||
CURLM *multi_handle;
|
||||
int transfers = 1; /* we start with one */
|
||||
@ -221,6 +222,10 @@ int main(int argc, char *argv[])
|
||||
if(argc == 2)
|
||||
url = argv[1];
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
/* init a multi stack */
|
||||
multi_handle = curl_multi_init();
|
||||
|
||||
@ -229,6 +234,7 @@ int main(int argc, char *argv[])
|
||||
/* set options */
|
||||
if(setup(easy, url)) {
|
||||
fprintf(stderr, "failed\n");
|
||||
curl_global_cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -270,7 +276,7 @@ int main(int argc, char *argv[])
|
||||
} while(transfers); /* as long as we have transfers going */
|
||||
|
||||
curl_multi_cleanup(multi_handle);
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -292,6 +292,7 @@ static int setup(struct input *i, int num, const char *upload)
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
CURLcode res;
|
||||
struct input trans[NUM_HANDLES];
|
||||
CURLM *multi_handle;
|
||||
int i;
|
||||
@ -313,12 +314,18 @@ int main(int argc, char **argv)
|
||||
else
|
||||
num_transfers = 3;
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
/* init a multi stack */
|
||||
multi_handle = curl_multi_init();
|
||||
|
||||
for(i = 0; i < num_transfers; i++) {
|
||||
if(setup(&trans[i], i, filename))
|
||||
if(setup(&trans[i], i, filename)) {
|
||||
curl_global_cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* add the individual transfer */
|
||||
curl_multi_add_handle(multi_handle, trans[i].hnd);
|
||||
@ -348,5 +355,7 @@ int main(int argc, char **argv)
|
||||
curl_easy_cleanup(trans[i].hnd);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -32,7 +32,9 @@ int main(void)
|
||||
{
|
||||
curl_version_info_data *ver;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
ver = curl_version_info(CURLVERSION_NOW);
|
||||
if(ver->features & CURL_VERSION_HTTP2)
|
||||
|
||||
@ -31,7 +31,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -50,5 +53,6 @@ int main(void)
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -31,7 +31,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -68,5 +71,6 @@ int main(void)
|
||||
/* free the custom headers */
|
||||
curl_slist_free_all(chunk);
|
||||
}
|
||||
return 0;
|
||||
curl_global_cleanup();
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -58,7 +58,9 @@ int main(int argc, char **argv)
|
||||
url = argv[1];
|
||||
|
||||
/* In Windows, this inits the Winsock stuff */
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
/* get a curl handle */
|
||||
curl = curl_easy_init();
|
||||
@ -100,5 +102,5 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -101,7 +101,11 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* In Windows, this inits the Winsock stuff */
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res) {
|
||||
fclose(hd_src);
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
/* get a curl handle */
|
||||
curl = curl_easy_init();
|
||||
@ -137,5 +141,5 @@ int main(int argc, char **argv)
|
||||
fclose(hd_src); /* close the local file */
|
||||
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -31,9 +31,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -79,5 +80,5 @@ int main(void)
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -87,7 +87,10 @@ static size_t payload_source(char *ptr, size_t size, size_t nmemb, void *userp)
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -126,5 +129,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -69,5 +72,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -69,5 +72,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -65,5 +68,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -65,5 +68,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -65,5 +68,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -63,5 +66,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -64,5 +67,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -66,5 +69,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,44 +39,48 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLM *mcurl;
|
||||
int still_running = 1;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(!curl)
|
||||
return 1;
|
||||
if(curl) {
|
||||
CURLM *mcurl;
|
||||
|
||||
mcurl = curl_multi_init();
|
||||
if(!mcurl)
|
||||
return 2;
|
||||
mcurl = curl_multi_init();
|
||||
if(mcurl) {
|
||||
int still_running = 1;
|
||||
|
||||
/* Set username and password */
|
||||
curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
|
||||
curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");
|
||||
/* Set username and password */
|
||||
curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
|
||||
curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");
|
||||
|
||||
/* This fetches message 1 from the user's inbox */
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "imap://imap.example.com/INBOX/;UID=1");
|
||||
/* This fetches message 1 from the user's inbox */
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "imap://imap.example.com/"
|
||||
"INBOX/;UID=1");
|
||||
|
||||
/* Tell the multi stack about our easy handle */
|
||||
curl_multi_add_handle(mcurl, curl);
|
||||
/* Tell the multi stack about our easy handle */
|
||||
curl_multi_add_handle(mcurl, curl);
|
||||
|
||||
do {
|
||||
CURLMcode mc = curl_multi_perform(mcurl, &still_running);
|
||||
do {
|
||||
CURLMcode mc = curl_multi_perform(mcurl, &still_running);
|
||||
|
||||
if(still_running)
|
||||
/* wait for activity, timeout or "nothing" */
|
||||
mc = curl_multi_poll(mcurl, NULL, 0, 1000, NULL);
|
||||
if(still_running)
|
||||
/* wait for activity, timeout or "nothing" */
|
||||
mc = curl_multi_poll(mcurl, NULL, 0, 1000, NULL);
|
||||
|
||||
if(mc)
|
||||
break;
|
||||
} while(still_running);
|
||||
if(mc)
|
||||
break;
|
||||
} while(still_running);
|
||||
|
||||
/* Always cleanup */
|
||||
curl_multi_remove_handle(mcurl, curl);
|
||||
curl_multi_cleanup(mcurl);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
/* Always cleanup */
|
||||
curl_multi_remove_handle(mcurl, curl);
|
||||
curl_multi_cleanup(mcurl);
|
||||
curl_easy_cleanup(curl);
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -65,5 +68,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -69,5 +72,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -40,7 +40,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -90,5 +93,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -80,5 +83,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -40,7 +40,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -90,5 +93,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -31,7 +31,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -48,5 +51,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -31,7 +31,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -44,5 +47,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -31,7 +31,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -54,5 +57,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -31,7 +31,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -49,5 +52,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -207,6 +207,7 @@ static size_t mywrite(char *ptr, size_t size, size_t nmemb, void *userdata)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
CURLcode res;
|
||||
unsigned i;
|
||||
int total_failed = 0;
|
||||
char errbuf[CURL_ERROR_SIZE] = { 0, };
|
||||
@ -222,9 +223,10 @@ int main(void)
|
||||
transfer[1].bodyfile = "400.txt";
|
||||
transfer[1].logfile = "400_transfer_log.txt";
|
||||
|
||||
if(curl_global_init(CURL_GLOBAL_DEFAULT)) {
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res) {
|
||||
fprintf(stderr, "curl_global_init failed\n");
|
||||
return 1;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
/* You could enable global tracing for extra verbosity when verbosity is
|
||||
@ -334,5 +336,7 @@ int main(void)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return total_failed ? 1 : 0;
|
||||
}
|
||||
|
||||
@ -31,7 +31,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -62,5 +65,8 @@ int main(void)
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -52,6 +52,10 @@ int main(void)
|
||||
CURLMsg *msg; /* for picking up messages with the transfer status */
|
||||
int msgs_left; /* how many messages are left */
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
/* Allocate one curl handle per transfer */
|
||||
for(i = 0; i < HANDLECOUNT; i++)
|
||||
handles[i] = curl_easy_init();
|
||||
@ -110,6 +114,7 @@ int main(void)
|
||||
}
|
||||
|
||||
curl_multi_cleanup(multi_handle);
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -127,6 +127,10 @@ int main(void)
|
||||
|
||||
int still_running = 0; /* keep number of running handles */
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
http_handle = curl_easy_init();
|
||||
|
||||
/* set the options (I left out a few, you get the point anyway) */
|
||||
@ -157,5 +161,7 @@ int main(void)
|
||||
|
||||
curl_easy_cleanup(http_handle);
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -42,6 +42,10 @@ int main(void)
|
||||
|
||||
int still_running = 1; /* keep number of running handles */
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
http_handle = curl_easy_init();
|
||||
http_handle2 = curl_easy_init();
|
||||
|
||||
@ -89,5 +93,7 @@ int main(void)
|
||||
curl_easy_cleanup(http_handle);
|
||||
curl_easy_cleanup(http_handle2);
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -219,12 +219,15 @@ static int handle_socket(CURL *easy, curl_socket_t s, int action, void *userp,
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
CURLcode res;
|
||||
|
||||
if(argc <= 1)
|
||||
return 0;
|
||||
|
||||
if(curl_global_init(CURL_GLOBAL_ALL)) {
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res) {
|
||||
fprintf(stderr, "Could not init curl\n");
|
||||
return 1;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
base = event_base_new();
|
||||
|
||||
@ -48,6 +48,10 @@ int main(void)
|
||||
struct curl_slist *headerlist = NULL;
|
||||
static const char buf[] = "Expect:";
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
CURL_IGNORE_DEPRECATION(
|
||||
/* Fill in the file upload field. This makes libcurl load data from
|
||||
the given file name when curl_easy_perform() is called. */
|
||||
@ -116,5 +120,6 @@ int main(void)
|
||||
/* free slist */
|
||||
curl_slist_free_all(headerlist);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -58,6 +58,10 @@ int main(void)
|
||||
CURLMsg *msg; /* for picking up messages with the transfer status */
|
||||
int msgs_left; /* how many messages are left */
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
/* Allocate one curl handle per transfer */
|
||||
for(i = 0; i < HANDLECOUNT; i++)
|
||||
handles[i] = curl_easy_init();
|
||||
@ -187,5 +191,7 @@ int main(void)
|
||||
for(i = 0; i < HANDLECOUNT; i++)
|
||||
curl_easy_cleanup(handles[i]);
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -43,6 +43,10 @@ int main(void)
|
||||
struct curl_slist *headerlist = NULL;
|
||||
static const char buf[] = "Expect:";
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
multi_handle = curl_multi_init();
|
||||
|
||||
@ -100,5 +104,6 @@ int main(void)
|
||||
/* free slist */
|
||||
curl_slist_free_all(headerlist);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -41,7 +41,9 @@ int main(void)
|
||||
CURLM *multi_handle;
|
||||
int still_running = 1; /* keep number of running handles */
|
||||
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
http_handle = curl_easy_init();
|
||||
|
||||
|
||||
@ -226,13 +226,16 @@ static int cb_socket(CURL *easy, curl_socket_t s, int action,
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
CURLcode res;
|
||||
struct datauv uv = { 0 };
|
||||
int running_handles;
|
||||
|
||||
if(argc <= 1)
|
||||
return 0;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
uv.loop = uv_default_loop();
|
||||
uv_timer_init(uv.loop, &uv.timeout);
|
||||
@ -251,6 +254,7 @@ int main(int argc, char **argv)
|
||||
curl_multi_socket_action(uv.multi, CURL_SOCKET_TIMEOUT, 0, &running_handles);
|
||||
uv_run(uv.loop, UV_RUN_DEFAULT);
|
||||
curl_multi_cleanup(uv.multi);
|
||||
curl_global_cleanup();
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
|
||||
@ -72,11 +72,14 @@ static void *pull_one_url(void *pindex)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
CURLcode res;
|
||||
pthread_t tid[NUMT];
|
||||
int i;
|
||||
|
||||
/* Must initialize libcurl before any threads are started */
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
for(i = 0; i < NUMT; i++) {
|
||||
int error = pthread_create(&tid[i],
|
||||
|
||||
@ -31,7 +31,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -45,5 +48,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -32,9 +32,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -68,5 +69,5 @@ int main(void)
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -68,5 +71,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -68,5 +71,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -62,5 +65,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -38,46 +38,50 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
CURLcode res;
|
||||
CURL *curl;
|
||||
CURLM *mcurl;
|
||||
int still_running = 1;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(!curl)
|
||||
return 1;
|
||||
if(curl) {
|
||||
CURLM *mcurl;
|
||||
|
||||
mcurl = curl_multi_init();
|
||||
if(!mcurl)
|
||||
return 2;
|
||||
mcurl = curl_multi_init();
|
||||
if(mcurl) {
|
||||
int still_running = 1;
|
||||
|
||||
/* Set username and password */
|
||||
curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
|
||||
curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");
|
||||
/* Set username and password */
|
||||
curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
|
||||
curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");
|
||||
|
||||
/* This retrieves message 1 from the user's mailbox */
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "pop3://pop.example.com/1");
|
||||
/* This retrieves message 1 from the user's mailbox */
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "pop3://pop.example.com/1");
|
||||
|
||||
/* Tell the multi stack about our easy handle */
|
||||
curl_multi_add_handle(mcurl, curl);
|
||||
/* Tell the multi stack about our easy handle */
|
||||
curl_multi_add_handle(mcurl, curl);
|
||||
|
||||
do {
|
||||
CURLMcode mc = curl_multi_perform(mcurl, &still_running);
|
||||
do {
|
||||
CURLMcode mc = curl_multi_perform(mcurl, &still_running);
|
||||
|
||||
if(still_running)
|
||||
/* wait for activity, timeout or "nothing" */
|
||||
mc = curl_multi_poll(mcurl, NULL, 0, 1000, NULL);
|
||||
if(still_running)
|
||||
/* wait for activity, timeout or "nothing" */
|
||||
mc = curl_multi_poll(mcurl, NULL, 0, 1000, NULL);
|
||||
|
||||
if(mc)
|
||||
break;
|
||||
if(mc)
|
||||
break;
|
||||
|
||||
} while(still_running);
|
||||
} while(still_running);
|
||||
|
||||
/* Always cleanup */
|
||||
curl_multi_remove_handle(mcurl, curl);
|
||||
curl_multi_cleanup(mcurl);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
/* Always cleanup */
|
||||
curl_multi_remove_handle(mcurl, curl);
|
||||
curl_multi_cleanup(mcurl);
|
||||
curl_easy_cleanup(curl);
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -68,5 +71,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -62,5 +65,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -40,7 +40,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -89,5 +92,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -68,5 +71,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -40,7 +40,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -89,5 +92,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -65,5 +68,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -39,7 +39,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -65,5 +68,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ int main(void)
|
||||
if(res != CURLE_OK) {
|
||||
fprintf(stderr, "curl_global_init() failed: %s\n",
|
||||
curl_easy_strerror(res));
|
||||
return 1;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
/* get a curl handle */
|
||||
|
||||
@ -63,10 +63,13 @@ int main(void)
|
||||
struct MemoryStruct chunk;
|
||||
static const char *postthis = "Field=1&Field=2&Field=3";
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
chunk.memory = malloc(1); /* grown as needed by realloc above */
|
||||
chunk.size = 0; /* no data at this point */
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.org/");
|
||||
|
||||
@ -57,7 +57,9 @@ int main(int argc, char *argv[])
|
||||
struct curl_slist *headerlist = NULL;
|
||||
static const char buf[] = "Expect:";
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
CURL_IGNORE_DEPRECATION(
|
||||
/* Fill in the file upload field */
|
||||
|
||||
@ -53,7 +53,9 @@ int main(int argc, char *argv[])
|
||||
struct curl_slist *headerlist = NULL;
|
||||
static const char buf[] = "Expect:";
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
|
||||
@ -70,9 +70,12 @@ static int xferinfo(void *p,
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
struct myprogress prog;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
prog.lastruntime = 0;
|
||||
@ -93,5 +96,6 @@ int main(void)
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -37,7 +37,9 @@ int main(void)
|
||||
curl_version_info_data *ver;
|
||||
const char *const *ptr;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
ver = curl_version_info(CURLVERSION_NOW);
|
||||
printf("Protocols:\n");
|
||||
|
||||
@ -30,7 +30,10 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
@ -41,5 +44,7 @@ int main(void)
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
@ -32,7 +32,6 @@
|
||||
int main(void)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
/* Each single name resolve string should be written using the format
|
||||
HOST:PORT:ADDRESS where HOST is the name libcurl tries to resolve, PORT
|
||||
@ -42,6 +41,10 @@ int main(void)
|
||||
struct curl_slist *host = curl_slist_append(NULL,
|
||||
"example.com:443:127.0.0.1");
|
||||
|
||||
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_RESOLVE, host);
|
||||
@ -53,6 +56,7 @@ int main(void)
|
||||
}
|
||||
|
||||
curl_slist_free_all(host);
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user