diff options
Diffstat (limited to 'docs/examples')
105 files changed, 1890 insertions, 1134 deletions
diff --git a/docs/examples/.gitignore b/docs/examples/.gitignore index d64e12de..aece671c 100644 --- a/docs/examples/.gitignore +++ b/docs/examples/.gitignore @@ -73,3 +73,7 @@ smtp-vrfy url2file usercertinmem xmlstream +http2-download +http2-serverpush +http2-upload +imap-lsub diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index 5d95a8a8..aa1862ec 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,9 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ -/* Example application source code using the multi interface to download many - * files, but with a capped maximum amount of simultaneous transfers. - * +/* <DESC> + * Source code using the multi interface to download many + * files, with a capped maximum amount of simultaneous transfers. + * </DESC> * Written by Michael Wallner */ @@ -126,41 +127,42 @@ int main(void) uses */ curl_multi_setopt(cm, CURLMOPT_MAXCONNECTS, (long)MAX); - for (C = 0; C < MAX; ++C) { + for(C = 0; C < MAX; ++C) { init(cm, C); } - while (U) { + while(U) { curl_multi_perform(cm, &U); - if (U) { + if(U) { FD_ZERO(&R); FD_ZERO(&W); FD_ZERO(&E); - if (curl_multi_fdset(cm, &R, &W, &E, &M)) { + if(curl_multi_fdset(cm, &R, &W, &E, &M)) { fprintf(stderr, "E: curl_multi_fdset\n"); return EXIT_FAILURE; } - if (curl_multi_timeout(cm, &L)) { + if(curl_multi_timeout(cm, &L)) { fprintf(stderr, "E: curl_multi_timeout\n"); return EXIT_FAILURE; } - if (L == -1) + if(L == -1) L = 100; - if (M == -1) { + if(M == -1) { #ifdef WIN32 Sleep(L); #else - sleep(L / 1000); + sleep((unsigned int)L / 1000); #endif - } else { + } + else { T.tv_sec = L/1000; T.tv_usec = (L%1000)*1000; - if (0 > select(M+1, &R, &W, &E, &T)) { + if(0 > select(M+1, &R, &W, &E, &T)) { fprintf(stderr, "E: select(%i,,,,%li): %i: %s\n", M+1, L, errno, strerror(errno)); return EXIT_FAILURE; @@ -168,8 +170,8 @@ int main(void) } } - while ((msg = curl_multi_info_read(cm, &Q))) { - if (msg->msg == CURLMSG_DONE) { + while((msg = curl_multi_info_read(cm, &Q))) { + if(msg->msg == CURLMSG_DONE) { char *url; CURL *e = msg->easy_handle; curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &url); @@ -181,7 +183,7 @@ int main(void) else { fprintf(stderr, "E: CURLMsg (%d)\n", msg->msg); } - if (C < CNT) { + if(C < CNT) { init(cm, C++); U++; /* just to prevent it from remaining at 0 if there are more URLs to get */ diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 8e2bc9a8..7a56f345 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -5,11 +5,11 @@ # | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # -# Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. +# Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms -# are also available at http://curl.haxx.se/docs/copyright.html. +# are also available at https://curl.haxx.se/docs/copyright.html. # # You may opt to use, copy, modify, merge, publish, distribute and/or sell # copies of the Software, and permit persons to whom the Software is @@ -61,3 +61,6 @@ endif include Makefile.inc all: $(check_PROGRAMS) + +checksrc: + @PERL@ $(top_srcdir)/lib/checksrc.pl $(srcdir)/*.c diff --git a/docs/examples/Makefile.example b/docs/examples/Makefile.example index dfd11787..17e614ea 100644 --- a/docs/examples/Makefile.example +++ b/docs/examples/Makefile.example @@ -9,7 +9,7 @@ # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms -# are also available at http://curl.haxx.se/docs/copyright.html. +# are also available at https://curl.haxx.se/docs/copyright.html. # # You may opt to use, copy, modify, merge, publish, distribute and/or sell # copies of the Software, and permit persons to whom the Software is diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 4b0c28ff..8ce6f57f 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -5,11 +5,11 @@ # | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # -# Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. +# Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms -# are also available at http://curl.haxx.se/docs/copyright.html. +# are also available at https://curl.haxx.se/docs/copyright.html. # # You may opt to use, copy, modify, merge, publish, distribute and/or sell # copies of the Software, and permit persons to whom the Software is @@ -32,7 +32,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ imap-list imap-lsub imap-fetch imap-store imap-append imap-examine \ imap-search imap-create imap-delete imap-copy imap-noop imap-ssl \ imap-tls imap-multi url2file sftpget ftpsget postinmemory http2-download \ - http2-upload + http2-upload http2-serverpush getredirect # These examples require external dependencies that may not be commonly # available on POSIX systems, so don't bother attempting to compile them here. diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 2da5294e..e75b6d13 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -9,7 +9,7 @@ # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms -# are also available at http://curl.haxx.se/docs/copyright.html. +# are also available at https://curl.haxx.se/docs/copyright.html. # # You may opt to use, copy, modify, merge, publish, distribute and/or sell # copies of the Software, and permit persons to whom the Software is @@ -50,7 +50,7 @@ LIBRTMP_PATH = ../../../librtmp-2.4 endif # Edit the path below to point to the base of your libidn package. ifndef LIBIDN_PATH -LIBIDN_PATH = ../../../libidn-1.30 +LIBIDN_PATH = ../../../libidn-1.32 endif # Edit the path below to point to the base of your MS IDN package. # Microsoft Internationalized Domain Names (IDN) Mitigation APIs 1.1 diff --git a/docs/examples/Makefile.netware b/docs/examples/Makefile.netware index f8e9955e..2d85e736 100644 --- a/docs/examples/Makefile.netware +++ b/docs/examples/Makefile.netware @@ -34,7 +34,7 @@ endif # Edit the path below to point to the base of your libidn package. ifndef LIBIDN_PATH -LIBIDN_PATH = ../../../libidn-1.30 +LIBIDN_PATH = ../../../libidn-1.32 endif # Edit the path below to point to the base of your librtmp package. diff --git a/docs/examples/README b/docs/examples/README index 1ca62a15..078cabed 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -32,51 +32,7 @@ actually torture our web site with your tests! Thanks. EXAMPLES -anyauthput.c - HTTP PUT using "any" authentication method -cacertinmem.c - Use a built-in PEM certificate to retrieve a https page -cookie_interface.c - shows usage of simple cookie interface -curlgtk.c - download using a GTK progress bar -curlx.c - getting file info from the remote cert data -debug.c - showing how to use the debug callback -fileupload.c - uploading to a file:// URL -fopen.c - fopen() layer that supports opening URLs and files -ftpget.c - simple getting a file from FTP -ftpgetresp.c - get the response strings from the FTP server -ftpupload.c - upload a file to an FTP server -ftpuploadresume.c - resume an upload to an FTP server -getinfo.c - get the Content-Type from the recent transfer -getinmemory.c - download a file to memory only -ghiper.c - curl_multi_socket() using code with glib-2 -hiperfifo.c - downloads all URLs written to the fifo, using - curl_multi_socket() and libevent -htmltidy.c - download a document and use libtidy to parse the HTML -htmltitle.cc - download a HTML file and extract the <title> tag from a HTML - page using libxml -http-post.c - HTTP POST -httpput.c - HTTP PUT a local file -https.c - simple HTTPS transfer -imap.c - simple IMAP transfer -multi-app.c - a multi-interface app -multi-debugcallback.c - a multi-interface app using the debug callback -multi-double.c - a multi-interface app doing two simultaneous transfers -multi-post.c - a multi-interface app doing a multipart formpost -multi-single.c - a multi-interface app getting a single file -multi-uv.c - a multi-interface app using libuv -multithread.c - an example using multi-treading transferring multiple files -opensslthreadlock.c - show how to do locking when using OpenSSL multi-threaded -persistant.c - request two URLs with a persistent connection -pop3s.c - POP3S transfer -pop3slist.c - POP3S LIST -post-callback.c - send a HTTP POST using a callback -postit2.c - send a HTTP multipart formpost -sampleconv.c - showing how a program on a non-ASCII platform would invoke - callbacks to do its own codeset conversions instead of using - the built-in iconv functions in libcurl -sepheaders.c - download headers to a separate file -simple.c - the most simple download a URL source -simplepost.c - HTTP POST -simplessl.c - HTTPS example with certificates many options set -synctime.c - Sync local time by extracting date from remote HTTP servers -url2file.c - download a document and store it in a file -xmlstream.c - Stream-parse a document using the streaming Expat parser -10-at-a-time.c - Download many files simultaneously, 10 at a time. +Each example source code file is designed to be and work stand-alone and +rather self-explanatory. The examples may at times lack the level of error +checks you need in a real world, but that is then only for the sake of +readability: to make the code smaller and easier to follow. diff --git a/docs/examples/adddocsref.pl b/docs/examples/adddocsref.pl index 2dcc24b6..efebfe2b 100755 --- a/docs/examples/adddocsref.pl +++ b/docs/examples/adddocsref.pl @@ -2,7 +2,7 @@ # pass files as argument(s) -my $docroot="http://curl.haxx.se/libcurl/c"; +my $docroot="https://curl.haxx.se/libcurl/c"; for $f (@ARGV) { open(NEW, ">$f.new"); diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index b89dca2e..b1367deb 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,11 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * HTTP PUT upload with authentiction using "any" method. libcurl picks the + * one the server supports/wants. + * </DESC> + */ #include <stdio.h> #include <fcntl.h> #ifdef WIN32 @@ -73,7 +78,8 @@ /* ioctl callback function */ static curlioerr my_ioctl(CURL *handle, curliocmd cmd, void *userp) { - intptr_t fd = (intptr_t)userp; + int *fdp = (int *)userp; + int fd = *fdp; (void)handle; /* not used in here */ @@ -95,10 +101,11 @@ static curlioerr my_ioctl(CURL *handle, curliocmd cmd, void *userp) /* read callback function, fread() look alike */ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) { - size_t retcode; + ssize_t retcode; curl_off_t nread; - intptr_t fd = (intptr_t)stream; + int *fdp = (int *)stream; + int fd = *fdp; retcode = read(fd, ptr, size * nmemb); @@ -114,7 +121,7 @@ int main(int argc, char **argv) { CURL *curl; CURLcode res; - intptr_t hd ; + int hd; struct stat file_info; char *file; @@ -127,7 +134,7 @@ int main(int argc, char **argv) url = argv[2]; /* get the file size of the local file */ - hd = open(file, O_RDONLY) ; + hd = open(file, O_RDONLY); fstat(hd, &file_info); /* In windows, this will init the winsock stuff */ @@ -140,20 +147,20 @@ int main(int argc, char **argv) curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); /* which file to upload */ - curl_easy_setopt(curl, CURLOPT_READDATA, (void*)hd); + curl_easy_setopt(curl, CURLOPT_READDATA, (void*)&hd); /* set the ioctl function */ curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, my_ioctl); /* pass the file descriptor to the ioctl callback as well */ - curl_easy_setopt(curl, CURLOPT_IOCTLDATA, (void*)hd); + curl_easy_setopt(curl, CURLOPT_IOCTLDATA, (void*)&hd); /* enable "uploading" (which means PUT when doing HTTP) */ - curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L) ; + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); /* specify target URL, and note that this URL should also include a file name, not only a directory (as you can do with GTP uploads) */ - curl_easy_setopt(curl,CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_URL, url); /* and give the size of the upload, this supports large file sizes on systems that have general support for it */ diff --git a/docs/examples/asiohiper.cpp b/docs/examples/asiohiper.cpp index eb5cd038..d6065e55 100644 --- a/docs/examples/asiohiper.cpp +++ b/docs/examples/asiohiper.cpp @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2012 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 2012 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -20,11 +20,11 @@ * ***************************************************************************/ +/* <DESC> + * demonstrate the use of multi socket interface with boost::asio + * </DESC> + */ /* - * file: asiohiper.cpp - * Example program to demonstrate the use of multi socket interface - * with boost::asio - * * This program is in c++ and uses boost::asio instead of libevent/libev. * Requires boost::asio, boost::bind and boost::system * @@ -48,6 +48,7 @@ #include <curl/curl.h> #include <boost/asio.hpp> #include <boost/bind.hpp> +#include <iostream> #define MSG_OUT stdout /* Send info to stdout, change to stderr if you want */ @@ -378,9 +379,9 @@ static curl_socket_t opensocket(void *clientp, curlsocktype purpose, } /* CURLOPT_CLOSESOCKETFUNCTION */ -static int closesocket(void *clientp, curl_socket_t item) +static int close_socket(void *clientp, curl_socket_t item) { - fprintf(MSG_OUT, "\nclosesocket : %d", item); + fprintf(MSG_OUT, "\nclose_socket : %d", item); std::map<curl_socket_t, boost::asio::ip::tcp::socket *>::iterator it = socket_map.find(item); @@ -427,7 +428,7 @@ static void new_conn(char *url, GlobalInfo *g) curl_easy_setopt(conn->easy, CURLOPT_OPENSOCKETFUNCTION, opensocket); /* call this function to close a socket */ - curl_easy_setopt(conn->easy, CURLOPT_CLOSESOCKETFUNCTION, closesocket); + curl_easy_setopt(conn->easy, CURLOPT_CLOSESOCKETFUNCTION, close_socket); fprintf(MSG_OUT, "\nAdding easy %p to multi %p (%s)", conn->easy, g->multi, url); @@ -441,7 +442,6 @@ static void new_conn(char *url, GlobalInfo *g) int main(int argc, char **argv) { GlobalInfo g; - CURLMcode rc; (void)argc; (void)argv; diff --git a/docs/examples/cacertinmem.c b/docs/examples/cacertinmem.c index 30a5153a..bba8c722 100644 --- a/docs/examples/cacertinmem.c +++ b/docs/examples/cacertinmem.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,25 +19,19 @@ * KIND, either express or implied. * ***************************************************************************/ -/* Example using a "in core" PEM certificate to retrieve a https page. - * Written by Theo Borm +/* <DESC> + * CA cert in memory with OpenSSL to get a HTTPS page. + * </DESC> */ -/* on a netBSD system with OPENSSL& LIBCURL installed from - * pkgsrc (using default paths) this program can be compiled using: - * gcc -I/usr/pkg/include -L/usr/pkg/lib -lcurl -Wl,-R/usr/pkg/lib -lssl - * -lcrypto -lz -o curlcacerttest curlcacerttest.c - * on other operating systems you may want to change paths to headers - * and libraries -*/ #include <openssl/ssl.h> #include <curl/curl.h> #include <stdio.h> -size_t writefunction( void *ptr, size_t size, size_t nmemb, void *stream) +size_t writefunction(void *ptr, size_t size, size_t nmemb, void *stream) { - fwrite(ptr,size,nmemb,stream); - return(nmemb*size); + fwrite(ptr, size, nmemb, stream); + return (nmemb*size); } static CURLcode sslctx_function(CURL * curl, void * sslctx, void * parm) @@ -93,14 +87,14 @@ static CURLcode sslctx_function(CURL * curl, void * sslctx, void * parm) * structure that SSL can use */ PEM_read_bio_X509(bio, &cert, 0, NULL); - if (cert == NULL) + if(cert == NULL) printf("PEM_read_bio_X509 failed...\n"); /* get a pointer to the X509 certificate store (which may be empty!) */ store=SSL_CTX_get_cert_store((SSL_CTX *)sslctx); /* add our certificate to this store */ - if (X509_STORE_add_cert(store, cert)==0) + if(X509_STORE_add_cert(store, cert)==0) printf("error adding certificate\n"); /* decrease reference counts */ @@ -108,7 +102,7 @@ static CURLcode sslctx_function(CURL * curl, void * sslctx, void * parm) BIO_free(bio); /* all set to go */ - return CURLE_OK ; + return CURLE_OK; } int main(void) @@ -118,22 +112,22 @@ int main(void) rv=curl_global_init(CURL_GLOBAL_ALL); ch=curl_easy_init(); - rv=curl_easy_setopt(ch,CURLOPT_VERBOSE, 0L); - rv=curl_easy_setopt(ch,CURLOPT_HEADER, 0L); - rv=curl_easy_setopt(ch,CURLOPT_NOPROGRESS, 1L); - rv=curl_easy_setopt(ch,CURLOPT_NOSIGNAL, 1L); - rv=curl_easy_setopt(ch,CURLOPT_WRITEFUNCTION, *writefunction); - rv=curl_easy_setopt(ch,CURLOPT_WRITEDATA, stdout); - rv=curl_easy_setopt(ch,CURLOPT_HEADERFUNCTION, *writefunction); - rv=curl_easy_setopt(ch,CURLOPT_HEADERDATA, stderr); - rv=curl_easy_setopt(ch,CURLOPT_SSLCERTTYPE,"PEM"); - rv=curl_easy_setopt(ch,CURLOPT_SSL_VERIFYPEER,1L); + rv=curl_easy_setopt(ch, CURLOPT_VERBOSE, 0L); + rv=curl_easy_setopt(ch, CURLOPT_HEADER, 0L); + rv=curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1L); + rv=curl_easy_setopt(ch, CURLOPT_NOSIGNAL, 1L); + rv=curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, *writefunction); + rv=curl_easy_setopt(ch, CURLOPT_WRITEDATA, stdout); + rv=curl_easy_setopt(ch, CURLOPT_HEADERFUNCTION, *writefunction); + rv=curl_easy_setopt(ch, CURLOPT_HEADERDATA, stderr); + rv=curl_easy_setopt(ch, CURLOPT_SSLCERTTYPE, "PEM"); + rv=curl_easy_setopt(ch, CURLOPT_SSL_VERIFYPEER, 1L); rv=curl_easy_setopt(ch, CURLOPT_URL, "https://www.example.com/"); /* first try: retrieve page without cacerts' certificate -> will fail */ rv=curl_easy_perform(ch); - if (rv==CURLE_OK) + if(rv==CURLE_OK) printf("*** transfer succeeded ***\n"); else printf("*** transfer failed ***\n"); @@ -142,9 +136,9 @@ int main(void) * load the certificate by installing a function doing the nescessary * "modifications" to the SSL CONTEXT just before link init */ - rv=curl_easy_setopt(ch,CURLOPT_SSL_CTX_FUNCTION, *sslctx_function); + rv=curl_easy_setopt(ch, CURLOPT_SSL_CTX_FUNCTION, *sslctx_function); rv=curl_easy_perform(ch); - if (rv==CURLE_OK) + if(rv==CURLE_OK) printf("*** transfer succeeded ***\n"); else printf("*** transfer failed ***\n"); diff --git a/docs/examples/certinfo.c b/docs/examples/certinfo.c index ac0109b0..de2e3108 100644 --- a/docs/examples/certinfo.c +++ b/docs/examples/certinfo.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Extract lots of TLS certificate info. + * </DESC> + */ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/chkspeed.c b/docs/examples/chkspeed.c index 31949b89..de205671 100644 --- a/docs/examples/chkspeed.c +++ b/docs/examples/chkspeed.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Show transfer timing info after download completes. + * </DESC> + */ /* Example source code to show how the callback function can be used to * download data into a chunk of memory instead of storing it in a file. * After successful download we use curl_easy_getinfo() calls to get the @@ -64,63 +68,78 @@ int main(int argc, char *argv[]) const char *url = URL_1M; char *appname = argv[0]; - if (argc > 1) { + if(argc > 1) { /* parse input parameters */ - for (argc--, argv++; *argv; argc--, argv++) { - if (strncasecmp(*argv, "-", 1) == 0) { - if (strncasecmp(*argv, "-H", 2) == 0) { + for(argc--, argv++; *argv; argc--, argv++) { + if(strncasecmp(*argv, "-", 1) == 0) { + if(strncasecmp(*argv, "-H", 2) == 0) { fprintf(stderr, "\rUsage: %s [-m=1|2|5|10|20|50|100] [-t] [-x] [url]\n", appname); exit(1); - } else if (strncasecmp(*argv, "-V", 2) == 0) { + } + else if(strncasecmp(*argv, "-V", 2) == 0) { fprintf(stderr, "\r%s %s - %s\n", appname, CHKSPEED_VERSION, curl_version()); exit(1); - } else if (strncasecmp(*argv, "-A", 2) == 0) { + } + else if(strncasecmp(*argv, "-A", 2) == 0) { prtall = 1; - } else if (strncasecmp(*argv, "-X", 2) == 0) { + } + else if(strncasecmp(*argv, "-X", 2) == 0) { prtsep = 1; - } else if (strncasecmp(*argv, "-T", 2) == 0) { + } + else if(strncasecmp(*argv, "-T", 2) == 0) { prttime = 1; - } else if (strncasecmp(*argv, "-M=", 3) == 0) { + } + else if(strncasecmp(*argv, "-M=", 3) == 0) { long m = strtol((*argv)+3, NULL, 10); switch(m) { - case 1: url = URL_1M; - break; - case 2: url = URL_2M; - break; - case 5: url = URL_5M; - break; - case 10: url = URL_10M; - break; - case 20: url = URL_20M; - break; - case 50: url = URL_50M; - break; - case 100: url = URL_100M; - break; - default: fprintf(stderr, "\r%s: invalid parameter %s\n", - appname, *argv + 3); - exit(1); + case 1: + url = URL_1M; + break; + case 2: + url = URL_2M; + break; + case 5: + url = URL_5M; + break; + case 10: + url = URL_10M; + break; + case 20: + url = URL_20M; + break; + case 50: + url = URL_50M; + break; + case 100: + url = URL_100M; + break; + default: + fprintf(stderr, "\r%s: invalid parameter %s\n", + appname, *argv + 3); + exit(1); } - } else { + } + else { fprintf(stderr, "\r%s: invalid or unknown option %s\n", appname, *argv); exit(1); } - } else { + } + else { url = *argv; } } } /* print separator line */ - if (prtsep) { + if(prtsep) { printf("-------------------------------------------------\n"); } /* print localtime */ - if (prttime) { + if(prttime) { time_t t = time(NULL); printf("Localtime: %s", ctime(&t)); } @@ -163,7 +182,7 @@ int main(int argc, char *argv[]) if((CURLE_OK == res) && (val>0)) printf("Average download speed: %0.3f kbyte/sec.\n", val / 1024); - if (prtall) { + if(prtall) { /* check for name resolution time */ res = curl_easy_getinfo(curl_handle, CURLINFO_NAMELOOKUP_TIME, &val); if((CURLE_OK == res) && (val>0)) @@ -174,8 +193,8 @@ int main(int argc, char *argv[]) if((CURLE_OK == res) && (val>0)) printf("Connect time: %0.3f sec.\n", val); } - - } else { + } + else { fprintf(stderr, "Error while fetching '%s' : %s\n", url, curl_easy_strerror(res)); } diff --git a/docs/examples/cookie_interface.c b/docs/examples/cookie_interface.c index 28ee7817..064c7b32 100644 --- a/docs/examples/cookie_interface.c +++ b/docs/examples/cookie_interface.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,7 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ -/* This example shows usage of simple cookie interface. */ +/* <DESC> + * Import and export cookies with COOKIELIST. + * </DESC> + */ #include <stdio.h> #include <string.h> @@ -39,17 +42,18 @@ print_cookies(CURL *curl) printf("Cookies, curl knows:\n"); res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies); - if (res != CURLE_OK) { - fprintf(stderr, "Curl curl_easy_getinfo failed: %s\n", curl_easy_strerror(res)); + if(res != CURLE_OK) { + fprintf(stderr, "Curl curl_easy_getinfo failed: %s\n", + curl_easy_strerror(res)); exit(1); } nc = cookies, i = 1; - while (nc) { + while(nc) { printf("[%d]: %s\n", i, nc->data); nc = nc->next; i++; } - if (i == 1) { + if(i == 1) { printf("(none)\n"); } curl_slist_free_all(cookies); @@ -63,14 +67,14 @@ main(void) curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); - if (curl) { + if(curl) { char nline[256]; curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.com/"); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); - curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); /* just to start the cookie engine */ + curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); /* start cookie engine */ res = curl_easy_perform(curl); - if (res != CURLE_OK) { + if(res != CURLE_OK) { fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res)); return 1; } @@ -89,10 +93,13 @@ main(void) #endif /* Netscape format cookie */ snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%lu\t%s\t%s", - ".google.com", "TRUE", "/", "FALSE", (unsigned long)time(NULL) + 31337UL, "PREF", "hello google, i like you very much!"); + ".google.com", "TRUE", "/", "FALSE", + (unsigned long)time(NULL) + 31337UL, + "PREF", "hello google, i like you very much!"); res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline); - if (res != CURLE_OK) { - fprintf(stderr, "Curl curl_easy_setopt failed: %s\n", curl_easy_strerror(res)); + if(res != CURLE_OK) { + fprintf(stderr, "Curl curl_easy_setopt failed: %s\n", + curl_easy_strerror(res)); return 1; } @@ -106,18 +113,21 @@ main(void) "Set-Cookie: OLD_PREF=3d141414bf4209321; " "expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.com"); res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline); - if (res != CURLE_OK) { - fprintf(stderr, "Curl curl_easy_setopt failed: %s\n", curl_easy_strerror(res)); + if(res != CURLE_OK) { + fprintf(stderr, "Curl curl_easy_setopt failed: %s\n", + curl_easy_strerror(res)); return 1; } print_cookies(curl); res = curl_easy_perform(curl); - if (res != CURLE_OK) { + if(res != CURLE_OK) { fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res)); return 1; } + + curl_easy_cleanup(curl); } else { fprintf(stderr, "Curl init failed!\n"); diff --git a/docs/examples/curlgtk.c b/docs/examples/curlgtk.c index 8cb9914c..c3129c19 100644 --- a/docs/examples/curlgtk.c +++ b/docs/examples/curlgtk.c @@ -5,9 +5,12 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (c) 2000 David Odin (aka DindinX) for MandrakeSoft + */ +/* <DESC> + * use the libcurl in a gtk-threaded application + * </DESC> */ -/* Copyright (c) 2000 David Odin (aka DindinX) for MandrakeSoft */ -/* an attempt to use the curl library in concert with a gtk-threaded application */ #include <stdio.h> #include <gtk/gtk.h> @@ -47,9 +50,9 @@ void *my_thread(void *ptr) gchar *url = ptr; curl = curl_easy_init(); - if(curl) - { - outfile = fopen("test.curl", "w"); + if(curl) { + const char *filename = "test.curl"; + outfile = fopen(filename, "wb"); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); @@ -94,7 +97,7 @@ int main(int argc, char **argv) gtk_container_add(GTK_CONTAINER(Frame2), Bar); gtk_widget_show_all(Window); - if (!g_thread_create(&my_thread, argv[1], FALSE, NULL) != 0) + if(!g_thread_create(&my_thread, argv[1], FALSE, NULL) != 0) g_warning("can't create the thread"); diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index c68cf0dd..155da237 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -9,7 +9,10 @@ certificate presented during ssl session establishment. */ - +/* <DESC> + * demonstrates use of SSL context callback, requires OpenSSL + * </DESC> + */ /* * Copyright (c) 2003 The OpenEvidence Project. All rights reserved. @@ -33,7 +36,7 @@ * "This product includes software developed by the Openevidence Project * for use in the OpenEvidence Toolkit. (http://www.openevidence.org/)" * This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * for use in the OpenSSL Toolkit (https://www.openssl.org/)" * This product includes cryptographic software written by Eric Young * (eay@cryptsoft.com). This product includes software written by Tim * Hudson (tjh@cryptsoft.com)." @@ -52,7 +55,7 @@ * "This product includes software developed by the OpenEvidence Project * for use in the OpenEvidence Toolkit (http://www.openevidence.org/) * This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * for use in the OpenSSL Toolkit (https://www.openssl.org/)" * This product includes cryptographic software written by Eric Young * (eay@cryptsoft.com). This product includes software written by Tim * Hudson (tjh@cryptsoft.com)." @@ -72,7 +75,7 @@ * ==================================================================== * * This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.openssl.org/) + * for use in the OpenSSL Toolkit (https://www.openssl.org/) * This product includes cryptographic software written by Eric Young * (eay@cryptsoft.com). This product includes software written by Tim * Hudson (tjh@cryptsoft.com). @@ -98,13 +101,18 @@ static const char *curlx_usage[]={ "usage: curlx args\n", " -p12 arg - tia file ", - " -envpass arg - environement variable which content the tia private key password", + " -envpass arg - environement variable which content the tia private" + " key password", " -out arg - output file (response)- default stdout", " -in arg - input file (request)- default stdin", - " -connect arg - URL of the server for the connection ex: www.openevidence.org", - " -mimetype arg - MIME type for data in ex : application/timestamp-query or application/dvcs -default application/timestamp-query", - " -acceptmime arg - MIME type acceptable for the response ex : application/timestamp-response or application/dvcs -default none", - " -accesstype arg - an Object identifier in an AIA/SIA method, e.g. AD_DVCS or ad_timestamping", + " -connect arg - URL of the server for the connection ex:" + " www.openevidence.org", + " -mimetype arg - MIME type for data in ex : application/timestamp-query" + " or application/dvcs -default application/timestamp-query", + " -acceptmime arg - MIME type acceptable for the response ex : " + "application/timestamp-response or application/dvcs -default none", + " -accesstype arg - an Object identifier in an AIA/SIA method, e.g." + " AD_DVCS or ad_timestamping", NULL }; @@ -125,22 +133,22 @@ static const char *curlx_usage[]={ /* This is a context that we pass to all callbacks */ typedef struct sslctxparm_st { - unsigned char * p12file ; - const char * pst ; - PKCS12 * p12 ; - EVP_PKEY * pkey ; - X509 * usercert ; - STACK_OF(X509) * ca ; + unsigned char * p12file; + const char * pst; + PKCS12 * p12; + EVP_PKEY * pkey; + X509 * usercert; + STACK_OF(X509) * ca; CURL * curl; BIO * errorbio; - int accesstype ; + int accesstype; int verbose; } sslctxparm; /* some helper function. */ -static char *i2s_ASN1_IA5STRING( ASN1_IA5STRING *ia5) +static char *ia5string(ASN1_IA5STRING *ia5) { char *tmp; if(!ia5 || !ia5->length) @@ -152,20 +160,20 @@ static char *i2s_ASN1_IA5STRING( ASN1_IA5STRING *ia5) } /* A conveniance routine to get an access URI. */ - -static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype) { - +static unsigned char *my_get_ext(X509 *cert, const int type, + int extensiontype) +{ int i; - STACK_OF(ACCESS_DESCRIPTION) * accessinfo ; - accessinfo = X509_get_ext_d2i(cert, extensiontype, NULL, NULL) ; + STACK_OF(ACCESS_DESCRIPTION) * accessinfo; + accessinfo = X509_get_ext_d2i(cert, extensiontype, NULL, NULL); - if (!sk_ACCESS_DESCRIPTION_num(accessinfo)) + if(!sk_ACCESS_DESCRIPTION_num(accessinfo)) return NULL; - for (i = 0; i < sk_ACCESS_DESCRIPTION_num(accessinfo); i++) { + for(i = 0; i < sk_ACCESS_DESCRIPTION_num(accessinfo); i++) { ACCESS_DESCRIPTION * ad = sk_ACCESS_DESCRIPTION_value(accessinfo, i); - if (OBJ_obj2nid(ad->method) == type) { - if (ad->location->type == GEN_URI) { - return i2s_ASN1_IA5STRING(ad->location->d.ia5); + if(OBJ_obj2nid(ad->method) == type) { + if(ad->location->type == GEN_URI) { + return ia5string(ad->location->d.ia5); } return NULL; } @@ -184,84 +192,86 @@ static int ssl_app_verify_callback(X509_STORE_CTX *ctx, void *arg) sslctxparm * p = (sslctxparm *) arg; int ok; - if (p->verbose > 2) - BIO_printf(p->errorbio,"entering ssl_app_verify_callback\n"); + if(p->verbose > 2) + BIO_printf(p->errorbio, "entering ssl_app_verify_callback\n"); - if ((ok= X509_verify_cert(ctx)) && ctx->cert) { - unsigned char * accessinfo ; - if (p->verbose > 1) - X509_print_ex(p->errorbio,ctx->cert,0,0); + if((ok= X509_verify_cert(ctx)) && ctx->cert) { + unsigned char * accessinfo; + if(p->verbose > 1) + X509_print_ex(p->errorbio, ctx->cert, 0, 0); - if (accessinfo = my_get_ext(ctx->cert,p->accesstype ,NID_sinfo_access)) { - if (p->verbose) - BIO_printf(p->errorbio,"Setting URL from SIA to: %s\n", accessinfo); + if(accessinfo = my_get_ext(ctx->cert, p->accesstype, NID_sinfo_access)) { + if(p->verbose) + BIO_printf(p->errorbio, "Setting URL from SIA to: %s\n", accessinfo); - curl_easy_setopt(p->curl, CURLOPT_URL,accessinfo); + curl_easy_setopt(p->curl, CURLOPT_URL, accessinfo); } - else if (accessinfo = my_get_ext(ctx->cert,p->accesstype, - NID_info_access)) { - if (p->verbose) - BIO_printf(p->errorbio,"Setting URL from AIA to: %s\n", accessinfo); + else if(accessinfo = my_get_ext(ctx->cert, p->accesstype, + NID_info_access)) { + if(p->verbose) + BIO_printf(p->errorbio, "Setting URL from AIA to: %s\n", accessinfo); - curl_easy_setopt(p->curl, CURLOPT_URL,accessinfo); + curl_easy_setopt(p->curl, CURLOPT_URL, accessinfo); } } - if (p->verbose > 2) - BIO_printf(p->errorbio,"leaving ssl_app_verify_callback with %d\n", ok); - return(ok); + if(p->verbose > 2) + BIO_printf(p->errorbio, "leaving ssl_app_verify_callback with %d\n", ok); + + return ok; } -/* This is an example of an curl SSL initialisation call back. The callback sets: +/* The SSL initialisation callback. The callback sets: - a private key and certificate - a trusted ca certificate - a preferred cipherlist - an application verification callback (the function above) */ -static CURLcode sslctxfun(CURL * curl, void * sslctx, void * parm) { - +static CURLcode sslctxfun(CURL * curl, void * sslctx, void * parm) +{ sslctxparm * p = (sslctxparm *) parm; - SSL_CTX * ctx = (SSL_CTX *) sslctx ; + SSL_CTX * ctx = (SSL_CTX *) sslctx; - if (!SSL_CTX_use_certificate(ctx,p->usercert)) { - BIO_printf(p->errorbio, "SSL_CTX_use_certificate problem\n"); goto err; + if(!SSL_CTX_use_certificate(ctx, p->usercert)) { + BIO_printf(p->errorbio, "SSL_CTX_use_certificate problem\n"); + goto err; } - if (!SSL_CTX_use_PrivateKey(ctx,p->pkey)) { - BIO_printf(p->errorbio, "SSL_CTX_use_PrivateKey\n"); goto err; + if(!SSL_CTX_use_PrivateKey(ctx, p->pkey)) { + BIO_printf(p->errorbio, "SSL_CTX_use_PrivateKey\n"); + goto err; } - if (!SSL_CTX_check_private_key(ctx)) { - BIO_printf(p->errorbio, "SSL_CTX_check_private_key\n"); goto err; + if(!SSL_CTX_check_private_key(ctx)) { + BIO_printf(p->errorbio, "SSL_CTX_check_private_key\n"); + goto err; } - SSL_CTX_set_quiet_shutdown(ctx,1); - SSL_CTX_set_cipher_list(ctx,"RC4-MD5"); + SSL_CTX_set_quiet_shutdown(ctx, 1); + SSL_CTX_set_cipher_list(ctx, "RC4-MD5"); SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY); - X509_STORE_add_cert(SSL_CTX_get_cert_store(ctx), sk_X509_value(p->ca, sk_X509_num(p->ca)-1)); - - SSL_CTX_set_verify_depth(ctx,2); - - SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,ZERO_NULL); + X509_STORE_add_cert(SSL_CTX_get_cert_store(ctx), + sk_X509_value(p->ca, sk_X509_num(p->ca)-1)); + SSL_CTX_set_verify_depth(ctx, 2); + SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, ZERO_NULL); SSL_CTX_set_cert_verify_callback(ctx, ssl_app_verify_callback, parm); - - return CURLE_OK ; + return CURLE_OK; err: ERR_print_errors(p->errorbio); return CURLE_SSL_CERTPROBLEM; } -int main(int argc, char **argv) { - +int main(int argc, char **argv) +{ BIO* in=NULL; BIO* out=NULL; char * outfile = NULL; - char * infile = NULL ; + char * infile = NULL; int tabLength=100; char *binaryptr; @@ -270,7 +280,7 @@ int main(int argc, char **argv) { char* contenttype; const char** pp; unsigned char* hostporturl = NULL; - BIO * p12bio ; + BIO * p12bio; char **args = argv + 1; unsigned char * serverurl; sslctxparm p; @@ -293,66 +303,91 @@ int main(int argc, char **argv) { OpenSSL_add_all_digests(); ERR_load_crypto_strings(); - - - while (*args && *args[0] == '-') { - if (!strcmp (*args, "-in")) { - if (args[1]) { + while(*args && *args[0] == '-') { + if(!strcmp (*args, "-in")) { + if(args[1]) { infile=*(++args); - } else badarg=1; - } else if (!strcmp (*args, "-out")) { - if (args[1]) { + } + else + badarg=1; + } + else if(!strcmp (*args, "-out")) { + if(args[1]) { outfile=*(++args); - } else badarg=1; - } else if (!strcmp (*args, "-p12")) { - if (args[1]) { + } + else + badarg=1; + } + else if(!strcmp (*args, "-p12")) { + if(args[1]) { p.p12file = *(++args); - } else badarg=1; - } else if (strcmp(*args,"-envpass") == 0) { - if (args[1]) { + } + else + badarg=1; + } + else if(strcmp(*args, "-envpass") == 0) { + if(args[1]) { p.pst = getenv(*(++args)); - } else badarg=1; - } else if (strcmp(*args,"-connect") == 0) { - if (args[1]) { + } + else + badarg=1; + } + else if(strcmp(*args, "-connect") == 0) { + if(args[1]) { hostporturl = *(++args); - } else badarg=1; - } else if (strcmp(*args,"-mimetype") == 0) { - if (args[1]) { + } + else + badarg=1; + } + else if(strcmp(*args, "-mimetype") == 0) { + if(args[1]) { mimetype = *(++args); - } else badarg=1; - } else if (strcmp(*args,"-acceptmime") == 0) { - if (args[1]) { + } + else + badarg=1; + } + else if(strcmp(*args, "-acceptmime") == 0) { + if(args[1]) { mimetypeaccept = *(++args); - } else badarg=1; - } else if (strcmp(*args,"-accesstype") == 0) { - if (args[1]) { - if ((p.accesstype = OBJ_obj2nid(OBJ_txt2obj(*++args,0))) == 0) badarg=1; - } else badarg=1; - } else if (strcmp(*args,"-verbose") == 0) { + } + else + badarg=1; + } + else if(strcmp(*args, "-accesstype") == 0) { + if(args[1]) { + if((p.accesstype = OBJ_obj2nid(OBJ_txt2obj(*++args, 0))) == 0) + badarg=1; + } + else + badarg=1; + } + else if(strcmp(*args, "-verbose") == 0) { p.verbose++; - } else badarg=1; + } + else + badarg=1; args++; } - if (mimetype==NULL || mimetypeaccept == NULL) badarg = 1; + if(mimetype==NULL || mimetypeaccept == NULL) + badarg = 1; - if (badarg) { - for (pp=curlx_usage; (*pp != NULL); pp++) - BIO_printf(p.errorbio,"%s\n",*pp); - BIO_printf(p.errorbio,"\n"); + if(badarg) { + for(pp=curlx_usage; (*pp != NULL); pp++) + BIO_printf(p.errorbio, "%s\n", *pp); + BIO_printf(p.errorbio, "\n"); goto err; } - - /* set input */ - if ((in=BIO_new(BIO_s_file())) == NULL) { + if((in=BIO_new(BIO_s_file())) == NULL) { BIO_printf(p.errorbio, "Error setting input bio\n"); goto err; - } else if (infile == NULL) - BIO_set_fp(in,stdin,BIO_NOCLOSE|BIO_FP_TEXT); - else if (BIO_read_filename(in,infile) <= 0) { + } + else if(infile == NULL) + BIO_set_fp(in, stdin, BIO_NOCLOSE|BIO_FP_TEXT); + else if(BIO_read_filename(in, infile) <= 0) { BIO_printf(p.errorbio, "Error opening input file %s\n", infile); BIO_free(in); goto err; @@ -360,12 +395,13 @@ int main(int argc, char **argv) { /* set output */ - if ((out=BIO_new(BIO_s_file())) == NULL) { + if((out=BIO_new(BIO_s_file())) == NULL) { BIO_printf(p.errorbio, "Error setting output bio.\n"); goto err; - } else if (outfile == NULL) - BIO_set_fp(out,stdout,BIO_NOCLOSE|BIO_FP_TEXT); - else if (BIO_write_filename(out,outfile) <= 0) { + } + else if(outfile == NULL) + BIO_set_fp(out, stdout, BIO_NOCLOSE|BIO_FP_TEXT); + else if(BIO_write_filename(out, outfile) <= 0) { BIO_printf(p.errorbio, "Error opening output file %s\n", outfile); BIO_free(out); goto err; @@ -374,62 +410,66 @@ int main(int argc, char **argv) { p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); - if (!(p.curl = curl_easy_init())) { + if(!(p.curl = curl_easy_init())) { BIO_printf(p.errorbio, "Cannot init curl lib\n"); goto err; } - - - if (!(p12bio = BIO_new_file(p.p12file , "rb"))) { - BIO_printf(p.errorbio, "Error opening P12 file %s\n", p.p12file); goto err; + if(!(p12bio = BIO_new_file(p.p12file, "rb"))) { + BIO_printf(p.errorbio, "Error opening P12 file %s\n", p.p12file); + goto err; } - if (!(p.p12 = d2i_PKCS12_bio (p12bio, NULL))) { - BIO_printf(p.errorbio, "Cannot decode P12 structure %s\n", p.p12file); goto err; + if(!(p.p12 = d2i_PKCS12_bio (p12bio, NULL))) { + BIO_printf(p.errorbio, "Cannot decode P12 structure %s\n", p.p12file); + goto err; } p.ca= NULL; - if (!(PKCS12_parse (p.p12, p.pst, &(p.pkey), &(p.usercert), &(p.ca) ) )) { - BIO_printf(p.errorbio,"Invalid P12 structure in %s\n", p.p12file); goto err; + if(!(PKCS12_parse (p.p12, p.pst, &(p.pkey), &(p.usercert), &(p.ca) ) )) { + BIO_printf(p.errorbio, "Invalid P12 structure in %s\n", p.p12file); + goto err; } - if (sk_X509_num(p.ca) <= 0) { - BIO_printf(p.errorbio,"No trustworthy CA given.%s\n", p.p12file); goto err; + if(sk_X509_num(p.ca) <= 0) { + BIO_printf(p.errorbio, "No trustworthy CA given.%s\n", p.p12file); + goto err; } - if (p.verbose > 1) - X509_print_ex(p.errorbio,p.usercert,0,0); + if(p.verbose > 1) + X509_print_ex(p.errorbio, p.usercert, 0, 0); /* determine URL to go */ - if (hostporturl) { - serverurl = malloc(9+strlen(hostporturl)); - sprintf(serverurl,"https://%s",hostporturl); + if(hostporturl) { + size_t len = strlen(hostporturl) + 9; + serverurl = malloc(len); + snprintf(serverurl, len, "https://%s", hostporturl); } - else if (p.accesstype != 0) { /* see whether we can find an AIA or SIA for a given access type */ - if (!(serverurl = my_get_ext(p.usercert,p.accesstype,NID_info_access))) { + else if(p.accesstype != 0) { /* see whether we can find an AIA or SIA for a + given access type */ + if(!(serverurl = my_get_ext(p.usercert, p.accesstype, NID_info_access))) { int j=0; - BIO_printf(p.errorbio,"no service URL in user cert " + BIO_printf(p.errorbio, "no service URL in user cert " "cherching in others certificats\n"); - for (j=0;j<sk_X509_num(p.ca);j++) { - if ((serverurl = my_get_ext(sk_X509_value(p.ca,j),p.accesstype, + for(j=0; j<sk_X509_num(p.ca); j++) { + if((serverurl = my_get_ext(sk_X509_value(p.ca, j), p.accesstype, NID_info_access))) break; - if ((serverurl = my_get_ext(sk_X509_value(p.ca,j),p.accesstype, + if((serverurl = my_get_ext(sk_X509_value(p.ca, j), p.accesstype, NID_sinfo_access))) break; } } } - if (!serverurl) { + if(!serverurl) { BIO_printf(p.errorbio, "no service URL in certificats," " check '-accesstype (AD_DVCS | ad_timestamping)'" " or use '-connect'\n"); goto err; } - if (p.verbose) + if(p.verbose) BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); curl_easy_setopt(p.curl, CURLOPT_URL, serverurl); @@ -437,38 +477,39 @@ int main(int argc, char **argv) { /* Now specify the POST binary data */ curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,(long)tabLength); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE, (long)tabLength); /* pass our list of custom made headers */ contenttype = malloc(15+strlen(mimetype)); - sprintf(contenttype,"Content-type: %s",mimetype); - headers = curl_slist_append(headers,contenttype); + snprintf(contenttype, 15+strlen(mimetype), "Content-type: %s", mimetype); + headers = curl_slist_append(headers, contenttype); curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers); - if (p.verbose) + if(p.verbose) BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); { FILE *outfp; - BIO_get_fp(out,&outfp); + BIO_get_fp(out, &outfp); curl_easy_setopt(p.curl, CURLOPT_WRITEDATA, outfp); } - res = curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun) ; + res = curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun); - if (res != CURLE_OK) - BIO_printf(p.errorbio,"%d %s=%d %d\n", __LINE__, "CURLOPT_SSL_CTX_FUNCTION",CURLOPT_SSL_CTX_FUNCTION,res); + if(res != CURLE_OK) + BIO_printf(p.errorbio, "%d %s=%d %d\n", __LINE__, + "CURLOPT_SSL_CTX_FUNCTION", CURLOPT_SSL_CTX_FUNCTION, res); curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_DATA, &p); { int lu; int i=0; - while ((lu = BIO_read (in,&binaryptr[i],tabLength-i)) >0 ) { + while((lu = BIO_read (in, &binaryptr[i], tabLength-i)) >0) { i+=lu; - if (i== tabLength) { + if(i== tabLength) { tabLength+=100; - binaryptr=realloc(binaryptr,tabLength); /* should be more careful */ + binaryptr=realloc(binaryptr, tabLength); /* should be more careful */ } } tabLength = i; @@ -476,23 +517,23 @@ int main(int argc, char **argv) { /* Now specify the POST binary data */ curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,(long)tabLength); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE, (long)tabLength); /* Perform the request, res will get the return code */ - BIO_printf(p.errorbio,"%d %s %d\n", __LINE__, "curl_easy_perform", + BIO_printf(p.errorbio, "%d %s %d\n", __LINE__, "curl_easy_perform", res = curl_easy_perform(p.curl)); { - int result =curl_easy_getinfo(p.curl,CURLINFO_CONTENT_TYPE,&response); - if( mimetypeaccept && p.verbose) - if(!strcmp(mimetypeaccept,response)) - BIO_printf(p.errorbio,"the response has a correct mimetype : %s\n", + int result =curl_easy_getinfo(p.curl, CURLINFO_CONTENT_TYPE, &response); + if(mimetypeaccept && p.verbose) + if(!strcmp(mimetypeaccept, response)) + BIO_printf(p.errorbio, "the response has a correct mimetype : %s\n", response); else - BIO_printf(p.errorbio,"the response doesn\'t have an acceptable " + BIO_printf(p.errorbio, "the response doesn\'t have an acceptable " "mime type, it is %s instead of %s\n", - response,mimetypeaccept); + response, mimetypeaccept); } /*** code d'erreur si accept mime ***, egalement code return HTTP != 200 ***/ @@ -508,6 +549,6 @@ int main(int argc, char **argv) { BIO_free(out); return (EXIT_SUCCESS); - err: BIO_printf(p.errorbio,"error"); + err: BIO_printf(p.errorbio, "error"); exit(1); } diff --git a/docs/examples/debug.c b/docs/examples/debug.c index 36dd80d7..f5d58bf1 100644 --- a/docs/examples/debug.c +++ b/docs/examples/debug.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Show how CURLOPT_DEBUGFUNCTION can be used. + * </DESC> + */ #include <stdio.h> #include <curl/curl.h> @@ -58,14 +62,14 @@ void dump(const char *text, for(c = 0; (c < width) && (i+c < size); c++) { /* check for 0D0A; if found, skip past and start a new line of output */ - if (nohex && (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) { + if(nohex && (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) { i+=(c+2-width); break; } fprintf(stream, "%c", (ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:'.'); /* check again for 0D0A, to avoid an extra \n if it's at width */ - if (nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) { + if(nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) { i+=(c+3-width); break; } diff --git a/docs/examples/evhiperfifo.c b/docs/examples/evhiperfifo.c index e03801d8..118f152e 100644 --- a/docs/examples/evhiperfifo.c +++ b/docs/examples/evhiperfifo.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * multi socket interface together with libev + * </DESC> + */ /* Example application source code using the multi socket interface to * download many files at once. * @@ -115,12 +119,12 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, GlobalInfo *g) { DPRINT("%s %li\n", __PRETTY_FUNCTION__, timeout_ms); ev_timer_stop(g->loop, &g->timer_event); - if (timeout_ms > 0) - { + if(timeout_ms > 0) { double t = timeout_ms / 1000; ev_timer_init(&g->timer_event, timer_cb, t, 0.); ev_timer_start(g->loop, &g->timer_event); - }else + } + else timer_cb(g->loop, &g->timer_event, 0); return 0; } @@ -128,20 +132,32 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, GlobalInfo *g) /* Die if we get a bad CURLMcode somewhere */ static void mcode_or_die(const char *where, CURLMcode code) { - if ( CURLM_OK != code ) - { + if(CURLM_OK != code) { const char *s; - switch ( code ) - { - case CURLM_BAD_HANDLE: s="CURLM_BAD_HANDLE"; break; - case CURLM_BAD_EASY_HANDLE: s="CURLM_BAD_EASY_HANDLE"; break; - case CURLM_OUT_OF_MEMORY: s="CURLM_OUT_OF_MEMORY"; break; - case CURLM_INTERNAL_ERROR: s="CURLM_INTERNAL_ERROR"; break; - case CURLM_UNKNOWN_OPTION: s="CURLM_UNKNOWN_OPTION"; break; - case CURLM_LAST: s="CURLM_LAST"; break; - default: s="CURLM_unknown"; + switch (code) { + case CURLM_BAD_HANDLE: + s="CURLM_BAD_HANDLE"; + break; + case CURLM_BAD_EASY_HANDLE: + s="CURLM_BAD_EASY_HANDLE"; + break; + case CURLM_OUT_OF_MEMORY: + s="CURLM_OUT_OF_MEMORY"; + break; + case CURLM_INTERNAL_ERROR: + s="CURLM_INTERNAL_ERROR"; + break; + case CURLM_UNKNOWN_OPTION: + s="CURLM_UNKNOWN_OPTION"; + break; + case CURLM_LAST: + s="CURLM_LAST"; break; - case CURLM_BAD_SOCKET: s="CURLM_BAD_SOCKET"; + default: + s="CURLM_unknown"; + break; + case CURLM_BAD_SOCKET: + s="CURLM_BAD_SOCKET"; fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s); /* ignore this error */ return; @@ -164,8 +180,8 @@ static void check_multi_info(GlobalInfo *g) CURLcode res; fprintf(MSG_OUT, "REMAINING: %d\n", g->still_running); - while ((msg = curl_multi_info_read(g->multi, &msgs_left))) { - if (msg->msg == CURLMSG_DONE) { + while((msg = curl_multi_info_read(g->multi, &msgs_left))) { + if(msg->msg == CURLMSG_DONE) { easy = msg->easy_handle; res = msg->data.result; curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn); @@ -193,8 +209,7 @@ static void event_cb(EV_P_ struct ev_io *w, int revents) rc = curl_multi_socket_action(g->multi, w->fd, action, &g->still_running); mcode_or_die("event_cb: curl_multi_socket_action", rc); check_multi_info(g); - if ( g->still_running <= 0 ) - { + if(g->still_running <= 0) { fprintf(MSG_OUT, "last transfer done, kill timeout\n"); ev_timer_stop(g->loop, &g->timer_event); } @@ -208,7 +223,8 @@ static void timer_cb(EV_P_ struct ev_timer *w, int revents) GlobalInfo *g = (GlobalInfo *)w->data; CURLMcode rc; - rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0, &g->still_running); + rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0, + &g->still_running); mcode_or_die("timer_cb: curl_multi_socket_action", rc); check_multi_info(g); } @@ -217,9 +233,8 @@ static void timer_cb(EV_P_ struct ev_timer *w, int revents) static void remsock(SockInfo *f, GlobalInfo *g) { printf("%s \n", __PRETTY_FUNCTION__); - if ( f ) - { - if ( f->evset ) + if(f) { + if(f->evset) ev_io_stop(g->loop, &f->ev); free(f); } @@ -237,7 +252,7 @@ static void setsock(SockInfo*f, curl_socket_t s, CURL*e, int act, GlobalInfo*g) f->sockfd = s; f->action = act; f->easy = e; - if ( f->evset ) + if(f->evset) ev_io_stop(g->loop, &f->ev); ev_io_init(&f->ev, event_cb, f->sockfd, kind); f->ev.data = g; @@ -269,18 +284,16 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) fprintf(MSG_OUT, "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); - if ( what == CURL_POLL_REMOVE ) - { + if(what == CURL_POLL_REMOVE) { fprintf(MSG_OUT, "\n"); remsock(fdp, g); - } else - { - if ( !fdp ) - { + } + else { + if(!fdp) { fprintf(MSG_OUT, "Adding data: %s\n", whatstr[what]); addsock(s, e, what, g); - } else - { + } + else { fprintf(MSG_OUT, "Changing action from %s to %s\n", whatstr[fdp->action], whatstr[what]); @@ -316,7 +329,7 @@ static int prog_cb (void *p, double dltotal, double dlnow, double ult, /* Create a new easy handle, and add it to the global curl_multi */ -static void new_conn(char *url, GlobalInfo *g ) +static void new_conn(char *url, GlobalInfo *g) { ConnInfo *conn; CURLMcode rc; @@ -326,8 +339,7 @@ static void new_conn(char *url, GlobalInfo *g ) conn->error[0]='\0'; conn->easy = curl_easy_init(); - if ( !conn->easy ) - { + if(!conn->easy) { fprintf(MSG_OUT, "curl_easy_init() failed, exiting!\n"); exit(2); } @@ -362,16 +374,16 @@ static void fifo_cb(EV_P_ struct ev_io *w, int revents) int n=0; GlobalInfo *g = (GlobalInfo *)w->data; - do - { + do { s[0]='\0'; rv=fscanf(g->input, "%1023s%n", s, &n); s[n]='\0'; - if ( n && s[0] ) - { - new_conn(s,g); /* if we read a URL, go get it! */ - } else break; - } while ( rv != EOF ); + if(n && s[0]) { + new_conn(s, g); /* if we read a URL, go get it! */ + } + else + break; + } while(rv != EOF); } /* Create a named pipe and tell libevent to monitor it */ @@ -382,24 +394,20 @@ static int init_fifo (GlobalInfo *g) curl_socket_t sockfd; fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo); - if ( lstat (fifo, &st) == 0 ) - { - if ( (st.st_mode & S_IFMT) == S_IFREG ) - { + if(lstat (fifo, &st) == 0) { + if((st.st_mode & S_IFMT) == S_IFREG) { errno = EEXIST; perror("lstat"); exit (1); } } unlink(fifo); - if ( mkfifo (fifo, 0600) == -1 ) - { + if(mkfifo (fifo, 0600) == -1) { perror("mkfifo"); exit (1); } sockfd = open(fifo, O_RDWR | O_NONBLOCK, 0); - if ( sockfd == -1 ) - { + if(sockfd == -1) { perror("open"); exit (1); } @@ -408,7 +416,7 @@ static int init_fifo (GlobalInfo *g) fprintf(MSG_OUT, "Now, pipe some URL's into > %s\n", fifo); ev_io_init(&g->fifo_event, fifo_cb, sockfd, EV_READ); ev_io_start(g->loop, &g->fifo_event); - return(0); + return (0); } int main(int argc, char **argv) diff --git a/docs/examples/externalsocket.c b/docs/examples/externalsocket.c index 5486d125..9b144b42 100644 --- a/docs/examples/externalsocket.c +++ b/docs/examples/externalsocket.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,9 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ -/* - * This is an example demonstrating how an application can pass in a custom +/* <DESC> + * An example demonstrating how an application can pass in a custom * socket to libcurl to use. This example also handles the connect itself. + * </DESC> */ #include <stdio.h> #include <string.h> @@ -53,7 +54,7 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) { - int written = fwrite(ptr, size, nmemb, (FILE *)stream); + size_t written = fwrite(ptr, size, nmemb, (FILE *)stream); return written; } @@ -91,7 +92,7 @@ int main(void) WSADATA wsaData; int initwsa; - if((initwsa = WSAStartup(MAKEWORD(2,0), &wsaData)) != 0) { + if((initwsa = WSAStartup(MAKEWORD(2, 0), &wsaData)) != 0) { printf("WSAStartup failed: %d\n", initwsa); return 1; } @@ -106,7 +107,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999"); /* Create the socket "manually" */ - if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) == CURL_SOCKET_BAD ) { + if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == CURL_SOCKET_BAD) { printf("Error creating listening socket.\n"); return 3; } @@ -115,10 +116,10 @@ int main(void) servaddr.sin_family = AF_INET; servaddr.sin_port = htons(PORTNUM); - if (INADDR_NONE == (servaddr.sin_addr.s_addr = inet_addr(IPADDR))) + if(INADDR_NONE == (servaddr.sin_addr.s_addr = inet_addr(IPADDR))) return 2; - if(connect(sockfd,(struct sockaddr *) &servaddr, sizeof(servaddr)) == + if(connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) == -1) { close(sockfd); printf("client error: connect: %s\n", strerror(errno)); diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c index 665eca0a..363fae69 100644 --- a/docs/examples/fileupload.c +++ b/docs/examples/fileupload.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Upload to a file:// URL + * </DESC> + */ #include <stdio.h> #include <curl/curl.h> #include <sys/stat.h> diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index 0aad0abf..71be178e 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -42,6 +42,10 @@ * * This example requires libcurl 7.9.7 or later. */ +/* <DESC> + * implements an fopen() abstraction allowing reading from URLs + * </DESC> + */ #include <stdio.h> #include <string.h> @@ -76,7 +80,7 @@ struct fcurl_data typedef struct fcurl_data URL_FILE; /* exported functions */ -URL_FILE *url_fopen(const char *url,const char *operation); +URL_FILE *url_fopen(const char *url, const char *operation); int url_fclose(URL_FILE *file); int url_feof(URL_FILE *file); size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file); @@ -102,9 +106,9 @@ static size_t write_callback(char *buffer, if(size > rembuff) { /* not enough space in buffer */ - newbuff=realloc(url->buffer,url->buffer_len + (size - rembuff)); + newbuff=realloc(url->buffer, url->buffer_len + (size - rembuff)); if(newbuff==NULL) { - fprintf(stderr,"callback buffer grow failed\n"); + fprintf(stderr, "callback buffer grow failed\n"); size=rembuff; } else { @@ -161,8 +165,7 @@ static int fill_buffer(URL_FILE *file, size_t want) /* get file descriptors from the transfers */ mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); - if(mc != CURLM_OK) - { + if(mc != CURLM_OK) { fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); break; } @@ -226,7 +229,7 @@ static int use_buffer(URL_FILE *file, size_t want) return 0; } -URL_FILE *url_fopen(const char *url,const char *operation) +URL_FILE *url_fopen(const char *url, const char *operation) { /* this code could check for URLs or types in the 'url' and basically use the real fopen() for standard files */ @@ -240,7 +243,7 @@ URL_FILE *url_fopen(const char *url,const char *operation) memset(file, 0, sizeof(URL_FILE)); - if((file->handle.file=fopen(url,operation))) + if((file->handle.file=fopen(url, operation))) file->type = CFTYPE_FILE; /* marked as URL */ else { @@ -334,13 +337,13 @@ size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) switch(file->type) { case CFTYPE_FILE: - want=fread(ptr,size,nmemb,file->handle.file); + want=fread(ptr, size, nmemb, file->handle.file); break; case CFTYPE_CURL: want = nmemb * size; - fill_buffer(file,want); + fill_buffer(file, want); /* check if theres data in the buffer - if not fill_buffer() * either errored or EOF */ @@ -354,7 +357,7 @@ size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) /* xfer data to caller */ memcpy(ptr, file->buffer, want); - use_buffer(file,want); + use_buffer(file, want); want = want / size; /* number of items */ break; @@ -379,7 +382,7 @@ char *url_fgets(char *ptr, size_t size, URL_FILE *file) break; case CFTYPE_CURL: - fill_buffer(file,want); + fill_buffer(file, want); /* check if theres data in the buffer - if not fill either errored or * EOF */ @@ -403,7 +406,7 @@ char *url_fgets(char *ptr, size_t size, URL_FILE *file) memcpy(ptr, file->buffer, want); ptr[want]=0;/* allways null terminate */ - use_buffer(file,want); + use_buffer(file, want); break; @@ -443,6 +446,10 @@ void url_rewind(URL_FILE *file) } } +#define FGETSFILE "fgets.test" +#define FREADFILE "fread.test" +#define REWINDFILE "rewind.test" + /* Small main program to retrive from a url using fgets and fread saving the * output to two test files (note the fgets method will corrupt binary files if * they contain 0 chars */ @@ -461,7 +468,7 @@ int main(int argc, char *argv[]) url=argv[1];/* use passed url */ /* copy from url line by line with fgets */ - outf=fopen("fgets.test","w+"); + outf=fopen(FGETSFILE, "wb+"); if(!outf) { perror("couldn't open fgets output file\n"); return 1; @@ -475,8 +482,8 @@ int main(int argc, char *argv[]) } while(!url_feof(handle)) { - url_fgets(buffer,sizeof(buffer),handle); - fwrite(buffer,1,strlen(buffer),outf); + url_fgets(buffer, sizeof(buffer), handle); + fwrite(buffer, 1, strlen(buffer), outf); } url_fclose(handle); @@ -485,7 +492,7 @@ int main(int argc, char *argv[]) /* Copy from url with fread */ - outf=fopen("fread.test","w+"); + outf=fopen(FREADFILE, "wb+"); if(!outf) { perror("couldn't open fread output file\n"); return 1; @@ -500,7 +507,7 @@ int main(int argc, char *argv[]) do { nread = url_fread(buffer, 1, sizeof(buffer), handle); - fwrite(buffer,1,nread,outf); + fwrite(buffer, 1, nread, outf); } while(nread); url_fclose(handle); @@ -509,7 +516,7 @@ int main(int argc, char *argv[]) /* Test rewind */ - outf=fopen("rewind.test","w+"); + outf=fopen(REWINDFILE, "wb+"); if(!outf) { perror("couldn't open fread output file\n"); return 1; @@ -522,21 +529,19 @@ int main(int argc, char *argv[]) return 2; } - nread = url_fread(buffer, 1,sizeof(buffer), handle); - fwrite(buffer,1,nread,outf); + nread = url_fread(buffer, 1, sizeof(buffer), handle); + fwrite(buffer, 1, nread, outf); url_rewind(handle); buffer[0]='\n'; - fwrite(buffer,1,1,outf); - - nread = url_fread(buffer, 1,sizeof(buffer), handle); - fwrite(buffer,1,nread,outf); + fwrite(buffer, 1, 1, outf); + nread = url_fread(buffer, 1, sizeof(buffer), handle); + fwrite(buffer, 1, nread, outf); url_fclose(handle); fclose(outf); - return 0;/* all done */ } diff --git a/docs/examples/ftp-wildcard.c b/docs/examples/ftp-wildcard.c index d175ddfd..f249bc13 100644 --- a/docs/examples/ftp-wildcard.c +++ b/docs/examples/ftp-wildcard.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * FTP wildcard pattern matching + * </DESC> + */ #include <curl/curl.h> #include <stdio.h> @@ -115,7 +119,7 @@ static long file_is_coming(struct curl_fileinfo *finfo, return CURL_CHUNK_BGN_FUNC_SKIP; } - data->output = fopen(finfo->filename, "w"); + data->output = fopen(finfo->filename, "wb"); if(!data->output) { return CURL_CHUNK_BGN_FUNC_FAIL; } diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 285283f7..9b7dc024 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -23,11 +23,9 @@ #include <curl/curl.h> -/* - * This is an example showing how to get a single file from an FTP server. - * It delays the actual destination file creation until the first write - * callback so that it won't create an empty file in case the remote file - * doesn't exist or something else fails. +/* <DESC> + * Get a single file from an FTP server. + * </DESC> */ struct FtpFile { @@ -65,7 +63,7 @@ int main(void) * You better replace the URL with one that works! */ curl_easy_setopt(curl, CURLOPT_URL, - "ftp://ftp.example.com/pub/www/utilities/curl/curl-7.9.2.tar.gz"); + "ftp://ftp.example.com/curl/curl-7.9.2.tar.gz"); /* Define our callback to get called when there's data to be written */ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite); /* Set a pointer to our struct to pass to the callback */ diff --git a/docs/examples/ftpgetinfo.c b/docs/examples/ftpgetinfo.c index dfdcf78b..277e52b9 100644 --- a/docs/examples/ftpgetinfo.c +++ b/docs/examples/ftpgetinfo.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -24,9 +24,9 @@ #include <curl/curl.h> -/* - * This is an example showing how to check a single file's size and mtime - * from an FTP server. +/* <DESC> + * Checks a single file's size and mtime from an FTP server. + * </DESC> */ static size_t throw_away(void *ptr, size_t size, size_t nmemb, void *data) @@ -65,16 +65,18 @@ int main(void) res = curl_easy_perform(curl); if(CURLE_OK == res) { - /* http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html */ + /* https://curl.haxx.se/libcurl/c/curl_easy_getinfo.html */ res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime); if((CURLE_OK == res) && (filetime >= 0)) { time_t file_time = (time_t)filetime; printf("filetime %s: %s", filename, ctime(&file_time)); } - res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &filesize); + res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, + &filesize); if((CURLE_OK == res) && (filesize>0.0)) printf("filesize %s: %0.0f bytes\n", filename, filesize); - } else { + } + else { /* we failed */ fprintf(stderr, "curl told us %d\n", res); } diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index dcb296ad..7dc34407 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -23,13 +23,11 @@ #include <curl/curl.h> -/* - * Similar to ftpget.c but this also stores the received response-lines +/* <DESC> + * Similar to ftpget.c but also stores the received response-lines * in a separate file using our own callback! - * - * This functionality was introduced in libcurl 7.9.3. + * </DESC> */ - static size_t write_response(void *ptr, size_t size, size_t nmemb, void *data) { @@ -37,6 +35,9 @@ write_response(void *ptr, size_t size, size_t nmemb, void *data) return fwrite(ptr, size, nmemb, writehere); } +#define FTPBODY "ftp-list" +#define FTPHEADERS "ftp-responses" + int main(void) { CURL *curl; @@ -45,10 +46,10 @@ int main(void) FILE *respfile; /* local file name to store the file as */ - ftpfile = fopen("ftp-list", "wb"); /* b is binary, needed on win32 */ + ftpfile = fopen(FTPBODY, "wb"); /* b is binary, needed on win32 */ /* local file name to store the FTP server's response lines in */ - respfile = fopen("ftp-responses", "wb"); /* b is binary, needed on win32 */ + respfile = fopen(FTPHEADERS, "wb"); /* b is binary, needed on win32 */ curl = curl_easy_init(); if(curl) { diff --git a/docs/examples/ftpsget.c b/docs/examples/ftpsget.c index dae45348..d53f0884 100644 --- a/docs/examples/ftpsget.c +++ b/docs/examples/ftpsget.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -24,11 +24,9 @@ #include <curl/curl.h> -/* - * This is an example showing how to get a single file from an FTPS server. - * It delays the actual destination file creation until the first write - * callback so that it won't create an empty file in case the remote file - * doesn't exist or something else fails. +/* <DESC> + * Get a single file from an FTPS server. + * </DESC> */ struct FtpFile { diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index e79f8d84..bba0c4d5 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -33,11 +33,10 @@ #include <unistd.h> #endif -/* - * This example shows an FTP upload, with a rename of the file just after - * a successful upload. - * - * Example based on source code provided by Erick Nuwendam. Thanks! +/* <DESC> + * Performs an FTP upload and renames the file just after a successful + * transfer. + * </DESC> */ #define LOCAL_FILE "/tmp/uploadthis.txt" @@ -105,7 +104,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); /* specify target */ - curl_easy_setopt(curl,CURLOPT_URL, REMOTE_URL); + curl_easy_setopt(curl, CURLOPT_URL, REMOTE_URL); /* pass in that last of FTP commands to run after the transfer */ curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist); diff --git a/docs/examples/ftpuploadresume.c b/docs/examples/ftpuploadresume.c index 55b8986c..64156340 100644 --- a/docs/examples/ftpuploadresume.c +++ b/docs/examples/ftpuploadresume.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,13 +19,9 @@ * KIND, either express or implied. * ***************************************************************************/ -/* Upload to FTP, resuming failed transfers - * - * Compile for MinGW like this: - * gcc -Wall -pedantic -std=c99 ftpuploadwithresume.c -o ftpuploadresume.exe - * -lcurl -lmsvcr70 - * - * Written by Philip Bock +/* <DESC> + * Upload to FTP, resuming failed transfers. + * </DESC> */ #include <stdlib.h> @@ -40,7 +36,8 @@ /* The MinGW headers are missing a few Win32 function definitions, you shouldn't need this if you use VC++ */ #if defined(__MINGW32__) && !defined(__MINGW64__) -int __cdecl _snscanf(const char * input, size_t length, const char * format, ...); +int __cdecl _snscanf(const char * input, size_t length, + const char * format, ...); #endif @@ -53,7 +50,7 @@ size_t getcontentlengthfunc(void *ptr, size_t size, size_t nmemb, void *stream) /* _snscanf() is Win32 specific */ r = _snscanf(ptr, size * nmemb, "Content-Length: %ld\n", &len); - if (r) /* Microsoft: we don't read the specs */ + if(r) /* Microsoft: we don't read the specs */ *((long *) stream) = len; return size * nmemb; @@ -71,7 +68,7 @@ size_t readfunc(void *ptr, size_t size, size_t nmemb, void *stream) FILE *f = stream; size_t n; - if (ferror(f)) + if(ferror(f)) return CURL_READFUNC_ABORT; n = fread(ptr, size, nmemb, f) * size; @@ -89,7 +86,7 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath, int c; f = fopen(localpath, "rb"); - if (f == NULL) { + if(!f) { perror(NULL); return 0; } @@ -98,7 +95,7 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath, curl_easy_setopt(curlhandle, CURLOPT_URL, remotepath); - if (timeout) + if(timeout) curl_easy_setopt(curlhandle, CURLOPT_FTP_RESPONSE_TIMEOUT, timeout); curl_easy_setopt(curlhandle, CURLOPT_HEADERFUNCTION, getcontentlengthfunc); @@ -109,14 +106,15 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath, curl_easy_setopt(curlhandle, CURLOPT_READFUNCTION, readfunc); curl_easy_setopt(curlhandle, CURLOPT_READDATA, f); - curl_easy_setopt(curlhandle, CURLOPT_FTPPORT, "-"); /* disable passive mode */ + /* disable passive mode */ + curl_easy_setopt(curlhandle, CURLOPT_FTPPORT, "-"); curl_easy_setopt(curlhandle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L); curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, 1L); - for (c = 0; (r != CURLE_OK) && (c < tries); c++) { + for(c = 0; (r != CURLE_OK) && (c < tries); c++) { /* are we resuming? */ - if (c) { /* yes */ + if(c) { /* yes */ /* determine the length of the file already written */ /* @@ -131,7 +129,7 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath, curl_easy_setopt(curlhandle, CURLOPT_HEADER, 1L); r = curl_easy_perform(curlhandle); - if (r != CURLE_OK) + if(r != CURLE_OK) continue; curl_easy_setopt(curlhandle, CURLOPT_NOBODY, 0L); @@ -150,7 +148,7 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath, fclose(f); - if (r == CURLE_OK) + if(r == CURLE_OK) return 1; else { fprintf(stderr, "%s\n", curl_easy_strerror(r)); @@ -165,7 +163,8 @@ int main(int c, char **argv) curl_global_init(CURL_GLOBAL_ALL); curlhandle = curl_easy_init(); - upload(curlhandle, "ftp://user:pass@example.com/path/file", "C:\\file", 0, 3); + upload(curlhandle, "ftp://user:pass@example.com/path/file", "C:\\file", + 0, 3); curl_easy_cleanup(curlhandle); curl_global_cleanup(); diff --git a/docs/examples/getinfo.c b/docs/examples/getinfo.c index acbe1e1a..5585564c 100644 --- a/docs/examples/getinfo.c +++ b/docs/examples/getinfo.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Use getinfo to get content-type after completed transfer. + * </DESC> + */ #include <stdio.h> #include <curl/curl.h> @@ -27,18 +31,14 @@ int main(void) CURL *curl; CURLcode res; - /* http://curl.haxx.se/libcurl/c/curl_easy_init.html */ curl = curl_easy_init(); if(curl) { - /* http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTURL */ curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.com/"); - /* http://curl.haxx.se/libcurl/c/curl_easy_perform.html */ res = curl_easy_perform(curl); if(CURLE_OK == res) { char *ct; /* ask for the content-type */ - /* http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html */ res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct); if((CURLE_OK == res) && ct) @@ -46,7 +46,6 @@ int main(void) } /* always cleanup */ - /* http://curl.haxx.se/libcurl/c/curl_easy_cleanup.html */ curl_easy_cleanup(curl); } return 0; diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index a1c21404..fb794783 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,8 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ -/* Example source code to show how the callback function can be used to - * download data into a chunk of memory instead of storing it in a file. +/* <DESC> + * Shows how the write callback function can be used to download data into a + * chunk of memory instead of storing it in a file. + * </DESC> */ #include <stdio.h> @@ -34,7 +36,6 @@ struct MemoryStruct { size_t size; }; - static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) { @@ -55,7 +56,6 @@ WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) return realsize; } - int main(void) { CURL *curl_handle; diff --git a/docs/examples/getredirect.c b/docs/examples/getredirect.c new file mode 100644 index 00000000..347b1e9b --- /dev/null +++ b/docs/examples/getredirect.c @@ -0,0 +1,70 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +/* <DESC> + * Show how to extract Location: header and URL to redirect to. + * </DESC> + */ +#include <stdio.h> +#include <curl/curl.h> + +int main(void) +{ + CURL *curl; + CURLcode res; + char *location; + long response_code; + + curl = curl_easy_init(); + if(curl) { + curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); + + /* example.com is redirected, figure out the redirection! */ + + /* Perform the request, res will get 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 { + res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); + if((res == CURLE_OK) && + ((response_code / 100) != 3)) { + /* a redirect implies a 3xx response code */ + fprintf(stderr, "Not a redirect.\n"); + } + else { + res = curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &location); + + if((res == CURLE_OK) && location) { + /* This is the new absolute URL that you could redirect to, even if + * the Location: response header may have been a relative URL. */ + printf("Redirected to: %s\n", location); + } + } + } + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} diff --git a/docs/examples/ghiper.c b/docs/examples/ghiper.c index 7571ffa3..7317a63d 100644 --- a/docs/examples/ghiper.c +++ b/docs/examples/ghiper.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,38 +19,41 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * multi socket API usage together with with glib2 + * </DESC> + */ /* Example application source code using the multi socket interface to * download many files at once. * * Written by Jeff Pohlmeyer -Requires glib-2.x and a (POSIX?) system that has mkfifo(). + Requires glib-2.x and a (POSIX?) system that has mkfifo(). -This is an adaptation of libcurl's "hipev.c" and libevent's "event-test.c" -sample programs, adapted to use glib's g_io_channel in place of libevent. + This is an adaptation of libcurl's "hipev.c" and libevent's "event-test.c" + sample programs, adapted to use glib's g_io_channel in place of libevent. -When running, the program creates the named pipe "hiper.fifo" + When running, the program creates the named pipe "hiper.fifo" -Whenever there is input into the fifo, the program reads the input as a list -of URL's and creates some new easy handles to fetch each URL via the -curl_multi "hiper" API. + Whenever there is input into the fifo, the program reads the input as a list + of URL's and creates some new easy handles to fetch each URL via the + curl_multi "hiper" API. -Thus, you can try a single URL: - % echo http://www.yahoo.com > hiper.fifo + Thus, you can try a single URL: + % echo http://www.yahoo.com > hiper.fifo -Or a whole bunch of them: - % cat my-url-list > hiper.fifo + Or a whole bunch of them: + % cat my-url-list > hiper.fifo -The fifo buffer is handled almost instantly, so you can even add more URL's -while the previous requests are still being downloaded. + The fifo buffer is handled almost instantly, so you can even add more URL's + while the previous requests are still being downloaded. -This is purely a demo app, all retrieved data is simply discarded by the write -callback. + This is purely a demo app, all retrieved data is simply discarded by the write + callback. */ - #include <glib.h> #include <sys/stat.h> #include <unistd.h> @@ -60,13 +63,10 @@ callback. #include <errno.h> #include <curl/curl.h> - #define MSG_OUT g_print /* Change to "g_error" to write to stderr */ #define SHOW_VERBOSE 0 /* Set to non-zero for libcurl messages */ #define SHOW_PROGRESS 0 /* Set to non-zero to enable progress callback */ - - /* Global information, common to all connections */ typedef struct _GlobalInfo { CURLM *multi; @@ -74,8 +74,6 @@ typedef struct _GlobalInfo { int still_running; } GlobalInfo; - - /* Information associated with a specific easy handle */ typedef struct _ConnInfo { CURL *easy; @@ -84,7 +82,6 @@ typedef struct _ConnInfo { char error[CURL_ERROR_SIZE]; } ConnInfo; - /* Information associated with a specific socket */ typedef struct _SockInfo { curl_socket_t sockfd; @@ -96,30 +93,25 @@ typedef struct _SockInfo { GlobalInfo *global; } SockInfo; - - - /* Die if we get a bad CURLMcode somewhere */ static void mcode_or_die(const char *where, CURLMcode code) { - if ( CURLM_OK != code ) { + if(CURLM_OK != code) { const char *s; switch (code) { - case CURLM_BAD_HANDLE: s="CURLM_BAD_HANDLE"; break; - case CURLM_BAD_EASY_HANDLE: s="CURLM_BAD_EASY_HANDLE"; break; - case CURLM_OUT_OF_MEMORY: s="CURLM_OUT_OF_MEMORY"; break; - case CURLM_INTERNAL_ERROR: s="CURLM_INTERNAL_ERROR"; break; - case CURLM_BAD_SOCKET: s="CURLM_BAD_SOCKET"; break; - case CURLM_UNKNOWN_OPTION: s="CURLM_UNKNOWN_OPTION"; break; - case CURLM_LAST: s="CURLM_LAST"; break; - default: s="CURLM_unknown"; + case CURLM_BAD_HANDLE: s="CURLM_BAD_HANDLE"; break; + case CURLM_BAD_EASY_HANDLE: s="CURLM_BAD_EASY_HANDLE"; break; + case CURLM_OUT_OF_MEMORY: s="CURLM_OUT_OF_MEMORY"; break; + case CURLM_INTERNAL_ERROR: s="CURLM_INTERNAL_ERROR"; break; + case CURLM_BAD_SOCKET: s="CURLM_BAD_SOCKET"; break; + case CURLM_UNKNOWN_OPTION: s="CURLM_UNKNOWN_OPTION"; break; + case CURLM_LAST: s="CURLM_LAST"; break; + default: s="CURLM_unknown"; } MSG_OUT("ERROR: %s returns %s\n", where, s); exit(code); } } - - /* Check for completed transfers, and remove their easy handles */ static void check_multi_info(GlobalInfo *g) { @@ -131,8 +123,8 @@ static void check_multi_info(GlobalInfo *g) CURLcode res; MSG_OUT("REMAINING: %d\n", g->still_running); - while ((msg = curl_multi_info_read(g->multi, &msgs_left))) { - if (msg->msg == CURLMSG_DONE) { + while((msg = curl_multi_info_read(g->multi, &msgs_left))) { + if(msg->msg == CURLMSG_DONE) { easy = msg->easy_handle; res = msg->data.result; curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn); @@ -146,8 +138,6 @@ static void check_multi_info(GlobalInfo *g) } } - - /* Called by glib when our timeout expires */ static gboolean timer_cb(gpointer data) { @@ -155,14 +145,12 @@ static gboolean timer_cb(gpointer data) CURLMcode rc; rc = curl_multi_socket_action(g->multi, - CURL_SOCKET_TIMEOUT, 0, &g->still_running); + CURL_SOCKET_TIMEOUT, 0, &g->still_running); mcode_or_die("timer_cb: curl_multi_socket_action", rc); check_multi_info(g); return FALSE; } - - /* Update the event timer after curl_multi library calls */ static int update_timeout_cb(CURLM *multi, long timeout_ms, void *userp) { @@ -172,15 +160,12 @@ static int update_timeout_cb(CURLM *multi, long timeout_ms, void *userp) timeout.tv_usec = (timeout_ms%1000)*1000; MSG_OUT("*** update_timeout_cb %ld => %ld:%ld ***\n", - timeout_ms, timeout.tv_sec, timeout.tv_usec); + timeout_ms, timeout.tv_sec, timeout.tv_usec); g->timer_event = g_timeout_add(timeout_ms, timer_cb, g); return 0; } - - - /* Called by glib when we get action on a multi socket */ static gboolean event_cb(GIOChannel *ch, GIOCondition condition, gpointer data) { @@ -198,41 +183,43 @@ static gboolean event_cb(GIOChannel *ch, GIOCondition condition, gpointer data) check_multi_info(g); if(g->still_running) { return TRUE; - } else { + } + else { MSG_OUT("last transfer done, kill timeout\n"); - if (g->timer_event) { g_source_remove(g->timer_event); } + if(g->timer_event) { + g_source_remove(g->timer_event); + } return FALSE; } } - - /* Clean up the SockInfo structure */ static void remsock(SockInfo *f) { - if (!f) { return; } - if (f->ev) { g_source_remove(f->ev); } + if(!f) { + return; + } + if(f->ev) { + g_source_remove(f->ev); + } g_free(f); } - - /* Assign information to a SockInfo structure */ static void setsock(SockInfo*f, curl_socket_t s, CURL*e, int act, GlobalInfo*g) { GIOCondition kind = - (act&CURL_POLL_IN?G_IO_IN:0)|(act&CURL_POLL_OUT?G_IO_OUT:0); + (act&CURL_POLL_IN?G_IO_IN:0)|(act&CURL_POLL_OUT?G_IO_OUT:0); f->sockfd = s; f->action = act; f->easy = e; - if (f->ev) { g_source_remove(f->ev); } - f->ev=g_io_add_watch(f->ch, kind, event_cb,g); - + if(f->ev) { + g_source_remove(f->ev); + } + f->ev=g_io_add_watch(f->ch, kind, event_cb, g); } - - /* Initialize a new SockInfo structure */ static void addsock(curl_socket_t s, CURL *easy, int action, GlobalInfo *g) { @@ -244,8 +231,6 @@ static void addsock(curl_socket_t s, CURL *easy, int action, GlobalInfo *g) curl_multi_assign(g->multi, s, fdp); } - - /* CURLMOPT_SOCKETFUNCTION */ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) { @@ -254,14 +239,15 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) static const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE" }; MSG_OUT("socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); - if (what == CURL_POLL_REMOVE) { + if(what == CURL_POLL_REMOVE) { MSG_OUT("\n"); remsock(fdp); - } else { - if (!fdp) { + } + else { + if(!fdp) { MSG_OUT("Adding data: %s%s\n", - what&CURL_POLL_IN?"READ":"", - what&CURL_POLL_OUT?"WRITE":"" ); + what&CURL_POLL_IN?"READ":"", + what&CURL_POLL_OUT?"WRITE":""); addsock(s, e, what, g); } else { @@ -273,8 +259,6 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) return 0; } - - /* CURLOPT_WRITEFUNCTION */ static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data) { @@ -285,30 +269,25 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data) return realsize; } - - /* CURLOPT_PROGRESSFUNCTION */ -static int prog_cb (void *p, double dltotal, double dlnow, double ult, double uln) +static int prog_cb (void *p, double dltotal, double dlnow, double ult, + double uln) { ConnInfo *conn = (ConnInfo *)p; MSG_OUT("Progress: %s (%g/%g)\n", conn->url, dlnow, dltotal); return 0; } - - /* Create a new easy handle, and add it to the global curl_multi */ -static void new_conn(char *url, GlobalInfo *g ) +static void new_conn(char *url, GlobalInfo *g) { ConnInfo *conn; CURLMcode rc; conn = g_malloc0(sizeof(ConnInfo)); - conn->error[0]='\0'; - conn->easy = curl_easy_init(); - if (!conn->easy) { + if(!conn->easy) { MSG_OUT("curl_easy_init() failed, exiting!\n"); exit(2); } @@ -336,93 +315,90 @@ static void new_conn(char *url, GlobalInfo *g ) that the necessary socket_action() call will be called by this app */ } - /* This gets called by glib whenever data is received from the fifo */ static gboolean fifo_cb (GIOChannel *ch, GIOCondition condition, gpointer data) { - #define BUF_SIZE 1024 +#define BUF_SIZE 1024 gsize len, tp; gchar *buf, *tmp, *all=NULL; GIOStatus rv; do { GError *err=NULL; - rv = g_io_channel_read_line (ch,&buf,&len,&tp,&err); - if ( buf ) { - if (tp) { buf[tp]='\0'; } - new_conn(buf,(GlobalInfo*)data); + rv = g_io_channel_read_line(ch, &buf, &len, &tp, &err); + if(buf) { + if(tp) { + buf[tp]='\0'; + } + new_conn(buf, (GlobalInfo*)data); g_free(buf); - } else { + } + else { buf = g_malloc(BUF_SIZE+1); - while (TRUE) { + while(TRUE) { buf[BUF_SIZE]='\0'; - g_io_channel_read_chars(ch,buf,BUF_SIZE,&len,&err); - if (len) { + g_io_channel_read_chars(ch, buf, BUF_SIZE, &len, &err); + if(len) { buf[len]='\0'; - if (all) { + if(all) { tmp=all; all=g_strdup_printf("%s%s", tmp, buf); g_free(tmp); - } else { + } + else { all = g_strdup(buf); } - } else { - break; + } + else { + break; } } - if (all) { - new_conn(all,(GlobalInfo*)data); + if(all) { + new_conn(all, (GlobalInfo*)data); g_free(all); } g_free(buf); } - if ( err ) { + if(err) { g_error("fifo_cb: %s", err->message); g_free(err); break; } - } while ( (len) && (rv == G_IO_STATUS_NORMAL) ); + } while((len) && (rv == G_IO_STATUS_NORMAL)); return TRUE; } - - - int init_fifo(void) { - struct stat st; - const char *fifo = "hiper.fifo"; - int socket; - - if (lstat (fifo, &st) == 0) { - if ((st.st_mode & S_IFMT) == S_IFREG) { - errno = EEXIST; - perror("lstat"); - exit (1); + struct stat st; + const char *fifo = "hiper.fifo"; + int socket; + + if(lstat (fifo, &st) == 0) { + if((st.st_mode & S_IFMT) == S_IFREG) { + errno = EEXIST; + perror("lstat"); + exit (1); + } } - } - - unlink (fifo); - if (mkfifo (fifo, 0600) == -1) { - perror("mkfifo"); - exit (1); - } - socket = open (fifo, O_RDWR | O_NONBLOCK, 0); + unlink (fifo); + if(mkfifo (fifo, 0600) == -1) { + perror("mkfifo"); + exit (1); + } - if (socket == -1) { - perror("open"); - exit (1); - } - MSG_OUT("Now, pipe some URL's into > %s\n", fifo); + socket = open (fifo, O_RDWR | O_NONBLOCK, 0); - return socket; + if(socket == -1) { + perror("open"); + exit (1); + } + MSG_OUT("Now, pipe some URL's into > %s\n", fifo); + return socket; } - - - int main(int argc, char **argv) { GlobalInfo *g; @@ -434,8 +410,8 @@ int main(int argc, char **argv) fd=init_fifo(); 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); + g_io_add_watch(ch, G_IO_IN, fifo_cb, g); + gmain=g_main_loop_new(NULL, FALSE); g->multi = curl_multi_init(); curl_multi_setopt(g->multi, CURLMOPT_SOCKETFUNCTION, sock_cb); curl_multi_setopt(g->multi, CURLMOPT_SOCKETDATA, g); diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index 84035aa2..98bcafe6 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * multi socket API usage with libevent 2 + * </DESC> + */ /* Example application source code using the multi socket interface to download many files at once. @@ -122,7 +126,7 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, GlobalInfo *g) /* Die if we get a bad CURLMcode somewhere */ static void mcode_or_die(const char *where, CURLMcode code) { - if ( CURLM_OK != code ) { + if(CURLM_OK != code) { const char *s; switch (code) { case CURLM_BAD_HANDLE: s="CURLM_BAD_HANDLE"; break; @@ -156,8 +160,8 @@ static void check_multi_info(GlobalInfo *g) CURLcode res; fprintf(MSG_OUT, "REMAINING: %d\n", g->still_running); - while ((msg = curl_multi_info_read(g->multi, &msgs_left))) { - if (msg->msg == CURLMSG_DONE) { + while((msg = curl_multi_info_read(g->multi, &msgs_left))) { + if(msg->msg == CURLMSG_DONE) { easy = msg->easy_handle; res = msg->data.result; curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn); @@ -187,9 +191,9 @@ static void event_cb(int fd, short kind, void *userp) mcode_or_die("event_cb: curl_multi_socket_action", rc); check_multi_info(g); - if ( g->still_running <= 0 ) { + if(g->still_running <= 0) { fprintf(MSG_OUT, "last transfer done, kill timeout\n"); - if (evtimer_pending(g->timer_event, NULL)) { + if(evtimer_pending(g->timer_event, NULL)) { evtimer_del(g->timer_event); } } @@ -216,8 +220,8 @@ static void timer_cb(int fd, short kind, void *userp) /* Clean up the SockInfo structure */ static void remsock(SockInfo *f) { - if (f) { - if (f->evset) + if(f) { + if(f->evset) event_free(f->ev); free(f); } @@ -234,7 +238,7 @@ static void setsock(SockInfo*f, curl_socket_t s, CURL*e, int act, GlobalInfo*g) f->sockfd = s; f->action = act; f->easy = e; - if (f->evset) + if(f->evset) event_free(f->ev); f->ev = event_new(g->evbase, f->sockfd, kind, event_cb, g); f->evset = 1; @@ -262,12 +266,12 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) fprintf(MSG_OUT, "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); - if (what == CURL_POLL_REMOVE) { + if(what == CURL_POLL_REMOVE) { fprintf(MSG_OUT, "\n"); remsock(fdp); } else { - if (!fdp) { + if(!fdp) { fprintf(MSG_OUT, "Adding data: %s\n", whatstr[what]); addsock(s, e, what, g); } @@ -308,7 +312,7 @@ static int prog_cb (void *p, double dltotal, double dlnow, double ult, /* Create a new easy handle, and add it to the global curl_multi */ -static void new_conn(char *url, GlobalInfo *g ) +static void new_conn(char *url, GlobalInfo *g) { ConnInfo *conn; CURLMcode rc; @@ -318,7 +322,7 @@ static void new_conn(char *url, GlobalInfo *g ) conn->error[0]='\0'; conn->easy = curl_easy_init(); - if (!conn->easy) { + if(!conn->easy) { fprintf(MSG_OUT, "curl_easy_init() failed, exiting!\n"); exit(2); } @@ -326,7 +330,7 @@ static void new_conn(char *url, GlobalInfo *g ) conn->url = strdup(url); curl_easy_setopt(conn->easy, CURLOPT_URL, conn->url); curl_easy_setopt(conn->easy, CURLOPT_WRITEFUNCTION, write_cb); - curl_easy_setopt(conn->easy, CURLOPT_WRITEDATA, &conn); + curl_easy_setopt(conn->easy, CURLOPT_WRITEDATA, conn); curl_easy_setopt(conn->easy, CURLOPT_VERBOSE, 1L); curl_easy_setopt(conn->easy, CURLOPT_ERRORBUFFER, conn->error); curl_easy_setopt(conn->easy, CURLOPT_PRIVATE, conn); @@ -356,10 +360,12 @@ static void fifo_cb(int fd, short event, void *arg) s[0]='\0'; rv=fscanf(g->input, "%1023s%n", s, &n); s[n]='\0'; - if ( n && s[0] ) { - new_conn(s,arg); /* if we read a URL, go get it! */ - } else break; - } while ( rv != EOF); + if(n && s[0]) { + new_conn(s, arg); /* if we read a URL, go get it! */ + } + else + break; + } while(rv != EOF); } /* Create a named pipe and tell libevent to monitor it */ @@ -370,20 +376,20 @@ static int init_fifo (GlobalInfo *g) curl_socket_t sockfd; fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo); - if (lstat (fifo, &st) == 0) { - if ((st.st_mode & S_IFMT) == S_IFREG) { + if(lstat (fifo, &st) == 0) { + if((st.st_mode & S_IFMT) == S_IFREG) { errno = EEXIST; perror("lstat"); exit (1); } } unlink(fifo); - if (mkfifo (fifo, 0600) == -1) { + if(mkfifo (fifo, 0600) == -1) { perror("mkfifo"); exit (1); } sockfd = open(fifo, O_RDWR | O_NONBLOCK, 0); - if (sockfd == -1) { + if(sockfd == -1) { perror("open"); exit (1); } diff --git a/docs/examples/href_extractor.c b/docs/examples/href_extractor.c index c11325d2..16f50c0e 100644 --- a/docs/examples/href_extractor.c +++ b/docs/examples/href_extractor.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2012, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 2012 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -20,13 +20,13 @@ * ***************************************************************************/ +/* <DESC> + * Uses the "Streaming HTML parser" to extract the href pieces in a streaming + * manner from a downloaded HTML. + * </DESC> + */ /* - * This example uses the "Streaming HTML parser" to extract the href pieces in - * a streaming manner from a downloaded HTML. Kindly donated by Michał - * Kowalczyk. - * - * The parser is found at - * http://code.google.com/p/htmlstreamparser/ + * The HTML parser is found at http://code.google.com/p/htmlstreamparser/ */ #include <stdio.h> @@ -38,11 +38,11 @@ static size_t write_callback(void *buffer, size_t size, size_t nmemb, void *hsp) { size_t realsize = size * nmemb, p; - for (p = 0; p < realsize; p++) { + for(p = 0; p < realsize; p++) { html_parser_char_parse(hsp, ((char *)buffer)[p]); - if (html_parser_cmp_tag(hsp, "a", 1)) - if (html_parser_cmp_attr(hsp, "href", 4)) - if (html_parser_is_in(hsp, HTML_VALUE_ENDED)) { + if(html_parser_cmp_tag(hsp, "a", 1)) + if(html_parser_cmp_attr(hsp, "href", 4)) + if(html_parser_is_in(hsp, HTML_VALUE_ENDED)) { html_parser_val(hsp)[html_parser_val_length(hsp)] = '\0'; printf("%s\n", html_parser_val(hsp)); } @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) CURL *curl; HTMLSTREAMPARSER *hsp; - if (argc != 2) { + if(argc != 2) { printf("Usage: %s URL\n", argv[0]); return EXIT_FAILURE; } diff --git a/docs/examples/htmltidy.c b/docs/examples/htmltidy.c index a36e331b..687e3f34 100644 --- a/docs/examples/htmltidy.c +++ b/docs/examples/htmltidy.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,13 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ -/* Download a document and use libtidy to parse the HTML. - * Written by Jeff Pohlmeyer - * +/* <DESC> + * Download a document and use libtidy to parse the HTML. + * </DESC> + */ +/* * LibTidy => http://tidy.sourceforge.net - * - * gcc -Wall -I/usr/local/include tidycurl.c -lcurl -ltidy -o tidycurl - * */ #include <stdio.h> @@ -38,29 +37,27 @@ uint write_cb(char *in, uint size, uint nmemb, TidyBuffer *out) { uint r; r = size * nmemb; - tidyBufAppend( out, in, r ); - return(r); + tidyBufAppend(out, in, r); + return r; } /* Traverse the document tree */ -void dumpNode(TidyDoc doc, TidyNode tnod, int indent ) +void dumpNode(TidyDoc doc, TidyNode tnod, int indent) { TidyNode child; - for ( child = tidyGetChild(tnod); child; child = tidyGetNext(child) ) - { - ctmbstr name = tidyNodeGetName( child ); - if ( name ) - { + for(child = tidyGetChild(tnod); child; child = tidyGetNext(child) ) { + ctmbstr name = tidyNodeGetName(child); + if(name) { /* if it has a name, then it's an HTML tag ... */ TidyAttr attr; - printf( "%*.*s%s ", indent, indent, "<", name); + printf("%*.*s%s ", indent, indent, "<", name); /* walk the attribute list */ - for ( attr=tidyAttrFirst(child); attr; attr=tidyAttrNext(attr) ) { + for(attr=tidyAttrFirst(child); attr; attr=tidyAttrNext(attr) ) { printf(tidyAttrName(attr)); tidyAttrValue(attr)?printf("=\"%s\" ", tidyAttrValue(attr)):printf(" "); } - printf( ">\n"); + printf(">\n"); } else { /* if it doesn't have a name, then it's probably text, cdata, etc... */ @@ -70,12 +67,12 @@ void dumpNode(TidyDoc doc, TidyNode tnod, int indent ) printf("%*.*s\n", indent, indent, buf.bp?(char *)buf.bp:""); tidyBufFree(&buf); } - dumpNode( doc, child, indent + 4 ); /* recursive */ + dumpNode(doc, child, indent + 4); /* recursive */ } } -int main(int argc, char **argv ) +int main(int argc, char **argv) { CURL *curl; char curl_errbuf[CURL_ERROR_SIZE]; @@ -83,7 +80,7 @@ int main(int argc, char **argv ) TidyBuffer docbuf = {0}; TidyBuffer tidy_errbuf = {0}; int err; - if ( argc == 2) { + if(argc == 2) { curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, argv[1]); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf); @@ -94,19 +91,19 @@ int main(int argc, char **argv ) tdoc = tidyCreate(); tidyOptSetBool(tdoc, TidyForceOutput, yes); /* try harder */ tidyOptSetInt(tdoc, TidyWrapLen, 4096); - tidySetErrorBuffer( tdoc, &tidy_errbuf ); + tidySetErrorBuffer(tdoc, &tidy_errbuf); tidyBufInit(&docbuf); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &docbuf); err=curl_easy_perform(curl); - if ( !err ) { + if(!err) { err = tidyParseBuffer(tdoc, &docbuf); /* parse the input */ - if ( err >= 0 ) { + if(err >= 0) { err = tidyCleanAndRepair(tdoc); /* fix any problems */ - if ( err >= 0 ) { + if(err >= 0) { err = tidyRunDiagnostics(tdoc); /* load tidy error buffer */ - if ( err >= 0 ) { - dumpNode( tdoc, tidyGetRoot(tdoc), 0 ); /* walk the tree */ + if(err >= 0) { + dumpNode(tdoc, tidyGetRoot(tdoc), 0); /* walk the tree */ fprintf(stderr, "%s\n", tidy_errbuf.bp); /* show errors */ } } @@ -120,11 +117,11 @@ int main(int argc, char **argv ) tidyBufFree(&docbuf); tidyBufFree(&tidy_errbuf); tidyRelease(tdoc); - return(err); + return err; } else - printf( "usage: %s <url>\n", argv[0] ); + printf("usage: %s <url>\n", argv[0]); - return(0); + return 0; } diff --git a/docs/examples/htmltitle.cpp b/docs/examples/htmltitle.cpp index ab89bb6a..5e6b4a00 100644 --- a/docs/examples/htmltitle.cpp +++ b/docs/examples/htmltitle.cpp @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,8 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ -// Get a web page, parse it with libxml. -// +/* <DESC> + * Get a web page, extract the title with libxml. + * </DESC> + */ // Written by Lars Nilsson // // GNU C++ compile command line suggestion (edit paths accordingly): @@ -40,7 +42,7 @@ // #ifdef _MSC_VER -#define COMPARE(a, b) (!stricmp((a), (b))) +#define COMPARE(a, b) (!_stricmp((a), (b))) #else #define COMPARE(a, b) (!strcasecmp((a), (b))) #endif diff --git a/docs/examples/http-post.c b/docs/examples/http-post.c index f1975b1e..01754527 100644 --- a/docs/examples/http-post.c +++ b/docs/examples/http-post.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * simple HTTP POST using the easy interface + * </DESC> + */ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/http2-download.c b/docs/examples/http2-download.c index 3b7ca81d..9e87a064 100644 --- a/docs/examples/http2-download.c +++ b/docs/examples/http2-download.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,8 +19,13 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Multiplexed HTTP/2 downloads over a single connection + * </DESC> + */ #include <stdio.h> #include <stdlib.h> +#include <string.h> /* somewhat unix-specific */ #include <sys/time.h> @@ -84,14 +89,14 @@ void dump(const char *text, int num, unsigned char *ptr, size_t size, for(c = 0; (c < width) && (i+c < size); c++) { /* check for 0D0A; if found, skip past and start a new line of output */ - if (nohex && (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) { + if(nohex && (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) { i+=(c+2-width); break; } fprintf(stderr, "%c", (ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:'.'); /* check again for 0D0A, to avoid an extra \n if it's at width */ - if (nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) { + if(nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) { i+=(c+3-width); break; } @@ -144,7 +149,7 @@ static void setup(CURL *hnd, int num) FILE *out; char filename[128]; - sprintf(filename, "dl-%d", num); + snprintf(filename, 128, "dl-%d", num); out = fopen(filename, "wb"); @@ -239,8 +244,7 @@ int main(int argc, char **argv) /* get file descriptors from the transfers */ mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); - if(mc != CURLM_OK) - { + if(mc != CURLM_OK) { fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); break; } diff --git a/docs/examples/http2-serverpush.c b/docs/examples/http2-serverpush.c new file mode 100644 index 00000000..1a8c69b7 --- /dev/null +++ b/docs/examples/http2-serverpush.c @@ -0,0 +1,320 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +/* <DESC> + * HTTP/2 server push + * </DESC> + */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +/* somewhat unix-specific */ +#include <sys/time.h> +#include <unistd.h> + +/* curl stuff */ +#include <curl/curl.h> + +#ifndef CURLPIPE_MULTIPLEX +#error "too old libcurl, can't do HTTP/2 server push!" +#endif + +static +void dump(const char *text, unsigned char *ptr, size_t size, + char nohex) +{ + size_t i; + size_t c; + + unsigned int width=0x10; + + if(nohex) + /* without the hex output, we can fit more on screen */ + width = 0x40; + + fprintf(stderr, "%s, %ld bytes (0x%lx)\n", + text, (long)size, (long)size); + + for(i=0; i<size; i+= width) { + + fprintf(stderr, "%4.4lx: ", (long)i); + + if(!nohex) { + /* hex not disabled, show it */ + for(c = 0; c < width; c++) + if(i+c < size) + fprintf(stderr, "%02x ", ptr[i+c]); + else + fputs(" ", stderr); + } + + for(c = 0; (c < width) && (i+c < size); c++) { + /* check for 0D0A; if found, skip past and start a new line of output */ + if(nohex && (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) { + i+=(c+2-width); + break; + } + fprintf(stderr, "%c", + (ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:'.'); + /* check again for 0D0A, to avoid an extra \n if it's at width */ + if(nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) { + i+=(c+3-width); + break; + } + } + fputc('\n', stderr); /* newline */ + } +} + +static +int my_trace(CURL *handle, curl_infotype type, + char *data, size_t size, + void *userp) +{ + const char *text; + (void)handle; /* prevent compiler warning */ + (void)userp; + switch (type) { + case CURLINFO_TEXT: + fprintf(stderr, "== Info: %s", data); + default: /* in case a new one is introduced to shock us */ + return 0; + + case CURLINFO_HEADER_OUT: + text = "=> Send header"; + break; + case CURLINFO_DATA_OUT: + text = "=> Send data"; + break; + case CURLINFO_SSL_DATA_OUT: + text = "=> Send SSL data"; + break; + case CURLINFO_HEADER_IN: + text = "<= Recv header"; + break; + case CURLINFO_DATA_IN: + text = "<= Recv data"; + break; + case CURLINFO_SSL_DATA_IN: + text = "<= Recv SSL data"; + break; + } + + dump(text, (unsigned char *)data, size, 1); + return 0; +} + +#define OUTPUTFILE "dl" + +static void setup(CURL *hnd) +{ + FILE *out = fopen(OUTPUTFILE, "wb"); + + /* write to this file */ + curl_easy_setopt(hnd, CURLOPT_WRITEDATA, out); + + /* set the same URL */ + curl_easy_setopt(hnd, CURLOPT_URL, "https://localhost:8443/index.html"); + + /* send it verbose for max debuggaility */ + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); + curl_easy_setopt(hnd, CURLOPT_DEBUGFUNCTION, my_trace); + + /* HTTP/2 please */ + curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); + + /* we use a self-signed test server, skip verification during debugging */ + curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L); + +#if (CURLPIPE_MULTIPLEX > 0) + /* wait for pipe connection to confirm */ + curl_easy_setopt(hnd, CURLOPT_PIPEWAIT, 1L); +#endif + +} + +/* called when there's an incoming push */ +static int server_push_callback(CURL *parent, + CURL *easy, + size_t num_headers, + struct curl_pushheaders *headers, + void *userp) +{ + char *headp; + size_t i; + int *transfers = (int *)userp; + char filename[128]; + FILE *out; + static unsigned int count = 0; + + (void)parent; /* we have no use for this */ + + snprintf(filename, 128, "push%u", count++); + + /* here's a new stream, save it in a new file for each new push */ + out = fopen(filename, "wb"); + + /* write to this file */ + curl_easy_setopt(easy, CURLOPT_WRITEDATA, out); + + fprintf(stderr, "**** push callback approves stream %u, got %d headers!\n", + count, (int)num_headers); + + for(i=0; i<num_headers; i++) { + headp = curl_pushheader_bynum(headers, i); + fprintf(stderr, "**** header %u: %s\n", (int)i, headp); + } + + headp = curl_pushheader_byname(headers, ":path"); + if(headp) { + fprintf(stderr, "**** The PATH is %s\n", headp /* skip :path + colon */); + } + + (*transfers)++; /* one more */ + return CURL_PUSH_OK; +} + + +/* + * Download a file over HTTP/2, take care of server push. + */ +int main(void) +{ + CURL *easy; + CURLM *multi_handle; + int still_running; /* keep number of running handles */ + int transfers=1; /* we start with one */ + struct CURLMsg *m; + + /* init a multi stack */ + multi_handle = curl_multi_init(); + + easy = curl_easy_init(); + + /* set options */ + setup(easy); + + /* add the easy transfer */ + curl_multi_add_handle(multi_handle, easy); + + curl_multi_setopt(multi_handle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX); + curl_multi_setopt(multi_handle, CURLMOPT_PUSHFUNCTION, server_push_callback); + curl_multi_setopt(multi_handle, CURLMOPT_PUSHDATA, &transfers); + + /* we start some action by calling perform right away */ + curl_multi_perform(multi_handle, &still_running); + + do { + struct timeval timeout; + int rc; /* select() return code */ + CURLMcode mc; /* curl_multi_fdset() return code */ + + fd_set fdread; + fd_set fdwrite; + fd_set fdexcep; + int maxfd = -1; + + long curl_timeo = -1; + + FD_ZERO(&fdread); + FD_ZERO(&fdwrite); + FD_ZERO(&fdexcep); + + /* set a suitable timeout to play around with */ + timeout.tv_sec = 1; + timeout.tv_usec = 0; + + curl_multi_timeout(multi_handle, &curl_timeo); + if(curl_timeo >= 0) { + timeout.tv_sec = curl_timeo / 1000; + if(timeout.tv_sec > 1) + timeout.tv_sec = 1; + else + timeout.tv_usec = (curl_timeo % 1000) * 1000; + } + + /* get file descriptors from the transfers */ + mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + + if(mc != CURLM_OK) { + fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); + break; + } + + /* On success the value of maxfd is guaranteed to be >= -1. We call + select(maxfd + 1, ...); specially in case of (maxfd == -1) there are + no fds ready yet so we call select(0, ...) --or Sleep() on Windows-- + to sleep 100ms, which is the minimum suggested value in the + curl_multi_fdset() doc. */ + + if(maxfd == -1) { +#ifdef _WIN32 + Sleep(100); + rc = 0; +#else + /* Portable sleep for platforms other than Windows. */ + struct timeval wait = { 0, 100 * 1000 }; /* 100ms */ + rc = select(0, NULL, NULL, NULL, &wait); +#endif + } + else { + /* Note that on some platforms 'timeout' may be modified by select(). + If you need access to the original value save a copy beforehand. */ + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); + } + + switch(rc) { + case -1: + /* select error */ + break; + case 0: + default: + /* timeout or readable/writable sockets */ + curl_multi_perform(multi_handle, &still_running); + break; + } + + /* + * A little caution when doing server push is that libcurl itself has + * created and added one or more easy handles but we need to clean them up + * when we are done. + */ + + do { + int msgq = 0;; + m = curl_multi_info_read(multi_handle, &msgq); + if(m && (m->msg == CURLMSG_DONE)) { + CURL *e = m->easy_handle; + transfers--; + curl_multi_remove_handle(multi_handle, e); + curl_easy_cleanup(e); + } + } while(m); + + } while(transfers); /* as long as we have transfers going */ + + curl_multi_cleanup(multi_handle); + + + return 0; +} diff --git a/docs/examples/http2-upload.c b/docs/examples/http2-upload.c index bca16c0d..b6353713 100644 --- a/docs/examples/http2-upload.c +++ b/docs/examples/http2-upload.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,8 +19,13 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Multiplexed HTTP/2 uploads over a single connection + * </DESC> + */ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <fcntl.h> #include <sys/stat.h> @@ -85,14 +90,14 @@ void dump(const char *text, int num, unsigned char *ptr, size_t size, for(c = 0; (c < width) && (i+c < size); c++) { /* check for 0D0A; if found, skip past and start a new line of output */ - if (nohex && (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) { + if(nohex && (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) { i+=(c+2-width); break; } fprintf(stderr, "%c", (ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:'.'); /* check again for 0D0A, to avoid an extra \n if it's at width */ - if (nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) { + if(nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) { i+=(c+3-width); break; } @@ -182,10 +187,10 @@ static void setup(CURL *hnd, int num, const char *upload) struct stat file_info; curl_off_t uploadsize; - sprintf(filename, "dl-%d", num); + snprintf(filename, 128, "dl-%d", num); out = fopen(filename, "wb"); - sprintf(url, "https://localhost:8443/upload-%d", num); + snprintf(url, 256, "https://localhost:8443/upload-%d", num); /* get the file size of the local file */ stat(upload, &file_info); @@ -303,8 +308,7 @@ int main(int argc, char **argv) /* get file descriptors from the transfers */ mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); - if(mc != CURLM_OK) - { + if(mc != CURLM_OK) { fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); break; } diff --git a/docs/examples/httpcustomheader.c b/docs/examples/httpcustomheader.c index 8542ead5..d22b7bc5 100644 --- a/docs/examples/httpcustomheader.c +++ b/docs/examples/httpcustomheader.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * HTTP request with custom modified, removed and added headers + * </DESC> + */ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index 2e9dc217..4f8aece1 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * HTTP PUT with easy interface and read callback + * </DESC> + */ #include <stdio.h> #include <fcntl.h> #include <sys/stat.h> @@ -56,7 +60,7 @@ int main(int argc, char **argv) { CURL *curl; CURLcode res; - FILE * hd_src ; + FILE * hd_src; struct stat file_info; char *file; diff --git a/docs/examples/https.c b/docs/examples/https.c index bd9a33ba..cca83fee 100644 --- a/docs/examples/https.c +++ b/docs/examples/https.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Simple HTTPS GET + * </DESC> + */ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/imap-append.c b/docs/examples/imap-append.c index fa531a8c..3f832897 100644 --- a/docs/examples/imap-append.c +++ b/docs/examples/imap-append.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * IMAP example showing how to send e-mails + * </DESC> + */ + #include <stdio.h> #include <string.h> #include <curl/curl.h> @@ -38,7 +44,8 @@ static const char *payload_text[] = { "To: " TO "\r\n", "From: " FROM "(Example User)\r\n", "Cc: " CC "(Another example User)\r\n", - "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>\r\n", + "Message-ID: " + "<dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>\r\n", "Subject: IMAP example message\r\n", "\r\n", /* empty line to divide headers from body, see RFC5322 */ "The body of the message starts here.\r\n", diff --git a/docs/examples/imap-copy.c b/docs/examples/imap-copy.c index fe2d91c1..4c3b640b 100644 --- a/docs/examples/imap-copy.c +++ b/docs/examples/imap-copy.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * IMAP example showing how to copy an e-mail from one folder to another + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/imap-create.c b/docs/examples/imap-create.c index 65ddede6..8f72cb8f 100644 --- a/docs/examples/imap-create.c +++ b/docs/examples/imap-create.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * IMAP example showing how to create a new folder + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/imap-delete.c b/docs/examples/imap-delete.c index 5113be9a..bd9d1a49 100644 --- a/docs/examples/imap-delete.c +++ b/docs/examples/imap-delete.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * IMAP example showing how to delete a folder + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/imap-examine.c b/docs/examples/imap-examine.c index a7b41c58..4287f8a1 100644 --- a/docs/examples/imap-examine.c +++ b/docs/examples/imap-examine.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * IMAP example showing how to obtain information about a folder + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/imap-fetch.c b/docs/examples/imap-fetch.c index 831d0dcf..192d2e9e 100644 --- a/docs/examples/imap-fetch.c +++ b/docs/examples/imap-fetch.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * IMAP example showing how to retreieve e-mails + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> @@ -40,7 +46,8 @@ int main(void) curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret"); /* This will fetch message 1 from the user's inbox */ - curl_easy_setopt(curl, CURLOPT_URL, "imap://imap.example.com/INBOX/;UID=1"); + curl_easy_setopt(curl, CURLOPT_URL, + "imap://imap.example.com/INBOX/;UID=1"); /* Perform the fetch */ res = curl_easy_perform(curl); diff --git a/docs/examples/imap-list.c b/docs/examples/imap-list.c index 4223052e..291e1e67 100644 --- a/docs/examples/imap-list.c +++ b/docs/examples/imap-list.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * IMAP example to list the folders within a mailbox + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/imap-lsub.c b/docs/examples/imap-lsub.c index 8960b62b..d130c3d5 100644 --- a/docs/examples/imap-lsub.c +++ b/docs/examples/imap-lsub.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * IMAP example to list the subscribed folders + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/imap-multi.c b/docs/examples/imap-multi.c index c7dc1307..8cd4858c 100644 --- a/docs/examples/imap-multi.c +++ b/docs/examples/imap-multi.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,7 +19,14 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * IMAP example using the multi interface + * </DESC> + */ + #include <stdio.h> +#include <string.h> #include <curl/curl.h> /* This is a simple example showing how to fetch mail using libcurl's IMAP @@ -113,8 +120,7 @@ int main(void) /* get file descriptors from the transfers */ mc = curl_multi_fdset(mcurl, &fdread, &fdwrite, &fdexcep, &maxfd); - if(mc != CURLM_OK) - { + if(mc != CURLM_OK) { fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); break; } diff --git a/docs/examples/imap-noop.c b/docs/examples/imap-noop.c index 71a55728..566890ef 100644 --- a/docs/examples/imap-noop.c +++ b/docs/examples/imap-noop.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * IMAP example showing how to perform a noop + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/imap-search.c b/docs/examples/imap-search.c index 0c1d2673..f1261e1e 100644 --- a/docs/examples/imap-search.c +++ b/docs/examples/imap-search.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * IMAP example showing how to search for new e-mails + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/imap-ssl.c b/docs/examples/imap-ssl.c index eec9b0e3..69839adb 100644 --- a/docs/examples/imap-ssl.c +++ b/docs/examples/imap-ssl.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * IMAP example using SSL + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> @@ -42,7 +48,8 @@ int main(void) /* This will fetch message 1 from the user's inbox. Note the use of * imaps:// rather than imap:// to request a SSL based connection. */ - curl_easy_setopt(curl, CURLOPT_URL, "imaps://imap.example.com/INBOX/;UID=1"); + curl_easy_setopt(curl, CURLOPT_URL, + "imaps://imap.example.com/INBOX/;UID=1"); /* If you want to connect to a site who isn't using a certificate that is * signed by one of the certs in the CA bundle you have, you can skip the diff --git a/docs/examples/imap-store.c b/docs/examples/imap-store.c index 8f5e7d5b..8479457b 100644 --- a/docs/examples/imap-store.c +++ b/docs/examples/imap-store.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * IMAP example showing how to modify the properties of an e-mail + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/imap-tls.c b/docs/examples/imap-tls.c index c439864b..7daa0bf3 100644 --- a/docs/examples/imap-tls.c +++ b/docs/examples/imap-tls.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * IMAP example using TLS + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> @@ -41,7 +47,8 @@ int main(void) curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret"); /* This will fetch message 1 from the user's inbox */ - curl_easy_setopt(curl, CURLOPT_URL, "imap://imap.example.com/INBOX/;UID=1"); + curl_easy_setopt(curl, CURLOPT_URL, + "imap://imap.example.com/INBOX/;UID=1"); /* In this example, we'll start with a plain text connection, and upgrade * to Transport Layer Security (TLS) using the STARTTLS command. Be careful @@ -55,12 +62,13 @@ int main(void) * CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST options to 0 (false). * curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); * curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + * * That is, in general, a bad idea. It is still better than sending your - * authentication details in plain text though. - * Instead, you should get the issuer certificate (or the host certificate - * if the certificate is self-signed) and add it to the set of certificates - * that are known to libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See - * docs/SSLCERTS for more information. */ + * authentication details in plain text though. Instead, you should get + * the issuer certificate (or the host certificate if the certificate is + * self-signed) and add it to the set of certificates that are known to + * libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See docs/SSLCERTS + * for more information. */ curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem"); /* Since the traffic will be encrypted, it is very useful to turn on debug diff --git a/docs/examples/makefile.dj b/docs/examples/makefile.dj index c18ef8a7..af761130 100644 --- a/docs/examples/makefile.dj +++ b/docs/examples/makefile.dj @@ -9,7 +9,7 @@ # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms -# are also available at http://curl.haxx.se/docs/copyright.html. +# are also available at https://curl.haxx.se/docs/copyright.html. # # You may opt to use, copy, modify, merge, publish, distribute and/or sell # copies of the Software, and permit persons to whom the Software is @@ -19,10 +19,6 @@ # KIND, either express or implied. # ########################################################################### -# -# Adapted for djgpp / Watt-32 / DOS by -# Gisle Vanem <gvanem@broadpark.no> -# TOPDIR = ../.. diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index b8258975..f8447930 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,7 +19,11 @@ * KIND, either express or implied. * ***************************************************************************/ -/* This is an example application source code using the multi interface. */ +/* <DESC> + * A basic application source code using the multi interface doing two + * transfers in parallel. + * </DESC> + */ #include <stdio.h> #include <string.h> @@ -51,8 +55,8 @@ int main(void) int msgs_left; /* how many messages are left */ /* Allocate one CURL handle per transfer */ - for (i=0; i<HANDLECOUNT; i++) - handles[i] = curl_easy_init(); + for(i=0; i<HANDLECOUNT; i++) + handles[i] = curl_easy_init(); /* set the options (I left out a few, you'll get the point anyway) */ curl_easy_setopt(handles[HTTP_HANDLE], CURLOPT_URL, "http://example.com"); @@ -64,8 +68,8 @@ int main(void) multi_handle = curl_multi_init(); /* add the individual transfers */ - for (i=0; i<HANDLECOUNT; i++) - curl_multi_add_handle(multi_handle, handles[i]); + for(i=0; i<HANDLECOUNT; i++) + curl_multi_add_handle(multi_handle, handles[i]); /* we start some action by calling perform right away */ curl_multi_perform(multi_handle, &still_running); @@ -102,8 +106,7 @@ int main(void) /* get file descriptors from the transfers */ mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); - if(mc != CURLM_OK) - { + if(mc != CURLM_OK) { fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); break; } @@ -142,12 +145,12 @@ int main(void) } while(still_running); /* See how the transfers went */ - while ((msg = curl_multi_info_read(multi_handle, &msgs_left))) { - if (msg->msg == CURLMSG_DONE) { + while((msg = curl_multi_info_read(multi_handle, &msgs_left))) { + if(msg->msg == CURLMSG_DONE) { int idx, found = 0; /* Find out which handle this message is about */ - for (idx=0; idx<HANDLECOUNT; idx++) { + for(idx=0; idx<HANDLECOUNT; idx++) { found = (msg->easy_handle == handles[idx]); if(found) break; @@ -167,8 +170,8 @@ int main(void) curl_multi_cleanup(multi_handle); /* Free the CURL handles */ - for (i=0; i<HANDLECOUNT; i++) - curl_easy_cleanup(handles[i]); + for(i=0; i<HANDLECOUNT; i++) + curl_easy_cleanup(handles[i]); return 0; } diff --git a/docs/examples/multi-debugcallback.c b/docs/examples/multi-debugcallback.c index 5fb86bea..d07cc3bb 100644 --- a/docs/examples/multi-debugcallback.c +++ b/docs/examples/multi-debugcallback.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,7 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ -/* This is an example showing the multi interface and the debug callback. */ +/* <DESC> + * multi interface and debug callback + * </DESC> + */ #include <stdio.h> #include <string.h> @@ -66,14 +69,14 @@ void dump(const char *text, for(c = 0; (c < width) && (i+c < size); c++) { /* check for 0D0A; if found, skip past and start a new line of output */ - if (nohex && (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) { + if(nohex && (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) { i+=(c+2-width); break; } fprintf(stream, "%c", (ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:'.'); /* check again for 0D0A, to avoid an extra \n if it's at width */ - if (nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) { + if(nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) { i+=(c+3-width); break; } @@ -176,8 +179,7 @@ int main(void) /* get file descriptors from the transfers */ mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); - if(mc != CURLM_OK) - { + if(mc != CURLM_OK) { fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); break; } diff --git a/docs/examples/multi-double.c b/docs/examples/multi-double.c index 0d8d0de4..4e50c768 100644 --- a/docs/examples/multi-double.c +++ b/docs/examples/multi-double.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * multi interface code doing two parallel HTTP transfers + * </DESC> + */ #include <stdio.h> #include <string.h> @@ -91,8 +95,7 @@ int main(void) /* get file descriptors from the transfers */ mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); - if(mc != CURLM_OK) - { + if(mc != CURLM_OK) { fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); break; } diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index 5bfdcfd1..5d9abc12 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,8 +19,11 @@ * KIND, either express or implied. * ***************************************************************************/ -/* This is an example application source code using the multi interface - * to do a multipart formpost without "blocking". */ +/* <DESC> + * using the multi interface to do a multipart formpost without blocking + * </DESC> + */ + #include <stdio.h> #include <string.h> #include <sys/time.h> @@ -112,8 +115,7 @@ int main(void) /* get file descriptors from the transfers */ mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); - if(mc != CURLM_OK) - { + if(mc != CURLM_OK) { fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); break; } diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c index a43a9f52..70b6d24b 100644 --- a/docs/examples/multi-single.c +++ b/docs/examples/multi-single.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,7 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ -/* This is a very simple example using the multi interface. */ +/* <DESC> + * using the multi interface to do a single download + * </DESC> + */ #include <stdio.h> #include <string.h> @@ -74,9 +77,8 @@ int main(void) /* wait for activity, timeout or "nothing" */ mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds); - if(mc != CURLM_OK) - { - fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); + if(mc != CURLM_OK) { + fprintf(stderr, "curl_multi_wait() failed, code %d.\n", mc); break; } diff --git a/docs/examples/multi-uv.c b/docs/examples/multi-uv.c index 0c0f8a2b..51526c89 100644 --- a/docs/examples/multi-uv.c +++ b/docs/examples/multi-uv.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -20,6 +20,10 @@ * ***************************************************************************/ +/* <DESC> + * multi_socket API using libuv + * </DESC> + */ /* Example application code using the multi socket interface to download multiple files at once, but instead of using curl_multi_perform and curl_multi_wait, which uses select(), we use libuv. @@ -80,9 +84,9 @@ void add_download(const char *url, int num) FILE *file; CURL *handle; - sprintf(filename, "%d.download", num); + snprintf(filename, 50, "%d.download", num); - file = fopen(filename, "w"); + file = fopen(filename, "wb"); if(!file) { fprintf(stderr, "Error opening %s\n", filename); return; diff --git a/docs/examples/multithread.c b/docs/examples/multithread.c index 831a0746..475e8fcf 100644 --- a/docs/examples/multithread.c +++ b/docs/examples/multithread.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,8 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ -/* A multi-threaded example that uses pthreads extensively to fetch - * X remote files at once */ +/* <DESC> + * A multi-threaded example that uses pthreads to fetch several files at once + * </DESC> + */ #include <stdio.h> #include <pthread.h> @@ -34,11 +36,11 @@ If you intend to use a SSL-based protocol here you MUST setup the OpenSSL callback functions as described here: - http://www.openssl.org/docs/crypto/threads.html#DESCRIPTION + https://www.openssl.org/docs/crypto/threads.html#DESCRIPTION */ const char * const urls[NUMT]= { - "http://curl.haxx.se/", + "https://curl.haxx.se/", "ftp://cool.haxx.se/", "http://www.contactor.se/", "www.haxx.se" diff --git a/docs/examples/opensslthreadlock.c b/docs/examples/opensslthreadlock.c index ad54f08e..eebc42ee 100644 --- a/docs/examples/opensslthreadlock.c +++ b/docs/examples/opensslthreadlock.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,16 +19,17 @@ * KIND, either express or implied. * ***************************************************************************/ -/* Example source code to show one way to set the necessary OpenSSL locking - * callbacks if you want to do multi-threaded transfers with HTTPS/FTPS with - * libcurl built to use OpenSSL. - * +/* <DESC> + * one way to set the necessary OpenSSL locking callbacks if you want to do + * multi-threaded transfers with HTTPS/FTPS with libcurl built to use OpenSSL. + * </DESC> + */ +/* * This is not a complete stand-alone example. * * Author: Jeremy Brown */ - #include <stdio.h> #include <pthread.h> #include <openssl/err.h> @@ -38,22 +39,22 @@ #define MUTEX_CLEANUP(x) pthread_mutex_destroy(&(x)) #define MUTEX_LOCK(x) pthread_mutex_lock(&(x)) #define MUTEX_UNLOCK(x) pthread_mutex_unlock(&(x)) -#define THREAD_ID pthread_self( ) +#define THREAD_ID pthread_self() -void handle_error(const char *file, int lineno, const char *msg){ - fprintf(stderr, "** %s:%d %s\n", file, lineno, msg); - ERR_print_errors_fp(stderr); - /* exit(-1); */ - } +void handle_error(const char *file, int lineno, const char *msg) +{ + fprintf(stderr, "** %s:%d %s\n", file, lineno, msg); + ERR_print_errors_fp(stderr); + /* exit(-1); */ +} /* This array will store all of the mutexes available to OpenSSL. */ static MUTEX_TYPE *mutex_buf= NULL; - static void locking_function(int mode, int n, const char * file, int line) { - if (mode & CRYPTO_LOCK) + if(mode & CRYPTO_LOCK) MUTEX_LOCK(mutex_buf[n]); else MUTEX_UNLOCK(mutex_buf[n]); @@ -68,10 +69,10 @@ int thread_setup(void) { int i; - mutex_buf = malloc(CRYPTO_num_locks( ) * sizeof(MUTEX_TYPE)); - if (!mutex_buf) + mutex_buf = malloc(CRYPTO_num_locks() * sizeof(MUTEX_TYPE)); + if(!mutex_buf) return 0; - for (i = 0; i < CRYPTO_num_locks( ); i++) + for(i = 0; i < CRYPTO_num_locks(); i++) MUTEX_SETUP(mutex_buf[i]); CRYPTO_set_id_callback(id_function); CRYPTO_set_locking_callback(locking_function); @@ -82,11 +83,11 @@ int thread_cleanup(void) { int i; - if (!mutex_buf) + if(!mutex_buf) return 0; CRYPTO_set_id_callback(NULL); CRYPTO_set_locking_callback(NULL); - for (i = 0; i < CRYPTO_num_locks( ); i++) + for(i = 0; i < CRYPTO_num_locks(); i++) MUTEX_CLEANUP(mutex_buf[i]); free(mutex_buf); mutex_buf = NULL; diff --git a/docs/examples/persistant.c b/docs/examples/persistant.c index 0917dfdb..a1e614bd 100644 --- a/docs/examples/persistant.c +++ b/docs/examples/persistant.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * re-using handles to do HTTP persistent connections + * </DESC> + */ #include <stdio.h> #include <unistd.h> #include <curl/curl.h> diff --git a/docs/examples/pop3-dele.c b/docs/examples/pop3-dele.c index fab598f0..14497835 100644 --- a/docs/examples/pop3-dele.c +++ b/docs/examples/pop3-dele.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * POP3 example showing how to delete e-mails + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/pop3-list.c b/docs/examples/pop3-list.c index aebcea6b..b530a044 100644 --- a/docs/examples/pop3-list.c +++ b/docs/examples/pop3-list.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * POP3 example to list the contents of a mailbox + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/pop3-multi.c b/docs/examples/pop3-multi.c index 6df09a26..f932918e 100644 --- a/docs/examples/pop3-multi.c +++ b/docs/examples/pop3-multi.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,7 +19,14 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * POP3 example using the multi interface + * </DESC> + */ + #include <stdio.h> +#include <string.h> #include <curl/curl.h> /* This is a simple example showing how to retrieve mail using libcurl's POP3 @@ -113,8 +120,7 @@ int main(void) /* get file descriptors from the transfers */ mc = curl_multi_fdset(mcurl, &fdread, &fdwrite, &fdexcep, &maxfd); - if(mc != CURLM_OK) - { + if(mc != CURLM_OK) { fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); break; } diff --git a/docs/examples/pop3-noop.c b/docs/examples/pop3-noop.c index 4efe6715..bc162d0c 100644 --- a/docs/examples/pop3-noop.c +++ b/docs/examples/pop3-noop.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * POP3 example showing how to perform a noop + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/pop3-retr.c b/docs/examples/pop3-retr.c index b5113fa9..b36ddb55 100644 --- a/docs/examples/pop3-retr.c +++ b/docs/examples/pop3-retr.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * POP3 example showing how to retrieve e-mails + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/pop3-ssl.c b/docs/examples/pop3-ssl.c index 0bbec8d9..f0d4e269 100644 --- a/docs/examples/pop3-ssl.c +++ b/docs/examples/pop3-ssl.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * POP3 example using SSL + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/pop3-stat.c b/docs/examples/pop3-stat.c index 7b318fc2..46a0a451 100644 --- a/docs/examples/pop3-stat.c +++ b/docs/examples/pop3-stat.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * POP3 example showing how to obtain message statistics + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/pop3-tls.c b/docs/examples/pop3-tls.c index 58278a1e..1a6c447a 100644 --- a/docs/examples/pop3-tls.c +++ b/docs/examples/pop3-tls.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * POP3 example using TLS + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> @@ -55,12 +61,13 @@ int main(void) * CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST options to 0 (false). * curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); * curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + * * That is, in general, a bad idea. It is still better than sending your - * authentication details in plain text though. - * Instead, you should get the issuer certificate (or the host certificate - * if the certificate is self-signed) and add it to the set of certificates - * that are known to libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See - * docs/SSLCERTS for more information. */ + * authentication details in plain text though. Instead, you should get + * the issuer certificate (or the host certificate if the certificate is + * self-signed) and add it to the set of certificates that are known to + * libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See docs/SSLCERTS + * for more information. */ curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem"); /* Since the traffic will be encrypted, it is very useful to turn on debug diff --git a/docs/examples/pop3-top.c b/docs/examples/pop3-top.c index 21cee889..f452b412 100644 --- a/docs/examples/pop3-top.c +++ b/docs/examples/pop3-top.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * POP3 example showing how to retreive only the headers of an e-mail + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/pop3-uidl.c b/docs/examples/pop3-uidl.c index debb1791..f127120e 100644 --- a/docs/examples/pop3-uidl.c +++ b/docs/examples/pop3-uidl.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * POP3 example to list the contents of a mailbox by unique ID + * </DESC> + */ + #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index 3e1cfb06..f4cd50c0 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,8 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ -/* An example source code that issues a HTTP POST and we provide the actual +/* <DESC> + * An example source code that issues a HTTP POST and we provide the actual * data through a read callback. + * </DESC> */ #include <stdio.h> #include <string.h> diff --git a/docs/examples/postinmemory.c b/docs/examples/postinmemory.c index 3afac4b2..9dd4cb63 100644 --- a/docs/examples/postinmemory.c +++ b/docs/examples/postinmemory.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Make a HTTP POST with data from memory and receive response in memory. + * </DESC> + */ #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/docs/examples/postit2.c b/docs/examples/postit2.c index 88ea78c8..67e685f1 100644 --- a/docs/examples/postit2.c +++ b/docs/examples/postit2.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * HTTP Multipart formpost with file upload and two additional parts. + * </DESC> + */ /* Example code that uploads a file name 'foo' to a remote script that accepts * "HTML form based" (as described in RFC1738) uploads using HTTP POST. * @@ -79,7 +83,7 @@ int main(int argc, char *argv[]) if(curl) { /* what URL that receives this POST */ curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/examplepost.cgi"); - if ( (argc == 2) && (!strcmp(argv[1], "noexpectheader")) ) + if((argc == 2) && (!strcmp(argv[1], "noexpectheader"))) /* only disable 100-continue header if explicitly requested */ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); diff --git a/docs/examples/progressfunc.c b/docs/examples/progressfunc.c index b2635bc8..ab34ef98 100644 --- a/docs/examples/progressfunc.c +++ b/docs/examples/progressfunc.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,11 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Use the progress callbacks, old and/or new one depending on available + * libcurl version. + * </DESC> + */ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/resolve.c b/docs/examples/resolve.c index 7b3e5656..15e343f9 100644 --- a/docs/examples/resolve.c +++ b/docs/examples/resolve.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,11 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Use CURLOPT_RESOLVE to feed custom IP addresses for given host name + port + * number combinations. + * </DESC> + */ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/rtsp.c b/docs/examples/rtsp.c index fed343df..63c46e15 100644 --- a/docs/examples/rtsp.c +++ b/docs/examples/rtsp.c @@ -27,6 +27,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ +/* <DESC> + * A basic RTSP transfer + * </DESC> + */ #include <stdio.h> #include <stdlib.h> @@ -42,12 +46,12 @@ static int _getch(void) { struct termios oldt, newt; int ch; - tcgetattr( STDIN_FILENO, &oldt ); + tcgetattr(STDIN_FILENO, &oldt); newt = oldt; - newt.c_lflag &= ~( ICANON | ECHO ); - tcsetattr( STDIN_FILENO, TCSANOW, &newt ); + newt.c_lflag &= ~( ICANON | ECHO); + tcsetattr(STDIN_FILENO, TCSANOW, &newt); ch = getchar(); - tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); + tcsetattr(STDIN_FILENO, TCSANOW, &oldt); return ch; } #endif @@ -58,12 +62,12 @@ static int _getch(void) /* error handling macros */ #define my_curl_easy_setopt(A, B, C) \ - if ((res = curl_easy_setopt((A), (B), (C))) != CURLE_OK) \ + if((res = curl_easy_setopt((A), (B), (C))) != CURLE_OK) \ fprintf(stderr, "curl_easy_setopt(%s, %s, %s) failed: %d\n", \ #A, #B, #C, res); #define my_curl_easy_perform(A) \ - if ((res = curl_easy_perform((A))) != CURLE_OK) \ + if((res = curl_easy_perform((A))) != CURLE_OK) \ fprintf(stderr, "curl_easy_perform(%s) failed: %d\n", #A, res); @@ -83,9 +87,9 @@ static void rtsp_describe(CURL *curl, const char *uri, const char *sdp_filename) { CURLcode res = CURLE_OK; - FILE *sdp_fp = fopen(sdp_filename, "wt"); + FILE *sdp_fp = fopen(sdp_filename, "wb"); printf("\nRTSP: DESCRIBE %s\n", uri); - if (sdp_fp == NULL) { + if(sdp_fp == NULL) { fprintf(stderr, "Could not open '%s' for writing\n", sdp_filename); sdp_fp = stdout; } @@ -96,7 +100,7 @@ static void rtsp_describe(CURL *curl, const char *uri, my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_DESCRIBE); my_curl_easy_perform(curl); my_curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout); - if (sdp_fp != stdout) { + if(sdp_fp != stdout) { fclose(sdp_fp); } } @@ -137,14 +141,15 @@ static void rtsp_teardown(CURL *curl, const char *uri) /* convert url into an sdp filename */ -static void get_sdp_filename(const char *url, char *sdp_filename) +static void get_sdp_filename(const char *url, char *sdp_filename, + size_t namelen) { const char *s = strrchr(url, '/'); strcpy(sdp_filename, "video.sdp"); - if (s != NULL) { + if(s != NULL) { s++; - if (s[0] != '\0') { - sprintf(sdp_filename, "%s.sdp", s); + if(s[0] != '\0') { + snprintf(sdp_filename, namelen, "%s.sdp", s); } } } @@ -156,10 +161,10 @@ static void get_media_control_attribute(const char *sdp_filename, { int max_len = 256; char *s = malloc(max_len); - FILE *sdp_fp = fopen(sdp_filename, "rt"); + FILE *sdp_fp = fopen(sdp_filename, "rb"); control[0] = '\0'; - if (sdp_fp != NULL) { - while (fgets(s, max_len - 2, sdp_fp) != NULL) { + if(sdp_fp != NULL) { + while(fgets(s, max_len - 2, sdp_fp) != NULL) { sscanf(s, " a = control: %s", control); } fclose(sdp_fp); @@ -174,7 +179,8 @@ int main(int argc, char * const argv[]) #if 1 const char *transport = "RTP/AVP;unicast;client_port=1234-1235"; /* UDP */ #else - const char *transport = "RTP/AVP/TCP;unicast;client_port=1234-1235"; /* TCP */ + /* TCP */ + const char *transport = "RTP/AVP/TCP;unicast;client_port=1234-1235"; #endif const char *range = "0.000-"; int rc = EXIT_SUCCESS; @@ -185,50 +191,53 @@ int main(int argc, char * const argv[]) printf(" Requires cURL V7.20 or greater\n\n"); /* check command line */ - if ((argc != 2) && (argc != 3)) { + if((argc != 2) && (argc != 3)) { base_name = strrchr(argv[0], '/'); - if (base_name == NULL) { + if(base_name == NULL) { base_name = strrchr(argv[0], '\\'); } - if (base_name == NULL) { + if(base_name == NULL) { base_name = argv[0]; - } else { + } + else { base_name++; } printf("Usage: %s url [transport]\n", base_name); printf(" url of video server\n"); - printf(" transport (optional) specifier for media stream protocol\n"); + printf(" transport (optional) specifier for media stream" + " protocol\n"); printf(" default transport: %s\n", transport); printf("Example: %s rtsp://192.168.0.2/media/video1\n\n", base_name); rc = EXIT_FAILURE; - } else { + } + else { const char *url = argv[1]; char *uri = malloc(strlen(url) + 32); char *sdp_filename = malloc(strlen(url) + 32); char *control = malloc(strlen(url) + 32); CURLcode res; - get_sdp_filename(url, sdp_filename); - if (argc == 3) { + get_sdp_filename(url, sdp_filename, strlen(url) + 32); + if(argc == 3) { transport = argv[2]; } /* initialize curl */ res = curl_global_init(CURL_GLOBAL_ALL); - if (res == CURLE_OK) { + if(res == CURLE_OK) { curl_version_info_data *data = curl_version_info(CURLVERSION_NOW); CURL *curl; fprintf(stderr, " cURL V%s loaded\n", data->version); /* initialize this curl session */ curl = curl_easy_init(); - if (curl != NULL) { + if(curl != NULL) { my_curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); my_curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L); my_curl_easy_setopt(curl, CURLOPT_HEADERDATA, stdout); my_curl_easy_setopt(curl, CURLOPT_URL, url); /* request server options */ - sprintf(uri, "%s", url); + snprintf(uri, strlen(url) + 32, "%s", url); rtsp_options(curl, uri); /* request session description and write response to sdp file */ @@ -238,11 +247,11 @@ int main(int argc, char * const argv[]) get_media_control_attribute(sdp_filename, control); /* setup media stream */ - sprintf(uri, "%s/%s", url, control); + snprintf(uri, strlen(url) + 32, "%s/%s", url, control); rtsp_setup(curl, uri, transport); /* start playing media stream */ - sprintf(uri, "%s/", url); + snprintf(uri, strlen(url) + 32, "%s/", url); rtsp_play(curl, uri, range); printf("Playing video, press any key to stop ..."); _getch(); @@ -254,11 +263,13 @@ int main(int argc, char * const argv[]) /* cleanup */ curl_easy_cleanup(curl); curl = NULL; - } else { + } + else { fprintf(stderr, "curl_easy_init() failed\n"); } curl_global_cleanup(); - } else { + } + else { fprintf(stderr, "curl_global_init(%s) failed: %d\n", "CURL_GLOBAL_ALL", res); } diff --git a/docs/examples/sampleconv.c b/docs/examples/sampleconv.c index 3db31609..eece6aae 100644 --- a/docs/examples/sampleconv.c +++ b/docs/examples/sampleconv.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,10 +19,13 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * This is a simple example showing how a program on a non-ASCII platform + * would invoke callbacks to do its own codeset conversions instead of + * using the built-in iconv functions in libcurl. + * </DESC> + */ /* - This is a simple example showing how a program on a non-ASCII platform - would invoke callbacks to do its own codeset conversions instead of - using the built-in iconv functions in libcurl. The IBM-1047 EBCDIC codeset is used for this example but the code would be similar for other non-ASCII codesets. @@ -46,10 +49,11 @@ CURLcode my_conv_from_ascii_to_ebcdic(char *buffer, size_t length) int rc; tempptrin = tempptrout = buffer; rc = platform_a2e(&tempptrin, &bytes, &tempptrout, &bytes); - if (rc == PLATFORM_CONV_OK) { - return(CURLE_OK); - } else { - return(CURLE_CONV_FAILED); + if(rc == PLATFORM_CONV_OK) { + return CURLE_OK; + } + else { + return CURLE_CONV_FAILED; } } @@ -60,10 +64,11 @@ CURLcode my_conv_from_ebcdic_to_ascii(char *buffer, size_t length) int rc; tempptrin = tempptrout = buffer; rc = platform_e2a(&tempptrin, &bytes, &tempptrout, &bytes); - if (rc == PLATFORM_CONV_OK) { - return(CURLE_OK); - } else { - return(CURLE_CONV_FAILED); + if(rc == PLATFORM_CONV_OK) { + return CURLE_OK; + } + else { + return CURLE_CONV_FAILED; } } @@ -74,10 +79,11 @@ CURLcode my_conv_from_utf8_to_ebcdic(char *buffer, size_t length) int rc; tempptrin = tempptrout = buffer; rc = platform_u2e(&tempptrin, &bytes, &tempptrout, &bytes); - if (rc == PLATFORM_CONV_OK) { - return(CURLE_OK); - } else { - return(CURLE_CONV_FAILED); + if(rc == PLATFORM_CONV_OK) { + return CURLE_OK; + } + else { + return CURLE_CONV_FAILED; } } diff --git a/docs/examples/sendrecv.c b/docs/examples/sendrecv.c index 88fddf59..41e283cd 100644 --- a/docs/examples/sendrecv.c +++ b/docs/examples/sendrecv.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,7 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ -/* An example of curl_easy_send() and curl_easy_recv() usage. */ +/* <DESC> + * An example of curl_easy_send() and curl_easy_recv() usage. + * </DESC> + */ #include <stdio.h> #include <string.h> @@ -41,12 +44,10 @@ static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms) FD_SET(sockfd, &errfd); /* always check for error */ - if(for_recv) - { + if(for_recv) { FD_SET(sockfd, &infd); } - else - { + else { FD_SET(sockfd, &outfd); } @@ -66,6 +67,14 @@ int main(void) size_t iolen; curl_off_t nread; + /* A general note of caution here: if you're using curl_easy_recv() or + curl_easy_send() to implement HTTP or _any_ other protocol libcurl + supports "natively", you're doing it wrong and you should stop. + + This example uses HTTP only to show how to use this API, it does not + suggest that writing an application doing this is sensible. + */ + curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); @@ -73,8 +82,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); res = curl_easy_perform(curl); - if(CURLE_OK != res) - { + if(CURLE_OK != res) { printf("Error: %s\n", strerror(res)); return 1; } @@ -85,17 +93,15 @@ int main(void) */ res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockextr); - if(CURLE_OK != res) - { + if(CURLE_OK != res) { printf("Error: %s\n", curl_easy_strerror(res)); return 1; } - sockfd = sockextr; + sockfd = (curl_socket_t)sockextr; /* wait for the socket to become ready for sending */ - if(!wait_on_socket(sockfd, 0, 60000L)) - { + if(!wait_on_socket(sockfd, 0, 60000L)) { printf("Error: timeout.\n"); return 1; } @@ -105,16 +111,14 @@ int main(void) * to see if all the request has been sent */ res = curl_easy_send(curl, request, strlen(request), &iolen); - if(CURLE_OK != res) - { + if(CURLE_OK != res) { printf("Error: %s\n", curl_easy_strerror(res)); return 1; } puts("Reading response."); /* read the response */ - for(;;) - { + for(;;) { char buf[1024]; wait_on_socket(sockfd, 1, 60000L); diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index 7402e354..a865d579 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Simple HTTP GET that stores the headers in a separate file + * </DESC> + */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -27,7 +31,7 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) { - int written = fwrite(ptr, size, nmemb, (FILE *)stream); + size_t written = fwrite(ptr, size, nmemb, (FILE *)stream); return written; } diff --git a/docs/examples/sessioninfo.c b/docs/examples/sessioninfo.c index 2641c713..11c87cd1 100644 --- a/docs/examples/sessioninfo.c +++ b/docs/examples/sessioninfo.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Uses the CURLINFO_TLS_SESSION data. + * </DESC> + */ /* Note that this example currently requires cURL to be linked against GnuTLS (and this program must also be linked against -lgnutls). */ diff --git a/docs/examples/sftpget.c b/docs/examples/sftpget.c index 434299dc..1ca7448e 100644 --- a/docs/examples/sftpget.c +++ b/docs/examples/sftpget.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Gets a file using an SFTP URL. + * </DESC> + */ #include <stdio.h> diff --git a/docs/examples/simple.c b/docs/examples/simple.c index 1912ce66..7226f4b9 100644 --- a/docs/examples/simple.c +++ b/docs/examples/simple.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Very simple HTTP GET + * </DESC> + */ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/simplepost.c b/docs/examples/simplepost.c index 8657771f..99df057d 100644 --- a/docs/examples/simplepost.c +++ b/docs/examples/simplepost.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Very simple HTTP POST + * </DESC> + */ #include <stdio.h> #include <string.h> #include <curl/curl.h> diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index aefb79f6..81713ab8 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Shows HTTPS usage with client certs and optional ssl engine use. + * </DESC> + */ #include <stdio.h> #include <curl/curl.h> @@ -43,7 +47,6 @@ int main(void) { - int i; CURL *curl; CURLcode res; FILE *headerfile; @@ -51,6 +54,7 @@ int main(void) static const char *pCertFile = "testcert.pem"; static const char *pCACertFile="cacert.pem"; + static const char *pHeaderFile = "dumpit"; const char *pKeyName; const char *pKeyType; @@ -67,7 +71,7 @@ int main(void) pEngine = NULL; #endif - headerfile = fopen("dumpit", "w"); + headerfile = fopen(pHeaderFile, "wb"); curl_global_init(CURL_GLOBAL_DEFAULT); @@ -77,47 +81,46 @@ int main(void) curl_easy_setopt(curl, CURLOPT_URL, "HTTPS://your.favourite.ssl.site"); curl_easy_setopt(curl, CURLOPT_HEADERDATA, headerfile); - for(i = 0; i < 1; i++) /* single-iteration loop, just to break out from */ - { - if (pEngine) /* use crypto engine */ - { - if (curl_easy_setopt(curl, CURLOPT_SSLENGINE,pEngine) != CURLE_OK) - { /* load the crypto engine */ - fprintf(stderr,"can't set crypto engine\n"); + do { /* dummy loop, just to break out from */ + if(pEngine) { + /* use crypto engine */ + if(curl_easy_setopt(curl, CURLOPT_SSLENGINE, pEngine) != CURLE_OK) { + /* load the crypto engine */ + fprintf(stderr, "can't set crypto engine\n"); break; } - if (curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT,1L) != CURLE_OK) - { /* set the crypto engine as default */ + if(curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1L) != CURLE_OK) { + /* set the crypto engine as default */ /* only needed for the first time you load a engine in a curl object... */ - fprintf(stderr,"can't set crypto engine as default\n"); + fprintf(stderr, "can't set crypto engine as default\n"); break; } } /* cert is stored PEM coded in file... */ /* since PEM is default, we needn't set it for PEM */ - curl_easy_setopt(curl,CURLOPT_SSLCERTTYPE,"PEM"); + curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "PEM"); /* set the cert for client authentication */ - curl_easy_setopt(curl,CURLOPT_SSLCERT,pCertFile); + curl_easy_setopt(curl, CURLOPT_SSLCERT, pCertFile); /* sorry, for engine we must set the passphrase (if the key has one...) */ - if (pPassphrase) - curl_easy_setopt(curl,CURLOPT_KEYPASSWD,pPassphrase); + if(pPassphrase) + curl_easy_setopt(curl, CURLOPT_KEYPASSWD, pPassphrase); /* if we use a key stored in a crypto engine, we must set the key type to "ENG" */ - curl_easy_setopt(curl,CURLOPT_SSLKEYTYPE,pKeyType); + curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, pKeyType); /* set the private key (file or ID in engine) */ - curl_easy_setopt(curl,CURLOPT_SSLKEY,pKeyName); + curl_easy_setopt(curl, CURLOPT_SSLKEY, pKeyName); /* set the file with the certs vaildating the server */ - curl_easy_setopt(curl,CURLOPT_CAINFO,pCACertFile); + curl_easy_setopt(curl, CURLOPT_CAINFO, pCACertFile); /* disconnect if we can't validate server's cert */ - curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,1L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); @@ -127,7 +130,7 @@ int main(void) curl_easy_strerror(res)); /* we are done... */ - } + } while(0); /* always cleanup */ curl_easy_cleanup(curl); } diff --git a/docs/examples/smooth-gtk-thread.c b/docs/examples/smooth-gtk-thread.c index 932f6e39..547cc0f3 100644 --- a/docs/examples/smooth-gtk-thread.c +++ b/docs/examples/smooth-gtk-thread.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,9 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ -/* This is a multi threaded application that uses a progress bar to show +/* <DESC> + * A multi threaded application that uses a progress bar to show * status. It uses Gtk+ to make a smooth pulse. - * + * </DESC> + */ +/* * Written by Jud Bishop after studying the other examples provided with * libcurl. * @@ -71,22 +74,19 @@ void *pull_one_url(void *NaN) /* Stop threads from entering unless j is incremented */ pthread_mutex_lock(&lock); - while ( j < num_urls ) - { + while(j < num_urls) { printf("j = %d\n", j); http = g_strdup_printf("xoap.weather.com/weather/local/%s?cc=*&dayf=5&unit=i\n", urls[j]); - printf( "http %s", http ); + printf("http %s", http); curl = curl_easy_init(); - if(curl) - { + if(curl) { - outfile = fopen(urls[j], "w"); - /* printf("fopen\n"); */ + outfile = fopen(urls[j], "wb"); /* Set the URL and transfer type */ curl_easy_setopt(curl, CURLOPT_URL, http); @@ -216,7 +216,7 @@ int main(int argc, char **argv) g_signal_connect(G_OBJECT (top_window), "delete-event", G_CALLBACK(cb_delete), NULL); - if (!g_thread_create(&create_thread, progress_bar, FALSE, NULL) != 0) + if(!g_thread_create(&create_thread, progress_bar, FALSE, NULL) != 0) g_warning("can't create the thread"); gtk_main(); @@ -225,4 +225,3 @@ int main(int argc, char **argv) return 0; } - diff --git a/docs/examples/smtp-expn.c b/docs/examples/smtp-expn.c index 0322d2fc..fb0ed1d1 100644 --- a/docs/examples/smtp-expn.c +++ b/docs/examples/smtp-expn.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,11 +19,17 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * SMTP example showing how to expand an e-mail mailing list + * </DESC> + */ + #include <stdio.h> #include <string.h> #include <curl/curl.h> -/* This is a simple example showing how to expand an email mailing list. +/* This is a simple example showing how to expand an e-mail mailing list. * * Notes: * diff --git a/docs/examples/smtp-mail.c b/docs/examples/smtp-mail.c index eea90b8a..315bb2cc 100644 --- a/docs/examples/smtp-mail.c +++ b/docs/examples/smtp-mail.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * SMTP example showing how to send e-mails + * </DESC> + */ + #include <stdio.h> #include <string.h> #include <curl/curl.h> @@ -39,7 +45,8 @@ static const char *payload_text[] = { "To: " TO "\r\n", "From: " FROM "(Example User)\r\n", "Cc: " CC "(Another example User)\r\n", - "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>\r\n", + "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@" + "rfcpedant.example.org>\r\n", "Subject: SMTP example message\r\n", "\r\n", /* empty line to divide headers from body, see RFC5322 */ "The body of the message starts here.\r\n", @@ -89,11 +96,12 @@ int main(void) /* This is the URL for your mailserver */ curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com"); - /* Note that this option isn't strictly required, omitting it will result in - * libcurl sending the MAIL FROM command with empty sender data. All + /* Note that this option isn't strictly required, omitting it will result + * 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. + * 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); @@ -122,13 +130,13 @@ int main(void) /* Free the list of recipients */ curl_slist_free_all(recipients); - /* curl won't send the QUIT command until you call cleanup, so you should be - * able to re-use this connection for additional messages (setting + /* curl won't send the QUIT command until you call cleanup, so you should + * be able to re-use this connection for additional messages (setting * CURLOPT_MAIL_FROM and CURLOPT_MAIL_RCPT as required, and calling * curl_easy_perform() again. It may not be a good idea to keep the - * connection open for a very long time though (more than a few minutes may - * result in the server timing out the connection), and you do want to clean - * up in the end. + * connection open for a very long time though (more than a few minutes + * may result in the server timing out the connection), and you do want to + * clean up in the end. */ curl_easy_cleanup(curl); } diff --git a/docs/examples/smtp-multi.c b/docs/examples/smtp-multi.c index 4098c7d1..89e1d941 100644 --- a/docs/examples/smtp-multi.c +++ b/docs/examples/smtp-multi.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * SMTP example using the multi interface + * </DESC> + */ + #include <string.h> #include <curl/curl.h> @@ -40,7 +46,8 @@ static const char *payload_text[] = { "To: " TO "\r\n", "From: " FROM "(Example User)\r\n", "Cc: " CC "(Another example User)\r\n", - "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>\r\n", + "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@" + "rfcpedant.example.org>\r\n", "Subject: SMTP multi example message\r\n", "\r\n", /* empty line to divide headers from body, see RFC5322 */ "The body of the message starts here.\r\n", @@ -180,8 +187,7 @@ int main(void) /* get file descriptors from the transfers */ mc = curl_multi_fdset(mcurl, &fdread, &fdwrite, &fdexcep, &maxfd); - if(mc != CURLM_OK) - { + if(mc != CURLM_OK) { fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); break; } diff --git a/docs/examples/smtp-ssl.c b/docs/examples/smtp-ssl.c index a774403f..f0123408 100644 --- a/docs/examples/smtp-ssl.c +++ b/docs/examples/smtp-ssl.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * SMTP example using SSL + * </DESC> + */ + #include <stdio.h> #include <string.h> #include <curl/curl.h> @@ -40,7 +46,8 @@ static const char *payload_text[] = { "To: " TO "\r\n", "From: " FROM "(Example User)\r\n", "Cc: " CC "(Another example User)\r\n", - "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>\r\n", + "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@" + "rfcpedant.example.org>\r\n", "Subject: SMTP SSL example message\r\n", "\r\n", /* empty line to divide headers from body, see RFC5322 */ "The body of the message starts here.\r\n", @@ -115,11 +122,12 @@ int main(void) curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); #endif - /* Note that this option isn't strictly required, omitting it will result in - * libcurl sending the MAIL FROM command with empty sender data. All + /* Note that this option isn't strictly required, omitting it will result + * 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. + * 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); diff --git a/docs/examples/smtp-tls.c b/docs/examples/smtp-tls.c index 4872dbdf..c863e059 100644 --- a/docs/examples/smtp-tls.c +++ b/docs/examples/smtp-tls.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,12 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * SMTP example using TLS + * </DESC> + */ + #include <stdio.h> #include <string.h> #include <curl/curl.h> @@ -40,7 +46,8 @@ static const char *payload_text[] = { "To: " TO "\r\n", "From: " FROM "(Example User)\r\n", "Cc: " CC "(Another example User)\r\n", - "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>\r\n", + "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@" + "rfcpedant.example.org>\r\n", "Subject: SMTP TLS example message\r\n", "\r\n", /* empty line to divide headers from body, see RFC5322 */ "The body of the message starts here.\r\n", @@ -110,18 +117,19 @@ int main(void) * curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); * curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); * That is, in general, a bad idea. It is still better than sending your - * authentication details in plain text though. - * Instead, you should get the issuer certificate (or the host certificate - * if the certificate is self-signed) and add it to the set of certificates - * that are known to libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See - * docs/SSLCERTS for more information. */ + * authentication details in plain text though. Instead, you should get + * the issuer certificate (or the host certificate if the certificate is + * self-signed) and add it to the set of certificates that are known to + * libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See docs/SSLCERTS + * for more information. */ curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem"); - /* Note that this option isn't strictly required, omitting it will result in - * libcurl sending the MAIL FROM command with empty sender data. All + /* Note that this option isn't strictly required, omitting it will result + * 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. + * 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); diff --git a/docs/examples/smtp-vrfy.c b/docs/examples/smtp-vrfy.c index 4e44cea9..4e0623fb 100644 --- a/docs/examples/smtp-vrfy.c +++ b/docs/examples/smtp-vrfy.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,11 +19,17 @@ * KIND, either express or implied. * ***************************************************************************/ + +/* <DESC> + * SMTP example showing how to verify an e-mail address + * </DESC> + */ + #include <stdio.h> #include <string.h> #include <curl/curl.h> -/* This is a simple example showing how to verify an email address from an +/* This is a simple example showing how to verify an e-mail address from an * SMTP server. * * Notes: diff --git a/docs/examples/synctime.c b/docs/examples/synctime.c index cd7d0731..1c787bb9 100644 --- a/docs/examples/synctime.c +++ b/docs/examples/synctime.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Set your system time from a remote HTTP server's Date: header. + * </DESC> + */ /* This example code only builds as-is on Windows. * * While Unix/Linux user, you do not need this software. @@ -125,7 +129,7 @@ size_t SyncTime_CURL_WriteOutput(void *ptr, size_t size, size_t nmemb, void *stream) { fwrite(ptr, size, nmemb, stream); - return(nmemb*size); + return (nmemb*size); } size_t SyncTime_CURL_WriteHeader(void *ptr, size_t size, size_t nmemb, @@ -134,17 +138,17 @@ size_t SyncTime_CURL_WriteHeader(void *ptr, size_t size, size_t nmemb, int i, RetVal; char TmpStr1[26], TmpStr2[26]; - if (ShowAllHeader == 1) + if(ShowAllHeader == 1) fprintf(stderr, "%s", (char *)(ptr)); - if (strncmp((char *)(ptr), "Date:", 5) == 0) { - if (ShowAllHeader == 0) + if(strncmp((char *)(ptr), "Date:", 5) == 0) { + if(ShowAllHeader == 0) fprintf(stderr, "HTTP Server. %s", (char *)(ptr)); - if (AutoSyncTime == 1) { + if(AutoSyncTime == 1) { *TmpStr1 = 0; *TmpStr2 = 0; - if (strlen((char *)(ptr)) > 50) /* Can prevent buffer overflow to + if(strlen((char *)(ptr)) > 50) /* Can prevent buffer overflow to TmpStr1 & 2? */ AutoSyncTime = 0; else { @@ -152,11 +156,10 @@ size_t SyncTime_CURL_WriteHeader(void *ptr, size_t size, size_t nmemb, TmpStr1, &SYSTime.wDay, TmpStr2, &SYSTime.wYear, &SYSTime.wHour, &SYSTime.wMinute, &SYSTime.wSecond); - if (RetVal == 7) { - + if(RetVal == 7) { SYSTime.wMilliseconds = 500; /* adjust to midpoint, 0.5 sec */ - for (i=0; i<12; i++) { - if (strcmp(MthStr[i], TmpStr2) == 0) { + for(i=0; i<12; i++) { + if(strcmp(MthStr[i], TmpStr2) == 0) { SYSTime.wMonth = i+1; break; } @@ -170,21 +173,21 @@ size_t SyncTime_CURL_WriteHeader(void *ptr, size_t size, size_t nmemb, } } - if (strncmp((char *)(ptr), "X-Cache: HIT", 12) == 0) { + if(strncmp((char *)(ptr), "X-Cache: HIT", 12) == 0) { fprintf(stderr, "ERROR: HTTP Server data is cached." " Server Date is no longer valid.\n"); AutoSyncTime = 0; } - return(nmemb*size); + return (nmemb*size); } void SyncTime_CURL_Init(CURL *curl, char *proxy_port, char *proxy_user_password) { - if (strlen(proxy_port) > 0) + if(strlen(proxy_port) > 0) curl_easy_setopt(curl, CURLOPT_PROXY, proxy_port); - if (strlen(proxy_user_password) > 0) + if(strlen(proxy_user_password) > 0) curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, proxy_user_password); #ifdef SYNCTIME_UA @@ -201,7 +204,7 @@ int SyncTime_CURL_Fetch(CURL *curl, char *URL_Str, char *OutFileName, CURLcode res; outfile = NULL; - if (HttpGetBody == HTTP_COMMAND_HEAD) + if(HttpGetBody == HTTP_COMMAND_HEAD) curl_easy_setopt(curl, CURLOPT_NOBODY, 1L); else { outfile = fopen(OutFileName, "wb"); @@ -210,7 +213,7 @@ int SyncTime_CURL_Fetch(CURL *curl, char *URL_Str, char *OutFileName, curl_easy_setopt(curl, CURLOPT_URL, URL_Str); res = curl_easy_perform(curl); - if (outfile != NULL) + if(outfile != NULL) fclose(outfile); return res; /* (CURLE_OK) */ } @@ -240,7 +243,7 @@ int conf_init(conf_t *conf) int i; *conf->http_proxy = 0; - for (i=0; i<MAX_STRING1; i++) + for(i=0; i<MAX_STRING1; i++) conf->proxy_user[i] = 0; /* Clean up password from memory */ *conf->timeserver = 0; return 1; @@ -268,24 +271,24 @@ int main(int argc, char *argv[]) RetValue = 0; /* Successful Exit */ conf_init(conf); - if (argc > 1) { - while (OptionIndex < argc) { - if (strncmp(argv[OptionIndex], "--server=", 9) == 0) + if(argc > 1) { + while(OptionIndex < argc) { + if(strncmp(argv[OptionIndex], "--server=", 9) == 0) snprintf(conf->timeserver, MAX_STRING, "%s", &argv[OptionIndex][9]); - if (strcmp(argv[OptionIndex], "--showall") == 0) + if(strcmp(argv[OptionIndex], "--showall") == 0) ShowAllHeader = 1; - if (strcmp(argv[OptionIndex], "--synctime") == 0) + if(strcmp(argv[OptionIndex], "--synctime") == 0) AutoSyncTime = 1; - if (strncmp(argv[OptionIndex], "--proxy-user=", 13) == 0) + if(strncmp(argv[OptionIndex], "--proxy-user=", 13) == 0) snprintf(conf->proxy_user, MAX_STRING, "%s", &argv[OptionIndex][13]); - if (strncmp(argv[OptionIndex], "--proxy=", 8) == 0) + if(strncmp(argv[OptionIndex], "--proxy=", 8) == 0) snprintf(conf->http_proxy, MAX_STRING, "%s", &argv[OptionIndex][8]); - if ((strcmp(argv[OptionIndex], "--help") == 0) || + if((strcmp(argv[OptionIndex], "--help") == 0) || (strcmp(argv[OptionIndex], "/?") == 0)) { showUsage(); return 0; @@ -294,13 +297,13 @@ int main(int argc, char *argv[]) } } - if (*conf->timeserver == 0) /* Use default server for time information */ + if(*conf->timeserver == 0) /* Use default server for time information */ snprintf(conf->timeserver, MAX_STRING, "%s", DefaultTimeServer[0]); /* Init CURL before usage */ curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); - if (curl) { + if(curl) { SyncTime_CURL_Init(curl, conf->http_proxy, conf->proxy_user); /* Calculating time diff between GMT and localtime */ @@ -312,7 +315,7 @@ int main(int argc, char *argv[]) tzonediffFloat = difftime(tt_local, tt_gmt); tzonediffWord = (int)(tzonediffFloat/3600.0); - if ((double)(tzonediffWord * 3600) == tzonediffFloat) + if((double)(tzonediffWord * 3600) == tzonediffFloat) snprintf(tzoneBuf, 15, "%+03d'00'", tzonediffWord); else snprintf(tzoneBuf, 15, "%+03d'30'", tzonediffWord); @@ -341,9 +344,9 @@ int main(int argc, char *argv[]) LOCALTime.wMilliseconds); fprintf(stderr, "\nAfter HTTP. Date: %s%s\n", timeBuf, tzoneBuf); - if (AutoSyncTime == 3) { + if(AutoSyncTime == 3) { /* Synchronising computer clock */ - if (!SetSystemTime(&SYSTime)) { /* Set system time */ + if(!SetSystemTime(&SYSTime)) { /* Set system time */ fprintf(stderr, "ERROR: Unable to set system time.\n"); RetValue = 1; } diff --git a/docs/examples/threaded-ssl.c b/docs/examples/threaded-ssl.c index a7e9c2de..5f1d9b92 100644 --- a/docs/examples/threaded-ssl.c +++ b/docs/examples/threaded-ssl.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,14 +19,19 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Show the required mutex callback setups for GnuTLS and OpenSSL when using + * libcurl multi-threaded. + * </DESC> + */ /* A multi-threaded example that uses pthreads and fetches 4 remote files at * once over HTTPS. The lock callbacks and stuff assume OpenSSL or GnuTLS * (libgcrypt) so far. * * OpenSSL docs for this: - * http://www.openssl.org/docs/crypto/threads.html + * https://www.openssl.org/docs/crypto/threads.html * gcrypt docs for this: - * http://gnupg.org/documentation/manuals/gcrypt/Multi_002dThreading.html + * https://gnupg.org/documentation/manuals/gcrypt/Multi_002dThreading.html */ #define USE_OPENSSL /* or USE_GNUTLS accordingly */ @@ -46,7 +51,7 @@ static void lock_callback(int mode, int type, char *file, int line) { (void)file; (void)line; - if (mode & CRYPTO_LOCK) { + if(mode & CRYPTO_LOCK) { pthread_mutex_lock(&(lockarray[type])); } else { @@ -59,7 +64,7 @@ static unsigned long thread_id(void) unsigned long ret; ret=(unsigned long)pthread_self(); - return(ret); + return ret; } static void init_locks(void) @@ -68,8 +73,8 @@ static void init_locks(void) lockarray=(pthread_mutex_t *)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t)); - for (i=0; i<CRYPTO_num_locks(); i++) { - pthread_mutex_init(&(lockarray[i]),NULL); + for(i=0; i<CRYPTO_num_locks(); i++) { + pthread_mutex_init(&(lockarray[i]), NULL); } CRYPTO_set_id_callback((unsigned long (*)())thread_id); @@ -81,7 +86,7 @@ static void kill_locks(void) int i; CRYPTO_set_locking_callback(NULL); - for (i=0; i<CRYPTO_num_locks(); i++) + for(i=0; i<CRYPTO_num_locks(); i++) pthread_mutex_destroy(&(lockarray[i])); OPENSSL_free(lockarray); diff --git a/docs/examples/url2file.c b/docs/examples/url2file.c index adf696c9..39f84d68 100644 --- a/docs/examples/url2file.c +++ b/docs/examples/url2file.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,6 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> + * Download a given URL into a local file named page.out. + * </DESC> + */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -37,7 +41,7 @@ int main(int argc, char *argv[]) static const char *pagefilename = "page.out"; FILE *pagefile; - if(argc < 2 ) { + if(argc < 2) { printf("Usage: %s <URL>\n", argv[0]); return 1; } @@ -61,7 +65,7 @@ int main(int argc, char *argv[]) /* open the file */ pagefile = fopen(pagefilename, "wb"); - if (pagefile) { + if(pagefile) { /* write the page body to this file handle */ curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, pagefile); diff --git a/docs/examples/usercertinmem.c b/docs/examples/usercertinmem.c index dd56c616..47573ebb 100644 --- a/docs/examples/usercertinmem.c +++ b/docs/examples/usercertinmem.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2013, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 2013 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,10 +19,13 @@ * KIND, either express or implied. * ***************************************************************************/ +/* <DESC> /* Example using an in memory PEM user certificate and RSA key to retrieve an * https page. - * Written by Ishan SinghLevett, based on Theo Borm's cacertinmem.c. - * Note that to maintain simplicity this example does not use a CA certificate + * </DESC> + */ +/* Written by Ishan SinghLevett, based on Theo Borm's cacertinmem.c. + * Note that to maintain simplicity this example does not use a CA certificate * for peer verification. However, some form of peer verification * must be used in real circumstances when a secure connection is required. */ @@ -35,8 +38,8 @@ static size_t writefunction(void *ptr, size_t size, size_t nmemb, void *stream) { - fwrite(ptr,size,nmemb,stream); - return(nmemb*size); + fwrite(ptr, size, nmemb, stream); + return (nmemb*size); } static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm) @@ -117,7 +120,7 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm) /* get a BIO */ bio = BIO_new_mem_buf((char *)mypem, -1); - if (bio == NULL) { + if(bio == NULL) { printf("BIO_new_mem_buf failed\n"); } @@ -125,49 +128,49 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm) * structure that SSL can use */ cert = PEM_read_bio_X509(bio, NULL, 0, NULL); - if (cert == NULL) { + if(cert == NULL) { printf("PEM_read_bio_X509 failed...\n"); } /*tell SSL to use the X509 certificate*/ ret = SSL_CTX_use_certificate((SSL_CTX*)sslctx, cert); - if (ret != 1) { + if(ret != 1) { printf("Use certificate failed\n"); } /*create a bio for the RSA key*/ kbio = BIO_new_mem_buf((char *)mykey, -1); - if (kbio == NULL) { + if(kbio == NULL) { printf("BIO_new_mem_buf failed\n"); } /*read the key bio into an RSA object*/ rsa = PEM_read_bio_RSAPrivateKey(kbio, NULL, 0, NULL); - if (rsa == NULL) { + if(rsa == NULL) { printf("Failed to create key bio\n"); } /*tell SSL to use the RSA key from memory*/ ret = SSL_CTX_use_RSAPrivateKey((SSL_CTX*)sslctx, rsa); - if (ret != 1) { + if(ret != 1) { printf("Use Key failed\n"); } /* free resources that have been allocated by openssl functions */ - if (bio) + if(bio) BIO_free(bio); - if (kbio) + if(kbio) BIO_free(kbio); - if (rsa) + if(rsa) RSA_free(rsa); - if (cert) + if(cert) X509_free(cert); /* all set to go */ - return CURLE_OK ; + return CURLE_OK; } int main(void) @@ -177,28 +180,28 @@ int main(void) rv = curl_global_init(CURL_GLOBAL_ALL); ch = curl_easy_init(); - rv = curl_easy_setopt(ch,CURLOPT_VERBOSE, 0L); - rv = curl_easy_setopt(ch,CURLOPT_HEADER, 0L); - rv = curl_easy_setopt(ch,CURLOPT_NOPROGRESS, 1L); - rv = curl_easy_setopt(ch,CURLOPT_NOSIGNAL, 1L); - rv = curl_easy_setopt(ch,CURLOPT_WRITEFUNCTION, *writefunction); - rv = curl_easy_setopt(ch,CURLOPT_WRITEDATA, stdout); - rv = curl_easy_setopt(ch,CURLOPT_HEADERFUNCTION, *writefunction); - rv = curl_easy_setopt(ch,CURLOPT_HEADERDATA, stderr); - rv = curl_easy_setopt(ch,CURLOPT_SSLCERTTYPE,"PEM"); + rv = curl_easy_setopt(ch, CURLOPT_VERBOSE, 0L); + rv = curl_easy_setopt(ch, CURLOPT_HEADER, 0L); + rv = curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1L); + rv = curl_easy_setopt(ch, CURLOPT_NOSIGNAL, 1L); + rv = curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, writefunction); + rv = curl_easy_setopt(ch, CURLOPT_WRITEDATA, stdout); + rv = curl_easy_setopt(ch, CURLOPT_HEADERFUNCTION, writefunction); + rv = curl_easy_setopt(ch, CURLOPT_HEADERDATA, stderr); + rv = curl_easy_setopt(ch, CURLOPT_SSLCERTTYPE, "PEM"); /* both VERIFYPEER and VERIFYHOST are set to 0 in this case because there is no CA certificate*/ - rv = curl_easy_setopt(ch,CURLOPT_SSL_VERIFYPEER, 0L); - rv = curl_easy_setopt(ch,CURLOPT_SSL_VERIFYHOST, 0L); + rv = curl_easy_setopt(ch, CURLOPT_SSL_VERIFYPEER, 0L); + rv = curl_easy_setopt(ch, CURLOPT_SSL_VERIFYHOST, 0L); rv = curl_easy_setopt(ch, CURLOPT_URL, "https://www.example.com/"); rv = curl_easy_setopt(ch, CURLOPT_SSLKEYTYPE, "PEM"); /* first try: retrieve page without user certificate and key -> will fail */ rv = curl_easy_perform(ch); - if (rv==CURLE_OK) { + if(rv==CURLE_OK) { printf("*** transfer succeeded ***\n"); } else { @@ -209,9 +212,9 @@ int main(void) * load the certificate and key by installing a function doing the necessary * "modifications" to the SSL CONTEXT just before link init */ - rv = curl_easy_setopt(ch,CURLOPT_SSL_CTX_FUNCTION, *sslctx_function); + rv = curl_easy_setopt(ch, CURLOPT_SSL_CTX_FUNCTION, *sslctx_function); rv = curl_easy_perform(ch); - if (rv==CURLE_OK) { + if(rv==CURLE_OK) { printf("*** transfer succeeded ***\n"); } else { diff --git a/docs/examples/version-check.pl b/docs/examples/version-check.pl index 92f0808d..074e50d8 100755 --- a/docs/examples/version-check.pl +++ b/docs/examples/version-check.pl @@ -10,7 +10,7 @@ # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms -# are also available at http://curl.haxx.se/docs/copyright.html. +# are also available at https://curl.haxx.se/docs/copyright.html. # # You may opt to use, copy, modify, merge, publish, distribute and/or sell # copies of the Software, and permit persons to whom the Software is diff --git a/docs/examples/xmlstream.c b/docs/examples/xmlstream.c index 81934450..8066828f 100644 --- a/docs/examples/xmlstream.c +++ b/docs/examples/xmlstream.c @@ -5,11 +5,11 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -19,8 +19,11 @@ * KIND, either express or implied. * ***************************************************************************/ -/* Stream-parse a document using the streaming Expat parser. - * Written by David Strauss +/* <DESC> + * Stream-parse a document using the streaming Expat parser. + * </DESC> + */ +/* Written by David Strauss * * Expat => http://www.libexpat.org/ * @@ -48,7 +51,8 @@ struct ParserStruct { struct MemoryStruct characters; }; -static void startElement(void *userData, const XML_Char *name, const XML_Char **atts) +static void startElement(void *userData, const XML_Char *name, + const XML_Char **atts) { struct ParserStruct *state = (struct ParserStruct *) userData; state->tags++; @@ -86,16 +90,18 @@ static void endElement(void *userData, const XML_Char *name) printf("%5lu %10lu %s\n", state->depth, state->characters.size, name); } -static size_t parseStreamCallback(void *contents, size_t length, size_t nmemb, void *userp) +static size_t parseStreamCallback(void *contents, size_t length, size_t nmemb, + void *userp) { XML_Parser parser = (XML_Parser) userp; size_t real_size = length * nmemb; struct ParserStruct *state = (struct ParserStruct *) XML_GetUserData(parser); /* Only parse if we're not already in a failure state. */ - if (state->ok && XML_Parse(parser, contents, real_size, 0) == 0) { + if(state->ok && XML_Parse(parser, contents, real_size, 0) == 0) { int error_code = XML_GetErrorCode(parser); - fprintf(stderr, "Parsing response buffer of length %lu failed with error code %d (%s).\n", + fprintf(stderr, "Parsing response buffer of length %lu failed" + " with error code %d (%s).\n", real_size, error_code, XML_ErrorString(error_code)); state->ok = 0; } @@ -123,7 +129,8 @@ int main(void) /* Initialize a libcurl handle. */ curl_global_init(CURL_GLOBAL_ALL ^ CURL_GLOBAL_SSL); curl_handle = curl_easy_init(); - curl_easy_setopt(curl_handle, CURLOPT_URL, "http://www.w3schools.com/xml/simple.xml"); + curl_easy_setopt(curl_handle, CURLOPT_URL, + "http://www.w3schools.com/xml/simple.xml"); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, parseStreamCallback); curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)parser); @@ -135,9 +142,9 @@ int main(void) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); } - else if (state.ok) { + else if(state.ok) { /* Expat requires one final call to finalize parsing. */ - if (XML_Parse(parser, NULL, 0, 1) == 0) { + if(XML_Parse(parser, NULL, 0, 1) == 0) { int error_code = XML_GetErrorCode(parser); fprintf(stderr, "Finalizing parsing failed with error code %d (%s).\n", error_code, XML_ErrorString(error_code)); |