docs/examples/10-at-a-time.c+4 -1
| @@ -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: */ |
docs/examples/address-scope.c+8 -2
| @@ -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 |
| } |
docs/examples/altsvc.c+6 -2
| @@ -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; |
| } |
docs/examples/anyauthput.c+6 -2
| @@ -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; |
| } |
docs/examples/block_ip.c+3 -2
| @@ -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(); |
docs/examples/cacertinmem.c+13 -13
| @@ -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; |
| } |
docs/examples/certinfo.c+4 -2
| @@ -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; |
| } |
docs/examples/chkspeed.c+3 -1
| @@ -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(); |
docs/examples/connect-to.c+8 -3
| @@ -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; |
| } |
docs/examples/cookie_interface.c+4 -1
| @@ -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]; |
docs/examples/crawler.c+5 -1
| @@ -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); |
docs/examples/debug.c+6 -1
| @@ -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; |
| } |
docs/examples/default-scheme.c+6 -1
| @@ -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; |
| } |
docs/examples/ephiperfifo.c+12 -1
| @@ -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; |
| } |
docs/examples/evhiperfifo.c+6 -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; |
| } |
docs/examples/externalsocket.c+5 -11
| @@ -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; |
| } |
docs/examples/fileupload.c+9 -1
| @@ -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; |
| } |
docs/examples/ftp-delete.c+4 -3
| @@ -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; |
| } |
docs/examples/ftp-wildcard.c+52 -61
| @@ -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; |
| + | } |
docs/examples/ftpget.c+4 -2
| @@ -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; |
| } |
docs/examples/ftpgetinfo.c+4 -2
| @@ -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; |
| } |
docs/examples/ftpgetresp.c+9 -2
| @@ -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; |
| } |
docs/examples/ftpsget.c+4 -2
| @@ -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; |
| } |
docs/examples/ftpupload.c+6 -2
| @@ -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; |
| } |
docs/examples/ftpuploadfrommem.c+1 -1
| @@ -122,5 +122,5 @@ int main(void) |
| curl_easy_cleanup(curl); |
| } |
| curl_global_cleanup(); |
| - | return 0; |
| + | return (int)res; |
| } |
docs/examples/ftpuploadresume.c+4 -1
| @@ -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:[email protected]/path/file", "C:\\file", |
docs/examples/getinfo.c+6 -2
| @@ -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; |
| } |
docs/examples/getinmemory.c+5 -3
| @@ -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; |
| } |
docs/examples/getredirect.c+6 -1
| @@ -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; |
| } |
docs/examples/getreferrer.c+5 -2
| @@ -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; |
| } |
docs/examples/ghiper.c+8 -1
| @@ -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; |
| } |
docs/examples/headerapi.c+5 -1
| @@ -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; |
| } |
docs/examples/hiperfifo.c+9 -1
| @@ -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; |
| } |
docs/examples/hsts-preload.c+6 -2
| @@ -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; |
| } |
docs/examples/htmltidy.c+45 -42
| @@ -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; |
| + | } |
| + | |
| + | res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)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); |
| |
| - | tdoc = tidyCreate(); |
| - | tidyOptSetBool(tdoc, TidyForceOutput, yes); /* try harder */ |
| - | tidyOptSetInt(tdoc, TidyWrapLen, 4096); |
| - | tidySetErrorBuffer(tdoc, &tidy_errbuf); |
| - | tidyBufInit(&docbuf); |
| + | 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); |
| - | 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_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; |
| } |
docs/examples/htmltitle.cpp+8 -5
| @@ -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; |
| } |
docs/examples/http-options.c+5 -1
| @@ -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; |
| } |
docs/examples/http-post.c+4 -2
| @@ -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; |
| } |
docs/examples/http2-download.c+9 -1
| @@ -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); |
docs/examples/http2-pushinmemory.c+5 -2
| @@ -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++) { |
docs/examples/http2-serverpush.c+7 -1
| @@ -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; |
| } |
docs/examples/http2-upload.c+10 -1
| @@ -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; |
| } |
docs/examples/http3-present.c+3 -1
| @@ -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) |
docs/examples/http3.c+5 -1
| @@ -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; |
| } |
docs/examples/httpcustomheader.c+6 -2
| @@ -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; |
| } |
docs/examples/httpput-postfields.c+4 -2
| @@ -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; |
| } |
docs/examples/httpput.c+6 -2
| @@ -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; |
| } |
docs/examples/https.c+4 -3
| @@ -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; |
| } |
docs/examples/imap-append.c+6 -1
| @@ -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; |
| } |
docs/examples/imap-authzid.c+6 -1
| @@ -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; |
| } |
docs/examples/imap-copy.c+6 -1
| @@ -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; |
| } |
docs/examples/imap-create.c+6 -1
| @@ -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; |
| } |
docs/examples/imap-delete.c+6 -1
| @@ -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; |
| } |
docs/examples/imap-examine.c+6 -1
| @@ -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; |
| } |
docs/examples/imap-fetch.c+6 -1
| @@ -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; |
| } |
docs/examples/imap-list.c+6 -1
| @@ -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; |
| } |
docs/examples/imap-lsub.c+6 -1
| @@ -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; |
| } |
docs/examples/imap-multi.c+31 -27
| @@ -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; |
docs/examples/imap-noop.c+6 -1
| @@ -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; |
| } |
docs/examples/imap-search.c+6 -1
| @@ -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; |
| } |
docs/examples/imap-ssl.c+6 -1
| @@ -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; |
| } |
docs/examples/imap-store.c+6 -1
| @@ -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; |
| } |
docs/examples/imap-tls.c+6 -1
| @@ -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; |
| } |
docs/examples/interface.c+6 -1
| @@ -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; |
| } |
docs/examples/ipv6.c+6 -1
| @@ -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; |
| } |
docs/examples/keepalive.c+6 -1
| @@ -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; |
| } |
docs/examples/localport.c+6 -1
| @@ -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; |
| } |
docs/examples/log_failed_transfers.c+6 -2
| @@ -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; |
| } |
docs/examples/maxconnects.c+7 -1
| @@ -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; |
| } |
docs/examples/multi-app.c+5 -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; |
| } |
docs/examples/multi-debugcallback.c+6 -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; |
| } |
docs/examples/multi-double.c+6 -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; |
| } |
docs/examples/multi-event.c+5 -2
| @@ -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(); |
docs/examples/multi-formadd.c+5 -0
| @@ -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; |
| } |
docs/examples/multi-legacy.c+6 -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; |
| } |
docs/examples/multi-post.c+5 -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; |
| } |
docs/examples/multi-single.c+3 -1
| @@ -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(); |
| |
docs/examples/multi-uv.c+5 -1
| @@ -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(); |
| |
docs/examples/multithread.c+4 -1
| @@ -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], |
docs/examples/netrc.c+6 -1
| @@ -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; |
| } |
docs/examples/persistent.c+4 -3
| @@ -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; |
| } |
docs/examples/pop3-authzid.c+6 -1
| @@ -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; |
| } |
docs/examples/pop3-dele.c+6 -1
| @@ -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; |
| } |
docs/examples/pop3-list.c+6 -1
| @@ -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; |
| } |
docs/examples/pop3-multi.c+31 -27
| @@ -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; |
docs/examples/pop3-noop.c+6 -1
| @@ -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; |
| } |
docs/examples/pop3-retr.c+6 -1
| @@ -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; |
| } |
docs/examples/pop3-ssl.c+6 -1
| @@ -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; |
| } |
docs/examples/pop3-stat.c+6 -1
| @@ -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; |
| } |
docs/examples/pop3-tls.c+6 -1
| @@ -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; |
| } |
docs/examples/pop3-top.c+6 -1
| @@ -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; |
| } |
docs/examples/pop3-uidl.c+6 -1
| @@ -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; |
| } |
docs/examples/post-callback.c+1 -1
| @@ -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 */ |
docs/examples/postinmemory.c+4 -1
| @@ -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/"); |
docs/examples/postit2-formadd.c+3 -1
| @@ -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 */ |
docs/examples/postit2.c+3 -1
| @@ -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) { |
docs/examples/progressfunc.c+5 -1
| @@ -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; |
| } |
docs/examples/protofeats.c+3 -1
| @@ -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"); |
docs/examples/range.c+6 -1
| @@ -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; |
| } |
docs/examples/resolve.c+5 -1
| @@ -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; |
| } |
docs/examples/rtsp-options.c+5 -1
| @@ -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) { |
| @@ -51,5 +54,6 @@ int main(void) |
| /* always cleanup */ |
| curl_easy_cleanup(curl); |
| } |
| + | curl_global_cleanup(); |
| return 0; |
| } |
docs/examples/sendrecv.c+5 -1
| @@ -83,6 +83,10 @@ int main(void) |
| const char *request = "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n"; |
| size_t request_len = strlen(request); |
| |
| + | CURLcode res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)res; |
| + | |
| /* A general note of caution here: if you are using curl_easy_recv() or |
| curl_easy_send() to implement HTTP or _any_ other protocol libcurl |
| supports "natively", you are doing it wrong and you should stop. |
| @@ -93,7 +97,6 @@ int main(void) |
| |
| curl = curl_easy_init(); |
| if(curl) { |
| - | CURLcode res; |
| curl_socket_t sockfd; |
| size_t nsent_total = 0; |
| |
| @@ -175,5 +178,6 @@ int main(void) |
| /* always cleanup */ |
| curl_easy_cleanup(curl); |
| } |
| + | curl_global_cleanup(); |
| return 0; |
| } |
docs/examples/sepheaders.c+49 -44
| @@ -38,60 +38,65 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) |
| |
| int main(void) |
| { |
| - | CURLcode res; |
| CURL *curl_handle; |
| - | static const char *headerfilename = "head.out"; |
| - | FILE *headerfile; |
| - | static const char *bodyfilename = "body.out"; |
| - | FILE *bodyfile; |
| |
| - | curl_global_init(CURL_GLOBAL_ALL); |
| + | CURLcode res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)res; |
| |
| /* init the curl session */ |
| curl_handle = curl_easy_init(); |
| + | if(curl_handle) { |
| + | static const char *headerfilename = "head.out"; |
| + | FILE *headerfile; |
| + | static const char *bodyfilename = "body.out"; |
| + | FILE *bodyfile; |
| + | |
| + | /* set URL to get */ |
| + | curl_easy_setopt(curl_handle, CURLOPT_URL, "https://example.com"); |
| + | |
| + | /* no progress meter please */ |
| + | curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L); |
| + | |
| + | /* send all data to this function */ |
| + | curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data); |
| + | |
| + | /* open the header file */ |
| + | headerfile = fopen(headerfilename, "wb"); |
| + | if(!headerfile) { |
| + | curl_easy_cleanup(curl_handle); |
| + | curl_global_cleanup(); |
| + | return -1; |
| + | } |
| + | |
| + | /* open the body file */ |
| + | bodyfile = fopen(bodyfilename, "wb"); |
| + | if(!bodyfile) { |
| + | curl_easy_cleanup(curl_handle); |
| + | fclose(headerfile); |
| + | curl_global_cleanup(); |
| + | return -1; |
| + | } |
| + | |
| + | /* we want the headers be written to this file handle */ |
| + | curl_easy_setopt(curl_handle, CURLOPT_HEADERDATA, headerfile); |
| + | |
| + | /* we want the body be written to this file handle instead of stdout */ |
| + | curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, bodyfile); |
| + | |
| + | /* get it! */ |
| + | res = curl_easy_perform(curl_handle); |
| + | |
| + | /* close the header file */ |
| + | fclose(headerfile); |
| |
| - | /* set URL to get */ |
| - | curl_easy_setopt(curl_handle, CURLOPT_URL, "https://example.com"); |
| - | |
| - | /* no progress meter please */ |
| - | curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L); |
| - | |
| - | /* send all data to this function */ |
| - | curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data); |
| + | /* close the body file */ |
| + | fclose(bodyfile); |
| |
| - | /* open the header file */ |
| - | headerfile = fopen(headerfilename, "wb"); |
| - | if(!headerfile) { |
| + | /* cleanup curl stuff */ |
| curl_easy_cleanup(curl_handle); |
| - | return -1; |
| - | } |
| - | |
| - | /* open the body file */ |
| - | bodyfile = fopen(bodyfilename, "wb"); |
| - | if(!bodyfile) { |
| - | curl_easy_cleanup(curl_handle); |
| - | fclose(headerfile); |
| - | return -1; |
| } |
| |
| - | /* we want the headers be written to this file handle */ |
| - | curl_easy_setopt(curl_handle, CURLOPT_HEADERDATA, headerfile); |
| - | |
| - | /* we want the body be written to this file handle instead of stdout */ |
| - | curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, bodyfile); |
| - | |
| - | /* get it! */ |
| - | res = curl_easy_perform(curl_handle); |
| - | |
| - | /* close the header file */ |
| - | fclose(headerfile); |
| - | |
| - | /* close the body file */ |
| - | fclose(bodyfile); |
| - | |
| - | /* cleanup curl stuff */ |
| - | curl_easy_cleanup(curl_handle); |
| - | |
| curl_global_cleanup(); |
| |
| return (int)res; |
docs/examples/sessioninfo.c+3 -3
| @@ -96,9 +96,9 @@ static size_t wrfu(void *ptr, size_t size, size_t nmemb, void *stream) |
| |
| int main(void) |
| { |
| - | CURLcode res = CURLE_OK; |
| - | |
| - | 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) { |
docs/examples/sftpget.c+4 -3
| @@ -62,13 +62,14 @@ static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, |
| int main(void) |
| { |
| CURL *curl; |
| - | CURLcode res; |
| struct FtpFile ftpfile = { |
| "yourfile.bin", /* name to store the file as if successful */ |
| NULL |
| }; |
| |
| - | 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) { |
| @@ -108,5 +109,5 @@ int main(void) |
| |
| curl_global_cleanup(); |
| |
| - | return 0; |
| + | return (int)res; |
| } |
docs/examples/sftpuploadresume.c+4 -1
| @@ -125,7 +125,10 @@ int main(void) |
| const char *filename = "filename"; |
| 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(); |
| |
| if(!sftpResumeUpload(curlhandle, remote, filename)) { |
docs/examples/shared-connection-cache.c+6 -3
| @@ -51,6 +51,10 @@ int main(void) |
| CURLSH *share; |
| int i; |
| |
| + | CURLcode res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)res; |
| + | |
| share = curl_share_init(); |
| curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); |
| |
| @@ -63,8 +67,6 @@ int main(void) |
| for(i = 0; i < 3; i++) { |
| CURL *curl = curl_easy_init(); |
| if(curl) { |
| - | CURLcode res; |
| - | |
| curl_easy_setopt(curl, CURLOPT_URL, "https://curl.se/"); |
| |
| /* use the share object */ |
| @@ -83,5 +85,6 @@ int main(void) |
| } |
| |
| curl_share_cleanup(share); |
| - | return 0; |
| + | curl_global_cleanup(); |
| + | return (int)res; |
| } |
docs/examples/simple.c+5 -1
| @@ -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) { |
| @@ -49,5 +52,6 @@ int main(void) |
| /* always cleanup */ |
| curl_easy_cleanup(curl); |
| } |
| + | curl_global_cleanup(); |
| return 0; |
| } |
docs/examples/simplepost.c+7 -3
| @@ -31,10 +31,13 @@ |
| |
| int main(void) |
| { |
| + | static const char *postthis = "moo mooo moo moo"; |
| + | |
| CURL *curl; |
| - | CURLcode res; |
| |
| - | static const char *postthis = "moo mooo moo moo"; |
| + | 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; |
| } |
docs/examples/simplessl.c+5 -1
| @@ -77,7 +77,11 @@ int main(void) |
| if(!headerfile) |
| return 1; |
| |
| - | curl_global_init(CURL_GLOBAL_DEFAULT); |
| + | res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) { |
| + | fclose(headerfile); |
| + | return (int)res; |
| + | } |
| |
| curl = curl_easy_init(); |
| if(curl) { |
docs/examples/smooth-gtk-thread.c+3 -1
| @@ -169,7 +169,9 @@ int main(int argc, char **argv) |
| GtkWidget *top_window, *outside_frame, *inside_frame, *progress_bar; |
| |
| /* Must initialize libcurl before any threads are started */ |
| - | curl_global_init(CURL_GLOBAL_ALL); |
| + | CURLcode res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)res; |
| |
| /* Init thread */ |
| g_thread_init(NULL); |
docs/examples/smtp-authzid.c+6 -1
| @@ -95,10 +95,13 @@ static size_t payload_source(char *ptr, size_t size, size_t nmemb, void *userp) |
| int main(void) |
| { |
| CURL *curl; |
| - | CURLcode res = CURLE_OK; |
| struct curl_slist *recipients = NULL; |
| struct upload_status upload_ctx = { 0 }; |
| |
| + | CURLcode res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)res; |
| + | |
| curl = curl_easy_init(); |
| if(curl) { |
| /* This is the URL for your mailserver. In this example we connect to the |
| @@ -158,5 +161,7 @@ int main(void) |
| curl_easy_cleanup(curl); |
| } |
| |
| + | curl_global_cleanup(); |
| + | |
| return (int)res; |
| } |
docs/examples/smtp-expn.c+6 -1
| @@ -42,9 +42,12 @@ |
| int main(void) |
| { |
| CURL *curl; |
| - | CURLcode res; |
| struct curl_slist *recipients = NULL; |
| |
| + | CURLcode res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)res; |
| + | |
| curl = curl_easy_init(); |
| if(curl) { |
| /* This is the URL for your mailserver */ |
| @@ -77,5 +80,7 @@ int main(void) |
| curl_easy_cleanup(curl); |
| } |
| |
| + | curl_global_cleanup(); |
| + | |
| return 0; |
| } |
docs/examples/smtp-mail.c+6 -1
| @@ -92,10 +92,13 @@ static size_t payload_source(char *ptr, size_t size, size_t nmemb, void *userp) |
| int main(void) |
| { |
| CURL *curl; |
| - | CURLcode res = CURLE_OK; |
| struct curl_slist *recipients = NULL; |
| struct upload_status upload_ctx = { 0 }; |
| |
| + | CURLcode res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)res; |
| + | |
| curl = curl_easy_init(); |
| if(curl) { |
| /* This is the URL for your mailserver */ |
| @@ -146,5 +149,7 @@ int main(void) |
| curl_easy_cleanup(curl); |
| } |
| |
| + | curl_global_cleanup(); |
| + | |
| return (int)res; |
| } |
docs/examples/smtp-mime.c+6 -1
| @@ -71,7 +71,10 @@ static const char inline_html[] = |
| 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) { |
| @@ -164,5 +167,7 @@ int main(void) |
| curl_mime_free(mime); |
| } |
| |
| + | curl_global_cleanup(); |
| + | |
| return (int)res; |
| } |
docs/examples/smtp-multi.c+63 -59
| @@ -85,68 +85,72 @@ static size_t payload_source(char *ptr, size_t size, size_t nmemb, void *userp) |
| int main(void) |
| { |
| CURL *curl; |
| - | CURLM *mcurl; |
| - | int still_running = 1; |
| - | struct curl_slist *recipients = NULL; |
| - | struct upload_status upload_ctx = { 0 }; |
| |
| - | 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; |
| - | |
| - | mcurl = curl_multi_init(); |
| - | if(!mcurl) |
| - | return 2; |
| - | |
| - | /* This is the URL for your mailserver */ |
| - | curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com"); |
| - | |
| - | /* Note that this option is not strictly required, omitting it results in |
| - | * libcurl sending the MAIL FROM command with empty sender data. All |
| - | * autoresponses should have an empty reverse-path, and should be directed |
| - | * to the address in the reverse-path which triggered them. Otherwise, they |
| - | * could cause an endless loop. See RFC 5321 Section 4.5.5 for more details. |
| - | */ |
| - | curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM_MAIL); |
| - | |
| - | /* Add two recipients, in this particular case they correspond to the |
| - | * To: and Cc: addressees in the header, but they could be any kind of |
| - | * recipient. */ |
| - | recipients = curl_slist_append(recipients, TO_MAIL); |
| - | recipients = curl_slist_append(recipients, CC_MAIL); |
| - | curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients); |
| - | |
| - | /* We are using a callback function to specify the payload (the headers and |
| - | * body of the message). You could just use the CURLOPT_READDATA option to |
| - | * specify a FILE pointer to read from. */ |
| - | curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source); |
| - | curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx); |
| - | curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); |
| - | |
| - | /* Tell the multi stack about our easy handle */ |
| - | curl_multi_add_handle(mcurl, curl); |
| - | |
| - | 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(mc) |
| - | break; |
| - | |
| - | } while(still_running); |
| - | |
| - | /* Free the list of recipients */ |
| - | curl_slist_free_all(recipients); |
| - | |
| - | /* Always cleanup */ |
| - | curl_multi_remove_handle(mcurl, curl); |
| - | curl_multi_cleanup(mcurl); |
| - | curl_easy_cleanup(curl); |
| + | if(curl) { |
| + | CURLM *mcurl; |
| + | |
| + | mcurl = curl_multi_init(); |
| + | if(mcurl) { |
| + | int still_running = 1; |
| + | struct curl_slist *recipients = NULL; |
| + | struct upload_status upload_ctx = { 0 }; |
| + | |
| + | /* This is the URL for your mailserver */ |
| + | curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com"); |
| + | |
| + | /* Note that this option is not strictly required, omitting it results |
| + | * in libcurl sending the MAIL FROM command with empty sender data. All |
| + | * autoresponses should have an empty reverse-path, and should be |
| + | * directed to the address in the reverse-path which triggered them. |
| + | * Otherwise, they could cause an endless loop. See RFC 5321 Section |
| + | * 4.5.5 for more details. |
| + | */ |
| + | curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM_MAIL); |
| + | |
| + | /* Add two recipients, in this particular case they correspond to the |
| + | * To: and Cc: addressees in the header, but they could be any kind of |
| + | * recipient. */ |
| + | recipients = curl_slist_append(recipients, TO_MAIL); |
| + | recipients = curl_slist_append(recipients, CC_MAIL); |
| + | curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients); |
| + | |
| + | /* We are using a callback function to specify the payload (the headers |
| + | * and body of the message). You could just use the CURLOPT_READDATA |
| + | * option to specify a FILE pointer to read from. */ |
| + | curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source); |
| + | curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx); |
| + | curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); |
| + | |
| + | /* Tell the multi stack about our easy handle */ |
| + | curl_multi_add_handle(mcurl, curl); |
| + | |
| + | 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(mc) |
| + | break; |
| + | |
| + | } while(still_running); |
| + | |
| + | /* Free the list of recipients */ |
| + | curl_slist_free_all(recipients); |
| + | |
| + | /* Always cleanup */ |
| + | curl_multi_remove_handle(mcurl, curl); |
| + | curl_multi_cleanup(mcurl); |
| + | } |
| + | curl_easy_cleanup(curl); |
| + | } |
| + | |
| curl_global_cleanup(); |
| |
| return 0; |
docs/examples/smtp-ssl.c+6 -1
| @@ -89,10 +89,13 @@ static size_t payload_source(char *ptr, size_t size, size_t nmemb, void *userp) |
| int main(void) |
| { |
| CURL *curl; |
| - | CURLcode res = CURLE_OK; |
| struct curl_slist *recipients = NULL; |
| struct upload_status upload_ctx = { 0 }; |
| |
| + | CURLcode res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)res; |
| + | |
| curl = curl_easy_init(); |
| if(curl) { |
| /* Set username and password */ |
| @@ -166,5 +169,7 @@ int main(void) |
| curl_easy_cleanup(curl); |
| } |
| |
| + | curl_global_cleanup(); |
| + | |
| return (int)res; |
| } |
docs/examples/smtp-tls.c+6 -1
| @@ -89,10 +89,13 @@ static size_t payload_source(char *ptr, size_t size, size_t nmemb, void *userp) |
| int main(void) |
| { |
| CURL *curl; |
| - | CURLcode res = CURLE_OK; |
| struct curl_slist *recipients = NULL; |
| struct upload_status upload_ctx = { 0 }; |
| |
| + | CURLcode res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)res; |
| + | |
| curl = curl_easy_init(); |
| if(curl) { |
| /* Set username and password */ |
| @@ -169,5 +172,7 @@ int main(void) |
| curl_easy_cleanup(curl); |
| } |
| |
| + | curl_global_cleanup(); |
| + | |
| return (int)res; |
| } |
docs/examples/smtp-vrfy.c+7 -2
| @@ -45,9 +45,12 @@ |
| int main(void) |
| { |
| CURL *curl; |
| - | CURLcode res; |
| struct curl_slist *recipients = NULL; |
| |
| + | CURLcode res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)res; |
| + | |
| curl = curl_easy_init(); |
| if(curl) { |
| /* This is the URL for your mailserver */ |
| @@ -77,5 +80,7 @@ int main(void) |
| curl_easy_cleanup(curl); |
| } |
| |
| - | return 0; |
| + | curl_global_cleanup(); |
| + | |
| + | return (int)res; |
| } |
docs/examples/synctime.c+5 -1
| @@ -245,6 +245,7 @@ static int conf_init(struct conf *conf) |
| |
| int main(int argc, char *argv[]) |
| { |
| + | CURLcode res; |
| CURL *curl; |
| struct conf conf[1]; |
| int RetValue; |
| @@ -285,7 +286,10 @@ int main(int argc, char *argv[]) |
| snprintf(conf->timeserver, MAX_STRING, "%s", DefaultTimeServer[0]); |
| |
| /* Init CURL before usage */ |
| - | curl_global_init(CURL_GLOBAL_ALL); |
| + | res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)res; |
| + | |
| curl = curl_easy_init(); |
| if(curl) { |
| struct tm *lt; |
docs/examples/threaded-ssl.c+4 -1
| @@ -72,13 +72,16 @@ static void *pull_one_url(void *pindex) |
| |
| int main(int argc, char **argv) |
| { |
| + | CURLcode res; |
| pthread_t tid[NUMT]; |
| int i; |
| (void)argc; |
| (void)argv; |
| |
| /* 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], |
docs/examples/unixsocket.c+6 -2
| @@ -41,7 +41,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) { |
| @@ -63,5 +66,6 @@ int main(void) |
| /* always cleanup */ |
| curl_easy_cleanup(curl); |
| } |
| - | return 0; |
| + | curl_global_cleanup(); |
| + | return (int)res; |
| } |
docs/examples/url2file.c+6 -3
| @@ -38,8 +38,7 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) |
| |
| int main(int argc, char *argv[]) |
| { |
| - | CURLcode res = CURLE_OK; |
| - | |
| + | CURLcode res; |
| CURL *curl_handle; |
| static const char *pagefilename = "page.out"; |
| FILE *pagefile; |
| @@ -49,7 +48,11 @@ int main(int argc, char *argv[]) |
| return 1; |
| } |
| |
| - | curl_global_init(CURL_GLOBAL_ALL); |
| + | res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) { |
| + | fprintf(stderr, "Could not init curl\n"); |
| + | return (int)res; |
| + | } |
| |
| /* init the curl session */ |
| curl_handle = curl_easy_init(); |
docs/examples/urlapi.c+6 -2
| @@ -35,11 +35,14 @@ |
| int main(void) |
| { |
| CURL *curl; |
| - | CURLcode res; |
| |
| CURLU *urlp; |
| CURLUcode uc; |
| |
| + | CURLcode res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)res; |
| + | |
| /* get a curl handle */ |
| curl = curl_easy_init(); |
| |
| @@ -73,5 +76,6 @@ int main(void) |
| cleanup: |
| curl_url_cleanup(urlp); |
| curl_easy_cleanup(curl); |
| - | return 0; |
| + | curl_global_cleanup(); |
| + | return (int)res; |
| } |
docs/examples/usercertinmem.c+9 -6
| @@ -157,7 +157,10 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *pointer) |
| int main(void) |
| { |
| CURL *ch; |
| - | CURLcode rv; |
| + | |
| + | CURLcode res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)res; |
| |
| curl_global_init(CURL_GLOBAL_ALL); |
| ch = curl_easy_init(); |
| @@ -180,8 +183,8 @@ int main(void) |
| curl_easy_setopt(ch, CURLOPT_SSLKEYTYPE, "PEM"); |
| |
| /* first try: retrieve page without user certificate and key -> fails */ |
| - | 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"); |
| @@ -191,13 +194,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; |
| } |
docs/examples/websocket-cb.c+6 -2
| @@ -44,7 +44,10 @@ static size_t writecb(char *b, size_t size, size_t nitems, void *p) |
| 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) { |
| @@ -64,5 +67,6 @@ int main(void) |
| /* always cleanup */ |
| curl_easy_cleanup(curl); |
| } |
| - | return 0; |
| + | curl_global_cleanup(); |
| + | return (int)res; |
| } |
docs/examples/websocket-updown.c+29 -26
| @@ -87,39 +87,42 @@ int main(int argc, const char *argv[]) |
| { |
| CURL *easy; |
| struct read_ctx rctx; |
| - | CURLcode res; |
| const char *payload = "Hello, friend!"; |
| |
| + | CURLcode res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)res; |
| + | |
| memset(&rctx, 0, sizeof(rctx)); |
| |
| easy = curl_easy_init(); |
| - | if(!easy) |
| - | return 1; |
| - | |
| - | if(argc == 2) |
| - | curl_easy_setopt(easy, CURLOPT_URL, argv[1]); |
| - | else |
| - | curl_easy_setopt(easy, CURLOPT_URL, "wss://example.com"); |
| + | if(easy) { |
| + | if(argc == 2) |
| + | curl_easy_setopt(easy, CURLOPT_URL, argv[1]); |
| + | else |
| + | curl_easy_setopt(easy, CURLOPT_URL, "wss://example.com"); |
| |
| - | curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, writecb); |
| - | curl_easy_setopt(easy, CURLOPT_WRITEDATA, easy); |
| - | curl_easy_setopt(easy, CURLOPT_READFUNCTION, readcb); |
| - | /* tell curl that we want to send the payload */ |
| - | rctx.easy = easy; |
| - | rctx.blen = strlen(payload); |
| - | memcpy(rctx.buf, payload, rctx.blen); |
| - | curl_easy_setopt(easy, CURLOPT_READDATA, &rctx); |
| - | curl_easy_setopt(easy, CURLOPT_UPLOAD, 1L); |
| + | curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, writecb); |
| + | curl_easy_setopt(easy, CURLOPT_WRITEDATA, easy); |
| + | curl_easy_setopt(easy, CURLOPT_READFUNCTION, readcb); |
| + | /* tell curl that we want to send the payload */ |
| + | rctx.easy = easy; |
| + | rctx.blen = strlen(payload); |
| + | memcpy(rctx.buf, payload, rctx.blen); |
| + | curl_easy_setopt(easy, CURLOPT_READDATA, &rctx); |
| + | curl_easy_setopt(easy, CURLOPT_UPLOAD, 1L); |
| |
| |
| - | /* Perform the request, res gets the return code */ |
| - | res = curl_easy_perform(easy); |
| - | /* Check for errors */ |
| - | if(res != CURLE_OK) |
| - | fprintf(stderr, "curl_easy_perform() failed: %s\n", |
| - | curl_easy_strerror(res)); |
| + | /* Perform the request, res gets the return code */ |
| + | res = curl_easy_perform(easy); |
| + | /* Check for errors */ |
| + | if(res != CURLE_OK) |
| + | fprintf(stderr, "curl_easy_perform() failed: %s\n", |
| + | curl_easy_strerror(res)); |
| |
| - | /* always cleanup */ |
| - | curl_easy_cleanup(easy); |
| - | return 0; |
| + | /* always cleanup */ |
| + | curl_easy_cleanup(easy); |
| + | } |
| + | curl_global_cleanup(); |
| + | return (int)res; |
| } |
docs/examples/websocket.c+24 -21
| @@ -138,31 +138,34 @@ static CURLcode websocket(CURL *curl) |
| int main(int argc, const char *argv[]) |
| { |
| CURL *curl; |
| - | CURLcode res; |
| + | |
| + | CURLcode res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)res; |
| |
| curl = curl_easy_init(); |
| - | if(!curl) { |
| - | return 1; /* memory failure */ |
| - | } |
| - | if(argc == 2) |
| - | curl_easy_setopt(curl, CURLOPT_URL, argv[1]); |
| - | else |
| - | curl_easy_setopt(curl, CURLOPT_URL, "wss://example.com"); |
| + | if(curl) { |
| + | if(argc == 2) |
| + | curl_easy_setopt(curl, CURLOPT_URL, argv[1]); |
| + | else |
| + | curl_easy_setopt(curl, CURLOPT_URL, "wss://example.com"); |
| |
| - | curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L); /* websocket style */ |
| + | curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L); /* websocket style */ |
| |
| - | /* Perform the request, res gets the return code */ |
| - | res = curl_easy_perform(curl); |
| - | /* Check for errors */ |
| - | if(res != CURLE_OK) |
| - | fprintf(stderr, "curl_easy_perform() failed: %s\n", |
| - | curl_easy_strerror(res)); |
| - | else { |
| - | /* connected and ready */ |
| - | res = websocket(curl); |
| - | } |
| + | /* Perform the request, res gets the return code */ |
| + | res = curl_easy_perform(curl); |
| + | /* Check for errors */ |
| + | if(res != CURLE_OK) |
| + | fprintf(stderr, "curl_easy_perform() failed: %s\n", |
| + | curl_easy_strerror(res)); |
| + | else { |
| + | /* connected and ready */ |
| + | res = websocket(curl); |
| + | } |
| |
| - | /* always cleanup */ |
| - | curl_easy_cleanup(curl); |
| + | /* always cleanup */ |
| + | curl_easy_cleanup(curl); |
| + | } |
| + | curl_global_cleanup(); |
| return (int)res; |
| } |
docs/examples/xmlstream.c+5 -2
| @@ -131,8 +131,11 @@ int main(void) |
| XML_SetElementHandler(parser, startElement, endElement); |
| XML_SetCharacterDataHandler(parser, characterDataHandler); |
| |
| + | res = curl_global_init(CURL_GLOBAL_ALL); |
| + | if(res) |
| + | return (int)res; |
| + | |
| /* Initialize a libcurl handle. */ |
| - | curl_global_init(CURL_GLOBAL_DEFAULT); |
| curl_handle = curl_easy_init(); |
| curl_easy_setopt(curl_handle, CURLOPT_URL, |
| "https://www.w3schools.com/xml/simple.xml"); |
| @@ -166,5 +169,5 @@ int main(void) |
| curl_easy_cleanup(curl_handle); |
| curl_global_cleanup(); |
| |
| - | return 0; |
| + | return (int)res; |
| } |