From 35aa363587f8169f9b1ceec22f5e8f8ebd9da91e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 20 Sep 2000 22:32:08 +0000 Subject: new libcurl example code stuff --- docs/examples/README | 8 ++++++ docs/examples/sepheaders.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++ docs/examples/simple.c | 26 +++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 docs/examples/README create mode 100644 docs/examples/sepheaders.c create mode 100644 docs/examples/simple.c (limited to 'docs/examples') diff --git a/docs/examples/README b/docs/examples/README new file mode 100644 index 000000000..09e1fa855 --- /dev/null +++ b/docs/examples/README @@ -0,0 +1,8 @@ +EXAMPLES + +This directory is for tiny libcurl programming examples. They are meant to +show some simple steps on how you can build your own application to take full +advantage of libcurl. + +If you end up with other small but still useful example sources, please mail +them for submission in future packages and on the web site. diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c new file mode 100644 index 000000000..724e14157 --- /dev/null +++ b/docs/examples/sepheaders.c @@ -0,0 +1,63 @@ +#include +#include +#include + +#include +#include +#include + +size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) +{ + written = fwrite(ptr,size,nmemb,outfile); + return written; +} + +int main(int argc, char **argv) +{ + CURL *curl_handle; + char *headerfilename = "head.out"; + FILE *headerfile; + char *bodyfilename = "body.out"; + FILE *bodyfile; + + /* init the curl session */ + curl_handle = curl_easy_init(); + + /* set URL to get */ + curl_easy_setopt(curl_handle, CURLOPT_URL, "http://curl.haxx.se"); + + /* no progress meter please */ + curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1); + + /* shut up completely */ + curl_easy_setopt(curl_handle, CURLOPT_MUTE, 1); + + /* send all data to this function */ + curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data); + + /* open the files */ + headerfile = fopen(headerfilename,"w"); + if (headerfile == NULL) { + curl_easy_cleanup(curl_handle); + return -1; + } + bodyfile = fopen(bodyfilename,"w"); + if (bodyfile == NULL) { + curl_easy_cleanup(curl_handle); + return -1; + } + + /* we want the headers to this file handle */ + curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER ,headerfile); + + /* get it! */ + curl_easy_perform(curl_handle); + + /* close the header file */ + fclose(headerfile); + + /* cleanup curl stuff */ + curl_easy_cleanup(curl_handle); + + return 0; +} diff --git a/docs/examples/simple.c b/docs/examples/simple.c new file mode 100644 index 000000000..e6138c4e1 --- /dev/null +++ b/docs/examples/simple.c @@ -0,0 +1,26 @@ +#include + +#include +#include +#include + +int main(int argc, char **argv) +{ + CURL *curl; + CURLcode res; + FILE *headerfile; + + headerfile = fopen("dumpit", "w"); + + curl = curl_easy_init(); + if(curl) { + /* what call to write: */ + curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); + curl_easy_setopt(curl, CURLOPT_WRITEHEADER, headerfile); + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} -- cgit v1.2.1 From e7736324b4750e6d1536ea7f6d603c82a361dbdb Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 3 Nov 2000 14:47:07 +0000 Subject: David Odin (aka DindinX) for MandrakeSoft, tiny example with GTK --- docs/examples/curlgtk.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 docs/examples/curlgtk.c (limited to 'docs/examples') diff --git a/docs/examples/curlgtk.c b/docs/examples/curlgtk.c new file mode 100644 index 000000000..48b10e9c7 --- /dev/null +++ b/docs/examples/curlgtk.c @@ -0,0 +1,87 @@ +/* curlgtk.c */ +/* Copyright (c) 2000 David Odin (aka DindinX) for MandrakeSoft */ +/* an attempt to use the curl library in concert with a gtk-threaded application */ + +#include +#include + +#include +#include /* new for v7 */ +#include /* new for v7 */ + +#include + +GtkWidget *Bar; + +size_t my_read_func(void *ptr, size_t size, size_t nmemb, FILE *stream) +{ + return fread(ptr, size, nmemb, stream); +} + +int my_progress_func(GtkWidget *Bar, int t, int d) +{ +/* printf("%d / %d (%g %%)\n", d, t, d*100.0/t);*/ + gdk_threads_enter(); + gtk_progress_set_value(GTK_PROGRESS(Bar), d*100.0/t); + gdk_threads_leave(); + return 0; +} + +void *curl_thread(void *ptr) +{ + CURL *curl; + CURLcode res; + FILE *outfile; + gchar *url = ptr; + + curl = curl_easy_init(); + if(curl) + { + outfile = fopen("/tmp/test.curl", "w"); + + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_FILE, outfile); + curl_easy_setopt(curl, CURLOPT_READFUNCTION, my_read_func); + curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func); + curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, Bar); + + res = curl_easy_perform(curl); + + fclose(outfile); + /* always cleanup */ + curl_easy_cleanup(curl); + } + return NULL; +} + +int main(int argc, char **argv) +{ + GtkWidget *Window, *Frame, *Frame2; + GtkAdjustment *adj; + pthread_t curl_tid; + + /* Init thread */ + g_thread_init(NULL); + + gtk_init(&argc, &argv); + Window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + Frame = gtk_frame_new(NULL); + gtk_frame_set_shadow_type(GTK_FRAME(Frame), GTK_SHADOW_OUT); + gtk_container_add(GTK_CONTAINER(Window), Frame); + Frame2 = gtk_frame_new(NULL); + gtk_frame_set_shadow_type(GTK_FRAME(Frame2), GTK_SHADOW_IN); + gtk_container_add(GTK_CONTAINER(Frame), Frame2); + gtk_container_set_border_width(GTK_CONTAINER(Frame2), 5); + adj = (GtkAdjustment*)gtk_adjustment_new(0, 0, 100, 0, 0, 0); + Bar = gtk_progress_bar_new_with_adjustment(adj); + gtk_container_add(GTK_CONTAINER(Frame2), Bar); + gtk_widget_show_all(Window); + + pthread_create(&curl_tid, NULL, curl_thread, argv[1]); + + gdk_threads_enter(); + gtk_main(); + gdk_threads_leave(); + return 0; +} + -- cgit v1.2.1 From 803005892cf16672a5a235004699db68d5be985a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 8 Jan 2001 14:36:34 +0000 Subject: mostly a dummy --- docs/examples/Makefile.am | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 docs/examples/Makefile.am (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am new file mode 100644 index 000000000..a8cd193ad --- /dev/null +++ b/docs/examples/Makefile.am @@ -0,0 +1,11 @@ +# +# $Id$ +# + +AUTOMAKE_OPTIONS = foreign no-dependencies + +EXTRA_DIST = + README curlgtk.c sepheaders.c simple.c + +all: + @echo "done" -- cgit v1.2.1 From 3c7a80a27533791456cbb8bb7d99eb409375199b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 8 Feb 2001 08:26:54 +0000 Subject: postit.c was added as a HTML form file upload example --- docs/examples/Makefile.am | 2 +- docs/examples/postit.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 docs/examples/postit.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index a8cd193ad..f620440c7 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -5,7 +5,7 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = - README curlgtk.c sepheaders.c simple.c + README curlgtk.c sepheaders.c simple.c postit.c all: @echo "done" diff --git a/docs/examples/postit.c b/docs/examples/postit.c new file mode 100644 index 000000000..710a14967 --- /dev/null +++ b/docs/examples/postit.c @@ -0,0 +1,68 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * 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. + * + * The imaginary form we'll fill in looks like: + * + *
+ * Enter file: + * Enter file name: + * + *
+ * + * This exact source code has not been verified to work. + */ + +#include + +#include +#include +#include + +int main(int argc, char **argv) +{ + CURL *curl; + CURLcode res; + + struct HttpPost *formpost=NULL; + struct HttpPost *lastptr=NULL; + + /* Fill in the file upload field */ + curl_formparse("sendfile=@foo", + &formpost, + &lastptr); + + /* Fill in the filename field */ + curl_formparse("filename=foo", + &formpost, + &lastptr); + + + /* Fill in the submit field too, even if this is rarely needed */ + curl_formparse("submit=send", + &formpost, + &lastptr); + + curl = curl_easy_init(); + if(curl) { + /* what URL that receives this POST */ + curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/examplepost.cgi"); + curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + + /* then cleanup the formpost chain */ + curl_formfree(formpost); + } + return 0; +} -- cgit v1.2.1 From 7de874c4381c6d2fb474b1497f8628d9df150c2c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 19 Feb 2001 13:38:05 +0000 Subject: just a few PHP/curl examples --- docs/examples/getpageinvar.php | 10 ++++++++++ docs/examples/simpleget.php | 13 +++++++++++++ docs/examples/simplepost.php | 12 ++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 docs/examples/getpageinvar.php create mode 100644 docs/examples/simpleget.php create mode 100644 docs/examples/simplepost.php (limited to 'docs/examples') diff --git a/docs/examples/getpageinvar.php b/docs/examples/getpageinvar.php new file mode 100644 index 000000000..c8d5c4987 --- /dev/null +++ b/docs/examples/getpageinvar.php @@ -0,0 +1,10 @@ +# +# The PHP curl module supports the received page to be returned in a variable +# if told. +# +$ch = curl_init(); + +curl_setopt($ch, CURLOPT_URL,"http://www.myurl.com/"); +curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); +$result=curl_exec ($ch); +curl_close ($ch); diff --git a/docs/examples/simpleget.php b/docs/examples/simpleget.php new file mode 100644 index 000000000..17c1757bf --- /dev/null +++ b/docs/examples/simpleget.php @@ -0,0 +1,13 @@ +# +# A very simple example that gets a HTTP page. +# + +$ch = curl_init(); + +curl_setopt ($ch, CURLOPT_URL, "http://www.zend.com/"); +curl_setopt ($ch, CURLOPT_HEADER, 0); + +curl_exec ($ch); + +curl_close ($ch); + diff --git a/docs/examples/simplepost.php b/docs/examples/simplepost.php new file mode 100644 index 000000000..dc4eadf5a --- /dev/null +++ b/docs/examples/simplepost.php @@ -0,0 +1,12 @@ +# +# A very simple PHP example that sends a HTTP POST to a remote site +# + +$ch = curl_init(); + +curl_setopt($ch, CURLOPT_URL,"http://www.mysite.com/tester.phtml"); +curl_setopt($ch, CURLOPT_POST, 1); +curl_setopt($ch, CURLOPT_POSTFIELDS, "postvar1=value1&postvar2=value2&postvar3=value3"); + +curl_exec ($ch); +curl_close ($ch); -- cgit v1.2.1 From 720fa45b562547fa3e04bf0b6dc5fe1ec5bea143 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 19 Feb 2001 13:38:29 +0000 Subject: blurb about different languages and environments added --- docs/examples/README | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/README b/docs/examples/README index 09e1fa855..0258036ac 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -6,3 +6,6 @@ advantage of libcurl. If you end up with other small but still useful example sources, please mail them for submission in future packages and on the web site. + +There are examples for different languages and environments. Browse around to +find those that fit you. -- cgit v1.2.1 From 43da41e73ea600e26916ac45833e06145251087f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 19 Feb 2001 13:39:21 +0000 Subject: Added three tiny PHP examples --- docs/examples/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index f620440c7..b8e9bc6a2 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -5,7 +5,8 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = - README curlgtk.c sepheaders.c simple.c postit.c + README curlgtk.c sepheaders.c simple.c postit.c \ + getpageinvar.php simpleget.php simplepost.php all: @echo "done" -- cgit v1.2.1 From ada9bc2b24ecb73c78e07aed933dc99f1d44ed3c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 20 Feb 2001 13:56:38 +0000 Subject: win32sockets.c is now added with winsock init/cleanup example functions --- docs/examples/Makefile.am | 1 + docs/examples/curlgtk.c | 10 +++++++++- docs/examples/postit.c | 3 +++ docs/examples/sepheaders.c | 13 +++++++++++++ docs/examples/simple.c | 13 +++++++++++++ docs/examples/win32sockets.c | 41 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 docs/examples/win32sockets.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index b8e9bc6a2..35b0a8817 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -6,6 +6,7 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c \ + win32sockets.c \ getpageinvar.php simpleget.php simplepost.php all: diff --git a/docs/examples/curlgtk.c b/docs/examples/curlgtk.c index 48b10e9c7..7c9ce2a1b 100644 --- a/docs/examples/curlgtk.c +++ b/docs/examples/curlgtk.c @@ -1,4 +1,12 @@ -/* curlgtk.c */ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ /* Copyright (c) 2000 David Odin (aka DindinX) for MandrakeSoft */ /* an attempt to use the curl library in concert with a gtk-threaded application */ diff --git a/docs/examples/postit.c b/docs/examples/postit.c index 710a14967..e811aa24a 100644 --- a/docs/examples/postit.c +++ b/docs/examples/postit.c @@ -21,6 +21,9 @@ * This exact source code has not been verified to work. */ +/* to make this work under windows, use the win32-functions from the + win32socket.c file as well */ + #include #include diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index 724e14157..ead557214 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -1,3 +1,16 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +/* to make this work under windows, use the win32-functions from the + win32socket.c file as well */ + #include #include #include diff --git a/docs/examples/simple.c b/docs/examples/simple.c index e6138c4e1..907d5e8e4 100644 --- a/docs/examples/simple.c +++ b/docs/examples/simple.c @@ -1,9 +1,22 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + #include #include #include #include +/* to make this work under windows, use the win32-functions from the + win32socket.c file as well */ + int main(int argc, char **argv) { CURL *curl; diff --git a/docs/examples/win32sockets.c b/docs/examples/win32sockets.c new file mode 100644 index 000000000..f052299d6 --- /dev/null +++ b/docs/examples/win32sockets.c @@ -0,0 +1,41 @@ +/* + * These are example functions doing socket init that Windows + * require. If you don't use windows, you can safely ignore this crap. + */ + +#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) +static void win32_cleanup(void) +{ + WSACleanup(); +} + +static CURLcode win32_init(void) +{ + WORD wVersionRequested; + WSADATA wsaData; + int err; + wVersionRequested = MAKEWORD(1, 1); + + err = WSAStartup(wVersionRequested, &wsaData); + + if (err != 0) + /* Tell the user that we couldn't find a useable */ + /* winsock.dll. */ + return 1; + + /* Confirm that the Windows Sockets DLL supports 1.1.*/ + /* Note that if the DLL supports versions greater */ + /* than 1.1 in addition to 1.1, it will still return */ + /* 1.1 in wVersion since that is the version we */ + /* requested. */ + + if ( LOBYTE( wsaData.wVersion ) != 1 || + HIBYTE( wsaData.wVersion ) != 1 ) { + /* Tell the user that we couldn't find a useable */ + + /* winsock.dll. */ + WSACleanup(); + return 1; + } + return 0; /* 0 is ok */ +} -- cgit v1.2.1 From e2590430c5c42842d1f2c24620f694de41c1af85 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 20 Feb 2001 13:57:50 +0000 Subject: removed the #ifdef --- docs/examples/win32sockets.c | 1 - 1 file changed, 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/win32sockets.c b/docs/examples/win32sockets.c index f052299d6..8dba979d3 100644 --- a/docs/examples/win32sockets.c +++ b/docs/examples/win32sockets.c @@ -3,7 +3,6 @@ * require. If you don't use windows, you can safely ignore this crap. */ -#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) static void win32_cleanup(void) { WSACleanup(); -- cgit v1.2.1 From 9479ac6dda4e2da012d397d427831b80358259a2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 5 Mar 2001 16:56:10 +0000 Subject: Added a persistant connection example --- docs/examples/Makefile.am | 2 +- docs/examples/persistant.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 docs/examples/persistant.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 35b0a8817..176e7b6f2 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -6,7 +6,7 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c \ - win32sockets.c \ + win32sockets.c persistant.c \ getpageinvar.php simpleget.php simplepost.php all: diff --git a/docs/examples/persistant.c b/docs/examples/persistant.c new file mode 100644 index 000000000..7b880dee6 --- /dev/null +++ b/docs/examples/persistant.c @@ -0,0 +1,53 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include +#include + +#include + +/* to make this work under windows, use the win32-functions from the + docs/examples/win32socket.c file as well */ + +/* This example REQUIRES libcurl 7.7 or later */ +#if (LIBCURL_VERSION_NUM < 0x070700) +#error Too old libcurl version, upgrade or stay away. +#endif + +int main(int argc, char **argv) +{ + CURL *curl; + CURLcode res; + +#ifdef MALLOCDEBUG + /* this sends all memory debug messages to a specified logfile */ + curl_memdebug("memdump"); +#endif + + curl = curl_easy_init(); + if(curl) { + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + curl_easy_setopt(curl, CURLOPT_HEADER, 1); + + /* get the first document */ + curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/"); + res = curl_easy_perform(curl); + + /* get another document from the same server using the same + connection */ + curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/docs/"); + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + + return 0; +} -- cgit v1.2.1 From ad4d5fabf88f5d91b38f9ebf2aea08cd2e2105ba Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 16 Mar 2001 13:44:57 +0000 Subject: the PHP examples are moved --- docs/examples/README | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/README b/docs/examples/README index 0258036ac..20d53b3bb 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -7,5 +7,4 @@ advantage of libcurl. If you end up with other small but still useful example sources, please mail them for submission in future packages and on the web site. -There are examples for different languages and environments. Browse around to -find those that fit you. +Try the php/examples/ directory for PHP programming snippets! -- cgit v1.2.1 From 721f9bca84ca51d89a7da823c3b5ac1ff6e86426 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 16 Mar 2001 13:45:42 +0000 Subject: moved to ../../php/examples/ --- docs/examples/getpageinvar.php | 10 ---------- docs/examples/simpleget.php | 13 ------------- docs/examples/simplepost.php | 12 ------------ 3 files changed, 35 deletions(-) delete mode 100644 docs/examples/getpageinvar.php delete mode 100644 docs/examples/simpleget.php delete mode 100644 docs/examples/simplepost.php (limited to 'docs/examples') diff --git a/docs/examples/getpageinvar.php b/docs/examples/getpageinvar.php deleted file mode 100644 index c8d5c4987..000000000 --- a/docs/examples/getpageinvar.php +++ /dev/null @@ -1,10 +0,0 @@ -# -# The PHP curl module supports the received page to be returned in a variable -# if told. -# -$ch = curl_init(); - -curl_setopt($ch, CURLOPT_URL,"http://www.myurl.com/"); -curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); -$result=curl_exec ($ch); -curl_close ($ch); diff --git a/docs/examples/simpleget.php b/docs/examples/simpleget.php deleted file mode 100644 index 17c1757bf..000000000 --- a/docs/examples/simpleget.php +++ /dev/null @@ -1,13 +0,0 @@ -# -# A very simple example that gets a HTTP page. -# - -$ch = curl_init(); - -curl_setopt ($ch, CURLOPT_URL, "http://www.zend.com/"); -curl_setopt ($ch, CURLOPT_HEADER, 0); - -curl_exec ($ch); - -curl_close ($ch); - diff --git a/docs/examples/simplepost.php b/docs/examples/simplepost.php deleted file mode 100644 index dc4eadf5a..000000000 --- a/docs/examples/simplepost.php +++ /dev/null @@ -1,12 +0,0 @@ -# -# A very simple PHP example that sends a HTTP POST to a remote site -# - -$ch = curl_init(); - -curl_setopt($ch, CURLOPT_URL,"http://www.mysite.com/tester.phtml"); -curl_setopt($ch, CURLOPT_POST, 1); -curl_setopt($ch, CURLOPT_POSTFIELDS, "postvar1=value1&postvar2=value2&postvar3=value3"); - -curl_exec ($ch); -curl_close ($ch); -- cgit v1.2.1 From 053bf49bd24db8fe8f4556291100f9b99bb2c4a0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 27 Mar 2001 09:00:18 +0000 Subject: Added ftpget.c just to show that it is exactly as easy to get FTP files --- docs/examples/Makefile.am | 3 +-- docs/examples/ftpget.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 docs/examples/ftpget.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 176e7b6f2..7f7628634 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -6,8 +6,7 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c \ - win32sockets.c persistant.c \ - getpageinvar.php simpleget.php simplepost.php + win32sockets.c persistant.c ftpget.c all: @echo "done" diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c new file mode 100644 index 000000000..bdf854521 --- /dev/null +++ b/docs/examples/ftpget.c @@ -0,0 +1,44 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include + +#include +#include +#include + +/* to make this work under windows, use the win32-functions from the + win32socket.c file as well */ + +int main(int argc, char **argv) +{ + CURL *curl; + CURLcode res; + FILE *ftpfile; + + /* local file name to store the file as */ + ftpfile = fopen("curl.tar.gz", "wb"); /* b is binary for win */ + + curl = curl_easy_init(); + if(curl) { + /* Get curl 7.7 from sunet.se's FTP site: */ + curl_easy_setopt(curl, CURLOPT_URL, + "ftp://ftp.sunet.se/pub/www/utilities/curl/curl-7.7.tar.gz"); + curl_easy_setopt(curl, CURLOPT_FILE, ftpfile); + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + + fclose(ftpfile); /* close the local file */ + + return 0; +} -- cgit v1.2.1 From 0b8b0b7c8699ea9691aea2527912c3af406f5b5c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 27 Mar 2001 09:09:09 +0000 Subject: Added Makefile.example as an example makefile that can build the example source files (if edited slightly) --- docs/examples/Makefile.am | 2 +- docs/examples/Makefile.example | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 docs/examples/Makefile.example (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 7f7628634..46d76eebe 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -6,7 +6,7 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c \ - win32sockets.c persistant.c ftpget.c + win32sockets.c persistant.c ftpget.c Makefile.example all: @echo "done" diff --git a/docs/examples/Makefile.example b/docs/examples/Makefile.example new file mode 100644 index 000000000..f18baa2d6 --- /dev/null +++ b/docs/examples/Makefile.example @@ -0,0 +1,41 @@ +############################################################################# +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ +# \___|\___/|_| \_\_____| +# +# $Id$ +# + +# What to call the final executable +TARGET = example + +# Which object files that the executable consists of +OBJS= ftpget.o + +# What compiler to use +CC = gcc + +# Compiler flags, -g for debug, -c to make an object file +CFLAGS = -c -g + +# This should point to a directory that holds libcurl, if it isn't +# in the system's standard lib dir +# We also set a -L to include the directory where we have the openssl +# libraries +LDFLAGS = -L/home/dast/lib -L/usr/local/ssl/lib + +# We need -lcurl for the curl stuff +# We need -lsocket and -lnsl when on Solaris +# We need -lssl and -lcrypto when using libcurl with SSL support +# We need -ldl for dlopen() if that is in libdl +LIBS = -lcurl -lsocket -lnsl -lssl -lcrypto -dl + +# Link the target with all objects and libraries +$(TARGET) : $(OBJS) + $(CC) $(LDFLAGS) $(LIBS) -o $(TARGET) $(OBJS) + +# Compile the source files into object files +ftpget.o : ftpget.c + $(CC) $(CFLAGS) $< -- cgit v1.2.1 From 45ffb16c2a6b89ed82232c2a26625dfafcaaba5c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 27 Mar 2001 09:10:53 +0000 Subject: Added a line about the new makefile example --- docs/examples/README | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/README b/docs/examples/README index 20d53b3bb..abaee9c0d 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -7,4 +7,8 @@ advantage of libcurl. If you end up with other small but still useful example sources, please mail them for submission in future packages and on the web site. +The Makefile.example is an example makefile that could be used to build these +examples. Just edit the file according to your system and requirements first. + Try the php/examples/ directory for PHP programming snippets! + -- cgit v1.2.1 From b86674174a5f04a4330923d33a6f3892d2709705 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 12 Apr 2001 11:13:28 +0000 Subject: Added text about curl.haxx.se not being a good test target for people's libcurl experiments... --- docs/examples/README | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/README b/docs/examples/README index abaee9c0d..3818a6ccc 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -12,3 +12,7 @@ examples. Just edit the file according to your system and requirements first. Try the php/examples/ directory for PHP programming snippets! + *PLEASE* do not use the curl.haxx.se site as a test target for your libcurl + applications/experiments. Even if the examples in this directory use that + site as an example URL at some places, it doesn't mean that the URLs work or + that we expect you to actually torture our web site with your tests! Thanks. -- cgit v1.2.1 From 73982c65d24720252ee54c24f385949f4dc9b9db Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 3 May 2001 09:10:07 +0000 Subject: fixed the EXTRA_DIST line --- docs/examples/Makefile.am | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 46d76eebe..64b561dc0 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -4,9 +4,8 @@ AUTOMAKE_OPTIONS = foreign no-dependencies -EXTRA_DIST = - README curlgtk.c sepheaders.c simple.c postit.c \ - win32sockets.c persistant.c ftpget.c Makefile.example +EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c \ + win32sockets.c persistant.c ftpget.c Makefile.example all: @echo "done" -- cgit v1.2.1 From 2ffc20dc7cd91e9057c0c5f478e5b3264a474f10 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 4 May 2001 09:35:43 +0000 Subject: example using multiple threads to get URLs --- docs/examples/multithread.c | 70 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 docs/examples/multithread.c (limited to 'docs/examples') diff --git a/docs/examples/multithread.c b/docs/examples/multithread.c new file mode 100644 index 000000000..c3936ef4a --- /dev/null +++ b/docs/examples/multithread.c @@ -0,0 +1,70 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +/* A multi-threaded example that uses pthreads extensively to fetch + * X remote files at once */ + +#include +#include +#include + +/* silly list of test-URLs */ +char *urls[]= { + "http://curl.haxx.se/", + "ftp://cool.haxx.se/", + "http://www.contactor.se/", + "www.haxx.se" +}; + +void *pull_one_url(void *url) +{ + CURL *curl; + + curl = curl_easy_init(); + + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_perform(curl); + + curl_easy_cleanup(curl); + + return NULL; +} + + +/* + int pthread_create(pthread_t *new_thread_ID, + const pthread_attr_t *attr, + void * (*start_func)(void *), void *arg); +*/ + +int main(int argc, char **argv) +{ + pthread_t tid[4]; + int i; + int error; + for(i=0; i< 4; i++) { + error = pthread_create(&tid[i], + NULL, /* default attributes please */ + pull_one_url, + urls[i]); + if(0 != error) + fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error); + else + fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]); + } + + /* now wait for all threads to terminate */ + for(i=0; i< 4; i++) { + error = pthread_join(tid[i], NULL); + fprintf(stderr, "Thread %d terminated\n", i); + } + + return 0; +} -- cgit v1.2.1 From 4127903183bc5f11c09111ccd88df86384bb3795 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 4 May 2001 09:35:55 +0000 Subject: Added multithread.c --- docs/examples/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 64b561dc0..ba52ce268 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -5,7 +5,8 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c \ - win32sockets.c persistant.c ftpget.c Makefile.example + win32sockets.c persistant.c ftpget.c Makefile.example \ + multithread.c all: @echo "done" -- cgit v1.2.1 From e1132ecbe6c73954feac45888f5804a917dfa2ae Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 15 May 2001 12:55:35 +0000 Subject: corrected --- docs/examples/sepheaders.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index ead557214..40110ce95 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -19,9 +19,9 @@ #include #include -size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) +size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) { - written = fwrite(ptr,size,nmemb,outfile); + written = fwrite(ptr, size, nmemb, (FILE *)stream); return written; } -- cgit v1.2.1 From 9e1e31869102027257a494086817aea355673936 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 15 May 2001 12:56:38 +0000 Subject: We need -lpthread for the pthread example --- docs/examples/Makefile.example | 1 + 1 file changed, 1 insertion(+) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.example b/docs/examples/Makefile.example index f18baa2d6..03e7c3f64 100644 --- a/docs/examples/Makefile.example +++ b/docs/examples/Makefile.example @@ -30,6 +30,7 @@ LDFLAGS = -L/home/dast/lib -L/usr/local/ssl/lib # We need -lsocket and -lnsl when on Solaris # We need -lssl and -lcrypto when using libcurl with SSL support # We need -ldl for dlopen() if that is in libdl +# We need -lpthread for the pthread example LIBS = -lcurl -lsocket -lnsl -lssl -lcrypto -dl # Link the target with all objects and libraries -- cgit v1.2.1 From 2457a319481fb5eaccda3a79e8c3f2b8623ab70c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 15 May 2001 13:03:53 +0000 Subject: an example on how you can use the write callback to receive data in a memory chunk --- docs/examples/getinmemory.c | 81 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 docs/examples/getinmemory.c (limited to 'docs/examples') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c new file mode 100644 index 000000000..3304a1dbd --- /dev/null +++ b/docs/examples/getinmemory.c @@ -0,0 +1,81 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * 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. + * + * This exact source code has not been verified to work. + */ + +/* to make this work under windows, use the win32-functions from the + win32socket.c file as well */ + +#include + +#include +#include +#include + +struct MemoryStruct { + char *memory; + size_t size; +}; + +size_t +WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) +{ + register int realsize = size * nmemb; + struct MemoryStruct *mem = (struct MemoryStruct *)data; + + mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1); + if (mem->memory) { + memcpy(&(mem->memory[mem->size]), ptr, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + } + return realsize; +} + +int main(int argc, char **argv) +{ + CURL *curl; + CURLcode res; + + struct MemoryStruct chunk; + + chunk.memory=NULL; /* we expect realloc(NULL, size) to work */ + chunk.size = 0; /* no data at this point */ + + /* init the curl session */ + curl_handle = curl_easy_init(); + + /* specify URL to get */ + curl_easy_setopt(curl_handle, CURLOPT_URL, "http://cool.haxx.se/"); + + /* send all data to this function */ + curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); + + /* we pass our 'chunk' struct to the callback function */ + curl_easy_setopt(curl_handle, CURLOPT_FILE, (void *)&chunk); + + /* get it! */ + curl_easy_perform(curl_handle); + + /* cleanup curl stuff */ + curl_easy_cleanup(curl_handle); + + /* + * Now, our chunk.memory points to a memory block that is chunk.size + * bytes big and contains the remote file. + * + * Do something nice with it! + */ + + return 0; +} -- cgit v1.2.1 From 3ceb2bcbb9cc3e77c6401ece5b05720779f459e9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 15 May 2001 13:04:53 +0000 Subject: this might actually compile too... --- docs/examples/getinmemory.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 3304a1dbd..afd6e3f03 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -44,8 +44,7 @@ WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) int main(int argc, char **argv) { - CURL *curl; - CURLcode res; + CURL *curl_handle; struct MemoryStruct chunk; -- cgit v1.2.1 From 3ab3be1b6e8e35ad6127e00855a050a2bb28b213 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 15 May 2001 13:08:23 +0000 Subject: Added getinmemory.c --- docs/examples/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index ba52ce268..eca6447a1 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -6,7 +6,7 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c \ win32sockets.c persistant.c ftpget.c Makefile.example \ - multithread.c + multithread.c getinmemory.c all: @echo "done" -- cgit v1.2.1 From 9646a8b346b989397c1bc750aebbe52507c89c45 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 29 Jun 2001 11:33:00 +0000 Subject: removed static, removed curl special return type, added include windows.h --- docs/examples/win32sockets.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/win32sockets.c b/docs/examples/win32sockets.c index 8dba979d3..59b31a44d 100644 --- a/docs/examples/win32sockets.c +++ b/docs/examples/win32sockets.c @@ -1,14 +1,17 @@ + /* * These are example functions doing socket init that Windows * require. If you don't use windows, you can safely ignore this crap. */ -static void win32_cleanup(void) +#include + +void win32_cleanup(void) { WSACleanup(); } -static CURLcode win32_init(void) +int win32_init(void) { WORD wVersionRequested; WSADATA wsaData; -- cgit v1.2.1 From f0efa89484b419d2713a28c250685047bd48a159 Mon Sep 17 00:00:00 2001 From: Sterling Hughes Date: Thu, 12 Jul 2001 02:00:24 +0000 Subject: Leftover -- add a note about this in the examples file :) --- docs/examples/win32sockets.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/win32sockets.c b/docs/examples/win32sockets.c index 59b31a44d..5f791c8b5 100644 --- a/docs/examples/win32sockets.c +++ b/docs/examples/win32sockets.c @@ -1,4 +1,10 @@ +/* + * Note: This is only required if you use curl 7.8 or lower, later + * versions provide an option to curl_global_init() that does the + * win32 initialization for you. + */ + /* * These are example functions doing socket init that Windows * require. If you don't use windows, you can safely ignore this crap. -- cgit v1.2.1 From 08655d8d5d0ea980227096366c231693198e61d6 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 21 Aug 2001 13:18:07 +0000 Subject: Georg Huettenegger's patch curl-7.8.1-pre5-patch-20010819 --- docs/examples/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index eca6447a1..909c76100 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -4,7 +4,7 @@ AUTOMAKE_OPTIONS = foreign no-dependencies -EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c \ +EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c postit2.c \ win32sockets.c persistant.c ftpget.c Makefile.example \ multithread.c getinmemory.c -- cgit v1.2.1 From 56e8d073bf26231d84f7ea9e8c5102966dfa4b2c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 23 Aug 2001 08:45:20 +0000 Subject: curl_formadd() using example, the 7.9 style of building rfc1867 form posts --- docs/examples/postit2.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 docs/examples/postit2.c (limited to 'docs/examples') diff --git a/docs/examples/postit2.c b/docs/examples/postit2.c new file mode 100644 index 000000000..9b7cda07e --- /dev/null +++ b/docs/examples/postit2.c @@ -0,0 +1,92 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * 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. + * + * The imaginary form we'll fill in looks like: + * + *
+ * Enter file: + * Enter file name: + * + *
+ * + * This exact source code has not been verified to work. + */ + +/* to make this work under windows, use the win32-functions from the + win32socket.c file as well */ + +#include +#include + +#include +#include +#include + +#if LIBCURL_VERSION_NUM < 0x070900 +#error "curl_formadd() is not introduced until libcurl 7.9 and later" +#endif + +int main(int argc, char *argv[]) +{ + CURL *curl; + CURLcode res; + + struct HttpPost *formpost=NULL; + struct HttpPost *lastptr=NULL; + struct curl_slist *headerlist=NULL; + char buf[] = "Expect:"; + + /* Fill in the file upload field */ + curl_formadd(&formpost, + &lastptr, + CURLFORM_COPYNAME, "sendfile", + CURLFORM_FILE, "postit2.c", + CURLFORM_END); + + /* Fill in the filename field */ + curl_formadd(&formpost, + &lastptr, + CURLFORM_COPYNAME, "filename", + CURLFORM_COPYCONTENTS, "postit2.c", + CURLFORM_END); + + + /* Fill in the submit field too, even if this is rarely needed */ + curl_formadd(&formpost, + &lastptr, + CURLFORM_COPYNAME, "submit", + CURLFORM_COPYCONTENTS, "send", + CURLFORM_END); + + curl = curl_easy_init(); + /* initalize custom header list (stating that Expect: 100-continue is not + wanted */ + headerlist = curl_slist_append(headerlist, buf); + if(curl) { + /* what URL that receives this POST */ + curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/examplepost.cgi"); + 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); + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + + /* then cleanup the formpost chain */ + curl_formfree(formpost); + /* free slist */ + curl_slist_free_all (headerlist); + } + return 0; +} -- cgit v1.2.1 From b6526af442e547cd6e234efef5121d481b1eb103 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 29 Aug 2001 07:12:04 +0000 Subject: added ftpupload.c --- docs/examples/Makefile.am | 2 +- docs/examples/ftpupload.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 docs/examples/ftpupload.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 909c76100..a05b8706c 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -6,7 +6,7 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c postit2.c \ win32sockets.c persistant.c ftpget.c Makefile.example \ - multithread.c getinmemory.c + multithread.c getinmemory.c ftpupload.c all: @echo "done" diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c new file mode 100644 index 000000000..5b430e648 --- /dev/null +++ b/docs/examples/ftpupload.c @@ -0,0 +1,88 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include + +#include + +/* + * 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! + */ + +#define LOCAL_FILE "/tmp/uploadthis.txt" +#define UPLOAD_FILE_AS "while-uploading.txt" +#define REMOTE_URL "ftp://localhost/" UPLOAD_FILE_AS +#define RENAME_FILE_TO "renamed-and-fine.txt" + +int main(int argc, char **argv) +{ + CURL *curl; + CURLcode res; + FILE *ftpfile; + FILE * hd_src ; + int hd ; + struct stat file_info; + + struct curl_slist *headerlist=NULL; + char buf_1 [] = "RNFR " UPLOAD_FILE_AS; + char buf_2 [] = "RNTO " RENAME_FILE_TO; + + /* get the file size of the local file */ + hd = open(LOCAL_FILE, O_RDONLY) ; + fstat(hd, &file_info); + close(hd) ; + + /* get a FILE * of the same file, could also be made with + fdopen() from the previous descriptor, but hey this is just + an example! */ + hd_src = fopen(LOCAL_FILE, "rb"); + + /* In windows, this will init the winsock stuff */ + curl_global_init(CURL_GLOBAL_ALL); + + /* get a curl handle */ + curl = curl_easy_init(); + if(curl) { + /* build a list of commands to pass to libcurl */ + headerlist = curl_slist_append(headerlist, buf_1); + headerlist = curl_slist_append(headerlist, buf_2); + + /* enable uploading */ + curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ; + + /* specify target */ + 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); + + /* now specify which file to upload */ + curl_easy_setopt(curl, CURLOPT_INFILE, hd_src); + + /* and give the size of the upload (optional) */ + curl_easy_setopt(curl, CURLOPT_INFILESIZE, file_info.st_size); + + /* Now run off and do what you've been told! */ + res = curl_easy_perform(curl); + + /* clean up the FTP commands list */ + curl_slist_free_all (headerlist); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + fclose(hd_src); /* close the local file */ + + curl_global_cleanup(); + return 0; +} -- cgit v1.2.1 From d5001a3f0bb81010f3ad7aa5e16f9ab2f340bc07 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 25 Sep 2001 05:55:56 +0000 Subject: Added httpput.c --- docs/examples/Makefile.am | 2 +- docs/examples/httpput.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 docs/examples/httpput.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index a05b8706c..6414e7d1d 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -6,7 +6,7 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c postit2.c \ win32sockets.c persistant.c ftpget.c Makefile.example \ - multithread.c getinmemory.c ftpupload.c + multithread.c getinmemory.c ftpupload.c httpput.c all: @echo "done" diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c new file mode 100644 index 000000000..78275c40a --- /dev/null +++ b/docs/examples/httpput.c @@ -0,0 +1,100 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include +#include +#include + +#include + +/* + * This example shows a HTTP PUT operation. PUTs a file given as a command + * line argument to the URL also given on the command line. + * + * This example also uses its own read callback. + */ + +size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) +{ + size_t retcode; + + /* in real-world cases, this would probably get this data differently + as this fread() stuff is exactly what the library already would do + by default internally */ + retcode = fread(ptr, size, nmemb, stream); + + fprintf(stderr, "*** We read %d bytes from file\n", retcode); + + return retcode; +} + +int main(int argc, char **argv) +{ + CURL *curl; + CURLcode res; + FILE *ftpfile; + FILE * hd_src ; + int hd ; + struct stat file_info; + + char *file; + char *url; + + if(argc < 3) + return 1; + + file= argv[1]; + url = argv[2]; + + /* get the file size of the local file */ + hd = open(file, O_RDONLY) ; + fstat(hd, &file_info); + close(hd) ; + + /* get a FILE * of the same file, could also be made with + fdopen() from the previous descriptor, but hey this is just + an example! */ + hd_src = fopen(file, "rb"); + + /* In windows, this will init the winsock stuff */ + curl_global_init(CURL_GLOBAL_ALL); + + /* get a curl handle */ + curl = curl_easy_init(); + if(curl) { + /* we want to use our own read function */ + curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); + + /* enable uploading */ + curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ; + + /* HTTP PUT please */ + curl_easy_setopt(curl, CURLOPT_PUT, TRUE); + + /* specify target */ + curl_easy_setopt(curl,CURLOPT_URL, url); + + /* now specify which file to upload */ + curl_easy_setopt(curl, CURLOPT_INFILE, hd_src); + + /* and give the size of the upload (optional) */ + curl_easy_setopt(curl, CURLOPT_INFILESIZE, file_info.st_size); + + /* Now run off and do what you've been told! */ + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + fclose(hd_src); /* close the local file */ + + curl_global_cleanup(); + return 0; +} -- cgit v1.2.1 From 226fe8bdf9c9ff8cb5667a058a6a7b58dc80711c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 18 Dec 2001 10:13:41 +0000 Subject: =?UTF-8?q?G=F6tz=20Babin-Ebell's=20contributed=20"simplessl.c"=20?= =?UTF-8?q?example=20source=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/examples/Makefile.am | 3 +- docs/examples/simplessl.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 docs/examples/simplessl.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 6414e7d1d..374fe95d6 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -6,7 +6,8 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c postit2.c \ win32sockets.c persistant.c ftpget.c Makefile.example \ - multithread.c getinmemory.c ftpupload.c httpput.c + multithread.c getinmemory.c ftpupload.c httpput.c \ + simplessl.c all: @echo "done" diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c new file mode 100644 index 000000000..534fac849 --- /dev/null +++ b/docs/examples/simplessl.c @@ -0,0 +1,110 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include + +#include +#include +#include + + +/* some requirements for this to work: + 1. set pCertFile to the file with the client certificate + 2. if the key is passphrase protected, set pPassphrase to the + passphrase you use + 3. if you are using a crypto engine: + 3.1. set a #define USE_ENGINE + 3.2. set pEngine to the name of the crypto engine you use + 3.3. set pKeyName to the key identifier you want to use + 4. if you don't use a crypto engine: + 4.1. set pKeyName to the file name of your client key + 4.2. if the format of the key file is DER, set pKeyType to "DER" + + !! verify of the server certificate is not implemented here !! +*/ + +int main(int argc, char **argv) +{ + CURL *curl; + CURLcode res; + FILE *headerfile; + + const char *pCertFile = "testcert.pem"; + + const char *pKeyName; + const char *pKeyType; + + const char *pEngine; + +#if USE_ENGINE + pKeyName = "rsa_test"; + pKeyType = "ENG"; + pEngine = "chil"; /* for nChiper HSM... */ +#else + pKeyName = "testkey.pem"; + pKeyType = "PEM"; + pEngine = NULL; +#endif + + const char *pPassphrase = NULL; + + headerfile = fopen("dumpit", "w"); + + curl_global_init(CURL_GLOBAL_DEFAULT); + + curl = curl_easy_init(); + if(curl) { + /* what call to write: */ + curl_easy_setopt(curl, CURLOPT_URL, "HTTPS://curl.haxx.se"); + curl_easy_setopt(curl, CURLOPT_WRITEHEADER, headerfile); + + while(1) /* do some ugly short cut... */ + { + 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,1) != 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"); + 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"); + /* set the cert for client authentication */ + 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_SSLKEYPASSWD,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); + /* set the private key (file or ID in engine) */ + curl_easy_setopt(curl,CURLOPT_SSLKEY,pKeyName); + + res = curl_easy_perform(curl); + break; /* we are done... */ + } + /* always cleanup */ + curl_easy_cleanup(curl); + } + + curl_global_cleanup(); + + return 0; +} -- cgit v1.2.1 From aec7358ca47d39d1967c528bc5f3b75f67f6d4be Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 8 Jan 2002 08:25:44 +0000 Subject: 7.9.3 pre-release commit --- docs/examples/ftpgetresp.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 docs/examples/ftpgetresp.c (limited to 'docs/examples') diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c new file mode 100644 index 000000000..eb56e19d2 --- /dev/null +++ b/docs/examples/ftpgetresp.c @@ -0,0 +1,61 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include + +#include +#include +#include + +/* + * Similar to ftpget.c but this also stores the received response-lines + * in a separate file using our own callback! + * + * This functionality was introduced in libcurl 7.9.3. + */ + +size_t +write_response(void *ptr, size_t size, size_t nmemb, void *data) +{ + FILE *writehere = (FILE *)data; + return fwrite(ptr, size, nmemb, writehere); +} + +int main(int argc, char **argv) +{ + CURL *curl; + CURLcode res; + FILE *ftpfile; + FILE *respfile; + + /* local file name to store the file as */ + ftpfile = fopen("ftp-list", "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 */ + + curl = curl_easy_init(); + if(curl) { + /* Get a file listing from sunet */ + curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.sunet.se/"); + curl_easy_setopt(curl, CURLOPT_FILE, ftpfile); + curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_response); + curl_easy_setopt(curl, CURLOPT_WRITEHEADER, respfile); + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + + fclose(ftpfile); /* close the local file */ + fclose(respfile); /* close the response file */ + + return 0; +} -- cgit v1.2.1 From ea9a88a9b81b45a4990189a68cfccbe6841a434b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 8 Jan 2002 08:26:22 +0000 Subject: another example source added --- docs/examples/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 374fe95d6..34a867f24 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -7,7 +7,7 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c postit2.c \ win32sockets.c persistant.c ftpget.c Makefile.example \ multithread.c getinmemory.c ftpupload.c httpput.c \ - simplessl.c + simplessl.c ftpgetresp.c all: @echo "done" -- cgit v1.2.1 From 0b1197936c488950041cc54db9db9af1d82ea0b8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 8 Jan 2002 13:05:44 +0000 Subject: I made the write callback create the file the first time it gets called so that it won't create an empty file if the remote file doesn't exist --- docs/examples/ftpget.c | 61 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 11 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index bdf854521..6d728c6ec 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -14,31 +14,70 @@ #include #include -/* to make this work under windows, use the win32-functions from the - win32socket.c file as well */ +/* + * 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. + */ + +struct FtpFile { + char *filename; + FILE *stream; +}; + +int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) +{ + struct FtpFile *out=(struct FtpFile *)stream; + if(out && !out->stream) { + /* open file for writing */ + out->stream=fopen(out->filename, "wb"); + if(!out->stream) + return -1; /* failure, can't open file to write */ + } + return fwrite(buffer, size, nmemb, out->stream); +} + -int main(int argc, char **argv) +int main(void) { CURL *curl; CURLcode res; - FILE *ftpfile; - - /* local file name to store the file as */ - ftpfile = fopen("curl.tar.gz", "wb"); /* b is binary for win */ + struct FtpFile ftpfile={ + "curl.tar.gz", /* name to store the file as if succesful */ + NULL + }; + curl_global_init(CURL_GLOBAL_DEFAULT); + curl = curl_easy_init(); if(curl) { - /* Get curl 7.7 from sunet.se's FTP site: */ + /* Get curl 7.9.2 from sunet.se's FTP site: */ curl_easy_setopt(curl, CURLOPT_URL, - "ftp://ftp.sunet.se/pub/www/utilities/curl/curl-7.7.tar.gz"); - curl_easy_setopt(curl, CURLOPT_FILE, ftpfile); + "ftp://ftp.sunet.se/pub/www/utilities/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 */ + curl_easy_setopt(curl, CURLOPT_FILE, &ftpfile); + + /* Switch on full protocol/debug output */ + curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE); + res = curl_easy_perform(curl); /* always cleanup */ curl_easy_cleanup(curl); + + if(CURLE_OK != res) { + /* we failed */ + fprintf(stderr, "curl told us %d\n", res); + } } - fclose(ftpfile); /* close the local file */ + if(ftpfile.stream) + fclose(ftpfile.stream); /* close the local file */ + + curl_global_cleanup(); return 0; } -- cgit v1.2.1 From fd1799f3bbd10981bbd470d5623363e6b7a91e2c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 9 Jan 2002 13:22:03 +0000 Subject: Cleaned up this example to make it even simpler. --- docs/examples/simple.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/simple.c b/docs/examples/simple.c index 907d5e8e4..186d493bd 100644 --- a/docs/examples/simple.c +++ b/docs/examples/simple.c @@ -9,27 +9,17 @@ */ #include - #include -#include -#include - -/* to make this work under windows, use the win32-functions from the - win32socket.c file as well */ int main(int argc, char **argv) { CURL *curl; CURLcode res; - FILE *headerfile; - - headerfile = fopen("dumpit", "w"); curl = curl_easy_init(); if(curl) { /* what call to write: */ curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); - curl_easy_setopt(curl, CURLOPT_WRITEHEADER, headerfile); res = curl_easy_perform(curl); /* always cleanup */ -- cgit v1.2.1 From 5bd6d631c62f5e21dbad4ac1af7193235bbb7c63 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 9 Jan 2002 13:22:31 +0000 Subject: cut off argc and argv as well --- docs/examples/simple.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/simple.c b/docs/examples/simple.c index 186d493bd..d591f9607 100644 --- a/docs/examples/simple.c +++ b/docs/examples/simple.c @@ -11,7 +11,7 @@ #include #include -int main(int argc, char **argv) +int main(void) { CURL *curl; CURLcode res; -- cgit v1.2.1 From bec0ebacf10d1e6e4712a41e832f161d858894f1 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 9 Jan 2002 13:23:01 +0000 Subject: bad comment begone --- docs/examples/simple.c | 1 - 1 file changed, 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/simple.c b/docs/examples/simple.c index d591f9607..1b93dd83b 100644 --- a/docs/examples/simple.c +++ b/docs/examples/simple.c @@ -18,7 +18,6 @@ int main(void) curl = curl_easy_init(); if(curl) { - /* what call to write: */ curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); res = curl_easy_perform(curl); -- cgit v1.2.1 From affe334675bf1f58c9d5d492dc6f6cd85524b32f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 10 Jan 2002 09:00:02 +0000 Subject: added http-post.c --- docs/examples/Makefile.am | 2 +- docs/examples/http-post.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 docs/examples/http-post.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 34a867f24..bc3753606 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -7,7 +7,7 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c postit2.c \ win32sockets.c persistant.c ftpget.c Makefile.example \ multithread.c getinmemory.c ftpupload.c httpput.c \ - simplessl.c ftpgetresp.c + simplessl.c ftpgetresp.c http-post.c all: @echo "done" diff --git a/docs/examples/http-post.c b/docs/examples/http-post.c new file mode 100644 index 000000000..1b4154fbf --- /dev/null +++ b/docs/examples/http-post.c @@ -0,0 +1,35 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include +#include + +int main(void) +{ + CURL *curl; + CURLcode res; + + curl = curl_easy_init(); + if(curl) { + /* First set the URL that is about to receive our POST. This URL can + just as well be a https:// URL if that is what should receive the + data. */ + curl_easy_setopt(curl, CURLOPT_URL, "http://postit.example.com/moo.cgi"); + /* Now specify the POST data */ + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=daniel&project=curl"); + + /* Perform the request, res will get the return code */ + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} -- cgit v1.2.1 From e4866563dedda10047c51747232c2d85fa346be2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 13 Jan 2002 11:32:36 +0000 Subject: =?UTF-8?q?G=F6tz=20Babin-Ebell=20updated=20with=20some=20new=207.?= =?UTF-8?q?9.3=20features?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/examples/simplessl.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index 534fac849..285d0cd37 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -37,6 +37,7 @@ int main(int argc, char **argv) FILE *headerfile; const char *pCertFile = "testcert.pem"; + const char *pCACertFile="cacert.pem" const char *pKeyName; const char *pKeyType; @@ -96,6 +97,10 @@ int main(int argc, char **argv) curl_easy_setopt(curl,CURLOPT_SSLKEYTYPE,pKeyType); /* set the private key (file or ID in engine) */ curl_easy_setopt(curl,CURLOPT_SSLKEY,pKeyName); + /* set the file with the certs vaildating the server */ + curl_easy_setopt(curl,CURLOPT_CAINFO,pCACertFile); + /* disconnect if we can't validate server's cert */ + curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,1); res = curl_easy_perform(curl); break; /* we are done... */ -- cgit v1.2.1 From ea811fee5202ee506b22470eae5111e6d99ea1e7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 16 Jan 2002 14:13:54 +0000 Subject: added a somewhat cool single-line command that builds most example sources on unix-like systems --- docs/examples/README | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/README b/docs/examples/README index 3818a6ccc..46f7321fb 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -10,6 +10,10 @@ them for submission in future packages and on the web site. The Makefile.example is an example makefile that could be used to build these examples. Just edit the file according to your system and requirements first. +Most examples should build fine using a command line like this: + + $ gcc `curl-config --cflags` `curl-config --libs` -o example example.c + Try the php/examples/ directory for PHP programming snippets! *PLEASE* do not use the curl.haxx.se site as a test target for your libcurl -- cgit v1.2.1 From 12cdfd282d707a35f4738fe54617ec2c583de0e9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 17 Jan 2002 13:45:19 +0000 Subject: added a comment about this example only works with 7.9.3 and newer libs --- docs/examples/simplessl.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index 285d0cd37..9a53603f4 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -28,6 +28,9 @@ 4.2. if the format of the key file is DER, set pKeyType to "DER" !! verify of the server certificate is not implemented here !! + + **** This example only works with libcurl 7.9.3 and later! **** + */ int main(int argc, char **argv) -- cgit v1.2.1 From a2b19c9a63f7db987a87385042172c2dd4487db8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 25 Jan 2002 10:07:07 +0000 Subject: postit.c is removed, it used the deprecated curl_formparse() and may encourage people to use bad functions --- docs/examples/Makefile.am | 2 +- docs/examples/postit.c | 71 ----------------------------------------------- 2 files changed, 1 insertion(+), 72 deletions(-) delete mode 100644 docs/examples/postit.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index bc3753606..a2a8417b3 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -4,7 +4,7 @@ AUTOMAKE_OPTIONS = foreign no-dependencies -EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit.c postit2.c \ +EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ win32sockets.c persistant.c ftpget.c Makefile.example \ multithread.c getinmemory.c ftpupload.c httpput.c \ simplessl.c ftpgetresp.c http-post.c diff --git a/docs/examples/postit.c b/docs/examples/postit.c deleted file mode 100644 index e811aa24a..000000000 --- a/docs/examples/postit.c +++ /dev/null @@ -1,71 +0,0 @@ -/***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * $Id$ - * - * 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. - * - * The imaginary form we'll fill in looks like: - * - *
- * Enter file: - * Enter file name: - * - *
- * - * This exact source code has not been verified to work. - */ - -/* to make this work under windows, use the win32-functions from the - win32socket.c file as well */ - -#include - -#include -#include -#include - -int main(int argc, char **argv) -{ - CURL *curl; - CURLcode res; - - struct HttpPost *formpost=NULL; - struct HttpPost *lastptr=NULL; - - /* Fill in the file upload field */ - curl_formparse("sendfile=@foo", - &formpost, - &lastptr); - - /* Fill in the filename field */ - curl_formparse("filename=foo", - &formpost, - &lastptr); - - - /* Fill in the submit field too, even if this is rarely needed */ - curl_formparse("submit=send", - &formpost, - &lastptr); - - curl = curl_easy_init(); - if(curl) { - /* what URL that receives this POST */ - curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/examplepost.cgi"); - curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); - res = curl_easy_perform(curl); - - /* always cleanup */ - curl_easy_cleanup(curl); - - /* then cleanup the formpost chain */ - curl_formfree(formpost); - } - return 0; -} -- cgit v1.2.1 From 9fc62a8dd0e940668c8ee6310fa9d4530cda744a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 4 Mar 2002 10:15:44 +0000 Subject: multi interface using examples --- docs/examples/multi-app.c | 92 ++++++++++++++++++++++++++++++++++++++++++++ docs/examples/multi-double.c | 87 +++++++++++++++++++++++++++++++++++++++++ docs/examples/multi-single.c | 80 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 259 insertions(+) create mode 100644 docs/examples/multi-app.c create mode 100644 docs/examples/multi-double.c create mode 100644 docs/examples/multi-single.c (limited to 'docs/examples') diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c new file mode 100644 index 000000000..9ed5bf236 --- /dev/null +++ b/docs/examples/multi-app.c @@ -0,0 +1,92 @@ +/* + * This is an example application source code using the multi interface. + */ + +#include +#include + +/* somewhat unix-specific */ +#include +#include + + +/* To start with, we include the header from the lib directory. This should + later of course be moved to the proper include dir. */ +#include "../lib/multi.h" + +/* + * Download a HTTP file and upload an FTP file simultaneously. + */ +int main(int argc, char **argv) +{ + CURL *http_handle; + CURL *ftp_handle; + CURLM *multi_handle; + + int still_running; /* keep number of running handles */ + + http_handle = curl_easy_init(); + ftp_handle = curl_easy_init(); + + /* set the options (I left out a few, you'll get the point anyway) */ + curl_easy_setopt(http_handle, CURLOPT_URL, "http://website.com"); + + curl_easy_setopt(ftp_handle, CURLOPT_URL, "ftp://ftpsite.com"); + curl_easy_setopt(ftp_handle, CURLOPT_UPLOAD, TRUE); + + /* init a multi stack */ + multi_handle = curl_multi_init(); + + /* add the individual transfers */ + curl_multi_add_handle(multi_handle, http_handle); + curl_multi_add_handle(multi_handle, ftp_handle); + + /* we start some action by calling perform right away */ + while(CURLM_CALL_MULTI_PERFORM == + curl_multi_perform(multi_handle, &still_running)); + + while(still_running) { + struct timeval timeout; + int rc; /* select() return code */ + + fd_set fdread; + fd_set fdwrite; + fd_set fdexcep; + int maxfd; + + 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; + + /* get file descriptors from the transfers */ + curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); + + switch(rc) { + case -1: + /* select error */ + break; + case 0: + /* timeout, do something else */ + break; + default: + /* one or more of curl's file descriptors say there's data to read + or write */ + curl_multi_perform(multi_handle, &still_running); + break; + } + } + + curl_multi_cleanup(multi_handle); + + curl_easy_cleanup(http_handle); + curl_easy_cleanup(ftp_handle); + + + return 0; +} diff --git a/docs/examples/multi-double.c b/docs/examples/multi-double.c new file mode 100644 index 000000000..c850b0fe4 --- /dev/null +++ b/docs/examples/multi-double.c @@ -0,0 +1,87 @@ +/* + * This is a simple example using the multi interface. + */ + +#include +#include + +/* somewhat unix-specific */ +#include +#include + +/* To start with, we include the header from the lib directory. This should + later of course be moved to the proper include dir. */ +#include "../lib/multi.h" + +/* + * Simply download two HTTP files! + */ +int main(int argc, char **argv) +{ + CURL *http_handle; + CURL *http_handle2; + CURLM *multi_handle; + + int still_running; /* keep number of running handles */ + + http_handle = curl_easy_init(); + http_handle2 = curl_easy_init(); + + /* set options */ + curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.haxx.se/"); + + /* set options */ + curl_easy_setopt(http_handle2, CURLOPT_URL, "http://localhost/"); + + /* init a multi stack */ + multi_handle = curl_multi_init(); + + /* add the individual transfers */ + curl_multi_add_handle(multi_handle, http_handle); + curl_multi_add_handle(multi_handle, http_handle2); + + /* we start some action by calling perform right away */ + while(CURLM_CALL_MULTI_PERFORM == + curl_multi_perform(multi_handle, &still_running)); + + while(still_running) { + struct timeval timeout; + int rc; /* select() return code */ + + fd_set fdread; + fd_set fdwrite; + fd_set fdexcep; + int maxfd; + + 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; + + /* get file descriptors from the transfers */ + curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + + 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; + } + } + + curl_multi_cleanup(multi_handle); + + curl_easy_cleanup(http_handle); + curl_easy_cleanup(http_handle2); + + return 0; +} diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c new file mode 100644 index 000000000..d17e03396 --- /dev/null +++ b/docs/examples/multi-single.c @@ -0,0 +1,80 @@ +/* + * This is a very simple example using the multi interface. + */ + +#include +#include + +/* somewhat unix-specific */ +#include +#include + +/* To start with, we include the header from the lib directory. This should + later of course be moved to the proper include dir. */ +#include "../lib/multi.h" + +/* + * Simply download a HTTP file. + */ +int main(int argc, char **argv) +{ + CURL *http_handle; + CURLM *multi_handle; + + int still_running; /* keep number of running handles */ + + http_handle = curl_easy_init(); + + /* set the options (I left out a few, you'll get the point anyway) */ + curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.haxx.se/"); + + /* init a multi stack */ + multi_handle = curl_multi_init(); + + /* add the individual transfers */ + curl_multi_add_handle(multi_handle, http_handle); + + /* we start some action by calling perform right away */ + while(CURLM_CALL_MULTI_PERFORM == + curl_multi_perform(multi_handle, &still_running)); + + while(still_running) { + struct timeval timeout; + int rc; /* select() return code */ + + fd_set fdread; + fd_set fdwrite; + fd_set fdexcep; + int maxfd; + + 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; + + /* get file descriptors from the transfers */ + curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + + 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; + } + } + + curl_multi_cleanup(multi_handle); + + curl_easy_cleanup(http_handle); + + return 0; +} -- cgit v1.2.1 From 6417fa95cfb856ca82c15ab1dea41f7388ea4cc7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 11 Mar 2002 15:00:57 +0000 Subject: corrected the use of the progress function --- docs/examples/curlgtk.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/curlgtk.c b/docs/examples/curlgtk.c index 7c9ce2a1b..bba1fe1c9 100644 --- a/docs/examples/curlgtk.c +++ b/docs/examples/curlgtk.c @@ -26,7 +26,11 @@ size_t my_read_func(void *ptr, size_t size, size_t nmemb, FILE *stream) return fread(ptr, size, nmemb, stream); } -int my_progress_func(GtkWidget *Bar, int t, int d) +int my_progress_func(GtkWidget *Bar, + double t, /* dltotal */ + double d, /* dlnow */ + double ultotal, + double ulnow) { /* printf("%d / %d (%g %%)\n", d, t, d*100.0/t);*/ gdk_threads_enter(); @@ -50,6 +54,7 @@ void *curl_thread(void *ptr) curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_FILE, outfile); curl_easy_setopt(curl, CURLOPT_READFUNCTION, my_read_func); + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func); curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, Bar); -- cgit v1.2.1 From d242214e18bee2c300c1888d5f8f80313fd60b11 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 14 Mar 2002 14:53:00 +0000 Subject: new example for libcurl 7.9.6 or later --- docs/examples/Makefile.am | 2 +- docs/examples/post-callback.c | 89 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 docs/examples/post-callback.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index a2a8417b3..67b8d41c3 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -7,7 +7,7 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ win32sockets.c persistant.c ftpget.c Makefile.example \ multithread.c getinmemory.c ftpupload.c httpput.c \ - simplessl.c ftpgetresp.c http-post.c + simplessl.c ftpgetresp.c http-post.c post-callback.c all: @echo "done" diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c new file mode 100644 index 000000000..d4664a575 --- /dev/null +++ b/docs/examples/post-callback.c @@ -0,0 +1,89 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * An example source code that issues a HTTP POST and we provide the actual + * data through a read callback. + * + * Please be aware of the fact that the size of the posted data MUST be + * specified before the transfer is being made (with CURLOPT_POSTFIELDSIZE). + * This requirement will change when libcurl starts supporting chunked-encoded + * sends. + * + * This example requires libcurl 7.9.6 or later. + */ +#include +#include +#include + +#if LIBCURL_VERSION_NUM < 0x070906 +#error this example source requires libcurl 7.9.6 or newer +#endif + +char data[]="this is what we post to the silly web server"; + +struct WriteThis { + char *readptr; + int sizeleft; +}; + +size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp) +{ + struct WriteThis *pooh = (struct WriteThis *)userp; + + if(size*nmemb < 1) + return 0; + + if(pooh->sizeleft) { + *(char *)ptr = pooh->readptr[0]; /* copy one single byte */ + pooh->readptr++; /* advance pointer */ + pooh->sizeleft--; /* less data left */ + return 1; /* we return 1 byte at a time! */ + } + + return -1; /* no more data left to deliver */ +} + +int main(void) +{ + CURL *curl; + CURLcode res; + + struct WriteThis pooh; + + pooh.readptr = data; + pooh.sizeleft = strlen(data); + + curl = curl_easy_init(); + if(curl) { + /* First set the URL that is about to receive our POST. */ + curl_easy_setopt(curl, CURLOPT_URL, + "http://receivingsite.com.pooh/index.cgi"); + /* Now specify we want to POST data */ + curl_easy_setopt(curl, CURLOPT_POST, TRUE); + + /* Set the expected POST size */ + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, pooh.sizeleft); + + /* we want to use our own read function */ + curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); + + /* pointer to pass to our read function */ + curl_easy_setopt(curl, CURLOPT_INFILE, &pooh); + + /* get verbose debug output please */ + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + + /* Perform the request, res will get the return code */ + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} -- cgit v1.2.1 From 28939dd45cf0f21c039af961120ee25f2bd391f9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 19 Mar 2002 14:00:47 +0000 Subject: fixed include and added header --- docs/examples/multi-app.c | 16 +++++++++++----- docs/examples/multi-double.c | 17 ++++++++++++----- docs/examples/multi-single.c | 15 +++++++++++---- 3 files changed, 34 insertions(+), 14 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index 9ed5bf236..13a221325 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -1,4 +1,12 @@ -/* +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * * This is an example application source code using the multi interface. */ @@ -9,10 +17,8 @@ #include #include - -/* To start with, we include the header from the lib directory. This should - later of course be moved to the proper include dir. */ -#include "../lib/multi.h" +/* curl stuff */ +#include /* * Download a HTTP file and upload an FTP file simultaneously. diff --git a/docs/examples/multi-double.c b/docs/examples/multi-double.c index c850b0fe4..2b92d55f5 100644 --- a/docs/examples/multi-double.c +++ b/docs/examples/multi-double.c @@ -1,5 +1,13 @@ -/* - * This is a simple example using the multi interface. +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * This is a very simple example using the multi interface. */ #include @@ -9,9 +17,8 @@ #include #include -/* To start with, we include the header from the lib directory. This should - later of course be moved to the proper include dir. */ -#include "../lib/multi.h" +/* curl stuff */ +#include /* * Simply download two HTTP files! diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c index d17e03396..562886a10 100644 --- a/docs/examples/multi-single.c +++ b/docs/examples/multi-single.c @@ -1,4 +1,12 @@ -/* +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * * This is a very simple example using the multi interface. */ @@ -9,9 +17,8 @@ #include #include -/* To start with, we include the header from the lib directory. This should - later of course be moved to the proper include dir. */ -#include "../lib/multi.h" +/* curl stuff */ +#include /* * Simply download a HTTP file. -- cgit v1.2.1 From c560327f2627e7bec0512b4fdbc1c5903c6954a8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 19 Mar 2002 14:01:34 +0000 Subject: Added the three multi interface source code examples to the distrib --- docs/examples/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 67b8d41c3..c6dcdf215 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -7,7 +7,8 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ win32sockets.c persistant.c ftpget.c Makefile.example \ multithread.c getinmemory.c ftpupload.c httpput.c \ - simplessl.c ftpgetresp.c http-post.c post-callback.c + simplessl.c ftpgetresp.c http-post.c post-callback.c \ + multi-app.c multi-double.c multi-single.c all: @echo "done" -- cgit v1.2.1 From 3bbf694d5a40a26a9eb8c261498048182508a7ca Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 6 May 2002 13:38:28 +0000 Subject: Added multi-post.c, based on the source file posted by Gustaf Hui --- docs/examples/Makefile.am | 2 +- docs/examples/multi-post.c | 126 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 docs/examples/multi-post.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index c6dcdf215..13634302e 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -8,7 +8,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ win32sockets.c persistant.c ftpget.c Makefile.example \ multithread.c getinmemory.c ftpupload.c httpput.c \ simplessl.c ftpgetresp.c http-post.c post-callback.c \ - multi-app.c multi-double.c multi-single.c + multi-app.c multi-double.c multi-single.c multi-post.c all: @echo "done" diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c new file mode 100644 index 000000000..b5a436449 --- /dev/null +++ b/docs/examples/multi-post.c @@ -0,0 +1,126 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * This is an example application source code using the multi interface + * to do a multipart formpost without "blocking". + */ +#include +#include +#include + +#include + +int main(int argc, char *argv[]) +{ + CURL *curl; + CURLcode res; + + CURLM *multi_handle; + int still_running; + + struct HttpPost *formpost=NULL; + struct HttpPost *lastptr=NULL; + struct curl_slist *headerlist=NULL; + char buf[] = "Expect:"; + + /* Fill in the file upload field */ + curl_formadd(&formpost, + &lastptr, + CURLFORM_COPYNAME, "sendfile", + CURLFORM_FILE, "postit2.c", + CURLFORM_END); + + /* Fill in the filename field */ + curl_formadd(&formpost, + &lastptr, + CURLFORM_COPYNAME, "filename", + CURLFORM_COPYCONTENTS, "postit2.c", + CURLFORM_END); + + + /* Fill in the submit field too, even if this is rarely needed */ + curl_formadd(&formpost, + &lastptr, + CURLFORM_COPYNAME, "submit", + CURLFORM_COPYCONTENTS, "send", + CURLFORM_END); + + curl = curl_easy_init(); + multi_handle = curl_multi_init(); + + /* initalize custom header list (stating that Expect: 100-continue is not + wanted */ + headerlist = curl_slist_append(headerlist, buf); + if(curl && multi_handle) { + int perform=0; + + /* what URL that receives this POST */ + curl_easy_setopt(curl, CURLOPT_URL, + "http://www.fillinyoururl.com/upload.cgi"); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); + curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); + + curl_multi_add_handle(multi_handle, curl); + + while(CURLM_CALL_MULTI_PERFORM == + curl_multi_perform(multi_handle, &still_running)); + + while(still_running) { + struct timeval timeout; + int rc; /* select() return code */ + + fd_set fdread; + fd_set fdwrite; + fd_set fdexcep; + int maxfd; + + 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; + + /* get file descriptors from the transfers */ + curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); + + switch(rc) { + case -1: + /* select error */ + break; + case 0: + printf("timeout!\n"); + default: + /* timeout or readable/writable sockets */ + printf("perform!\n"); + while(CURLM_CALL_MULTI_PERFORM == + curl_multi_perform(multi_handle, &still_running)); + printf("running: %d!\n", still_running); + break; + } + } + + curl_multi_cleanup(multi_handle); + + /* always cleanup */ + curl_easy_cleanup(curl); + + /* then cleanup the formpost chain */ + curl_formfree(formpost); + + /* free slist */ + curl_slist_free_all (headerlist); + } + return 0; +} -- cgit v1.2.1 From 1913b4eeed8fde06b544d883c3b599c71ca47f5f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 13 May 2002 07:28:10 +0000 Subject: fopen.c added, a fopen() style emulation for URL reading --- docs/examples/Makefile.am | 11 +-- docs/examples/fopen.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 228 insertions(+), 5 deletions(-) create mode 100644 docs/examples/fopen.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 13634302e..c0c82f3b5 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -4,11 +4,12 @@ AUTOMAKE_OPTIONS = foreign no-dependencies -EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ - win32sockets.c persistant.c ftpget.c Makefile.example \ - multithread.c getinmemory.c ftpupload.c httpput.c \ - simplessl.c ftpgetresp.c http-post.c post-callback.c \ - multi-app.c multi-double.c multi-single.c multi-post.c +EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ + win32sockets.c persistant.c ftpget.c Makefile.example \ + multithread.c getinmemory.c ftpupload.c httpput.c \ + simplessl.c ftpgetresp.c http-post.c post-callback.c \ + multi-app.c multi-double.c multi-single.c multi-post.c \ + fopen.c all: @echo "done" diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c new file mode 100644 index 000000000..a60d10334 --- /dev/null +++ b/docs/examples/fopen.c @@ -0,0 +1,222 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * This example source code introduces an fopen()/fread()/fclose() emulation + * for URL reads. Using an approach similar to this, you could replace your + * program's fopen() with this url_fopen() and fread() with url_fread() and + * it should be possible to read remote streams instead of (only) local files. + * + * See the main() function at the bottom that shows a tiny app in action. + * + * This source code is a proof of concept. It will need further attention to + * become production-use useful and solid. + * + * This example requires libcurl 7.9.7 or later. + */ +#include +#include +#include + +#include +#include +#include + +struct data { + int type; + union { + CURL *curl; + FILE *file; + } handle; + + /* TODO: We should perhaps document the biggest possible buffer chunk we can + get from libcurl in one single callback... */ + char buffer[CURL_MAX_WRITE_SIZE]; + + char *readptr; /* read from here */ + int bytes; /* bytes available from read pointer */ + + CURLMcode m; /* stored from a previous url_fread() */ +}; + +typedef struct data URL_FILE; + +/* we use a global one for convenience */ +CURLM *multi_handle; + +static +size_t write_callback(char *buffer, + size_t size, + size_t nitems, + void *userp) +{ + URL_FILE *url = (URL_FILE *)userp; + size *= nitems; + + memcpy(url->readptr, buffer, size); + url->readptr += size; + url->bytes += size; + + return size; +} + +URL_FILE *url_fopen(char *url, char *operation) +{ + /* this code could check for URLs or types in the 'url' and + basicly use the real fopen() for standard files */ + + URL_FILE *file; + int still_running; + + file = (URL_FILE *)malloc(sizeof(URL_FILE)); + if(!file) + return NULL; + + memset(file, 0, sizeof(URL_FILE)); + + file->type = 1; /* marked as URL, use 0 for plain file */ + file->handle.curl = curl_easy_init(); + + curl_easy_setopt(file->handle.curl, CURLOPT_URL, url); + curl_easy_setopt(file->handle.curl, CURLOPT_FILE, file); + curl_easy_setopt(file->handle.curl, CURLOPT_VERBOSE, FALSE); + curl_easy_setopt(file->handle.curl, CURLOPT_WRITEFUNCTION, write_callback); + + if(!multi_handle) + multi_handle = curl_multi_init(); + + curl_multi_add_handle(multi_handle, file->handle.curl); + + while(CURLM_CALL_MULTI_PERFORM == + curl_multi_perform(multi_handle, &still_running)); + + /* if still_running would be 0 now, we should return NULL */ + + return file; +} + +void url_fclose(URL_FILE *file) +{ + /* make sure the easy handle is not in the multi handle anymore */ + curl_multi_remove_handle(multi_handle, file->handle.curl); + + /* cleanup */ + curl_easy_cleanup(file->handle.curl); +} + + + +size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) +{ + fd_set fdread; + fd_set fdwrite; + fd_set fdexcep; + int maxfd; + struct timeval timeout; + int rc; + int still_running = 0; + + if(!file->bytes) { /* no data available at this point */ + + file->readptr = file->buffer; /* reset read pointer */ + + if(CURLM_CALL_MULTI_PERFORM == file->m) { + while(CURLM_CALL_MULTI_PERFORM == + curl_multi_perform(multi_handle, &still_running)) { + if(file->bytes) { + printf("(fread) WOAH! THis happened!\n"); + break; + } + } + if(!still_running) { + printf("NO MORE RUNNING AROUND!\n"); + return 0; + } + } + + FD_ZERO(&fdread); + FD_ZERO(&fdwrite); + FD_ZERO(&fdexcep); + + /* set a suitable timeout to fail on */ + timeout.tv_sec = 500; /* 5 minutes */ + timeout.tv_usec = 0; + + /* get file descriptors from the transfers */ + curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); + + switch(rc) { + case -1: + /* select error */ + break; + case 0: + break; + default: + /* timeout or readable/writable sockets */ + do { + file->m = curl_multi_perform(multi_handle, &still_running); + + if(file->bytes) + /* we have received data, return that now */ + break; + + } while(CURLM_CALL_MULTI_PERFORM == file->m); + + + if(!still_running) + printf("NO MORE RUNNING AROUND!\n"); + + break; + } + } + else + printf("(fread) Skip network read\n"); + + if(file->bytes) { + /* data already available, return that */ + int want = size * nmemb; + + if(file->bytes < want) + want = file->bytes; + + memcpy(ptr, file->readptr, want); + file->readptr += want; + file->bytes -= want; + + printf("(fread) return %d bytes\n", want); + + return want; + } + return 0; /* no data available to return */ +} + + +int main(int argc, char *argv[]) +{ + URL_FILE *handle; + int nread; + char buffer[256]; + + handle = url_fopen("http://www.haxx.se", "r"); + + if(!handle) { + printf("couldn't url_fopen()\n"); + } + + do { + nread = url_fread(buffer, sizeof(buffer), 1, handle); + + printf("We got: %d bytes\n", nread); + } while(nread); + + url_fclose(handle); + + return 0; +} -- cgit v1.2.1 From 5215f6f654abce135142481f2220d7cc7e5a5464 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 13 May 2002 07:29:22 +0000 Subject: we don't need win32sockets.c anymore, we support this internally --- docs/examples/Makefile.am | 2 +- docs/examples/win32sockets.c | 49 -------------------------------------------- 2 files changed, 1 insertion(+), 50 deletions(-) delete mode 100644 docs/examples/win32sockets.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index c0c82f3b5..78e1baef8 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -5,7 +5,7 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ - win32sockets.c persistant.c ftpget.c Makefile.example \ + persistant.c ftpget.c Makefile.example \ multithread.c getinmemory.c ftpupload.c httpput.c \ simplessl.c ftpgetresp.c http-post.c post-callback.c \ multi-app.c multi-double.c multi-single.c multi-post.c \ diff --git a/docs/examples/win32sockets.c b/docs/examples/win32sockets.c deleted file mode 100644 index 5f791c8b5..000000000 --- a/docs/examples/win32sockets.c +++ /dev/null @@ -1,49 +0,0 @@ - -/* - * Note: This is only required if you use curl 7.8 or lower, later - * versions provide an option to curl_global_init() that does the - * win32 initialization for you. - */ - -/* - * These are example functions doing socket init that Windows - * require. If you don't use windows, you can safely ignore this crap. - */ - -#include - -void win32_cleanup(void) -{ - WSACleanup(); -} - -int win32_init(void) -{ - WORD wVersionRequested; - WSADATA wsaData; - int err; - wVersionRequested = MAKEWORD(1, 1); - - err = WSAStartup(wVersionRequested, &wsaData); - - if (err != 0) - /* Tell the user that we couldn't find a useable */ - /* winsock.dll. */ - return 1; - - /* Confirm that the Windows Sockets DLL supports 1.1.*/ - /* Note that if the DLL supports versions greater */ - /* than 1.1 in addition to 1.1, it will still return */ - /* 1.1 in wVersion since that is the version we */ - /* requested. */ - - if ( LOBYTE( wsaData.wVersion ) != 1 || - HIBYTE( wsaData.wVersion ) != 1 ) { - /* Tell the user that we couldn't find a useable */ - - /* winsock.dll. */ - WSACleanup(); - return 1; - } - return 0; /* 0 is ok */ -} -- cgit v1.2.1 From fc5c9d8f179b8a4efafee9317779a78763c3d4eb Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 19 Jun 2002 12:30:12 +0000 Subject: simplepost.c shows a simple POST ;-) --- docs/examples/Makefile.am | 2 +- docs/examples/simplepost.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 docs/examples/simplepost.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 78e1baef8..b2ddad406 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -9,7 +9,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ multithread.c getinmemory.c ftpupload.c httpput.c \ simplessl.c ftpgetresp.c http-post.c post-callback.c \ multi-app.c multi-double.c multi-single.c multi-post.c \ - fopen.c + fopen.c simplepost.c all: @echo "done" diff --git a/docs/examples/simplepost.c b/docs/examples/simplepost.c new file mode 100644 index 000000000..57c1f61d7 --- /dev/null +++ b/docs/examples/simplepost.c @@ -0,0 +1,36 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include +#include + +int main(void) +{ + CURL *curl; + CURLcode res; + + char *postthis="moo mooo moo moo"; + + curl = curl_easy_init(); + if(curl) { + curl_easy_setopt(curl, CURLOPT_URL, "http://posthere.com"); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis); + + /* if we don't provide POSTFIELDSIZE, libcurl will strlen() by + itself */ + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(postthis)); + + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} -- cgit v1.2.1 From b79e250ed27e349d51a3671940c81915edcbc5ef Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 19 Jun 2002 12:31:49 +0000 Subject: simplified the compile line even more --- docs/examples/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/README b/docs/examples/README index 46f7321fb..ac58ad6f9 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -12,7 +12,7 @@ examples. Just edit the file according to your system and requirements first. Most examples should build fine using a command line like this: - $ gcc `curl-config --cflags` `curl-config --libs` -o example example.c + $ `curl-config --cc --cflags --libs` -o example example.c Try the php/examples/ directory for PHP programming snippets! -- cgit v1.2.1 From b9f8e80b1432bef32209df0a8f04966f546cc1f2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 19 Jun 2002 12:37:02 +0000 Subject: removed the php/examples reference as that dir is not in the archives --- docs/examples/README | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/README b/docs/examples/README index ac58ad6f9..dfc0d5a8c 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -1,7 +1,7 @@ EXAMPLES -This directory is for tiny libcurl programming examples. They are meant to -show some simple steps on how you can build your own application to take full +This directory is for libcurl programming examples. They are meant to show +some simple steps on how you can build your own application to take full advantage of libcurl. If you end up with other small but still useful example sources, please mail @@ -14,9 +14,7 @@ Most examples should build fine using a command line like this: $ `curl-config --cc --cflags --libs` -o example example.c -Try the php/examples/ directory for PHP programming snippets! - - *PLEASE* do not use the curl.haxx.se site as a test target for your libcurl - applications/experiments. Even if the examples in this directory use that - site as an example URL at some places, it doesn't mean that the URLs work or - that we expect you to actually torture our web site with your tests! Thanks. +*PLEASE* do not use the curl.haxx.se site as a test target for your libcurl +applications/experiments. Even if the examples in this directory use that site +as an example URL at some places, it doesn't mean that the URLs work or that +we expect you to actually torture our web site with your tests! Thanks. -- cgit v1.2.1 From b5dd257427e9bcf84985a1be8a3273e1c3767ea0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 8 Aug 2002 23:05:50 +0000 Subject: makes things better --- docs/examples/.cvsignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 docs/examples/.cvsignore (limited to 'docs/examples') diff --git a/docs/examples/.cvsignore b/docs/examples/.cvsignore new file mode 100644 index 000000000..282522db0 --- /dev/null +++ b/docs/examples/.cvsignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in -- cgit v1.2.1 From c74cb59e0843144ada7ad5e5b90303a66bb27c44 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 12 Aug 2002 11:36:48 +0000 Subject: added comment about CURLOPT_WRITEDATA for directing contents somewhere --- docs/examples/sepheaders.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index 40110ce95..3f4eb5cf4 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -63,6 +63,10 @@ int main(int argc, char **argv) /* we want the headers to this file handle */ curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER ,headerfile); + /* + * Notice here that if you want the actual data sent anywhere else but + * stdout, you should consider using the CURLOPT_WRITEDATA option. */ + /* get it! */ curl_easy_perform(curl_handle); -- cgit v1.2.1 From c7d517f6d2fd056e50fa0cb345e22d6cd7917216 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 14 Aug 2002 23:01:14 +0000 Subject: re-order the compiler arguments to keep more compiler happy --- docs/examples/Makefile.example | 2 +- docs/examples/README | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.example b/docs/examples/Makefile.example index 03e7c3f64..0852c0f3c 100644 --- a/docs/examples/Makefile.example +++ b/docs/examples/Makefile.example @@ -35,7 +35,7 @@ LIBS = -lcurl -lsocket -lnsl -lssl -lcrypto -dl # Link the target with all objects and libraries $(TARGET) : $(OBJS) - $(CC) $(LDFLAGS) $(LIBS) -o $(TARGET) $(OBJS) + $(CC) -o $(TARGET) $(OBJS) $(LDFLAGS) $(LIBS) # Compile the source files into object files ftpget.o : ftpget.c diff --git a/docs/examples/README b/docs/examples/README index dfc0d5a8c..dd053d8f0 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -14,6 +14,11 @@ Most examples should build fine using a command line like this: $ `curl-config --cc --cflags --libs` -o example example.c +Some compilers don't like having the arguments in this order but instead +want you do reorganize them like: + + $ `curl-config --cc` -o example example.c `curl-config --cflags --libs` + *PLEASE* do not use the curl.haxx.se site as a test target for your libcurl applications/experiments. Even if the examples in this directory use that site as an example URL at some places, it doesn't mean that the URLs work or that -- cgit v1.2.1 From 9e1123debe5a3fcf3e1d706596f65fc4367658ba Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 22 Nov 2002 07:39:15 +0000 Subject: don't use curl.haxx.se --- docs/examples/simplessl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index 9a53603f4..4eedfc78e 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -66,7 +66,7 @@ int main(int argc, char **argv) curl = curl_easy_init(); if(curl) { /* what call to write: */ - curl_easy_setopt(curl, CURLOPT_URL, "HTTPS://curl.haxx.se"); + curl_easy_setopt(curl, CURLOPT_URL, "HTTPS://your.favourite.ssl.site"); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, headerfile); while(1) /* do some ugly short cut... */ -- cgit v1.2.1 From a39cdc80b7ed6d98612a718e7eec63bb44a4a46b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 3 Dec 2002 12:34:43 +0000 Subject: Jeff pointed out this flaw in the example --- docs/examples/multi-double.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/multi-double.c b/docs/examples/multi-double.c index 2b92d55f5..51b4ed370 100644 --- a/docs/examples/multi-double.c +++ b/docs/examples/multi-double.c @@ -80,7 +80,8 @@ int main(int argc, char **argv) case 0: default: /* timeout or readable/writable sockets */ - curl_multi_perform(multi_handle, &still_running); + while(CURLM_CALL_MULTI_PERFORM == + curl_multi_perform(multi_handle, &still_running)); break; } } -- cgit v1.2.1 From 16e0da2c4b5048129fdb04896dbb0ec86a927ae0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 9 Jan 2003 11:42:07 +0000 Subject: call curl_multi_perform() correctly --- docs/examples/multi-single.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c index 562886a10..1998d25db 100644 --- a/docs/examples/multi-single.c +++ b/docs/examples/multi-single.c @@ -74,7 +74,8 @@ int main(int argc, char **argv) case 0: default: /* timeout or readable/writable sockets */ - curl_multi_perform(multi_handle, &still_running); + while(CURLM_CALL_MULTI_PERFORM == + curl_multi_perform(multi_handle, &still_running)); break; } } -- cgit v1.2.1 From cc09e9d4c29782c7421bba0062793f2140f7ad15 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 9 Jan 2003 11:43:08 +0000 Subject: fix --- docs/examples/multi-app.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index 13a221325..aead0244f 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -83,7 +83,8 @@ int main(int argc, char **argv) default: /* one or more of curl's file descriptors say there's data to read or write */ - curl_multi_perform(multi_handle, &still_running); + while(CURLM_CALL_MULTI_PERFORM == + curl_multi_perform(multi_handle, &still_running)); break; } } -- cgit v1.2.1 From 173b35eaf85728276f021520e49e0fd5c5bd6d05 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 27 Jan 2003 10:25:20 +0000 Subject: made it work made it cause less compiler warnings made it require 7.9.7 to build --- docs/examples/fopen.c | 95 +++++++++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 41 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index a60d10334..8fc4b1f7c 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -22,10 +22,13 @@ #include #include #include +#include #include -#include -#include + +#if (LIBCURL_VERSION_NUM < 0x070907) +#error "too old libcurl version, get the latest!" +#endif struct data { int type; @@ -34,8 +37,8 @@ struct data { FILE *file; } handle; - /* TODO: We should perhaps document the biggest possible buffer chunk we can - get from libcurl in one single callback... */ + /* This is the documented biggest possible buffer chunk we can get from + libcurl in one single callback! */ char buffer[CURL_MAX_WRITE_SIZE]; char *readptr; /* read from here */ @@ -62,6 +65,8 @@ size_t write_callback(char *buffer, url->readptr += size; url->bytes += size; + fprintf(stderr, "callback %d size bytes\n", size); + return size; } @@ -72,6 +77,7 @@ URL_FILE *url_fopen(char *url, char *operation) URL_FILE *file; int still_running; + (void)operation; file = (URL_FILE *)malloc(sizeof(URL_FILE)); if(!file) @@ -134,47 +140,51 @@ size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) } } if(!still_running) { - printf("NO MORE RUNNING AROUND!\n"); + printf("DONE RUNNING AROUND!\n"); return 0; } } - FD_ZERO(&fdread); - FD_ZERO(&fdwrite); - FD_ZERO(&fdexcep); - - /* set a suitable timeout to fail on */ - timeout.tv_sec = 500; /* 5 minutes */ - timeout.tv_usec = 0; - - /* get file descriptors from the transfers */ - curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); - - rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); - - switch(rc) { - case -1: - /* select error */ - break; - case 0: - break; - default: - /* timeout or readable/writable sockets */ - do { - file->m = curl_multi_perform(multi_handle, &still_running); - - if(file->bytes) - /* we have received data, return that now */ - break; + do { - } while(CURLM_CALL_MULTI_PERFORM == file->m); - - - if(!still_running) - printf("NO MORE RUNNING AROUND!\n"); - - break; - } + FD_ZERO(&fdread); + FD_ZERO(&fdwrite); + FD_ZERO(&fdexcep); + + /* set a suitable timeout to fail on */ + timeout.tv_sec = 500; /* 5 minutes */ + timeout.tv_usec = 0; + + /* get file descriptors from the transfers */ + curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); + + switch(rc) { + case -1: + /* select error */ + break; + case 0: + break; + default: + /* timeout or readable/writable sockets */ + printf("select() returned %d!\n", rc); + do { + file->m = curl_multi_perform(multi_handle, &still_running); + + if(file->bytes) + /* we have received data, return that now */ + break; + + } while(CURLM_CALL_MULTI_PERFORM == file->m); + + + if(!still_running) + printf("DONE RUNNING AROUND!\n"); + + break; + } + } while(still_running && (file->bytes <= 0)); } else printf("(fread) Skip network read\n"); @@ -204,7 +214,10 @@ int main(int argc, char *argv[]) int nread; char buffer[256]; - handle = url_fopen("http://www.haxx.se", "r"); + (void)argc; + (void)argv; + + handle = url_fopen("http://curl.haxx.se/", "r"); if(!handle) { printf("couldn't url_fopen()\n"); -- cgit v1.2.1 From ebe5191b631a093fb9ad37b778d51b39d86c1966 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 10 Mar 2003 17:01:11 +0000 Subject: no the data is not freed, this is left for the app to do when needed --- docs/examples/getinmemory.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index afd6e3f03..7d6629123 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -74,6 +74,10 @@ int main(int argc, char **argv) * bytes big and contains the remote file. * * Do something nice with it! + * + * You should be aware of the fact that at this point we might have an + * allocated data block, and nothing has yet deallocated that data. So when + * you're done with it, you should free() it as a nice application. */ return 0; -- cgit v1.2.1 From 5334a58f9bd177961dc55485dcc98353244db5d0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 17 Mar 2003 12:38:08 +0000 Subject: Andy Cedilnik's corrections --- docs/examples/ftpupload.c | 3 +++ docs/examples/sepheaders.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index 5b430e648..dee44c4ab 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -11,6 +11,9 @@ #include #include +#include +#include +#include /* * This example shows an FTP upload, with a rename of the file just after diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index 3f4eb5cf4..7168f8016 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -21,7 +21,7 @@ size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) { - written = fwrite(ptr, size, nmemb, (FILE *)stream); + int written = fwrite(ptr, size, nmemb, (FILE *)stream); return written; } -- cgit v1.2.1 From 662c6592208abf87652ec98d6482cbcb9d8048bf Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 20 May 2003 12:44:55 +0000 Subject: missing semicolon, by Gisle Vanem --- docs/examples/simplessl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index 4eedfc78e..781e06909 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -40,7 +40,7 @@ int main(int argc, char **argv) FILE *headerfile; const char *pCertFile = "testcert.pem"; - const char *pCACertFile="cacert.pem" + const char *pCACertFile="cacert.pem"; const char *pKeyName; const char *pKeyType; -- cgit v1.2.1 From d5043133e63290e0abedc34ddd1889bbd4bb953e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 21 May 2003 08:08:48 +0000 Subject: Gisle Vanem made curl build with djgpp on DOS. --- docs/examples/Makefile.am | 2 +- docs/examples/makefile.dj | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 docs/examples/makefile.dj (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index b2ddad406..c21d00bdf 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -9,7 +9,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ multithread.c getinmemory.c ftpupload.c httpput.c \ simplessl.c ftpgetresp.c http-post.c post-callback.c \ multi-app.c multi-double.c multi-single.c multi-post.c \ - fopen.c simplepost.c + fopen.c simplepost.c makefile.dj all: @echo "done" diff --git a/docs/examples/makefile.dj b/docs/examples/makefile.dj new file mode 100644 index 000000000..6b3cb9d39 --- /dev/null +++ b/docs/examples/makefile.dj @@ -0,0 +1,31 @@ +# +# Adapted for djgpp / Watt-32 / DOS by +# Gisle Vanem +# + +include ../../packages/DOS/common.dj + +CFLAGS += -I../../include + +LIBS = ../../lib/libcurl.a + +ifeq ($(USE_SSL),1) + LIBS += $(OPENSSL_ROOT)/lib/libssl.a $(OPENSSL_ROOT)/lib/libcrypt.a +endif + +LIBS += $(WATT32_ROOT)/lib/libwatt.a $(ZLIB_ROOT)/libz.a + +PROGRAMS = fopen.exe ftpget.exe ftpgetre.exe ftpuploa.exe getinmem.exe \ + http-pos.exe httpput.exe multi-ap.exe multi-do.exe \ + multi-po.exe multi-si.exe persista.exe post-cal.exe \ + postit2.exe sepheade.exe simple.exe simpless.exe + +all: $(PROGRAMS) + +.c.exe: + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) + @echo + +clean: + rm -f $(PROGRAMS) + -- cgit v1.2.1 From d3b81ea3f7862bfac32536baf9a0bd1e7c94f40f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 11 Aug 2003 21:34:52 +0000 Subject: Vincent Sanders's massive update of this example code. One could argue weather this is still an "example" or a whole new API layer! ;-) --- docs/examples/fopen.c | 662 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 496 insertions(+), 166 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index 8fc4b1f7c..452995bc3 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -1,28 +1,53 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| * - * $Id$ + * This example source code introduces a c library buffered I/O interface to + * URL reads it supports fopen(), fread(), fgets(), feof(), fclose(), + * rewind(). Supported functions have identical prototypes to their normal c + * lib namesakes and are preceaded by url_ . * - * This example source code introduces an fopen()/fread()/fclose() emulation - * for URL reads. Using an approach similar to this, you could replace your - * program's fopen() with this url_fopen() and fread() with url_fread() and - * it should be possible to read remote streams instead of (only) local files. + * Using this code you can replace your program's fopen() with url_fopen() + * and fread() with url_fread() and it become possible to read remote streams + * instead of (only) local files. Local files (ie those that can be directly + * fopened) will drop back to using the underlying clib implementations * - * See the main() function at the bottom that shows a tiny app in action. + * See the main() function at the bottom that shows an app that retrives from a + * specified url using fgets() and fread() and saves as two output files. * - * This source code is a proof of concept. It will need further attention to - * become production-use useful and solid. + * Coyright (c)2003 Simtec Electronics + * + * Re-implemented by Vincent Sanders with extensive + * reference to original curl example code + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This example requires libcurl 7.9.7 or later. */ + #include #include #include #include +#include #include @@ -30,206 +55,511 @@ #error "too old libcurl version, get the latest!" #endif -struct data { - int type; - union { - CURL *curl; - FILE *file; - } handle; - - /* This is the documented biggest possible buffer chunk we can get from - libcurl in one single callback! */ - char buffer[CURL_MAX_WRITE_SIZE]; - char *readptr; /* read from here */ - int bytes; /* bytes available from read pointer */ +enum fcurl_type_e { CFTYPE_NONE=0, CFTYPE_FILE=1, CFTYPE_CURL=2 }; - CURLMcode m; /* stored from a previous url_fread() */ +struct fcurl_data +{ + enum fcurl_type_e type; /* type of handle */ + union { + CURL *curl; + FILE *file; + } handle; /* handle */ + + char *buffer; /* buffer to store cached data*/ + int buffer_len; /* currently allocated buffers length */ + int buffer_pos; /* end of data in buffer*/ + int still_running; /* Is background url fetch still in progress */ }; -typedef struct data URL_FILE; +typedef struct fcurl_data URL_FILE; + +/* exported functions */ +URL_FILE *url_fopen(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); +char * url_fgets(char *ptr, int size, URL_FILE *file); +void url_rewind(URL_FILE *file); /* we use a global one for convenience */ CURLM *multi_handle; -static -size_t write_callback(char *buffer, - size_t size, - size_t nitems, - void *userp) +/* curl calls this routine to get more data */ +static size_t +write_callback(char *buffer, + size_t size, + size_t nitems, + void *userp) { - URL_FILE *url = (URL_FILE *)userp; - size *= nitems; + char *newbuff; + int rembuff; + + URL_FILE *url = (URL_FILE *)userp; + size *= nitems; + + rembuff=url->buffer_len - url->buffer_pos;//remaining space in buffer + + if(size > rembuff) + { + //not enuf space in buffer + newbuff=realloc(url->buffer,url->buffer_len + (size - rembuff)); + if(newbuff==NULL) + { + fprintf(stderr,"callback buffer grow failed\n"); + size=rembuff; + } + else + { + /* realloc suceeded increase buffer size*/ + url->buffer_len+=size - rembuff; + url->buffer=newbuff; + + /*printf("Callback buffer grown to %d bytes\n",url->buffer_len);*/ + } + } + + memcpy(&url->buffer[url->buffer_pos], buffer, size); + url->buffer_pos += size; - memcpy(url->readptr, buffer, size); - url->readptr += size; - url->bytes += size; + /*fprintf(stderr, "callback %d size bytes\n", size);*/ + + return size; +} - fprintf(stderr, "callback %d size bytes\n", size); +/* use to attempt to fill the read buffer up to requested number of bytes */ +static int +curl_fill_buffer(URL_FILE *file,int want,int waittime) +{ + fd_set fdread; + fd_set fdwrite; + fd_set fdexcep; + int maxfd; + struct timeval timeout; + int rc; + + /* only attempt to fill buffer if transactions still running and buffer + * doesnt exceed required size already + */ + if((!file->still_running) || (file->buffer_pos > want)) + return 0; + + /* attempt to fill buffer */ + do + { + FD_ZERO(&fdread); + FD_ZERO(&fdwrite); + FD_ZERO(&fdexcep); + + /* set a suitable timeout to fail on */ + timeout.tv_sec = 60; /* 1 minute */ + timeout.tv_usec = 0; + + /* get file descriptors from the transfers */ + curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); + + switch(rc) { + case -1: + /* select error */ + break; + + case 0: + break; + + default: + /* timeout or readable/writable sockets */ + /* note we *could* be more efficient and not wait for + * CURLM_CALL_MULTI_PERFORM to clear here and check it on re-entry + * but that gets messy */ + while(curl_multi_perform(multi_handle, &file->still_running) == + CURLM_CALL_MULTI_PERFORM); + + break; + } + } while(file->still_running && (file->buffer_pos < want)); + return 1; +} - return size; +/* use to remove want bytes from the front of a files buffer */ +static int +curl_use_buffer(URL_FILE *file,int want) +{ + /* sort out buffer */ + if((file->buffer_pos - want) <=0) + { + /* ditch buffer - write will recreate */ + if(file->buffer) + free(file->buffer); + + file->buffer=NULL; + file->buffer_pos=0; + file->buffer_len=0; + } + else + { + /* move rest down make it available for later */ + memmove(file->buffer, + &file->buffer[want], + (file->buffer_pos - want)); + + file->buffer_pos -= want; + } + return 0; } -URL_FILE *url_fopen(char *url, char *operation) + + +URL_FILE * +url_fopen(char *url,const char *operation) { - /* this code could check for URLs or types in the 'url' and - basicly use the real fopen() for standard files */ + /* this code could check for URLs or types in the 'url' and + basicly use the real fopen() for standard files */ + + URL_FILE *file; + (void)operation; + + file = (URL_FILE *)malloc(sizeof(URL_FILE)); + if(!file) + return NULL; - URL_FILE *file; - int still_running; - (void)operation; + memset(file, 0, sizeof(URL_FILE)); + + if((file->handle.file=fopen(url,operation))) + { + file->type = CFTYPE_FILE; /* marked as URL */ + } + else + { + file->type = CFTYPE_CURL; /* marked as URL */ + file->handle.curl = curl_easy_init(); - file = (URL_FILE *)malloc(sizeof(URL_FILE)); - if(!file) - return NULL; + curl_easy_setopt(file->handle.curl, CURLOPT_URL, url); + curl_easy_setopt(file->handle.curl, CURLOPT_FILE, file); + curl_easy_setopt(file->handle.curl, CURLOPT_VERBOSE, FALSE); + curl_easy_setopt(file->handle.curl, CURLOPT_WRITEFUNCTION, write_callback); - memset(file, 0, sizeof(URL_FILE)); + if(!multi_handle) + multi_handle = curl_multi_init(); - file->type = 1; /* marked as URL, use 0 for plain file */ - file->handle.curl = curl_easy_init(); + curl_multi_add_handle(multi_handle, file->handle.curl); - curl_easy_setopt(file->handle.curl, CURLOPT_URL, url); - curl_easy_setopt(file->handle.curl, CURLOPT_FILE, file); - curl_easy_setopt(file->handle.curl, CURLOPT_VERBOSE, FALSE); - curl_easy_setopt(file->handle.curl, CURLOPT_WRITEFUNCTION, write_callback); + /* lets start the fetch */ + while(curl_multi_perform(multi_handle, &file->still_running) == + CURLM_CALL_MULTI_PERFORM ); - if(!multi_handle) - multi_handle = curl_multi_init(); + if((file->buffer_pos == 0) && (!file->still_running)) + { + /* if still_running is 0 now, we should return NULL */ - curl_multi_add_handle(multi_handle, file->handle.curl); + /* make sure the easy handle is not in the multi handle anymore */ + curl_multi_remove_handle(multi_handle, file->handle.curl); - while(CURLM_CALL_MULTI_PERFORM == - curl_multi_perform(multi_handle, &still_running)); + /* cleanup */ + curl_easy_cleanup(file->handle.curl); - /* if still_running would be 0 now, we should return NULL */ + free(file); - return file; + file = NULL; + } + } + return file; } -void url_fclose(URL_FILE *file) +int +url_fclose(URL_FILE *file) { - /* make sure the easy handle is not in the multi handle anymore */ - curl_multi_remove_handle(multi_handle, file->handle.curl); + int ret=0;/* default is good return */ - /* cleanup */ - curl_easy_cleanup(file->handle.curl); -} + switch(file->type) + { + case CFTYPE_FILE: + ret=fclose(file->handle.file); /* passthrough */ + break; + + case CFTYPE_CURL: + /* make sure the easy handle is not in the multi handle anymore */ + curl_multi_remove_handle(multi_handle, file->handle.curl); + /* cleanup */ + curl_easy_cleanup(file->handle.curl); + break; + + default: /* unknown or supported type - oh dear */ + ret=EOF; + errno=EBADF; + break; + + } + if(file->buffer) + free(file->buffer);/* free any allocated buffer space */ -size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) + free(file); + + return ret; +} + +int +url_feof(URL_FILE *file) { - fd_set fdread; - fd_set fdwrite; - fd_set fdexcep; - int maxfd; - struct timeval timeout; - int rc; - int still_running = 0; - - if(!file->bytes) { /* no data available at this point */ - - file->readptr = file->buffer; /* reset read pointer */ - - if(CURLM_CALL_MULTI_PERFORM == file->m) { - while(CURLM_CALL_MULTI_PERFORM == - curl_multi_perform(multi_handle, &still_running)) { - if(file->bytes) { - printf("(fread) WOAH! THis happened!\n"); - break; - } - } - if(!still_running) { - printf("DONE RUNNING AROUND!\n"); - return 0; - } + int ret=0; + + switch(file->type) + { + case CFTYPE_FILE: + ret=feof(file->handle.file); + break; + + case CFTYPE_CURL: + if((file->buffer_pos == 0) && (!file->still_running)) + ret = 1; + break; + default: /* unknown or supported type - oh dear */ + ret=-1; + errno=EBADF; + break; } + return ret; +} - do { +size_t +url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) +{ + size_t want; + + switch(file->type) + { + case CFTYPE_FILE: + want=fread(ptr,size,nmemb,file->handle.file); + break; + + case CFTYPE_CURL: + want = nmemb * size; + + curl_fill_buffer(file,want,1); + + /* check if theres data in the buffer - if not curl_fill_buffer() + * either errored or EOF */ + if(!file->buffer_pos) + return 0; + + /* ensure only available data is considered */ + if(file->buffer_pos < want) + want = file->buffer_pos; - FD_ZERO(&fdread); - FD_ZERO(&fdwrite); - FD_ZERO(&fdexcep); - - /* set a suitable timeout to fail on */ - timeout.tv_sec = 500; /* 5 minutes */ - timeout.tv_usec = 0; - - /* get file descriptors from the transfers */ - curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); - - rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); - - switch(rc) { - case -1: - /* select error */ - break; - case 0: - break; - default: - /* timeout or readable/writable sockets */ - printf("select() returned %d!\n", rc); - do { - file->m = curl_multi_perform(multi_handle, &still_running); - - if(file->bytes) - /* we have received data, return that now */ - break; - - } while(CURLM_CALL_MULTI_PERFORM == file->m); - - - if(!still_running) - printf("DONE RUNNING AROUND!\n"); - - break; - } - } while(still_running && (file->bytes <= 0)); - } - else - printf("(fread) Skip network read\n"); - - if(file->bytes) { - /* data already available, return that */ - int want = size * nmemb; - - if(file->bytes < want) - want = file->bytes; - - memcpy(ptr, file->readptr, want); - file->readptr += want; - file->bytes -= want; - - printf("(fread) return %d bytes\n", want); + /* xfer data to caller */ + memcpy(ptr, file->buffer, want); + curl_use_buffer(file,want); + + want = want / size; /* number of items - nb correct op - checked + * with glibc code*/ + + /*printf("(fread) return %d bytes %d left\n", want,file->buffer_pos);*/ + break; + + default: /* unknown or supported type - oh dear */ + want=0; + errno=EBADF; + break; + + } return want; - } - return 0; /* no data available to return */ } +char * +url_fgets(char *ptr, int size, URL_FILE *file) +{ + int want = size - 1;/* always need to leave room for zero termination */ + int loop; + + switch(file->type) + { + case CFTYPE_FILE: + ptr = fgets(ptr,size,file->handle.file); + break; + + case CFTYPE_CURL: + curl_fill_buffer(file,want,1); + + /* check if theres data in the buffer - if not fill either errored or + * EOF */ + if(!file->buffer_pos) + return NULL; + + /* ensure only available data is considered */ + if(file->buffer_pos < want) + want = file->buffer_pos; + + /*buffer contains data */ + /* look for newline or eof */ + for(loop=0;loop < want;loop++) + { + if(file->buffer[loop] == '\n') + { + want=loop+1;/* include newline */ + break; + } + } + + /* xfer data to caller */ + memcpy(ptr, file->buffer, want); + ptr[want]=0;/* allways null terminate */ + + curl_use_buffer(file,want); + + /*printf("(fgets) return %d bytes %d left\n", want,file->buffer_pos);*/ + break; + + default: /* unknown or supported type - oh dear */ + ptr=NULL; + errno=EBADF; + break; + } + + return ptr;/*success */ +} + +void +url_rewind(URL_FILE *file) +{ + switch(file->type) + { + case CFTYPE_FILE: + rewind(file->handle.file); /* passthrough */ + break; + + case CFTYPE_CURL: + /* halt transaction */ + curl_multi_remove_handle(multi_handle, file->handle.curl); + + /* restart */ + curl_multi_add_handle(multi_handle, file->handle.curl); + + /* ditch buffer - write will recreate - resets stream pos*/ + if(file->buffer) + free(file->buffer); + + file->buffer=NULL; + file->buffer_pos=0; + file->buffer_len=0; + + break; -int main(int argc, char *argv[]) + default: /* unknown or supported type - oh dear */ + break; + + } + +} + + +/* 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 */ +int +main(int argc, char *argv[]) { - URL_FILE *handle; - int nread; - char buffer[256]; + URL_FILE *handle; + FILE *outf; + + int nread; + char buffer[256]; + char *url; + + if(argc < 2) + { + url="http://192.168.7.3/testfile";/* default to testurl */ + } + else + { + url=argv[1];/* use passed url */ + } + + /* copy from url line by line with fgets */ + outf=fopen("fgets.test","w+"); + if(!outf) + { + perror("couldnt open fgets output file\n"); + return 1; + } + + handle = url_fopen(url, "r"); + if(!handle) + { + printf("couldn't url_fopen()\n"); + fclose(outf); + return 2; + } + + while(!url_feof(handle)) + { + url_fgets(buffer,sizeof(buffer),handle); + fwrite(buffer,1,strlen(buffer),outf); + } + + url_fclose(handle); + + fclose(outf); + + + /* Copy from url with fread */ + outf=fopen("fread.test","w+"); + if(!outf) + { + perror("couldnt open fread output file\n"); + return 1; + } + + handle = url_fopen("testfile", "r"); + if(!handle) { + printf("couldn't url_fopen()\n"); + fclose(outf); + return 2; + } + + do { + nread = url_fread(buffer, 1,sizeof(buffer), handle); + fwrite(buffer,1,nread,outf); + } while(nread); + + url_fclose(handle); + + fclose(outf); + + + /* Test rewind */ + outf=fopen("rewind.test","w+"); + if(!outf) + { + perror("couldnt open fread output file\n"); + return 1; + } + + handle = url_fopen("testfile", "r"); + if(!handle) { + printf("couldn't url_fopen()\n"); + fclose(outf); + return 2; + } + + nread = url_fread(buffer, 1,sizeof(buffer), handle); + fwrite(buffer,1,nread,outf); + url_rewind(handle); - (void)argc; - (void)argv; + buffer[0]='\n'; + fwrite(buffer,1,1,outf); - handle = url_fopen("http://curl.haxx.se/", "r"); + nread = url_fread(buffer, 1,sizeof(buffer), handle); + fwrite(buffer,1,nread,outf); - if(!handle) { - printf("couldn't url_fopen()\n"); - } - do { - nread = url_fread(buffer, sizeof(buffer), 1, handle); + url_fclose(handle); - printf("We got: %d bytes\n", nread); - } while(nread); + fclose(outf); - url_fclose(handle); - return 0; + return 0;/* all done */ } -- cgit v1.2.1 From a95df8246b352cd54777cc518a406e7ff35b2322 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 28 Aug 2003 11:21:14 +0000 Subject: Henrik Storner's rewrite that includes a nice usage of curl_multi_info_read() --- docs/examples/multi-app.c | 51 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 11 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index aead0244f..9e3d72703 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -23,29 +23,38 @@ /* * Download a HTTP file and upload an FTP file simultaneously. */ + +#define HANDLECOUNT 2 /* Number of simultaneous transfers */ +#define HTTP_HANDLE 0 /* Index for the HTTP transfer */ +#define FTP_HANDLE 1 /* Index for the FTP transfer */ + int main(int argc, char **argv) { - CURL *http_handle; - CURL *ftp_handle; + CURL *handles[HANDLECOUNT]; CURLM *multi_handle; int still_running; /* keep number of running handles */ + int i; - http_handle = curl_easy_init(); - ftp_handle = curl_easy_init(); + CURLMsg *msg; /* for picking up messages with the transfer status */ + int msgs_left; /* how many messages are left */ + + /* Allocate one CURL handle per transfer */ + for (i=0; imsg == CURLMSG_DONE) { + + int idx, found = 0; + + /* Find out which handle this message is about */ + for (idx=0; (!found && (idxeasy_handle == handles[idx]); + + switch (idx) { + case HTTP_HANDLE: + printf("HTTP transfer completed with status %d\n", msg->data.result); + break; + case FTP_HANDLE: + printf("FTP transfer completed with status %d\n", msg->data.result); + break; + } + } + } + /* Free the CURL handles */ + for (i=0; i Date: Fri, 3 Oct 2003 13:46:27 +0000 Subject: Peter Sylvester's curlx.c code example added --- docs/examples/Makefile.am | 2 +- docs/examples/curlx.c | 480 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 481 insertions(+), 1 deletion(-) create mode 100644 docs/examples/curlx.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index c21d00bdf..69d9dff33 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -9,7 +9,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ multithread.c getinmemory.c ftpupload.c httpput.c \ simplessl.c ftpgetresp.c http-post.c post-callback.c \ multi-app.c multi-double.c multi-single.c multi-post.c \ - fopen.c simplepost.c makefile.dj + fopen.c simplepost.c makefile.dj curlx.c all: @echo "done" diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c new file mode 100644 index 000000000..c5aabd344 --- /dev/null +++ b/docs/examples/curlx.c @@ -0,0 +1,480 @@ +/* + curlx.c Authors: Peter Sylvester, Jean-Paul Merlin + + This is a little program to demonstrate the usage of + + - an ssl initialisation callback setting a user key and trustbases + coming from a pkcs12 file + - using an ssl application callback to find a URI in the + certificate presented during ssl session establishment. + +*/ + + +/* + * Copyright (c) 2003 The OpenEvidence Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, the following disclaimer, + * and the original OpenSSL and SSLeay Licences below. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, the following disclaimer + * and the original OpenSSL and SSLeay Licences below in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgments: + * "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/)" + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com)." + * + * 4. The names "OpenEvidence Toolkit" and "OpenEvidence Project" must not be + * used to endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openevidence-core@openevidence.org. + * + * 5. Products derived from this software may not be called "OpenEvidence" + * nor may "OpenEvidence" appear in their names without prior written + * permission of the OpenEvidence Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgments: + * "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/)" + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com)." + * + * THIS SOFTWARE IS PROVIDED BY THE OpenEvidence PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenEvidence PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://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). + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static char *curlx_usage[]={ +"usage: curlx args\n", +" -p12 arg - tia file ", +" -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.openevidenve.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 +}; + +/* + + ./curlx -p12 psy.p12 -envpass XX -in request -verbose -accesstype AD_DVCS + -mimetype application/dvcs -acceptmime application/dvcs -out response + +*/ + +/* 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 ; + CURL * curl; + BIO * errorbio; + int accesstype ; + int verbose; + +} sslctxparm; + +/* some helper function. */ + +static char *i2s_ASN1_IA5STRING( ASN1_IA5STRING *ia5) +{ + char *tmp; + if(!ia5 || !ia5->length) return NULL; + tmp = OPENSSL_malloc(ia5->length + 1); + memcpy(tmp, ia5->data, ia5->length); + tmp[ia5->length] = 0; + return tmp; +} + +/* A conveniance routine to get an access URI. */ + +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) ; + + if (!sk_ACCESS_DESCRIPTION_num(accessinfo)) return NULL; + 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); + } + return NULL; + } + } + return NULL; +} + +/* This is an application verification call back, it does not + perform any addition verification but tries to find a URL + in the presented certificat. If found, this will become + the URL to be used in the POST. +*/ + +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 ((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); + 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); + 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); +} + + +/* This is an example of an curl SSL initialisation call back. 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) { + + sslctxparm * p = (sslctxparm *) parm; + 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_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; + } + + 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(ctx->cert_store,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,NULL); + + SSL_CTX_set_cert_verify_callback(ctx, ssl_app_verify_callback, parm); + + + return CURLE_OK ; +err: + ERR_print_errors(p->errorbio); + return CURLE_SSL_CERTPROBLEM; + +} + +int main(int argc, char **argv) { + + BIO* in=NULL; + BIO* out=NULL; + + + char * outfile = NULL; + char * infile = NULL ; + + int tabLength=100; + char *binaryptr; + char* mimetype; + char* mimetypeaccept=NULL; + char* contenttype; + char** pp; + unsigned char* hostporturl = NULL; + binaryptr=(char*)malloc(tabLength); + BIO * p12bio ; + char **args = argv + 1; + unsigned char * serverurl; + sslctxparm p; + char *response; + p.verbose = 0; + + CURLcode res; + struct curl_slist * headers=NULL; + + p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); + + curl_global_init(CURL_GLOBAL_DEFAULT); + +/* we need some more for the P12 decoding */ + + OpenSSL_add_all_ciphers(); + OpenSSL_add_all_digests(); + ERR_load_crypto_strings(); + + + int badarg=0; + + while (*args && *args[0] == '-') { + if (!strcmp (*args, "-in")) { + if (args[1]) { + infile=*(++args); + } else badarg=1; + } else if (!strcmp (*args, "-out")) { + if (args[1]) { + outfile=*(++args); + } 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]) { + p.pst = getenv(*(++args)); + } 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]) { + mimetype = *(++args); + } 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) { + p.verbose++; + } else badarg=1; + args++; + } + + 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"); + goto err; + } + + + + /* set input */ + + 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) { + BIO_printf(p.errorbio, "Error opening input file %s\n", infile); + BIO_free(in); + goto err; + } + + /* set output */ + + 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) { + BIO_printf(p.errorbio, "Error opening output file %s\n", outfile); + BIO_free(out); + goto err; + } + + + p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); + + 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 (!(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 (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); + + /* determine URL to go */ + + if (hostporturl) { + serverurl=(char*) malloc(9+strlen(hostporturl)); + sprintf(serverurl,"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))) { + BIO_printf(p.errorbio,"no service URL in user cert cherching in others certificats\n"); + int j=0; + int find=0; + for (j=0;j\n", serverurl); + curl_easy_setopt(p.curl, CURLOPT_URL, serverurl); + + /* Now specify the POST binary data */ + + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); + + /* pass our list of custom made headers */ + + contenttype=(char*) malloc(15+strlen(mimetype)); + sprintf(contenttype,"Content-type: %s",mimetype); + headers = curl_slist_append(headers,contenttype); + curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers); + + if (p.verbose) BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); + + { + FILE *outfp; + BIO_get_fp(out,&outfp); + curl_easy_setopt(p.curl, CURLOPT_FILE,outfp); + } + + 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); + + 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 ) { + i+=lu; + if (i== tabLength) { + tabLength+=100; + binaryptr=(char*)realloc(binaryptr,tabLength); /* should be more careful */ + } + } + tabLength = i; + } + /* Now specify the POST binary data */ + + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); + + + /* Perform the request, res will get the return code */ + + 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",response); + else + BIO_printf(p.errorbio,"the reponse doesn\'t has an acceptable mime type, it is %s instead of %s\n",response,mimetypeaccept); + } + + /*** code d'erreur si accept mime ***, egalement code return HTTP != 200 ***/ + +/* free the header list*/ + + curl_slist_free_all(headers); + + /* always cleanup */ + curl_easy_cleanup(p.curl); + + BIO_free(in); + BIO_free(out); + return (EXIT_SUCCESS); + + + err: BIO_printf(p.errorbio,"error"); + exit(1); +} + + + + -- cgit v1.2.1 From 4d280124683a7d57cacb14729f964aec21eba7d7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 19 Nov 2003 08:19:20 +0000 Subject: remove the wrong win32 comment and use global_init --- docs/examples/getinmemory.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 7d6629123..e45beb070 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -13,9 +13,6 @@ * This exact source code has not been verified to work. */ -/* to make this work under windows, use the win32-functions from the - win32socket.c file as well */ - #include #include @@ -51,6 +48,8 @@ int main(int argc, char **argv) chunk.memory=NULL; /* we expect realloc(NULL, size) to work */ chunk.size = 0; /* no data at this point */ + curl_global_init(CURL_GLOBAL_ALL); + /* init the curl session */ curl_handle = curl_easy_init(); -- cgit v1.2.1 From 79e4aee18549b520f73548ce6ef94f6d8d5350f2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 19 Nov 2003 08:20:13 +0000 Subject: cleaned up --- docs/examples/persistant.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/persistant.c b/docs/examples/persistant.c index 7b880dee6..0a17031b8 100644 --- a/docs/examples/persistant.c +++ b/docs/examples/persistant.c @@ -10,26 +10,14 @@ #include #include - #include -/* to make this work under windows, use the win32-functions from the - docs/examples/win32socket.c file as well */ - -/* This example REQUIRES libcurl 7.7 or later */ -#if (LIBCURL_VERSION_NUM < 0x070700) -#error Too old libcurl version, upgrade or stay away. -#endif - int main(int argc, char **argv) { CURL *curl; CURLcode res; -#ifdef MALLOCDEBUG - /* this sends all memory debug messages to a specified logfile */ - curl_memdebug("memdump"); -#endif + curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if(curl) { -- cgit v1.2.1 From cc48658564dad6cd57b7526ab1e98780145a473f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 19 Nov 2003 08:21:34 +0000 Subject: cut off old crappy win32 comments and use the proper global_init instead also removed very old "require libcurl older than blablabla" --- docs/examples/postit2.c | 9 ++------- docs/examples/sepheaders.c | 5 ++--- 2 files changed, 4 insertions(+), 10 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/postit2.c b/docs/examples/postit2.c index 9b7cda07e..a46f0a71b 100644 --- a/docs/examples/postit2.c +++ b/docs/examples/postit2.c @@ -21,9 +21,6 @@ * This exact source code has not been verified to work. */ -/* to make this work under windows, use the win32-functions from the - win32socket.c file as well */ - #include #include @@ -31,10 +28,6 @@ #include #include -#if LIBCURL_VERSION_NUM < 0x070900 -#error "curl_formadd() is not introduced until libcurl 7.9 and later" -#endif - int main(int argc, char *argv[]) { CURL *curl; @@ -45,6 +38,8 @@ int main(int argc, char *argv[]) struct curl_slist *headerlist=NULL; char buf[] = "Expect:"; + curl_global_init(CURL_GLOBAL_ALL); + /* Fill in the file upload field */ curl_formadd(&formpost, &lastptr, diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index 7168f8016..6e8735168 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -8,9 +8,6 @@ * $Id$ */ -/* to make this work under windows, use the win32-functions from the - win32socket.c file as well */ - #include #include #include @@ -33,6 +30,8 @@ int main(int argc, char **argv) char *bodyfilename = "body.out"; FILE *bodyfile; + curl_global_init(CURL_GLOBAL_ALL); + /* init the curl session */ curl_handle = curl_easy_init(); -- cgit v1.2.1 From f68219ddaab9dab05a195a6fd126b4edb5ecccdc Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 8 Dec 2003 14:13:19 +0000 Subject: use the newer option names --- docs/examples/fopen.c | 2 +- docs/examples/ftpget.c | 2 +- docs/examples/ftpgetresp.c | 2 +- docs/examples/ftpupload.c | 2 +- docs/examples/getinmemory.c | 2 +- docs/examples/httpput.c | 2 +- docs/examples/post-callback.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index 452995bc3..272c1ad87 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -236,7 +236,7 @@ url_fopen(char *url,const char *operation) file->handle.curl = curl_easy_init(); curl_easy_setopt(file->handle.curl, CURLOPT_URL, url); - curl_easy_setopt(file->handle.curl, CURLOPT_FILE, file); + curl_easy_setopt(file->handle.curl, CURLOPT_WRITEDATA, file); curl_easy_setopt(file->handle.curl, CURLOPT_VERBOSE, FALSE); curl_easy_setopt(file->handle.curl, CURLOPT_WRITEFUNCTION, write_callback); diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 6d728c6ec..2c2275fa5 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -58,7 +58,7 @@ int main(void) /* 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 */ - curl_easy_setopt(curl, CURLOPT_FILE, &ftpfile); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile); /* Switch on full protocol/debug output */ curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE); diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index eb56e19d2..82b1d36a7 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -45,7 +45,7 @@ int main(int argc, char **argv) if(curl) { /* Get a file listing from sunet */ curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.sunet.se/"); - curl_easy_setopt(curl, CURLOPT_FILE, ftpfile); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftpfile); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_response); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, respfile); res = curl_easy_perform(curl); diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index dee44c4ab..2ac874537 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -70,7 +70,7 @@ int main(int argc, char **argv) curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist); /* now specify which file to upload */ - curl_easy_setopt(curl, CURLOPT_INFILE, hd_src); + curl_easy_setopt(curl, CURLOPT_READDATA, hd_src); /* and give the size of the upload (optional) */ curl_easy_setopt(curl, CURLOPT_INFILESIZE, file_info.st_size); diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index e45beb070..f7e27460f 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -60,7 +60,7 @@ int main(int argc, char **argv) curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); /* we pass our 'chunk' struct to the callback function */ - curl_easy_setopt(curl_handle, CURLOPT_FILE, (void *)&chunk); + curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk); /* get it! */ curl_easy_perform(curl_handle); diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index 78275c40a..983e60240 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -82,7 +82,7 @@ int main(int argc, char **argv) curl_easy_setopt(curl,CURLOPT_URL, url); /* now specify which file to upload */ - curl_easy_setopt(curl, CURLOPT_INFILE, hd_src); + curl_easy_setopt(curl, CURLOPT_READDATA, hd_src); /* and give the size of the upload (optional) */ curl_easy_setopt(curl, CURLOPT_INFILESIZE, file_info.st_size); diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index d4664a575..eda878677 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -74,7 +74,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); /* pointer to pass to our read function */ - curl_easy_setopt(curl, CURLOPT_INFILE, &pooh); + curl_easy_setopt(curl, CURLOPT_READDATA, &pooh); /* get verbose debug output please */ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); -- cgit v1.2.1 From 821302bcf3cb608b2f29dffc757f5152cbe63a39 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 8 Dec 2003 14:14:26 +0000 Subject: removed old version checks --- docs/examples/fopen.c | 5 ----- docs/examples/post-callback.c | 10 ---------- 2 files changed, 15 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index 272c1ad87..eb5501628 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -51,11 +51,6 @@ #include -#if (LIBCURL_VERSION_NUM < 0x070907) -#error "too old libcurl version, get the latest!" -#endif - - enum fcurl_type_e { CFTYPE_NONE=0, CFTYPE_FILE=1, CFTYPE_CURL=2 }; struct fcurl_data diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index eda878677..76d1e1ba5 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -10,21 +10,11 @@ * An example source code that issues a HTTP POST and we provide the actual * data through a read callback. * - * Please be aware of the fact that the size of the posted data MUST be - * specified before the transfer is being made (with CURLOPT_POSTFIELDSIZE). - * This requirement will change when libcurl starts supporting chunked-encoded - * sends. - * - * This example requires libcurl 7.9.6 or later. */ #include #include #include -#if LIBCURL_VERSION_NUM < 0x070906 -#error this example source requires libcurl 7.9.6 or newer -#endif - char data[]="this is what we post to the silly web server"; struct WriteThis { -- cgit v1.2.1 From f4e987cd19c3869cb66fc161dd3222ee2a25e16d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 18 Dec 2003 07:52:31 +0000 Subject: clarified the URL part based on the problems Martin Hilpert had --- docs/examples/httpput.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index 983e60240..ec80d3c9a 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -78,7 +78,8 @@ int main(int argc, char **argv) /* HTTP PUT please */ curl_easy_setopt(curl, CURLOPT_PUT, TRUE); - /* specify target */ + /* specify target URL, and note that this URL should include a file + name, not only a directory */ curl_easy_setopt(curl,CURLOPT_URL, url); /* now specify which file to upload */ -- cgit v1.2.1 From 36a2fac79f8751dca9075e83803b6cfa04d82387 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 18 Dec 2003 18:05:10 +0000 Subject: typecast the size to long for platforms where st_size is off_t --- docs/examples/httpput.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index ec80d3c9a..48c9f70ec 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -85,8 +85,9 @@ int main(int argc, char **argv) /* now specify which file to upload */ curl_easy_setopt(curl, CURLOPT_READDATA, hd_src); - /* and give the size of the upload (optional) */ - curl_easy_setopt(curl, CURLOPT_INFILESIZE, file_info.st_size); + /* and give the size of the upload, make sure that we don't accidentally + pass a larger variable type than "long". */ + curl_easy_setopt(curl, CURLOPT_INFILESIZE, (long) file_info.st_size); /* Now run off and do what you've been told! */ res = curl_easy_perform(curl); -- cgit v1.2.1 From b60e0fa97ed7ddc66d0ad6d00dfd78319bb6ad36 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 5 Jan 2004 22:29:29 +0000 Subject: David J Meyer's large file support. --- docs/examples/ftpupload.c | 2 +- docs/examples/httpput.c | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index 2ac874537..d51e43c4d 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -73,7 +73,7 @@ int main(int argc, char **argv) curl_easy_setopt(curl, CURLOPT_READDATA, hd_src); /* and give the size of the upload (optional) */ - curl_easy_setopt(curl, CURLOPT_INFILESIZE, file_info.st_size); + curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, file_info.st_size); /* Now run off and do what you've been told! */ res = curl_easy_perform(curl); diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index 48c9f70ec..3b3fac136 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -85,9 +85,8 @@ int main(int argc, char **argv) /* now specify which file to upload */ curl_easy_setopt(curl, CURLOPT_READDATA, hd_src); - /* and give the size of the upload, make sure that we don't accidentally - pass a larger variable type than "long". */ - curl_easy_setopt(curl, CURLOPT_INFILESIZE, (long) file_info.st_size); + /* and give the size of the upload */ + curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, file_info.st_size); /* Now run off and do what you've been told! */ res = curl_easy_perform(curl); -- cgit v1.2.1 From 7f679c3da3f941789a6a9654bbced6a81ddd932b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 9 Feb 2004 07:12:33 +0000 Subject: Ken Rastatter's fixes to improve portability of this example: These minor changes remove portability issues with the this example and allow it to run on Win32. Specifically: * The use of pthread_create() has been replaced by g_thread_create(). This removes the dependency on the pthreads library. Since this is an example using GTK+, g_thread_create() is available as it is a part of glibc. * The CURLOPT_FILE option is now referred to by its "newer name" CURLOPT_WRITEDATA. * The use of CURLOPT_WRITEFUNCTION has been added. As described in the docs, this avoids the crashes when using a DLL under Win32. * The output file has been renamed from "/tmp/test.curl" to "test.curl". It's unlikely that there is a /tmp when in Win32 and other examples in libcurl write their output files to the working directory. --- docs/examples/curlgtk.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/curlgtk.c b/docs/examples/curlgtk.c index bba1fe1c9..69b016261 100644 --- a/docs/examples/curlgtk.c +++ b/docs/examples/curlgtk.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -17,10 +17,13 @@ #include /* new for v7 */ #include /* new for v7 */ -#include - GtkWidget *Bar; +size_t my_write_func(void *ptr, size_t size, size_t nmemb, FILE *stream) +{ + return fwrite(ptr, size, nmemb, stream); +} + size_t my_read_func(void *ptr, size_t size, size_t nmemb, FILE *stream) { return fread(ptr, size, nmemb, stream); @@ -45,25 +48,27 @@ void *curl_thread(void *ptr) CURLcode res; FILE *outfile; gchar *url = ptr; - + curl = curl_easy_init(); if(curl) { - outfile = fopen("/tmp/test.curl", "w"); + outfile = fopen("test.curl", "w"); curl_easy_setopt(curl, CURLOPT_URL, url); - curl_easy_setopt(curl, CURLOPT_FILE, outfile); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_func); curl_easy_setopt(curl, CURLOPT_READFUNCTION, my_read_func); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func); curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, Bar); - + res = curl_easy_perform(curl); fclose(outfile); /* always cleanup */ curl_easy_cleanup(curl); } + return NULL; } @@ -71,11 +76,10 @@ int main(int argc, char **argv) { GtkWidget *Window, *Frame, *Frame2; GtkAdjustment *adj; - pthread_t curl_tid; /* Init thread */ g_thread_init(NULL); - + gtk_init(&argc, &argv); Window = gtk_window_new(GTK_WINDOW_TOPLEVEL); Frame = gtk_frame_new(NULL); @@ -90,8 +94,10 @@ int main(int argc, char **argv) gtk_container_add(GTK_CONTAINER(Frame2), Bar); gtk_widget_show_all(Window); - pthread_create(&curl_tid, NULL, curl_thread, argv[1]); - + if (!g_thread_create(&curl_thread, argv[1], FALSE, NULL) != 0) + g_warning("can't create the thread"); + + gdk_threads_enter(); gtk_main(); gdk_threads_leave(); -- cgit v1.2.1 From 6b33a5f954c11d77c82ead15e3e5560ca8568c42 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 28 Mar 2004 21:41:10 +0000 Subject: use the correct struct --- docs/examples/postit2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/postit2.c b/docs/examples/postit2.c index a46f0a71b..d1ecadd61 100644 --- a/docs/examples/postit2.c +++ b/docs/examples/postit2.c @@ -33,8 +33,8 @@ int main(int argc, char *argv[]) CURL *curl; CURLcode res; - struct HttpPost *formpost=NULL; - struct HttpPost *lastptr=NULL; + struct curl_httppost *formpost=NULL; + struct curl_httppost *lastptr=NULL; struct curl_slist *headerlist=NULL; char buf[] = "Expect:"; -- cgit v1.2.1 From 9d99af532912a3c3dcd3b489c4073ddb439ddcf6 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 2 Apr 2004 06:40:31 +0000 Subject: if select returns -1, bail out of the loop --- docs/examples/multi-single.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c index 1998d25db..b6ba0c5c0 100644 --- a/docs/examples/multi-single.c +++ b/docs/examples/multi-single.c @@ -70,6 +70,8 @@ int main(int argc, char **argv) switch(rc) { case -1: /* select error */ + still_running = 0; + printf("select() returns error, this is badness\n"); break; case 0: default: -- cgit v1.2.1 From 4973b0f88abd8c77ecbeb512c3930da2bc65d5f3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 13 May 2004 08:22:40 +0000 Subject: basic https fetching script --- docs/examples/https.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 docs/examples/https.c (limited to 'docs/examples') diff --git a/docs/examples/https.c b/docs/examples/https.c new file mode 100644 index 000000000..9ce5a308b --- /dev/null +++ b/docs/examples/https.c @@ -0,0 +1,53 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include +#include + +int main(void) +{ + CURL *curl; + CURLcode res; + + curl = curl_easy_init(); + if(curl) { + curl_easy_setopt(curl, CURLOPT_URL, "https://sourceforge.net/"); + +#ifdef SKIP_PEER_VERIFICATION + /* + * 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 + * verification of the server's certificate. This makes the connection + * A LOT LESS SECURE. + * + * If you have a CA cert for the server stored someplace else than in the + * default bundle, then the CURLOPT_CAPATH option might come handy for + * you. + */ + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE); +#endif + +#ifdef SKIP_HOSTNAME_VERFICATION + /* + * If the site you're connecting to uses a different host name that what + * they have mentioned in their server certificate's commonName (or + * subjectAltName) fields, libcurl will refuse to connect. You can skip + * this check, but this will make the connection less secure. + */ + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); +#endif + + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} -- cgit v1.2.1 From 47d52d4eca270c9aa211cf44ae31c8b54d29c10d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 13 May 2004 08:23:09 +0000 Subject: added https.c --- docs/examples/Makefile.am | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 69d9dff33..783455151 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -5,11 +5,10 @@ AUTOMAKE_OPTIONS = foreign no-dependencies EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ - persistant.c ftpget.c Makefile.example \ - multithread.c getinmemory.c ftpupload.c httpput.c \ - simplessl.c ftpgetresp.c http-post.c post-callback.c \ - multi-app.c multi-double.c multi-single.c multi-post.c \ - fopen.c simplepost.c makefile.dj curlx.c + persistant.c ftpget.c Makefile.example multithread.c getinmemory.c \ + ftpupload.c httpput.c simplessl.c ftpgetresp.c http-post.c \ + post-callback.c multi-app.c multi-double.c multi-single.c \ + multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c all: @echo "done" -- cgit v1.2.1 From 662cb303729cfb4f875ee3ed9486122e193cc16c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 19 May 2004 09:08:19 +0000 Subject: Set CURLOPT_USERAGENT too --- docs/examples/getinmemory.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index f7e27460f..c1b6e12d4 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -62,6 +62,10 @@ int main(int argc, char **argv) /* we pass our 'chunk' struct to the callback function */ curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk); + /* some servers don't like requests that are made withput a user-agent + field, so we provide one */ + curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0"); + /* get it! */ curl_easy_perform(curl_handle); -- cgit v1.2.1 From a94e117ede4712420a86ade19e6e74ee8b1046f3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 19 May 2004 09:09:31 +0000 Subject: language! --- docs/examples/getinmemory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index c1b6e12d4..10ce8551f 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -62,7 +62,7 @@ int main(int argc, char **argv) /* we pass our 'chunk' struct to the callback function */ curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk); - /* some servers don't like requests that are made withput a user-agent + /* some servers don't like requests that are made without a user-agent field, so we provide one */ curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0"); -- cgit v1.2.1 From 1adfe0fe182afe6507a35f5a7129183bb7b4a351 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 24 May 2004 15:12:37 +0000 Subject: multi interface, debug callback --- docs/examples/multi-debugcallback.c | 178 ++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 docs/examples/multi-debugcallback.c (limited to 'docs/examples') diff --git a/docs/examples/multi-debugcallback.c b/docs/examples/multi-debugcallback.c new file mode 100644 index 000000000..286267219 --- /dev/null +++ b/docs/examples/multi-debugcallback.c @@ -0,0 +1,178 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * This is a very simple example using the multi interface and the debug + * callback. + */ + +#include +#include + +/* somewhat unix-specific */ +#include +#include + +/* curl stuff */ +#include + +typedef char bool; +#define TRUE 1 + +static +void dump(const char *text, + FILE *stream, unsigned char *ptr, size_t size, + bool 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(stream, "%s, %zd bytes (0x%zx)\n", text, size, size); + + for(i=0; i=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', stream); /* newline */ + } + fflush(stream); +} + +static +int my_trace(CURL *handle, curl_infotype type, + unsigned char *data, size_t size, + void *userp) +{ + const char *text; + + (void)handle; /* prevent compiler warning */ + + 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_HEADER_IN: + text = "<= Recv header"; + break; + case CURLINFO_DATA_IN: + text = "<= Recv data"; + break; + } + + dump(text, stderr, data, size, TRUE); + return 0; +} + +/* + * Simply download a HTTP file. + */ +int main(int argc, char **argv) +{ + CURL *http_handle; + CURLM *multi_handle; + + int still_running; /* keep number of running handles */ + + http_handle = curl_easy_init(); + + /* set the options (I left out a few, you'll get the point anyway) */ + curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.haxx.se/"); + + curl_easy_setopt(http_handle, CURLOPT_DEBUGFUNCTION, my_trace); + curl_easy_setopt(http_handle, CURLOPT_VERBOSE, TRUE); + + /* init a multi stack */ + multi_handle = curl_multi_init(); + + /* add the individual transfers */ + curl_multi_add_handle(multi_handle, http_handle); + + /* we start some action by calling perform right away */ + while(CURLM_CALL_MULTI_PERFORM == + curl_multi_perform(multi_handle, &still_running)); + + while(still_running) { + struct timeval timeout; + int rc; /* select() return code */ + + fd_set fdread; + fd_set fdwrite; + fd_set fdexcep; + int maxfd; + + 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; + + /* get file descriptors from the transfers */ + curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); + + switch(rc) { + case -1: + /* select error */ + still_running = 0; + printf("select() returns error, this is badness\n"); + break; + case 0: + default: + /* timeout or readable/writable sockets */ + while(CURLM_CALL_MULTI_PERFORM == + curl_multi_perform(multi_handle, &still_running)); + break; + } + } + + curl_multi_cleanup(multi_handle); + + curl_easy_cleanup(http_handle); + + return 0; +} -- cgit v1.2.1 From 120394cc4585a0d79682a946c81c5084e1467249 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 24 May 2004 15:16:29 +0000 Subject: remove trailing whitespace --- docs/examples/multi-single.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c index b6ba0c5c0..0ba932f7a 100644 --- a/docs/examples/multi-single.c +++ b/docs/examples/multi-single.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ -- cgit v1.2.1 From 88229a0f2ab259ca7c42096eef188a4264aa03e9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 24 May 2004 15:16:53 +0000 Subject: new example proving that the debug callback works even when the multi interface is used --- docs/examples/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 783455151..e42a9600f 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -8,7 +8,8 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ persistant.c ftpget.c Makefile.example multithread.c getinmemory.c \ ftpupload.c httpput.c simplessl.c ftpgetresp.c http-post.c \ post-callback.c multi-app.c multi-double.c multi-single.c \ - multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c + multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c \ + multi-debugcallback.c all: @echo "done" -- cgit v1.2.1 From 459801d6e0e3d829f5c2eefcec189a1842ef7e37 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 26 May 2004 08:58:25 +0000 Subject: strip trailing whitespace --- docs/examples/ftpupload.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index d51e43c4d..e69ec2d00 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -46,7 +46,7 @@ int main(int argc, char **argv) close(hd) ; /* get a FILE * of the same file, could also be made with - fdopen() from the previous descriptor, but hey this is just + fdopen() from the previous descriptor, but hey this is just an example! */ hd_src = fopen(LOCAL_FILE, "rb"); -- cgit v1.2.1 From 15cd35f67fa76f6d043bdf8e53b64ebb56339d2a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 26 May 2004 09:00:03 +0000 Subject: added example that makes an upload to a file:// url --- docs/examples/Makefile.am | 2 +- docs/examples/fileupload.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 docs/examples/fileupload.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index e42a9600f..e81e4b840 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -9,7 +9,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ ftpupload.c httpput.c simplessl.c ftpgetresp.c http-post.c \ post-callback.c multi-app.c multi-double.c multi-single.c \ multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c \ - multi-debugcallback.c + multi-debugcallback.c fileupload.c all: @echo "done" diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c new file mode 100644 index 000000000..315c2a1b1 --- /dev/null +++ b/docs/examples/fileupload.c @@ -0,0 +1,65 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include +#include +#include +#include + +int main(void) +{ + CURL *curl; + CURLcode res; + curl_off_t size; + struct stat file_info; + double speed_upload, total_time; + FILE *fd; + + fd = fopen("debugit", "r"); /* open file to upload */ + if(!fd) { + + return 1; /* can't continue */ + } + + stat("debugit", &file_info); /* to get the file size */ + + curl = curl_easy_init(); + if(curl) { + /* upload to this place */ + curl_easy_setopt(curl, CURLOPT_URL, + "file:///home/dast/src/curl/debug/new"); + + /* tell it to "upload" to the URL */ + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1); + + /* set where to read from (on Windows you need to use READFUNCTION too) */ + curl_easy_setopt(curl, CURLOPT_READDATA, fd); + + /* and give the size of the upload (optional) */ + curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, + (curl_off_t)file_info.st_size); + + /* enable verbose for easier tracing */ + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + + res = curl_easy_perform(curl); + + /* now extract transfer info */ + curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload); + curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time); + + fprintf(stderr, "Speed: %.3f bytes/sec during %.3f seconds\n", + speed_upload, total_time); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} -- cgit v1.2.1 From 9e987ac6a29c37d88799ab7f09fc17c212f90baf Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 3 Jun 2004 09:20:48 +0000 Subject: getinfo.c is a new tiny example that uses curl_easy_getinfo() to get the content-type after a transfer. --- docs/examples/Makefile.am | 2 +- docs/examples/getinfo.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 docs/examples/getinfo.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index e81e4b840..b9419bce5 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -9,7 +9,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ ftpupload.c httpput.c simplessl.c ftpgetresp.c http-post.c \ post-callback.c multi-app.c multi-double.c multi-single.c \ multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c \ - multi-debugcallback.c fileupload.c + multi-debugcallback.c fileupload.c getinfo.c all: @echo "done" diff --git a/docs/examples/getinfo.c b/docs/examples/getinfo.c new file mode 100644 index 000000000..733262a3e --- /dev/null +++ b/docs/examples/getinfo.c @@ -0,0 +1,37 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include +#include + +int main(void) +{ + CURL *curl; + CURLcode res; + + curl = curl_easy_init(); + if(curl) { + curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); + res = curl_easy_perform(curl); + + if(CURLE_OK == res) { + char *ct; + /* ask for the content-type */ + res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct); + + if((CURLE_OK == res) && ct) + printf("We received Content-Type: %s\n", ct); + } + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} -- cgit v1.2.1 From 2e8f37aca56b2af3650f7f95fd3ffa840587ea91 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 3 Jun 2004 11:15:27 +0000 Subject: Added example of how to use the upcoming support for FTP 3rd party transfers --- docs/examples/Makefile.am | 2 +- docs/examples/ftp3rdparty.c | 104 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 docs/examples/ftp3rdparty.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index b9419bce5..7d7b239fa 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -9,7 +9,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ ftpupload.c httpput.c simplessl.c ftpgetresp.c http-post.c \ post-callback.c multi-app.c multi-double.c multi-single.c \ multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c \ - multi-debugcallback.c fileupload.c getinfo.c + multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c all: @echo "done" diff --git a/docs/examples/ftp3rdparty.c b/docs/examples/ftp3rdparty.c new file mode 100644 index 000000000..31391ba96 --- /dev/null +++ b/docs/examples/ftp3rdparty.c @@ -0,0 +1,104 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include + +#include +#include +#include + +/* + * This is an example showing how to transfer a file between two remote hosts. + */ + + + +int main(void) +{ + CURL *curl; + CURLcode res; + char sourceFileName[] = "/tmp/file"; + char targetFileName[] = "/tmp/curlTargetTest.dat"; + char sourceHost[] = "source"; + char targetHost[] = "target"; + char sourceUserPass[] = "user:pass"; + char targetUserPass[] = "user:pass"; + char url[100]; + + struct curl_slist *source_pre_cmd = NULL; + struct curl_slist *target_pre_cmd = NULL; + struct curl_slist *source_post_cmd = NULL; + struct curl_slist *target_post_cmd = NULL; + char cmd[] = "PWD"; /* just to test */ + + curl_global_init(CURL_GLOBAL_DEFAULT); + + curl = curl_easy_init(); + if (curl) { + sprintf(url, "ftp://%s@%s/%s", targetUserPass, targetHost, targetFileName); + printf("%s\n", url); + curl_easy_setopt(curl, CURLOPT_URL, url); + + /* Set a proxy host */ + curl_easy_setopt(curl, CURLOPT_SOURCE_HOST, sourceHost); + + /* Set a proxy user and password */ + curl_easy_setopt(curl, CURLOPT_SOURCE_USERPWD, sourceUserPass); + + /* Set a proxy full file name */ + curl_easy_setopt(curl, CURLOPT_SOURCE_PATH, sourceFileName); + + /* Set a proxy passive host */ + curl_easy_setopt(curl, CURLOPT_PASV_HOST, 0); /* optional */ + + /* build a list of commands to pass to libcurl */ + source_pre_cmd = curl_slist_append(source_pre_cmd, cmd); + /* Set a proxy pre-quote command */ + curl_easy_setopt(curl, CURLOPT_SOURCE_PREQUOTE, source_pre_cmd); + + /* build a list of commands to pass to libcurl */ + target_pre_cmd = curl_slist_append(target_pre_cmd, cmd); + /* Set a pre-quote command */ + curl_easy_setopt(curl, CURLOPT_PREQUOTE, target_pre_cmd); + + /* build a list of commands to pass to libcurl */ + source_post_cmd = curl_slist_append(source_post_cmd, cmd); + /* Set a proxy post-quote command */ + curl_easy_setopt(curl, CURLOPT_SOURCE_POSTQUOTE, source_post_cmd); + + /* build a list of commands to pass to libcurl */ + target_post_cmd = curl_slist_append(target_post_cmd, cmd); + /* Set a post-quote command */ + curl_easy_setopt(curl, CURLOPT_POSTQUOTE, target_post_cmd); + + /* Switch on full protocol/debug output */ + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + + res = curl_easy_perform(curl); + + /* clean up the FTP commands list */ + curl_slist_free_all(source_pre_cmd); + curl_slist_free_all(target_pre_cmd); + curl_slist_free_all(source_post_cmd); + curl_slist_free_all(target_post_cmd); + + /* always cleanup */ + curl_easy_cleanup(curl); + + if(CURLE_OK != res) { + /* we failed */ + fprintf(stderr, "curl told us %d\n", res); + } + } + + curl_global_cleanup(); + + return 0; +} -- cgit v1.2.1 From c81ac51e5c1063fb34c2f30ec14009a5b5d52099 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 29 Jun 2004 18:43:04 +0000 Subject: Gisle's update --- docs/examples/makefile.dj | 95 +++++++++++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 31 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/makefile.dj b/docs/examples/makefile.dj index 6b3cb9d39..642a5b090 100644 --- a/docs/examples/makefile.dj +++ b/docs/examples/makefile.dj @@ -1,31 +1,64 @@ -# -# Adapted for djgpp / Watt-32 / DOS by -# Gisle Vanem -# - -include ../../packages/DOS/common.dj - -CFLAGS += -I../../include - -LIBS = ../../lib/libcurl.a - -ifeq ($(USE_SSL),1) - LIBS += $(OPENSSL_ROOT)/lib/libssl.a $(OPENSSL_ROOT)/lib/libcrypt.a -endif - -LIBS += $(WATT32_ROOT)/lib/libwatt.a $(ZLIB_ROOT)/libz.a - -PROGRAMS = fopen.exe ftpget.exe ftpgetre.exe ftpuploa.exe getinmem.exe \ - http-pos.exe httpput.exe multi-ap.exe multi-do.exe \ - multi-po.exe multi-si.exe persista.exe post-cal.exe \ - postit2.exe sepheade.exe simple.exe simpless.exe - -all: $(PROGRAMS) - -.c.exe: - $(CC) $(CFLAGS) -o $@ $^ $(LIBS) - @echo - -clean: - rm -f $(PROGRAMS) - +# +# Adapted for djgpp / Watt-32 / DOS by +# Gisle Vanem +# + +include ../../packages/DOS/common.dj + +CFLAGS += -I../../include + +LIBS = ../../lib/libcurl.a + +ifeq ($(USE_SSL),1) + LIBS += $(OPENSSL_ROOT)/lib/libssl.a $(OPENSSL_ROOT)/lib/libcrypt.a +endif + +LIBS += $(WATT32_ROOT)/lib/libwatt.a $(ZLIB_ROOT)/libz.a + +PROGRAMS = fopen.exe ftpget.exe ftpgetre.exe ftpuploa.exe getinmem.exe \ + http-pos.exe httpput.exe multi-ap.exe multi-do.exe \ + multi-po.exe multi-si.exe persista.exe post-cal.exe \ + postit2.exe sepheade.exe simple.exe simpless.exe + +all: $(PROGRAMS) + +.c.exe: + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) + @echo + +clean: + rm -f $(PROGRAMS) + +- 1,32 ---- +# +# Adapted for djgpp / Watt-32 / DOS by +# Gisle Vanem +# + +include ../../packages/DOS/common.dj + +CFLAGS += -I../../include + +LIBS = ../../lib/libcurl.a + +ifeq ($(USE_SSL),1) + LIBS += $(OPENSSL_ROOT)/lib/libssl.a $(OPENSSL_ROOT)/lib/libcrypt.a +endif + +LIBS += $(WATT32_ROOT)/lib/libwatt.a $(ZLIB_ROOT)/libz.a + +PROGRAMS = fopen.exe ftpget.exe ftpgetre.exe ftpuploa.exe getinmem.exe \ + http-pos.exe httpput.exe multi-ap.exe multi-do.exe \ + multi-po.exe multi-si.exe persista.exe post-cal.exe \ + postit2.exe sepheade.exe simple.exe simpless.exe https.exe \ + ftp3rdpa.exe getinfo.exe + +all: $(PROGRAMS) + +%.exe: %.c + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) + @echo + +clean: + rm -f $(PROGRAMS) + -- cgit v1.2.1 From 574e91137569fda3d25fa86d19dec6c6b0580075 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 30 Jun 2004 12:34:33 +0000 Subject: Another Gisle update --- docs/examples/makefile.dj | 97 ++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 64 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/makefile.dj b/docs/examples/makefile.dj index 642a5b090..4200520be 100644 --- a/docs/examples/makefile.dj +++ b/docs/examples/makefile.dj @@ -1,64 +1,33 @@ -# -# Adapted for djgpp / Watt-32 / DOS by -# Gisle Vanem -# - -include ../../packages/DOS/common.dj - -CFLAGS += -I../../include - -LIBS = ../../lib/libcurl.a - -ifeq ($(USE_SSL),1) - LIBS += $(OPENSSL_ROOT)/lib/libssl.a $(OPENSSL_ROOT)/lib/libcrypt.a -endif - -LIBS += $(WATT32_ROOT)/lib/libwatt.a $(ZLIB_ROOT)/libz.a - -PROGRAMS = fopen.exe ftpget.exe ftpgetre.exe ftpuploa.exe getinmem.exe \ - http-pos.exe httpput.exe multi-ap.exe multi-do.exe \ - multi-po.exe multi-si.exe persista.exe post-cal.exe \ - postit2.exe sepheade.exe simple.exe simpless.exe - -all: $(PROGRAMS) - -.c.exe: - $(CC) $(CFLAGS) -o $@ $^ $(LIBS) - @echo - -clean: - rm -f $(PROGRAMS) - -- 1,32 ---- -# -# Adapted for djgpp / Watt-32 / DOS by -# Gisle Vanem -# - -include ../../packages/DOS/common.dj - -CFLAGS += -I../../include - -LIBS = ../../lib/libcurl.a - -ifeq ($(USE_SSL),1) - LIBS += $(OPENSSL_ROOT)/lib/libssl.a $(OPENSSL_ROOT)/lib/libcrypt.a -endif - -LIBS += $(WATT32_ROOT)/lib/libwatt.a $(ZLIB_ROOT)/libz.a - -PROGRAMS = fopen.exe ftpget.exe ftpgetre.exe ftpuploa.exe getinmem.exe \ - http-pos.exe httpput.exe multi-ap.exe multi-do.exe \ - multi-po.exe multi-si.exe persista.exe post-cal.exe \ - postit2.exe sepheade.exe simple.exe simpless.exe https.exe \ - ftp3rdpa.exe getinfo.exe - -all: $(PROGRAMS) - -%.exe: %.c - $(CC) $(CFLAGS) -o $@ $^ $(LIBS) - @echo - -clean: - rm -f $(PROGRAMS) - +# +# Adapted for djgpp / Watt-32 / DOS by +# Gisle Vanem +# + +include ../../packages/DOS/common.dj + +CFLAGS += -I../../include -DFALSE=0 -DTRUE=1 + +LIBS = ../../lib/libcurl.a + +ifeq ($(USE_SSL),1) + LIBS += $(OPENSSL_ROOT)/lib/libssl.a $(OPENSSL_ROOT)/lib/libcrypt.a +endif + +LIBS += $(WATT32_ROOT)/lib/libwatt.a $(ZLIB_ROOT)/libz.a + +PROGRAMS = fopen.exe ftpget.exe ftpgetresp.exe ftpupload.exe \ + getinmemory.exe http-post.exe httpput.exe multi-app.exe \ + multi-double.exe multi-post.exe multi-single.exe \ + persistant.exe post-callback.exe postit2.exe \ + sepheaders.exe simple.exe simplessl.exe https.exe \ + ftp3rdparty.exe getinfo.exe + +all: $(PROGRAMS) + +%.exe: %.c + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) + @echo + +clean: + rm -f $(PROGRAMS) + -- cgit v1.2.1 From cb8813522083672d408325a11300b91dffd806c3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 12 Aug 2004 07:01:20 +0000 Subject: removed trailing whitespace, indented to curl-style levels --- docs/examples/simplessl.c | 86 +++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 40 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index 781e06909..745d6e82c 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -71,42 +71,48 @@ int main(int argc, char **argv) while(1) /* do some ugly short cut... */ { - 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,1) != 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"); - 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"); - /* set the cert for client authentication */ - 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_SSLKEYPASSWD,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); - /* set the private key (file or ID in engine) */ - curl_easy_setopt(curl,CURLOPT_SSLKEY,pKeyName); - /* set the file with the certs vaildating the server */ - curl_easy_setopt(curl,CURLOPT_CAINFO,pCACertFile); - /* disconnect if we can't validate server's cert */ - curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,1); - - res = curl_easy_perform(curl); - break; /* we are done... */ + 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,1) != 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"); + 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"); + + /* set the cert for client authentication */ + 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_SSLKEYPASSWD,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); + + /* set the private key (file or ID in engine) */ + curl_easy_setopt(curl,CURLOPT_SSLKEY,pKeyName); + + /* set the file with the certs vaildating the server */ + curl_easy_setopt(curl,CURLOPT_CAINFO,pCACertFile); + + /* disconnect if we can't validate server's cert */ + curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,1); + + res = curl_easy_perform(curl); + break; /* we are done... */ } /* always cleanup */ curl_easy_cleanup(curl); -- cgit v1.2.1 From 4a4490d5f1fc711b9d402fc0b1be986430b3c797 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 23 Aug 2004 14:22:26 +0000 Subject: debug.c is a fresh new example showing how to use the DEBUGFUNCTION to get lots of fine info from a transfer --- docs/examples/Makefile.am | 2 +- docs/examples/debug.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 docs/examples/debug.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 7d7b239fa..6425707d8 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -9,7 +9,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ ftpupload.c httpput.c simplessl.c ftpgetresp.c http-post.c \ post-callback.c multi-app.c multi-double.c multi-single.c \ multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c \ - multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c + multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c debug.c all: @echo "done" diff --git a/docs/examples/debug.c b/docs/examples/debug.c new file mode 100644 index 000000000..153f3839e --- /dev/null +++ b/docs/examples/debug.c @@ -0,0 +1,128 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include +#include + +struct data { + char trace_ascii; /* 1 or 0 */ +}; + +static +void dump(const char *text, + FILE *stream, 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(stream, "%s, %zd bytes (0x%zx)\n", text, size, size); + + for(i=0; i=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', stream); /* newline */ + } + fflush(stream); +} + +static +int my_trace(CURL *handle, curl_infotype type, + unsigned char *data, size_t size, + void *userp) +{ + struct data *config = (struct data *)userp; + const char *text; + (void)handle; /* prevent compiler warning */ + + 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_HEADER_IN: + text = "<= Recv header"; + break; + case CURLINFO_DATA_IN: + text = "<= Recv data"; + break; + case CURLINFO_SSL_DATA_IN: + text = "<= Recv SSL data"; + break; + case CURLINFO_SSL_DATA_OUT: + text = "<= Send SSL data"; + break; + } + + dump(text, stderr, data, size, config->trace_ascii); + return 0; +} + +int main(void) +{ + CURL *curl; + CURLcode res; + struct data config; + + config.trace_ascii = 1; /* enable ascii tracing */ + + curl = curl_easy_init(); + if(curl) { + curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace); + curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &config); + + /* the DEBUGFUNCTION has no effect until we enable VERBOSE */ + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + + curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} -- cgit v1.2.1 From e8b295ff7d2d887b0a021914ec0d31c6f186200f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 23 Aug 2004 14:22:44 +0000 Subject: lost of more into on how to tweak some headers --- docs/examples/post-callback.c | 52 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 7 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index 76d1e1ba5..ecffce303 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -57,9 +57,6 @@ int main(void) /* Now specify we want to POST data */ curl_easy_setopt(curl, CURLOPT_POST, TRUE); - /* Set the expected POST size */ - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, pooh.sizeleft); - /* we want to use our own read function */ curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); @@ -69,6 +66,47 @@ int main(void) /* get verbose debug output please */ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + /* + If you use POST to a HTTP 1.1 server, you can send data without knowing + the size before starting the POST if you use chunked encoding. You + enable this by adding a header like "Transfer-Encoding: chunked" with + CURLOPT_HTTPHEADER. With HTTP 1.0 or without chunked transfer, you must + specify the size in the request. + */ +#ifdef USE_CHUNKED + { + curl_slist *chunk = NULL; + + chunk = curl_slist_append(chunk, "Transfer-Encoding: chunked"); + res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER); + /* use curl_slist_free_all() after the *perform() call to free this + list again */ + } +#else + /* Set the expected POST size. If you want to POST large amounts of data, + consider CURLOPT_POSTFIELDSIZE_LARGE */ + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, pooh.sizeleft); +#endif + +#ifdef DISABLE_EXPECT + /* + Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue" + header. You can disable this header with CURLOPT_HTTPHEADER as usual. + NOTE: if you want chunked transfer too, you need to combine these two + since you can only set one list of headers with CURLOPT_HTTPHEADER. */ + + /* A less good option would be to enforce HTTP 1.0, but that might also + have other implications. */ + { + curl_slist *chunk = NULL; + + chunk = curl_slist_append(chunk, "Expect:"); + res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER); + /* use curl_slist_free_all() after the *perform() call to free this + list again */ + } +#endif + /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); -- cgit v1.2.1 From d736ac51c047119c8d82df9f18b127cbcecc86c6 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 23 Aug 2004 14:22:52 +0000 Subject: stripped trailing whitespace --- docs/examples/ftpget.c | 16 ++++++++++------ docs/examples/postit2.c | 10 +++++----- docs/examples/simple.c | 8 ++++---- 3 files changed, 19 insertions(+), 15 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 2c2275fa5..0274b7f69 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -49,10 +49,14 @@ int main(void) }; curl_global_init(CURL_GLOBAL_DEFAULT); - + curl = curl_easy_init(); if(curl) { - /* Get curl 7.9.2 from sunet.se's FTP site: */ + /* + * Get curl 7.9.2 from sunet.se's FTP site. curl 7.9.2 is most likely not + * present there by the time you read this, so you'd better replace the + * URL with one that works! + */ curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.sunet.se/pub/www/utilities/curl/curl-7.9.2.tar.gz"); /* Define our callback to get called when there's data to be written */ diff --git a/docs/examples/postit2.c b/docs/examples/postit2.c index d1ecadd61..e022d284f 100644 --- a/docs/examples/postit2.c +++ b/docs/examples/postit2.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -53,7 +53,7 @@ int main(int argc, char *argv[]) CURLFORM_COPYNAME, "filename", CURLFORM_COPYCONTENTS, "postit2.c", CURLFORM_END); - + /* Fill in the submit field too, even if this is rarely needed */ curl_formadd(&formpost, diff --git a/docs/examples/simple.c b/docs/examples/simple.c index 1b93dd83b..baee2ce0d 100644 --- a/docs/examples/simple.c +++ b/docs/examples/simple.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ -- cgit v1.2.1 From 39af394a1c3ae1d8ac71ad263a7c524988702c2e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 6 Oct 2004 07:50:18 +0000 Subject: removed tabs and trailing whitespace from source --- docs/examples/curlx.c | 572 +++++++++++++++++++++++----------------------- docs/examples/fopen.c | 396 ++++++++++++++++---------------- docs/examples/multi-app.c | 24 +- 3 files changed, 496 insertions(+), 496 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index c5aabd344..2bb9a064d 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -1,4 +1,4 @@ -/* +/* curlx.c Authors: Peter Sylvester, Jean-Paul Merlin This is a little program to demonstrate the usage of @@ -6,7 +6,7 @@ - an ssl initialisation callback setting a user key and trustbases coming from a pkcs12 file - using an ssl application callback to find a URI in the - certificate presented during ssl session establishment. + certificate presented during ssl session establishment. */ @@ -20,13 +20,13 @@ * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, the following disclaimer, - * and the original OpenSSL and SSLeay Licences below. + * and the original OpenSSL and SSLeay Licences below. * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions, the following disclaimer + * notice, this list of conditions, the following disclaimer * and the original OpenSSL and SSLeay Licences below in * the documentation and/or other materials provided with the - * distribution. + * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgments: @@ -100,7 +100,7 @@ static char *curlx_usage[]={ " -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.openevidenve.org", +" -connect arg - URL of the server for the connection ex: www.openevidenve.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", @@ -109,7 +109,7 @@ NULL /* - ./curlx -p12 psy.p12 -envpass XX -in request -verbose -accesstype AD_DVCS + ./curlx -p12 psy.p12 -envpass XX -in request -verbose -accesstype AD_DVCS -mimetype application/dvcs -acceptmime application/dvcs -out response */ @@ -134,33 +134,33 @@ typedef struct sslctxparm_st { static char *i2s_ASN1_IA5STRING( ASN1_IA5STRING *ia5) { - char *tmp; - if(!ia5 || !ia5->length) return NULL; - tmp = OPENSSL_malloc(ia5->length + 1); - memcpy(tmp, ia5->data, ia5->length); - tmp[ia5->length] = 0; - return tmp; + char *tmp; + if(!ia5 || !ia5->length) return NULL; + tmp = OPENSSL_malloc(ia5->length + 1); + memcpy(tmp, ia5->data, ia5->length); + tmp[ia5->length] = 0; + return tmp; } /* A conveniance routine to get an access URI. */ 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) ; - - if (!sk_ACCESS_DESCRIPTION_num(accessinfo)) return NULL; - 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); - } - return NULL; - } - } - return NULL; + int i; + STACK_OF(ACCESS_DESCRIPTION) * accessinfo ; + accessinfo = X509_get_ext_d2i(cert, extensiontype, NULL, NULL) ; + + if (!sk_ACCESS_DESCRIPTION_num(accessinfo)) return NULL; + 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); + } + return NULL; + } + } + return NULL; } /* This is an application verification call back, it does not @@ -170,192 +170,192 @@ static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype) */ 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 ((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); - 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); - 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); + sslctxparm * p = (sslctxparm *) arg; + int ok; + + 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 (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); + } 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); + } + } + 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: - - a private key and certificate + - 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) { - - sslctxparm * p = (sslctxparm *) parm; - 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_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; - } - - 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(ctx->cert_store,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,NULL); - - SSL_CTX_set_cert_verify_callback(ctx, ssl_app_verify_callback, parm); - - - return CURLE_OK ; -err: - ERR_print_errors(p->errorbio); - return CURLE_SSL_CERTPROBLEM; + + sslctxparm * p = (sslctxparm *) parm; + 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_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; + } + + 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(ctx->cert_store,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,NULL); + + SSL_CTX_set_cert_verify_callback(ctx, ssl_app_verify_callback, parm); + + + return CURLE_OK ; +err: + ERR_print_errors(p->errorbio); + return CURLE_SSL_CERTPROBLEM; } int main(int argc, char **argv) { - BIO* in=NULL; - BIO* out=NULL; - - - char * outfile = NULL; - char * infile = NULL ; - - int tabLength=100; - char *binaryptr; - char* mimetype; - char* mimetypeaccept=NULL; - char* contenttype; - char** pp; - unsigned char* hostporturl = NULL; - binaryptr=(char*)malloc(tabLength); - BIO * p12bio ; - char **args = argv + 1; - unsigned char * serverurl; - sslctxparm p; - char *response; - p.verbose = 0; - - CURLcode res; - struct curl_slist * headers=NULL; - - p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); - - curl_global_init(CURL_GLOBAL_DEFAULT); - + BIO* in=NULL; + BIO* out=NULL; + + + char * outfile = NULL; + char * infile = NULL ; + + int tabLength=100; + char *binaryptr; + char* mimetype; + char* mimetypeaccept=NULL; + char* contenttype; + char** pp; + unsigned char* hostporturl = NULL; + binaryptr=(char*)malloc(tabLength); + BIO * p12bio ; + char **args = argv + 1; + unsigned char * serverurl; + sslctxparm p; + char *response; + p.verbose = 0; + + CURLcode res; + struct curl_slist * headers=NULL; + + p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); + + curl_global_init(CURL_GLOBAL_DEFAULT); + /* we need some more for the P12 decoding */ OpenSSL_add_all_ciphers(); - OpenSSL_add_all_digests(); - ERR_load_crypto_strings(); - - - int badarg=0; - - while (*args && *args[0] == '-') { - if (!strcmp (*args, "-in")) { - if (args[1]) { - infile=*(++args); - } else badarg=1; - } else if (!strcmp (*args, "-out")) { - if (args[1]) { - outfile=*(++args); - } 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]) { - p.pst = getenv(*(++args)); - } 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]) { - mimetype = *(++args); - } 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) { - p.verbose++; - } else badarg=1; - args++; - } - - 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"); - goto err; - } - - - - /* set input */ - - 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) { - BIO_printf(p.errorbio, "Error opening input file %s\n", infile); - BIO_free(in); - goto err; - } - - /* set output */ - - 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) { - BIO_printf(p.errorbio, "Error opening output file %s\n", outfile); - BIO_free(out); - goto err; - } - - - p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); - - if (!(p.curl = curl_easy_init())) { - BIO_printf(p.errorbio, "Cannot init curl lib\n"); - goto err; - } + OpenSSL_add_all_digests(); + ERR_load_crypto_strings(); + + + int badarg=0; + + while (*args && *args[0] == '-') { + if (!strcmp (*args, "-in")) { + if (args[1]) { + infile=*(++args); + } else badarg=1; + } else if (!strcmp (*args, "-out")) { + if (args[1]) { + outfile=*(++args); + } 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]) { + p.pst = getenv(*(++args)); + } 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]) { + mimetype = *(++args); + } 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) { + p.verbose++; + } else badarg=1; + args++; + } + + 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"); + goto err; + } + + + + /* set input */ + + 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) { + BIO_printf(p.errorbio, "Error opening input file %s\n", infile); + BIO_free(in); + goto err; + } + + /* set output */ + + 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) { + BIO_printf(p.errorbio, "Error opening output file %s\n", outfile); + BIO_free(out); + goto err; + } + + + p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); + + if (!(p.curl = curl_easy_init())) { + BIO_printf(p.errorbio, "Cannot init curl lib\n"); + goto err; + } @@ -365,112 +365,112 @@ int main(int argc, char **argv) { 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) ) )) { + + 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 (sk_X509_num(p.ca) <= 0) { + 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); - - /* determine URL to go */ - - if (hostporturl) { - serverurl=(char*) malloc(9+strlen(hostporturl)); - sprintf(serverurl,"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))) { - BIO_printf(p.errorbio,"no service URL in user cert cherching in others certificats\n"); - int j=0; - int find=0; - for (j=0;j\n", serverurl); - curl_easy_setopt(p.curl, CURLOPT_URL, serverurl); - - /* Now specify the POST binary data */ - - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); - - /* pass our list of custom made headers */ - - contenttype=(char*) malloc(15+strlen(mimetype)); - sprintf(contenttype,"Content-type: %s",mimetype); - headers = curl_slist_append(headers,contenttype); - curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers); - - if (p.verbose) BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); - - { - FILE *outfp; - BIO_get_fp(out,&outfp); - curl_easy_setopt(p.curl, CURLOPT_FILE,outfp); - } - - 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); - - 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 ) { - i+=lu; - if (i== tabLength) { - tabLength+=100; - binaryptr=(char*)realloc(binaryptr,tabLength); /* should be more careful */ - } - } - tabLength = i; - } - /* Now specify the POST binary data */ - - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); - - + } + + if (p.verbose > 1) X509_print_ex(p.errorbio,p.usercert,0,0); + + /* determine URL to go */ + + if (hostporturl) { + serverurl=(char*) malloc(9+strlen(hostporturl)); + sprintf(serverurl,"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))) { + BIO_printf(p.errorbio,"no service URL in user cert cherching in others certificats\n"); + int j=0; + int find=0; + for (j=0;j\n", serverurl); + curl_easy_setopt(p.curl, CURLOPT_URL, serverurl); + + /* Now specify the POST binary data */ + + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); + + /* pass our list of custom made headers */ + + contenttype=(char*) malloc(15+strlen(mimetype)); + sprintf(contenttype,"Content-type: %s",mimetype); + headers = curl_slist_append(headers,contenttype); + curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers); + + if (p.verbose) BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); + + { + FILE *outfp; + BIO_get_fp(out,&outfp); + curl_easy_setopt(p.curl, CURLOPT_FILE,outfp); + } + + 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); + + 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 ) { + i+=lu; + if (i== tabLength) { + tabLength+=100; + binaryptr=(char*)realloc(binaryptr,tabLength); /* should be more careful */ + } + } + tabLength = i; + } + /* Now specify the POST binary data */ + + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); + + /* Perform the request, res will get the return code */ - BIO_printf(p.errorbio,"%d %s %d\n", __LINE__, "curl_easy_perform", res = curl_easy_perform(p.curl)); + 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",response); - else - BIO_printf(p.errorbio,"the reponse doesn\'t has an acceptable mime type, it is %s instead of %s\n",response,mimetypeaccept); - } + 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 reponse doesn\'t has an acceptable mime type, it is %s instead of %s\n",response,mimetypeaccept); + } - /*** code d'erreur si accept mime ***, egalement code return HTTP != 200 ***/ + /*** code d'erreur si accept mime ***, egalement code return HTTP != 200 ***/ /* free the header list*/ curl_slist_free_all(headers); - + /* always cleanup */ curl_easy_cleanup(p.curl); - + BIO_free(in); BIO_free(out); return (EXIT_SUCCESS); - - + + err: BIO_printf(p.errorbio,"error"); exit(1); } diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index eb5501628..88729e72d 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -55,16 +55,16 @@ enum fcurl_type_e { CFTYPE_NONE=0, CFTYPE_FILE=1, CFTYPE_CURL=2 }; struct fcurl_data { - enum fcurl_type_e type; /* type of handle */ + enum fcurl_type_e type; /* type of handle */ union { - CURL *curl; - FILE *file; - } handle; /* handle */ - - char *buffer; /* buffer to store cached data*/ - int buffer_len; /* currently allocated buffers length */ - int buffer_pos; /* end of data in buffer*/ - int still_running; /* Is background url fetch still in progress */ + CURL *curl; + FILE *file; + } handle; /* handle */ + + char *buffer; /* buffer to store cached data*/ + int buffer_len; /* currently allocated buffers length */ + int buffer_pos; /* end of data in buffer*/ + int still_running; /* Is background url fetch still in progress */ }; typedef struct fcurl_data URL_FILE; @@ -83,9 +83,9 @@ CURLM *multi_handle; /* curl calls this routine to get more data */ static size_t write_callback(char *buffer, - size_t size, - size_t nitems, - void *userp) + size_t size, + size_t nitems, + void *userp) { char *newbuff; int rembuff; @@ -97,21 +97,21 @@ write_callback(char *buffer, if(size > rembuff) { - //not enuf space in buffer - newbuff=realloc(url->buffer,url->buffer_len + (size - rembuff)); - if(newbuff==NULL) - { - fprintf(stderr,"callback buffer grow failed\n"); - size=rembuff; - } - else - { - /* realloc suceeded increase buffer size*/ - url->buffer_len+=size - rembuff; - url->buffer=newbuff; - - /*printf("Callback buffer grown to %d bytes\n",url->buffer_len);*/ - } + //not enuf space in buffer + newbuff=realloc(url->buffer,url->buffer_len + (size - rembuff)); + if(newbuff==NULL) + { + fprintf(stderr,"callback buffer grow failed\n"); + size=rembuff; + } + else + { + /* realloc suceeded increase buffer size*/ + url->buffer_len+=size - rembuff; + url->buffer=newbuff; + + /*printf("Callback buffer grown to %d bytes\n",url->buffer_len);*/ + } } memcpy(&url->buffer[url->buffer_pos], buffer, size); @@ -137,42 +137,42 @@ curl_fill_buffer(URL_FILE *file,int want,int waittime) * doesnt exceed required size already */ if((!file->still_running) || (file->buffer_pos > want)) - return 0; + return 0; /* attempt to fill buffer */ do { - FD_ZERO(&fdread); - FD_ZERO(&fdwrite); - FD_ZERO(&fdexcep); + FD_ZERO(&fdread); + FD_ZERO(&fdwrite); + FD_ZERO(&fdexcep); - /* set a suitable timeout to fail on */ - timeout.tv_sec = 60; /* 1 minute */ - timeout.tv_usec = 0; + /* set a suitable timeout to fail on */ + timeout.tv_sec = 60; /* 1 minute */ + timeout.tv_usec = 0; - /* get file descriptors from the transfers */ - curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + /* get file descriptors from the transfers */ + curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); - rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); - switch(rc) { - case -1: - /* select error */ - break; + switch(rc) { + case -1: + /* select error */ + break; - case 0: - break; + case 0: + break; - default: - /* timeout or readable/writable sockets */ - /* note we *could* be more efficient and not wait for - * CURLM_CALL_MULTI_PERFORM to clear here and check it on re-entry - * but that gets messy */ - while(curl_multi_perform(multi_handle, &file->still_running) == - CURLM_CALL_MULTI_PERFORM); + default: + /* timeout or readable/writable sockets */ + /* note we *could* be more efficient and not wait for + * CURLM_CALL_MULTI_PERFORM to clear here and check it on re-entry + * but that gets messy */ + while(curl_multi_perform(multi_handle, &file->still_running) == + CURLM_CALL_MULTI_PERFORM); - break; - } + break; + } } while(file->still_running && (file->buffer_pos < want)); return 1; } @@ -184,22 +184,22 @@ curl_use_buffer(URL_FILE *file,int want) /* sort out buffer */ if((file->buffer_pos - want) <=0) { - /* ditch buffer - write will recreate */ - if(file->buffer) - free(file->buffer); + /* ditch buffer - write will recreate */ + if(file->buffer) + free(file->buffer); - file->buffer=NULL; - file->buffer_pos=0; - file->buffer_len=0; + file->buffer=NULL; + file->buffer_pos=0; + file->buffer_len=0; } else { - /* move rest down make it available for later */ - memmove(file->buffer, - &file->buffer[want], - (file->buffer_pos - want)); + /* move rest down make it available for later */ + memmove(file->buffer, + &file->buffer[want], + (file->buffer_pos - want)); - file->buffer_pos -= want; + file->buffer_pos -= want; } return 0; } @@ -217,47 +217,47 @@ url_fopen(char *url,const char *operation) file = (URL_FILE *)malloc(sizeof(URL_FILE)); if(!file) - return NULL; + return NULL; memset(file, 0, sizeof(URL_FILE)); if((file->handle.file=fopen(url,operation))) { - file->type = CFTYPE_FILE; /* marked as URL */ + file->type = CFTYPE_FILE; /* marked as URL */ } else { - file->type = CFTYPE_CURL; /* marked as URL */ - file->handle.curl = curl_easy_init(); + file->type = CFTYPE_CURL; /* marked as URL */ + file->handle.curl = curl_easy_init(); - curl_easy_setopt(file->handle.curl, CURLOPT_URL, url); - curl_easy_setopt(file->handle.curl, CURLOPT_WRITEDATA, file); - curl_easy_setopt(file->handle.curl, CURLOPT_VERBOSE, FALSE); - curl_easy_setopt(file->handle.curl, CURLOPT_WRITEFUNCTION, write_callback); + curl_easy_setopt(file->handle.curl, CURLOPT_URL, url); + curl_easy_setopt(file->handle.curl, CURLOPT_WRITEDATA, file); + curl_easy_setopt(file->handle.curl, CURLOPT_VERBOSE, FALSE); + curl_easy_setopt(file->handle.curl, CURLOPT_WRITEFUNCTION, write_callback); - if(!multi_handle) - multi_handle = curl_multi_init(); + if(!multi_handle) + multi_handle = curl_multi_init(); - curl_multi_add_handle(multi_handle, file->handle.curl); + curl_multi_add_handle(multi_handle, file->handle.curl); - /* lets start the fetch */ - while(curl_multi_perform(multi_handle, &file->still_running) == - CURLM_CALL_MULTI_PERFORM ); + /* lets start the fetch */ + while(curl_multi_perform(multi_handle, &file->still_running) == + CURLM_CALL_MULTI_PERFORM ); - if((file->buffer_pos == 0) && (!file->still_running)) - { - /* if still_running is 0 now, we should return NULL */ + if((file->buffer_pos == 0) && (!file->still_running)) + { + /* if still_running is 0 now, we should return NULL */ - /* make sure the easy handle is not in the multi handle anymore */ - curl_multi_remove_handle(multi_handle, file->handle.curl); + /* make sure the easy handle is not in the multi handle anymore */ + curl_multi_remove_handle(multi_handle, file->handle.curl); - /* cleanup */ - curl_easy_cleanup(file->handle.curl); + /* cleanup */ + curl_easy_cleanup(file->handle.curl); - free(file); + free(file); - file = NULL; - } + file = NULL; + } } return file; } @@ -270,26 +270,26 @@ url_fclose(URL_FILE *file) switch(file->type) { case CFTYPE_FILE: - ret=fclose(file->handle.file); /* passthrough */ - break; + ret=fclose(file->handle.file); /* passthrough */ + break; case CFTYPE_CURL: - /* make sure the easy handle is not in the multi handle anymore */ - curl_multi_remove_handle(multi_handle, file->handle.curl); + /* make sure the easy handle is not in the multi handle anymore */ + curl_multi_remove_handle(multi_handle, file->handle.curl); - /* cleanup */ - curl_easy_cleanup(file->handle.curl); - break; + /* cleanup */ + curl_easy_cleanup(file->handle.curl); + break; default: /* unknown or supported type - oh dear */ - ret=EOF; - errno=EBADF; - break; + ret=EOF; + errno=EBADF; + break; } if(file->buffer) - free(file->buffer);/* free any allocated buffer space */ + free(file->buffer);/* free any allocated buffer space */ free(file); @@ -304,17 +304,17 @@ url_feof(URL_FILE *file) switch(file->type) { case CFTYPE_FILE: - ret=feof(file->handle.file); - break; + ret=feof(file->handle.file); + break; case CFTYPE_CURL: - if((file->buffer_pos == 0) && (!file->still_running)) - ret = 1; - break; + if((file->buffer_pos == 0) && (!file->still_running)) + ret = 1; + break; default: /* unknown or supported type - oh dear */ - ret=-1; - errno=EBADF; - break; + ret=-1; + errno=EBADF; + break; } return ret; } @@ -327,38 +327,38 @@ 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); - break; + want=fread(ptr,size,nmemb,file->handle.file); + break; case CFTYPE_CURL: - want = nmemb * size; + want = nmemb * size; - curl_fill_buffer(file,want,1); + curl_fill_buffer(file,want,1); - /* check if theres data in the buffer - if not curl_fill_buffer() - * either errored or EOF */ - if(!file->buffer_pos) - return 0; + /* check if theres data in the buffer - if not curl_fill_buffer() + * either errored or EOF */ + if(!file->buffer_pos) + return 0; - /* ensure only available data is considered */ - if(file->buffer_pos < want) - want = file->buffer_pos; + /* ensure only available data is considered */ + if(file->buffer_pos < want) + want = file->buffer_pos; - /* xfer data to caller */ - memcpy(ptr, file->buffer, want); + /* xfer data to caller */ + memcpy(ptr, file->buffer, want); - curl_use_buffer(file,want); + curl_use_buffer(file,want); - want = want / size; /* number of items - nb correct op - checked - * with glibc code*/ + want = want / size; /* number of items - nb correct op - checked + * with glibc code*/ - /*printf("(fread) return %d bytes %d left\n", want,file->buffer_pos);*/ - break; + /*printf("(fread) return %d bytes %d left\n", want,file->buffer_pos);*/ + break; default: /* unknown or supported type - oh dear */ - want=0; - errno=EBADF; - break; + want=0; + errno=EBADF; + break; } return want; @@ -373,45 +373,45 @@ url_fgets(char *ptr, int size, URL_FILE *file) switch(file->type) { case CFTYPE_FILE: - ptr = fgets(ptr,size,file->handle.file); - break; + ptr = fgets(ptr,size,file->handle.file); + break; case CFTYPE_CURL: - curl_fill_buffer(file,want,1); + curl_fill_buffer(file,want,1); - /* check if theres data in the buffer - if not fill either errored or - * EOF */ - if(!file->buffer_pos) - return NULL; + /* check if theres data in the buffer - if not fill either errored or + * EOF */ + if(!file->buffer_pos) + return NULL; - /* ensure only available data is considered */ - if(file->buffer_pos < want) - want = file->buffer_pos; + /* ensure only available data is considered */ + if(file->buffer_pos < want) + want = file->buffer_pos; - /*buffer contains data */ - /* look for newline or eof */ - for(loop=0;loop < want;loop++) - { - if(file->buffer[loop] == '\n') - { - want=loop+1;/* include newline */ - break; - } - } + /*buffer contains data */ + /* look for newline or eof */ + for(loop=0;loop < want;loop++) + { + if(file->buffer[loop] == '\n') + { + want=loop+1;/* include newline */ + break; + } + } - /* xfer data to caller */ - memcpy(ptr, file->buffer, want); - ptr[want]=0;/* allways null terminate */ + /* xfer data to caller */ + memcpy(ptr, file->buffer, want); + ptr[want]=0;/* allways null terminate */ - curl_use_buffer(file,want); + curl_use_buffer(file,want); - /*printf("(fgets) return %d bytes %d left\n", want,file->buffer_pos);*/ - break; + /*printf("(fgets) return %d bytes %d left\n", want,file->buffer_pos);*/ + break; default: /* unknown or supported type - oh dear */ - ptr=NULL; - errno=EBADF; - break; + ptr=NULL; + errno=EBADF; + break; } return ptr;/*success */ @@ -423,28 +423,28 @@ url_rewind(URL_FILE *file) switch(file->type) { case CFTYPE_FILE: - rewind(file->handle.file); /* passthrough */ - break; + rewind(file->handle.file); /* passthrough */ + break; case CFTYPE_CURL: - /* halt transaction */ - curl_multi_remove_handle(multi_handle, file->handle.curl); + /* halt transaction */ + curl_multi_remove_handle(multi_handle, file->handle.curl); - /* restart */ - curl_multi_add_handle(multi_handle, file->handle.curl); + /* restart */ + curl_multi_add_handle(multi_handle, file->handle.curl); - /* ditch buffer - write will recreate - resets stream pos*/ - if(file->buffer) - free(file->buffer); + /* ditch buffer - write will recreate - resets stream pos*/ + if(file->buffer) + free(file->buffer); - file->buffer=NULL; - file->buffer_pos=0; - file->buffer_len=0; + file->buffer=NULL; + file->buffer_pos=0; + file->buffer_len=0; - break; + break; default: /* unknown or supported type - oh dear */ - break; + break; } @@ -466,33 +466,33 @@ main(int argc, char *argv[]) if(argc < 2) { - url="http://192.168.7.3/testfile";/* default to testurl */ + url="http://192.168.7.3/testfile";/* default to testurl */ } else { - url=argv[1];/* use passed url */ + url=argv[1];/* use passed url */ } /* copy from url line by line with fgets */ outf=fopen("fgets.test","w+"); if(!outf) { - perror("couldnt open fgets output file\n"); - return 1; + perror("couldnt open fgets output file\n"); + return 1; } handle = url_fopen(url, "r"); if(!handle) { - printf("couldn't url_fopen()\n"); - fclose(outf); - return 2; + printf("couldn't url_fopen()\n"); + fclose(outf); + return 2; } 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); @@ -504,20 +504,20 @@ main(int argc, char *argv[]) outf=fopen("fread.test","w+"); if(!outf) { - perror("couldnt open fread output file\n"); - return 1; + perror("couldnt open fread output file\n"); + return 1; } handle = url_fopen("testfile", "r"); if(!handle) { - printf("couldn't url_fopen()\n"); - fclose(outf); - return 2; + printf("couldn't url_fopen()\n"); + fclose(outf); + return 2; } do { - 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); } while(nread); url_fclose(handle); @@ -529,26 +529,26 @@ main(int argc, char *argv[]) outf=fopen("rewind.test","w+"); if(!outf) { - perror("couldnt open fread output file\n"); - return 1; + perror("couldnt open fread output file\n"); + return 1; } handle = url_fopen("testfile", "r"); if(!handle) { - printf("couldn't url_fopen()\n"); - fclose(outf); - return 2; + printf("couldn't url_fopen()\n"); + fclose(outf); + return 2; } - nread = url_fread(buffer, 1,sizeof(buffer), handle); - fwrite(buffer,1,nread,outf); - url_rewind(handle); + nread = url_fread(buffer, 1,sizeof(buffer), handle); + fwrite(buffer,1,nread,outf); + url_rewind(handle); - buffer[0]='\n'; - fwrite(buffer,1,1,outf); + buffer[0]='\n'; + fwrite(buffer,1,1,outf); - 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_fclose(handle); diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index 9e3d72703..ecb7e3814 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -24,9 +24,9 @@ * Download a HTTP file and upload an FTP file simultaneously. */ -#define HANDLECOUNT 2 /* Number of simultaneous transfers */ -#define HTTP_HANDLE 0 /* Index for the HTTP transfer */ -#define FTP_HANDLE 1 /* Index for the FTP transfer */ +#define HANDLECOUNT 2 /* Number of simultaneous transfers */ +#define HTTP_HANDLE 0 /* Index for the HTTP transfer */ +#define FTP_HANDLE 1 /* Index for the FTP transfer */ int main(int argc, char **argv) { @@ -111,11 +111,11 @@ int main(int argc, char **argv) switch (idx) { case HTTP_HANDLE: - printf("HTTP transfer completed with status %d\n", msg->data.result); - break; - case FTP_HANDLE: - printf("FTP transfer completed with status %d\n", msg->data.result); - break; + printf("HTTP transfer completed with status %d\n", msg->data.result); + break; + case FTP_HANDLE: + printf("FTP transfer completed with status %d\n", msg->data.result); + break; } } } -- cgit v1.2.1 From a91a75355d863e6aeb849f0de9169234217990bc Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Wed, 6 Oct 2004 13:24:08 +0000 Subject: *** empty log message *** --- docs/examples/multi-app.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index ecb7e3814..5383a40ae 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -98,8 +98,6 @@ int main(int argc, char **argv) } } - curl_multi_cleanup(multi_handle); - /* See how the transfers went */ while ((msg = curl_multi_info_read(multi_handle, &msgs_left))) { if (msg->msg == CURLMSG_DONE) { @@ -120,6 +118,8 @@ int main(int argc, char **argv) } } + curl_multi_cleanup(multi_handle); + /* Free the CURL handles */ for (i=0; i Date: Sat, 16 Oct 2004 13:17:15 +0000 Subject: Open "debugit" in binary mode ("rb"). --- docs/examples/fileupload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c index 315c2a1b1..455cb0ecf 100644 --- a/docs/examples/fileupload.c +++ b/docs/examples/fileupload.c @@ -22,7 +22,7 @@ int main(void) double speed_upload, total_time; FILE *fd; - fd = fopen("debugit", "r"); /* open file to upload */ + fd = fopen("debugit", "rb"); /* open file to upload */ if(!fd) { return 1; /* can't continue */ -- cgit v1.2.1 From 186f433e4038b697b40f66a293f0f15332d055c4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 2 Nov 2004 08:26:55 +0000 Subject: modified to not use realloc() on a NULL pointer --- docs/examples/getinmemory.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 10ce8551f..5a77e9c7e 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -24,13 +24,23 @@ struct MemoryStruct { size_t size; }; +void *myrealloc(void *ptr, size_t size) +{ + /* There might be a realloc() out there that doesn't like reallocing + NULL pointers, so we take care of it here */ + if(ptr) + return realloc(ptr, size); + else + return malloc(size); +} + size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) { register int realsize = size * nmemb; struct MemoryStruct *mem = (struct MemoryStruct *)data; - - mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1); + + mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1); if (mem->memory) { memcpy(&(mem->memory[mem->size]), ptr, realsize); mem->size += realsize; -- cgit v1.2.1 From 87753cda49b3f95087867ea7e0e134666b02ff92 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 16 Nov 2004 08:49:51 +0000 Subject: mention the openssl callbacks for SSL multithread --- docs/examples/multithread.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/multithread.c b/docs/examples/multithread.c index c3936ef4a..fc9a9a87c 100644 --- a/docs/examples/multithread.c +++ b/docs/examples/multithread.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -15,7 +15,15 @@ #include #include -/* silly list of test-URLs */ +/* + List of URLs to fetch. + + 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 + +*/ char *urls[]= { "http://curl.haxx.se/", "ftp://cool.haxx.se/", @@ -28,17 +36,15 @@ void *pull_one_url(void *url) CURL *curl; curl = curl_easy_init(); - curl_easy_setopt(curl, CURLOPT_URL, url); - curl_easy_perform(curl); - + curl_easy_perform(curl); /* ignores error */ curl_easy_cleanup(curl); return NULL; } -/* +/* int pthread_create(pthread_t *new_thread_ID, const pthread_attr_t *attr, void * (*start_func)(void *), void *arg); @@ -56,7 +62,7 @@ int main(int argc, char **argv) urls[i]); if(0 != error) fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error); - else + else fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]); } -- cgit v1.2.1 From e80f566a1489401f04e3ed1a08ccb456cf778954 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 21 Nov 2004 12:42:28 +0000 Subject: added comment for windows people about READFUNCTION being needed --- docs/examples/ftpupload.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index e69ec2d00..68b86fdf4 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -72,6 +72,12 @@ int main(int argc, char **argv) /* now specify which file to upload */ curl_easy_setopt(curl, CURLOPT_READDATA, hd_src); + /* NOTE: if you want this example to work on Windows with libcurl as a + DLL, you MUST also provide a read callback with + CURLOPT_READFUNCTION. Failing to do so will give you a crash since a + DLL may not use the variable's memory when passed in to it from an app + like this. */ + /* and give the size of the upload (optional) */ curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, file_info.st_size); -- cgit v1.2.1 From 855a9eff767e6aea52ecaea905bd8519c0ade944 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 22 Nov 2004 13:39:23 +0000 Subject: add URLs in comments for all libcurl function calls --- docs/examples/adddocsref.pl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 docs/examples/adddocsref.pl (limited to 'docs/examples') diff --git a/docs/examples/adddocsref.pl b/docs/examples/adddocsref.pl new file mode 100755 index 000000000..2dcc24b63 --- /dev/null +++ b/docs/examples/adddocsref.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl + +# pass files as argument(s) + +my $docroot="http://curl.haxx.se/libcurl/c"; + +for $f (@ARGV) { + open(NEW, ">$f.new"); + open(F, "<$f"); + while() { + my $l = $_; + if($l =~ /\/* $docroot/) { + # just ignore preciously added refs + } + elsif($l =~ /^( *).*curl_easy_setopt\([^,]*, *([^ ,]*) *,/) { + my ($prefix, $anc) = ($1, $2); + $anc =~ s/_//g; + print NEW "$prefix/* $docroot/curl_easy_setopt.html#$anc */\n"; + print NEW $l; + } + elsif($l =~ /^( *).*(curl_([^\(]*))\(/) { + my ($prefix, $func) = ($1, $2); + print NEW "$prefix/* $docroot/$func.html */\n"; + print NEW $l; + } + else { + print NEW $l; + } + } + close(F); + close(NEW); + + system("mv $f $f.org"); + system("mv $f.new $f"); +} -- cgit v1.2.1 From b7a6b78e0caaf7f59bdfe64cc8c27f765257b6a0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 22 Nov 2004 13:43:52 +0000 Subject: renamed curl_thread to my_thread to avoid confusion --- docs/examples/curlgtk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/curlgtk.c b/docs/examples/curlgtk.c index 69b016261..37c47f417 100644 --- a/docs/examples/curlgtk.c +++ b/docs/examples/curlgtk.c @@ -42,7 +42,7 @@ int my_progress_func(GtkWidget *Bar, return 0; } -void *curl_thread(void *ptr) +void *my_thread(void *ptr) { CURL *curl; CURLcode res; @@ -94,7 +94,7 @@ int main(int argc, char **argv) gtk_container_add(GTK_CONTAINER(Frame2), Bar); gtk_widget_show_all(Window); - if (!g_thread_create(&curl_thread, argv[1], FALSE, NULL) != 0) + if (!g_thread_create(&my_thread, argv[1], FALSE, NULL) != 0) g_warning("can't create the thread"); -- cgit v1.2.1 From 7f447134873959e3faca64070f7eb4be4d7708b1 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 22 Nov 2004 13:48:35 +0000 Subject: re-indented to curl style --- docs/examples/curlx.c | 676 ++++++++++++++++++++++++++------------------------ 1 file changed, 351 insertions(+), 325 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 2bb9a064d..1ee384ff2 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -4,9 +4,9 @@ This is a little program to demonstrate the usage of - an ssl initialisation callback setting a user key and trustbases - coming from a pkcs12 file + coming from a pkcs12 file - using an ssl application callback to find a URI in the - certificate presented during ssl session establishment. + certificate presented during ssl session establishment. */ @@ -95,38 +95,38 @@ #include static char *curlx_usage[]={ -"usage: curlx args\n", -" -p12 arg - tia file ", -" -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.openevidenve.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 + "usage: curlx args\n", + " -p12 arg - tia file ", + " -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.openevidenve.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 }; /* - ./curlx -p12 psy.p12 -envpass XX -in request -verbose -accesstype AD_DVCS - -mimetype application/dvcs -acceptmime application/dvcs -out response +./curlx -p12 psy.p12 -envpass XX -in request -verbose -accesstype AD_DVCS +-mimetype application/dvcs -acceptmime application/dvcs -out response */ /* 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 ; - CURL * curl; - BIO * errorbio; - int accesstype ; - int verbose; + unsigned char * p12file ; + const char * pst ; + PKCS12 * p12 ; + EVP_PKEY * pkey ; + X509 * usercert ; + STACK_OF(X509) * ca ; + CURL * curl; + BIO * errorbio; + int accesstype ; + int verbose; } sslctxparm; @@ -134,33 +134,35 @@ typedef struct sslctxparm_st { static char *i2s_ASN1_IA5STRING( ASN1_IA5STRING *ia5) { - char *tmp; - if(!ia5 || !ia5->length) return NULL; - tmp = OPENSSL_malloc(ia5->length + 1); - memcpy(tmp, ia5->data, ia5->length); - tmp[ia5->length] = 0; - return tmp; + char *tmp; + if(!ia5 || !ia5->length) + return NULL; + tmp = OPENSSL_malloc(ia5->length + 1); + memcpy(tmp, ia5->data, ia5->length); + tmp[ia5->length] = 0; + return tmp; } /* A conveniance routine to get an access URI. */ 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) ; - - if (!sk_ACCESS_DESCRIPTION_num(accessinfo)) return NULL; - 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); - } - return NULL; - } - } - return NULL; + int i; + STACK_OF(ACCESS_DESCRIPTION) * accessinfo ; + accessinfo = X509_get_ext_d2i(cert, extensiontype, NULL, NULL) ; + + if (!sk_ACCESS_DESCRIPTION_num(accessinfo)) + return NULL; + 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); + } + return NULL; + } + } + return NULL; } /* This is an application verification call back, it does not @@ -169,312 +171,336 @@ static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype) the URL to be used in the POST. */ -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 ((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); - 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); - 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); +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 ((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); + + 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); + + 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); } /* This is an example of an curl SSL initialisation call back. The callback sets: - - a private key and certificate - - a trusted ca certificate - - a preferred cipherlist - - an application verification callback (the function above) + - 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) { - sslctxparm * p = (sslctxparm *) parm; - SSL_CTX * ctx = (SSL_CTX *) sslctx ; + sslctxparm * p = (sslctxparm *) parm; + 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_PrivateKey(ctx,p->pkey)) { - BIO_printf(p->errorbio, "SSL_CTX_use_PrivateKey\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_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_mode(ctx, SSL_MODE_AUTO_RETRY); + 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(ctx->cert_store,sk_X509_value(p->ca,sk_X509_num(p->ca)-1)); + X509_STORE_add_cert(ctx->cert_store,sk_X509_value(p->ca, + sk_X509_num(p->ca)-1)); - SSL_CTX_set_verify_depth(ctx,2); + SSL_CTX_set_verify_depth(ctx,2); - SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,NULL); + SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,NULL); - SSL_CTX_set_cert_verify_callback(ctx, ssl_app_verify_callback, parm); + SSL_CTX_set_cert_verify_callback(ctx, ssl_app_verify_callback, parm); - return CURLE_OK ; -err: - ERR_print_errors(p->errorbio); - return CURLE_SSL_CERTPROBLEM; + return CURLE_OK ; + err: + ERR_print_errors(p->errorbio); + return CURLE_SSL_CERTPROBLEM; } int main(int argc, char **argv) { - BIO* in=NULL; - BIO* out=NULL; - - - char * outfile = NULL; - char * infile = NULL ; - - int tabLength=100; - char *binaryptr; - char* mimetype; - char* mimetypeaccept=NULL; - char* contenttype; - char** pp; - unsigned char* hostporturl = NULL; - binaryptr=(char*)malloc(tabLength); - BIO * p12bio ; - char **args = argv + 1; - unsigned char * serverurl; - sslctxparm p; - char *response; - p.verbose = 0; - - CURLcode res; - struct curl_slist * headers=NULL; - - p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); - - curl_global_init(CURL_GLOBAL_DEFAULT); - -/* we need some more for the P12 decoding */ - - OpenSSL_add_all_ciphers(); - OpenSSL_add_all_digests(); - ERR_load_crypto_strings(); - - - int badarg=0; - - while (*args && *args[0] == '-') { - if (!strcmp (*args, "-in")) { - if (args[1]) { - infile=*(++args); - } else badarg=1; - } else if (!strcmp (*args, "-out")) { - if (args[1]) { - outfile=*(++args); - } 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]) { - p.pst = getenv(*(++args)); - } 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]) { - mimetype = *(++args); - } 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) { - p.verbose++; - } else badarg=1; - args++; - } - - 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"); - goto err; - } - - - - /* set input */ - - 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) { - BIO_printf(p.errorbio, "Error opening input file %s\n", infile); - BIO_free(in); - goto err; - } - - /* set output */ - - 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) { - BIO_printf(p.errorbio, "Error opening output file %s\n", outfile); - BIO_free(out); - goto err; - } - - - p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); - - 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 (!(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 (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); - - /* determine URL to go */ - - if (hostporturl) { - serverurl=(char*) malloc(9+strlen(hostporturl)); - sprintf(serverurl,"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))) { - BIO_printf(p.errorbio,"no service URL in user cert cherching in others certificats\n"); - int j=0; - int find=0; - for (j=0;j\n", serverurl); - curl_easy_setopt(p.curl, CURLOPT_URL, serverurl); - - /* Now specify the POST binary data */ - - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); - - /* pass our list of custom made headers */ - - contenttype=(char*) malloc(15+strlen(mimetype)); - sprintf(contenttype,"Content-type: %s",mimetype); - headers = curl_slist_append(headers,contenttype); - curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers); - - if (p.verbose) BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); - - { - FILE *outfp; - BIO_get_fp(out,&outfp); - curl_easy_setopt(p.curl, CURLOPT_FILE,outfp); - } - - 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); - - 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 ) { - i+=lu; - if (i== tabLength) { - tabLength+=100; - binaryptr=(char*)realloc(binaryptr,tabLength); /* should be more careful */ - } - } - tabLength = i; - } - /* Now specify the POST binary data */ - - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); - - - /* Perform the request, res will get the return code */ - - 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",response); - else - BIO_printf(p.errorbio,"the reponse doesn\'t has an acceptable mime type, it is %s instead of %s\n",response,mimetypeaccept); - } - - /*** code d'erreur si accept mime ***, egalement code return HTTP != 200 ***/ - -/* free the header list*/ - - curl_slist_free_all(headers); - - /* always cleanup */ - curl_easy_cleanup(p.curl); - + BIO* in=NULL; + BIO* out=NULL; + + char * outfile = NULL; + char * infile = NULL ; + + int tabLength=100; + char *binaryptr; + char* mimetype; + char* mimetypeaccept=NULL; + char* contenttype; + char** pp; + unsigned char* hostporturl = NULL; + binaryptr=(char*)malloc(tabLength); + BIO * p12bio ; + char **args = argv + 1; + unsigned char * serverurl; + sslctxparm p; + char *response; + p.verbose = 0; + + CURLcode res; + struct curl_slist * headers=NULL; + + p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); + + curl_global_init(CURL_GLOBAL_DEFAULT); + + /* we need some more for the P12 decoding */ + + OpenSSL_add_all_ciphers(); + OpenSSL_add_all_digests(); + ERR_load_crypto_strings(); + + + int badarg=0; + + while (*args && *args[0] == '-') { + if (!strcmp (*args, "-in")) { + if (args[1]) { + infile=*(++args); + } else badarg=1; + } else if (!strcmp (*args, "-out")) { + if (args[1]) { + outfile=*(++args); + } 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]) { + p.pst = getenv(*(++args)); + } 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]) { + mimetype = *(++args); + } 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) { + p.verbose++; + } else badarg=1; + args++; + } + + 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"); + goto err; + } + + + + /* set input */ + + 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) { + BIO_printf(p.errorbio, "Error opening input file %s\n", infile); BIO_free(in); + goto err; + } + + /* set output */ + + 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) { + BIO_printf(p.errorbio, "Error opening output file %s\n", outfile); BIO_free(out); - return (EXIT_SUCCESS); + goto err; + } + + + p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); + + 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 (!(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 (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); + + /* determine URL to go */ + + if (hostporturl) { + serverurl=(char*) malloc(9+strlen(hostporturl)); + sprintf(serverurl,"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))) { + BIO_printf(p.errorbio,"no service URL in user cert " + "cherching in others certificats\n"); + int j=0; + int find=0; + for (j=0;j\n", serverurl); + + curl_easy_setopt(p.curl, CURLOPT_URL, serverurl); + + /* Now specify the POST binary data */ + + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); + + /* pass our list of custom made headers */ + + contenttype=(char*) malloc(15+strlen(mimetype)); + sprintf(contenttype,"Content-type: %s",mimetype); + headers = curl_slist_append(headers,contenttype); + curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers); + + if (p.verbose) + BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); + + { + FILE *outfp; + BIO_get_fp(out,&outfp); + curl_easy_setopt(p.curl, CURLOPT_FILE,outfp); + } + + 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); + + 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 ) { + i+=lu; + if (i== tabLength) { + tabLength+=100; + binaryptr=(char*)realloc(binaryptr,tabLength); /* should be more careful */ + } + } + tabLength = i; + } + /* Now specify the POST binary data */ + + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); + + + /* Perform the request, res will get the return code */ + + 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", + response); + else + BIO_printf(p.errorbio,"the reponse doesn\'t has an acceptable " + "mime type, it is %s instead of %s\n", + response,mimetypeaccept); + } + + /*** code d'erreur si accept mime ***, egalement code return HTTP != 200 ***/ +/* free the header list*/ - err: BIO_printf(p.errorbio,"error"); - exit(1); -} - + curl_slist_free_all(headers); + /* always cleanup */ + curl_easy_cleanup(p.curl); + BIO_free(in); + BIO_free(out); + return (EXIT_SUCCESS); + err: BIO_printf(p.errorbio,"error"); + exit(1); +} -- cgit v1.2.1 From 097d449cc1d4961b3a11b992e21c2c0ccb73106f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 22 Nov 2004 14:07:23 +0000 Subject: remove curl_ prefix from functions not present in libcurl --- docs/examples/fopen.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index 88729e72d..a2e6fc94a 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -124,7 +124,7 @@ write_callback(char *buffer, /* use to attempt to fill the read buffer up to requested number of bytes */ static int -curl_fill_buffer(URL_FILE *file,int want,int waittime) +fill_buffer(URL_FILE *file,int want,int waittime) { fd_set fdread; fd_set fdwrite; @@ -179,7 +179,7 @@ curl_fill_buffer(URL_FILE *file,int want,int waittime) /* use to remove want bytes from the front of a files buffer */ static int -curl_use_buffer(URL_FILE *file,int want) +use_buffer(URL_FILE *file,int want) { /* sort out buffer */ if((file->buffer_pos - want) <=0) @@ -333,9 +333,9 @@ url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) case CFTYPE_CURL: want = nmemb * size; - curl_fill_buffer(file,want,1); + fill_buffer(file,want,1); - /* check if theres data in the buffer - if not curl_fill_buffer() + /* check if theres data in the buffer - if not fill_buffer() * either errored or EOF */ if(!file->buffer_pos) return 0; @@ -347,7 +347,7 @@ url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) /* xfer data to caller */ memcpy(ptr, file->buffer, want); - curl_use_buffer(file,want); + use_buffer(file,want); want = want / size; /* number of items - nb correct op - checked * with glibc code*/ @@ -377,7 +377,7 @@ url_fgets(char *ptr, int size, URL_FILE *file) break; case CFTYPE_CURL: - curl_fill_buffer(file,want,1); + fill_buffer(file,want,1); /* check if theres data in the buffer - if not fill either errored or * EOF */ @@ -403,7 +403,7 @@ url_fgets(char *ptr, int size, URL_FILE *file) memcpy(ptr, file->buffer, want); ptr[want]=0;/* allways null terminate */ - curl_use_buffer(file,want); + use_buffer(file,want); /*printf("(fgets) return %d bytes %d left\n", want,file->buffer_pos);*/ break; -- cgit v1.2.1 From b3572269a42db0e9e5e3f68c3166f454e4e7df3c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 22 Nov 2004 14:41:24 +0000 Subject: removed unused variable and trailing whitespace --- docs/examples/httpput.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index 3b3fac136..d4b7dd5af 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -39,7 +39,6 @@ int main(int argc, char **argv) { CURL *curl; CURLcode res; - FILE *ftpfile; FILE * hd_src ; int hd ; struct stat file_info; @@ -49,17 +48,17 @@ int main(int argc, char **argv) if(argc < 3) return 1; - + file= argv[1]; url = argv[2]; - + /* get the file size of the local file */ hd = open(file, O_RDONLY) ; fstat(hd, &file_info); close(hd) ; /* get a FILE * of the same file, could also be made with - fdopen() from the previous descriptor, but hey this is just + fdopen() from the previous descriptor, but hey this is just an example! */ hd_src = fopen(file, "rb"); -- cgit v1.2.1 From 4207ef3d272513913785bd72c4686299f79cdcc4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 22 Nov 2004 14:41:36 +0000 Subject: removed trailing whitespace --- docs/examples/http-post.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/http-post.c b/docs/examples/http-post.c index 1b4154fbf..30ca3536b 100644 --- a/docs/examples/http-post.c +++ b/docs/examples/http-post.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ -- cgit v1.2.1 From f84d2b4d361412e3c0a49369ec0299c9e618d4ac Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 22 Nov 2004 16:24:46 +0000 Subject: trying a version with URLs for all function calls --- docs/examples/getinfo.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/getinfo.c b/docs/examples/getinfo.c index 733262a3e..eb0cae31f 100644 --- a/docs/examples/getinfo.c +++ b/docs/examples/getinfo.c @@ -16,14 +16,18 @@ 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, "curl.haxx.se"); + /* 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) @@ -31,6 +35,7 @@ int main(void) } /* always cleanup */ + /* http://curl.haxx.se/libcurl/c/curl_easy_cleanup.html */ curl_easy_cleanup(curl); } return 0; -- cgit v1.2.1 From 3e1caa61859a6057a65eb7c1585d47e05026c4f2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 24 Nov 2004 16:11:35 +0000 Subject: HTTP "auth done right". See lib/README.httpauth --- docs/examples/Makefile.am | 3 +- docs/examples/README | 39 ++++++++++++- docs/examples/anyauthput.c | 135 +++++++++++++++++++++++++++++++++++++++++++++ docs/examples/https.c | 8 +-- docs/examples/multi-post.c | 8 +-- docs/examples/persistant.c | 8 +-- docs/examples/simplepost.c | 8 +-- 7 files changed, 191 insertions(+), 18 deletions(-) create mode 100644 docs/examples/anyauthput.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 6425707d8..34ac520a7 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -9,7 +9,8 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ ftpupload.c httpput.c simplessl.c ftpgetresp.c http-post.c \ post-callback.c multi-app.c multi-double.c multi-single.c \ multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c \ - multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c debug.c + multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c debug.c \ + anyauthput.c all: @echo "done" diff --git a/docs/examples/README b/docs/examples/README index dd053d8f0..9951241c5 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -1,4 +1,8 @@ -EXAMPLES + _ _ ____ _ + ___| | | | _ \| | + / __| | | | |_) | | + | (__| |_| | _ <| |___ + \___|\___/|_| \_\_____| This directory is for libcurl programming examples. They are meant to show some simple steps on how you can build your own application to take full @@ -7,6 +11,8 @@ advantage of libcurl. If you end up with other small but still useful example sources, please mail them for submission in future packages and on the web site. +BUILDING + The Makefile.example is an example makefile that could be used to build these examples. Just edit the file according to your system and requirements first. @@ -23,3 +29,34 @@ want you do reorganize them like: applications/experiments. Even if the examples in this directory use that site as an example URL at some places, it doesn't mean that the URLs work or that we expect you to actually torture our web site with your tests! Thanks. + +EXAMPLES + +anyauthput.c - HTTP PUT using "any" authentication method +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 +ftp3rdparty.c - FTP 3rd party transfer +ftpget.c - simple getting a file from FTP +ftpgetresp.c - get the response strings from the FTP server +ftpupload.c - upload a file to a FTP server +getinfo.c - get the Content-Type from the recent transfer +getinmemory.c - download a file to memory only +http-post.c - HTTP POST +httpput.c - HTTP PUT a local file +https.c - simple HTTPS 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 +multithread.c - an example using multi-treading transfering multiple files +persistant.c - request two URLs with a persistant connection +post-callback.c - send a HTTP POST using a callback +postit2.c - send a HTTP multipart formpost +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 diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c new file mode 100644 index 000000000..c5486333e --- /dev/null +++ b/docs/examples/anyauthput.c @@ -0,0 +1,135 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include +#include +#include + +#include + +#if LIBCURL_VERSION_NUM < 0x070c03 +#error "upgrade your libcurl to no less than 7.12.3" +#endif + +/* + * This example shows a HTTP PUT operation with authentiction using "any" + * type. It PUTs a file given as a command line argument to the URL also given + * on the command line. + * + * Since libcurl 7.12.3, using "any" auth and POST/PUT requires a set ioctl + * function. + * + * This example also uses its own read callback. + */ + +/* ioctl callback function */ +static curlioerr my_ioctl(CURL *handle, curliocmd cmd, void *userp) +{ + int fd = (int)userp; + + (void)handle; /* not used in here */ + + switch(cmd) { + case CURLIOCMD_RESTARTREAD: + /* mr libcurl kindly asks as to rewind the read data stream to start */ + if(-1 == lseek(fd, 0, SEEK_SET)) + /* couldn't rewind */ + return CURLIOE_FAILRESTART; + + break; + + default: /* ignore unknown commands */ + return CURLIOE_UNKNOWNCMD; + } + return CURLIOE_OK; /* success! */ +} + +/* read callback function, fread() look alike */ +size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) +{ + size_t retcode; + + int fd = (int)stream; + + retcode = read(fd, ptr, size * nmemb); + + fprintf(stderr, "*** We read %d bytes from file\n", retcode); + + return retcode; +} + +int main(int argc, char **argv) +{ + CURL *curl; + CURLcode res; + int hd ; + struct stat file_info; + + char *file; + char *url; + + if(argc < 3) + return 1; + + file= argv[1]; + url = argv[2]; + + /* get the file size of the local file */ + hd = open(file, O_RDONLY) ; + fstat(hd, &file_info); + + /* In windows, this will init the winsock stuff */ + curl_global_init(CURL_GLOBAL_ALL); + + /* get a curl handle */ + curl = curl_easy_init(); + if(curl) { + /* we want to use our own read function */ + curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); + + /* which file to upload */ + curl_easy_setopt(curl, CURLOPT_READDATA, 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, hd); + + /* enable "uploading" (which means PUT when doing HTTP) */ + curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ; + + /* 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); + + /* and give the size of the upload, this supports large file sizes + on systems that have general support for it */ + curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, file_info.st_size); + + /* tell libcurl we can use "any" auth, which lets the lib pick one, but it + also costs one extra round-trip and possibly sending of all the PUT + data twice!!! */ + curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); + + /* set user name and password for the authentication */ + curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password"); + + /* Now run off and do what you've been told! */ + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + close(hd); /* close the local file */ + + curl_global_cleanup(); + return 0; +} diff --git a/docs/examples/https.c b/docs/examples/https.c index 9ce5a308b..8ce7c0b3a 100644 --- a/docs/examples/https.c +++ b/docs/examples/https.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index b5a436449..0f9a599ac 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ diff --git a/docs/examples/persistant.c b/docs/examples/persistant.c index 0a17031b8..673889914 100644 --- a/docs/examples/persistant.c +++ b/docs/examples/persistant.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ diff --git a/docs/examples/simplepost.c b/docs/examples/simplepost.c index 57c1f61d7..1d156c583 100644 --- a/docs/examples/simplepost.c +++ b/docs/examples/simplepost.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ -- cgit v1.2.1 From f0e66d8c76dc53ab9046f82e14ff9785b439a9da Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Fri, 26 Nov 2004 15:04:15 +0000 Subject: Added anyauthput.exe. --- docs/examples/makefile.dj | 66 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/makefile.dj b/docs/examples/makefile.dj index 4200520be..35e53d381 100644 --- a/docs/examples/makefile.dj +++ b/docs/examples/makefile.dj @@ -1,33 +1,33 @@ -# -# Adapted for djgpp / Watt-32 / DOS by -# Gisle Vanem -# - -include ../../packages/DOS/common.dj - -CFLAGS += -I../../include -DFALSE=0 -DTRUE=1 - -LIBS = ../../lib/libcurl.a - -ifeq ($(USE_SSL),1) - LIBS += $(OPENSSL_ROOT)/lib/libssl.a $(OPENSSL_ROOT)/lib/libcrypt.a -endif - -LIBS += $(WATT32_ROOT)/lib/libwatt.a $(ZLIB_ROOT)/libz.a - -PROGRAMS = fopen.exe ftpget.exe ftpgetresp.exe ftpupload.exe \ - getinmemory.exe http-post.exe httpput.exe multi-app.exe \ - multi-double.exe multi-post.exe multi-single.exe \ - persistant.exe post-callback.exe postit2.exe \ - sepheaders.exe simple.exe simplessl.exe https.exe \ - ftp3rdparty.exe getinfo.exe - -all: $(PROGRAMS) - -%.exe: %.c - $(CC) $(CFLAGS) -o $@ $^ $(LIBS) - @echo - -clean: - rm -f $(PROGRAMS) - +# +# Adapted for djgpp / Watt-32 / DOS by +# Gisle Vanem +# + +include ../../packages/DOS/common.dj + +CFLAGS += -I../../include -DFALSE=0 -DTRUE=1 + +LIBS = ../../lib/libcurl.a + +ifeq ($(USE_SSL),1) + LIBS += $(OPENSSL_ROOT)/lib/libssl.a $(OPENSSL_ROOT)/lib/libcrypt.a +endif + +LIBS += $(WATT32_ROOT)/lib/libwatt.a $(ZLIB_ROOT)/libz.a + +PROGRAMS = fopen.exe ftpget.exe ftpgetresp.exe ftpupload.exe \ + getinmemory.exe http-post.exe httpput.exe multi-app.exe \ + multi-double.exe multi-post.exe multi-single.exe \ + persistant.exe post-callback.exe postit2.exe \ + sepheaders.exe simple.exe simplessl.exe https.exe \ + ftp3rdparty.exe getinfo.exe anyauthput.exe + +all: $(PROGRAMS) + +%.exe: %.c + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) + @echo + +clean: + rm -f $(PROGRAMS) + -- cgit v1.2.1 From 2fe3829e5eafe2659a9ce32ad6532a1b037d3485 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 19 Jan 2005 10:09:15 +0000 Subject: add a URL to an article about making Apache support PUT --- docs/examples/httpput.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index d4b7dd5af..162a6b0d8 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -19,6 +19,9 @@ * line argument to the URL also given on the command line. * * This example also uses its own read callback. + * + * Here's an article on how to setup a PUT handler for Apache: + * http://www.apacheweek.com/features/put */ size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) -- cgit v1.2.1 From 8dd799b4bddc21f55b0ebc746ca00fba3bccafea Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 20 Jan 2005 14:24:56 +0000 Subject: If you give a *_LARGE option you MUST make sure that the type of the passed-in argument is a curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must make sure that to pass in a type 'long' argument. */ --- docs/examples/ftpupload.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index 68b86fdf4..c0ae40a26 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -78,8 +78,12 @@ int main(int argc, char **argv) DLL may not use the variable's memory when passed in to it from an app like this. */ - /* and give the size of the upload (optional) */ - curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, file_info.st_size); + /* Set the size of the file to upload (optional). If you give a *_LARGE + option you MUST make sure that the type of the passed-in argument is a + curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must + make sure that to pass in a type 'long' argument. */ + curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, + (curl_off_t)file_info.st_size); /* Now run off and do what you've been told! */ res = curl_easy_perform(curl); -- cgit v1.2.1 From 7e42cb61f75890832792c082510ec610f4c32cbe Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 21 Jan 2005 09:32:32 +0000 Subject: FTP third transfer support overhaul. See CHANGES for details. --- docs/examples/ftp3rdparty.c | 47 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/ftp3rdparty.c b/docs/examples/ftp3rdparty.c index 31391ba96..b4756f580 100644 --- a/docs/examples/ftp3rdparty.c +++ b/docs/examples/ftp3rdparty.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -16,22 +16,20 @@ /* * This is an example showing how to transfer a file between two remote hosts. + * 7.13.0 or later required. */ - - int main(void) { CURL *curl; CURLcode res; - char sourceFileName[] = "/tmp/file"; - char targetFileName[] = "/tmp/curlTargetTest.dat"; - char sourceHost[] = "source"; - char targetHost[] = "target"; + char source_url[] = "ftp://remotehost.com/path/to/source"; + char target_url[] = "ftp://aotherserver.com/path/to/dest"; + char sourceUserPass[] = "user:pass"; char targetUserPass[] = "user:pass"; char url[100]; - + struct curl_slist *source_pre_cmd = NULL; struct curl_slist *target_pre_cmd = NULL; struct curl_slist *source_post_cmd = NULL; @@ -39,24 +37,25 @@ int main(void) char cmd[] = "PWD"; /* just to test */ curl_global_init(CURL_GLOBAL_DEFAULT); - + curl = curl_easy_init(); if (curl) { - sprintf(url, "ftp://%s@%s/%s", targetUserPass, targetHost, targetFileName); - printf("%s\n", url); - curl_easy_setopt(curl, CURLOPT_URL, url); + /* The ordinary URL is the target when speaking 3rd party transfers */ + curl_easy_setopt(curl, CURLOPT_URL, target_url); - /* Set a proxy host */ - curl_easy_setopt(curl, CURLOPT_SOURCE_HOST, sourceHost); + /* Set a source URL */ + curl_easy_setopt(curl, CURLOPT_SOURCE_URL, source_url); - /* Set a proxy user and password */ - curl_easy_setopt(curl, CURLOPT_SOURCE_USERPWD, sourceUserPass); + /* Set target user and password */ + curl_easy_setopt(curl, CURLOPT_USERPWD, targetUserPass); - /* Set a proxy full file name */ - curl_easy_setopt(curl, CURLOPT_SOURCE_PATH, sourceFileName); + /* Set source user and password */ + curl_easy_setopt(curl, CURLOPT_SOURCE_USERPWD, sourceUserPass); - /* Set a proxy passive host */ - curl_easy_setopt(curl, CURLOPT_PASV_HOST, 0); /* optional */ +#if 0 + /* FTPPORT enables PORT on the target side, instead of PASV. */ + curl_easy_setopt(curl, CURLOPT_FTPPORT, ""); /* optional */ +#endif /* build a list of commands to pass to libcurl */ source_pre_cmd = curl_slist_append(source_pre_cmd, cmd); @@ -77,7 +76,7 @@ int main(void) target_post_cmd = curl_slist_append(target_post_cmd, cmd); /* Set a post-quote command */ curl_easy_setopt(curl, CURLOPT_POSTQUOTE, target_post_cmd); - + /* Switch on full protocol/debug output */ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); -- cgit v1.2.1 From 883343ba63a376ce9326149b0476262993d73b08 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 31 Jan 2005 18:22:40 +0000 Subject: HTML parsing (with libxml) example code by Lars Nilsson. --- docs/examples/Makefile.am | 2 +- docs/examples/htmltitle.cc | 297 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 298 insertions(+), 1 deletion(-) create mode 100644 docs/examples/htmltitle.cc (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 34ac520a7..f9b2939c4 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -10,7 +10,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ post-callback.c multi-app.c multi-double.c multi-single.c \ multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c \ multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c debug.c \ - anyauthput.c + anyauthput.c htmltitle.cc all: @echo "done" diff --git a/docs/examples/htmltitle.cc b/docs/examples/htmltitle.cc new file mode 100644 index 000000000..7d0cc4c3c --- /dev/null +++ b/docs/examples/htmltitle.cc @@ -0,0 +1,297 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +// Get a web page, parse it with libxml. +// +// Written by Lars Nilsson +// +// GNU C++ compile command line suggestion (edit paths accordingly): +// +// g++ -Wall -I/opt/curl/include -I/opt/libxml/include/libxml2 htmltitle.cc \ +// -o htmltitle -L/opt/curl/lib -L/opt/libxml/lib -lcurl -lxml2 + +#include +#include +#include +#include +#include +#include + +// +// Case-insensitive string comparison +// + +#ifdef _MSC_VER +#define COMPARE(a, b) (!stricmp((a), (b))) +#else +#define COMPARE(a, b) (!strcasecmp((a), (b))) +#endif + +// +// libxml callback context structure +// + +struct Context +{ + Context(): addTitle(false) { } + + bool addTitle; + std::string title; +}; + +// +// libcurl variables for error strings and returned data + +static char errorBuffer[CURL_ERROR_SIZE]; +static std::string buffer; + +// +// libcurl write callback function +// + +static int writer(char *data, size_t size, size_t nmemb, + std::string *writerData) +{ + if (writerData == NULL) + return 0; + + writerData->append(data, size*nmemb); + + return size * nmemb; +} + +// +// libcurl connection initialization +// + +static bool init(CURL *&conn, char *url) +{ + CURLcode code; + + conn = curl_easy_init(); + + if (conn == NULL) + { + fprintf(stderr, "Failed to create CURL connection\n"); + + exit(EXIT_FAILURE); + } + + code = curl_easy_setopt(conn, CURLOPT_ERRORBUFFER, errorBuffer); + if (code != CURLE_OK) + { + fprintf(stderr, "Failed to set error buffer [%d]\n", code); + + return false; + } + + code = curl_easy_setopt(conn, CURLOPT_URL, url); + if (code != CURLE_OK) + { + fprintf(stderr, "Failed to set URL [%s]\n", errorBuffer); + + return false; + } + + code = curl_easy_setopt(conn, CURLOPT_FOLLOWLOCATION, 1); + if (code != CURLE_OK) + { + fprintf(stderr, "Failed to set redirect option [%s]\n", errorBuffer); + + return false; + } + + code = curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writer); + if (code != CURLE_OK) + { + fprintf(stderr, "Failed to set writer [%s]\n", errorBuffer); + + return false; + } + + code = curl_easy_setopt(conn, CURLOPT_WRITEDATA, &buffer); + if (code != CURLE_OK) + { + fprintf(stderr, "Failed to set write data [%s]\n", errorBuffer); + + return false; + } + + return true; +} + +// +// libxml start element callback function +// + +static void startElement(void *voidContext, + const xmlChar *name, + const xmlChar **attributes) +{ + Context *context = (Context *)voidContext; + + if (COMPARE((char *)name, "TITLE")) + { + context->title = ""; + context->addTitle = true; + } +} + +// +// libxml end element callback function +// + +static void endElement(void *voidContext, + const xmlChar *name) +{ + Context *context = (Context *)voidContext; + + if (COMPARE((char *)name, "TITLE")) + context->addTitle = false; +} + +// +// Text handling helper function +// + +static void handleCharacters(Context *context, + const xmlChar *chars, + int length) +{ + if (context->addTitle) + context->title.append((char *)chars, length); +} + +// +// libxml PCDATA callback function +// + +static void characters(void *voidContext, + const xmlChar *chars, + int length) +{ + Context *context = (Context *)voidContext; + + handleCharacters(context, chars, length); +} + +// +// libxml CDATA callback function +// + +static void cdata(void *voidContext, + const xmlChar *chars, + int length) +{ + Context *context = (Context *)voidContext; + + handleCharacters(context, chars, length); +} + +// +// libxml SAX callback structure +// + +static htmlSAXHandler saxHandler = +{ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + startElement, + endElement, + NULL, + characters, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + cdata, + NULL +}; + +// +// Parse given (assumed to be) HTML text and return the title +// + +static void parseHtml(const std::string &html, + std::string &title) +{ + htmlParserCtxtPtr ctxt; + Context context; + + ctxt = htmlCreatePushParserCtxt(&saxHandler, &context, "", 0, "", + XML_CHAR_ENCODING_NONE); + + htmlParseChunk(ctxt, html.c_str(), html.size(), 0); + htmlParseChunk(ctxt, "", 0, 1); + + htmlFreeParserCtxt(ctxt); + + title = context.title; +} + +int main(int argc, char *argv[]) +{ + CURL *conn = NULL; + CURLcode code; + std::string title; + + // Ensure one argument is given + + if (argc != 2) + { + fprintf(stderr, "Usage: %s \n", argv[0]); + + exit(EXIT_FAILURE); + } + + // Initialize CURL connection + + if (!init(conn, argv[1])) + { + fprintf(stderr, "Connection initializion failed\n"); + + exit(EXIT_FAILURE); + } + + // Retrieve content for the URL + + code = curl_easy_perform(conn); + if (code != CURLE_OK) + { + fprintf(stderr, "Failed to get '%s' [%s]\n", argv[1], errorBuffer); + + exit(EXIT_FAILURE); + } + + // Parse the (assumed) HTML code + + parseHtml(buffer, title); + + // Display the extracted title + + printf("Title: %s\n", title.c_str()); + + return EXIT_SUCCESS; +} -- cgit v1.2.1 From d7648d94ca802752ea6d8c061fecb87bce6d3d17 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 31 Jan 2005 18:23:42 +0000 Subject: htmltitle --- docs/examples/README | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/README b/docs/examples/README index 9951241c5..21fc5f644 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -44,6 +44,8 @@ ftpgetresp.c - get the response strings from the FTP server ftpupload.c - upload a file to a FTP server getinfo.c - get the Content-Type from the recent transfer getinmemory.c - download a file to memory only +htmltitle.cc - download a HTML file and extract the tag from a HTML + page using libxml http-post.c - HTTP POST httpput.c - HTTP PUT a local file https.c - simple HTTPS transfer -- cgit v1.2.1 From 21b410545445d8465011d4b4b91f7b5fe38b3095 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Mon, 31 Jan 2005 20:03:01 +0000 Subject: somewhat nicer libcurl usage --- docs/examples/htmltitle.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/htmltitle.cc b/docs/examples/htmltitle.cc index 7d0cc4c3c..9e683488f 100644 --- a/docs/examples/htmltitle.cc +++ b/docs/examples/htmltitle.cc @@ -266,6 +266,8 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } + curl_global_init(CURL_GLOBAL_DEFAULT); + // Initialize CURL connection if (!init(conn, argv[1])) @@ -278,6 +280,8 @@ int main(int argc, char *argv[]) // Retrieve content for the URL code = curl_easy_perform(conn); + curl_easy_cleanup(conn); + if (code != CURLE_OK) { fprintf(stderr, "Failed to get '%s' [%s]\n", argv[1], errorBuffer); -- cgit v1.2.1 From 6b81cf4bc9e0fa65bfef06f8dff8ad292b2fcb47 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 2 Feb 2005 19:25:37 +0000 Subject: HTML parsing example with libtidy, by Jeff Pohlmeyer --- docs/examples/htmltidy.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 docs/examples/htmltidy.c (limited to 'docs/examples') diff --git a/docs/examples/htmltidy.c b/docs/examples/htmltidy.c new file mode 100644 index 000000000..112a4e6b6 --- /dev/null +++ b/docs/examples/htmltidy.c @@ -0,0 +1,118 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * Download a document and use libtidy to parse the HTML. + * Written by Jeff Pohlmeyer + * + * LibTidy => http://tidy.sourceforge.net + * + * gcc -Wall -I/usr/local/include tidycurl.c -lcurl -ltidy -o tidycurl + * + */ + +#include <stdio.h> +#include <tidy/tidy.h> +#include <tidy/buffio.h> +#include <curl/curl.h> + +/* curl write callback, to fill tidy's input buffer... */ +uint write_cb(char *in, uint size, uint nmemb, TidyBuffer *out) +{ + uint r; + r = size * nmemb; + tidyBufAppend( out, in, r ); + return(r); +} + +/* Traverse the document tree */ +void dumpNode(TidyDoc doc, TidyNode tnod, int indent ) +{ + TidyNode child; + 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); + /* walk the attribute list */ + for ( attr=tidyAttrFirst(child); attr; attr=tidyAttrNext(attr) ) { + printf(tidyAttrName(attr)); + tidyAttrValue(attr)?printf("=\"%s\" ", + tidyAttrValue(attr)):printf(" "); + } + printf( ">\n"); + } + else { + /* if it doesn't have a name, then it's probably text, cdata, etc... */ + TidyBuffer buf; + tidyBufInit(&buf); + tidyNodeGetText(doc, child, &buf); + printf("%*.*s\n", indent, indent, buf.bp?(char *)buf.bp:""); + tidyBufFree(&buf); + } + dumpNode( doc, child, indent + 4 ); /* recursive */ + } +} + + +int main(int argc, char **argv ) +{ + CURL *curl; + char curl_errbuf[CURL_ERROR_SIZE]; + TidyDoc tdoc; + TidyBuffer docbuf = {0}; + TidyBuffer tidy_errbuf = {0}; + int err; + if ( argc == 2) { + curl = curl_easy_init(); + curl_easy_setopt(curl, CURLOPT_URL, argv[1]); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf); + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, no); + curl_easy_setopt(curl, CURLOPT_VERBOSE, yes); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb); + + tdoc = tidyCreate(); + tidyOptSetBool(tdoc, TidyForceOutput, yes); /* try harder */ + tidyOptSetInt(tdoc, TidyWrapLen, 4096); + tidySetErrorBuffer( tdoc, &tidy_errbuf ); + tidyBufInit(&docbuf); + + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &docbuf); + err=curl_easy_perform(curl); + if ( !err ) { + err = tidyParseBuffer(tdoc, &docbuf); /* parse the input */ + if ( err >= 0 ) { + err = tidyCleanAndRepair(tdoc); /* fix any problems */ + if ( err >= 0 ) { + err = tidyRunDiagnostics(tdoc); /* load tidy error buffer */ + if ( err >= 0 ) { + dumpNode( tdoc, tidyGetRoot(tdoc), 0 ); /* walk the tree */ + fprintf(stderr, "%s\n", tidy_errbuf.bp); /* show errors */ + } + } + } + } + else + fprintf(stderr, "%s\n", curl_errbuf); + + /* clean-up */ + curl_easy_cleanup(curl); + tidyBufFree(&docbuf); + tidyBufFree(&tidy_errbuf); + tidyRelease(tdoc); + return(err); + + } + else + printf( "usage: %s <url>\n", argv[0] ); + + return(0); +} -- cgit v1.2.1 From ab96e2d6e98a798c065a8b3760c794bd7a3b9275 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 2 Feb 2005 19:25:49 +0000 Subject: another example --- docs/examples/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index f9b2939c4..5df1e593d 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -10,7 +10,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ post-callback.c multi-app.c multi-double.c multi-single.c \ multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c \ multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c debug.c \ - anyauthput.c htmltitle.cc + anyauthput.c htmltitle.cc htmltidy.c all: @echo "done" -- cgit v1.2.1 From 2248599ae140b03d1d369cfb45cb14b4aea21891 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Fri, 4 Feb 2005 23:53:12 +0000 Subject: fix type --- docs/examples/getinmemory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 5a77e9c7e..3ca3aedd2 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -37,7 +37,7 @@ void *myrealloc(void *ptr, size_t size) size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) { - register int realsize = size * nmemb; + size_t realsize = size * nmemb; struct MemoryStruct *mem = (struct MemoryStruct *)data; mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1); -- cgit v1.2.1 From 62082293c5307db04ca6b26553e045f53e2e0255 Mon Sep 17 00:00:00 2001 From: Gisle Vanem <gvanem@broadpark.no> Date: Wed, 9 Feb 2005 15:15:01 +0000 Subject: Some functions are static here, but extern in libxml's SAX.h. gcc doesn't like that. Rename. --- docs/examples/htmltitle.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/htmltitle.cc b/docs/examples/htmltitle.cc index 9e683488f..62a4363d5 100644 --- a/docs/examples/htmltitle.cc +++ b/docs/examples/htmltitle.cc @@ -131,7 +131,7 @@ static bool init(CURL *&conn, char *url) // libxml start element callback function // -static void startElement(void *voidContext, +static void StartElement(void *voidContext, const xmlChar *name, const xmlChar **attributes) { @@ -148,7 +148,7 @@ static void startElement(void *voidContext, // libxml end element callback function // -static void endElement(void *voidContext, +static void EndElement(void *voidContext, const xmlChar *name) { Context *context = (Context *)voidContext; @@ -173,7 +173,7 @@ static void handleCharacters(Context *context, // libxml PCDATA callback function // -static void characters(void *voidContext, +static void Characters(void *voidContext, const xmlChar *chars, int length) { @@ -215,10 +215,10 @@ static htmlSAXHandler saxHandler = NULL, NULL, NULL, - startElement, - endElement, + StartElement, + EndElement, NULL, - characters, + Characters, NULL, NULL, NULL, -- cgit v1.2.1 From e4c0a85da03b1b9070fc93e06ec989d1dce33fed Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Mon, 9 May 2005 21:12:03 +0000 Subject: Jeremy Brown's OpenSSL thread-locking example --- docs/examples/Makefile.am | 2 +- docs/examples/opensslthreadlock.c | 77 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 docs/examples/opensslthreadlock.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 5df1e593d..7e71c2846 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -10,7 +10,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ post-callback.c multi-app.c multi-double.c multi-single.c \ multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c \ multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c debug.c \ - anyauthput.c htmltitle.cc htmltidy.c + anyauthput.c htmltitle.cc htmltidy.c opensslthreadlock.c all: @echo "done" diff --git a/docs/examples/opensslthreadlock.c b/docs/examples/opensslthreadlock.c new file mode 100644 index 000000000..82de206da --- /dev/null +++ b/docs/examples/opensslthreadlock.c @@ -0,0 +1,77 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * 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. + * + * This is not a complete stand-alone example. + * + * Author: Jeremy Brown + */ + +#define MUTEX_TYPE pthread_mutex_t +#define MUTEX_SETUP(x) pthread_mutex_init(&(x), NULL) +#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( ) + + +void handle_error(const char *file, int lineno, const char *msg){ + fprintf(stderr, ** %s:%i %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) + MUTEX_LOCK(mutex_buf[n]); + else + MUTEX_UNLOCK(mutex_buf[n]); +} + +static unsigned long id_function(void) +{ + return ((unsigned long)THREAD_ID); +} + +int thread_setup(void) +{ + int i; + + mutex_buf = (MUTEX_TYPE *)malloc(CRYPTO_num_locks( ) * sizeof(MUTEX_TYPE)); + if (!mutex_buf) + return 0; + 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); + return 1; +} + +int thread_cleanup(void) +{ + int i; + + if (!mutex_buf) + return 0; + CRYPTO_set_id_callback(NULL); + CRYPTO_set_locking_callback(NULL); + for (i = 0; i < CRYPTO_num_locks( ); i++) + MUTEX_CLEANUP(mutex_buf[i]); + free(mutex_buf); + mutex_buf = NULL; + return 1; +} -- cgit v1.2.1 From 2236ba0d206fe9fef5d93889ee652feaa03fe089 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 27 Jul 2005 22:17:14 +0000 Subject: Peteris Krumins added CURLOPT_COOKIELIST and CURLINFO_COOKIELIST, which is a simple interface to extracting and setting cookies in libcurl's internal "cookie jar". See the new cookie_interface.c example code. --- docs/examples/Makefile.am | 3 +- docs/examples/cookie_interface.c | 110 +++++++++++++++++++++++++++++++++++++++ docs/examples/makefile.dj | 3 +- 3 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 docs/examples/cookie_interface.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 7e71c2846..d2a60a0f6 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -10,7 +10,8 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ post-callback.c multi-app.c multi-double.c multi-single.c \ multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c \ multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c debug.c \ - anyauthput.c htmltitle.cc htmltidy.c opensslthreadlock.c + anyauthput.c htmltitle.cc htmltidy.c opensslthreadlock.c \ + cookie_interface.c all: @echo "done" diff --git a/docs/examples/cookie_interface.c b/docs/examples/cookie_interface.c new file mode 100644 index 000000000..b9278dbcd --- /dev/null +++ b/docs/examples/cookie_interface.c @@ -0,0 +1,110 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * This example shows usage of simple cookie interface. + */ + +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <time.h> + +#include <curl/curl.h> + +static void +print_cookies(CURL *curl) +{ + CURLcode res; + struct curl_slist *cookies; + struct curl_slist *nc; + int i; + + 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)); + exit(1); + } + nc = cookies, i = 1; + while (nc) { + printf("[%d]: %s\n", i, nc->data); + nc = nc->next; + i++; + } + if (i == 1) { + printf("(none)\n"); + } + curl_slist_free_all(cookies); +} + +int +main(void) +{ + CURL *curl; + CURLcode res; + + curl_global_init(CURL_GLOBAL_ALL); + curl = curl_easy_init(); + if (curl) { + char nline[256]; + + curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/"); /* google.com sets "PREF" cookie */ + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); /* just to start the cookie engine */ + res = curl_easy_perform(curl); + if (res != CURLE_OK) { + fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res)); + return 1; + } + + print_cookies(curl); + + printf("Erasing curl's knowledge of cookies!\n"); + curl_easy_setopt(curl, CURLOPT_COOKIELIST, NULL); + + print_cookies(curl); + + printf("-----------------------------------------------\n" + "Setting a cookie \"PREF\" via cookie interface:\n"); +#ifdef WIN32 +#define snprintf _snprintf +#endif + /* Netscape format cookie */ + snprintf(nline, 256, "%s\t%s\t%s\t%s\t%u\t%s\t%s", + ".google.com", "TRUE", "/", "FALSE", time(NULL) + 31337, "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)); + return 1; + } + + /* HTTP-header style cookie */ + snprintf(nline, 256, + "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)); + return 1; + } + + print_cookies(curl); + + res = curl_easy_perform(curl); + if (res != CURLE_OK) { + fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res)); + return 1; + } + } + else { + fprintf(stderr, "Curl init failed!\n"); + return 1; + } + + curl_global_cleanup(); + return 0; +} diff --git a/docs/examples/makefile.dj b/docs/examples/makefile.dj index 35e53d381..8d19ef63e 100644 --- a/docs/examples/makefile.dj +++ b/docs/examples/makefile.dj @@ -20,7 +20,8 @@ PROGRAMS = fopen.exe ftpget.exe ftpgetresp.exe ftpupload.exe \ multi-double.exe multi-post.exe multi-single.exe \ persistant.exe post-callback.exe postit2.exe \ sepheaders.exe simple.exe simplessl.exe https.exe \ - ftp3rdparty.exe getinfo.exe anyauthput.exe + ftp3rdparty.exe getinfo.exe anyauthput.exe \ + cookie_interface.exe all: $(PROGRAMS) -- cgit v1.2.1 From 9da9d00c62b3f45ffb53a95a2a88a31c661dbd83 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Thu, 28 Jul 2005 21:51:20 +0000 Subject: fixed example since this is how the interface works now --- docs/examples/cookie_interface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/cookie_interface.c b/docs/examples/cookie_interface.c index b9278dbcd..d184edb54 100644 --- a/docs/examples/cookie_interface.c +++ b/docs/examples/cookie_interface.c @@ -64,7 +64,7 @@ main(void) print_cookies(curl); printf("Erasing curl's knowledge of cookies!\n"); - curl_easy_setopt(curl, CURLOPT_COOKIELIST, NULL); + curl_easy_setopt(curl, CURLOPT_COOKIELIST, "ALL"); print_cookies(curl); -- cgit v1.2.1 From 49a16f7121768621de0a99f0a52c9576ccbadf1e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 24 Aug 2005 17:07:27 +0000 Subject: Theo Borm's example, as was posted here: http://curl.haxx.se/mail/lib-2005-08/0163.html --- docs/examples/Makefile.am | 2 +- docs/examples/cacertinmem.c | 138 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 docs/examples/cacertinmem.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index d2a60a0f6..488bf7929 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -11,7 +11,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c \ multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c debug.c \ anyauthput.c htmltitle.cc htmltidy.c opensslthreadlock.c \ - cookie_interface.c + cookie_interface.c cacertinmem.c all: @echo "done" diff --git a/docs/examples/cacertinmem.c b/docs/examples/cacertinmem.c new file mode 100644 index 000000000..de5e3248e --- /dev/null +++ b/docs/examples/cacertinmem.c @@ -0,0 +1,138 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * Example using a "in core" PEM certificate to retrieve a https page. + * Written by Theo Borm + */ + +/* 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) +{ + fwrite(ptr,size,nmemb,stream); + return(nmemb*size); +} + +static CURLcode sslctx_function(CURL * curl, void * sslctx, void * parm) +{ + X509_STORE * store; + X509 * cert=NULL; + BIO * bio; + char * mypem = /* www.cacert.org */ + "-----BEGIN CERTIFICATE-----\n"\ + "MIIHPTCCBSWgAwIBAgIBADANBgkqhkiG9w0BAQQFADB5MRAwDgYDVQQKEwdSb290\n"\ + "IENBMR4wHAYDVQQLExVodHRwOi8vd3d3LmNhY2VydC5vcmcxIjAgBgNVBAMTGUNB\n"\ + "IENlcnQgU2lnbmluZyBBdXRob3JpdHkxITAfBgkqhkiG9w0BCQEWEnN1cHBvcnRA\n"\ + "Y2FjZXJ0Lm9yZzAeFw0wMzAzMzAxMjI5NDlaFw0zMzAzMjkxMjI5NDlaMHkxEDAO\n"\ + "BgNVBAoTB1Jvb3QgQ0ExHjAcBgNVBAsTFWh0dHA6Ly93d3cuY2FjZXJ0Lm9yZzEi\n"\ + "MCAGA1UEAxMZQ0EgQ2VydCBTaWduaW5nIEF1dGhvcml0eTEhMB8GCSqGSIb3DQEJ\n"\ + "ARYSc3VwcG9ydEBjYWNlcnQub3JnMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIIC\n"\ + "CgKCAgEAziLA4kZ97DYoB1CW8qAzQIxL8TtmPzHlawI229Z89vGIj053NgVBlfkJ\n"\ + "8BLPRoZzYLdufujAWGSuzbCtRRcMY/pnCujW0r8+55jE8Ez64AO7NV1sId6eINm6\n"\ + "zWYyN3L69wj1x81YyY7nDl7qPv4coRQKFWyGhFtkZip6qUtTefWIonvuLwphK42y\n"\ + "fk1WpRPs6tqSnqxEQR5YYGUFZvjARL3LlPdCfgv3ZWiYUQXw8wWRBB0bF4LsyFe7\n"\ + "w2t6iPGwcswlWyCR7BYCEo8y6RcYSNDHBS4CMEK4JZwFaz+qOqfrU0j36NK2B5jc\n"\ + "G8Y0f3/JHIJ6BVgrCFvzOKKrF11myZjXnhCLotLddJr3cQxyYN/Nb5gznZY0dj4k\n"\ + "epKwDpUeb+agRThHqtdB7Uq3EvbXG4OKDy7YCbZZ16oE/9KTfWgu3YtLq1i6L43q\n"\ + "laegw1SJpfvbi1EinbLDvhG+LJGGi5Z4rSDTii8aP8bQUWWHIbEZAWV/RRyH9XzQ\n"\ + "QUxPKZgh/TMfdQwEUfoZd9vUFBzugcMd9Zi3aQaRIt0AUMyBMawSB3s42mhb5ivU\n"\ + "fslfrejrckzzAeVLIL+aplfKkQABi6F1ITe1Yw1nPkZPcCBnzsXWWdsC4PDSy826\n"\ + "YreQQejdIOQpvGQpQsgi3Hia/0PsmBsJUUtaWsJx8cTLc6nloQsCAwEAAaOCAc4w\n"\ + "ggHKMB0GA1UdDgQWBBQWtTIb1Mfz4OaO873SsDrusjkY0TCBowYDVR0jBIGbMIGY\n"\ + "gBQWtTIb1Mfz4OaO873SsDrusjkY0aF9pHsweTEQMA4GA1UEChMHUm9vdCBDQTEe\n"\ + "MBwGA1UECxMVaHR0cDovL3d3dy5jYWNlcnQub3JnMSIwIAYDVQQDExlDQSBDZXJ0\n"\ + "IFNpZ25pbmcgQXV0aG9yaXR5MSEwHwYJKoZIhvcNAQkBFhJzdXBwb3J0QGNhY2Vy\n"\ + "dC5vcmeCAQAwDwYDVR0TAQH/BAUwAwEB/zAyBgNVHR8EKzApMCegJaAjhiFodHRw\n"\ + "czovL3d3dy5jYWNlcnQub3JnL3Jldm9rZS5jcmwwMAYJYIZIAYb4QgEEBCMWIWh0\n"\ + "dHBzOi8vd3d3LmNhY2VydC5vcmcvcmV2b2tlLmNybDA0BglghkgBhvhCAQgEJxYl\n"\ + "aHR0cDovL3d3dy5jYWNlcnQub3JnL2luZGV4LnBocD9pZD0xMDBWBglghkgBhvhC\n"\ + "AQ0ESRZHVG8gZ2V0IHlvdXIgb3duIGNlcnRpZmljYXRlIGZvciBGUkVFIGhlYWQg\n"\ + "b3ZlciB0byBodHRwOi8vd3d3LmNhY2VydC5vcmcwDQYJKoZIhvcNAQEEBQADggIB\n"\ + "ACjH7pyCArpcgBLKNQodgW+JapnM8mgPf6fhjViVPr3yBsOQWqy1YPaZQwGjiHCc\n"\ + "nWKdpIevZ1gNMDY75q1I08t0AoZxPuIrA2jxNGJARjtT6ij0rPtmlVOKTV39O9lg\n"\ + "18p5aTuxZZKmxoGCXJzN600BiqXfEVWqFcofN8CCmHBh22p8lqOOLlQ+TyGpkO/c\n"\ + "gr/c6EWtTZBzCDyUZbAEmXZ/4rzCahWqlwQ3JNgelE5tDlG+1sSPypZt90Pf6DBl\n"\ + "Jzt7u0NDY8RD97LsaMzhGY4i+5jhe1o+ATc7iwiwovOVThrLm82asduycPAtStvY\n"\ + "sONvRUgzEv/+PDIqVPfE94rwiCPCR/5kenHA0R6mY7AHfqQv0wGP3J8rtsYIqQ+T\n"\ + "SCX8Ev2fQtzzxD72V7DX3WnRBnc0CkvSyqD/HMaMyRa+xMwyN2hzXwj7UfdJUzYF\n"\ + "CpUCTPJ5GhD22Dp1nPMd8aINcGeGG7MW9S/lpOt5hvk9C8JzC6WZrG/8Z7jlLwum\n"\ + "GCSNe9FINSkYQKyTYOGWhlC0elnYjyELn8+CkcY7v2vcB5G5l1YjqrZslMZIBjzk\n"\ + "zk6q5PYvCdxTby78dOs6Y5nCpqyJvKeyRKANihDjbPIky/qbn3BHLt4Ui9SyIAmW\n"\ + "omTxJBzcoTWcFbLUvFUufQb1nA5V9FrWk9p2rSVzTMVD\n"\ + "-----END CERTIFICATE-----\n"; + /* get a BIO */ + bio=BIO_new_mem_buf(mypem, -1); + /* use it to read the PEM formatted certificate from memory into an X509 + * structure that SSL can use + */ + PEM_read_bio_X509(bio, &cert, 0, 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) + printf("error adding certificate\n"); + + /* all set to go */ + return CURLE_OK ; +} + +int main(void) +{ + CURL * ch; + CURLcode rv; + + rv=curl_global_init(CURL_GLOBAL_ALL); + ch=curl_easy_init(); + rv=curl_easy_setopt(ch,CURLOPT_VERBOSE, 0); + rv=curl_easy_setopt(ch,CURLOPT_HEADER, 0); + rv=curl_easy_setopt(ch,CURLOPT_NOPROGRESS, 1); + rv=curl_easy_setopt(ch,CURLOPT_NOSIGNAL, 1); + 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_WRITEHEADER, stderr); + rv=curl_easy_setopt(ch,CURLOPT_SSLCERTTYPE,"PEM"); + rv=curl_easy_setopt(ch,CURLOPT_SSL_VERIFYPEER,1); + rv=curl_easy_setopt(ch, CURLOPT_URL, "https://www.cacert.org/"); + + /* first try: retrieve page without cacerts' certificate -> will fail + */ + rv=curl_easy_perform(ch); + if (rv==CURLE_OK) + printf("*** transfer succeeded ***\n"); + else + printf("*** transfer failed ***\n"); + + /* second try: retrieve page using cacerts' certificate -> will succeed + * 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_perform(ch); + if (rv==CURLE_OK) + printf("*** transfer succeeded ***\n"); + else + printf("*** transfer failed ***\n"); + + curl_easy_cleanup(ch); + curl_global_cleanup(); +} -- cgit v1.2.1 From ab1f5c3edd55910c967bafcb5385ddeaf9dc53e2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Mon, 10 Oct 2005 20:58:18 +0000 Subject: make it compile warning-free and free() the memory before exit --- docs/examples/getinmemory.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 3ca3aedd2..00ed39eb2 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -14,6 +14,8 @@ */ #include <stdio.h> +#include <stdlib.h> +#include <string.h> #include <curl/curl.h> #include <curl/types.h> @@ -93,5 +95,8 @@ int main(int argc, char **argv) * you're done with it, you should free() it as a nice application. */ + if(chunk.memory) + free(chunk.memory); + return 0; } -- cgit v1.2.1 From 95330925115c073532160e6d480cec9ce433e043 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 14 Dec 2005 13:10:14 +0000 Subject: Rene Bernhardt's corrections --- docs/examples/post-callback.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index ecffce303..1da88a8af 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -78,7 +78,7 @@ int main(void) curl_slist *chunk = NULL; chunk = curl_slist_append(chunk, "Transfer-Encoding: chunked"); - res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER); + res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); /* use curl_slist_free_all() after the *perform() call to free this list again */ } @@ -101,7 +101,7 @@ int main(void) curl_slist *chunk = NULL; chunk = curl_slist_append(chunk, "Expect:"); - res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER); + res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); /* use curl_slist_free_all() after the *perform() call to free this list again */ } -- cgit v1.2.1 From da2c12467587fa2b8e65f0b8dd3d3137d2afb2a5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Sat, 4 Feb 2006 18:08:54 +0000 Subject: Frank's synctime.c example and an updated list in README --- docs/examples/Makefile.am | 2 +- docs/examples/README | 4 + docs/examples/synctime.c | 339 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 344 insertions(+), 1 deletion(-) create mode 100644 docs/examples/synctime.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 488bf7929..0adb01ebb 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -11,7 +11,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c \ multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c debug.c \ anyauthput.c htmltitle.cc htmltidy.c opensslthreadlock.c \ - cookie_interface.c cacertinmem.c + cookie_interface.c cacertinmem.c synctime.c all: @echo "done" diff --git a/docs/examples/README b/docs/examples/README index 21fc5f644..42146c5d9 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -33,6 +33,8 @@ we expect you to 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 @@ -55,6 +57,7 @@ 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 multithread.c - an example using multi-treading transfering multiple files +opensslthreadlock.c - show how to do locking when using OpenSSL multi-threaded persistant.c - request two URLs with a persistant connection post-callback.c - send a HTTP POST using a callback postit2.c - send a HTTP multipart formpost @@ -62,3 +65,4 @@ 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 extracing date from remote HTTP servers diff --git a/docs/examples/synctime.c b/docs/examples/synctime.c new file mode 100644 index 000000000..9f3bba0e9 --- /dev/null +++ b/docs/examples/synctime.c @@ -0,0 +1,339 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * This example code only builds as-is on Windows. + * + * Synchronising your computer clock via Internet time server usually relies + * on DAYTIME, TIME, or NTP protocols. These protocols provide good accurate + * time synchronisation but it does not work very well through a + * firewall/proxy. Some adjustment has to be made to the firewall/proxy for + * these protocols to work properly. + * + * There is an indirect method. Since most webserver provide server time in + * their HTTP header, therefore you could synchronise your computer clock + * using HTTP protocol which has no problem with firewall/proxy. + * + * For this software to work, you should take note of these items. + * 1. Your firewall/proxy must allow your computer to surf internet. + * 2. Webserver system time must in sync with the NTP time server, + * or at least provide an accurate time keeping. + * 3. Webserver HTTP header does not provide the milliseconds units, + * so there is no way to get very accurate time. + * 4. This software could only provide an accuracy of +- a few seconds, + * as Round-Trip delay time is not taken into consideration. + * Compensation of network, firewall/proxy delay cannot be simply divide + * the Round-Trip delay time by half. + * 5. Win32 SetSystemTime() API will set your computer clock according to + * GMT/UTC time. Therefore your computer timezone must be properly set. + * 6. Webserver data should not be cached by the proxy server. Some + * webserver provide Cache-Control to prevent caching. + * + * References: + * http://tf.nist.gov/timefreq/service/its.htm + * http://tf.nist.gov/timefreq/service/firewall.htm + * + * Usage: + * This software will synchronise your computer clock only when you issue + * it with --synctime. By default, it only display the webserver's clock. + * + * Written by: Frank (contributed to libcurl) + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL THE AUTHOR OF THIS SOFTWARE BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + * + */ + +#include <stdio.h> +#include <time.h> +#include <windows.h> +#include <curl/curl.h> + + +#define MAX_STRING 256 +#define MAX_STRING1 MAX_STRING+1 + +typedef struct +{ + char http_proxy[MAX_STRING1]; + char proxy_user[MAX_STRING1]; + char timeserver[MAX_STRING1]; +} conf_t; + +char DefaultTimeServer[4][MAX_STRING1] = +{ + "http://nist.time.gov/timezone.cgi?UTC/s/0", + "http://www.google.com/", + "http://www.worldtimeserver.com/current_time_in_UTC.aspx", + "http://www.worldtime.com/cgi-bin/wt.cgi" +}; + +char *DayStr[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; +char *MthStr[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + +int ShowAllHeader; +int AutoSyncTime; +SYSTEMTIME SYSTime; +SYSTEMTIME LOCALTime; + +#define HTTP_COMMAND_HEAD 0 +#define HTTP_COMMAND_GET 1 + + +size_t SyncTime_CURL_WriteOutput(void *ptr, size_t size, size_t nmemb, + void *stream) +{ + fwrite(ptr, size, nmemb, stream); + return(nmemb*size); +} + +size_t SyncTime_CURL_WriteHeader(void *ptr, size_t size, size_t nmemb, + void *stream) +{ + int i, RetVal; + char TmpStr1[26], TmpStr2[26]; + + if (ShowAllHeader == 1) + fprintf(stderr, "%s", (char *)(ptr)); + + if (strncmp((char *)(ptr), "Date:", 5) == 0) { + if (ShowAllHeader == 0) + fprintf(stderr, "HTTP Server. %s", (char *)(ptr)); + + if (AutoSyncTime == 1) { + *TmpStr1 = 0; + *TmpStr2 = 0; + if (strlen((char *)(ptr)) > 50) /* Can prevent buffer overflow to + TmpStr1 & 2? */ + AutoSyncTime = 0; + else { + RetVal = sscanf ((char *)(ptr), "Date: %s %d %s %d %d:%d:%d", + TmpStr1, &SYSTime.wDay, TmpStr2, &SYSTime.wYear, + &SYSTime.wHour, &SYSTime.wMinute, &SYSTime.wSecond); + + if (RetVal == 7) { + + SYSTime.wMilliseconds = 500; /* adjust to midpoint, 0.5 sec */ + for (i=0; i<12; i++) { + if (strcmp(MthStr[i], TmpStr2) == 0) { + SYSTime.wMonth = i+1; + break; + } + } + AutoSyncTime = 3; /* Computer clock will be adjusted */ + } + else { + AutoSyncTime = 0; /* Error in sscanf() fields conversion */ + } + } + } + } + + 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); +} + +void SyncTime_CURL_Init(CURL *curl, char *proxy_port, + char *proxy_user_password) +{ + if (strlen(proxy_port) > 0) + curl_easy_setopt(curl, CURLOPT_PROXY, proxy_port); + + if (strlen(proxy_user_password) > 0) + curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, proxy_user_password); + + /* Trick Webserver by claiming that you are using Microsoft WinXP SP2, IE6 */ + curl_easy_setopt(curl, CURLOPT_USERAGENT, + "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, *SyncTime_CURL_WriteOutput); + curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, *SyncTime_CURL_WriteHeader); +} + +int SyncTime_CURL_Fetch(CURL *curl, char *URL_Str, char *OutFileName, + int HttpGetBody) +{ + FILE *outfile; + CURLcode res; + + outfile = NULL; + if (HttpGetBody == HTTP_COMMAND_HEAD) + curl_easy_setopt(curl, CURLOPT_NOBODY, 1); + else { + outfile = fopen(OutFileName, "wb"); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); + } + + curl_easy_setopt(curl, CURLOPT_URL, URL_Str); + res = curl_easy_perform(curl); + if (outfile != NULL) + fclose(outfile); + return res; /* (CURLE_OK) */ +} + +void showUsage(void) +{ + fprintf(stderr, "SYNCTIME: Synchronising computer clock with time server" + " using HTTP protocol.\n"); + fprintf(stderr, "Usage : SYNCTIME [Option]\n"); + fprintf(stderr, "Options :\n"); + fprintf(stderr, " --server=WEBSERVER Use this time server instead" + " of default.\n"); + fprintf(stderr, " --showall Show all HTTP header.\n"); + fprintf(stderr, " --synctime Synchronising computer clock" + " with time server.\n"); + fprintf(stderr, " --proxy-user=USER[:PASS] Set proxy username and" + " password.\n"); + fprintf(stderr, " --proxy=HOST[:PORT] Use HTTP proxy on given" + " port.\n"); + fprintf(stderr, " --help Print this help.\n"); + fprintf(stderr, "\n"); + return; +} + +int conf_init(conf_t *conf) +{ + int i; + + *conf->http_proxy = 0; + for (i=0; i<MAX_STRING1; i++) + conf->proxy_user[i] = 0; /* Clean up password from memory */ + *conf->timeserver = 0; + return 1; +} + +int main(int argc, char *argv[]) +{ + CURL *curl; + conf_t conf[1]; + int OptionIndex; + struct tm *lt; + struct tm *gmt; + time_t tt; + time_t tt_local; + time_t tt_gmt; + double tzonediffFloat; + int tzonediffWord; + char timeBuf[61]; + char tzoneBuf[16]; + int RetValue; + + OptionIndex = 0; + ShowAllHeader = 0; /* Do not show HTTP Header */ + AutoSyncTime = 0; /* Do not synchronise computer clock */ + RetValue = 0; /* Successful Exit */ + conf_init(conf); + + 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) + ShowAllHeader = 1; + + if (strcmp(argv[OptionIndex], "--synctime") == 0) + AutoSyncTime = 1; + + 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) + snprintf(conf->http_proxy, MAX_STRING, "%s", &argv[OptionIndex][8]); + + if ((strcmp(argv[OptionIndex], "--help") == 0) || + (strcmp(argv[OptionIndex], "/?") == 0)) { + showUsage(); + return 0; + } + OptionIndex++; + } + } + + 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) { + SyncTime_CURL_Init(curl, conf->http_proxy, conf->proxy_user); + + /* Calculating time diff between GMT and localtime */ + tt = time(0); + lt = localtime(&tt); + tt_local = mktime(lt); + gmt = gmtime(&tt); + tt_gmt = mktime(gmt); + tzonediffFloat = difftime(tt_local, tt_gmt); + tzonediffWord = (int)(tzonediffFloat/3600.0); + + if ((double)(tzonediffWord * 3600) == tzonediffFloat) + snprintf(tzoneBuf, 15, "%+03d'00'", tzonediffWord); + else + snprintf(tzoneBuf, 15, "%+03d'30'", tzonediffWord); + + /* Get current system time and local time */ + GetSystemTime(&SYSTime); + GetLocalTime(&LOCALTime); + snprintf(timeBuf, 60, "%s, %02d %s %04d %02d:%02d:%02d.%03d, ", + DayStr[LOCALTime.wDayOfWeek], LOCALTime.wDay, + MthStr[LOCALTime.wMonth-1], LOCALTime.wYear, + LOCALTime.wHour, LOCALTime.wMinute, LOCALTime.wSecond, + LOCALTime.wMilliseconds); + fprintf(stderr, "\nBefore HTTP. Date: %s%s\n\n", timeBuf, tzoneBuf); + + /* HTTP HEAD command to the Webserver */ + fprintf(stderr, "Fetch: %s\n", conf->timeserver); + SyncTime_CURL_Fetch(curl, conf->timeserver, "index.htm", + HTTP_COMMAND_HEAD); + + GetLocalTime(&LOCALTime); + snprintf(timeBuf, 60, "%s, %02d %s %04d %02d:%02d:%02d.%03d, ", + DayStr[LOCALTime.wDayOfWeek], LOCALTime.wDay, + MthStr[LOCALTime.wMonth-1], LOCALTime.wYear, + LOCALTime.wHour, LOCALTime.wMinute, LOCALTime.wSecond, + LOCALTime.wMilliseconds); + fprintf(stderr, "\nAfter HTTP. Date: %s%s\n", timeBuf, tzoneBuf); + + if (AutoSyncTime == 3) { + /* Synchronising computer clock */ + if (!SetSystemTime(&SYSTime)) { /* Set system time */ + fprintf(stderr, "ERROR: Unable to set system time.\n"); + RetValue = 1; + } + else { + /* Successfully re-adjusted computer clock */ + GetLocalTime(&LOCALTime); + snprintf(timeBuf, 60, "%s, %02d %s %04d %02d:%02d:%02d.%03d, ", + DayStr[LOCALTime.wDayOfWeek], LOCALTime.wDay, + MthStr[LOCALTime.wMonth-1], LOCALTime.wYear, + LOCALTime.wHour, LOCALTime.wMinute, LOCALTime.wSecond, + LOCALTime.wMilliseconds); + fprintf(stderr, "\nNew System's Date: %s%s\n", timeBuf, tzoneBuf); + } + } + + /* Cleanup before exit */ + conf_init(conf); + curl_easy_cleanup(curl); + } + return RetValue; +} -- cgit v1.2.1 From 655331a91b2d68106c0afb63c1bdf6245a6cc30c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Sun, 9 Apr 2006 08:39:08 +0000 Subject: new little example using the new conversion callbacks added in 7.15.4 --- docs/examples/Makefile.am | 2 +- docs/examples/sampleconv.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 docs/examples/sampleconv.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 0adb01ebb..c09183b64 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -11,7 +11,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c \ multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c debug.c \ anyauthput.c htmltitle.cc htmltidy.c opensslthreadlock.c \ - cookie_interface.c cacertinmem.c synctime.c + cookie_interface.c cacertinmem.c synctime.c sampleconv.c all: @echo "done" diff --git a/docs/examples/sampleconv.c b/docs/examples/sampleconv.c new file mode 100644 index 000000000..89cfb933e --- /dev/null +++ b/docs/examples/sampleconv.c @@ -0,0 +1,95 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ +/* + 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. + + Three callback functions are created below: + my_conv_from_ascii_to_ebcdic, + my_conv_from_ebcdic_to_ascii, and + my_conv_from_utf8_to_ebcdic + + The "platform_xxx" calls represent platform-specific conversion routines. + + */ + +#include <stdio.h> +#include <curl/curl.h> + +CURLcode my_conv_from_ascii_to_ebcdic(char *buffer, size_t length) +{ + char *tempptrin, *tempptrout; + size_t bytes = 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); + } +} + +CURLcode my_conv_from_ebcdic_to_ascii(char *buffer, size_t length) +{ + char *tempptrin, *tempptrout; + size_t bytes = 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); + } +} + +CURLcode my_conv_from_utf8_to_ebcdic(char *buffer, size_t length) +{ + char *tempptrin, *tempptrout; + size_t bytes = 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); + } +} + +int main(void) +{ + CURL *curl; + CURLcode res; + + curl = curl_easy_init(); + if(curl) { + curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); + + /* use platform-specific functions for codeset conversions */ + curl_easy_setopt(curl, CURLOPT_CONV_FROM_NETWORK_FUNCTION, + my_conv_from_ascii_to_ebcdic); + curl_easy_setopt(curl, CURLOPT_CONV_TO_NETWORK_FUNCTION, + my_conv_from_ebcdic_to_ascii); + curl_easy_setopt(curl, CURLOPT_CONV_FROM_UTF8_FUNCTION, + my_conv_from_utf8_to_ebcdic); + + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} -- cgit v1.2.1 From 80a0b81c2a7550f106585827491433278818969c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Tue, 2 May 2006 09:19:31 +0000 Subject: Make this code use the proper pointers --- docs/examples/multi-post.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index 0f9a599ac..b89e2d632 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -24,12 +24,13 @@ int main(int argc, char *argv[]) CURLM *multi_handle; int still_running; - struct HttpPost *formpost=NULL; - struct HttpPost *lastptr=NULL; + struct curl_httppost *formpost=NULL; + struct curl_httppost *lastptr=NULL; struct curl_slist *headerlist=NULL; char buf[] = "Expect:"; - /* Fill in the file upload field */ + /* Fill in the file upload field. This makes libcurl load data from + the given file name when curl_easy_perform() is called. */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "sendfile", @@ -43,7 +44,6 @@ int main(int argc, char *argv[]) CURLFORM_COPYCONTENTS, "postit2.c", CURLFORM_END); - /* Fill in the submit field too, even if this is rarely needed */ curl_formadd(&formpost, &lastptr, -- cgit v1.2.1 From d5e9041344924baf085bd306f12cb53292d4efa7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Thu, 11 May 2006 22:24:44 +0000 Subject: The new ftpuploadresume.c example by Philip Bock --- docs/examples/Makefile.am | 2 +- docs/examples/ftpuploadresume.c | 154 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 docs/examples/ftpuploadresume.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index c09183b64..61a6770fb 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -11,7 +11,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c \ multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c debug.c \ anyauthput.c htmltitle.cc htmltidy.c opensslthreadlock.c \ - cookie_interface.c cacertinmem.c synctime.c sampleconv.c + cookie_interface.c cacertinmem.c synctime.c sampleconv.c ftpuploadresume.c all: @echo "done" diff --git a/docs/examples/ftpuploadresume.c b/docs/examples/ftpuploadresume.c new file mode 100644 index 000000000..f83cd0a2d --- /dev/null +++ b/docs/examples/ftpuploadresume.c @@ -0,0 +1,154 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * 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 + */ + +#include <stdlib.h> +#include <stdio.h> + +#include <curl/curl.h> + + +/* The MinGW headers are missing a few Win32 function definitions, + you shouldn't need this if you use VC++ */ +int __cdecl _snscanf(const char * input, size_t length, const char * format, ...); + + +/* parse headers for Content-Length */ +size_t getcontentlengthfunc(void *ptr, size_t size, size_t nmemb, void *stream) { + int r; + long len = 0; + + /* _snscanf() is Win32 specific */ + r = _snscanf(ptr, size * nmemb, "Content-Length: %ld\n", &len); + + if (r) /* Microsoft: we don't read the specs */ + *((long *) stream) = len; + + return size * nmemb; +} + +/* discard downloaded data */ +size_t discardfunc(void *ptr, size_t size, size_t nmemb, void *stream) { + return size * nmemb; +} + +/* read data to upload */ +size_t readfunc(void *ptr, size_t size, size_t nmemb, void *stream) +{ + FILE *f = stream; + size_t n; + + if (ferror(f)) + return CURL_READFUNC_ABORT; + + n = fread(ptr, size, nmemb, f) * size; + + return n; +} + + +int upload(CURL *curlhandle, const char * remotepath, const char * localpath, + long timeout, long tries) +{ + FILE *f; + long uploaded_len = 0; + CURLcode r = CURLE_GOT_NOTHING; + int c; + + f = fopen(localpath, "rb"); + if (f == NULL) { + perror(NULL); + return 0; + } + + curl_easy_setopt(curlhandle, CURLOPT_UPLOAD, TRUE); + + curl_easy_setopt(curlhandle, CURLOPT_URL, remotepath); + + if (timeout) + curl_easy_setopt(curlhandle, CURLOPT_FTP_RESPONSE_TIMEOUT, timeout); + + curl_easy_setopt(curlhandle, CURLOPT_HEADERFUNCTION, getcontentlengthfunc); + curl_easy_setopt(curlhandle, CURLOPT_HEADERDATA, &uploaded_len); + + curl_easy_setopt(curlhandle, CURLOPT_WRITEFUNCTION, discardfunc); + + curl_easy_setopt(curlhandle, CURLOPT_READFUNCTION, readfunc); + curl_easy_setopt(curlhandle, CURLOPT_READDATA, f); + + curl_easy_setopt(curlhandle, CURLOPT_FTPPORT, "-"); /* disable passive mode */ + curl_easy_setopt(curlhandle, CURLOPT_FTP_CREATE_MISSING_DIRS, TRUE); + + curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, TRUE); + + for (c = 0; (r != CURLE_OK) && (c < tries); c++) { + /* are we resuming? */ + if (c) { /* yes */ + /* determine the length of the file already written */ + + /* + * With NOBODY and NOHEADER, libcurl will issue a SIZE + * command, but the only way to retrieve the result is + * to parse the returned Content-Length header. Thus, + * getcontentlengthfunc(). We need discardfunc() above + * because HEADER will dump the headers to stdout + * without it. + */ + curl_easy_setopt(curlhandle, CURLOPT_NOBODY, TRUE); + curl_easy_setopt(curlhandle, CURLOPT_HEADER, TRUE); + + r = curl_easy_perform(curlhandle); + if (r != CURLE_OK) + continue; + + curl_easy_setopt(curlhandle, CURLOPT_NOBODY, FALSE); + curl_easy_setopt(curlhandle, CURLOPT_HEADER, FALSE); + + fseek(f, uploaded_len, SEEK_SET); + + curl_easy_setopt(curlhandle, CURLOPT_FTPAPPEND, TRUE); + } + else { /* no */ + curl_easy_setopt(curlhandle, CURLOPT_FTPAPPEND, FALSE); + } + + r = curl_easy_perform(curlhandle); + } + + fclose(f); + + if (r == CURLE_OK) + return 1; + else { + fprintf(stderr, "%s\n", curl_easy_strerror(r)); + return 0; + } +} + +int main(int c, char **argv) { + CURL *curlhandle = NULL; + + curl_global_init(CURL_GLOBAL_ALL); + curlhandle = curl_easy_init(); + + upload(curlhandle, "ftp://user:pass@host/path/file", "C:\\file", 0, 3); + + curl_easy_cleanup(curlhandle); + curl_global_cleanup(); + + return 0; +} -- cgit v1.2.1 From 279dd6d878cc032b9024bf67743e0d30fba4874b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Fri, 30 Jun 2006 10:26:26 +0000 Subject: typecast the number passed to CURLOPT_INFILESIZE_LARGE as a curl_off_t --- docs/examples/httpput.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index 162a6b0d8..0d360adc7 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -87,8 +87,10 @@ int main(int argc, char **argv) /* now specify which file to upload */ curl_easy_setopt(curl, CURLOPT_READDATA, hd_src); - /* and give the size of the upload */ - curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, file_info.st_size); + /* provide the size of the upload, we specicially typecast the value + to curl_off_t since we must be sure to use the correct data size */ + curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, + (curl_off_t)file_info.st_size); /* Now run off and do what you've been told! */ res = curl_easy_perform(curl); -- cgit v1.2.1 From bc2f0c7dcbd22ab52971df4a419933e70f263a3f Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Wed, 5 Jul 2006 23:10:37 +0000 Subject: Prevent definition of HAVE_WINxxx_H symbols and avoid inclusion of Windows headers when compiled with Cygwin in POSIX emulation mode. --- docs/examples/synctime.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/synctime.c b/docs/examples/synctime.c index 9f3bba0e9..fc629ee33 100644 --- a/docs/examples/synctime.c +++ b/docs/examples/synctime.c @@ -59,7 +59,9 @@ #include <stdio.h> #include <time.h> +#ifndef __CYGWIN__ #include <windows.h> +#endif #include <curl/curl.h> -- cgit v1.2.1 From fb6508054833b491b5e3a5ade1410f368c4c3354 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Tue, 12 Sep 2006 07:54:55 +0000 Subject: example code by Michael Wallner --- docs/examples/10-at-a-time.c | 163 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 docs/examples/10-at-a-time.c (limited to 'docs/examples') diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c new file mode 100644 index 000000000..be3b6faee --- /dev/null +++ b/docs/examples/10-at-a-time.c @@ -0,0 +1,163 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * Example application source code using the multi interface to download many + * files, but with a capped maximum amount of simultaneous transfers. + * + * Written by Michael Wallner + */ + +#include <stdlib.h> +#include <curl/multi.h> + +static const char *urls[] = { + "http://www.microsoft.com", + "http://www.opensource.org", + "http://www.google.com", + "http://www.yahoo.com", + "http://www.ibm.com", + "http://www.mysql.com", + "http://www.oracle.com", + "http://www.ripe.net", + "http://www.iana.org", + "http://www.amazon.com", + "http://www.netcraft.com", + "http://www.heise.de", + "http://www.chip.de", + "http://www.ca.com", + "http://www.cnet.com", + "http://www.news.com", + "http://www.cnn.com", + "http://www.wikipedia.org", + "http://www.dell.com", + "http://www.hp.com", + "http://www.cert.org", + "http://www.mit.edu", + "http://www.nist.gov", + "http://www.ebay.com", + "http://www.playstation.com", + "http://www.uefa.com", + "http://www.ieee.org", + "http://www.apple.com", + "http://www.sony.com", + "http://www.symantec.com", + "http://www.zdnet.com", + "http://www.fujitsu.com", + "http://www.supermicro.com", + "http://www.hotmail.com", + "http://www.ecma.com", + "http://www.bbc.co.uk", + "http://news.google.com", + "http://www.foxnews.com", + "http://www.msn.com", + "http://www.wired.com", + "http://www.sky.com", + "http://www.usatoday.com", + "http://www.cbs.com", + "http://www.nbc.com", + "http://slashdot.org", + "http://www.bloglines.com", + "http://www.techweb.com", + "http://www.newslink.org", + "http://www.un.org", +}; + +#define MAX 10 /* number of simultaneous transfers */ +#define CNT sizeof(urls)/sizeof(char*) /* total number of transfers to do */ + +static int cb(char *d, size_t n, size_t l, void *p) +{ + /* take care of the data here, ignored in this example */ + (void)d; + (void)p; + return n*l; +} + +static void init(CURLM *cm, int i) +{ + CURL *eh = curl_easy_init(); + + curl_easy_setopt(eh, CURLOPT_WRITEFUNCTION, cb); + curl_easy_setopt(eh, CURLOPT_HEADER, 0); + curl_easy_setopt(eh, CURLOPT_URL, urls[i]); + curl_easy_setopt(eh, CURLOPT_PRIVATE, urls[i]); + curl_easy_setopt(eh, CURLOPT_VERBOSE, 0); + + curl_multi_add_handle(cm, eh); +} + +int main(void) +{ + CURLM *cm; + CURLMsg *msg; + long L; + unsigned int C=0; + int M, Q, U = -1; + fd_set R, W, E; + struct timeval T; + + curl_global_init(CURL_GLOBAL_ALL); + + cm = curl_multi_init(); + + for (C = 0; C < MAX; ++C) { + init(cm, C); + } + + while (U) { + while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(cm, &U)); + + if (U) { + FD_ZERO(&R); + FD_ZERO(&W); + FD_ZERO(&E); + + 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)) { + fprintf(stderr, "E: curl_multi_timeout\n"); + return EXIT_FAILURE; + } + + T.tv_sec = L/1000; + T.tv_usec = (L%1000)*1000; + + if (0 > select(M+1, &R, &W, &E, &T)) { + fprintf(stderr, "E: select\n"); + return EXIT_FAILURE; + } + } + + 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); + fprintf(stderr, "R: %d - %s <%s>\n", + msg->data.result, curl_easy_strerror(msg->data.result), url); + curl_multi_remove_handle(cm, e); + curl_easy_cleanup(e); + } + else { + fprintf(stderr, "E: CURLMsg (%d)\n", msg->msg); + } + if (C < CNT) { + init(cm, C++); + } + } + } + + curl_multi_cleanup(cm); + curl_global_cleanup(); + + return EXIT_SUCCESS; +} -- cgit v1.2.1 From 6df85adf3eff596ba7414c53f85db2ab088161e3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Tue, 12 Sep 2006 11:25:00 +0000 Subject: hiperfifo.c by Jeff Pohlmeyer --- docs/examples/Makefile.am | 3 +- docs/examples/README | 14 +- docs/examples/hiperfifo.c | 412 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 424 insertions(+), 5 deletions(-) create mode 100644 docs/examples/hiperfifo.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 61a6770fb..5cd572401 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -11,7 +11,8 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c \ multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c debug.c \ anyauthput.c htmltitle.cc htmltidy.c opensslthreadlock.c \ - cookie_interface.c cacertinmem.c synctime.c sampleconv.c ftpuploadresume.c + cookie_interface.c cacertinmem.c synctime.c sampleconv.c ftpuploadresume.c \ + 10-at-a-time.c hiperfifo.c all: @echo "done" diff --git a/docs/examples/README b/docs/examples/README index 42146c5d9..71d0ab96e 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -26,9 +26,9 @@ want you do reorganize them like: $ `curl-config --cc` -o example example.c `curl-config --cflags --libs` *PLEASE* do not use the curl.haxx.se site as a test target for your libcurl -applications/experiments. Even if the examples in this directory use that site -as an example URL at some places, it doesn't mean that the URLs work or that -we expect you to actually torture our web site with your tests! Thanks. +applications/experiments. Even if some of the examples use that site as a URL +at some places, it doesn't mean that the URLs work or that we expect you to +actually torture our web site with your tests! Thanks. EXAMPLES @@ -43,9 +43,11 @@ fopen.c - fopen() layer that supports opening URLs and files ftp3rdparty.c - FTP 3rd party transfer ftpget.c - simple getting a file from FTP ftpgetresp.c - get the response strings from the FTP server -ftpupload.c - upload a file to a 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 +hiperfifo.c - downloads all URLs written to the fifo htmltitle.cc - download a HTML file and extract the <title> tag from a HTML page using libxml http-post.c - HTTP POST @@ -61,8 +63,12 @@ opensslthreadlock.c - show how to do locking when using OpenSSL multi-threaded persistant.c - request two URLs with a persistant connection 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 extracing date from remote HTTP servers +10-at-a-time.c - Download many files simultaneously, 10 at a time. diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c new file mode 100644 index 000000000..625ea761f --- /dev/null +++ b/docs/examples/hiperfifo.c @@ -0,0 +1,412 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * Example application source code using the multi socket interface to + * download many files at once. + * + * Written by Jeff Pohlmeyer + +Requires libevent and a (POSIX?) system that has mkfifo(). + +This is an adaptation of libcurl's "hipev.c" and libevent's "event-test.c" +sample programs. + +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. + + +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 + +The fifo buffer is handled almost instantly, so you can even add more URL's +while the previous requests are still being downloaded. + +Note: + For the sake of simplicity, URL length is limited to 1023 char's ! + +This is purely a demo app, all retrieved data is simply discarded by the write +callback. + +*/ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sys/time.h> +#include <time.h> +#include <unistd.h> +#include <sys/poll.h> +#include <curl/curl.h> +#include <event.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <errno.h> + + +#define MSG_OUT stdout /* Send info to stdout, change to stderr if you want */ + + +/* Global information, common to all connections */ +typedef struct _GlobalInfo { + struct event fifo_event; + struct event timer_event; + CURLM *multi; + int prev_running; + int still_running; + FILE* input; +} GlobalInfo; + + +/* Information associated with a specific easy handle */ +typedef struct _ConnInfo { + CURL *easy; + char *url; + GlobalInfo *global; + char error[CURL_ERROR_SIZE]; +} ConnInfo; + + +/* Information associated with a specific socket */ +typedef struct _SockInfo { + curl_socket_t sockfd; + CURL *easy; + int action; + long timeout; + struct event ev; + int evset; + GlobalInfo *global; +} SockInfo; + + + +/* Update the event timer after curl_multi library calls */ +static void update_timeout(GlobalInfo *g) +{ + long timeout_ms; + struct timeval timeout; + + curl_multi_timeout(g->multi, &timeout_ms); + timeout.tv_sec = timeout_ms/1000; + timeout.tv_usec = (timeout_ms%1000)*1000; + evtimer_add(&g->timer_event, &timeout); +} + + + +/* Die if we get a bad CURLMcode somewhere */ +void mcode_or_die(char *where, CURLMcode code) { + if ( CURLM_OK != code ) { + char *s; + switch (code) { + case CURLM_CALL_MULTI_PERFORM: s="CURLM_CALL_MULTI_PERFORM"; break; + case CURLM_OK: s="CURLM_OK"; break; + 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"; + } + fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s); + exit(code); + } +} + + + +/* Check for completed transfers, and remove their easy handles */ +static void check_run_count(GlobalInfo *g) +{ + if (g->prev_running > g->still_running) { + char *eff_url=NULL; + CURLMsg *msg; + int msgs_left; + ConnInfo *conn=NULL; + CURL*easy; + CURLcode res; + + fprintf(MSG_OUT, "REMAINING: %d\n", g->still_running); + /* + I am still uncertain whether it is safe to remove an easy handle + from inside the curl_multi_info_read loop, so here I will search + for completed transfers in the inner "while" loop, and then remove + them in the outer "do-while" loop... + */ + do { + easy=NULL; + while ((msg = curl_multi_info_read(g->multi, &msgs_left))) { + if (msg->msg == CURLMSG_DONE) { + easy=msg->easy_handle; + res=msg->data.result; + } + } + if (easy) { + curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn); + curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url); + fprintf(MSG_OUT, "DONE: %s => (%d) %s\n", eff_url, res, conn->error); + curl_multi_remove_handle(g->multi, easy); + free(conn->url); + curl_easy_cleanup(easy); + free(conn); + } + } while ( easy ); + } + g->prev_running = g->still_running; +} + + + +/* Called by libevent when we get action on a multi socket */ +static void event_cb(int fd, short kind, void *userp) +{ + GlobalInfo *g = (GlobalInfo*) userp; + CURLMcode rc; + + do { + rc = curl_multi_socket(g->multi, fd, &g->still_running); + } while (rc == CURLM_CALL_MULTI_PERFORM); + mcode_or_die("event_cb: curl_multi_socket", rc); + check_run_count(g); + if(g->still_running) { + update_timeout(g); + } else { + fprintf(MSG_OUT, "last transfer done, kill timeout\n"); + if (evtimer_pending(&g->timer_event, NULL)) { + evtimer_del(&g->timer_event); + } + } +} + + + +/* Called by libevent when our timeout expires */ +static void timer_cb(int fd, short kind, void *userp) +{ + (void)fd; + (void)kind; + GlobalInfo *g = (GlobalInfo *)userp; + CURLMcode rc; + + do { + rc = curl_multi_socket(g->multi, CURL_SOCKET_TIMEOUT, &g->still_running); + } while (rc == CURLM_CALL_MULTI_PERFORM); + mcode_or_die("timer_cb: curl_multi_socket", rc); + check_run_count(g); + if ( g->still_running ) { update_timeout(g); } +} + + + +/* Clean up the SockInfo structure */ +static void remsock(SockInfo *f) +{ + if (!f) { return; } + if (f->evset) { event_del(&f->ev); } + free(f); +} + + + +/* Assign information to a SockInfo structure */ +static void setsock(SockInfo*f, curl_socket_t s, CURL*e, int act, GlobalInfo*g) +{ + int kind = + (act&CURL_POLL_IN?EV_READ:0)|(act&CURL_POLL_OUT?EV_WRITE:0)|EV_PERSIST; + + f->sockfd = s; + f->action = act; + f->easy = e; + if (f->evset) { event_del(&f->ev); } + event_set( &f->ev, f->sockfd, kind, event_cb, g); + f->evset=1; + event_add(&f->ev, NULL); +} + + + +/* Initialize a new SockInfo structure */ +static void addsock(curl_socket_t s, CURL *easy, int action, GlobalInfo *g) { + SockInfo *fdp = calloc(sizeof(SockInfo), 1); + + fdp->global = g; + setsock(fdp, s, easy, action, 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) +{ + GlobalInfo *g = (GlobalInfo*) cbp; + SockInfo *fdp = (SockInfo*) sockp; + char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE" }; + + fprintf(MSG_OUT, + "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); + if (what == CURL_POLL_REMOVE) { + fprintf(MSG_OUT, "\n"); + remsock(fdp); + } else { + if (!fdp) { + fprintf(MSG_OUT, "Adding data: %s%s\n", + what&CURL_POLL_IN?"READ":"", + what&CURL_POLL_OUT?"WRITE":"" ); + addsock(s, e, what, g); + } + else { + fprintf(MSG_OUT, + "Changing action from %d to %d\n", fdp->action, what); + setsock(fdp, s, e, what, g); + } + } + return 0; +} + + + +/* CURLOPT_WRITEFUNCTION */ +static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data) +{ + size_t realsize = size * nmemb; + ConnInfo *conn = (ConnInfo*) data; + (void)ptr; + (void)conn; + return realsize; +} + + +/* CURLOPT_PROGRESSFUNCTION */ +int prog_cb (void *p, double dltotal, double dlnow, double ult, double uln) +{ + ConnInfo *conn = (ConnInfo *)p; + fprintf(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 */ +void new_conn(char *url, GlobalInfo *g ) { + ConnInfo *conn; + CURLMcode rc; + + conn = calloc(1, sizeof(ConnInfo)); + memset(conn, 0, sizeof(ConnInfo)); + conn->error[0]='\0'; + + conn->easy = curl_easy_init(); + if (!conn->easy) { + fprintf(MSG_OUT, "curl_easy_init() failed, exiting!\n"); + exit(2); + } + conn->global = 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_VERBOSE, 0); + curl_easy_setopt(conn->easy, CURLOPT_ERRORBUFFER, conn->error); + curl_easy_setopt(conn->easy, CURLOPT_PRIVATE, conn); + curl_easy_setopt(conn->easy, CURLOPT_NOPROGRESS, 0); + curl_easy_setopt(conn->easy, CURLOPT_PROGRESSFUNCTION, prog_cb); + curl_easy_setopt(conn->easy, CURLOPT_PROGRESSDATA, conn); + fprintf(MSG_OUT, + "Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url); + rc =curl_multi_add_handle(g->multi, conn->easy); + mcode_or_die("new_conn: curl_multi_add_handle", rc); + do { + rc = curl_multi_socket_all(g->multi, &g->still_running); + } while (CURLM_CALL_MULTI_PERFORM == rc); + mcode_or_die("new_conn: curl_multi_socket_all", rc); + check_run_count(g); +} + + + +/* This gets called whenever data is received from the fifo */ +void fifo_cb(int fd, short event, void *arg) { + char s[1024]; + long int rv=0; + int n=0; + GlobalInfo *g = (GlobalInfo *)arg; + + do { + 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); +} + + + +/* Create a named pipe and tell libevent to monitor it */ +int init_fifo (GlobalInfo *g) { + struct stat st; + char *fifo = "hiper.fifo"; + int socket; + + fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo); + 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); + if (socket == -1) { + perror("open"); + exit (1); + } + g->input = fdopen(socket, "r"); + + fprintf(MSG_OUT, "Now, pipe some URL's into > %s\n", fifo); + event_set(&g->fifo_event, socket, EV_READ | EV_PERSIST, fifo_cb, g); + event_add(&g->fifo_event, NULL); + return (0); +} + + + +int main(int argc, char **argv) +{ + GlobalInfo g; + CURLMcode rc; + + memset(&g, 0, sizeof(GlobalInfo)); + event_init(); + init_fifo(&g); + g.multi = curl_multi_init(); + evtimer_set(&g.timer_event, timer_cb, &g); + curl_multi_setopt(g.multi, CURLMOPT_SOCKETFUNCTION, sock_cb); + curl_multi_setopt(g.multi, CURLMOPT_SOCKETDATA, &g); + do { + rc = curl_multi_socket_all(g.multi, &g.still_running); + } while (CURLM_CALL_MULTI_PERFORM == rc); + update_timeout(&g); + event_dispatch(); + curl_multi_cleanup(g.multi); + return 0; +} -- cgit v1.2.1 From 9e54d4c7d29352f54aed28542f5b840e9d88c071 Mon Sep 17 00:00:00 2001 From: Gisle Vanem <gvanem@broadpark.no> Date: Wed, 13 Sep 2006 13:51:03 +0000 Subject: Use CSOURCES as other makefiles. Add line for dependency generation. --- docs/examples/makefile.dj | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/makefile.dj b/docs/examples/makefile.dj index 8d19ef63e..d0d4b67f0 100644 --- a/docs/examples/makefile.dj +++ b/docs/examples/makefile.dj @@ -15,13 +15,13 @@ endif LIBS += $(WATT32_ROOT)/lib/libwatt.a $(ZLIB_ROOT)/libz.a -PROGRAMS = fopen.exe ftpget.exe ftpgetresp.exe ftpupload.exe \ - getinmemory.exe http-post.exe httpput.exe multi-app.exe \ - multi-double.exe multi-post.exe multi-single.exe \ - persistant.exe post-callback.exe postit2.exe \ - sepheaders.exe simple.exe simplessl.exe https.exe \ - ftp3rdparty.exe getinfo.exe anyauthput.exe \ - cookie_interface.exe +CSOURCES = fopen.c ftpget.c ftpgetresp.c ftpupload.c getinmemory.c \ + http-post.c httpput.c multi-app.c multi-double.c multi-post.c \ + multi-single.c persistant.c post-callback.c postit2.c \ + sepheaders.c simple.c simplessl.c https.c ftp3rdparty.c \ + getinfo.c anyauthput.c cookie_interface.c 10-at-a-time.c + +PROGRAMS = $(CSOURCES:.c=.exe) all: $(PROGRAMS) @@ -32,3 +32,5 @@ all: $(PROGRAMS) clean: rm -f $(PROGRAMS) +# DO NOT DELETE THIS LINE + -- cgit v1.2.1 From 56fcf85ab61b4dc44796f1241e1b7c2349afc6ea Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Sun, 8 Oct 2006 22:19:25 +0000 Subject: slightly improved --- docs/examples/hiperfifo.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index 625ea761f..f640bf9dc 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -98,6 +98,9 @@ static void update_timeout(GlobalInfo *g) struct timeval timeout; curl_multi_timeout(g->multi, &timeout_ms); + if(timeout_ms < 0) + return; + timeout.tv_sec = timeout_ms/1000; timeout.tv_usec = (timeout_ms%1000)*1000; evtimer_add(&g->timer_event, &timeout); @@ -152,6 +155,7 @@ static void check_run_count(GlobalInfo *g) if (msg->msg == CURLMSG_DONE) { easy=msg->easy_handle; res=msg->data.result; + break; } } if (easy) { -- cgit v1.2.1 From d5eb386d0013ae595e6ef49eac77d49f346edd74 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Tue, 10 Oct 2006 19:46:57 +0000 Subject: Added ghiper.c, Jeff Pohlmeyer's example code using the curl_multi_socket() API with glib2 --- docs/examples/Makefile.am | 2 +- docs/examples/ghiper.c | 462 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 463 insertions(+), 1 deletion(-) create mode 100644 docs/examples/ghiper.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 5cd572401..060697a84 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -12,7 +12,7 @@ EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c debug.c \ anyauthput.c htmltitle.cc htmltidy.c opensslthreadlock.c \ cookie_interface.c cacertinmem.c synctime.c sampleconv.c ftpuploadresume.c \ - 10-at-a-time.c hiperfifo.c + 10-at-a-time.c hiperfifo.c ghiper.c all: @echo "done" diff --git a/docs/examples/ghiper.c b/docs/examples/ghiper.c new file mode 100644 index 000000000..7a3ae90c6 --- /dev/null +++ b/docs/examples/ghiper.c @@ -0,0 +1,462 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id: ghiper.c + * + * 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(). + +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" + +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 + +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. + +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> +#include <fcntl.h> +#include <stdlib.h> +#include <stdio.h> +#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; + guint timer_event; + int prev_running; + int still_running; + int requested; /* count: curl_easy_init() */ + int completed; /* count: curl_easy_cleanup() */ +} GlobalInfo; + + + +/* Information associated with a specific easy handle */ +typedef struct _ConnInfo { + CURL *easy; + char *url; + GlobalInfo *global; + char error[CURL_ERROR_SIZE]; +} ConnInfo; + + +/* Information associated with a specific socket */ +typedef struct _SockInfo { + curl_socket_t sockfd; + CURL *easy; + int action; + long timeout; + GIOChannel *ch; + guint ev; + GlobalInfo *global; +} SockInfo; + + + + +static void update_timeout(GlobalInfo *g); + + + + +/* Die if we get a bad CURLMcode somewhere */ +static void mcode_or_die(char *where, CURLMcode code) { + if ( CURLM_OK != code ) { + char *s; + switch (code) { + case CURLM_CALL_MULTI_PERFORM: s="CURLM_CALL_MULTI_PERFORM"; break; + case CURLM_OK: s="CURLM_OK"; break; + 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_run_count(GlobalInfo *g) +{ + if (g->prev_running > g->still_running) { + char *eff_url=NULL; + CURLMsg *msg; + int msgs_left; + ConnInfo *conn=NULL; + CURL*easy; + CURLcode res; + + MSG_OUT("REMAINING: %d\n", g->still_running); + /* + I am still uncertain whether it is safe to remove an easy handle + from inside the curl_multi_info_read loop, so here I will search + for completed transfers in the inner "while" loop, and then remove + them in the outer "do-while" loop... + */ + do { + easy=NULL; + while ((msg = curl_multi_info_read(g->multi, &msgs_left))) { + if (msg->msg == CURLMSG_DONE) { + easy=msg->easy_handle; + res=msg->data.result; + break; + } + } + if (easy) { + curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn); + curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url); + MSG_OUT("DONE: %s => (%d) %s\n", eff_url, res, conn->error); + curl_multi_remove_handle(g->multi, easy); + g_free(conn->url); + curl_easy_cleanup(easy); + g_free(conn); + g->completed++; + } + } while ( easy ); + MSG_OUT("Requested: %d Completed:%d\n", g->requested, g->completed); + } + g->prev_running = g->still_running; +} + + + + +/* Called by glib when our timeout expires */ +static gboolean timer_cb(gpointer data) +{ + GlobalInfo *g = (GlobalInfo *)data; + CURLMcode rc; + + do { + rc = curl_multi_socket(g->multi, CURL_SOCKET_TIMEOUT, &g->still_running); + } while (rc == CURLM_CALL_MULTI_PERFORM); + mcode_or_die("timer_cb: curl_multi_socket", rc); + check_run_count(g); + if ( g->still_running ) { update_timeout(g); } + return FALSE; +} + + + + +/* Update the event timer after curl_multi library calls */ +static void update_timeout(GlobalInfo *g) +{ + long timeout_ms; + curl_multi_timeout(g->multi, &timeout_ms); + if ( timeout_ms < 0 ) { return; } + /* MSG_OUT("update_timeout to %ld ms\n", timeout_ms); */ + g->timer_event = g_timeout_add(timeout_ms, timer_cb,g); +} + + + +/* Called by glib when we get action on a multi socket */ +static gboolean event_cb(GIOChannel *ch, GIOCondition condition, gpointer data) +{ + GlobalInfo *g = (GlobalInfo*) data; + CURLMcode rc; + int fd=g_io_channel_unix_get_fd(ch); + do { + rc = curl_multi_socket(g->multi, fd, &g->still_running); + } while (rc == CURLM_CALL_MULTI_PERFORM); + mcode_or_die("event_cb: curl_multi_socket", rc); + check_run_count(g); + if(g->still_running) { + update_timeout(g); + return TRUE; + } else { + MSG_OUT("last transfer done, kill timeout\n"); + 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); } + 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); + + 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); + +} + + + +/* Initialize a new SockInfo structure */ +static void addsock(curl_socket_t s, CURL *easy, int action, GlobalInfo *g) +{ + SockInfo *fdp = g_malloc0(sizeof(SockInfo)); + + fdp->global = g; + fdp->ch=g_io_channel_unix_new(s); + setsock(fdp, s, easy, action, 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) +{ + GlobalInfo *g = (GlobalInfo*) cbp; + SockInfo *fdp = (SockInfo*) sockp; + 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) { + MSG_OUT("\n"); + remsock(fdp); + } else { + if (!fdp) { + MSG_OUT("Adding data: %s%s\n", + what&CURL_POLL_IN?"READ":"", + what&CURL_POLL_OUT?"WRITE":"" ); + addsock(s, e, what, g); + } + else { + MSG_OUT( + "Changing action from %d to %d\n", fdp->action, what); + setsock(fdp, s, e, what, g); + } + } + return 0; +} + + + +/* CURLOPT_WRITEFUNCTION */ +static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data) +{ + size_t realsize = size * nmemb; + ConnInfo *conn = (ConnInfo*) data; + (void)ptr; + (void)conn; + return realsize; +} + + + +/* CURLOPT_PROGRESSFUNCTION */ +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 ) +{ + ConnInfo *conn; + CURLMcode rc; + + conn = g_malloc0(sizeof(ConnInfo)); + + conn->error[0]='\0'; + + conn->easy = curl_easy_init(); + if (!conn->easy) { + MSG_OUT("curl_easy_init() failed, exiting!\n"); + exit(2); + } + conn->global = g; + conn->url = g_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_VERBOSE, SHOW_VERBOSE); + curl_easy_setopt(conn->easy, CURLOPT_ERRORBUFFER, conn->error); + curl_easy_setopt(conn->easy, CURLOPT_PRIVATE, conn); + curl_easy_setopt(conn->easy, CURLOPT_NOPROGRESS, SHOW_PROGRESS?0:1); + curl_easy_setopt(conn->easy, CURLOPT_PROGRESSFUNCTION, prog_cb); + curl_easy_setopt(conn->easy, CURLOPT_PROGRESSDATA, conn); + curl_easy_setopt(conn->easy, CURLOPT_FOLLOWLOCATION, 1); + curl_easy_setopt(conn->easy, CURLOPT_CONNECTTIMEOUT, 30); + curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_LIMIT, 1); + curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_TIME, 30); + + MSG_OUT("Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url); + rc =curl_multi_add_handle(g->multi, conn->easy); + mcode_or_die("new_conn: curl_multi_add_handle", rc); + g->requested++; + do { + rc = curl_multi_socket_all(g->multi, &g->still_running); + } while (CURLM_CALL_MULTI_PERFORM == rc); + mcode_or_die("new_conn: curl_multi_socket_all", rc); + check_run_count(g); +} + + +/* 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 + 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); + g_free(buf); + } else { + buf = g_malloc(BUF_SIZE+1); + while (TRUE) { + buf[BUF_SIZE]='\0'; + g_io_channel_read_chars(ch,buf,BUF_SIZE,&len,&err); + if (len) { + buf[len]='\0'; + if (all) { + tmp=all; + all=g_strdup_printf("%s%s", tmp, buf); + g_free(tmp); + } else { + all = g_strdup(buf); + } + } else { + break; + } + } + if (all) { + new_conn(all,(GlobalInfo*)data); + g_free(all); + } + g_free(buf); + } + if ( err ) { + g_error("fifo_cb: %s", err->message); + g_free(err); + break; + } + } while ( (len) && (rv == G_IO_STATUS_NORMAL) ); + return TRUE; +} + + + + +int init_fifo(void) +{ + struct stat st; + 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); + + 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; + CURLMcode rc; + GMainLoop*gmain; + int fd; + GIOChannel* ch; + g=g_malloc0(sizeof(GlobalInfo)); + + 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->multi = curl_multi_init(); + curl_multi_setopt(g->multi, CURLMOPT_SOCKETFUNCTION, sock_cb); + curl_multi_setopt(g->multi, CURLMOPT_SOCKETDATA, g); + do { + rc = curl_multi_socket_all(g->multi, &g->still_running); + } while (CURLM_CALL_MULTI_PERFORM == rc); + update_timeout(g); + g_main_loop_run(gmain); + curl_multi_cleanup(g->multi); + return 0; +} -- cgit v1.2.1 From 083a84e5d0fda642433df6108561cc084b306f58 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Tue, 10 Oct 2006 19:48:24 +0000 Subject: repair id string --- docs/examples/ghiper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/ghiper.c b/docs/examples/ghiper.c index 7a3ae90c6..1aa197a08 100644 --- a/docs/examples/ghiper.c +++ b/docs/examples/ghiper.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id: ghiper.c + * $Id$ * * Example application source code using the multi socket interface to * download many files at once. -- cgit v1.2.1 From 4c04c091385a0d0659ef5b7086036a468ebeb843 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Thu, 12 Oct 2006 21:26:50 +0000 Subject: ghiper now uses the timer callback in the multi interface --- docs/examples/README | 4 +++- docs/examples/ghiper.c | 29 ++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/README b/docs/examples/README index 71d0ab96e..8d2f0d7af 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -47,7 +47,9 @@ 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 -hiperfifo.c - downloads all URLs written to the fifo +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 htmltitle.cc - download a HTML file and extract the <title> tag from a HTML page using libxml http-post.c - HTTP POST diff --git a/docs/examples/ghiper.c b/docs/examples/ghiper.c index 1aa197a08..cd0895b5f 100644 --- a/docs/examples/ghiper.c +++ b/docs/examples/ghiper.c @@ -90,11 +90,6 @@ typedef struct _SockInfo { -static void update_timeout(GlobalInfo *g); - - - - /* Die if we get a bad CURLMcode somewhere */ static void mcode_or_die(char *where, CURLMcode code) { if ( CURLM_OK != code ) { @@ -175,25 +170,29 @@ static gboolean timer_cb(gpointer data) } while (rc == CURLM_CALL_MULTI_PERFORM); mcode_or_die("timer_cb: curl_multi_socket", rc); check_run_count(g); - if ( g->still_running ) { update_timeout(g); } return FALSE; } - /* Update the event timer after curl_multi library calls */ -static void update_timeout(GlobalInfo *g) +static int update_timeout_cb(CURLM *multi, long timeout_ms, void *userp) { - long timeout_ms; - curl_multi_timeout(g->multi, &timeout_ms); - if ( timeout_ms < 0 ) { return; } - /* MSG_OUT("update_timeout to %ld ms\n", timeout_ms); */ - g->timer_event = g_timeout_add(timeout_ms, timer_cb,g); + struct timeval timeout; + GlobalInfo *g=(GlobalInfo *)userp; + timeout.tv_sec = timeout_ms/1000; + timeout.tv_usec = (timeout_ms%1000)*1000; + + MSG_OUT("*** update_timeout_cb %ld => %ld:%ld ***\n", + 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) { @@ -206,7 +205,6 @@ static gboolean event_cb(GIOChannel *ch, GIOCondition condition, gpointer data) mcode_or_die("event_cb: curl_multi_socket", rc); check_run_count(g); if(g->still_running) { - update_timeout(g); return TRUE; } else { MSG_OUT("last transfer done, kill timeout\n"); @@ -452,10 +450,11 @@ int main(int argc, char **argv) g->multi = curl_multi_init(); curl_multi_setopt(g->multi, CURLMOPT_SOCKETFUNCTION, sock_cb); curl_multi_setopt(g->multi, CURLMOPT_SOCKETDATA, g); + curl_multi_setopt(g->multi, CURLMOPT_TIMERFUNCTION, update_timeout_cb); + curl_multi_setopt(g->multi, CURLMOPT_TIMERDATA, g); do { rc = curl_multi_socket_all(g->multi, &g->still_running); } while (CURLM_CALL_MULTI_PERFORM == rc); - update_timeout(g); g_main_loop_run(gmain); curl_multi_cleanup(g->multi); return 0; -- cgit v1.2.1 From f53347631eb4a5a075589e6fece43aced010a5bb Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Fri, 13 Oct 2006 14:01:19 +0000 Subject: Added comments about checking return code and the maxfd counter --- docs/examples/10-at-a-time.c | 3 +++ docs/examples/fopen.c | 4 ++++ docs/examples/multi-app.c | 4 ++++ docs/examples/multi-debugcallback.c | 4 ++++ docs/examples/multi-double.c | 4 ++++ docs/examples/multi-post.c | 4 ++++ docs/examples/multi-single.c | 4 ++++ 7 files changed, 27 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index be3b6faee..50392259c 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -123,6 +123,9 @@ int main(void) return EXIT_FAILURE; } + /* In a real-world program you OF COURSE check the return that maxfd is + bigger than -1 so that the call to select() below makes sense! */ + if (curl_multi_timeout(cm, &L)) { fprintf(stderr, "E: curl_multi_timeout\n"); return EXIT_FAILURE; diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index a2e6fc94a..de235bbc4 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -153,6 +153,10 @@ fill_buffer(URL_FILE *file,int want,int waittime) /* get file descriptors from the transfers */ curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + /* In a real-world program you OF COURSE check the return code of the + function calls, *and* you make sure that maxfd is bigger than -1 + so that the call to select() below makes sense! */ + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); switch(rc) { diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index 5383a40ae..6c0ef7e7f 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -80,6 +80,10 @@ int main(int argc, char **argv) /* get file descriptors from the transfers */ curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + /* In a real-world program you OF COURSE check the return code of the + function calls, *and* you make sure that maxfd is bigger than -1 so + that the call to select() below makes sense! */ + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); switch(rc) { diff --git a/docs/examples/multi-debugcallback.c b/docs/examples/multi-debugcallback.c index 286267219..4c93df4dc 100644 --- a/docs/examples/multi-debugcallback.c +++ b/docs/examples/multi-debugcallback.c @@ -153,6 +153,10 @@ int main(int argc, char **argv) /* get file descriptors from the transfers */ curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + /* In a real-world program you OF COURSE check the return code of the + function calls, *and* you make sure that maxfd is bigger than -1 + so that the call to select() below makes sense! */ + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); switch(rc) { diff --git a/docs/examples/multi-double.c b/docs/examples/multi-double.c index 51b4ed370..0a4cde855 100644 --- a/docs/examples/multi-double.c +++ b/docs/examples/multi-double.c @@ -71,6 +71,10 @@ int main(int argc, char **argv) /* get file descriptors from the transfers */ curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + /* In a real-world program you OF COURSE check the return code of the + function calls, *and* you make sure that maxfd is bigger than -1 so + that the call to select() below makes sense! */ + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); switch(rc) { diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index b89e2d632..894ace0ed 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -93,6 +93,10 @@ int main(int argc, char *argv[]) /* get file descriptors from the transfers */ curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + /* In a real-world program you OF COURSE check the return code of the + function calls, *and* you make sure that maxfd is bigger than -1 + so that the call to select() below makes sense! */ + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); switch(rc) { diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c index 0ba932f7a..b23f3c9d4 100644 --- a/docs/examples/multi-single.c +++ b/docs/examples/multi-single.c @@ -65,6 +65,10 @@ int main(int argc, char **argv) /* get file descriptors from the transfers */ curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + /* In a real-world program you OF COURSE check the return code of the + function calls, *and* you make sure that maxfd is bigger than -1 so + that the call to select() below makes sense! */ + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); switch(rc) { -- cgit v1.2.1 From 7575e6afc44f30f07a9bc8c2696c1fb451fd323e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Fri, 20 Oct 2006 21:26:10 +0000 Subject: made the arrow for 'Send SSL data' point in the right direction! --- docs/examples/debug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/debug.c b/docs/examples/debug.c index 153f3839e..1443ae55d 100644 --- a/docs/examples/debug.c +++ b/docs/examples/debug.c @@ -84,6 +84,9 @@ int my_trace(CURL *handle, curl_infotype type, 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; @@ -93,9 +96,6 @@ int my_trace(CURL *handle, curl_infotype type, case CURLINFO_SSL_DATA_IN: text = "<= Recv SSL data"; break; - case CURLINFO_SSL_DATA_OUT: - text = "<= Send SSL data"; - break; } dump(text, stderr, data, size, config->trace_ascii); -- cgit v1.2.1 From 609044aea2ffa2520b14b810e46e2a256c8db56c Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Sun, 29 Oct 2006 21:19:23 +0000 Subject: Compiler warning fix --- docs/examples/curlx.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 1ee384ff2..31f01e8ad 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -114,6 +114,13 @@ static char *curlx_usage[]={ */ +/* + * We use this ZERO_NULL to avoid picky compiler warnings, + * when assigning a NULL pointer to a function pointer var. + */ + +#define ZERO_NULL 0 + /* This is a context that we pass to all callbacks */ typedef struct sslctxparm_st { @@ -236,7 +243,7 @@ static CURLcode sslctxfun(CURL * curl, void * sslctx, void * parm) { SSL_CTX_set_verify_depth(ctx,2); - SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,NULL); + SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,ZERO_NULL); SSL_CTX_set_cert_verify_callback(ctx, ssl_app_verify_callback, parm); -- cgit v1.2.1 From a03c76b228fc85e457934335d46173b967721644 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 8 Nov 2006 08:49:27 +0000 Subject: ok stop using old and deprecated options --- docs/examples/sepheaders.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index 6e8735168..cf2f419d6 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -41,9 +41,6 @@ int main(int argc, char **argv) /* no progress meter please */ curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1); - /* shut up completely */ - curl_easy_setopt(curl_handle, CURLOPT_MUTE, 1); - /* send all data to this function */ curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data); -- cgit v1.2.1 From c6ff612f6e757f02d0258166ffbf530727e402dc Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Sun, 19 Nov 2006 21:55:34 +0000 Subject: Frank Teo provided an updated, mostly docs changed --- docs/examples/synctime.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/synctime.c b/docs/examples/synctime.c index fc629ee33..cd8d0805d 100644 --- a/docs/examples/synctime.c +++ b/docs/examples/synctime.c @@ -9,6 +9,18 @@ * * This example code only builds as-is on Windows. * + * While Unix/Linux user, you do not need this software. + * You can achieve the same result as synctime using curl, awk and date. + * Set proxy as according to your network, but beware of proxy Cache-Control. + * + * To set your system clock, root access is required. + * # date -s "`curl -sI http://nist.time.gov/timezone.cgi?UTC/s/0 \ + * | awk -F': ' '/Date: / {print $2}'`" + * + * To view remote webserver date and time. + * $ curl -sI http://nist.time.gov/timezone.cgi?UTC/s/0 \ + * | awk -F': ' '/Date: / {print $2}' + * * Synchronising your computer clock via Internet time server usually relies * on DAYTIME, TIME, or NTP protocols. These protocols provide good accurate * time synchronisation but it does not work very well through a @@ -300,10 +312,11 @@ int main(int argc, char *argv[]) MthStr[LOCALTime.wMonth-1], LOCALTime.wYear, LOCALTime.wHour, LOCALTime.wMinute, LOCALTime.wSecond, LOCALTime.wMilliseconds); - fprintf(stderr, "\nBefore HTTP. Date: %s%s\n\n", timeBuf, tzoneBuf); + + fprintf(stderr, "Fetch: %s\n\n", conf->timeserver); + fprintf(stderr, "Before HTTP. Date: %s%s\n\n", timeBuf, tzoneBuf); /* HTTP HEAD command to the Webserver */ - fprintf(stderr, "Fetch: %s\n", conf->timeserver); SyncTime_CURL_Fetch(curl, conf->timeserver, "index.htm", HTTP_COMMAND_HEAD); -- cgit v1.2.1 From 605a39117810a9bb3e99e2aba8c4d5fc7afa5db8 Mon Sep 17 00:00:00 2001 From: Gisle Vanem <gvanem@broadpark.no> Date: Sat, 17 Mar 2007 17:58:45 +0000 Subject: Added cvs id. Use TOPDIR variable. Updated CSOURCES. Dependencies are now put in external file depend.dj. --- docs/examples/makefile.dj | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/makefile.dj b/docs/examples/makefile.dj index d0d4b67f0..4e33c0151 100644 --- a/docs/examples/makefile.dj +++ b/docs/examples/makefile.dj @@ -1,13 +1,16 @@ +# $Id$ # # Adapted for djgpp / Watt-32 / DOS by # Gisle Vanem <giva@bgnett.no> # -include ../../packages/DOS/common.dj +TOPDIR = ../.. -CFLAGS += -I../../include -DFALSE=0 -DTRUE=1 +include $(TOPDIR)/packages/DOS/common.dj -LIBS = ../../lib/libcurl.a +CFLAGS += -DFALSE=0 -DTRUE=1 + +LIBS = $(TOPDIR)/lib/libcurl.a ifeq ($(USE_SSL),1) LIBS += $(OPENSSL_ROOT)/lib/libssl.a $(OPENSSL_ROOT)/lib/libcrypt.a @@ -15,22 +18,24 @@ endif LIBS += $(WATT32_ROOT)/lib/libwatt.a $(ZLIB_ROOT)/libz.a -CSOURCES = fopen.c ftpget.c ftpgetresp.c ftpupload.c getinmemory.c \ - http-post.c httpput.c multi-app.c multi-double.c multi-post.c \ - multi-single.c persistant.c post-callback.c postit2.c \ - sepheaders.c simple.c simplessl.c https.c ftp3rdparty.c \ - getinfo.c anyauthput.c cookie_interface.c 10-at-a-time.c +CSOURCES = fopen.c ftpget.c ftpgetresp.c ftpupload.c getinmemory.c \ + http-post.c httpput.c https.c multi-app.c multi-double.c \ + multi-post.c multi-single.c persistant.c post-callback.c \ + postit2.c sepheaders.c simple.c simplepost.c simplessl.c \ + multi-debugcallback.c fileupload.c getinfo.c anyauthput.c \ + 10-at-a-time.c # ftpuploadresume.c ftp3rdparty.c cookie_interface.c PROGRAMS = $(CSOURCES:.c=.exe) all: $(PROGRAMS) + @echo Welcome to libcurl example program %.exe: %.c $(CC) $(CFLAGS) -o $@ $^ $(LIBS) @echo -clean: - rm -f $(PROGRAMS) +clean vclean realclean: + - rm -f $(PROGRAMS) depend.dj -# DO NOT DELETE THIS LINE +-include depend.dj -- cgit v1.2.1 From 1afb67e31b3e8f952e39e4de4f1abeac3fc84376 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 2 May 2007 13:52:38 +0000 Subject: - Jeff Pohlmeyer improved the hiperfifo.c example to use the CURLMOPT_TIMERFUNCTION callback option. --- docs/examples/hiperfifo.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index f640bf9dc..e8d767133 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -92,18 +92,15 @@ typedef struct _SockInfo { /* Update the event timer after curl_multi library calls */ -static void update_timeout(GlobalInfo *g) +static int multi_timer_cb(CURLM *multi, long timeout_ms, GlobalInfo *g) { - long timeout_ms; struct timeval timeout; - curl_multi_timeout(g->multi, &timeout_ms); - if(timeout_ms < 0) - return; - timeout.tv_sec = timeout_ms/1000; timeout.tv_usec = (timeout_ms%1000)*1000; + fprintf(MSG_OUT, "multi_timer_cb: Setting timeout to %ld ms\n", timeout_ms); evtimer_add(&g->timer_event, &timeout); + return 0; } @@ -185,9 +182,7 @@ static void event_cb(int fd, short kind, void *userp) } while (rc == CURLM_CALL_MULTI_PERFORM); mcode_or_die("event_cb: curl_multi_socket", rc); check_run_count(g); - if(g->still_running) { - update_timeout(g); - } else { + if ( g->still_running <= 0 ) { fprintf(MSG_OUT, "last transfer done, kill timeout\n"); if (evtimer_pending(&g->timer_event, NULL)) { evtimer_del(&g->timer_event); @@ -210,7 +205,6 @@ static void timer_cb(int fd, short kind, void *userp) } while (rc == CURLM_CALL_MULTI_PERFORM); mcode_or_die("timer_cb: curl_multi_socket", rc); check_run_count(g); - if ( g->still_running ) { update_timeout(g); } } @@ -406,10 +400,11 @@ int main(int argc, char **argv) evtimer_set(&g.timer_event, timer_cb, &g); curl_multi_setopt(g.multi, CURLMOPT_SOCKETFUNCTION, sock_cb); curl_multi_setopt(g.multi, CURLMOPT_SOCKETDATA, &g); + curl_multi_setopt(g.multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb); + curl_multi_setopt(g.multi, CURLMOPT_TIMERDATA, &g); do { rc = curl_multi_socket_all(g.multi, &g.still_running); } while (CURLM_CALL_MULTI_PERFORM == rc); - update_timeout(&g); event_dispatch(); curl_multi_cleanup(g.multi); return 0; -- cgit v1.2.1 From 8edbe262d90ff0bb860becea58a39b7e6eaa2ebc Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 27 Jun 2007 21:29:29 +0000 Subject: fix little flaw that could make the transfer loop end prematurely --- docs/examples/10-at-a-time.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index 50392259c..41c2f4883 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -155,6 +155,8 @@ int main(void) } if (C < CNT) { init(cm, C++); + U++; /* just to prevent it from remaining at 0 if there are more + URLs to get */ } } } -- cgit v1.2.1 From 9ca688c8e71c9b3313ceeaf1f4037341befd3c0c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 27 Jun 2007 21:35:17 +0000 Subject: James Bursa's improvement --- docs/examples/10-at-a-time.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index 41c2f4883..29c7f08d9 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -13,7 +13,10 @@ * Written by Michael Wallner */ +#include <errno.h> #include <stdlib.h> +#include <string.h> +#include <unistd.h> #include <curl/multi.h> static const char *urls[] = { @@ -106,6 +109,10 @@ int main(void) cm = curl_multi_init(); + /* we can optionally limit the total amount of connections this multi handle + uses */ + curl_multi_setopt(cm, CURLMOPT_MAXCONNECTS, MAX); + for (C = 0; C < MAX; ++C) { init(cm, C); } @@ -123,20 +130,24 @@ int main(void) return EXIT_FAILURE; } - /* In a real-world program you OF COURSE check the return that maxfd is - bigger than -1 so that the call to select() below makes sense! */ - if (curl_multi_timeout(cm, &L)) { fprintf(stderr, "E: curl_multi_timeout\n"); return EXIT_FAILURE; } - - T.tv_sec = L/1000; - T.tv_usec = (L%1000)*1000; - - if (0 > select(M+1, &R, &W, &E, &T)) { - fprintf(stderr, "E: select\n"); - return EXIT_FAILURE; + if (L == -1) + L = 100; + + if (M == -1) { + sleep(L / 1000); + } else { + T.tv_sec = L/1000; + T.tv_usec = (L%1000)*1000; + + 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; + } } } -- cgit v1.2.1 From e2bac4fe6f290af6408570f3ed918e4672866c31 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Fri, 6 Jul 2007 20:14:03 +0000 Subject: add note about windows and dlls with CURLOPT_WRITEDATA --- docs/examples/ftpgetresp.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index 82b1d36a7..cf61ded02 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -34,7 +34,7 @@ int main(int argc, char **argv) CURLcode res; FILE *ftpfile; FILE *respfile; - + /* local file name to store the file as */ ftpfile = fopen("ftp-list", "wb"); /* b is binary, needed on win32 */ @@ -46,6 +46,8 @@ int main(int argc, char **argv) /* Get a file listing from sunet */ curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.sunet.se/"); curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftpfile); + /* If you intend to use this on windows with a libcurl DLL, you must use + CURLOPT_WRITEFUNCTION as well */ curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_response); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, respfile); res = curl_easy_perform(curl); -- cgit v1.2.1 From ffff8ddbef298d960bb4f91128298cf28f8d9928 Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Thu, 12 Jul 2007 20:38:54 +0000 Subject: Compile most of the example apps in docs/examples when doing a 'make check'. --- docs/examples/Makefile.am | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 060697a84..64a79dce2 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -2,17 +2,31 @@ # $Id$ # -AUTOMAKE_OPTIONS = foreign no-dependencies - -EXTRA_DIST = README curlgtk.c sepheaders.c simple.c postit2.c \ - persistant.c ftpget.c Makefile.example multithread.c getinmemory.c \ - ftpupload.c httpput.c simplessl.c ftpgetresp.c http-post.c \ - post-callback.c multi-app.c multi-double.c multi-single.c \ - multi-post.c fopen.c simplepost.c makefile.dj curlx.c https.c \ - multi-debugcallback.c fileupload.c getinfo.c ftp3rdparty.c debug.c \ - anyauthput.c htmltitle.cc htmltidy.c opensslthreadlock.c \ - cookie_interface.c cacertinmem.c synctime.c sampleconv.c ftpuploadresume.c \ - 10-at-a-time.c hiperfifo.c ghiper.c - -all: - @echo "done" +AUTOMAKE_OPTIONS = foreign nostdinc + +EXTRA_DIST = README Makefile.example makefile.dj $(COMPLICATED_EXAMPLES) + +INCLUDES = -I$(top_srcdir)/include/curl \ + -I$(top_builddir)/lib \ + -I$(top_srcdir)/lib + +LIBDIR = $(top_builddir)/lib + +# Dependencies +LDADD = $(LIBDIR)/libcurl.la + +# These are all libcurl example programs to be test compiled +noinst_PROGRAMS = 10-at-a-time anyauthput cookie_interface \ + debug fileupload fopen ftpget ftpgetresp ftpupload \ + getinfo getinmemory http-post httpput \ + https multi-app multi-debugcallback multi-double \ + multi-post multi-single persistant post-callback \ + postit2 sepheaders simple simplepost simplessl + +# These examples require external dependencies that may not be commonly +# available on POSIX systems, so don't bother attempting to compile them here. +COMPLICATED_EXAMPLES = \ + curlgtk.c curlx.c htmltitle.cc cacertinmem.c ftpuploadresume.c \ + ghiper.c hiperfifo.c htmltidy.c multithread.c \ + opensslthreadlock.c sampleconv.c synctime.c + -- cgit v1.2.1 From f5a6355172fce41ce66acf84ca645d6df2c833a8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Thu, 12 Jul 2007 20:54:54 +0000 Subject: fix include path --- docs/examples/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 64a79dce2..5fa9a496f 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -6,7 +6,7 @@ AUTOMAKE_OPTIONS = foreign nostdinc EXTRA_DIST = README Makefile.example makefile.dj $(COMPLICATED_EXAMPLES) -INCLUDES = -I$(top_srcdir)/include/curl \ +INCLUDES = -I$(top_srcdir)/include \ -I$(top_builddir)/lib \ -I$(top_srcdir)/lib -- cgit v1.2.1 From 4a728747e6f8845e500910e397dfc99aaf4a7984 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Thu, 12 Jul 2007 20:55:17 +0000 Subject: make it compile fine --- docs/examples/anyauthput.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index c5486333e..54cea0017 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -11,6 +11,7 @@ #include <stdio.h> #include <fcntl.h> #include <sys/stat.h> +#include <unistd.h> #include <curl/curl.h> @@ -18,6 +19,10 @@ #error "upgrade your libcurl to no less than 7.12.3" #endif +#ifndef TRUE +#define TRUE 1 +#endif + /* * This example shows a HTTP PUT operation with authentiction using "any" * type. It PUTs a file given as a command line argument to the URL also given -- cgit v1.2.1 From 49ce3e5160a9576e797bf87cef012b09d1c54ecb Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Thu, 12 Jul 2007 21:11:10 +0000 Subject: Fixed some compile warnings and errors and improved portability in the examples. Removed ftp3rdparty.c since libcurl doesn't support 3rd party FTP transfers any longer. --- docs/examples/cacertinmem.c | 1 + docs/examples/cookie_interface.c | 4 +- docs/examples/curlx.c | 17 ++++--- docs/examples/fileupload.c | 1 - docs/examples/fopen.c | 18 +++---- docs/examples/ftp3rdparty.c | 103 -------------------------------------- docs/examples/ftpget.c | 4 +- docs/examples/ftpupload.c | 7 ++- docs/examples/ftpuploadresume.c | 20 ++++---- docs/examples/ghiper.c | 8 +-- docs/examples/hiperfifo.c | 4 +- docs/examples/httpput.c | 4 +- docs/examples/https.c | 2 +- docs/examples/multi-app.c | 2 +- docs/examples/multi-post.c | 4 +- docs/examples/multithread.c | 4 +- docs/examples/opensslthreadlock.c | 7 ++- docs/examples/post-callback.c | 6 +-- docs/examples/postit2.c | 2 +- docs/examples/sepheaders.c | 4 +- docs/examples/simplepost.c | 3 +- docs/examples/simplessl.c | 7 ++- docs/examples/synctime.c | 8 +-- 23 files changed, 71 insertions(+), 169 deletions(-) delete mode 100644 docs/examples/ftp3rdparty.c (limited to 'docs/examples') diff --git a/docs/examples/cacertinmem.c b/docs/examples/cacertinmem.c index de5e3248e..e58c9ace9 100644 --- a/docs/examples/cacertinmem.c +++ b/docs/examples/cacertinmem.c @@ -135,4 +135,5 @@ int main(void) curl_easy_cleanup(ch); curl_global_cleanup(); + return rv; } diff --git a/docs/examples/cookie_interface.c b/docs/examples/cookie_interface.c index d184edb54..a39106e34 100644 --- a/docs/examples/cookie_interface.c +++ b/docs/examples/cookie_interface.c @@ -74,7 +74,7 @@ main(void) #define snprintf _snprintf #endif /* Netscape format cookie */ - snprintf(nline, 256, "%s\t%s\t%s\t%s\t%u\t%s\t%s", + snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%u\t%s\t%s", ".google.com", "TRUE", "/", "FALSE", time(NULL) + 31337, "PREF", "hello google, i like you very much!"); res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline); if (res != CURLE_OK) { @@ -83,7 +83,7 @@ main(void) } /* HTTP-header style cookie */ - snprintf(nline, 256, + snprintf(nline, sizeof(nline), "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); diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 31f01e8ad..636c8b4fe 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -81,6 +81,7 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <curl/curl.h> #include <openssl/x509v3.h> #include <openssl/x509_vfy.h> @@ -94,13 +95,13 @@ #include <openssl/bio.h> #include <openssl/ssl.h> -static char *curlx_usage[]={ +static const char *curlx_usage[]={ "usage: curlx args\n", " -p12 arg - tia file ", " -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.openevidenve.org", + " -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", @@ -268,19 +269,21 @@ int main(int argc, char **argv) { char* mimetype; char* mimetypeaccept=NULL; char* contenttype; - char** pp; + const char** pp; unsigned char* hostporturl = NULL; - binaryptr=(char*)malloc(tabLength); BIO * p12bio ; char **args = argv + 1; unsigned char * serverurl; sslctxparm p; char *response; - p.verbose = 0; CURLcode res; struct curl_slist * headers=NULL; + int badarg=0; + + binaryptr=(char*)malloc(tabLength); + p.verbose = 0; p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); curl_global_init(CURL_GLOBAL_DEFAULT); @@ -292,7 +295,6 @@ int main(int argc, char **argv) { ERR_load_crypto_strings(); - int badarg=0; while (*args && *args[0] == '-') { if (!strcmp (*args, "-in")) { @@ -407,10 +409,9 @@ int main(int argc, char **argv) { } 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 " "cherching in others certificats\n"); - int j=0; - int find=0; 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))) diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c index 455cb0ecf..0f6e69d20 100644 --- a/docs/examples/fileupload.c +++ b/docs/examples/fileupload.c @@ -17,7 +17,6 @@ int main(void) { CURL *curl; CURLcode res; - curl_off_t size; struct stat file_info; double speed_upload, total_time; FILE *fd; diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index de235bbc4..7c50b0cc6 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -70,7 +70,7 @@ struct fcurl_data typedef struct fcurl_data URL_FILE; /* exported functions */ -URL_FILE *url_fopen(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); @@ -93,11 +93,11 @@ write_callback(char *buffer, URL_FILE *url = (URL_FILE *)userp; size *= nitems; - rembuff=url->buffer_len - url->buffer_pos;//remaining space in buffer + rembuff=url->buffer_len - url->buffer_pos; /* remaining space in buffer */ if(size > rembuff) { - //not enuf space in buffer + /* not enough space in buffer */ newbuff=realloc(url->buffer,url->buffer_len + (size - rembuff)); if(newbuff==NULL) { @@ -211,7 +211,7 @@ use_buffer(URL_FILE *file,int want) URL_FILE * -url_fopen(char *url,const char *operation) +url_fopen(const char *url,const char *operation) { /* this code could check for URLs or types in the 'url' and basicly use the real fopen() for standard files */ @@ -236,7 +236,7 @@ url_fopen(char *url,const char *operation) curl_easy_setopt(file->handle.curl, CURLOPT_URL, url); curl_easy_setopt(file->handle.curl, CURLOPT_WRITEDATA, file); - curl_easy_setopt(file->handle.curl, CURLOPT_VERBOSE, FALSE); + curl_easy_setopt(file->handle.curl, CURLOPT_VERBOSE, 0); curl_easy_setopt(file->handle.curl, CURLOPT_WRITEFUNCTION, write_callback); if(!multi_handle) @@ -466,7 +466,7 @@ main(int argc, char *argv[]) int nread; char buffer[256]; - char *url; + const char *url; if(argc < 2) { @@ -481,7 +481,7 @@ main(int argc, char *argv[]) outf=fopen("fgets.test","w+"); if(!outf) { - perror("couldnt open fgets output file\n"); + perror("couldn't open fgets output file\n"); return 1; } @@ -508,7 +508,7 @@ main(int argc, char *argv[]) outf=fopen("fread.test","w+"); if(!outf) { - perror("couldnt open fread output file\n"); + perror("couldn't open fread output file\n"); return 1; } @@ -533,7 +533,7 @@ main(int argc, char *argv[]) outf=fopen("rewind.test","w+"); if(!outf) { - perror("couldnt open fread output file\n"); + perror("couldn't open fread output file\n"); return 1; } diff --git a/docs/examples/ftp3rdparty.c b/docs/examples/ftp3rdparty.c deleted file mode 100644 index b4756f580..000000000 --- a/docs/examples/ftp3rdparty.c +++ /dev/null @@ -1,103 +0,0 @@ -/***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * $Id$ - */ - -#include <stdio.h> - -#include <curl/curl.h> -#include <curl/types.h> -#include <curl/easy.h> - -/* - * This is an example showing how to transfer a file between two remote hosts. - * 7.13.0 or later required. - */ - -int main(void) -{ - CURL *curl; - CURLcode res; - char source_url[] = "ftp://remotehost.com/path/to/source"; - char target_url[] = "ftp://aotherserver.com/path/to/dest"; - - char sourceUserPass[] = "user:pass"; - char targetUserPass[] = "user:pass"; - char url[100]; - - struct curl_slist *source_pre_cmd = NULL; - struct curl_slist *target_pre_cmd = NULL; - struct curl_slist *source_post_cmd = NULL; - struct curl_slist *target_post_cmd = NULL; - char cmd[] = "PWD"; /* just to test */ - - curl_global_init(CURL_GLOBAL_DEFAULT); - - curl = curl_easy_init(); - if (curl) { - /* The ordinary URL is the target when speaking 3rd party transfers */ - curl_easy_setopt(curl, CURLOPT_URL, target_url); - - /* Set a source URL */ - curl_easy_setopt(curl, CURLOPT_SOURCE_URL, source_url); - - /* Set target user and password */ - curl_easy_setopt(curl, CURLOPT_USERPWD, targetUserPass); - - /* Set source user and password */ - curl_easy_setopt(curl, CURLOPT_SOURCE_USERPWD, sourceUserPass); - -#if 0 - /* FTPPORT enables PORT on the target side, instead of PASV. */ - curl_easy_setopt(curl, CURLOPT_FTPPORT, ""); /* optional */ -#endif - - /* build a list of commands to pass to libcurl */ - source_pre_cmd = curl_slist_append(source_pre_cmd, cmd); - /* Set a proxy pre-quote command */ - curl_easy_setopt(curl, CURLOPT_SOURCE_PREQUOTE, source_pre_cmd); - - /* build a list of commands to pass to libcurl */ - target_pre_cmd = curl_slist_append(target_pre_cmd, cmd); - /* Set a pre-quote command */ - curl_easy_setopt(curl, CURLOPT_PREQUOTE, target_pre_cmd); - - /* build a list of commands to pass to libcurl */ - source_post_cmd = curl_slist_append(source_post_cmd, cmd); - /* Set a proxy post-quote command */ - curl_easy_setopt(curl, CURLOPT_SOURCE_POSTQUOTE, source_post_cmd); - - /* build a list of commands to pass to libcurl */ - target_post_cmd = curl_slist_append(target_post_cmd, cmd); - /* Set a post-quote command */ - curl_easy_setopt(curl, CURLOPT_POSTQUOTE, target_post_cmd); - - /* Switch on full protocol/debug output */ - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); - - res = curl_easy_perform(curl); - - /* clean up the FTP commands list */ - curl_slist_free_all(source_pre_cmd); - curl_slist_free_all(target_pre_cmd); - curl_slist_free_all(source_post_cmd); - curl_slist_free_all(target_post_cmd); - - /* always cleanup */ - curl_easy_cleanup(curl); - - if(CURLE_OK != res) { - /* we failed */ - fprintf(stderr, "curl told us %d\n", res); - } - } - - curl_global_cleanup(); - - return 0; -} diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 0274b7f69..4e3fc8fc3 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -22,7 +22,7 @@ */ struct FtpFile { - char *filename; + const char *filename; FILE *stream; }; @@ -65,7 +65,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile); /* Switch on full protocol/debug output */ - curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); res = curl_easy_perform(curl); diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index c0ae40a26..65f8a8a79 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -31,14 +31,13 @@ int main(int argc, char **argv) { CURL *curl; CURLcode res; - FILE *ftpfile; FILE * hd_src ; int hd ; struct stat file_info; struct curl_slist *headerlist=NULL; - char buf_1 [] = "RNFR " UPLOAD_FILE_AS; - char buf_2 [] = "RNTO " RENAME_FILE_TO; + static const char buf_1 [] = "RNFR " UPLOAD_FILE_AS; + static const char buf_2 [] = "RNTO " RENAME_FILE_TO; /* get the file size of the local file */ hd = open(LOCAL_FILE, O_RDONLY) ; @@ -61,7 +60,7 @@ int main(int argc, char **argv) headerlist = curl_slist_append(headerlist, buf_2); /* enable uploading */ - curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ; + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1) ; /* specify target */ curl_easy_setopt(curl,CURLOPT_URL, REMOTE_URL); diff --git a/docs/examples/ftpuploadresume.c b/docs/examples/ftpuploadresume.c index f83cd0a2d..8e6be977a 100644 --- a/docs/examples/ftpuploadresume.c +++ b/docs/examples/ftpuploadresume.c @@ -24,7 +24,9 @@ /* The MinGW headers are missing a few Win32 function definitions, you shouldn't need this if you use VC++ */ +#ifdef __MINGW32__ int __cdecl _snscanf(const char * input, size_t length, const char * format, ...); +#endif /* parse headers for Content-Length */ @@ -75,7 +77,7 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath, return 0; } - curl_easy_setopt(curlhandle, CURLOPT_UPLOAD, TRUE); + curl_easy_setopt(curlhandle, CURLOPT_UPLOAD, 1); curl_easy_setopt(curlhandle, CURLOPT_URL, remotepath); @@ -91,9 +93,9 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath, curl_easy_setopt(curlhandle, CURLOPT_READDATA, f); curl_easy_setopt(curlhandle, CURLOPT_FTPPORT, "-"); /* disable passive mode */ - curl_easy_setopt(curlhandle, CURLOPT_FTP_CREATE_MISSING_DIRS, TRUE); + curl_easy_setopt(curlhandle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1); - curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, TRUE); + curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, 1); for (c = 0; (r != CURLE_OK) && (c < tries); c++) { /* are we resuming? */ @@ -108,22 +110,22 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath, * because HEADER will dump the headers to stdout * without it. */ - curl_easy_setopt(curlhandle, CURLOPT_NOBODY, TRUE); - curl_easy_setopt(curlhandle, CURLOPT_HEADER, TRUE); + curl_easy_setopt(curlhandle, CURLOPT_NOBODY, 1); + curl_easy_setopt(curlhandle, CURLOPT_HEADER, 1); r = curl_easy_perform(curlhandle); if (r != CURLE_OK) continue; - curl_easy_setopt(curlhandle, CURLOPT_NOBODY, FALSE); - curl_easy_setopt(curlhandle, CURLOPT_HEADER, FALSE); + curl_easy_setopt(curlhandle, CURLOPT_NOBODY, 0); + curl_easy_setopt(curlhandle, CURLOPT_HEADER, 0); fseek(f, uploaded_len, SEEK_SET); - curl_easy_setopt(curlhandle, CURLOPT_FTPAPPEND, TRUE); + curl_easy_setopt(curlhandle, CURLOPT_FTPAPPEND, 1); } else { /* no */ - curl_easy_setopt(curlhandle, CURLOPT_FTPAPPEND, FALSE); + curl_easy_setopt(curlhandle, CURLOPT_FTPAPPEND, 0); } r = curl_easy_perform(curlhandle); diff --git a/docs/examples/ghiper.c b/docs/examples/ghiper.c index cd0895b5f..db7d3cb1c 100644 --- a/docs/examples/ghiper.c +++ b/docs/examples/ghiper.c @@ -91,9 +91,9 @@ typedef struct _SockInfo { /* Die if we get a bad CURLMcode somewhere */ -static void mcode_or_die(char *where, CURLMcode code) { +static void mcode_or_die(const char *where, CURLMcode code) { if ( CURLM_OK != code ) { - char *s; + const char *s; switch (code) { case CURLM_CALL_MULTI_PERFORM: s="CURLM_CALL_MULTI_PERFORM"; break; case CURLM_OK: s="CURLM_OK"; break; @@ -259,7 +259,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) { GlobalInfo *g = (GlobalInfo*) cbp; SockInfo *fdp = (SockInfo*) sockp; - char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE" }; + 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) { @@ -402,7 +402,7 @@ static gboolean fifo_cb (GIOChannel *ch, GIOCondition condition, gpointer data) int init_fifo(void) { struct stat st; - char *fifo = "hiper.fifo"; + const char *fifo = "hiper.fifo"; int socket; if (lstat (fifo, &st) == 0) { diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index e8d767133..76e506fb5 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -252,7 +252,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) { GlobalInfo *g = (GlobalInfo*) cbp; SockInfo *fdp = (SockInfo*) sockp; - char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE" }; + const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE" }; fprintf(MSG_OUT, "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); @@ -357,7 +357,7 @@ void fifo_cb(int fd, short event, void *arg) { /* Create a named pipe and tell libevent to monitor it */ int init_fifo (GlobalInfo *g) { struct stat st; - char *fifo = "hiper.fifo"; + static const char *fifo = "hiper.fifo"; int socket; fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo); diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index 0d360adc7..8fd423c7d 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -75,10 +75,10 @@ int main(int argc, char **argv) curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); /* enable uploading */ - curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ; + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1) ; /* HTTP PUT please */ - curl_easy_setopt(curl, CURLOPT_PUT, TRUE); + curl_easy_setopt(curl, CURLOPT_PUT, 1); /* specify target URL, and note that this URL should include a file name, not only a directory */ diff --git a/docs/examples/https.c b/docs/examples/https.c index 8ce7c0b3a..4a83f5f93 100644 --- a/docs/examples/https.c +++ b/docs/examples/https.c @@ -31,7 +31,7 @@ int main(void) * default bundle, then the CURLOPT_CAPATH option might come handy for * you. */ - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); #endif #ifdef SKIP_HOSTNAME_VERFICATION diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index 6c0ef7e7f..5969c91c8 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -47,7 +47,7 @@ int main(int argc, char **argv) curl_easy_setopt(handles[HTTP_HANDLE], CURLOPT_URL, "http://website.com"); curl_easy_setopt(handles[FTP_HANDLE], CURLOPT_URL, "ftp://ftpsite.com"); - curl_easy_setopt(handles[FTP_HANDLE], CURLOPT_UPLOAD, TRUE); + curl_easy_setopt(handles[FTP_HANDLE], CURLOPT_UPLOAD, 1); /* init a multi stack */ multi_handle = curl_multi_init(); diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index 894ace0ed..c560bb916 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -19,7 +19,6 @@ int main(int argc, char *argv[]) { CURL *curl; - CURLcode res; CURLM *multi_handle; int still_running; @@ -27,7 +26,7 @@ int main(int argc, char *argv[]) struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; struct curl_slist *headerlist=NULL; - char buf[] = "Expect:"; + static const char buf[] = "Expect:"; /* Fill in the file upload field. This makes libcurl load data from the given file name when curl_easy_perform() is called. */ @@ -58,7 +57,6 @@ int main(int argc, char *argv[]) wanted */ headerlist = curl_slist_append(headerlist, buf); if(curl && multi_handle) { - int perform=0; /* what URL that receives this POST */ curl_easy_setopt(curl, CURLOPT_URL, diff --git a/docs/examples/multithread.c b/docs/examples/multithread.c index fc9a9a87c..78c3a157a 100644 --- a/docs/examples/multithread.c +++ b/docs/examples/multithread.c @@ -24,7 +24,7 @@ http://www.openssl.org/docs/crypto/threads.html#DESCRIPTION */ -char *urls[]= { +const char *urls[]= { "http://curl.haxx.se/", "ftp://cool.haxx.se/", "http://www.contactor.se/", @@ -59,7 +59,7 @@ int main(int argc, char **argv) error = pthread_create(&tid[i], NULL, /* default attributes please */ pull_one_url, - urls[i]); + (void *)urls[i]); if(0 != error) fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error); else diff --git a/docs/examples/opensslthreadlock.c b/docs/examples/opensslthreadlock.c index 82de206da..18a2f77fc 100644 --- a/docs/examples/opensslthreadlock.c +++ b/docs/examples/opensslthreadlock.c @@ -16,6 +16,11 @@ * Author: Jeremy Brown */ + +#include <stdio.h> +#include <pthread.h> +#include <openssl/err.h> + #define MUTEX_TYPE pthread_mutex_t #define MUTEX_SETUP(x) pthread_mutex_init(&(x), NULL) #define MUTEX_CLEANUP(x) pthread_mutex_destroy(&(x)) @@ -25,7 +30,7 @@ void handle_error(const char *file, int lineno, const char *msg){ - fprintf(stderr, ** %s:%i %s\n, file, lineno, msg); + fprintf(stderr, "** %s:%d %s\n", file, lineno, msg); ERR_print_errors_fp(stderr); /* exit(-1); */ } diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index 1da88a8af..a2c89873f 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -15,10 +15,10 @@ #include <string.h> #include <curl/curl.h> -char data[]="this is what we post to the silly web server"; +const char data[]="this is what we post to the silly web server"; struct WriteThis { - char *readptr; + const char *readptr; int sizeleft; }; @@ -55,7 +55,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_URL, "http://receivingsite.com.pooh/index.cgi"); /* Now specify we want to POST data */ - curl_easy_setopt(curl, CURLOPT_POST, TRUE); + curl_easy_setopt(curl, CURLOPT_POST, 1); /* we want to use our own read function */ curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); diff --git a/docs/examples/postit2.c b/docs/examples/postit2.c index e022d284f..0660cc5b5 100644 --- a/docs/examples/postit2.c +++ b/docs/examples/postit2.c @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; struct curl_slist *headerlist=NULL; - char buf[] = "Expect:"; + static const char buf[] = "Expect:"; curl_global_init(CURL_GLOBAL_ALL); diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index cf2f419d6..e35aebfb1 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -25,9 +25,9 @@ size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) int main(int argc, char **argv) { CURL *curl_handle; - char *headerfilename = "head.out"; + static const char *headerfilename = "head.out"; FILE *headerfile; - char *bodyfilename = "body.out"; + static const char *bodyfilename = "body.out"; FILE *bodyfile; curl_global_init(CURL_GLOBAL_ALL); diff --git a/docs/examples/simplepost.c b/docs/examples/simplepost.c index 1d156c583..9bab83b7d 100644 --- a/docs/examples/simplepost.c +++ b/docs/examples/simplepost.c @@ -9,6 +9,7 @@ */ #include <stdio.h> +#include <string.h> #include <curl/curl.h> int main(void) @@ -16,7 +17,7 @@ int main(void) CURL *curl; CURLcode res; - char *postthis="moo mooo moo moo"; + static const char *postthis="moo mooo moo moo"; curl = curl_easy_init(); if(curl) { diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index 745d6e82c..7ad35237c 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -38,9 +38,10 @@ int main(int argc, char **argv) CURL *curl; CURLcode res; FILE *headerfile; + const char *pPassphrase = NULL; - const char *pCertFile = "testcert.pem"; - const char *pCACertFile="cacert.pem"; + static const char *pCertFile = "testcert.pem"; + static const char *pCACertFile="cacert.pem"; const char *pKeyName; const char *pKeyType; @@ -57,8 +58,6 @@ int main(int argc, char **argv) pEngine = NULL; #endif - const char *pPassphrase = NULL; - headerfile = fopen("dumpit", "w"); curl_global_init(CURL_GLOBAL_DEFAULT); diff --git a/docs/examples/synctime.c b/docs/examples/synctime.c index cd8d0805d..2d5a8e51e 100644 --- a/docs/examples/synctime.c +++ b/docs/examples/synctime.c @@ -87,7 +87,7 @@ typedef struct char timeserver[MAX_STRING1]; } conf_t; -char DefaultTimeServer[4][MAX_STRING1] = +const char DefaultTimeServer[4][MAX_STRING1] = { "http://nist.time.gov/timezone.cgi?UTC/s/0", "http://www.google.com/", @@ -95,9 +95,9 @@ char DefaultTimeServer[4][MAX_STRING1] = "http://www.worldtime.com/cgi-bin/wt.cgi" }; -char *DayStr[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; -char *MthStr[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; +const char *DayStr[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; +const char *MthStr[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; int ShowAllHeader; int AutoSyncTime; -- cgit v1.2.1 From 5bed99c97da7fcbd1c832074dc73efefee81a94c Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Fri, 13 Jul 2007 21:31:44 +0000 Subject: The examples don't need access to curl internal source files. --- docs/examples/Makefile.am | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 5fa9a496f..c64b8f1d8 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -6,9 +6,7 @@ AUTOMAKE_OPTIONS = foreign nostdinc EXTRA_DIST = README Makefile.example makefile.dj $(COMPLICATED_EXAMPLES) -INCLUDES = -I$(top_srcdir)/include \ - -I$(top_builddir)/lib \ - -I$(top_srcdir)/lib +INCLUDES = -I$(top_srcdir)/include LIBDIR = $(top_builddir)/lib -- cgit v1.2.1 From 4706a9334149f656eef9b5e8888da1ead23b0941 Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Mon, 16 Jul 2007 21:22:12 +0000 Subject: Fixed some more simple compile warnings in the examples. --- docs/examples/anyauthput.c | 2 +- docs/examples/cookie_interface.c | 3 ++- docs/examples/ftpget.c | 2 +- docs/examples/ftpgetresp.c | 2 +- docs/examples/ftpupload.c | 1 + docs/examples/getinmemory.c | 4 ++-- docs/examples/httpput.c | 3 ++- docs/examples/post-callback.c | 2 +- docs/examples/sepheaders.c | 2 +- 9 files changed, 12 insertions(+), 9 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index 54cea0017..bc6138f58 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -57,7 +57,7 @@ static curlioerr my_ioctl(CURL *handle, curliocmd cmd, void *userp) } /* read callback function, fread() look alike */ -size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) +static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) { size_t retcode; diff --git a/docs/examples/cookie_interface.c b/docs/examples/cookie_interface.c index a39106e34..b0f33831d 100644 --- a/docs/examples/cookie_interface.c +++ b/docs/examples/cookie_interface.c @@ -10,6 +10,7 @@ #include <stdio.h> #include <string.h> +#include <stdlib.h> #include <errno.h> #include <time.h> @@ -74,7 +75,7 @@ main(void) #define snprintf _snprintf #endif /* Netscape format cookie */ - snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%u\t%s\t%s", + snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%lu\t%s\t%s", ".google.com", "TRUE", "/", "FALSE", time(NULL) + 31337, "PREF", "hello google, i like you very much!"); res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline); if (res != CURLE_OK) { diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 4e3fc8fc3..42e70bd57 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -26,7 +26,7 @@ struct FtpFile { FILE *stream; }; -int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) +static int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) { struct FtpFile *out=(struct FtpFile *)stream; if(out && !out->stream) { diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index cf61ded02..31c1f424f 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -21,7 +21,7 @@ * This functionality was introduced in libcurl 7.9.3. */ -size_t +static size_t write_response(void *ptr, size_t size, size_t nmemb, void *data) { FILE *writehere = (FILE *)data; diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index 65f8a8a79..5a098495d 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -14,6 +14,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <unistd.h> /* * This example shows an FTP upload, with a rename of the file just after diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 00ed39eb2..e80aa4165 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -26,7 +26,7 @@ struct MemoryStruct { size_t size; }; -void *myrealloc(void *ptr, size_t size) +static void *myrealloc(void *ptr, size_t size) { /* There might be a realloc() out there that doesn't like reallocing NULL pointers, so we take care of it here */ @@ -36,7 +36,7 @@ void *myrealloc(void *ptr, size_t size) return malloc(size); } -size_t +static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) { size_t realsize = size * nmemb; diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index 8fd423c7d..5b92548a5 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -11,6 +11,7 @@ #include <stdio.h> #include <fcntl.h> #include <sys/stat.h> +#include <unistd.h> #include <curl/curl.h> @@ -24,7 +25,7 @@ * http://www.apacheweek.com/features/put */ -size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) +static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) { size_t retcode; diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index a2c89873f..531b68156 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -22,7 +22,7 @@ struct WriteThis { int sizeleft; }; -size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp) +static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp) { struct WriteThis *pooh = (struct WriteThis *)userp; diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index e35aebfb1..adfa4374a 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -16,7 +16,7 @@ #include <curl/types.h> #include <curl/easy.h> -size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) +static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) { int written = fwrite(ptr, size, nmemb, (FILE *)stream); return written; -- cgit v1.2.1 From d0edb478964cb5bf7446c34d5ac1e9d34dc5ca63 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Sat, 11 Aug 2007 20:57:54 +0000 Subject: Patrick Monnerat modified the LDAP code and approach in curl. Starting now, the configure script checks for openldap and friends and we link with those libs just like we link all other third party libraries, and we no longer dlopen() those libraries. Our private header file lib/ldap.h was renamed to lib/curl_ldap.h due to this. I set a tag in CVS (curl-7_17_0-preldapfix) just before this commit, just in case. --- docs/examples/Makefile.example | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.example b/docs/examples/Makefile.example index 0852c0f3c..7afe04cf6 100644 --- a/docs/examples/Makefile.example +++ b/docs/examples/Makefile.example @@ -29,9 +29,8 @@ LDFLAGS = -L/home/dast/lib -L/usr/local/ssl/lib # We need -lcurl for the curl stuff # We need -lsocket and -lnsl when on Solaris # We need -lssl and -lcrypto when using libcurl with SSL support -# We need -ldl for dlopen() if that is in libdl # We need -lpthread for the pthread example -LIBS = -lcurl -lsocket -lnsl -lssl -lcrypto -dl +LIBS = -lcurl -lsocket -lnsl -lssl -lcrypto # Link the target with all objects and libraries $(TARGET) : $(OBJS) -- cgit v1.2.1 From 138ca334f9038d542832910ef2359b6cc7d29561 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Fri, 17 Aug 2007 22:33:25 +0000 Subject: ignore all the binaries and the .deps and .libs --- docs/examples/.cvsignore | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/.cvsignore b/docs/examples/.cvsignore index 282522db0..44e99847c 100644 --- a/docs/examples/.cvsignore +++ b/docs/examples/.cvsignore @@ -1,2 +1,30 @@ Makefile Makefile.in +.deps +.libs +10-at-a-time +anyauthput +cookie_interface +debug +fileupload +fopen +ftpget +ftpgetresp +ftpupload +getinfo +getinmemory +http-post +httpput +https +multi-app +multi-debugcallback +multi-double +multi-post +multi-single +persistant +post-callback +postit2 +sepheaders +simple +simplepost +simplessl -- cgit v1.2.1 From 9f44a95522162c0f4a61093efe1bf1f58b087358 Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Thu, 30 Aug 2007 20:34:57 +0000 Subject: Renamed several libcurl error codes and options to make them more general and allow reuse by multiple protocols. Several unused error codes were removed. In all cases, macros were added to preserve source (and binary) compatibility with the old names. These macros are subject to removal at a future date, but probably not before 2009. An application can be tested to see if it is using any obsolete code by compiling it with the CURL_NO_OLDIES macro defined. Documented some newer error codes in libcurl-error(3) --- docs/examples/ftpuploadresume.c | 4 ++-- docs/examples/simplessl.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/ftpuploadresume.c b/docs/examples/ftpuploadresume.c index 8e6be977a..7c71add0c 100644 --- a/docs/examples/ftpuploadresume.c +++ b/docs/examples/ftpuploadresume.c @@ -122,10 +122,10 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath, fseek(f, uploaded_len, SEEK_SET); - curl_easy_setopt(curlhandle, CURLOPT_FTPAPPEND, 1); + curl_easy_setopt(curlhandle, CURLOPT_APPEND, 1); } else { /* no */ - curl_easy_setopt(curlhandle, CURLOPT_FTPAPPEND, 0); + curl_easy_setopt(curlhandle, CURLOPT_APPEND, 0); } r = curl_easy_perform(curlhandle); diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index 7ad35237c..77da32d08 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -95,7 +95,7 @@ int main(int argc, char **argv) /* sorry, for engine we must set the passphrase (if the key has one...) */ if (pPassphrase) - curl_easy_setopt(curl,CURLOPT_SSLKEYPASSWD,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" */ -- cgit v1.2.1 From 6d27647b61faf2cfc2c9ad3433d848db833534e4 Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Thu, 13 Sep 2007 20:36:52 +0000 Subject: Remove remaining traces of ftp3rdparty.c and mention htmltidy.c --- docs/examples/README | 8 ++++---- docs/examples/makefile.dj | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/README b/docs/examples/README index 8d2f0d7af..d6c478568 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -40,7 +40,6 @@ 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 -ftp3rdparty.c - FTP 3rd party transfer 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 @@ -50,6 +49,7 @@ 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 @@ -60,9 +60,9 @@ 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 -multithread.c - an example using multi-treading transfering multiple files +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 persistant connection +persistant.c - request two URLs with a persistent connection 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 @@ -72,5 +72,5 @@ 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 extracing date from remote HTTP servers +synctime.c - Sync local time by extracting date from remote HTTP servers 10-at-a-time.c - Download many files simultaneously, 10 at a time. diff --git a/docs/examples/makefile.dj b/docs/examples/makefile.dj index 4e33c0151..c47f003ee 100644 --- a/docs/examples/makefile.dj +++ b/docs/examples/makefile.dj @@ -23,7 +23,7 @@ CSOURCES = fopen.c ftpget.c ftpgetresp.c ftpupload.c getinmemory.c \ multi-post.c multi-single.c persistant.c post-callback.c \ postit2.c sepheaders.c simple.c simplepost.c simplessl.c \ multi-debugcallback.c fileupload.c getinfo.c anyauthput.c \ - 10-at-a-time.c # ftpuploadresume.c ftp3rdparty.c cookie_interface.c + 10-at-a-time.c # ftpuploadresume.c cookie_interface.c PROGRAMS = $(CSOURCES:.c=.exe) -- cgit v1.2.1 From 8412d1e4937899aedc69852cc5de63c4273e14d6 Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Thu, 13 Sep 2007 22:20:35 +0000 Subject: Compile samples with -DCURL_NO_OLDIES --- docs/examples/Makefile.am | 1 + 1 file changed, 1 insertion(+) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index c64b8f1d8..9127c3d5a 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -9,6 +9,7 @@ EXTRA_DIST = README Makefile.example makefile.dj $(COMPLICATED_EXAMPLES) INCLUDES = -I$(top_srcdir)/include LIBDIR = $(top_builddir)/lib +CPPFLAGS = -DCURL_NO_OLDIES # Dependencies LDADD = $(LIBDIR)/libcurl.la -- cgit v1.2.1 From bbc4e05434277b06843e0994c1ed891eb6a27e2d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Mon, 5 Nov 2007 10:07:34 +0000 Subject: Andres Garcia made it build and run on windows --- docs/examples/10-at-a-time.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index 29c7f08d9..99a031103 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -18,6 +18,9 @@ #include <string.h> #include <unistd.h> #include <curl/multi.h> +#ifdef WIN32 +#include <windows.h> +#endif static const char *urls[] = { "http://www.microsoft.com", @@ -138,7 +141,11 @@ int main(void) L = 100; if (M == -1) { +#ifdef WIN32 + Sleep(L); +#else sleep(L / 1000); +#endif } else { T.tv_sec = L/1000; T.tv_usec = (L%1000)*1000; -- cgit v1.2.1 From 70f10f1ac9270d67ceec53f3db5f76af8532c5e0 Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Wed, 7 Nov 2007 04:53:37 +0000 Subject: Add a call to curl_global_cleanup to show how to do a proper shutdown. --- docs/examples/getinmemory.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index e80aa4165..fc1f87a91 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -98,5 +98,8 @@ int main(int argc, char **argv) if(chunk.memory) free(chunk.memory); + /* we're done with libcurl, so clean it up */ + curl_global_cleanup(); + return 0; } -- cgit v1.2.1 From bff962398d0f572b4ea689053e020080565944d5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Sat, 17 Nov 2007 10:22:44 +0000 Subject: Andres Garcia made the examples build fine on Windows (mingw + msys) when the lib was built staticly. --- docs/examples/Makefile.am | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 9127c3d5a..73383131e 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -9,7 +9,13 @@ EXTRA_DIST = README Makefile.example makefile.dj $(COMPLICATED_EXAMPLES) INCLUDES = -I$(top_srcdir)/include LIBDIR = $(top_builddir)/lib -CPPFLAGS = -DCURL_NO_OLDIES + +if STATICLIB +# we need this define when building with a static lib on Windows +STATICCPPFLAGS = -DCURL_STATICLIB +endif + +CPPFLAGS = -DCURL_NO_OLDIES $(STATICCPPFLAGS) # Dependencies LDADD = $(LIBDIR)/libcurl.la -- cgit v1.2.1 From e40327ba00add934890874b622289da66740941d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Sun, 20 Jan 2008 11:12:11 +0000 Subject: This is a multi threaded application that uses a progress bar to show status. It uses Gtk+ to make a smooth pulse. Written by Jud Bishop --- docs/examples/smooth-gtk-thread.c | 217 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 docs/examples/smooth-gtk-thread.c (limited to 'docs/examples') diff --git a/docs/examples/smooth-gtk-thread.c b/docs/examples/smooth-gtk-thread.c new file mode 100644 index 000000000..271939cea --- /dev/null +++ b/docs/examples/smooth-gtk-thread.c @@ -0,0 +1,217 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * This is a multi threaded application that uses a progress bar to show + * status. It uses Gtk+ to make a smooth pulse. + * + * Written by Jud Bishop after studying the other examples provided with + * libcurl. + * + * To compile (on a single line): + * gcc -ggdb `pkg-config --cflags --libs gtk+-2.0` -lcurl -lssl -lcrypto + * -lgthread-2.0 -dl smooth-gtk-thread.c -o smooth-gtk-thread + */ + +#include <stdio.h> +#include <gtk/gtk.h> +#include <glib.h> +#include <unistd.h> +#include <pthread.h> + +#include <curl/curl.h> +#include <curl/types.h> /* new for v7 */ +#include <curl/easy.h> /* new for v7 */ + +#define NUMT 4 + +pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; +int j = 0; +gint num_urls = 9; /* Just make sure this is less than urls[]*/ +char *urls[]= { + "90022", + "90023", + "90024", + "90025", + "90026", + "90027", + "90028", + "90029", + "90030" +}; + +size_t write_file(void *ptr, size_t size, size_t nmemb, FILE *stream) +{ + /* printf("write_file\n"); */ + return fwrite(ptr, size, nmemb, stream); +} + +/* http://xoap.weather.com/weather/local/46214?cc=*&dayf=5&unit=i */ +void *pull_one_url(void *NaN) +{ + CURL *curl; + CURLcode res; + gchar *http; + FILE *outfile; + gint i; + + /* Stop threads from entering unless j is incremented */ + pthread_mutex_lock(&lock); + 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 ); + + curl = curl_easy_init(); + if(curl) + { + + outfile = fopen(urls[j], "w"); + /* printf("fopen\n"); */ + + /* Set the URL and transfer type */ + curl_easy_setopt(curl, CURLOPT_URL, http); + + /* Write to the file */ + curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_file); + + j++; /* critical line */ + pthread_mutex_unlock(&lock); + + res = curl_easy_perform(curl); + + fclose(outfile); + printf("fclose\n"); + + curl_easy_cleanup(curl); + } + g_free (http); + + /* Adds more latency, testing the mutex.*/ + sleep(1); + + } /* end while */ + return NULL; +} + + +gboolean pulse_bar(gpointer data) +{ + gdk_threads_enter(); + gtk_progress_bar_pulse (GTK_PROGRESS_BAR (data)); + gdk_threads_leave(); + + /* Return true so the function will be called again; + * returning false removes this timeout function. + */ + return TRUE; +} + +void *create_thread(void *progress_bar) +{ + pthread_t tid[NUMT]; + int i; + int error; + + /* Make sure I don't create more threads than urls. */ + for(i=0; i < NUMT && i < num_urls ; i++) { + error = pthread_create(&tid[i], + NULL, /* default attributes please */ + pull_one_url, + NULL); + if(0 != error) + fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error); + else + fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]); + } + + /* Wait for all threads to terminate. */ + for(i=0; i < NUMT && i < num_urls; i++) { + error = pthread_join(tid[i], NULL); + fprintf(stderr, "Thread %d terminated\n", i); + } + + /* This stops the pulsing if you have it turned on in the progress bar + section */ + g_source_remove(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(progress_bar), + "pulse_id"))); + + /* This destroys the progress bar */ + gtk_widget_destroy(progress_bar); + + /* [Un]Comment this out to kill the program rather than pushing close. */ + /* gtk_main_quit(); */ + + + return NULL; + +} + +static gboolean cb_delete(GtkWidget *window, gpointer data) +{ + gtk_main_quit(); + return FALSE; +} + +int main(int argc, char **argv) +{ + GtkWidget *top_window, *outside_frame, *inside_frame, *progress_bar; + GtkAdjustment *adj; + + /* Init thread */ + g_thread_init(NULL); + gdk_threads_init (); + gdk_threads_enter (); + + gtk_init(&argc, &argv); + + /* Base window */ + top_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + /* Frame */ + outside_frame = gtk_frame_new(NULL); + gtk_frame_set_shadow_type(GTK_FRAME(outside_frame), GTK_SHADOW_OUT); + gtk_container_add(GTK_CONTAINER(top_window), outside_frame); + + /* Frame */ + inside_frame = gtk_frame_new(NULL); + gtk_frame_set_shadow_type(GTK_FRAME(inside_frame), GTK_SHADOW_IN); + gtk_container_set_border_width(GTK_CONTAINER(inside_frame), 5); + gtk_container_add(GTK_CONTAINER(outside_frame), inside_frame); + + /* Progress bar */ + progress_bar = gtk_progress_bar_new(); + gtk_progress_bar_pulse (GTK_PROGRESS_BAR (progress_bar)); + /* Make uniform pulsing */ + gint pulse_ref = g_timeout_add (300, pulse_bar, progress_bar); + g_object_set_data(G_OBJECT(progress_bar), "pulse_id", + GINT_TO_POINTER(pulse_ref)); + gtk_container_add(GTK_CONTAINER(inside_frame), progress_bar); + + gtk_widget_show_all(top_window); + printf("gtk_widget_show_all\n"); + + 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) + g_warning("can't create the thread"); + + gtk_main(); + gdk_threads_leave(); + printf("gdk_threads_leave\n"); + + return 0; +} + -- cgit v1.2.1 From 454e840590eef557c114b32edb14c113f165272a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Sun, 3 Feb 2008 12:28:48 +0000 Subject: threaded-ssl.c is a little example that does multi-threaded downloads from HTTPS sites with OpenSSL-enabled libcurl (and pthreads) and thus do the thread-locking and things openssl-style. --- docs/examples/Makefile.am | 2 +- docs/examples/threaded-ssl.c | 124 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 docs/examples/threaded-ssl.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 73383131e..16f3152b5 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -33,5 +33,5 @@ noinst_PROGRAMS = 10-at-a-time anyauthput cookie_interface \ COMPLICATED_EXAMPLES = \ curlgtk.c curlx.c htmltitle.cc cacertinmem.c ftpuploadresume.c \ ghiper.c hiperfifo.c htmltidy.c multithread.c \ - opensslthreadlock.c sampleconv.c synctime.c + opensslthreadlock.c sampleconv.c synctime.c threaded-ssl.c diff --git a/docs/examples/threaded-ssl.c b/docs/examples/threaded-ssl.c new file mode 100644 index 000000000..e49443d40 --- /dev/null +++ b/docs/examples/threaded-ssl.c @@ -0,0 +1,124 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * A multi-threaded example that uses pthreads and fetches 4 remote files at + * once over HTTPS. The lock callbacks and stuff assume OpenSSL so far. + * Should be expanded to do optional GnuTLS style locking. + * + * OpenSSL docs for this: http://www.openssl.org/docs/crypto/threads.html + */ + +#include <stdio.h> +#include <pthread.h> +#include <curl/curl.h> +#include <openssl/crypto.h> + +/* we have this global to let the callback get easy access to it */ +static pthread_mutex_t *lockarray; + +static void lock_callback(int mode, int type, char *file, int line) +{ + (void)file; + (void)line; + if (mode & CRYPTO_LOCK) { + pthread_mutex_lock(&(lockarray[type])); + } + else { + pthread_mutex_unlock(&(lockarray[type])); + } +} + +static unsigned long thread_id(void) +{ + unsigned long ret; + + ret=(unsigned long)pthread_self(); + return(ret); +} + +static void init_locks(void) +{ + int i; + + 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); + } + + CRYPTO_set_id_callback((unsigned long (*)())thread_id); + CRYPTO_set_locking_callback((void (*)())lock_callback); +} + +static void kill_locks(void) +{ + int i; + + CRYPTO_set_locking_callback(NULL); + for (i=0; i<CRYPTO_num_locks(); i++) + pthread_mutex_destroy(&(lockarray[i])); + + OPENSSL_free(lockarray); +} + +/* List of URLs to fetch.*/ +const char *urls[]= { + "https://www.sf.net/", + "https://www.openssl.org/", + "https://www.sf.net/", + "https://www.openssl.org/", +}; + +static void *pull_one_url(void *url) +{ + CURL *curl; + + curl = curl_easy_init(); + curl_easy_setopt(curl, CURLOPT_URL, url); + /* this example doesn't verify the server's certificate, which means we + might be downloading stuff from an impostor */ + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); + curl_easy_perform(curl); /* ignores error */ + curl_easy_cleanup(curl); + + return NULL; +} + +int main(int argc, char **argv) +{ + pthread_t tid[4]; + int i; + int error; + (void)argc; /* we don't use any arguments in this example */ + (void)argv; + + init_locks(); + + for(i=0; i< 4; i++) { + error = pthread_create(&tid[i], + NULL, /* default attributes please */ + pull_one_url, + (void *)urls[i]); + if(0 != error) + fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error); + else + fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]); + } + + /* now wait for all threads to terminate */ + for(i=0; i< 4; i++) { + error = pthread_join(tid[i], NULL); + fprintf(stderr, "Thread %d terminated\n", i); + } + + kill_locks(); + + return 0; +} -- cgit v1.2.1 From 6398f71cc44b60da4c5e579bfdfdd33c572532ba Mon Sep 17 00:00:00 2001 From: Gunter Knauf <gk@gknw.de> Date: Mon, 18 Feb 2008 15:32:34 +0000 Subject: moved sample program defines into separate Makefile.inc so that other makefiles can pick up the defines from there. --- docs/examples/Makefile.am | 20 +++++--------------- docs/examples/Makefile.inc | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 docs/examples/Makefile.inc (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 16f3152b5..83980492b 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -4,7 +4,8 @@ AUTOMAKE_OPTIONS = foreign nostdinc -EXTRA_DIST = README Makefile.example makefile.dj $(COMPLICATED_EXAMPLES) +EXTRA_DIST = README Makefile.example Makefile.inc Makefile.m32 \ + makefile.dj $(COMPLICATED_EXAMPLES) INCLUDES = -I$(top_srcdir)/include @@ -20,18 +21,7 @@ CPPFLAGS = -DCURL_NO_OLDIES $(STATICCPPFLAGS) # Dependencies LDADD = $(LIBDIR)/libcurl.la -# These are all libcurl example programs to be test compiled -noinst_PROGRAMS = 10-at-a-time anyauthput cookie_interface \ - debug fileupload fopen ftpget ftpgetresp ftpupload \ - getinfo getinmemory http-post httpput \ - https multi-app multi-debugcallback multi-double \ - multi-post multi-single persistant post-callback \ - postit2 sepheaders simple simplepost simplessl - -# These examples require external dependencies that may not be commonly -# available on POSIX systems, so don't bother attempting to compile them here. -COMPLICATED_EXAMPLES = \ - curlgtk.c curlx.c htmltitle.cc cacertinmem.c ftpuploadresume.c \ - ghiper.c hiperfifo.c htmltidy.c multithread.c \ - opensslthreadlock.c sampleconv.c synctime.c threaded-ssl.c +# Makefile.inc provides the noinst_PROGRAMS and COMPLICATED_EXAMPLES defines +include Makefile.inc + diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc new file mode 100644 index 000000000..8753d4f4b --- /dev/null +++ b/docs/examples/Makefile.inc @@ -0,0 +1,16 @@ +# These are all libcurl example programs to be test compiled +noinst_PROGRAMS = 10-at-a-time anyauthput cookie_interface \ + debug fileupload fopen ftpget ftpgetresp ftpupload \ + getinfo getinmemory http-post httpput \ + https multi-app multi-debugcallback multi-double \ + multi-post multi-single persistant post-callback \ + postit2 sepheaders simple simplepost simplessl + +# These examples require external dependencies that may not be commonly +# available on POSIX systems, so don't bother attempting to compile them here. +COMPLICATED_EXAMPLES = \ + curlgtk.c curlx.c htmltitle.cc cacertinmem.c ftpuploadresume.c \ + ghiper.c hiperfifo.c htmltidy.c multithread.c \ + opensslthreadlock.c sampleconv.c synctime.c threaded-ssl.c + + -- cgit v1.2.1 From 109328749460a9fcc026d4314f4fcb094227e7fb Mon Sep 17 00:00:00 2001 From: Gunter Knauf <gk@gknw.de> Date: Mon, 18 Feb 2008 15:43:23 +0000 Subject: added makefile for MingW32 to build most of the samples. --- docs/examples/Makefile.m32 | 135 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 docs/examples/Makefile.m32 (limited to 'docs/examples') diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 new file mode 100644 index 000000000..e1ebab853 --- /dev/null +++ b/docs/examples/Makefile.m32 @@ -0,0 +1,135 @@ +######################################################################### +# $Id$ +# +## Makefile for building curl examples with MingW32 +## and optionally OpenSSL (0.9.8), libssh2 (0.18), zlib (1.2.3) +## +## Usage: +## mingw32-make -f Makefile.m32 [SSL=1] [SSH2=1] [ZLIB=1] [SSPI=1] [IPV6=1] [DYN=1] +## +## Hint: you can also set environment vars to control the build, f.e.: +## set ZLIB_PATH=c:/zlib-1.2.3 +## set ZLIB=1 +## +######################################################################### + +# Edit the path below to point to the base of your Zlib sources. +ifndef ZLIB_PATH +ZLIB_PATH = ../../zlib-1.2.3 +endif +# Edit the path below to point to the base of your OpenSSL package. +ifndef OPENSSL_PATH +OPENSSL_PATH = ../../openssl-0.9.8g +endif +# Edit the path below to point to the base of your LibSSH2 package. +ifndef LIBSSH2_PATH +LIBSSH2_PATH = ../../libssh2-0.18 +endif +# Edit the path below to point to the base of your Novell LDAP NDK. +ifndef LDAP_SDK +LDAP_SDK = c:/novell/ndk/cldapsdk/win32 +endif + +PROOT = ../.. +ARES_LIB = $(PROOT)/ares + +SSL = 1 +ZLIB = 1 + +CC = gcc +CFLAGS = -g -O2 -Wall +# comment LDFLAGS below to keep debug info +LDFLAGS = -s +RC = windres +RCFLAGS = --include-dir=$(PROOT)/include -O COFF -i +RM = del /q /f > NUL 2>&1 +CP = copy + +######################################################## +## Nothing more to do below this line! + +INCLUDES = -I. -I$(PROOT) -I$(PROOT)/include -I$(PROOT)/lib +LINK = $(CC) $(LDFLAGS) -o $@ + +curl_PROGRAMS = curl.exe +ifdef DYN + curl_DEPENDENCIES = $(PROOT)/lib/libcurldll.a $(PROOT)/lib/libcurl.dll + curl_LDADD = -L$(PROOT)/lib -lcurldll +else + curl_DEPENDENCIES = $(PROOT)/lib/libcurl.a + curl_LDADD = -L$(PROOT)/lib -lcurl + CFLAGS += -DCURL_STATICLIB +endif +ifdef ARES + ifndef DYN + curl_DEPENDENCIES += $(ARES_LIB)/libcares.a + endif + CFLAGS += -DUSE_ARES + curl_LDADD += -L$(ARES_LIB) -lcares +endif +ifdef SSH2 + CFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H + curl_LDADD += -L$(LIBSSH2_PATH)/win32 -lssh2 +endif +ifdef SSL + INCLUDES += -I"$(OPENSSL_PATH)/outinc" + CFLAGS += -DUSE_SSLEAY -DHAVE_OPENSSL_ENGINE_H + ifdef DYN + curl_LDADD += -L$(OPENSSL_PATH)/out -leay32 -lssl32 + else + curl_LDADD += -L$(OPENSSL_PATH)/out -lssl -lcrypto -lgdi32 + endif +endif +ifdef ZLIB + INCLUDES += -I"$(ZLIB_PATH)" + CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H + curl_LDADD += -L$(ZLIB_PATH) -lz +endif +ifdef SSPI + CFLAGS += -DUSE_WINDOWS_SSPI +endif +ifdef IPV6 + CFLAGS += -DENABLE_IPV6 +endif +ifdef LDAPS + CFLAGS += -DHAVE_LDAP_SSL +endif +ifdef USE_LDAP_NOVELL + CFLAGS += -DCURL_HAS_NOVELL_LDAPSDK + curl_LDADD += -L"$(LDAP_SDK)/lib/mscvc" -lldapsdk -lldapssl -lldapx +endif +ifdef USE_LDAP_OPENLDAP + CFLAGS += -DCURL_HAS_OPENLDAP_LDAPSDK + curl_LDADD += -L"$(LDAP_SDK)/lib" -lldap -llber +endif +ifndef USE_LDAP_NOVELL +ifndef USE_LDAP_OPENLDAP +curl_LDADD += -lwldap32 +endif +endif +curl_LDADD += -lws2_32 -lwinmm +COMPILE = $(CC) $(INCLUDES) $(CFLAGS) + +# Makefile.inc provides the noinst_PROGRAMS and COMPLICATED_EXAMPLES defines +include Makefile.inc + +example_PROGRAMS := $(patsubst %,%.exe,$(strip $(noinst_PROGRAMS))) + +.SUFFIXES: .rc .res .o .exe + + +all: $(example_PROGRAMS) + +.o.exe: $(curl_DEPENDENCIES) + $(LINK) $< $(curl_LDADD) + +.c.o: + $(COMPILE) -c $< + +.rc.res: + $(RC) $(RCFLAGS) $< -o $@ + +clean: + $(RM) $(example_PROGRAMS) + + -- cgit v1.2.1 From 7a5596bf02624588cfa7905a6995c2165a375776 Mon Sep 17 00:00:00 2001 From: Gunter Knauf <gk@gknw.de> Date: Tue, 19 Feb 2008 16:13:52 +0000 Subject: made changes to work with Win32; replaced fstat() with stat() call and bail out if local file not found. --- docs/examples/ftpupload.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index 5a098495d..ab803bdfe 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -14,7 +14,11 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#ifdef WIN32 +#include <io.h> +#else #include <unistd.h> +#endif /* * This example shows an FTP upload, with a rename of the file just after @@ -32,8 +36,7 @@ int main(int argc, char **argv) { CURL *curl; CURLcode res; - FILE * hd_src ; - int hd ; + FILE *hd_src; struct stat file_info; struct curl_slist *headerlist=NULL; @@ -41,13 +44,13 @@ int main(int argc, char **argv) static const char buf_2 [] = "RNTO " RENAME_FILE_TO; /* get the file size of the local file */ - hd = open(LOCAL_FILE, O_RDONLY) ; - fstat(hd, &file_info); - close(hd) ; + if (stat(LOCAL_FILE, &file_info)) { + printf("Couldnt open '%s': %s\n", LOCAL_FILE, strerror(errno)); + exit(1); + } + printf("Local file size: %ld bytes.\n", file_info.st_size); - /* get a FILE * of the same file, could also be made with - fdopen() from the previous descriptor, but hey this is just - an example! */ + /* get a FILE * of the same file */ hd_src = fopen(LOCAL_FILE, "rb"); /* In windows, this will init the winsock stuff */ -- cgit v1.2.1 From ade0890746c43b078722b6e960a59a0834d416f2 Mon Sep 17 00:00:00 2001 From: Gunter Knauf <gk@gknw.de> Date: Tue, 19 Feb 2008 16:23:03 +0000 Subject: fix for new codestyle. --- docs/examples/ftpupload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index ab803bdfe..f4d3384ea 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -44,7 +44,7 @@ int main(int argc, char **argv) static const char buf_2 [] = "RNTO " RENAME_FILE_TO; /* get the file size of the local file */ - if (stat(LOCAL_FILE, &file_info)) { + if(stat(LOCAL_FILE, &file_info)) { printf("Couldnt open '%s': %s\n", LOCAL_FILE, strerror(errno)); exit(1); } -- cgit v1.2.1 From d208e56b1665ac17a96dae21885f56ee7b7f5227 Mon Sep 17 00:00:00 2001 From: Gunter Knauf <gk@gknw.de> Date: Wed, 20 Feb 2008 12:33:45 +0000 Subject: added read callback function in order to prevent crashs on Win32 when linked against DLL: --- docs/examples/ftpupload.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index f4d3384ea..db209a78d 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -32,6 +32,22 @@ #define REMOTE_URL "ftp://localhost/" UPLOAD_FILE_AS #define RENAME_FILE_TO "renamed-and-fine.txt" +/* NOTE: if you want this example to work on Windows with libcurl as a + DLL, you MUST also provide a read callback with + CURLOPT_READFUNCTION. Failing to do so will give you a crash since a + DLL may not use the variable's memory when passed in to it from an app + like this. */ +static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) +{ + /* in real-world cases, this would probably get this data differently + as this fread() stuff is exactly what the library already would do + by default internally */ + size_t retcode = fread(ptr, size, nmemb, stream); + + fprintf(stderr, "*** We read %d bytes from file\n", retcode); + return retcode; +} + int main(int argc, char **argv) { CURL *curl; @@ -63,6 +79,9 @@ int main(int argc, char **argv) headerlist = curl_slist_append(headerlist, buf_1); headerlist = curl_slist_append(headerlist, buf_2); + /* we want to use our own read function */ + curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); + /* enable uploading */ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1) ; @@ -75,12 +94,6 @@ int main(int argc, char **argv) /* now specify which file to upload */ curl_easy_setopt(curl, CURLOPT_READDATA, hd_src); - /* NOTE: if you want this example to work on Windows with libcurl as a - DLL, you MUST also provide a read callback with - CURLOPT_READFUNCTION. Failing to do so will give you a crash since a - DLL may not use the variable's memory when passed in to it from an app - like this. */ - /* Set the size of the file to upload (optional). If you give a *_LARGE option you MUST make sure that the type of the passed-in argument is a curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must -- cgit v1.2.1 From 4ae644e427a685f5777c93130c3d5831d168c5b4 Mon Sep 17 00:00:00 2001 From: Gunter Knauf <gk@gknw.de> Date: Wed, 20 Feb 2008 12:36:35 +0000 Subject: reformatted comment. --- docs/examples/ftpupload.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index db209a78d..8b29a21ec 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -33,10 +33,9 @@ #define RENAME_FILE_TO "renamed-and-fine.txt" /* NOTE: if you want this example to work on Windows with libcurl as a - DLL, you MUST also provide a read callback with - CURLOPT_READFUNCTION. Failing to do so will give you a crash since a - DLL may not use the variable's memory when passed in to it from an app - like this. */ + DLL, you MUST also provide a read callback with CURLOPT_READFUNCTION. + Failing to do so will give you a crash since a DLL may not use the + variable's memory when passed in to it from an app like this. */ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) { /* in real-world cases, this would probably get this data differently -- cgit v1.2.1 From 5e9c564883512130d356a81f6dcb3057572f1690 Mon Sep 17 00:00:00 2001 From: Gunter Knauf <gk@gknw.de> Date: Thu, 21 Feb 2008 15:02:14 +0000 Subject: fixed missing header; changed bail out from exit() to return(). Mentioned on the list by Michal Marek. --- docs/examples/ftpupload.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index 8b29a21ec..9ce548480 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -14,6 +14,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <errno.h> #ifdef WIN32 #include <io.h> #else @@ -61,7 +62,7 @@ int main(int argc, char **argv) /* get the file size of the local file */ if(stat(LOCAL_FILE, &file_info)) { printf("Couldnt open '%s': %s\n", LOCAL_FILE, strerror(errno)); - exit(1); + return 1; } printf("Local file size: %ld bytes.\n", file_info.st_size); -- cgit v1.2.1 From 3154f04fb908ddf0066fe1d07cab2bbc0e9e67f4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Sat, 23 Feb 2008 23:00:24 +0000 Subject: now builds and runs with GnuTLS-built libcurls too --- docs/examples/threaded-ssl.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/threaded-ssl.c b/docs/examples/threaded-ssl.c index e49443d40..c3455369b 100644 --- a/docs/examples/threaded-ssl.c +++ b/docs/examples/threaded-ssl.c @@ -8,20 +8,26 @@ * $Id$ * * A multi-threaded example that uses pthreads and fetches 4 remote files at - * once over HTTPS. The lock callbacks and stuff assume OpenSSL so far. - * Should be expanded to do optional GnuTLS style locking. + * 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 + * OpenSSL docs for this: + * http://www.openssl.org/docs/crypto/threads.html + * gcrypt docs for this: + * http://gnupg.org/documentation/manuals/gcrypt/Multi_002dThreading.html */ +#define USE_OPENSSL /* or USE_GNUTLS accordingly */ + #include <stdio.h> #include <pthread.h> #include <curl/curl.h> -#include <openssl/crypto.h> /* we have this global to let the callback get easy access to it */ static pthread_mutex_t *lockarray; +#ifdef USE_OPENSSL +#include <openssl/crypto.h> static void lock_callback(int mode, int type, char *file, int line) { (void)file; @@ -66,6 +72,21 @@ static void kill_locks(void) OPENSSL_free(lockarray); } +#endif + +#ifdef USE_GNUTLS +#include <gcrypt.h> +#include <errno.h> + +GCRY_THREAD_OPTION_PTHREAD_IMPL; + +void init_locks(void) +{ + gcry_control(GCRYCTL_SET_THREAD_CBS); +} + +#define kill_locks() +#endif /* List of URLs to fetch.*/ const char *urls[]= { -- cgit v1.2.1 From b12fef3f3137bc606d283a2e527dd9050edf2b12 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 27 Feb 2008 09:06:15 +0000 Subject: Michal Marek's cleanup of how curl_easy_setopt() is used in examples and test code. Thanks to his curl_easy_setopt() typechecker work... --- docs/examples/10-at-a-time.c | 2 +- docs/examples/anyauthput.c | 10 +++++----- docs/examples/debug.c | 4 ++-- docs/examples/ftpget.c | 2 +- docs/examples/multi-debugcallback.c | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index 99a031103..b30efc075 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -77,7 +77,7 @@ static const char *urls[] = { #define MAX 10 /* number of simultaneous transfers */ #define CNT sizeof(urls)/sizeof(char*) /* total number of transfers to do */ -static int cb(char *d, size_t n, size_t l, void *p) +static size_t cb(char *d, size_t n, size_t l, void *p) { /* take care of the data here, ignored in this example */ (void)d; diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index bc6138f58..2c8f738ea 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -37,7 +37,7 @@ /* ioctl callback function */ static curlioerr my_ioctl(CURL *handle, curliocmd cmd, void *userp) { - int fd = (int)userp; + intptr_t fd = (intptr_t)userp; (void)handle; /* not used in here */ @@ -61,7 +61,7 @@ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) { size_t retcode; - int fd = (int)stream; + intptr_t fd = (intptr_t)stream; retcode = read(fd, ptr, size * nmemb); @@ -74,7 +74,7 @@ int main(int argc, char **argv) { CURL *curl; CURLcode res; - int hd ; + intptr_t hd ; struct stat file_info; char *file; @@ -100,13 +100,13 @@ int main(int argc, char **argv) curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); /* which file to upload */ - curl_easy_setopt(curl, CURLOPT_READDATA, 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, hd); + curl_easy_setopt(curl, CURLOPT_IOCTLDATA, (void*)hd); /* enable "uploading" (which means PUT when doing HTTP) */ curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ; diff --git a/docs/examples/debug.c b/docs/examples/debug.c index 1443ae55d..6f7a6383a 100644 --- a/docs/examples/debug.c +++ b/docs/examples/debug.c @@ -65,7 +65,7 @@ void dump(const char *text, static int my_trace(CURL *handle, curl_infotype type, - unsigned char *data, size_t size, + char *data, size_t size, void *userp) { struct data *config = (struct data *)userp; @@ -98,7 +98,7 @@ int my_trace(CURL *handle, curl_infotype type, break; } - dump(text, stderr, data, size, config->trace_ascii); + dump(text, stderr, (unsigned char *)data, size, config->trace_ascii); return 0; } diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 42e70bd57..155e79cb7 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -26,7 +26,7 @@ struct FtpFile { FILE *stream; }; -static int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) +static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) { struct FtpFile *out=(struct FtpFile *)stream; if(out && !out->stream) { diff --git a/docs/examples/multi-debugcallback.c b/docs/examples/multi-debugcallback.c index 4c93df4dc..1cd6e4398 100644 --- a/docs/examples/multi-debugcallback.c +++ b/docs/examples/multi-debugcallback.c @@ -74,7 +74,7 @@ void dump(const char *text, static int my_trace(CURL *handle, curl_infotype type, - unsigned char *data, size_t size, + char *data, size_t size, void *userp) { const char *text; -- cgit v1.2.1 From f3c0afa5b8f1460020f3718e2b050d4940240a58 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Thu, 13 Mar 2008 12:36:22 +0000 Subject: fix code that is normally #ifdef'ed out --- docs/examples/post-callback.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index 531b68156..1a044808a 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -75,7 +75,7 @@ int main(void) */ #ifdef USE_CHUNKED { - curl_slist *chunk = NULL; + struct curl_slist *chunk = NULL; chunk = curl_slist_append(chunk, "Transfer-Encoding: chunked"); res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); @@ -98,7 +98,7 @@ int main(void) /* A less good option would be to enforce HTTP 1.0, but that might also have other implications. */ { - curl_slist *chunk = NULL; + struct curl_slist *chunk = NULL; chunk = curl_slist_append(chunk, "Expect:"); res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); -- cgit v1.2.1 From 1e482fe6a8dbc36a4e9ad19eb8fec98f240b5ed5 Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Mon, 31 Mar 2008 03:01:13 +0000 Subject: Changed the makefile so the doc/examples/ programs are never built in a normal build/install (only with the 'make check' target), so that a build failure in the examples isn't fatal. --- docs/examples/Makefile.am | 2 +- docs/examples/Makefile.inc | 2 +- docs/examples/Makefile.m32 | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 83980492b..83069d442 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -21,7 +21,7 @@ CPPFLAGS = -DCURL_NO_OLDIES $(STATICCPPFLAGS) # Dependencies LDADD = $(LIBDIR)/libcurl.la -# Makefile.inc provides the noinst_PROGRAMS and COMPLICATED_EXAMPLES defines +# Makefile.inc provides the check_PROGRAMS and COMPLICATED_EXAMPLES defines include Makefile.inc diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 8753d4f4b..5d0c162a5 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -1,5 +1,5 @@ # These are all libcurl example programs to be test compiled -noinst_PROGRAMS = 10-at-a-time anyauthput cookie_interface \ +check_PROGRAMS = 10-at-a-time anyauthput cookie_interface \ debug fileupload fopen ftpget ftpgetresp ftpupload \ getinfo getinmemory http-post httpput \ https multi-app multi-debugcallback multi-double \ diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index e1ebab853..9fec1f42f 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -110,10 +110,10 @@ endif curl_LDADD += -lws2_32 -lwinmm COMPILE = $(CC) $(INCLUDES) $(CFLAGS) -# Makefile.inc provides the noinst_PROGRAMS and COMPLICATED_EXAMPLES defines +# Makefile.inc provides the check_PROGRAMS and COMPLICATED_EXAMPLES defines include Makefile.inc -example_PROGRAMS := $(patsubst %,%.exe,$(strip $(noinst_PROGRAMS))) +example_PROGRAMS := $(patsubst %,%.exe,$(strip $(check_PROGRAMS))) .SUFFIXES: .rc .res .o .exe -- cgit v1.2.1 From 16a9c5e02be15c1dde3aa21b3ced5a71c6fae53c Mon Sep 17 00:00:00 2001 From: Gunter Knauf <gk@gknw.de> Date: Wed, 2 Apr 2008 03:11:34 +0000 Subject: removed unused var. --- docs/examples/Makefile.m32 | 1 - 1 file changed, 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 9fec1f42f..470061c4c 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -51,7 +51,6 @@ CP = copy INCLUDES = -I. -I$(PROOT) -I$(PROOT)/include -I$(PROOT)/lib LINK = $(CC) $(LDFLAGS) -o $@ -curl_PROGRAMS = curl.exe ifdef DYN curl_DEPENDENCIES = $(PROOT)/lib/libcurldll.a $(PROOT)/lib/libcurl.dll curl_LDADD = -L$(PROOT)/lib -lcurldll -- cgit v1.2.1 From bf52cef16fd2cc1ad83f760059d27f49f036c3eb Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Thu, 3 Apr 2008 20:28:32 +0000 Subject: Made sure that curl_global_init is called in all the multithreaded example programs. --- docs/examples/curlgtk.c | 7 +++++-- docs/examples/multithread.c | 16 +++++++++++----- docs/examples/smooth-gtk-thread.c | 7 ++++--- docs/examples/threaded-ssl.c | 13 +++++++++---- 4 files changed, 29 insertions(+), 14 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/curlgtk.c b/docs/examples/curlgtk.c index 37c47f417..19f7b1712 100644 --- a/docs/examples/curlgtk.c +++ b/docs/examples/curlgtk.c @@ -29,7 +29,7 @@ size_t my_read_func(void *ptr, size_t size, size_t nmemb, FILE *stream) return fread(ptr, size, nmemb, stream); } -int my_progress_func(GtkWidget *Bar, +int my_progress_func(GtkWidget *bar, double t, /* dltotal */ double d, /* dlnow */ double ultotal, @@ -37,7 +37,7 @@ int my_progress_func(GtkWidget *Bar, { /* printf("%d / %d (%g %%)\n", d, t, d*100.0/t);*/ gdk_threads_enter(); - gtk_progress_set_value(GTK_PROGRESS(Bar), d*100.0/t); + gtk_progress_set_value(GTK_PROGRESS(bar), d*100.0/t); gdk_threads_leave(); return 0; } @@ -77,6 +77,9 @@ int main(int argc, char **argv) GtkWidget *Window, *Frame, *Frame2; GtkAdjustment *adj; + /* Must initialize libcurl before any threads are started */ + curl_global_init(CURL_GLOBAL_ALL); + /* Init thread */ g_thread_init(NULL); diff --git a/docs/examples/multithread.c b/docs/examples/multithread.c index 78c3a157a..939e9daef 100644 --- a/docs/examples/multithread.c +++ b/docs/examples/multithread.c @@ -15,6 +15,8 @@ #include <pthread.h> #include <curl/curl.h> +#define NUMT 4 + /* List of URLs to fetch. @@ -24,14 +26,14 @@ http://www.openssl.org/docs/crypto/threads.html#DESCRIPTION */ -const char *urls[]= { +const char * const urls[NUMT]= { "http://curl.haxx.se/", "ftp://cool.haxx.se/", "http://www.contactor.se/", "www.haxx.se" }; -void *pull_one_url(void *url) +static void *pull_one_url(void *url) { CURL *curl; @@ -52,10 +54,14 @@ void *pull_one_url(void *url) int main(int argc, char **argv) { - pthread_t tid[4]; + pthread_t tid[NUMT]; int i; int error; - for(i=0; i< 4; i++) { + + /* Must initialize libcurl before any threads are started */ + curl_global_init(CURL_GLOBAL_ALL); + + for(i=0; i< NUMT; i++) { error = pthread_create(&tid[i], NULL, /* default attributes please */ pull_one_url, @@ -67,7 +73,7 @@ int main(int argc, char **argv) } /* now wait for all threads to terminate */ - for(i=0; i< 4; i++) { + for(i=0; i< NUMT; i++) { error = pthread_join(tid[i], NULL); fprintf(stderr, "Thread %d terminated\n", i); } diff --git a/docs/examples/smooth-gtk-thread.c b/docs/examples/smooth-gtk-thread.c index 271939cea..2d41aa248 100644 --- a/docs/examples/smooth-gtk-thread.c +++ b/docs/examples/smooth-gtk-thread.c @@ -33,7 +33,7 @@ pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; int j = 0; gint num_urls = 9; /* Just make sure this is less than urls[]*/ -char *urls[]= { +const char * const urls[]= { "90022", "90023", "90024", @@ -58,7 +58,6 @@ void *pull_one_url(void *NaN) CURLcode res; gchar *http; FILE *outfile; - gint i; /* Stop threads from entering unless j is incremented */ pthread_mutex_lock(&lock); @@ -167,7 +166,9 @@ static gboolean cb_delete(GtkWidget *window, gpointer data) int main(int argc, char **argv) { GtkWidget *top_window, *outside_frame, *inside_frame, *progress_bar; - GtkAdjustment *adj; + + /* Must initialize libcurl before any threads are started */ + curl_global_init(CURL_GLOBAL_ALL); /* Init thread */ g_thread_init(NULL); diff --git a/docs/examples/threaded-ssl.c b/docs/examples/threaded-ssl.c index c3455369b..afc609551 100644 --- a/docs/examples/threaded-ssl.c +++ b/docs/examples/threaded-ssl.c @@ -23,6 +23,8 @@ #include <pthread.h> #include <curl/curl.h> +#define NUMT 4 + /* we have this global to let the callback get easy access to it */ static pthread_mutex_t *lockarray; @@ -89,7 +91,7 @@ void init_locks(void) #endif /* List of URLs to fetch.*/ -const char *urls[]= { +const char * const urls[]= { "https://www.sf.net/", "https://www.openssl.org/", "https://www.sf.net/", @@ -114,15 +116,18 @@ static void *pull_one_url(void *url) int main(int argc, char **argv) { - pthread_t tid[4]; + pthread_t tid[NUMT]; int i; int error; (void)argc; /* we don't use any arguments in this example */ (void)argv; + /* Must initialize libcurl before any threads are started */ + curl_global_init(CURL_GLOBAL_ALL); + init_locks(); - for(i=0; i< 4; i++) { + for(i=0; i< NUMT; i++) { error = pthread_create(&tid[i], NULL, /* default attributes please */ pull_one_url, @@ -134,7 +139,7 @@ int main(int argc, char **argv) } /* now wait for all threads to terminate */ - for(i=0; i< 4; i++) { + for(i=0; i< NUMT; i++) { error = pthread_join(tid[i], NULL); fprintf(stderr, "Thread %d terminated\n", i); } -- cgit v1.2.1 From aa2a54c10a19bce9a9b73d92a9712a7616405e6f Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Fri, 4 Apr 2008 18:45:37 +0000 Subject: Give a hint as to why a url_fopen failed. --- docs/examples/fopen.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index 7c50b0cc6..44d2498a0 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -488,7 +488,7 @@ main(int argc, char *argv[]) handle = url_fopen(url, "r"); if(!handle) { - printf("couldn't url_fopen()\n"); + printf("couldn't url_fopen() %s\n", url); fclose(outf); return 2; } @@ -514,7 +514,7 @@ main(int argc, char *argv[]) handle = url_fopen("testfile", "r"); if(!handle) { - printf("couldn't url_fopen()\n"); + printf("couldn't url_fopen() testfile\n"); fclose(outf); return 2; } @@ -539,7 +539,7 @@ main(int argc, char *argv[]) handle = url_fopen("testfile", "r"); if(!handle) { - printf("couldn't url_fopen()\n"); + printf("couldn't url_fopen() testfile\n"); fclose(outf); return 2; } -- cgit v1.2.1 From 79300cdcd988e65c37bd3d9b391cd7a73ebefc6b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Sat, 12 Apr 2008 08:35:04 +0000 Subject: return 0 not -1 at end of data! --- docs/examples/post-callback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index 1a044808a..e3f37c4ae 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -36,7 +36,7 @@ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp) return 1; /* we return 1 byte at a time! */ } - return -1; /* no more data left to deliver */ + return 0; /* no more data left to deliver */ } int main(void) -- cgit v1.2.1 From 19479ea0217c93fd2973168084d1bb724eb8a34f Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Fri, 9 May 2008 16:31:51 +0000 Subject: Internal time differences now use monotonic time source if available. This also implies the removal of the winmm.lib dependency for WIN32. --- docs/examples/Makefile.m32 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 470061c4c..5107c04fe 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -106,7 +106,7 @@ ifndef USE_LDAP_OPENLDAP curl_LDADD += -lwldap32 endif endif -curl_LDADD += -lws2_32 -lwinmm +curl_LDADD += -lws2_32 COMPILE = $(CC) $(INCLUDES) $(CFLAGS) # Makefile.inc provides the check_PROGRAMS and COMPLICATED_EXAMPLES defines -- cgit v1.2.1 From 514592b89207e83d13b5a4e79bc247aa6f74c4b7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Mon, 12 May 2008 21:43:24 +0000 Subject: - Introducing curl_easy_send() and curl_easy_recv(). They can be used to send and receive data over a connection previously setup with curl_easy_perform() and its CURLOPT_CONNECT_ONLY option. The sendrecv.c example was added to show how they can be used. --- docs/examples/Makefile.inc | 3 +- docs/examples/sendrecv.c | 117 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 docs/examples/sendrecv.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 5d0c162a5..840c9bf6c 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -4,7 +4,8 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface \ getinfo getinmemory http-post httpput \ https multi-app multi-debugcallback multi-double \ multi-post multi-single persistant post-callback \ - postit2 sepheaders simple simplepost simplessl + postit2 sepheaders simple simplepost simplessl \ + sendrecv # 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/sendrecv.c b/docs/examples/sendrecv.c new file mode 100644 index 000000000..1a37d2862 --- /dev/null +++ b/docs/examples/sendrecv.c @@ -0,0 +1,117 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * An example of curl_easy_send() and curl_easy_recv() usage. + * + * $Id$ + */ + +#include <stdio.h> +#include <string.h> +#include <curl/curl.h> + +/* Auxiliary function that waits on the socket. */ +static int wait_on_socket(int sockfd, int for_recv, long timeout_ms) +{ + struct timeval tv; + long seconds, usecs; + fd_set infd, outfd, errfd; + int res; + + tv.tv_sec = timeout_ms / 1000; + tv.tv_usec= (timeout_ms % 1000) * 1000; + + FD_ZERO(&infd); + FD_ZERO(&outfd); + FD_ZERO(&errfd); + + FD_SET(sockfd, &errfd); /* always check for error */ + + if(for_recv) + { + FD_SET(sockfd, &infd); + } + else + { + FD_SET(sockfd, &outfd); + } + + /* select() returns the number of signalled sockets or -1 */ + res = select(sockfd + 1, &infd, &outfd, &errfd, &tv); + return res; +} + +int main(void) +{ + CURL *curl; + CURLcode res; + /* Minimalistic http request */ + const char *request = "GET / HTTP/1.0\r\nHost: curl.haxx.se\r\n\r\n"; + int sockfd; /* socket */ + size_t iolen; + + curl = curl_easy_init(); + if(curl) { + curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); + /* Do not do the transfer - only connect to host */ + curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); + res = curl_easy_perform(curl); + + if(CURLE_OK != res) + { + printf("Error: %s\n", strerror(res)); + return 1; + } + + /* Extract the socket from the curl handle - we'll need it + * for waiting */ + res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockfd); + + if(CURLE_OK != res) + { + printf("Error: %s\n", strerror(res)); + return 1; + } + + /* wait for the socket to become ready for sending */ + if(!wait_on_socket(sockfd, 0, 60000L)) + { + printf("Error: timeout.\n"); + return 1; + } + + puts("Sending request."); + /* Send the request. Real applications should check the iolen + * to see if all the request has been sent */ + res = curl_easy_send(curl, request, strlen(request), &iolen); + + if(CURLE_OK != res) + { + printf("Error: %s\n", strerror(res)); + return 1; + } + puts("Reading response."); + + /* read the response */ + for(;;) + { + char buf[1024]; + + wait_on_socket(sockfd, 1, 60000L); + res = curl_easy_recv(curl, buf, 1024, &iolen); + + if(CURLE_OK != res) + break; + + printf("Received %u bytes.\n", iolen); + } + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} -- cgit v1.2.1 From ade57a781cfc3ec6877acd6ab30225c20e3efd09 Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Thu, 15 May 2008 22:31:23 +0000 Subject: Included stdint.h to get the intptr_t type (needed on OpenBSD at least). --- docs/examples/anyauthput.c | 1 + 1 file changed, 1 insertion(+) (limited to 'docs/examples') diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index 2c8f738ea..952c7c2d7 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -9,6 +9,7 @@ */ #include <stdio.h> +#include <stdint.h> #include <fcntl.h> #include <sys/stat.h> #include <unistd.h> -- cgit v1.2.1 From e059efda1b3db101536a2f9da2e9e63b71a554f4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Fri, 16 May 2008 21:14:50 +0000 Subject: removed lots of warnings --- docs/examples/hiperfifo.c | 52 ++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index 76e506fb5..065a974ad 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -95,6 +95,7 @@ typedef struct _SockInfo { static int multi_timer_cb(CURLM *multi, long timeout_ms, GlobalInfo *g) { struct timeval timeout; + (void)multi; /* unused */ timeout.tv_sec = timeout_ms/1000; timeout.tv_usec = (timeout_ms%1000)*1000; @@ -103,12 +104,11 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, GlobalInfo *g) return 0; } - - /* Die if we get a bad CURLMcode somewhere */ -void mcode_or_die(char *where, CURLMcode code) { +static void mcode_or_die(const char *where, CURLMcode code) +{ if ( CURLM_OK != code ) { - char *s; + const char *s; switch (code) { case CURLM_CALL_MULTI_PERFORM: s="CURLM_CALL_MULTI_PERFORM"; break; case CURLM_OK: s="CURLM_OK"; break; @@ -176,6 +176,7 @@ static void event_cb(int fd, short kind, void *userp) { GlobalInfo *g = (GlobalInfo*) userp; CURLMcode rc; + (void)kind; /* unused */ do { rc = curl_multi_socket(g->multi, fd, &g->still_running); @@ -195,10 +196,10 @@ static void event_cb(int fd, short kind, void *userp) /* Called by libevent when our timeout expires */ static void timer_cb(int fd, short kind, void *userp) { - (void)fd; - (void)kind; GlobalInfo *g = (GlobalInfo *)userp; CURLMcode rc; + (void)fd; + (void)kind; do { rc = curl_multi_socket(g->multi, CURL_SOCKET_TIMEOUT, &g->still_running); @@ -289,16 +290,21 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data) /* CURLOPT_PROGRESSFUNCTION */ -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; + (void)ult; + (void)uln; + fprintf(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 */ -void new_conn(char *url, GlobalInfo *g ) { +static void new_conn(char *url, GlobalInfo *g ) +{ ConnInfo *conn; CURLMcode rc; @@ -333,14 +339,15 @@ void new_conn(char *url, GlobalInfo *g ) { check_run_count(g); } - - /* This gets called whenever data is received from the fifo */ -void fifo_cb(int fd, short event, void *arg) { +static void fifo_cb(int fd, short event, void *arg) +{ char s[1024]; long int rv=0; int n=0; GlobalInfo *g = (GlobalInfo *)arg; + (void)fd; /* unused */ + (void)event; /* unused */ do { s[0]='\0'; @@ -352,13 +359,12 @@ void fifo_cb(int fd, short event, void *arg) { } while ( rv != EOF); } - - /* Create a named pipe and tell libevent to monitor it */ -int init_fifo (GlobalInfo *g) { +static int init_fifo (GlobalInfo *g) +{ struct stat st; static const char *fifo = "hiper.fifo"; - int socket; + int sockfd; fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo); if (lstat (fifo, &st) == 0) { @@ -373,25 +379,25 @@ int init_fifo (GlobalInfo *g) { perror("mkfifo"); exit (1); } - socket = open(fifo, O_RDWR | O_NONBLOCK, 0); - if (socket == -1) { - perror("open"); - exit (1); + sockfd = open(fifo, O_RDWR | O_NONBLOCK, 0); + if (sockfd == -1) { + perror("open"); + exit (1); } - g->input = fdopen(socket, "r"); + g->input = fdopen(sockfd, "r"); fprintf(MSG_OUT, "Now, pipe some URL's into > %s\n", fifo); - event_set(&g->fifo_event, socket, EV_READ | EV_PERSIST, fifo_cb, g); + event_set(&g->fifo_event, sockfd, EV_READ | EV_PERSIST, fifo_cb, g); event_add(&g->fifo_event, NULL); return (0); } - - int main(int argc, char **argv) { GlobalInfo g; CURLMcode rc; + (void)argc; + (void)argv; memset(&g, 0, sizeof(GlobalInfo)); event_init(); -- cgit v1.2.1 From c2a84aa6f02ee81c5c3e12b6d35cd0307fb24d7b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Mon, 19 May 2008 20:40:53 +0000 Subject: change the code style to be more curlish, and changed some of the output to be more descriptive and finally set VERBOSE mode to 1 by default --- docs/examples/hiperfifo.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index 065a974ad..a3b3b55eb 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -116,10 +116,14 @@ static void mcode_or_die(const char *where, CURLMcode code) 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"; + break; + case CURLM_BAD_SOCKET: s="CURLM_BAD_SOCKET"; + fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s); + /* ignore this error */ + return; } fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s); exit(code); @@ -213,9 +217,11 @@ static void timer_cb(int fd, short kind, void *userp) /* Clean up the SockInfo structure */ static void remsock(SockInfo *f) { - if (!f) { return; } - if (f->evset) { event_del(&f->ev); } - free(f); + if (f) { + if (f->evset) + event_del(&f->ev); + free(f); + } } @@ -229,8 +235,9 @@ 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) { event_del(&f->ev); } - event_set( &f->ev, f->sockfd, kind, event_cb, g); + if (f->evset) + event_del(&f->ev); + event_set(&f->ev, f->sockfd, kind, event_cb, g); f->evset=1; event_add(&f->ev, NULL); } @@ -246,8 +253,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) { @@ -260,16 +265,16 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) if (what == CURL_POLL_REMOVE) { fprintf(MSG_OUT, "\n"); remsock(fdp); - } else { + } + else { if (!fdp) { - fprintf(MSG_OUT, "Adding data: %s%s\n", - what&CURL_POLL_IN?"READ":"", - what&CURL_POLL_OUT?"WRITE":"" ); + fprintf(MSG_OUT, "Adding data: %s\n", whatstr[what]); addsock(s, e, what, g); } else { fprintf(MSG_OUT, - "Changing action from %d to %d\n", fdp->action, what); + "Changing action from %s to %s\n", + whatstr[fdp->action], whatstr[what]); setsock(fdp, s, e, what, g); } } @@ -322,7 +327,7 @@ static void new_conn(char *url, GlobalInfo *g ) 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_VERBOSE, 0); + curl_easy_setopt(conn->easy, CURLOPT_VERBOSE, 1); curl_easy_setopt(conn->easy, CURLOPT_ERRORBUFFER, conn->error); curl_easy_setopt(conn->easy, CURLOPT_PRIVATE, conn); curl_easy_setopt(conn->easy, CURLOPT_NOPROGRESS, 0); -- cgit v1.2.1 From e664cd5826d43930fcc5b5dbaedbec94af33184b Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Thu, 22 May 2008 21:20:07 +0000 Subject: Fixed a surprising number of example programs that were passing int arguments to curl_easy_setopt instead of long. --- docs/examples/10-at-a-time.c | 4 ++-- docs/examples/anyauthput.c | 7 ++++--- docs/examples/cacertinmem.c | 10 +++++----- docs/examples/cookie_interface.c | 2 +- docs/examples/curlgtk.c | 2 +- docs/examples/curlx.c | 4 ++-- docs/examples/debug.c | 2 +- docs/examples/fileupload.c | 4 ++-- docs/examples/fopen.c | 2 +- docs/examples/ftpget.c | 2 +- docs/examples/ftpupload.c | 3 ++- docs/examples/ftpuploadresume.c | 18 +++++++++--------- docs/examples/ghiper.c | 12 ++++++------ docs/examples/hiperfifo.c | 4 ++-- docs/examples/htmltidy.c | 4 ++-- docs/examples/htmltitle.cc | 2 +- docs/examples/httpput.c | 6 +++--- docs/examples/https.c | 4 ++-- docs/examples/multi-app.c | 2 +- docs/examples/multi-debugcallback.c | 2 +- docs/examples/multi-post.c | 2 +- docs/examples/persistant.c | 4 ++-- docs/examples/post-callback.c | 6 +++--- docs/examples/sepheaders.c | 4 ++-- docs/examples/simplepost.c | 2 +- docs/examples/simplessl.c | 4 ++-- docs/examples/synctime.c | 2 +- docs/examples/threaded-ssl.c | 4 ++-- 28 files changed, 63 insertions(+), 61 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index b30efc075..0b2a20ed8 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -90,10 +90,10 @@ static void init(CURLM *cm, int i) CURL *eh = curl_easy_init(); curl_easy_setopt(eh, CURLOPT_WRITEFUNCTION, cb); - curl_easy_setopt(eh, CURLOPT_HEADER, 0); + curl_easy_setopt(eh, CURLOPT_HEADER, 0L); curl_easy_setopt(eh, CURLOPT_URL, urls[i]); curl_easy_setopt(eh, CURLOPT_PRIVATE, urls[i]); - curl_easy_setopt(eh, CURLOPT_VERBOSE, 0); + curl_easy_setopt(eh, CURLOPT_VERBOSE, 0L); curl_multi_add_handle(cm, eh); } diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index 952c7c2d7..41531f7aa 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -110,7 +110,7 @@ int main(int argc, char **argv) curl_easy_setopt(curl, CURLOPT_IOCTLDATA, (void*)hd); /* enable "uploading" (which means PUT when doing HTTP) */ - curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ; + 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) */ @@ -118,12 +118,13 @@ int main(int argc, char **argv) /* and give the size of the upload, this supports large file sizes on systems that have general support for it */ - curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, file_info.st_size); + curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, + (curl_off_t)file_info.st_size); /* tell libcurl we can use "any" auth, which lets the lib pick one, but it also costs one extra round-trip and possibly sending of all the PUT data twice!!! */ - curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); + curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY); /* set user name and password for the authentication */ curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password"); diff --git a/docs/examples/cacertinmem.c b/docs/examples/cacertinmem.c index e58c9ace9..78809ae93 100644 --- a/docs/examples/cacertinmem.c +++ b/docs/examples/cacertinmem.c @@ -102,16 +102,16 @@ int main(void) rv=curl_global_init(CURL_GLOBAL_ALL); ch=curl_easy_init(); - rv=curl_easy_setopt(ch,CURLOPT_VERBOSE, 0); - rv=curl_easy_setopt(ch,CURLOPT_HEADER, 0); - rv=curl_easy_setopt(ch,CURLOPT_NOPROGRESS, 1); - rv=curl_easy_setopt(ch,CURLOPT_NOSIGNAL, 1); + 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_WRITEHEADER, stderr); rv=curl_easy_setopt(ch,CURLOPT_SSLCERTTYPE,"PEM"); - rv=curl_easy_setopt(ch,CURLOPT_SSL_VERIFYPEER,1); + rv=curl_easy_setopt(ch,CURLOPT_SSL_VERIFYPEER,1L); rv=curl_easy_setopt(ch, CURLOPT_URL, "https://www.cacert.org/"); /* first try: retrieve page without cacerts' certificate -> will fail diff --git a/docs/examples/cookie_interface.c b/docs/examples/cookie_interface.c index b0f33831d..51b32428d 100644 --- a/docs/examples/cookie_interface.c +++ b/docs/examples/cookie_interface.c @@ -54,7 +54,7 @@ main(void) char nline[256]; curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/"); /* google.com sets "PREF" cookie */ - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); /* just to start the cookie engine */ res = curl_easy_perform(curl); if (res != CURLE_OK) { diff --git a/docs/examples/curlgtk.c b/docs/examples/curlgtk.c index 19f7b1712..2327929fb 100644 --- a/docs/examples/curlgtk.c +++ b/docs/examples/curlgtk.c @@ -58,7 +58,7 @@ void *my_thread(void *ptr) curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_func); curl_easy_setopt(curl, CURLOPT_READFUNCTION, my_read_func); - curl_easy_setopt(curl, CURLOPT_NOPROGRESS, FALSE); + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func); curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, Bar); diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 636c8b4fe..bd192865f 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -438,7 +438,7 @@ 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,tabLength); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,(long)tabLength); /* pass our list of custom made headers */ @@ -477,7 +477,7 @@ 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,tabLength); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,(long)tabLength); /* Perform the request, res will get the return code */ diff --git a/docs/examples/debug.c b/docs/examples/debug.c index 6f7a6383a..543a565eb 100644 --- a/docs/examples/debug.c +++ b/docs/examples/debug.c @@ -116,7 +116,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &config); /* the DEBUGFUNCTION has no effect until we enable VERBOSE */ - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); res = curl_easy_perform(curl); diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c index 0f6e69d20..cb88ef687 100644 --- a/docs/examples/fileupload.c +++ b/docs/examples/fileupload.c @@ -36,7 +36,7 @@ int main(void) "file:///home/dast/src/curl/debug/new"); /* tell it to "upload" to the URL */ - curl_easy_setopt(curl, CURLOPT_UPLOAD, 1); + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); /* set where to read from (on Windows you need to use READFUNCTION too) */ curl_easy_setopt(curl, CURLOPT_READDATA, fd); @@ -46,7 +46,7 @@ int main(void) (curl_off_t)file_info.st_size); /* enable verbose for easier tracing */ - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); res = curl_easy_perform(curl); diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index 44d2498a0..9801e15c1 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -236,7 +236,7 @@ url_fopen(const char *url,const char *operation) curl_easy_setopt(file->handle.curl, CURLOPT_URL, url); curl_easy_setopt(file->handle.curl, CURLOPT_WRITEDATA, file); - curl_easy_setopt(file->handle.curl, CURLOPT_VERBOSE, 0); + curl_easy_setopt(file->handle.curl, CURLOPT_VERBOSE, 0L); curl_easy_setopt(file->handle.curl, CURLOPT_WRITEFUNCTION, write_callback); if(!multi_handle) diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 155e79cb7..179fd6129 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -65,7 +65,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile); /* Switch on full protocol/debug output */ - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); res = curl_easy_perform(curl); diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index 9ce548480..76fc92ebb 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -9,6 +9,7 @@ */ #include <stdio.h> +#include <string.h> #include <curl/curl.h> #include <sys/types.h> @@ -83,7 +84,7 @@ int main(int argc, char **argv) curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); /* enable uploading */ - curl_easy_setopt(curl, CURLOPT_UPLOAD, 1) ; + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); /* specify target */ curl_easy_setopt(curl,CURLOPT_URL, REMOTE_URL); diff --git a/docs/examples/ftpuploadresume.c b/docs/examples/ftpuploadresume.c index 7c71add0c..d8d1c5b88 100644 --- a/docs/examples/ftpuploadresume.c +++ b/docs/examples/ftpuploadresume.c @@ -77,7 +77,7 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath, return 0; } - curl_easy_setopt(curlhandle, CURLOPT_UPLOAD, 1); + curl_easy_setopt(curlhandle, CURLOPT_UPLOAD, 1L); curl_easy_setopt(curlhandle, CURLOPT_URL, remotepath); @@ -93,9 +93,9 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath, curl_easy_setopt(curlhandle, CURLOPT_READDATA, f); curl_easy_setopt(curlhandle, CURLOPT_FTPPORT, "-"); /* disable passive mode */ - curl_easy_setopt(curlhandle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1); + curl_easy_setopt(curlhandle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L); - curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, 1); + curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, 1L); for (c = 0; (r != CURLE_OK) && (c < tries); c++) { /* are we resuming? */ @@ -110,22 +110,22 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath, * because HEADER will dump the headers to stdout * without it. */ - curl_easy_setopt(curlhandle, CURLOPT_NOBODY, 1); - curl_easy_setopt(curlhandle, CURLOPT_HEADER, 1); + curl_easy_setopt(curlhandle, CURLOPT_NOBODY, 1L); + curl_easy_setopt(curlhandle, CURLOPT_HEADER, 1L); r = curl_easy_perform(curlhandle); if (r != CURLE_OK) continue; - curl_easy_setopt(curlhandle, CURLOPT_NOBODY, 0); - curl_easy_setopt(curlhandle, CURLOPT_HEADER, 0); + curl_easy_setopt(curlhandle, CURLOPT_NOBODY, 0L); + curl_easy_setopt(curlhandle, CURLOPT_HEADER, 0L); fseek(f, uploaded_len, SEEK_SET); - curl_easy_setopt(curlhandle, CURLOPT_APPEND, 1); + curl_easy_setopt(curlhandle, CURLOPT_APPEND, 1L); } else { /* no */ - curl_easy_setopt(curlhandle, CURLOPT_APPEND, 0); + curl_easy_setopt(curlhandle, CURLOPT_APPEND, 0L); } r = curl_easy_perform(curlhandle); diff --git a/docs/examples/ghiper.c b/docs/examples/ghiper.c index db7d3cb1c..a9b695ea0 100644 --- a/docs/examples/ghiper.c +++ b/docs/examples/ghiper.c @@ -325,16 +325,16 @@ static void new_conn(char *url, GlobalInfo *g ) 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_VERBOSE, SHOW_VERBOSE); + curl_easy_setopt(conn->easy, CURLOPT_VERBOSE, (long)SHOW_VERBOSE); curl_easy_setopt(conn->easy, CURLOPT_ERRORBUFFER, conn->error); curl_easy_setopt(conn->easy, CURLOPT_PRIVATE, conn); - curl_easy_setopt(conn->easy, CURLOPT_NOPROGRESS, SHOW_PROGRESS?0:1); + curl_easy_setopt(conn->easy, CURLOPT_NOPROGRESS, SHOW_PROGRESS?0L:1L); curl_easy_setopt(conn->easy, CURLOPT_PROGRESSFUNCTION, prog_cb); curl_easy_setopt(conn->easy, CURLOPT_PROGRESSDATA, conn); - curl_easy_setopt(conn->easy, CURLOPT_FOLLOWLOCATION, 1); - curl_easy_setopt(conn->easy, CURLOPT_CONNECTTIMEOUT, 30); - curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_LIMIT, 1); - curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_TIME, 30); + curl_easy_setopt(conn->easy, CURLOPT_FOLLOWLOCATION, 1L); + curl_easy_setopt(conn->easy, CURLOPT_CONNECTTIMEOUT, 30L); + curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_TIME, 30L); MSG_OUT("Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url); rc =curl_multi_add_handle(g->multi, conn->easy); diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index a3b3b55eb..95ca8ad0d 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -327,10 +327,10 @@ static void new_conn(char *url, GlobalInfo *g ) 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_VERBOSE, 1); + 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); - curl_easy_setopt(conn->easy, CURLOPT_NOPROGRESS, 0); + curl_easy_setopt(conn->easy, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(conn->easy, CURLOPT_PROGRESSFUNCTION, prog_cb); curl_easy_setopt(conn->easy, CURLOPT_PROGRESSDATA, conn); fprintf(MSG_OUT, diff --git a/docs/examples/htmltidy.c b/docs/examples/htmltidy.c index 112a4e6b6..cd75401a9 100644 --- a/docs/examples/htmltidy.c +++ b/docs/examples/htmltidy.c @@ -75,8 +75,8 @@ int main(int argc, char **argv ) curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, argv[1]); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf); - curl_easy_setopt(curl, CURLOPT_NOPROGRESS, no); - curl_easy_setopt(curl, CURLOPT_VERBOSE, yes); + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb); tdoc = tidyCreate(); diff --git a/docs/examples/htmltitle.cc b/docs/examples/htmltitle.cc index 62a4363d5..de7ff0339 100644 --- a/docs/examples/htmltitle.cc +++ b/docs/examples/htmltitle.cc @@ -100,7 +100,7 @@ static bool init(CURL *&conn, char *url) return false; } - code = curl_easy_setopt(conn, CURLOPT_FOLLOWLOCATION, 1); + code = curl_easy_setopt(conn, CURLOPT_FOLLOWLOCATION, 1L); if (code != CURLE_OK) { fprintf(stderr, "Failed to set redirect option [%s]\n", errorBuffer); diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index 5b92548a5..585dfa2cc 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -76,14 +76,14 @@ int main(int argc, char **argv) curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); /* enable uploading */ - curl_easy_setopt(curl, CURLOPT_UPLOAD, 1) ; + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); /* HTTP PUT please */ - curl_easy_setopt(curl, CURLOPT_PUT, 1); + curl_easy_setopt(curl, CURLOPT_PUT, 1L); /* specify target URL, and note that this URL should include a file name, not only a directory */ - curl_easy_setopt(curl,CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_URL, url); /* now specify which file to upload */ curl_easy_setopt(curl, CURLOPT_READDATA, hd_src); diff --git a/docs/examples/https.c b/docs/examples/https.c index 4a83f5f93..e6b8e89b6 100644 --- a/docs/examples/https.c +++ b/docs/examples/https.c @@ -31,7 +31,7 @@ int main(void) * default bundle, then the CURLOPT_CAPATH option might come handy for * you. */ - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); #endif #ifdef SKIP_HOSTNAME_VERFICATION @@ -41,7 +41,7 @@ int main(void) * subjectAltName) fields, libcurl will refuse to connect. You can skip * this check, but this will make the connection less secure. */ - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); #endif res = curl_easy_perform(curl); diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index 5969c91c8..a8a92ab33 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -47,7 +47,7 @@ int main(int argc, char **argv) curl_easy_setopt(handles[HTTP_HANDLE], CURLOPT_URL, "http://website.com"); curl_easy_setopt(handles[FTP_HANDLE], CURLOPT_URL, "ftp://ftpsite.com"); - curl_easy_setopt(handles[FTP_HANDLE], CURLOPT_UPLOAD, 1); + curl_easy_setopt(handles[FTP_HANDLE], CURLOPT_UPLOAD, 1L); /* init a multi stack */ multi_handle = curl_multi_init(); diff --git a/docs/examples/multi-debugcallback.c b/docs/examples/multi-debugcallback.c index 1cd6e4398..6a7403a8a 100644 --- a/docs/examples/multi-debugcallback.c +++ b/docs/examples/multi-debugcallback.c @@ -121,7 +121,7 @@ int main(int argc, char **argv) curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.haxx.se/"); curl_easy_setopt(http_handle, CURLOPT_DEBUGFUNCTION, my_trace); - curl_easy_setopt(http_handle, CURLOPT_VERBOSE, TRUE); + curl_easy_setopt(http_handle, CURLOPT_VERBOSE, 1L); /* init a multi stack */ multi_handle = curl_multi_init(); diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index c560bb916..18973a94a 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) /* what URL that receives this POST */ curl_easy_setopt(curl, CURLOPT_URL, "http://www.fillinyoururl.com/upload.cgi"); - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); diff --git a/docs/examples/persistant.c b/docs/examples/persistant.c index 673889914..3d75b9ebe 100644 --- a/docs/examples/persistant.c +++ b/docs/examples/persistant.c @@ -21,8 +21,8 @@ int main(int argc, char **argv) curl = curl_easy_init(); if(curl) { - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); - curl_easy_setopt(curl, CURLOPT_HEADER, 1); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + curl_easy_setopt(curl, CURLOPT_HEADER, 1L); /* get the first document */ curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/"); diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index e3f37c4ae..ed89cac2a 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -55,7 +55,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_URL, "http://receivingsite.com.pooh/index.cgi"); /* Now specify we want to POST data */ - curl_easy_setopt(curl, CURLOPT_POST, 1); + curl_easy_setopt(curl, CURLOPT_POST, 1L); /* we want to use our own read function */ curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); @@ -64,7 +64,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_READDATA, &pooh); /* get verbose debug output please */ - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); /* If you use POST to a HTTP 1.1 server, you can send data without knowing @@ -85,7 +85,7 @@ int main(void) #else /* Set the expected POST size. If you want to POST large amounts of data, consider CURLOPT_POSTFIELDSIZE_LARGE */ - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, pooh.sizeleft); + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)pooh.sizeleft); #endif #ifdef DISABLE_EXPECT diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index adfa4374a..9d3dba1f9 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -39,7 +39,7 @@ int main(int argc, char **argv) curl_easy_setopt(curl_handle, CURLOPT_URL, "http://curl.haxx.se"); /* no progress meter please */ - curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1); + curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L); /* send all data to this function */ curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data); @@ -57,7 +57,7 @@ int main(int argc, char **argv) } /* we want the headers to this file handle */ - curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER ,headerfile); + curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, headerfile); /* * Notice here that if you want the actual data sent anywhere else but diff --git a/docs/examples/simplepost.c b/docs/examples/simplepost.c index 9bab83b7d..4aed4f999 100644 --- a/docs/examples/simplepost.c +++ b/docs/examples/simplepost.c @@ -26,7 +26,7 @@ int main(void) /* if we don't provide POSTFIELDSIZE, libcurl will strlen() by itself */ - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(postthis)); + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(postthis)); res = curl_easy_perform(curl); diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index 77da32d08..ea9eb5ee7 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -77,7 +77,7 @@ int main(int argc, char **argv) fprintf(stderr,"can't set crypto engine\n"); break; } - if (curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT,1) != CURLE_OK) + 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... */ @@ -108,7 +108,7 @@ int main(int argc, char **argv) curl_easy_setopt(curl,CURLOPT_CAINFO,pCACertFile); /* disconnect if we can't validate server's cert */ - curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,1); + curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,1L); res = curl_easy_perform(curl); break; /* we are done... */ diff --git a/docs/examples/synctime.c b/docs/examples/synctime.c index 2d5a8e51e..dd824670e 100644 --- a/docs/examples/synctime.c +++ b/docs/examples/synctime.c @@ -189,7 +189,7 @@ int SyncTime_CURL_Fetch(CURL *curl, char *URL_Str, char *OutFileName, outfile = NULL; if (HttpGetBody == HTTP_COMMAND_HEAD) - curl_easy_setopt(curl, CURLOPT_NOBODY, 1); + curl_easy_setopt(curl, CURLOPT_NOBODY, 1L); else { outfile = fopen(OutFileName, "wb"); curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); diff --git a/docs/examples/threaded-ssl.c b/docs/examples/threaded-ssl.c index afc609551..6b979bac4 100644 --- a/docs/examples/threaded-ssl.c +++ b/docs/examples/threaded-ssl.c @@ -106,8 +106,8 @@ static void *pull_one_url(void *url) curl_easy_setopt(curl, CURLOPT_URL, url); /* this example doesn't verify the server's certificate, which means we might be downloading stuff from an impostor */ - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); curl_easy_perform(curl); /* ignores error */ curl_easy_cleanup(curl); -- cgit v1.2.1 From a95e600eb0fa1fdba0d2627ff15aaf9392b6c253 Mon Sep 17 00:00:00 2001 From: Gisle Vanem <gvanem@broadpark.no> Date: Tue, 8 Jul 2008 13:55:20 +0000 Subject: Added libidn libs as needed. Added compilation of sendrecv.c and cookie_interface.c. --- docs/examples/makefile.dj | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/makefile.dj b/docs/examples/makefile.dj index c47f003ee..853b6b4ed 100644 --- a/docs/examples/makefile.dj +++ b/docs/examples/makefile.dj @@ -16,6 +16,10 @@ ifeq ($(USE_SSL),1) LIBS += $(OPENSSL_ROOT)/lib/libssl.a $(OPENSSL_ROOT)/lib/libcrypt.a endif +ifeq ($(USE_IDNA),1) + LIBS += $(LIBIDN_ROOT)/lib/dj_obj/libidn.a -liconv +endif + LIBS += $(WATT32_ROOT)/lib/libwatt.a $(ZLIB_ROOT)/libz.a CSOURCES = fopen.c ftpget.c ftpgetresp.c ftpupload.c getinmemory.c \ @@ -23,7 +27,7 @@ CSOURCES = fopen.c ftpget.c ftpgetresp.c ftpupload.c getinmemory.c \ multi-post.c multi-single.c persistant.c post-callback.c \ postit2.c sepheaders.c simple.c simplepost.c simplessl.c \ multi-debugcallback.c fileupload.c getinfo.c anyauthput.c \ - 10-at-a-time.c # ftpuploadresume.c cookie_interface.c + 10-at-a-time.c sendrecv.c cookie_interface.c # ftpuploadresume.c PROGRAMS = $(CSOURCES:.c=.exe) -- cgit v1.2.1 From a00febe1a0b1fd458bb9d6582cf231bb7370ccc8 Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Tue, 15 Jul 2008 13:54:30 +0000 Subject: add comment for include paths --- docs/examples/Makefile.am | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 83069d442..e897844e8 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -7,6 +7,13 @@ AUTOMAKE_OPTIONS = foreign nostdinc EXTRA_DIST = README Makefile.example Makefile.inc Makefile.m32 \ makefile.dj $(COMPLICATED_EXAMPLES) +# Specify our include paths here, and do it relative to $(top_srcdir) and +# $(top_builddir), to ensure that these paths which belong to the library +# being currently built and tested are searched before the library which +# might possibly already be installed in the system. +# +# $(top_srcdir)/include is for libcurl's external include files + INCLUDES = -I$(top_srcdir)/include LIBDIR = $(top_builddir)/lib -- cgit v1.2.1 From 14240e9e109fe6af19438c6531d573f85dbb0b1e Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Thu, 7 Aug 2008 00:29:08 +0000 Subject: Initial support of curlbuild.h and curlrules.h which allows to have a curl_off_t data type no longer gated to off_t. --- docs/examples/Makefile.am | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index e897844e8..886e8ada6 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -12,9 +12,11 @@ EXTRA_DIST = README Makefile.example Makefile.inc Makefile.m32 \ # being currently built and tested are searched before the library which # might possibly already be installed in the system. # +# $(top_builddir)/include is for libcurl's generated curl/curlbuild.h file # $(top_srcdir)/include is for libcurl's external include files -INCLUDES = -I$(top_srcdir)/include +INCLUDES = -I$(top_builddir)/include \ + -I$(top_srcdir)/include LIBDIR = $(top_builddir)/lib -- cgit v1.2.1 From aab2d52b25776345f88537fd22f3d79c0fce170d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 13 Aug 2008 08:51:52 +0000 Subject: httpcustomheader.c is a new tiny example showing a HTTP request with a custom header replacing an internal one --- docs/examples/Makefile.inc | 2 +- docs/examples/httpcustomheader.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 docs/examples/httpcustomheader.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 840c9bf6c..68b66c3e3 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -5,7 +5,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface \ https multi-app multi-debugcallback multi-double \ multi-post multi-single persistant post-callback \ postit2 sepheaders simple simplepost simplessl \ - sendrecv + sendrecv httpcustomheader # 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/httpcustomheader.c b/docs/examples/httpcustomheader.c new file mode 100644 index 000000000..13e62e657 --- /dev/null +++ b/docs/examples/httpcustomheader.c @@ -0,0 +1,38 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include <stdio.h> +#include <curl/curl.h> + +int main(void) +{ + CURL *curl; + CURLcode res; + + curl = curl_easy_init(); + if(curl) { + struct curl_slist *chunk = NULL; + + chunk = curl_slist_append(chunk, "Accept: moo"); + + /* request with the built-in Accept: */ + curl_easy_setopt(curl, CURLOPT_URL, "localhost"); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + res = curl_easy_perform(curl); + + /* redo request with our own custom Accept: */ + res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} -- cgit v1.2.1 From cf30b24706ee0d30f8aeae4360f39c96d329fad5 Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Thu, 14 Aug 2008 18:41:37 +0000 Subject: Fixed unused variable warning --- docs/examples/sendrecv.c | 1 - 1 file changed, 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/sendrecv.c b/docs/examples/sendrecv.c index 1a37d2862..45bae652a 100644 --- a/docs/examples/sendrecv.c +++ b/docs/examples/sendrecv.c @@ -18,7 +18,6 @@ static int wait_on_socket(int sockfd, int for_recv, long timeout_ms) { struct timeval tv; - long seconds, usecs; fd_set infd, outfd, errfd; int res; -- cgit v1.2.1 From d8cab4c13382d70995cfa26878d697a1ff7d4556 Mon Sep 17 00:00:00 2001 From: Gisle Vanem <gvanem@broadpark.no> Date: Sun, 17 Aug 2008 16:20:23 +0000 Subject: Pick-up programs from Makefile.inc. --- docs/examples/makefile.dj | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/makefile.dj b/docs/examples/makefile.dj index 853b6b4ed..6bf99d82f 100644 --- a/docs/examples/makefile.dj +++ b/docs/examples/makefile.dj @@ -22,14 +22,9 @@ endif LIBS += $(WATT32_ROOT)/lib/libwatt.a $(ZLIB_ROOT)/libz.a -CSOURCES = fopen.c ftpget.c ftpgetresp.c ftpupload.c getinmemory.c \ - http-post.c httpput.c https.c multi-app.c multi-double.c \ - multi-post.c multi-single.c persistant.c post-callback.c \ - postit2.c sepheaders.c simple.c simplepost.c simplessl.c \ - multi-debugcallback.c fileupload.c getinfo.c anyauthput.c \ - 10-at-a-time.c sendrecv.c cookie_interface.c # ftpuploadresume.c - -PROGRAMS = $(CSOURCES:.c=.exe) +include Makefile.inc + +PROGRAMS = $(patsubst %,%.exe,$(check_PROGRAMS)) all: $(PROGRAMS) @echo Welcome to libcurl example program -- cgit v1.2.1 From 79ffbf7fe1af3fb3d6a4a1ad31eeaaecb1dbd8e6 Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Sun, 31 Aug 2008 12:12:35 +0000 Subject: MSVC adjustment --- docs/examples/10-at-a-time.c | 7 +++---- docs/examples/anyauthput.c | 17 +++++++++++++++-- docs/examples/fopen.c | 4 +++- docs/examples/ftpuploadresume.c | 3 +++ 4 files changed, 24 insertions(+), 7 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index 0b2a20ed8..13ff196c8 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -16,11 +16,10 @@ #include <errno.h> #include <stdlib.h> #include <string.h> -#include <unistd.h> -#include <curl/multi.h> -#ifdef WIN32 -#include <windows.h> +#ifndef WIN32 +# include <unistd.h> #endif +#include <curl/multi.h> static const char *urls[] = { "http://www.microsoft.com", diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index 41531f7aa..11c9d3c77 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -9,10 +9,23 @@ */ #include <stdio.h> -#include <stdint.h> #include <fcntl.h> +#ifdef WIN32 +# include <io.h> +#else +# include <stdint.h> +# include <unistd.h> +#endif +#include <sys/types.h> #include <sys/stat.h> -#include <unistd.h> + +#ifdef _MSC_VER +# ifdef _WIN64 + typedef __int64 intptr_t; +# else + typedef int intptr_t; +# endif +#endif #include <curl/curl.h> diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index 9801e15c1..0a9e9e30d 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -45,7 +45,9 @@ #include <stdio.h> #include <string.h> -#include <sys/time.h> +#ifndef WIN32 +# include <sys/time.h> +#endif #include <stdlib.h> #include <errno.h> diff --git a/docs/examples/ftpuploadresume.c b/docs/examples/ftpuploadresume.c index d8d1c5b88..362711c33 100644 --- a/docs/examples/ftpuploadresume.c +++ b/docs/examples/ftpuploadresume.c @@ -21,6 +21,9 @@ #include <curl/curl.h> +#if defined(_MSC_VER) && (_MSC_VER < 1300) +# error _snscanf requires MSVC 7.0 or later. +#endif /* The MinGW headers are missing a few Win32 function definitions, you shouldn't need this if you use VC++ */ -- cgit v1.2.1 From 4c9768565ec3a9baf26ac8a547bca6e42cc64fa5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Fri, 5 Sep 2008 14:29:21 +0000 Subject: - Introducing CURLOPT_CERTINFO and the corresponding CURLINFO_CERTINFO. By enabling this feature with CURLOPT_CERTINFO for a request using SSL (HTTPS or FTPS), libcurl will gather lots of server certificate info and that info can then get extracted by a client after the request has completed with curl_easy_getinfo()'s CURLINFO_CERTINFO option. Linus Nielsen Feltzing helped me test and smoothen out this feature. Unfortunately, this feature currently only works with libcurl built to use OpenSSL. This feature was sponsored by networking4all.com - thanks! --- docs/examples/Makefile.inc | 3 +-- docs/examples/certinfo.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 docs/examples/certinfo.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 68b66c3e3..c3ee0228b 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -5,7 +5,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface \ https multi-app multi-debugcallback multi-double \ multi-post multi-single persistant post-callback \ postit2 sepheaders simple simplepost simplessl \ - sendrecv httpcustomheader + sendrecv httpcustomheader certinfo # These examples require external dependencies that may not be commonly # available on POSIX systems, so don't bother attempting to compile them here. @@ -14,4 +14,3 @@ COMPLICATED_EXAMPLES = \ ghiper.c hiperfifo.c htmltidy.c multithread.c \ opensslthreadlock.c sampleconv.c synctime.c threaded-ssl.c - diff --git a/docs/examples/certinfo.c b/docs/examples/certinfo.c new file mode 100644 index 000000000..b0e9759f4 --- /dev/null +++ b/docs/examples/certinfo.c @@ -0,0 +1,62 @@ +/***************************************************************************** + */ + +#include <stdio.h> + +#include <curl/curl.h> +#include <curl/types.h> +#include <curl/easy.h> + +static size_t wrfu(void *ptr, size_t size, size_t nmemb, void *stream) +{ + return size * nmemb; +} +int main(int argc, char **argv) +{ + CURL *curl; + CURLcode res; + + curl_global_init(CURL_GLOBAL_DEFAULT); + + curl = curl_easy_init(); + if(curl) { + curl_easy_setopt(curl, CURLOPT_URL, "https://www.networking4all.com/"); + + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wrfu); + + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + + curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); + curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L); + + res = curl_easy_perform(curl); + + if(!res) { + struct curl_certinfo *ci = NULL; + + res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &ci); + + if(!res && ci) { + int i; + printf("%d certs!\n", ci->num_of_certs); + + for(i=0; i<ci->num_of_certs; i++) { + struct curl_slist *slist; + + for(slist = ci->certinfo[i]; slist; slist = slist->next) + printf("%s\n", slist->data); + + } + } + + } + + + curl_easy_cleanup(curl); + } + + curl_global_cleanup(); + + return 0; +} -- cgit v1.2.1 From 861b647e7b1da564b831a5b07312a30feb7b6c58 Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Sat, 6 Sep 2008 04:28:43 +0000 Subject: remove unnecessary typecasting of realloc() --- docs/examples/curlx.c | 2 +- docs/examples/getinmemory.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index bd192865f..521812b9a 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -469,7 +469,7 @@ int main(int argc, char **argv) { i+=lu; if (i== tabLength) { tabLength+=100; - binaryptr=(char*)realloc(binaryptr,tabLength); /* should be more careful */ + binaryptr=realloc(binaryptr,tabLength); /* should be more careful */ } } tabLength = i; diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index fc1f87a91..c92482166 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -26,6 +26,8 @@ struct MemoryStruct { size_t size; }; +static void *myrealloc(void *ptr, size_t size); + static void *myrealloc(void *ptr, size_t size) { /* There might be a realloc() out there that doesn't like reallocing @@ -42,7 +44,7 @@ WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) size_t realsize = size * nmemb; struct MemoryStruct *mem = (struct MemoryStruct *)data; - mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1); + mem->memory = myrealloc(mem->memory, mem->size + realsize + 1); if (mem->memory) { memcpy(&(mem->memory[mem->size]), ptr, realsize); mem->size += realsize; -- cgit v1.2.1 From 59e378f48fed849e8e41f0bc6a10bf7a1732ae8a Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Sat, 6 Sep 2008 05:29:05 +0000 Subject: remove unnecessary typecasting of malloc() --- docs/examples/curlx.c | 6 +++--- docs/examples/fopen.c | 2 +- docs/examples/opensslthreadlock.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 521812b9a..09d27cc97 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -281,7 +281,7 @@ int main(int argc, char **argv) { struct curl_slist * headers=NULL; int badarg=0; - binaryptr=(char*)malloc(tabLength); + binaryptr = malloc(tabLength); p.verbose = 0; p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); @@ -404,7 +404,7 @@ int main(int argc, char **argv) { /* determine URL to go */ if (hostporturl) { - serverurl=(char*) malloc(9+strlen(hostporturl)); + serverurl = malloc(9+strlen(hostporturl)); sprintf(serverurl,"https://%s",hostporturl); } else if (p.accesstype != 0) { /* see whether we can find an AIA or SIA for a given access type */ @@ -442,7 +442,7 @@ int main(int argc, char **argv) { /* pass our list of custom made headers */ - contenttype=(char*) malloc(15+strlen(mimetype)); + contenttype = malloc(15+strlen(mimetype)); sprintf(contenttype,"Content-type: %s",mimetype); headers = curl_slist_append(headers,contenttype); curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers); diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index 0a9e9e30d..a8a4fe482 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -221,7 +221,7 @@ url_fopen(const char *url,const char *operation) URL_FILE *file; (void)operation; - file = (URL_FILE *)malloc(sizeof(URL_FILE)); + file = malloc(sizeof(URL_FILE)); if(!file) return NULL; diff --git a/docs/examples/opensslthreadlock.c b/docs/examples/opensslthreadlock.c index 18a2f77fc..3ac7124b0 100644 --- a/docs/examples/opensslthreadlock.c +++ b/docs/examples/opensslthreadlock.c @@ -56,7 +56,7 @@ int thread_setup(void) { int i; - mutex_buf = (MUTEX_TYPE *)malloc(CRYPTO_num_locks( ) * sizeof(MUTEX_TYPE)); + mutex_buf = malloc(CRYPTO_num_locks( ) * sizeof(MUTEX_TYPE)); if (!mutex_buf) return 0; for (i = 0; i < CRYPTO_num_locks( ); i++) -- cgit v1.2.1 From 152cf6325d3b1b0383d9c36fab9243005e4ea456 Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Wed, 10 Sep 2008 07:11:45 +0000 Subject: Checked in some grammatical and minor other fixes in the documentation and examples that I found in the FreeBSD ports system. --- docs/examples/fileupload.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c index cb88ef687..6ed523c36 100644 --- a/docs/examples/fileupload.c +++ b/docs/examples/fileupload.c @@ -27,7 +27,11 @@ int main(void) return 1; /* can't continue */ } - stat("debugit", &file_info); /* to get the file size */ + /* to get the file size */ + if(fstat(fileno(fd), &file_info) != 0) { + + return 1; /* can't continue */ + } curl = curl_easy_init(); if(curl) { -- cgit v1.2.1 From 0eb083e979eb62ce9d5446e927eb8e7682105f10 Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Mon, 22 Sep 2008 17:27:24 +0000 Subject: Argument to CURLMOPT_MAXCONNECTS must be a long --- docs/examples/10-at-a-time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index 13ff196c8..14b6e93af 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -113,7 +113,7 @@ int main(void) /* we can optionally limit the total amount of connections this multi handle uses */ - curl_multi_setopt(cm, CURLMOPT_MAXCONNECTS, MAX); + curl_multi_setopt(cm, CURLMOPT_MAXCONNECTS, (long)MAX); for (C = 0; C < MAX; ++C) { init(cm, C); -- cgit v1.2.1 From 22d4db1cf2f2661c6d7292c9545051937be25ed2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 19 Nov 2008 15:30:41 +0000 Subject: I updated this example to use the modern paradigms of the socket API where *_socket_all() and *_socket() aren't used at all but only *_socket_action() is. --- docs/examples/hiperfifo.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index 95ca8ad0d..d19048506 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -180,12 +180,17 @@ static void event_cb(int fd, short kind, void *userp) { GlobalInfo *g = (GlobalInfo*) userp; CURLMcode rc; - (void)kind; /* unused */ + + int action = + (kind&EV_READ:CURL_CSELECT_IN)| + (kind&EV_WRITE:CURL_CSELECT_OUT); do { - rc = curl_multi_socket(g->multi, fd, &g->still_running); + rc = curl_multi_socket_action(g->multi, fd, action, &g->still_running); } while (rc == CURLM_CALL_MULTI_PERFORM); - mcode_or_die("event_cb: curl_multi_socket", rc); + + mcode_or_die("event_cb: curl_multi_socket_action", rc); + check_run_count(g); if ( g->still_running <= 0 ) { fprintf(MSG_OUT, "last transfer done, kill timeout\n"); @@ -206,9 +211,10 @@ static void timer_cb(int fd, short kind, void *userp) (void)kind; do { - rc = curl_multi_socket(g->multi, CURL_SOCKET_TIMEOUT, &g->still_running); + rc = curl_multi_socket_action(g->multi, + CURL_SOCKET_TIMEOUT, 0, &g->still_running); } while (rc == CURLM_CALL_MULTI_PERFORM); - mcode_or_die("timer_cb: curl_multi_socket", rc); + mcode_or_die("timer_cb: curl_multi_socket_action", rc); check_run_count(g); } @@ -337,11 +343,9 @@ static void new_conn(char *url, GlobalInfo *g ) "Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url); rc =curl_multi_add_handle(g->multi, conn->easy); mcode_or_die("new_conn: curl_multi_add_handle", rc); - do { - rc = curl_multi_socket_all(g->multi, &g->still_running); - } while (CURLM_CALL_MULTI_PERFORM == rc); - mcode_or_die("new_conn: curl_multi_socket_all", rc); - check_run_count(g); + + /* note that the add_handle() will set a time-out to trigger very soon so + that the necessary socket_action() call will be called by this app */ } /* This gets called whenever data is received from the fifo */ @@ -409,13 +413,16 @@ int main(int argc, char **argv) init_fifo(&g); g.multi = curl_multi_init(); evtimer_set(&g.timer_event, timer_cb, &g); + + /* setup the generic multi interface options we want */ curl_multi_setopt(g.multi, CURLMOPT_SOCKETFUNCTION, sock_cb); curl_multi_setopt(g.multi, CURLMOPT_SOCKETDATA, &g); curl_multi_setopt(g.multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb); curl_multi_setopt(g.multi, CURLMOPT_TIMERDATA, &g); - do { - rc = curl_multi_socket_all(g.multi, &g.still_running); - } while (CURLM_CALL_MULTI_PERFORM == rc); + + /* we don't call any curl_multi_socket*() function yet as we have no handles + added! */ + event_dispatch(); curl_multi_cleanup(g.multi); return 0; -- cgit v1.2.1 From 0b489c7e611bc0bb5e224fc5e680fb7ae57a0557 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 19 Nov 2008 15:31:55 +0000 Subject: and now it compiles too! --- docs/examples/hiperfifo.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index d19048506..4102408ce 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -182,8 +182,8 @@ static void event_cb(int fd, short kind, void *userp) CURLMcode rc; int action = - (kind&EV_READ:CURL_CSELECT_IN)| - (kind&EV_WRITE:CURL_CSELECT_OUT); + (kind&EV_READ?CURL_CSELECT_IN:0)| + (kind&EV_WRITE?CURL_CSELECT_OUT:0); do { rc = curl_multi_socket_action(g->multi, fd, action, &g->still_running); @@ -404,7 +404,6 @@ static int init_fifo (GlobalInfo *g) int main(int argc, char **argv) { GlobalInfo g; - CURLMcode rc; (void)argc; (void)argv; -- cgit v1.2.1 From dd2fc45c27d71faf5d37abb313758c0df6c9afd4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Fri, 21 Nov 2008 10:10:33 +0000 Subject: Markus Koetter's adaptation of hiperfifo.c to instead use libev --- docs/examples/Makefile.inc | 2 +- docs/examples/evhiperfifo.c | 460 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 461 insertions(+), 1 deletion(-) create mode 100644 docs/examples/evhiperfifo.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index c3ee0228b..14ba74e8c 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -12,5 +12,5 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface \ COMPLICATED_EXAMPLES = \ curlgtk.c curlx.c htmltitle.cc cacertinmem.c ftpuploadresume.c \ ghiper.c hiperfifo.c htmltidy.c multithread.c \ - opensslthreadlock.c sampleconv.c synctime.c threaded-ssl.c + opensslthreadlock.c sampleconv.c synctime.c threaded-ssl.c evhiperfifo.c diff --git a/docs/examples/evhiperfifo.c b/docs/examples/evhiperfifo.c new file mode 100644 index 000000000..e77715aae --- /dev/null +++ b/docs/examples/evhiperfifo.c @@ -0,0 +1,460 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * Example application source code using the multi socket interface to + * download many files at once. + * + * This example features the same basic functionality as hiperfifo.c does, + * but this uses libev instead of libevent. + * + * Written by Jeff Pohlmeyer, converted to use libev by Markus Koetter + +Requires libev and a (POSIX?) system that has mkfifo(). + +This is an adaptation of libcurl's "hipev.c" and libevent's "event-test.c" +sample programs. + +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. + + +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 + +The fifo buffer is handled almost instantly, so you can even add more URL's +while the previous requests are still being downloaded. + +Note: + For the sake of simplicity, URL length is limited to 1023 char's ! + +This is purely a demo app, all retrieved data is simply discarded by the write +callback. + +*/ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <sys/time.h> +#include <time.h> +#include <unistd.h> +#include <sys/poll.h> +#include <curl/curl.h> +#include <ev.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <errno.h> + +#define DPRINT(x...) printf(x) + +#define MSG_OUT stdout /* Send info to stdout, change to stderr if you want */ + + +/* Global information, common to all connections */ +typedef struct _GlobalInfo +{ + struct ev_loop *loop; + struct ev_io fifo_event; + struct ev_timer timer_event; + CURLM *multi; + int prev_running; + int still_running; + FILE* input; +} GlobalInfo; + + +/* Information associated with a specific easy handle */ +typedef struct _ConnInfo +{ + CURL *easy; + char *url; + GlobalInfo *global; + char error[CURL_ERROR_SIZE]; +} ConnInfo; + + +/* Information associated with a specific socket */ +typedef struct _SockInfo +{ + curl_socket_t sockfd; + CURL *easy; + int action; + long timeout; + struct ev_io ev; + int evset; + GlobalInfo *global; +} SockInfo; + +static void timer_cb(EV_P_ struct ev_timer *w, int revents); + +/* Update the event timer after curl_multi library calls */ +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) + { + double t = timeout_ms / 1000; + ev_timer_init(&g->timer_event, timer_cb, t, 0.); + ev_timer_start(g->loop, &g->timer_event); + }else + timer_cb(g->loop, &g->timer_event, 0); + return 0; +} + +/* Die if we get a bad CURLMcode somewhere */ +static void mcode_or_die(const char *where, CURLMcode code) +{ + if ( CURLM_OK != code ) + { + const char *s; + switch ( code ) + { + case CURLM_CALL_MULTI_PERFORM: s="CURLM_CALL_MULTI_PERFORM"; break; + case CURLM_OK: s="CURLM_OK"; break; + 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"; + break; + case CURLM_BAD_SOCKET: s="CURLM_BAD_SOCKET"; + fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s); + /* ignore this error */ + return; + } + fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s); + exit(code); + } +} + + + +/* Check for completed transfers, and remove their easy handles */ +static void check_run_count(GlobalInfo *g) +{ + DPRINT("%s prev %i still %i\n", __PRETTY_FUNCTION__, + g->prev_running, g->still_running); + if ( g->prev_running > g->still_running ) + { + char *eff_url=NULL; + CURLMsg *msg; + int msgs_left; + ConnInfo *conn=NULL; + CURL*easy; + CURLcode res; + + fprintf(MSG_OUT, "REMAINING: %d\n", g->still_running); + /* + I am still uncertain whether it is safe to remove an easy + handle from inside the curl_multi_info_read loop, so here I + will search for completed transfers in the inner "while" + loop, and then remove them in the outer "do-while" loop... + */ + do + { + easy=NULL; + while ( (msg = curl_multi_info_read(g->multi, &msgs_left)) ) + { + if ( msg->msg == CURLMSG_DONE ) + { + easy=msg->easy_handle; + res=msg->data.result; + } + + if ( easy ) + { + curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn); + curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url); + fprintf(MSG_OUT, "DONE: %s => (%d) %s\n", eff_url, res, conn->error); + curl_multi_remove_handle(g->multi, easy); + free(conn->url); + curl_easy_cleanup(easy); + free(conn); + } + } + } while ( easy ); + } + g->prev_running = g->still_running; +} + + +/* Called by libevent when we get action on a multi socket */ +static void event_cb(EV_P_ struct ev_io *w, int revents) +{ + DPRINT("%s w %p revents %i\n", __PRETTY_FUNCTION__, w, revents); + GlobalInfo *g = (GlobalInfo*) w->data; + CURLMcode rc; + + int action = (revents&EV_READ?CURL_POLL_IN:0)| + (revents&EV_WRITE?CURL_POLL_OUT:0); + do + { + rc = curl_multi_socket_action(g->multi, w->fd, action, &g->still_running); + } while ( rc == CURLM_CALL_MULTI_PERFORM ); + mcode_or_die("event_cb: curl_multi_socket", rc); + check_run_count(g); + if ( g->still_running <= 0 ) + { + fprintf(MSG_OUT, "last transfer done, kill timeout\n"); + ev_timer_stop(g->loop, &g->timer_event); + } +} + +/* Called by libevent when our timeout expires */ +static void timer_cb(EV_P_ struct ev_timer *w, int revents) +{ + DPRINT("%s w %p revents %i\n", __PRETTY_FUNCTION__, w, revents); + + GlobalInfo *g = (GlobalInfo *)w->data; + CURLMcode rc; + + do + { + rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0, &g->still_running); + } while ( rc == CURLM_CALL_MULTI_PERFORM ); + mcode_or_die("timer_cb: curl_multi_socket", rc); + check_run_count(g); +} + +/* Clean up the SockInfo structure */ +static void remsock(SockInfo *f, GlobalInfo *g) +{ + printf("%s \n", __PRETTY_FUNCTION__); + if ( f ) + { + if ( f->evset ) + ev_io_stop(g->loop, &f->ev); + free(f); + } +} + + + +/* Assign information to a SockInfo structure */ +static void setsock(SockInfo*f, curl_socket_t s, CURL*e, int act, GlobalInfo*g) +{ + printf("%s \n", __PRETTY_FUNCTION__); + + int kind = (act&CURL_POLL_IN?EV_READ:0)|(act&CURL_POLL_OUT?EV_WRITE:0); + + f->sockfd = s; + f->action = act; + f->easy = e; + if ( f->evset ) + ev_io_stop(g->loop, &f->ev); + ev_io_init(&f->ev, event_cb, f->sockfd, kind); + f->ev.data = g; + f->evset=1; + ev_io_start(g->loop, &f->ev); +} + + + +/* Initialize a new SockInfo structure */ +static void addsock(curl_socket_t s, CURL *easy, int action, GlobalInfo *g) +{ + SockInfo *fdp = calloc(sizeof(SockInfo), 1); + + fdp->global = g; + setsock(fdp, s, easy, action, 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) +{ + DPRINT("%s e %p s %i what %i cbp %p sockp %p\n", + __PRETTY_FUNCTION__, e, s, what, cbp, sockp); + + GlobalInfo *g = (GlobalInfo*) cbp; + SockInfo *fdp = (SockInfo*) sockp; + const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE"}; + + fprintf(MSG_OUT, + "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); + if ( what == CURL_POLL_REMOVE ) + { + fprintf(MSG_OUT, "\n"); + remsock(fdp, g); + } else + { + if ( !fdp ) + { + fprintf(MSG_OUT, "Adding data: %s\n", whatstr[what]); + addsock(s, e, what, g); + } else + { + fprintf(MSG_OUT, + "Changing action from %s to %s\n", + whatstr[fdp->action], whatstr[what]); + setsock(fdp, s, e, what, g); + } + } + return 0; +} + + +/* CURLOPT_WRITEFUNCTION */ +static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data) +{ + size_t realsize = size * nmemb; + ConnInfo *conn = (ConnInfo*) data; + (void)ptr; + (void)conn; + return realsize; +} + + +/* CURLOPT_PROGRESSFUNCTION */ +static int prog_cb (void *p, double dltotal, double dlnow, double ult, + double uln) +{ + ConnInfo *conn = (ConnInfo *)p; + (void)ult; + (void)uln; + + fprintf(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 ) +{ + ConnInfo *conn; + CURLMcode rc; + + conn = calloc(1, sizeof(ConnInfo)); + memset(conn, 0, sizeof(ConnInfo)); + conn->error[0]='\0'; + + conn->easy = curl_easy_init(); + if ( !conn->easy ) + { + fprintf(MSG_OUT, "curl_easy_init() failed, exiting!\n"); + exit(2); + } + conn->global = 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_VERBOSE, 1L); + curl_easy_setopt(conn->easy, CURLOPT_ERRORBUFFER, conn->error); + curl_easy_setopt(conn->easy, CURLOPT_PRIVATE, conn); + curl_easy_setopt(conn->easy, CURLOPT_NOPROGRESS, 0L); + curl_easy_setopt(conn->easy, CURLOPT_PROGRESSFUNCTION, prog_cb); + curl_easy_setopt(conn->easy, CURLOPT_PROGRESSDATA, conn); + curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_TIME, 3L); + curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_LIMIT, 10L); + + fprintf(MSG_OUT, + "Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url); + rc =curl_multi_add_handle(g->multi, conn->easy); + mcode_or_die("new_conn: curl_multi_add_handle", rc); + + mcode_or_die("new_conn: curl_multi_socket_all", rc); + check_run_count(g); +} + +/* This gets called whenever data is received from the fifo */ +static void fifo_cb(EV_P_ struct ev_io *w, int revents) +{ + char s[1024]; + long int rv=0; + int n=0; + GlobalInfo *g = (GlobalInfo *)w->data; + + 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 ); +} + +/* Create a named pipe and tell libevent to monitor it */ +static int init_fifo (GlobalInfo *g) +{ + struct stat st; + static const char *fifo = "hiper.fifo"; + int sockfd; + + fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo); + 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); + } + sockfd = open(fifo, O_RDWR | O_NONBLOCK, 0); + if ( sockfd == -1 ) + { + perror("open"); + exit (1); + } + g->input = fdopen(sockfd, "r"); + + 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); +} + +int main(int argc, char **argv) +{ + GlobalInfo g; + CURLMcode rc; + (void)argc; + (void)argv; + + memset(&g, 0, sizeof(GlobalInfo)); + g.loop = ev_default_loop(0); + + init_fifo(&g); + g.multi = curl_multi_init(); + + ev_timer_init(&g.timer_event, timer_cb, 0., 0.); + g.timer_event.data = &g; + g.fifo_event.data = &g; + curl_multi_setopt(g.multi, CURLMOPT_SOCKETFUNCTION, sock_cb); + curl_multi_setopt(g.multi, CURLMOPT_SOCKETDATA, &g); + curl_multi_setopt(g.multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb); + curl_multi_setopt(g.multi, CURLMOPT_TIMERDATA, &g); + do + { + rc = curl_multi_socket_all(g.multi, &g.still_running); + } while ( CURLM_CALL_MULTI_PERFORM == rc ); + + ev_loop(g.loop, 0); + curl_multi_cleanup(g.multi); + return 0; +} -- cgit v1.2.1 From 79a91b8168056002705c9f0aebcb1a6b323a1b4c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Mon, 12 Jan 2009 21:29:23 +0000 Subject: make this example not only replace an internal header but also add a totally new and non-standard one --- docs/examples/httpcustomheader.c | 1 + 1 file changed, 1 insertion(+) (limited to 'docs/examples') diff --git a/docs/examples/httpcustomheader.c b/docs/examples/httpcustomheader.c index 13e62e657..1551fafe2 100644 --- a/docs/examples/httpcustomheader.c +++ b/docs/examples/httpcustomheader.c @@ -21,6 +21,7 @@ int main(void) struct curl_slist *chunk = NULL; chunk = curl_slist_append(chunk, "Accept: moo"); + chunk = curl_slist_append(chunk, "Another: yes"); /* request with the built-in Accept: */ curl_easy_setopt(curl, CURLOPT_URL, "localhost"); -- cgit v1.2.1 From f11969015a0932e9ec3f10d5439fa855eab0e4ce Mon Sep 17 00:00:00 2001 From: Gisle Vanem <gvanem@broadpark.no> Date: Sat, 18 Apr 2009 09:59:42 +0000 Subject: Avoid compiler warning about unused argument. --- docs/examples/htmltitle.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'docs/examples') diff --git a/docs/examples/htmltitle.cc b/docs/examples/htmltitle.cc index de7ff0339..b02895f4c 100644 --- a/docs/examples/htmltitle.cc +++ b/docs/examples/htmltitle.cc @@ -142,6 +142,7 @@ static void StartElement(void *voidContext, context->title = ""; context->addTitle = true; } + (void) attributes; } // -- cgit v1.2.1 From 0427b783e2ae554a118057d23c65f29041b7cb6e Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Mon, 18 May 2009 12:33:51 +0000 Subject: Add empty line, to force CVS to update the $Id date string format --- docs/examples/getinfo.c | 1 + docs/examples/http-post.c | 1 + 2 files changed, 2 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/getinfo.c b/docs/examples/getinfo.c index eb0cae31f..7c462b205 100644 --- a/docs/examples/getinfo.c +++ b/docs/examples/getinfo.c @@ -40,3 +40,4 @@ int main(void) } return 0; } + diff --git a/docs/examples/http-post.c b/docs/examples/http-post.c index 30ca3536b..bde06c6ea 100644 --- a/docs/examples/http-post.c +++ b/docs/examples/http-post.c @@ -33,3 +33,4 @@ int main(void) } return 0; } + -- cgit v1.2.1 From 4677778f854e2f8bfef70069d46c4c694cff859e Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Tue, 19 May 2009 12:12:22 +0000 Subject: Remove empty line used to force CVS to update the $Id date string format --- docs/examples/getinfo.c | 1 - docs/examples/http-post.c | 1 - 2 files changed, 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/getinfo.c b/docs/examples/getinfo.c index 7c462b205..eb0cae31f 100644 --- a/docs/examples/getinfo.c +++ b/docs/examples/getinfo.c @@ -40,4 +40,3 @@ int main(void) } return 0; } - diff --git a/docs/examples/http-post.c b/docs/examples/http-post.c index bde06c6ea..30ca3536b 100644 --- a/docs/examples/http-post.c +++ b/docs/examples/http-post.c @@ -33,4 +33,3 @@ int main(void) } return 0; } - -- cgit v1.2.1 From 6582895b5146149aab7c619cbcb0ea292cfe12e6 Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Fri, 5 Jun 2009 18:40:40 +0000 Subject: docs/example patches for VMS --- docs/examples/anyauthput.c | 4 +++- docs/examples/debug.c | 5 +++-- docs/examples/ftpupload.c | 2 +- docs/examples/multi-debugcallback.c | 7 ++++--- 4 files changed, 11 insertions(+), 7 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index 11c9d3c77..dd5b5ddf7 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -13,7 +13,9 @@ #ifdef WIN32 # include <io.h> #else -# include <stdint.h> +# ifndef __VMS +# include <stdint.h> +# endif # include <unistd.h> #endif #include <sys/types.h> diff --git a/docs/examples/debug.c b/docs/examples/debug.c index 543a565eb..30ce820cc 100644 --- a/docs/examples/debug.c +++ b/docs/examples/debug.c @@ -29,11 +29,12 @@ void dump(const char *text, /* without the hex output, we can fit more on screen */ width = 0x40; - fprintf(stream, "%s, %zd bytes (0x%zx)\n", text, size, size); + fprintf(stream, "%s, %010.10ld bytes (0x%08.8lx)\n", + text, (long)size, (long)size); for(i=0; i<size; i+= width) { - fprintf(stream, "%04zx: ", i); + fprintf(stream, "%04.4lx: ", (long)i); if(!nohex) { /* hex not disabled, show it */ diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index 76fc92ebb..a72792479 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -65,7 +65,7 @@ int main(int argc, char **argv) printf("Couldnt open '%s': %s\n", LOCAL_FILE, strerror(errno)); return 1; } - printf("Local file size: %ld bytes.\n", file_info.st_size); + printf("Local file size: %ld bytes.\n", (long)file_info.st_size); /* get a FILE * of the same file */ hd_src = fopen(LOCAL_FILE, "rb"); diff --git a/docs/examples/multi-debugcallback.c b/docs/examples/multi-debugcallback.c index 6a7403a8a..22d26c774 100644 --- a/docs/examples/multi-debugcallback.c +++ b/docs/examples/multi-debugcallback.c @@ -38,11 +38,12 @@ void dump(const char *text, /* without the hex output, we can fit more on screen */ width = 0x40; - fprintf(stream, "%s, %zd bytes (0x%zx)\n", text, size, size); + fprintf(stream, "%s, %010.10ld bytes (0x%08.8lx)\n", + text, (long)size, (long)size); for(i=0; i<size; i+= width) { - fprintf(stream, "%04zx: ", i); + fprintf(stream, "%04.4lx: ", (long)i); if(!nohex) { /* hex not disabled, show it */ @@ -74,7 +75,7 @@ void dump(const char *text, static int my_trace(CURL *handle, curl_infotype type, - char *data, size_t size, + unsigned char *data, size_t size, void *userp) { const char *text; -- cgit v1.2.1 From 420bfbcf40996644988c02b8a88e6e72d076df4e Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Mon, 8 Jun 2009 15:09:47 +0000 Subject: Use curl_off_t and CURL_FORMAT_CURL_OFF_T for file size. --- docs/examples/ftpupload.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index a72792479..3982cde62 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -55,6 +55,7 @@ int main(int argc, char **argv) CURLcode res; FILE *hd_src; struct stat file_info; + curl_off_t fsize; struct curl_slist *headerlist=NULL; static const char buf_1 [] = "RNFR " UPLOAD_FILE_AS; @@ -65,7 +66,9 @@ int main(int argc, char **argv) printf("Couldnt open '%s': %s\n", LOCAL_FILE, strerror(errno)); return 1; } - printf("Local file size: %ld bytes.\n", (long)file_info.st_size); + fsize = (curl_off_t)file_info.st_size; + + printf("Local file size: %" CURL_FORMAT_CURL_OFF_T " bytes.\n", fsize); /* get a FILE * of the same file */ hd_src = fopen(LOCAL_FILE, "rb"); @@ -100,7 +103,7 @@ int main(int argc, char **argv) curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must make sure that to pass in a type 'long' argument. */ curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, - (curl_off_t)file_info.st_size); + (curl_off_t)fsize); /* Now run off and do what you've been told! */ res = curl_easy_perform(curl); -- cgit v1.2.1 From 5d502eb90c674dcba8e169550174b8439c5061da Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Wed, 10 Jun 2009 12:59:59 +0000 Subject: VMS adjustment --- docs/examples/anyauthput.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index dd5b5ddf7..c96f3c180 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -13,7 +13,9 @@ #ifdef WIN32 # include <io.h> #else -# ifndef __VMS +# ifdef __VMS + typedef int intptr_t; +# else # include <stdint.h> # endif # include <unistd.h> -- cgit v1.2.1 From 9539d3229811abda1287e244d65b836f6ec16ad1 Mon Sep 17 00:00:00 2001 From: Gunter Knauf <gk@gknw.de> Date: Mon, 31 Aug 2009 02:06:19 +0000 Subject: added simple chkspeed sample. --- docs/examples/chkspeed.c | 163 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 docs/examples/chkspeed.c (limited to 'docs/examples') diff --git a/docs/examples/chkspeed.c b/docs/examples/chkspeed.c new file mode 100644 index 000000000..50bf9c099 --- /dev/null +++ b/docs/examples/chkspeed.c @@ -0,0 +1,163 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * 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 + * amount of downloaded bytes, the time used for the whole download, and + * the average download speed. + * On Linux you can create the download test files with: + * dd if=/dev/urandom of=file_1M.bin bs=1M count=1 + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +#include <curl/curl.h> +#include <curl/types.h> +#include <curl/easy.h> + +#define URL_BASE "http://speedtest.your.domain/" +#define URL_1M URL_BASE "file_1M.bin" +#define URL_2M URL_BASE "file_2M.bin" +#define URL_5M URL_BASE "file_5M.bin" +#define URL_10M URL_BASE "file_10M.bin" +#define URL_20M URL_BASE "file_20M.bin" +#define URL_50M URL_BASE "file_50M.bin" +#define URL_100M URL_BASE "file_100M.bin" + +#define CHKSPEED_VERSION "1.0" + +static size_t WriteCallback(void *ptr, size_t size, size_t nmemb, void *data) +{ + /* we are not interested in the downloaded bytes itself, + so we only return the size we would have saved ... */ + return (size_t)(size * nmemb); +} + +int main(int argc, char *argv[]) +{ + CURL *curl_handle; + CURLcode res; + int prtsep = 0, prttime = 0; + char *url = URL_1M; + char *appname = argv[0]; + + if (argc > 1) { + /* parse input parameters */ + 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) { + fprintf(stderr, "\r%s %s - %s\n", + appname, CHKSPEED_VERSION, curl_version()); + exit(1); + } else if (strncasecmp(*argv, "-X", 2) == 0) { + prtsep = 1; + } else if (strncasecmp(*argv, "-T", 2) == 0) { + prttime = 1; + } else if (strncasecmp(*argv, "-M=", 3) == 0) { + int m = atoi(*argv + 3); + 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); + } + } else { + fprintf(stderr, "\r%s: invalid or unknown option %s\n", + appname, *argv); + exit(1); + } + } else { + url = *argv; + } + } + } + + /* print separator line */ + if (prtsep) { + printf("-------------------------------------------------\n"); + } + /* print localtime */ + if (prttime) { + time_t t = time(NULL); + printf("Localtime: %s", ctime(&t)); + } + + /* init libcurl */ + curl_global_init(CURL_GLOBAL_ALL); + + /* init the curl session */ + curl_handle = curl_easy_init(); + + /* specify URL to get */ + curl_easy_setopt(curl_handle, CURLOPT_URL, url); + + /* send all data to this function */ + curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteCallback); + + /* some servers don't like requests that are made without a user-agent + field, so we provide one */ + curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, + "libcurl-speedchecker/" CHKSPEED_VERSION); + + /* get it! */ + res = curl_easy_perform(curl_handle); + + if(CURLE_OK == res) { + double val; + + /* check for bytes downloaded */ + res = curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD, &val); + if((CURLE_OK == res) && val) + printf("Data downloaded: %0.0f bytes.\n", val); + + /* check for total download time */ + res = curl_easy_getinfo(curl_handle, CURLINFO_TOTAL_TIME, &val); + if((CURLE_OK == res) && val) + printf("Total download time: %0.3f sec.\n", val); + + /* check for average download speed */ + res = curl_easy_getinfo(curl_handle, CURLINFO_SPEED_DOWNLOAD, &val); + if((CURLE_OK == res) && val) + printf("Average download speed: %0.3f kbyte/sec.\n", val / 1024); + + } else { + printf("Errror while fetching '%s' : %s\n", url, curl_easy_strerror(res)); + } + + /* cleanup curl stuff */ + curl_easy_cleanup(curl_handle); + + /* we're done with libcurl, so clean it up */ + curl_global_cleanup(); + + return 0; +} -- cgit v1.2.1 From cf910f3097f90bfaba27de1706d466fdf3afdd9e Mon Sep 17 00:00:00 2001 From: Gunter Knauf <gk@gknw.de> Date: Thu, 3 Sep 2009 17:53:21 +0000 Subject: updated MingW32 makefile for recent external libs. --- docs/examples/Makefile.m32 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 5107c04fe..1096e3f68 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -19,11 +19,11 @@ ZLIB_PATH = ../../zlib-1.2.3 endif # Edit the path below to point to the base of your OpenSSL package. ifndef OPENSSL_PATH -OPENSSL_PATH = ../../openssl-0.9.8g +OPENSSL_PATH = ../../openssl-0.9.8k endif # Edit the path below to point to the base of your LibSSH2 package. ifndef LIBSSH2_PATH -LIBSSH2_PATH = ../../libssh2-0.18 +LIBSSH2_PATH = ../../libssh2-1.2 endif # Edit the path below to point to the base of your Novell LDAP NDK. ifndef LDAP_SDK -- cgit v1.2.1 From d0552269498456199cab92f319d96ff0a7b72314 Mon Sep 17 00:00:00 2001 From: Gunter Knauf <gk@gknw.de> Date: Thu, 3 Sep 2009 17:54:02 +0000 Subject: added chkspeed to samples. --- docs/examples/Makefile.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 14ba74e8c..4ac1878f9 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -5,7 +5,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface \ https multi-app multi-debugcallback multi-double \ multi-post multi-single persistant post-callback \ postit2 sepheaders simple simplepost simplessl \ - sendrecv httpcustomheader certinfo + sendrecv httpcustomheader certinfo chkspeed # These examples require external dependencies that may not be commonly # available on POSIX systems, so don't bother attempting to compile them here. -- cgit v1.2.1 From 7df26a5415bc2f3f93d9537a99a76079f73688f6 Mon Sep 17 00:00:00 2001 From: Gunter Knauf <gk@gknw.de> Date: Sat, 5 Sep 2009 15:23:37 +0000 Subject: added ftpgetinfo sample since users asked frequently for such a sample. --- docs/examples/ftpgetinfo.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 docs/examples/ftpgetinfo.c (limited to 'docs/examples') diff --git a/docs/examples/ftpgetinfo.c b/docs/examples/ftpgetinfo.c new file mode 100644 index 000000000..a0af09bb3 --- /dev/null +++ b/docs/examples/ftpgetinfo.c @@ -0,0 +1,77 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include <stdio.h> +#include <string.h> + +#include <curl/curl.h> +#include <curl/types.h> +#include <curl/easy.h> + +/* + * This is an example showing how to check a single file's size and mtime + * from an FTP server. + */ + +static size_t throw_away(void *ptr, size_t size, size_t nmemb, void *data) +{ + /* we are not interested in the headers itself, + so we only return the size we would have saved ... */ + return (size_t)(size * nmemb); +} + +int main(void) +{ + /* Check for binutils 2.19.1 from ftp.gnu.org's FTP site. */ + char ftpurl[] = "ftp://ftp.gnu.org/gnu/binutils/binutils-2.19.1.tar.bz2"; + CURL *curl; + CURLcode res; + const time_t filetime; + const double filesize; + const char *filename = strrchr(ftpurl, '/') + 1; + + curl_global_init(CURL_GLOBAL_DEFAULT); + + curl = curl_easy_init(); + if(curl) { + curl_easy_setopt(curl, CURLOPT_URL, ftpurl); + /* No download if the file */ + curl_easy_setopt(curl, CURLOPT_NOBODY, 1L); + /* Ask for filetime */ + curl_easy_setopt(curl, CURLOPT_FILETIME, 1L); + /* No header output: TODO 14.1 http-style HEAD output for ftp */ + curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, throw_away); + curl_easy_setopt(curl, CURLOPT_HEADER, 0L); + /* Switch on full protocol/debug output */ + /* curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); */ + + res = curl_easy_perform(curl); + + if(CURLE_OK == res) { + /* http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html */ + res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime); + if((CURLE_OK == res) && filetime) + printf("filetime %s: %s", filename, ctime(&filetime)); + res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &filesize); + if((CURLE_OK == res) && filesize) + printf("filesize %s: %0.0f bytes\n", filename, filesize); + } else { + /* we failed */ + fprintf(stderr, "curl told us %d\n", res); + } + + /* always cleanup */ + curl_easy_cleanup(curl); + } + + curl_global_cleanup(); + + return 0; +} -- cgit v1.2.1 From aaed838872779eaa08f92acea9c848bd522bb14c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Sat, 5 Sep 2009 17:54:30 +0000 Subject: add ftpgetinfo --- docs/examples/Makefile.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 4ac1878f9..c104368e9 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -5,7 +5,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface \ https multi-app multi-debugcallback multi-double \ multi-post multi-single persistant post-callback \ postit2 sepheaders simple simplepost simplessl \ - sendrecv httpcustomheader certinfo chkspeed + sendrecv httpcustomheader certinfo chkspeed ftpgetinfo # These examples require external dependencies that may not be commonly # available on POSIX systems, so don't bother attempting to compile them here. -- cgit v1.2.1 From 5389ac0ddfca51599d3db67734fe9fe694868fbc Mon Sep 17 00:00:00 2001 From: Gunter Knauf <gk@gknw.de> Date: Thu, 10 Sep 2009 15:00:21 +0000 Subject: fixed spelling. --- docs/examples/chkspeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/chkspeed.c b/docs/examples/chkspeed.c index 50bf9c099..031eec893 100644 --- a/docs/examples/chkspeed.c +++ b/docs/examples/chkspeed.c @@ -150,7 +150,7 @@ int main(int argc, char *argv[]) printf("Average download speed: %0.3f kbyte/sec.\n", val / 1024); } else { - printf("Errror while fetching '%s' : %s\n", url, curl_easy_strerror(res)); + printf("Error while fetching '%s' : %s\n", url, curl_easy_strerror(res)); } /* cleanup curl stuff */ -- cgit v1.2.1 From 945feafe25b97bdf0d91f49c5452608d66f2e047 Mon Sep 17 00:00:00 2001 From: Gunter Knauf <gk@gknw.de> Date: Thu, 10 Sep 2009 18:36:06 +0000 Subject: use stderr for error output. --- docs/examples/chkspeed.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/chkspeed.c b/docs/examples/chkspeed.c index 031eec893..7d2a3da61 100644 --- a/docs/examples/chkspeed.c +++ b/docs/examples/chkspeed.c @@ -150,7 +150,8 @@ int main(int argc, char *argv[]) printf("Average download speed: %0.3f kbyte/sec.\n", val / 1024); } else { - printf("Error while fetching '%s' : %s\n", url, curl_easy_strerror(res)); + fprintf(stderr, "Error while fetching '%s' : %s\n", + url, curl_easy_strerror(res)); } /* cleanup curl stuff */ -- cgit v1.2.1 From f39380b1ac3d32c754d891262fd177531a74055f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Mon, 2 Nov 2009 21:20:45 +0000 Subject: strerror() => curl_easy_strerror() --- docs/examples/sendrecv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/sendrecv.c b/docs/examples/sendrecv.c index 45bae652a..a6853c326 100644 --- a/docs/examples/sendrecv.c +++ b/docs/examples/sendrecv.c @@ -72,7 +72,7 @@ int main(void) if(CURLE_OK != res) { - printf("Error: %s\n", strerror(res)); + printf("Error: %s\n", curl_easy_strerror(res)); return 1; } @@ -90,7 +90,7 @@ int main(void) if(CURLE_OK != res) { - printf("Error: %s\n", strerror(res)); + printf("Error: %s\n", curl_easy_strerror(res)); return 1; } puts("Reading response."); -- cgit v1.2.1 From 55e68ba3338b02d9a52dfe6343054e61a944a895 Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Thu, 5 Nov 2009 15:04:03 +0000 Subject: I removed leading 'curl' path on the 'curlbuild.h' include statement in curl.h, adjusting auto-makefiles include path, to enhance portability to OS's without an orthogonal directory tree structure such as OS/400. --- docs/examples/Makefile.am | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 886e8ada6..2e4121d86 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -12,10 +12,12 @@ EXTRA_DIST = README Makefile.example Makefile.inc Makefile.m32 \ # being currently built and tested are searched before the library which # might possibly already be installed in the system. # -# $(top_builddir)/include is for libcurl's generated curl/curlbuild.h file +# $(top_builddir)/include/curl for generated curlbuild.h included from curl.h +# $(top_builddir)/include for generated curlbuild.h included from lib/setup.h # $(top_srcdir)/include is for libcurl's external include files -INCLUDES = -I$(top_builddir)/include \ +INCLUDES = -I$(top_builddir)/include/curl \ + -I$(top_builddir)/include \ -I$(top_srcdir)/include LIBDIR = $(top_builddir)/lib -- cgit v1.2.1 From 2e830066031e1aa1e6bc4bef8d02dd30bbde205a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Mon, 4 Jan 2010 18:43:29 +0000 Subject: use the modern name for this option --- docs/examples/curlx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 09d27cc97..9b1c29158 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -453,7 +453,7 @@ int main(int argc, char **argv) { { FILE *outfp; BIO_get_fp(out,&outfp); - curl_easy_setopt(p.curl, CURLOPT_FILE,outfp); + curl_easy_setopt(p.curl, CURLOPT_WRITEDATA, outfp); } res = curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun) ; -- cgit v1.2.1 From a74e885befcded7dd958563badaaf8a5f29587aa Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Thu, 21 Jan 2010 09:53:30 +0000 Subject: Yun Fu pointed out a flaw in the loop that checks handles, and I indented the code more curl-style --- docs/examples/multi-app.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index a8a92ab33..fa3349822 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -105,20 +105,23 @@ int main(int argc, char **argv) /* See how the transfers went */ 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; (!found && (idx<HANDLECOUNT)); idx++) found = (msg->easy_handle == handles[idx]); - - switch (idx) { - case HTTP_HANDLE: - printf("HTTP transfer completed with status %d\n", msg->data.result); - break; - case FTP_HANDLE: - printf("FTP transfer completed with status %d\n", msg->data.result); - break; - } + int idx, found = 0; + + /* Find out which handle this message is about */ + for (idx=0; idx<HANDLECOUNT; idx++) { + found = (msg->easy_handle == handles[idx]); + if(found) + break; + } + + switch (idx) { + case HTTP_HANDLE: + printf("HTTP transfer completed with status %d\n", msg->data.result); + break; + case FTP_HANDLE: + printf("FTP transfer completed with status %d\n", msg->data.result); + break; + } } } -- cgit v1.2.1 From a07bc79117971b96ebf3188c0a34a73ee0a3609b Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Sun, 14 Feb 2010 19:40:18 +0000 Subject: removed trailing whitespace --- docs/examples/Makefile.example | 8 ++++---- docs/examples/chkspeed.c | 4 ++-- docs/examples/cookie_interface.c | 6 +++--- docs/examples/curlx.c | 2 +- docs/examples/ftpgetinfo.c | 4 ++-- docs/examples/multi-double.c | 8 ++++---- docs/examples/multi-post.c | 2 +- docs/examples/sampleconv.c | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.example b/docs/examples/Makefile.example index 7afe04cf6..5d9b7c9ca 100644 --- a/docs/examples/Makefile.example +++ b/docs/examples/Makefile.example @@ -1,8 +1,8 @@ ############################################################################# -# _ _ ____ _ -# Project ___| | | | _ \| | -# / __| | | | |_) | | -# | (__| |_| | _ <| |___ +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # # $Id$ diff --git a/docs/examples/chkspeed.c b/docs/examples/chkspeed.c index 7d2a3da61..9eacd65f9 100644 --- a/docs/examples/chkspeed.c +++ b/docs/examples/chkspeed.c @@ -40,7 +40,7 @@ static size_t WriteCallback(void *ptr, size_t size, size_t nmemb, void *data) { /* we are not interested in the downloaded bytes itself, - so we only return the size we would have saved ... */ + so we only return the size we would have saved ... */ return (size_t)(size * nmemb); } @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) for (argc--, argv++; *argv; argc--, argv++) { if (strncasecmp(*argv, "-", 1) == 0) { if (strncasecmp(*argv, "-H", 2) == 0) { - fprintf(stderr, + fprintf(stderr, "\rUsage: %s [-m=1|2|5|10|20|50|100] [-t] [-x] [url]\n", appname); exit(1); diff --git a/docs/examples/cookie_interface.c b/docs/examples/cookie_interface.c index 51b32428d..27bfa3932 100644 --- a/docs/examples/cookie_interface.c +++ b/docs/examples/cookie_interface.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * This example shows usage of simple cookie interface. + * This example shows usage of simple cookie interface. */ #include <stdio.h> @@ -80,7 +80,7 @@ main(void) 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)); - return 1; + return 1; } /* HTTP-header style cookie */ @@ -90,7 +90,7 @@ main(void) 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)); - return 1; + return 1; } print_cookies(curl); diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 9b1c29158..62bdfe405 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -115,7 +115,7 @@ static const char *curlx_usage[]={ */ -/* +/* * We use this ZERO_NULL to avoid picky compiler warnings, * when assigning a NULL pointer to a function pointer var. */ diff --git a/docs/examples/ftpgetinfo.c b/docs/examples/ftpgetinfo.c index a0af09bb3..336cc79dd 100644 --- a/docs/examples/ftpgetinfo.c +++ b/docs/examples/ftpgetinfo.c @@ -23,7 +23,7 @@ static size_t throw_away(void *ptr, size_t size, size_t nmemb, void *data) { /* we are not interested in the headers itself, - so we only return the size we would have saved ... */ + so we only return the size we would have saved ... */ return (size_t)(size * nmemb); } @@ -45,7 +45,7 @@ int main(void) /* No download if the file */ curl_easy_setopt(curl, CURLOPT_NOBODY, 1L); /* Ask for filetime */ - curl_easy_setopt(curl, CURLOPT_FILETIME, 1L); + curl_easy_setopt(curl, CURLOPT_FILETIME, 1L); /* No header output: TODO 14.1 http-style HEAD output for ftp */ curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, throw_away); curl_easy_setopt(curl, CURLOPT_HEADER, 0L); diff --git a/docs/examples/multi-double.c b/docs/examples/multi-double.c index 0a4cde855..2fb6973bb 100644 --- a/docs/examples/multi-double.c +++ b/docs/examples/multi-double.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index 18973a94a..91669aa51 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -28,7 +28,7 @@ int main(int argc, char *argv[]) struct curl_slist *headerlist=NULL; static const char buf[] = "Expect:"; - /* Fill in the file upload field. This makes libcurl load data from + /* Fill in the file upload field. This makes libcurl load data from the given file name when curl_easy_perform() is called. */ curl_formadd(&formpost, &lastptr, diff --git a/docs/examples/sampleconv.c b/docs/examples/sampleconv.c index 89cfb933e..8ed2b3b16 100644 --- a/docs/examples/sampleconv.c +++ b/docs/examples/sampleconv.c @@ -9,7 +9,7 @@ */ /* 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 + 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 -- cgit v1.2.1 From 46b112bcd439f4413925a7300d66a3e6f148765e Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Tue, 16 Feb 2010 13:32:45 +0000 Subject: replaced tabs with spaces --- docs/examples/anyauthput.c | 2 +- docs/examples/ftpuploadresume.c | 152 ++++++++++++++++++++-------------------- 2 files changed, 77 insertions(+), 77 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index c96f3c180..d0c65cf1b 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -136,7 +136,7 @@ int main(int argc, char **argv) /* and give the size of the upload, this supports large file sizes on systems that have general support for it */ curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, - (curl_off_t)file_info.st_size); + (curl_off_t)file_info.st_size); /* tell libcurl we can use "any" auth, which lets the lib pick one, but it also costs one extra round-trip and possibly sending of all the PUT diff --git a/docs/examples/ftpuploadresume.c b/docs/examples/ftpuploadresume.c index 362711c33..d20c4a9c6 100644 --- a/docs/examples/ftpuploadresume.c +++ b/docs/examples/ftpuploadresume.c @@ -34,126 +34,126 @@ int __cdecl _snscanf(const char * input, size_t length, const char * format, ... /* parse headers for Content-Length */ size_t getcontentlengthfunc(void *ptr, size_t size, size_t nmemb, void *stream) { - int r; - long len = 0; + int r; + long len = 0; - /* _snscanf() is Win32 specific */ - r = _snscanf(ptr, size * nmemb, "Content-Length: %ld\n", &len); + /* _snscanf() is Win32 specific */ + r = _snscanf(ptr, size * nmemb, "Content-Length: %ld\n", &len); - if (r) /* Microsoft: we don't read the specs */ - *((long *) stream) = len; + if (r) /* Microsoft: we don't read the specs */ + *((long *) stream) = len; - return size * nmemb; + return size * nmemb; } /* discard downloaded data */ size_t discardfunc(void *ptr, size_t size, size_t nmemb, void *stream) { - return size * nmemb; + return size * nmemb; } /* read data to upload */ size_t readfunc(void *ptr, size_t size, size_t nmemb, void *stream) { - FILE *f = stream; - size_t n; + FILE *f = stream; + size_t n; - if (ferror(f)) - return CURL_READFUNC_ABORT; + if (ferror(f)) + return CURL_READFUNC_ABORT; - n = fread(ptr, size, nmemb, f) * size; + n = fread(ptr, size, nmemb, f) * size; - return n; + return n; } int upload(CURL *curlhandle, const char * remotepath, const char * localpath, long timeout, long tries) { - FILE *f; - long uploaded_len = 0; - CURLcode r = CURLE_GOT_NOTHING; - int c; + FILE *f; + long uploaded_len = 0; + CURLcode r = CURLE_GOT_NOTHING; + int c; - f = fopen(localpath, "rb"); - if (f == NULL) { - perror(NULL); - return 0; - } + f = fopen(localpath, "rb"); + if (f == NULL) { + perror(NULL); + return 0; + } - curl_easy_setopt(curlhandle, CURLOPT_UPLOAD, 1L); + curl_easy_setopt(curlhandle, CURLOPT_UPLOAD, 1L); - curl_easy_setopt(curlhandle, CURLOPT_URL, remotepath); + curl_easy_setopt(curlhandle, CURLOPT_URL, remotepath); - if (timeout) - curl_easy_setopt(curlhandle, CURLOPT_FTP_RESPONSE_TIMEOUT, timeout); + if (timeout) + curl_easy_setopt(curlhandle, CURLOPT_FTP_RESPONSE_TIMEOUT, timeout); - curl_easy_setopt(curlhandle, CURLOPT_HEADERFUNCTION, getcontentlengthfunc); - curl_easy_setopt(curlhandle, CURLOPT_HEADERDATA, &uploaded_len); + curl_easy_setopt(curlhandle, CURLOPT_HEADERFUNCTION, getcontentlengthfunc); + curl_easy_setopt(curlhandle, CURLOPT_HEADERDATA, &uploaded_len); - curl_easy_setopt(curlhandle, CURLOPT_WRITEFUNCTION, discardfunc); + curl_easy_setopt(curlhandle, CURLOPT_WRITEFUNCTION, discardfunc); - curl_easy_setopt(curlhandle, CURLOPT_READFUNCTION, readfunc); - curl_easy_setopt(curlhandle, CURLOPT_READDATA, f); + curl_easy_setopt(curlhandle, CURLOPT_READFUNCTION, readfunc); + curl_easy_setopt(curlhandle, CURLOPT_READDATA, f); - curl_easy_setopt(curlhandle, CURLOPT_FTPPORT, "-"); /* disable passive mode */ - curl_easy_setopt(curlhandle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L); + curl_easy_setopt(curlhandle, CURLOPT_FTPPORT, "-"); /* disable passive mode */ + curl_easy_setopt(curlhandle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L); - curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, 1L); + curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, 1L); - for (c = 0; (r != CURLE_OK) && (c < tries); c++) { - /* are we resuming? */ - if (c) { /* yes */ - /* determine the length of the file already written */ + for (c = 0; (r != CURLE_OK) && (c < tries); c++) { + /* are we resuming? */ + if (c) { /* yes */ + /* determine the length of the file already written */ - /* - * With NOBODY and NOHEADER, libcurl will issue a SIZE - * command, but the only way to retrieve the result is - * to parse the returned Content-Length header. Thus, - * getcontentlengthfunc(). We need discardfunc() above - * because HEADER will dump the headers to stdout - * without it. - */ - curl_easy_setopt(curlhandle, CURLOPT_NOBODY, 1L); - curl_easy_setopt(curlhandle, CURLOPT_HEADER, 1L); + /* + * With NOBODY and NOHEADER, libcurl will issue a SIZE + * command, but the only way to retrieve the result is + * to parse the returned Content-Length header. Thus, + * getcontentlengthfunc(). We need discardfunc() above + * because HEADER will dump the headers to stdout + * without it. + */ + curl_easy_setopt(curlhandle, CURLOPT_NOBODY, 1L); + curl_easy_setopt(curlhandle, CURLOPT_HEADER, 1L); - r = curl_easy_perform(curlhandle); - if (r != CURLE_OK) - continue; + r = curl_easy_perform(curlhandle); + if (r != CURLE_OK) + continue; - curl_easy_setopt(curlhandle, CURLOPT_NOBODY, 0L); - curl_easy_setopt(curlhandle, CURLOPT_HEADER, 0L); + curl_easy_setopt(curlhandle, CURLOPT_NOBODY, 0L); + curl_easy_setopt(curlhandle, CURLOPT_HEADER, 0L); - fseek(f, uploaded_len, SEEK_SET); + fseek(f, uploaded_len, SEEK_SET); - curl_easy_setopt(curlhandle, CURLOPT_APPEND, 1L); - } - else { /* no */ - curl_easy_setopt(curlhandle, CURLOPT_APPEND, 0L); - } + curl_easy_setopt(curlhandle, CURLOPT_APPEND, 1L); + } + else { /* no */ + curl_easy_setopt(curlhandle, CURLOPT_APPEND, 0L); + } - r = curl_easy_perform(curlhandle); - } + r = curl_easy_perform(curlhandle); + } - fclose(f); + fclose(f); - if (r == CURLE_OK) - return 1; - else { - fprintf(stderr, "%s\n", curl_easy_strerror(r)); - return 0; - } + if (r == CURLE_OK) + return 1; + else { + fprintf(stderr, "%s\n", curl_easy_strerror(r)); + return 0; + } } int main(int c, char **argv) { - CURL *curlhandle = NULL; + CURL *curlhandle = NULL; - curl_global_init(CURL_GLOBAL_ALL); - curlhandle = curl_easy_init(); + curl_global_init(CURL_GLOBAL_ALL); + curlhandle = curl_easy_init(); - upload(curlhandle, "ftp://user:pass@host/path/file", "C:\\file", 0, 3); + upload(curlhandle, "ftp://user:pass@host/path/file", "C:\\file", 0, 3); - curl_easy_cleanup(curlhandle); - curl_global_cleanup(); + curl_easy_cleanup(curlhandle); + curl_global_cleanup(); - return 0; + return 0; } -- cgit v1.2.1 From eef316f09933244739e5729cd565a9827868f604 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Fri, 26 Feb 2010 22:58:24 +0000 Subject: =?UTF-8?q?spellchecked=20by=20St=E9phane=20Fillod?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/examples/fopen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index a8a4fe482..e3814e6ab 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -13,7 +13,7 @@ * See the main() function at the bottom that shows an app that retrives from a * specified url using fgets() and fread() and saves as two output files. * - * Coyright (c)2003 Simtec Electronics + * Copyright (c) 2003 Simtec Electronics * * Re-implemented by Vincent Sanders <vince@kyllikki.org> with extensive * reference to original curl example code -- cgit v1.2.1 From 2309b4e330b96bc2e1f8e36b6184015e59544037 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 24 Mar 2010 11:02:54 +0100 Subject: remove the CVSish $Id$ lines --- docs/examples/10-at-a-time.c | 1 - docs/examples/Makefile.am | 1 - docs/examples/Makefile.example | 1 - docs/examples/Makefile.m32 | 1 - docs/examples/anyauthput.c | 1 - docs/examples/cacertinmem.c | 1 - docs/examples/chkspeed.c | 1 - docs/examples/curlgtk.c | 1 - docs/examples/debug.c | 1 - docs/examples/evhiperfifo.c | 1 - docs/examples/fileupload.c | 1 - docs/examples/ftpget.c | 1 - docs/examples/ftpgetinfo.c | 1 - docs/examples/ftpgetresp.c | 1 - docs/examples/ftpupload.c | 1 - docs/examples/ftpuploadresume.c | 1 - docs/examples/getinfo.c | 1 - docs/examples/getinmemory.c | 1 - docs/examples/ghiper.c | 1 - docs/examples/hiperfifo.c | 1 - docs/examples/htmltidy.c | 1 - docs/examples/htmltitle.cc | 1 - docs/examples/http-post.c | 1 - docs/examples/httpcustomheader.c | 1 - docs/examples/httpput.c | 1 - docs/examples/https.c | 1 - docs/examples/makefile.dj | 1 - docs/examples/multi-app.c | 1 - docs/examples/multi-debugcallback.c | 1 - docs/examples/multi-double.c | 1 - docs/examples/multi-post.c | 1 - docs/examples/multi-single.c | 1 - docs/examples/multithread.c | 1 - docs/examples/opensslthreadlock.c | 1 - docs/examples/persistant.c | 1 - docs/examples/post-callback.c | 1 - docs/examples/postit2.c | 1 - docs/examples/sampleconv.c | 1 - docs/examples/sendrecv.c | 1 - docs/examples/sepheaders.c | 1 - docs/examples/simple.c | 1 - docs/examples/simplepost.c | 1 - docs/examples/simplessl.c | 1 - docs/examples/smooth-gtk-thread.c | 1 - docs/examples/synctime.c | 1 - docs/examples/threaded-ssl.c | 1 - 46 files changed, 46 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index 14b6e93af..51326422c 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * Example application source code using the multi interface to download many * files, but with a capped maximum amount of simultaneous transfers. diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 2e4121d86..8d92f7311 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -1,5 +1,4 @@ # -# $Id$ # AUTOMAKE_OPTIONS = foreign nostdinc diff --git a/docs/examples/Makefile.example b/docs/examples/Makefile.example index 5d9b7c9ca..29ca0d7a2 100644 --- a/docs/examples/Makefile.example +++ b/docs/examples/Makefile.example @@ -5,7 +5,6 @@ # | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # -# $Id$ # # What to call the final executable diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 1096e3f68..15750d01f 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -1,5 +1,4 @@ ######################################################################### -# $Id$ # ## Makefile for building curl examples with MingW32 ## and optionally OpenSSL (0.9.8), libssh2 (0.18), zlib (1.2.3) diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index d0c65cf1b..cec9fede5 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/cacertinmem.c b/docs/examples/cacertinmem.c index 78809ae93..fc3c9b110 100644 --- a/docs/examples/cacertinmem.c +++ b/docs/examples/cacertinmem.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * Example using a "in core" PEM certificate to retrieve a https page. * Written by Theo Borm diff --git a/docs/examples/chkspeed.c b/docs/examples/chkspeed.c index 9eacd65f9..c56fe3ccc 100644 --- a/docs/examples/chkspeed.c +++ b/docs/examples/chkspeed.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * 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. diff --git a/docs/examples/curlgtk.c b/docs/examples/curlgtk.c index 2327929fb..2c4428083 100644 --- a/docs/examples/curlgtk.c +++ b/docs/examples/curlgtk.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ /* Copyright (c) 2000 David Odin (aka DindinX) for MandrakeSoft */ /* an attempt to use the curl library in concert with a gtk-threaded application */ diff --git a/docs/examples/debug.c b/docs/examples/debug.c index 30ce820cc..d5bf75028 100644 --- a/docs/examples/debug.c +++ b/docs/examples/debug.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/evhiperfifo.c b/docs/examples/evhiperfifo.c index e77715aae..8695ffabf 100644 --- a/docs/examples/evhiperfifo.c +++ b/docs/examples/evhiperfifo.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * Example application source code using the multi socket interface to * download many files at once. diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c index 6ed523c36..cdec75137 100644 --- a/docs/examples/fileupload.c +++ b/docs/examples/fileupload.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 179fd6129..78727e7ef 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/ftpgetinfo.c b/docs/examples/ftpgetinfo.c index 336cc79dd..f30974bd1 100644 --- a/docs/examples/ftpgetinfo.c +++ b/docs/examples/ftpgetinfo.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index 31c1f424f..8d837f36f 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index 3982cde62..d553850f0 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/ftpuploadresume.c b/docs/examples/ftpuploadresume.c index d20c4a9c6..3dda06781 100644 --- a/docs/examples/ftpuploadresume.c +++ b/docs/examples/ftpuploadresume.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * Upload to FTP, resuming failed transfers * diff --git a/docs/examples/getinfo.c b/docs/examples/getinfo.c index eb0cae31f..a9630191f 100644 --- a/docs/examples/getinfo.c +++ b/docs/examples/getinfo.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index c92482166..5a66a04ca 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * 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. diff --git a/docs/examples/ghiper.c b/docs/examples/ghiper.c index a9b695ea0..4f3913d71 100644 --- a/docs/examples/ghiper.c +++ b/docs/examples/ghiper.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * Example application source code using the multi socket interface to * download many files at once. diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index 4102408ce..f5b422b4a 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * Example application source code using the multi socket interface to * download many files at once. diff --git a/docs/examples/htmltidy.c b/docs/examples/htmltidy.c index cd75401a9..9a46955da 100644 --- a/docs/examples/htmltidy.c +++ b/docs/examples/htmltidy.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * Download a document and use libtidy to parse the HTML. * Written by Jeff Pohlmeyer diff --git a/docs/examples/htmltitle.cc b/docs/examples/htmltitle.cc index b02895f4c..da3354a55 100644 --- a/docs/examples/htmltitle.cc +++ b/docs/examples/htmltitle.cc @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ // Get a web page, parse it with libxml. diff --git a/docs/examples/http-post.c b/docs/examples/http-post.c index 30ca3536b..523177d28 100644 --- a/docs/examples/http-post.c +++ b/docs/examples/http-post.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/httpcustomheader.c b/docs/examples/httpcustomheader.c index 1551fafe2..599b84fe8 100644 --- a/docs/examples/httpcustomheader.c +++ b/docs/examples/httpcustomheader.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index 585dfa2cc..821e95fd8 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/https.c b/docs/examples/https.c index e6b8e89b6..29b50be3b 100644 --- a/docs/examples/https.c +++ b/docs/examples/https.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/makefile.dj b/docs/examples/makefile.dj index 6bf99d82f..8736e6e78 100644 --- a/docs/examples/makefile.dj +++ b/docs/examples/makefile.dj @@ -1,4 +1,3 @@ -# $Id$ # # Adapted for djgpp / Watt-32 / DOS by # Gisle Vanem <giva@bgnett.no> diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index fa3349822..a86dd0efd 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * This is an example application source code using the multi interface. */ diff --git a/docs/examples/multi-debugcallback.c b/docs/examples/multi-debugcallback.c index 22d26c774..b10b47cd1 100644 --- a/docs/examples/multi-debugcallback.c +++ b/docs/examples/multi-debugcallback.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * This is a very simple example using the multi interface and the debug * callback. diff --git a/docs/examples/multi-double.c b/docs/examples/multi-double.c index 2fb6973bb..ef3bf92fc 100644 --- a/docs/examples/multi-double.c +++ b/docs/examples/multi-double.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * This is a very simple example using the multi interface. */ diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index 91669aa51..229e84306 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * This is an example application source code using the multi interface * to do a multipart formpost without "blocking". diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c index b23f3c9d4..3e236f326 100644 --- a/docs/examples/multi-single.c +++ b/docs/examples/multi-single.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * This is a very simple example using the multi interface. */ diff --git a/docs/examples/multithread.c b/docs/examples/multithread.c index 939e9daef..5f59a99d7 100644 --- a/docs/examples/multithread.c +++ b/docs/examples/multithread.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ /* A multi-threaded example that uses pthreads extensively to fetch diff --git a/docs/examples/opensslthreadlock.c b/docs/examples/opensslthreadlock.c index 3ac7124b0..706e90121 100644 --- a/docs/examples/opensslthreadlock.c +++ b/docs/examples/opensslthreadlock.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * 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 diff --git a/docs/examples/persistant.c b/docs/examples/persistant.c index 3d75b9ebe..0e65dd8fb 100644 --- a/docs/examples/persistant.c +++ b/docs/examples/persistant.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index ed89cac2a..1e688a1c8 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * An example source code that issues a HTTP POST and we provide the actual * data through a read callback. diff --git a/docs/examples/postit2.c b/docs/examples/postit2.c index 0660cc5b5..7268fcbbc 100644 --- a/docs/examples/postit2.c +++ b/docs/examples/postit2.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * 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. diff --git a/docs/examples/sampleconv.c b/docs/examples/sampleconv.c index 8ed2b3b16..3a31a60b4 100644 --- a/docs/examples/sampleconv.c +++ b/docs/examples/sampleconv.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ /* This is a simple example showing how a program on a non-ASCII platform diff --git a/docs/examples/sendrecv.c b/docs/examples/sendrecv.c index a6853c326..6cba1dbcf 100644 --- a/docs/examples/sendrecv.c +++ b/docs/examples/sendrecv.c @@ -7,7 +7,6 @@ * * An example of curl_easy_send() and curl_easy_recv() usage. * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index 9d3dba1f9..f2a659d1d 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/simple.c b/docs/examples/simple.c index baee2ce0d..582c62426 100644 --- a/docs/examples/simple.c +++ b/docs/examples/simple.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/simplepost.c b/docs/examples/simplepost.c index 4aed4f999..d68435baf 100644 --- a/docs/examples/simplepost.c +++ b/docs/examples/simplepost.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index ea9eb5ee7..db3accaaa 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ */ #include <stdio.h> diff --git a/docs/examples/smooth-gtk-thread.c b/docs/examples/smooth-gtk-thread.c index 2d41aa248..5b60ded31 100644 --- a/docs/examples/smooth-gtk-thread.c +++ b/docs/examples/smooth-gtk-thread.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * This is a multi threaded application that uses a progress bar to show * status. It uses Gtk+ to make a smooth pulse. diff --git a/docs/examples/synctime.c b/docs/examples/synctime.c index dd824670e..4ed031ac4 100644 --- a/docs/examples/synctime.c +++ b/docs/examples/synctime.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * This example code only builds as-is on Windows. * diff --git a/docs/examples/threaded-ssl.c b/docs/examples/threaded-ssl.c index 6b979bac4..438ddaa03 100644 --- a/docs/examples/threaded-ssl.c +++ b/docs/examples/threaded-ssl.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * 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 -- cgit v1.2.1 From 05de2cf18094ddfb461b70bd5e6af4b6098c408c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Thu, 25 Mar 2010 23:22:03 +0100 Subject: remove all .cvsignore files --- docs/examples/.cvsignore | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 docs/examples/.cvsignore (limited to 'docs/examples') diff --git a/docs/examples/.cvsignore b/docs/examples/.cvsignore deleted file mode 100644 index 44e99847c..000000000 --- a/docs/examples/.cvsignore +++ /dev/null @@ -1,30 +0,0 @@ -Makefile -Makefile.in -.deps -.libs -10-at-a-time -anyauthput -cookie_interface -debug -fileupload -fopen -ftpget -ftpgetresp -ftpupload -getinfo -getinmemory -http-post -httpput -https -multi-app -multi-debugcallback -multi-double -multi-post -multi-single -persistant -post-callback -postit2 -sepheaders -simple -simplepost -simplessl -- cgit v1.2.1 From d487ade72c5f31703ce097e8460e0225fad80348 Mon Sep 17 00:00:00 2001 From: Kamil Dudka <kdudka@redhat.com> Date: Sat, 24 Apr 2010 12:14:21 +0200 Subject: test536: do not fail with threaded DNS resolver Also tweaked comments in certain examples using curl_multi_fdset(). --- docs/examples/fopen.c | 8 +++++--- docs/examples/multi-app.c | 8 +++++--- docs/examples/multi-debugcallback.c | 8 +++++--- docs/examples/multi-double.c | 8 +++++--- docs/examples/multi-post.c | 8 +++++--- docs/examples/multi-single.c | 8 +++++--- 6 files changed, 30 insertions(+), 18 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index e3814e6ab..35e24b11f 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -131,7 +131,6 @@ fill_buffer(URL_FILE *file,int want,int waittime) fd_set fdread; fd_set fdwrite; fd_set fdexcep; - int maxfd; struct timeval timeout; int rc; @@ -144,6 +143,7 @@ fill_buffer(URL_FILE *file,int want,int waittime) /* attempt to fill buffer */ do { + int maxfd = -1; FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); @@ -156,8 +156,10 @@ fill_buffer(URL_FILE *file,int want,int waittime) curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); /* In a real-world program you OF COURSE check the return code of the - function calls, *and* you make sure that maxfd is bigger than -1 - so that the call to select() below makes sense! */ + function calls. On success, the value of maxfd is guaranteed to be + greater or equal than -1. We call select(maxfd + 1, ...), specially + in case of (maxfd == -1), we call select(0, ...), which is basically + equal to sleep. */ rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index a86dd0efd..38b50cd0d 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -66,7 +66,7 @@ int main(int argc, char **argv) fd_set fdread; fd_set fdwrite; fd_set fdexcep; - int maxfd; + int maxfd = -1; FD_ZERO(&fdread); FD_ZERO(&fdwrite); @@ -80,8 +80,10 @@ int main(int argc, char **argv) curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); /* In a real-world program you OF COURSE check the return code of the - function calls, *and* you make sure that maxfd is bigger than -1 so - that the call to select() below makes sense! */ + function calls. On success, the value of maxfd is guaranteed to be + greater or equal than -1. We call select(maxfd + 1, ...), specially in + case of (maxfd == -1), we call select(0, ...), which is basically equal + to sleep. */ rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); diff --git a/docs/examples/multi-debugcallback.c b/docs/examples/multi-debugcallback.c index b10b47cd1..8e964c67b 100644 --- a/docs/examples/multi-debugcallback.c +++ b/docs/examples/multi-debugcallback.c @@ -140,7 +140,7 @@ int main(int argc, char **argv) fd_set fdread; fd_set fdwrite; fd_set fdexcep; - int maxfd; + int maxfd = -1; FD_ZERO(&fdread); FD_ZERO(&fdwrite); @@ -154,8 +154,10 @@ int main(int argc, char **argv) curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); /* In a real-world program you OF COURSE check the return code of the - function calls, *and* you make sure that maxfd is bigger than -1 - so that the call to select() below makes sense! */ + function calls. On success, the value of maxfd is guaranteed to be + greater or equal than -1. We call select(maxfd + 1, ...), specially in + case of (maxfd == -1), we call select(0, ...), which is basically equal + to sleep. */ rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); diff --git a/docs/examples/multi-double.c b/docs/examples/multi-double.c index ef3bf92fc..bc5b446ea 100644 --- a/docs/examples/multi-double.c +++ b/docs/examples/multi-double.c @@ -57,7 +57,7 @@ int main(int argc, char **argv) fd_set fdread; fd_set fdwrite; fd_set fdexcep; - int maxfd; + int maxfd = -1; FD_ZERO(&fdread); FD_ZERO(&fdwrite); @@ -71,8 +71,10 @@ int main(int argc, char **argv) curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); /* In a real-world program you OF COURSE check the return code of the - function calls, *and* you make sure that maxfd is bigger than -1 so - that the call to select() below makes sense! */ + function calls. On success, the value of maxfd is guaranteed to be + greater or equal than -1. We call select(maxfd + 1, ...), specially in + case of (maxfd == -1), we call select(0, ...), which is basically equal + to sleep. */ rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index 229e84306..0d3f78e5e 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) fd_set fdread; fd_set fdwrite; fd_set fdexcep; - int maxfd; + int maxfd = -1; FD_ZERO(&fdread); FD_ZERO(&fdwrite); @@ -91,8 +91,10 @@ int main(int argc, char *argv[]) curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); /* In a real-world program you OF COURSE check the return code of the - function calls, *and* you make sure that maxfd is bigger than -1 - so that the call to select() below makes sense! */ + function calls. On success, the value of maxfd is guaranteed to be + greater or equal than -1. We call select(maxfd + 1, ...), specially in + case of (maxfd == -1), we call select(0, ...), which is basically equal + to sleep. */ rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c index 3e236f326..cba4f32cc 100644 --- a/docs/examples/multi-single.c +++ b/docs/examples/multi-single.c @@ -51,7 +51,7 @@ int main(int argc, char **argv) fd_set fdread; fd_set fdwrite; fd_set fdexcep; - int maxfd; + int maxfd = -1; FD_ZERO(&fdread); FD_ZERO(&fdwrite); @@ -65,8 +65,10 @@ int main(int argc, char **argv) curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); /* In a real-world program you OF COURSE check the return code of the - function calls, *and* you make sure that maxfd is bigger than -1 so - that the call to select() below makes sense! */ + function calls. On success, the value of maxfd is guaranteed to be + greater or equal than -1. We call select(maxfd + 1, ...), specially in + case of (maxfd == -1), we call select(0, ...), which is basically equal + to sleep. */ rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); -- cgit v1.2.1 From 31dd8ab1d63b8b4af9551cfc2ccadcc273c50bba Mon Sep 17 00:00:00 2001 From: Pavel Raiskup <pavel@raiskup.cz> Date: Thu, 24 Jun 2010 17:22:47 +0200 Subject: examples: new FTP wildcard showcase --- docs/examples/Makefile.inc | 20 +++---- docs/examples/ftp-wildcard.c | 136 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 12 deletions(-) create mode 100644 docs/examples/ftp-wildcard.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index c104368e9..78d312665 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -1,16 +1,12 @@ # These are all libcurl example programs to be test compiled -check_PROGRAMS = 10-at-a-time anyauthput cookie_interface \ - debug fileupload fopen ftpget ftpgetresp ftpupload \ - getinfo getinmemory http-post httpput \ - https multi-app multi-debugcallback multi-double \ - multi-post multi-single persistant post-callback \ - postit2 sepheaders simple simplepost simplessl \ - sendrecv httpcustomheader certinfo chkspeed ftpgetinfo +check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ + fopen ftpget ftpgetresp ftpupload getinfo getinmemory http-post httpput \ + https multi-app multi-debugcallback multi-double multi-post multi-single \ + persistant post-callback postit2 sepheaders simple simplepost simplessl \ + sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard # These examples require external dependencies that may not be commonly # available on POSIX systems, so don't bother attempting to compile them here. -COMPLICATED_EXAMPLES = \ - curlgtk.c curlx.c htmltitle.cc cacertinmem.c ftpuploadresume.c \ - ghiper.c hiperfifo.c htmltidy.c multithread.c \ - opensslthreadlock.c sampleconv.c synctime.c threaded-ssl.c evhiperfifo.c - +COMPLICATED_EXAMPLES = curlgtk.c curlx.c htmltitle.cc cacertinmem.c \ + ftpuploadresume.c ghiper.c hiperfifo.c htmltidy.c multithread.c \ + opensslthreadlock.c sampleconv.c synctime.c threaded-ssl.c evhiperfifo.c diff --git a/docs/examples/ftp-wildcard.c b/docs/examples/ftp-wildcard.c new file mode 100644 index 000000000..732515c7a --- /dev/null +++ b/docs/examples/ftp-wildcard.c @@ -0,0 +1,136 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + */ + +#include <curl/curl.h> +#include <stdio.h> + +struct callback_data { + FILE *output; +}; + +static long file_is_comming(struct curl_fileinfo *finfo, + struct callback_data *data, + int remains); + +static long file_is_downloaded(struct callback_data *data); + +static size_t write_it(char *buff, size_t size, size_t nmemb, + struct callback_data *data); + +int main(int argc, char **argv) +{ + int rc = CURLE_OK; + + /* curl easy handle */ + CURL *handle; + + /* help data */ + struct callback_data data = { 0 }; + + /* global initialization */ + rc = curl_global_init(CURL_GLOBAL_ALL); + if(rc) + return rc; + + /* initialization of easy handle */ + handle = curl_easy_init(); + if(!handle) { + curl_global_cleanup(); + return CURLE_OUT_OF_MEMORY; + } + + /* turn on wildcard matching */ + curl_easy_setopt(handle, CURLOPT_WILDCARDMATCH, 1L); + + /* callback is called before download of concrete file started */ + curl_easy_setopt(handle, CURLOPT_CHUNK_BGN_FUNCTION, file_is_comming); + + /* callback is called after data from the file have been transferred */ + curl_easy_setopt(handle, CURLOPT_CHUNK_END_FUNCTION, file_is_downloaded); + + /* this callback will write contents into files */ + curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_it); + + /* put transfer data into callbacks */ + curl_easy_setopt(handle, CURLOPT_CHUNK_DATA, &data); + curl_easy_setopt(handle, CURLOPT_WRITEDATA, &data); + + /* curl_easy_setopt(handle, CURLOPT_VERBOSE, 1L); */ + + /* set an URL containing wildcard pattern (only in the last part) */ + if(argc == 2) + curl_easy_setopt(handle, CURLOPT_URL, argv[1]); + else + curl_easy_setopt(handle, CURLOPT_URL, + "ftp://curltest.howto.cz:123456@curltest.howto.cz/test/*"); + + /* and start transfer! */ + rc = curl_easy_perform(handle); + + curl_easy_cleanup(handle); + curl_global_cleanup(); + return rc; +} + +static long file_is_comming(struct curl_fileinfo *finfo, + struct callback_data *data, + int remains) +{ + printf("%3d %40s %10luB ", remains, finfo->filename, + (unsigned long)finfo->size); + + switch(finfo->filetype) { + case CURLFILETYPE_DIRECTORY: + printf(" DIR\n"); + break; + case CURLFILETYPE_FILE: + printf("FILE "); + break; + default: + printf("OTHER\n"); + break; + } + + if(finfo->filetype == CURLFILETYPE_FILE) { + /* do not transfer files >= 50B */ + if(finfo->size > 50) { + printf("SKIPPED\n"); + return CURL_CHUNK_BGN_FUNC_SKIP; + } + + data->output = fopen(finfo->filename, "w"); + if(!data->output) { + return CURL_CHUNK_BGN_FUNC_FAIL; + } + } + + return CURL_CHUNK_BGN_FUNC_OK; +} + +static long file_is_downloaded(struct callback_data *data) +{ + if(data->output) { + printf("DOWNLOADED\n"); + fclose(data->output); + data->output = 0x0; + } + return CURL_CHUNK_END_FUNC_OK; +} + +static size_t write_it(char *buff, size_t size, size_t nmemb, + struct callback_data *data) +{ + size_t written = 0; + if(data->output) + written = fwrite(buff, size, nmemb, data->output); + else + /* listing output */ + written = fwrite(buff, size, nmemb, stdout); + return written; +} -- cgit v1.2.1 From bc0699f226ec55fde58a823fb818d8f8106c8fbd Mon Sep 17 00:00:00 2001 From: Constantine Sapuntzakis <csapuntz@gmail.com> Date: Wed, 14 Jul 2010 00:32:53 +0200 Subject: examples: add curl_multi_timeout Make the multi-interface using examples use curl_multi_timeout to properly educate users how to do things. --- docs/examples/fopen.c | 11 +++++++++++ docs/examples/multi-app.c | 11 +++++++++++ docs/examples/multi-debugcallback.c | 11 +++++++++++ docs/examples/multi-double.c | 11 +++++++++++ docs/examples/multi-post.c | 11 +++++++++++ docs/examples/multi-single.c | 11 +++++++++++ 6 files changed, 66 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index 35e24b11f..f21526b29 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -144,6 +144,8 @@ fill_buffer(URL_FILE *file,int want,int waittime) do { int maxfd = -1; + long curl_timeo = -1; + FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); @@ -152,6 +154,15 @@ fill_buffer(URL_FILE *file,int want,int waittime) timeout.tv_sec = 60; /* 1 minute */ 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 */ curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index 38b50cd0d..bcc9f393a 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -68,6 +68,8 @@ int main(int argc, char **argv) fd_set fdexcep; int maxfd = -1; + long curl_timeo = -1; + FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); @@ -76,6 +78,15 @@ int main(int argc, char **argv) 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 */ curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); diff --git a/docs/examples/multi-debugcallback.c b/docs/examples/multi-debugcallback.c index 8e964c67b..fa90bbc48 100644 --- a/docs/examples/multi-debugcallback.c +++ b/docs/examples/multi-debugcallback.c @@ -142,6 +142,8 @@ int main(int argc, char **argv) fd_set fdexcep; int maxfd = -1; + long curl_timeo = -1; + FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); @@ -150,6 +152,15 @@ int main(int argc, char **argv) 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 */ curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); diff --git a/docs/examples/multi-double.c b/docs/examples/multi-double.c index bc5b446ea..8ac939a96 100644 --- a/docs/examples/multi-double.c +++ b/docs/examples/multi-double.c @@ -59,6 +59,8 @@ int main(int argc, char **argv) fd_set fdexcep; int maxfd = -1; + long curl_timeo = -1; + FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); @@ -67,6 +69,15 @@ int main(int argc, char **argv) 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 */ curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index 0d3f78e5e..df574ae72 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -79,6 +79,8 @@ int main(int argc, char *argv[]) fd_set fdexcep; int maxfd = -1; + long curl_timeo = -1; + FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); @@ -87,6 +89,15 @@ int main(int argc, char *argv[]) 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 */ curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c index cba4f32cc..d3f9cfde0 100644 --- a/docs/examples/multi-single.c +++ b/docs/examples/multi-single.c @@ -53,6 +53,8 @@ int main(int argc, char **argv) fd_set fdexcep; int maxfd = -1; + long curl_timeo = -1; + FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); @@ -61,6 +63,15 @@ int main(int argc, char **argv) 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 */ curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); -- cgit v1.2.1 From e9f35132642b8bace7ab40207603b5713296fe25 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Mon, 2 Aug 2010 23:46:24 +0200 Subject: example: fix code to build warning-free --- docs/examples/chkspeed.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/chkspeed.c b/docs/examples/chkspeed.c index c56fe3ccc..d802469b8 100644 --- a/docs/examples/chkspeed.c +++ b/docs/examples/chkspeed.c @@ -40,6 +40,8 @@ static size_t WriteCallback(void *ptr, size_t size, size_t nmemb, void *data) { /* we are not interested in the downloaded bytes itself, so we only return the size we would have saved ... */ + (void)ptr; /* unused */ + (void)data; /* unused */ return (size_t)(size * nmemb); } @@ -48,7 +50,7 @@ int main(int argc, char *argv[]) CURL *curl_handle; CURLcode res; int prtsep = 0, prttime = 0; - char *url = URL_1M; + const char *url = URL_1M; char *appname = argv[0]; if (argc > 1) { @@ -135,17 +137,17 @@ int main(int argc, char *argv[]) /* check for bytes downloaded */ res = curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD, &val); - if((CURLE_OK == res) && val) + if((CURLE_OK == res) && (val>0)) printf("Data downloaded: %0.0f bytes.\n", val); /* check for total download time */ res = curl_easy_getinfo(curl_handle, CURLINFO_TOTAL_TIME, &val); - if((CURLE_OK == res) && val) + if((CURLE_OK == res) && (val>0)) printf("Total download time: %0.3f sec.\n", val); /* check for average download speed */ res = curl_easy_getinfo(curl_handle, CURLINFO_SPEED_DOWNLOAD, &val); - if((CURLE_OK == res) && val) + if((CURLE_OK == res) && (val>0)) printf("Average download speed: %0.3f kbyte/sec.\n", val / 1024); } else { -- cgit v1.2.1 From fc308282ac9f368da7497431742c56ac3905e017 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Mon, 2 Aug 2010 23:47:44 +0200 Subject: .gitignore: ignore all built examples --- docs/examples/.gitignore | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 docs/examples/.gitignore (limited to 'docs/examples') diff --git a/docs/examples/.gitignore b/docs/examples/.gitignore new file mode 100644 index 000000000..3acd509b3 --- /dev/null +++ b/docs/examples/.gitignore @@ -0,0 +1,32 @@ +10-at-a-time +anyauthput +certinfo +chkspeed +cookie_interface +debug +fileupload +fopen +ftp-wildcard +ftpget +ftpgetinfo +ftpgetresp +ftpupload +getinfo +getinmemory +http-post +httpcustomheader +httpput +https +multi-app +multi-debugcallback +multi-double +multi-post +multi-single +persistant +post-callback +postit2 +sendrecv +sepheaders +simple +simplepost +simplessl -- cgit v1.2.1 From fbefd816e493a2c690e342bd3e91ce6e5300f31e Mon Sep 17 00:00:00 2001 From: James Bursa <james@zamez.org> Date: Tue, 14 Sep 2010 22:52:04 +0200 Subject: getinmemory: make the example easier to follow 1. Remove the comment warning that it's "not been verified to work". It works with no problems in my testing. 2. Remove 2 unnecessary includes. 3. Remove the myrealloc(). Initialize chunk.memory with malloc() instead of NULL. The comments for these two parts contradicted each other. 4. Handle out of memory from realloc() instead of continuing. 5. Print a brief status message at the end. --- docs/examples/getinmemory.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 5a66a04ca..2e34f1787 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -8,8 +8,6 @@ * * 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. - * - * This exact source code has not been verified to work. */ #include <stdio.h> @@ -17,25 +15,12 @@ #include <string.h> #include <curl/curl.h> -#include <curl/types.h> -#include <curl/easy.h> struct MemoryStruct { char *memory; size_t size; }; -static void *myrealloc(void *ptr, size_t size); - -static void *myrealloc(void *ptr, size_t size) -{ - /* There might be a realloc() out there that doesn't like reallocing - NULL pointers, so we take care of it here */ - if(ptr) - return realloc(ptr, size); - else - return malloc(size); -} static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) @@ -43,22 +28,28 @@ WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) size_t realsize = size * nmemb; struct MemoryStruct *mem = (struct MemoryStruct *)data; - mem->memory = myrealloc(mem->memory, mem->size + realsize + 1); - if (mem->memory) { - memcpy(&(mem->memory[mem->size]), ptr, realsize); - mem->size += realsize; - mem->memory[mem->size] = 0; + mem->memory = realloc(mem->memory, mem->size + realsize + 1); + if (mem->memory == NULL) { + /* out of memory! */ + printf("not enough memory (realloc returned NULL)\n"); + exit(EXIT_FAILURE); } + + memcpy(&(mem->memory[mem->size]), ptr, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + return realsize; } + int main(int argc, char **argv) { CURL *curl_handle; struct MemoryStruct chunk; - chunk.memory=NULL; /* we expect realloc(NULL, size) to work */ + chunk.memory = malloc(1); /* will be grown as needed by the realloc above */ chunk.size = 0; /* no data at this point */ curl_global_init(CURL_GLOBAL_ALL); @@ -96,6 +87,8 @@ int main(int argc, char **argv) * you're done with it, you should free() it as a nice application. */ + printf("%lu bytes retrieved\n", chunk.size); + if(chunk.memory) free(chunk.memory); -- cgit v1.2.1 From 5fb4279ec7199e291d9bf4c903f89395f60a3d31 Mon Sep 17 00:00:00 2001 From: Dirk Manske <dm@nonitor.de> Date: Thu, 30 Sep 2010 11:33:33 +0200 Subject: multi & hiper examples: updates and cleanups all multi and hiper examples: * don't loop curl_multi_perform calls, that was <7.20.0 style, currently the exported multi functions will not return CURLM_CALL_MULTI_PERFORM all hiper examples: * renamed check_run_count to check_multi_info * don't compare current running handle count with previous value, this was the wrong way to check for finished requests, simply call curl_multi_info_read * it's also safe to call curl_multi_remove_handle inside the curl_multi_info_read loop. ghiper.c: * replaced curl_multi_socket (that function is marked as obsolete) calls with curl_multi_socket_action calls (as in hiperfifo.c and evhiperfifo.c) ghiper.c and evhiperfifo.c: * be smart as hiperfifo.c, don't do uncessary curl_multi_* calls in new_conn and main --- docs/examples/10-at-a-time.c | 2 +- docs/examples/evhiperfifo.c | 98 ++++++++++++---------------------- docs/examples/fopen.c | 10 +--- docs/examples/ghiper.c | 103 ++++++++++++++---------------------- docs/examples/hiperfifo.c | 78 ++++++++++----------------- docs/examples/multi-app.c | 6 +-- docs/examples/multi-debugcallback.c | 6 +-- docs/examples/multi-double.c | 6 +-- docs/examples/multi-post.c | 6 +-- docs/examples/multi-single.c | 6 +-- 10 files changed, 116 insertions(+), 205 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index 51326422c..b215cbfd4 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -119,7 +119,7 @@ int main(void) } while (U) { - while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(cm, &U)); + curl_multi_perform(cm, &U); if (U) { FD_ZERO(&R); diff --git a/docs/examples/evhiperfifo.c b/docs/examples/evhiperfifo.c index 8695ffabf..6cdccf839 100644 --- a/docs/examples/evhiperfifo.c +++ b/docs/examples/evhiperfifo.c @@ -68,7 +68,6 @@ typedef struct _GlobalInfo struct ev_io fifo_event; struct ev_timer timer_event; CURLM *multi; - int prev_running; int still_running; FILE* input; } GlobalInfo; @@ -122,7 +121,6 @@ static void mcode_or_die(const char *where, CURLMcode code) switch ( code ) { case CURLM_CALL_MULTI_PERFORM: s="CURLM_CALL_MULTI_PERFORM"; break; - case CURLM_OK: s="CURLM_OK"; break; 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; @@ -144,54 +142,33 @@ static void mcode_or_die(const char *where, CURLMcode code) /* Check for completed transfers, and remove their easy handles */ -static void check_run_count(GlobalInfo *g) +static void check_multi_info(GlobalInfo *g) { - DPRINT("%s prev %i still %i\n", __PRETTY_FUNCTION__, - g->prev_running, g->still_running); - if ( g->prev_running > g->still_running ) - { - char *eff_url=NULL; - CURLMsg *msg; - int msgs_left; - ConnInfo *conn=NULL; - CURL*easy; - CURLcode res; - - fprintf(MSG_OUT, "REMAINING: %d\n", g->still_running); - /* - I am still uncertain whether it is safe to remove an easy - handle from inside the curl_multi_info_read loop, so here I - will search for completed transfers in the inner "while" - loop, and then remove them in the outer "do-while" loop... - */ - do - { - easy=NULL; - while ( (msg = curl_multi_info_read(g->multi, &msgs_left)) ) - { - if ( msg->msg == CURLMSG_DONE ) - { - easy=msg->easy_handle; - res=msg->data.result; - } - - if ( easy ) - { - curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn); - curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url); - fprintf(MSG_OUT, "DONE: %s => (%d) %s\n", eff_url, res, conn->error); - curl_multi_remove_handle(g->multi, easy); - free(conn->url); - curl_easy_cleanup(easy); - free(conn); - } - } - } while ( easy ); + char *eff_url; + CURLMsg *msg; + int msgs_left; + ConnInfo *conn; + CURL *easy; + 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) { + easy = msg->easy_handle; + res = msg->data.result; + curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn); + curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url); + fprintf(MSG_OUT, "DONE: %s => (%d) %s\n", eff_url, res, conn->error); + curl_multi_remove_handle(g->multi, easy); + free(conn->url); + curl_easy_cleanup(easy); + free(conn); + } } - g->prev_running = g->still_running; } + /* Called by libevent when we get action on a multi socket */ static void event_cb(EV_P_ struct ev_io *w, int revents) { @@ -201,12 +178,9 @@ static void event_cb(EV_P_ struct ev_io *w, int revents) int action = (revents&EV_READ?CURL_POLL_IN:0)| (revents&EV_WRITE?CURL_POLL_OUT:0); - do - { - rc = curl_multi_socket_action(g->multi, w->fd, action, &g->still_running); - } while ( rc == CURLM_CALL_MULTI_PERFORM ); - mcode_or_die("event_cb: curl_multi_socket", rc); - check_run_count(g); + 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 ) { fprintf(MSG_OUT, "last transfer done, kill timeout\n"); @@ -222,12 +196,9 @@ static void timer_cb(EV_P_ struct ev_timer *w, int revents) GlobalInfo *g = (GlobalInfo *)w->data; CURLMcode rc; - do - { - rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0, &g->still_running); - } while ( rc == CURLM_CALL_MULTI_PERFORM ); - mcode_or_die("timer_cb: curl_multi_socket", rc); - check_run_count(g); + 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); } /* Clean up the SockInfo structure */ @@ -364,11 +335,11 @@ static void new_conn(char *url, GlobalInfo *g ) fprintf(MSG_OUT, "Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url); - rc =curl_multi_add_handle(g->multi, conn->easy); + rc = curl_multi_add_handle(g->multi, conn->easy); mcode_or_die("new_conn: curl_multi_add_handle", rc); - mcode_or_die("new_conn: curl_multi_socket_all", rc); - check_run_count(g); + /* note that the add_handle() will set a time-out to trigger very soon so + that the necessary socket_action() call will be called by this app */ } /* This gets called whenever data is received from the fifo */ @@ -448,10 +419,9 @@ int main(int argc, char **argv) curl_multi_setopt(g.multi, CURLMOPT_SOCKETDATA, &g); curl_multi_setopt(g.multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb); curl_multi_setopt(g.multi, CURLMOPT_TIMERDATA, &g); - do - { - rc = curl_multi_socket_all(g.multi, &g.still_running); - } while ( CURLM_CALL_MULTI_PERFORM == rc ); + + /* we don't call any curl_multi_socket*() function yet as we have no handles + added! */ ev_loop(g.loop, 0); curl_multi_cleanup(g.multi); diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index f21526b29..1310993bd 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -184,12 +184,7 @@ fill_buffer(URL_FILE *file,int want,int waittime) default: /* timeout or readable/writable sockets */ - /* note we *could* be more efficient and not wait for - * CURLM_CALL_MULTI_PERFORM to clear here and check it on re-entry - * but that gets messy */ - while(curl_multi_perform(multi_handle, &file->still_running) == - CURLM_CALL_MULTI_PERFORM); - + curl_multi_perform(multi_handle, &file->still_running); break; } } while(file->still_running && (file->buffer_pos < want)); @@ -260,8 +255,7 @@ url_fopen(const char *url,const char *operation) curl_multi_add_handle(multi_handle, file->handle.curl); /* lets start the fetch */ - while(curl_multi_perform(multi_handle, &file->still_running) == - CURLM_CALL_MULTI_PERFORM ); + curl_multi_perform(multi_handle, &file->still_running); if((file->buffer_pos == 0) && (!file->still_running)) { diff --git a/docs/examples/ghiper.c b/docs/examples/ghiper.c index 4f3913d71..ac11790cc 100644 --- a/docs/examples/ghiper.c +++ b/docs/examples/ghiper.c @@ -58,10 +58,7 @@ callback. typedef struct _GlobalInfo { CURLM *multi; guint timer_event; - int prev_running; int still_running; - int requested; /* count: curl_easy_init() */ - int completed; /* count: curl_easy_cleanup() */ } GlobalInfo; @@ -95,7 +92,6 @@ static void mcode_or_die(const char *where, CURLMcode code) { const char *s; switch (code) { case CURLM_CALL_MULTI_PERFORM: s="CURLM_CALL_MULTI_PERFORM"; break; - case CURLM_OK: s="CURLM_OK"; break; 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; @@ -113,62 +109,43 @@ static void mcode_or_die(const char *where, CURLMcode code) { /* Check for completed transfers, and remove their easy handles */ -static void check_run_count(GlobalInfo *g) +static void check_multi_info(GlobalInfo *g) { - if (g->prev_running > g->still_running) { - char *eff_url=NULL; - CURLMsg *msg; - int msgs_left; - ConnInfo *conn=NULL; - CURL*easy; - CURLcode res; - - MSG_OUT("REMAINING: %d\n", g->still_running); - /* - I am still uncertain whether it is safe to remove an easy handle - from inside the curl_multi_info_read loop, so here I will search - for completed transfers in the inner "while" loop, and then remove - them in the outer "do-while" loop... - */ - do { - easy=NULL; - while ((msg = curl_multi_info_read(g->multi, &msgs_left))) { - if (msg->msg == CURLMSG_DONE) { - easy=msg->easy_handle; - res=msg->data.result; - break; - } - } - if (easy) { - curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn); - curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url); - MSG_OUT("DONE: %s => (%d) %s\n", eff_url, res, conn->error); - curl_multi_remove_handle(g->multi, easy); - g_free(conn->url); - curl_easy_cleanup(easy); - g_free(conn); - g->completed++; - } - } while ( easy ); - MSG_OUT("Requested: %d Completed:%d\n", g->requested, g->completed); + char *eff_url; + CURLMsg *msg; + int msgs_left; + ConnInfo *conn; + CURL *easy; + 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) { + easy = msg->easy_handle; + res = msg->data.result; + curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn); + curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url); + MSG_OUT("DONE: %s => (%d) %s\n", eff_url, res, conn->error); + curl_multi_remove_handle(g->multi, easy); + free(conn->url); + curl_easy_cleanup(easy); + free(conn); + } } - g->prev_running = g->still_running; } - /* Called by glib when our timeout expires */ static gboolean timer_cb(gpointer data) { GlobalInfo *g = (GlobalInfo *)data; CURLMcode rc; - do { - rc = curl_multi_socket(g->multi, CURL_SOCKET_TIMEOUT, &g->still_running); - } while (rc == CURLM_CALL_MULTI_PERFORM); - mcode_or_die("timer_cb: curl_multi_socket", rc); - check_run_count(g); + 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); return FALSE; } @@ -198,11 +175,15 @@ static gboolean event_cb(GIOChannel *ch, GIOCondition condition, gpointer data) GlobalInfo *g = (GlobalInfo*) data; CURLMcode rc; int fd=g_io_channel_unix_get_fd(ch); - do { - rc = curl_multi_socket(g->multi, fd, &g->still_running); - } while (rc == CURLM_CALL_MULTI_PERFORM); - mcode_or_die("event_cb: curl_multi_socket", rc); - check_run_count(g); + + int action = + (condition & G_IO_IN ? CURL_CSELECT_IN : 0) | + (condition & G_IO_OUT ? CURL_CSELECT_OUT : 0); + + rc = curl_multi_socket_action(g->multi, fd, action, &g->still_running); + mcode_or_die("event_cb: curl_multi_socket_action", rc); + + check_multi_info(g); if(g->still_running) { return TRUE; } else { @@ -338,12 +319,9 @@ static void new_conn(char *url, GlobalInfo *g ) MSG_OUT("Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url); rc =curl_multi_add_handle(g->multi, conn->easy); mcode_or_die("new_conn: curl_multi_add_handle", rc); - g->requested++; - do { - rc = curl_multi_socket_all(g->multi, &g->still_running); - } while (CURLM_CALL_MULTI_PERFORM == rc); - mcode_or_die("new_conn: curl_multi_socket_all", rc); - check_run_count(g); + + /* note that the add_handle() will set a time-out to trigger very soon so + that the necessary socket_action() call will be called by this app */ } @@ -451,9 +429,10 @@ int main(int argc, char **argv) curl_multi_setopt(g->multi, CURLMOPT_SOCKETDATA, g); curl_multi_setopt(g->multi, CURLMOPT_TIMERFUNCTION, update_timeout_cb); curl_multi_setopt(g->multi, CURLMOPT_TIMERDATA, g); - do { - rc = curl_multi_socket_all(g->multi, &g->still_running); - } while (CURLM_CALL_MULTI_PERFORM == rc); + + /* we don't call any curl_multi_socket*() function yet as we have no handles + added! */ + g_main_loop_run(gmain); curl_multi_cleanup(g->multi); return 0; diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index f5b422b4a..c9096871b 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -62,7 +62,6 @@ typedef struct _GlobalInfo { struct event fifo_event; struct event timer_event; CURLM *multi; - int prev_running; int still_running; FILE* input; } GlobalInfo; @@ -110,7 +109,6 @@ static void mcode_or_die(const char *where, CURLMcode code) const char *s; switch (code) { case CURLM_CALL_MULTI_PERFORM: s="CURLM_CALL_MULTI_PERFORM"; break; - case CURLM_OK: s="CURLM_OK"; break; 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; @@ -132,44 +130,29 @@ static void mcode_or_die(const char *where, CURLMcode code) /* Check for completed transfers, and remove their easy handles */ -static void check_run_count(GlobalInfo *g) +static void check_multi_info(GlobalInfo *g) { - if (g->prev_running > g->still_running) { - char *eff_url=NULL; - CURLMsg *msg; - int msgs_left; - ConnInfo *conn=NULL; - CURL*easy; - CURLcode res; - - fprintf(MSG_OUT, "REMAINING: %d\n", g->still_running); - /* - I am still uncertain whether it is safe to remove an easy handle - from inside the curl_multi_info_read loop, so here I will search - for completed transfers in the inner "while" loop, and then remove - them in the outer "do-while" loop... - */ - do { - easy=NULL; - while ((msg = curl_multi_info_read(g->multi, &msgs_left))) { - if (msg->msg == CURLMSG_DONE) { - easy=msg->easy_handle; - res=msg->data.result; - break; - } - } - if (easy) { - curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn); - curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url); - fprintf(MSG_OUT, "DONE: %s => (%d) %s\n", eff_url, res, conn->error); - curl_multi_remove_handle(g->multi, easy); - free(conn->url); - curl_easy_cleanup(easy); - free(conn); - } - } while ( easy ); + char *eff_url; + CURLMsg *msg; + int msgs_left; + ConnInfo *conn; + CURL *easy; + 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) { + easy = msg->easy_handle; + res = msg->data.result; + curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn); + curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url); + fprintf(MSG_OUT, "DONE: %s => (%d) %s\n", eff_url, res, conn->error); + curl_multi_remove_handle(g->multi, easy); + free(conn->url); + curl_easy_cleanup(easy); + free(conn); + } } - g->prev_running = g->still_running; } @@ -181,16 +164,13 @@ static void event_cb(int fd, short kind, void *userp) CURLMcode rc; int action = - (kind&EV_READ?CURL_CSELECT_IN:0)| - (kind&EV_WRITE?CURL_CSELECT_OUT:0); - - do { - rc = curl_multi_socket_action(g->multi, fd, action, &g->still_running); - } while (rc == CURLM_CALL_MULTI_PERFORM); + (kind & EV_READ ? CURL_CSELECT_IN : 0) | + (kind & EV_WRITE ? CURL_CSELECT_OUT : 0); + rc = curl_multi_socket_action(g->multi, fd, action, &g->still_running); mcode_or_die("event_cb: curl_multi_socket_action", rc); - check_run_count(g); + check_multi_info(g); if ( g->still_running <= 0 ) { fprintf(MSG_OUT, "last transfer done, kill timeout\n"); if (evtimer_pending(&g->timer_event, NULL)) { @@ -209,12 +189,10 @@ static void timer_cb(int fd, short kind, void *userp) (void)fd; (void)kind; - do { - rc = curl_multi_socket_action(g->multi, + rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0, &g->still_running); - } while (rc == CURLM_CALL_MULTI_PERFORM); mcode_or_die("timer_cb: curl_multi_socket_action", rc); - check_run_count(g); + check_multi_info(g); } @@ -340,7 +318,7 @@ static void new_conn(char *url, GlobalInfo *g ) curl_easy_setopt(conn->easy, CURLOPT_PROGRESSDATA, conn); fprintf(MSG_OUT, "Adding easy %p to multi %p (%s)\n", conn->easy, g->multi, url); - rc =curl_multi_add_handle(g->multi, conn->easy); + rc = curl_multi_add_handle(g->multi, conn->easy); mcode_or_die("new_conn: curl_multi_add_handle", rc); /* note that the add_handle() will set a time-out to trigger very soon so diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index bcc9f393a..a5e85c42f 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -56,8 +56,7 @@ int main(int argc, char **argv) curl_multi_add_handle(multi_handle, handles[i]); /* we start some action by calling perform right away */ - while(CURLM_CALL_MULTI_PERFORM == - curl_multi_perform(multi_handle, &still_running)); + curl_multi_perform(multi_handle, &still_running); while(still_running) { struct timeval timeout; @@ -108,8 +107,7 @@ int main(int argc, char **argv) default: /* one or more of curl's file descriptors say there's data to read or write */ - while(CURLM_CALL_MULTI_PERFORM == - curl_multi_perform(multi_handle, &still_running)); + curl_multi_perform(multi_handle, &still_running); break; } } diff --git a/docs/examples/multi-debugcallback.c b/docs/examples/multi-debugcallback.c index fa90bbc48..6d647e66e 100644 --- a/docs/examples/multi-debugcallback.c +++ b/docs/examples/multi-debugcallback.c @@ -130,8 +130,7 @@ int main(int argc, char **argv) curl_multi_add_handle(multi_handle, http_handle); /* we start some action by calling perform right away */ - while(CURLM_CALL_MULTI_PERFORM == - curl_multi_perform(multi_handle, &still_running)); + curl_multi_perform(multi_handle, &still_running); while(still_running) { struct timeval timeout; @@ -181,8 +180,7 @@ int main(int argc, char **argv) case 0: default: /* timeout or readable/writable sockets */ - while(CURLM_CALL_MULTI_PERFORM == - curl_multi_perform(multi_handle, &still_running)); + curl_multi_perform(multi_handle, &still_running); break; } } diff --git a/docs/examples/multi-double.c b/docs/examples/multi-double.c index 8ac939a96..702f9ae3d 100644 --- a/docs/examples/multi-double.c +++ b/docs/examples/multi-double.c @@ -47,8 +47,7 @@ int main(int argc, char **argv) curl_multi_add_handle(multi_handle, http_handle2); /* we start some action by calling perform right away */ - while(CURLM_CALL_MULTI_PERFORM == - curl_multi_perform(multi_handle, &still_running)); + curl_multi_perform(multi_handle, &still_running); while(still_running) { struct timeval timeout; @@ -96,8 +95,7 @@ int main(int argc, char **argv) case 0: default: /* timeout or readable/writable sockets */ - while(CURLM_CALL_MULTI_PERFORM == - curl_multi_perform(multi_handle, &still_running)); + curl_multi_perform(multi_handle, &still_running); break; } } diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index df574ae72..8ab4bb904 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -67,8 +67,7 @@ int main(int argc, char *argv[]) curl_multi_add_handle(multi_handle, curl); - while(CURLM_CALL_MULTI_PERFORM == - curl_multi_perform(multi_handle, &still_running)); + curl_multi_perform(multi_handle, &still_running); while(still_running) { struct timeval timeout; @@ -118,8 +117,7 @@ int main(int argc, char *argv[]) default: /* timeout or readable/writable sockets */ printf("perform!\n"); - while(CURLM_CALL_MULTI_PERFORM == - curl_multi_perform(multi_handle, &still_running)); + curl_multi_perform(multi_handle, &still_running); printf("running: %d!\n", still_running); break; } diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c index d3f9cfde0..fdcb5d8a8 100644 --- a/docs/examples/multi-single.c +++ b/docs/examples/multi-single.c @@ -41,8 +41,7 @@ int main(int argc, char **argv) curl_multi_add_handle(multi_handle, http_handle); /* we start some action by calling perform right away */ - while(CURLM_CALL_MULTI_PERFORM == - curl_multi_perform(multi_handle, &still_running)); + curl_multi_perform(multi_handle, &still_running); while(still_running) { struct timeval timeout; @@ -92,8 +91,7 @@ int main(int argc, char **argv) case 0: default: /* timeout or readable/writable sockets */ - while(CURLM_CALL_MULTI_PERFORM == - curl_multi_perform(multi_handle, &still_running)); + curl_multi_perform(multi_handle, &still_running); break; } } -- cgit v1.2.1 From 18e7b52e8e95f7204d8ef7ff0f0ff0043afe45a9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Tue, 5 Oct 2010 15:00:19 +0200 Subject: examples: use example.com in example URLs --- docs/examples/cacertinmem.c | 2 +- docs/examples/certinfo.c | 2 +- docs/examples/cookie_interface.c | 2 +- docs/examples/debug.c | 2 +- docs/examples/ftp-wildcard.c | 3 +-- docs/examples/ftpget.c | 6 ++---- docs/examples/ftpgetinfo.c | 3 +-- docs/examples/ftpgetresp.c | 2 +- docs/examples/ftpupload.c | 2 +- docs/examples/ftpuploadresume.c | 11 +++++++---- docs/examples/getinfo.c | 2 +- docs/examples/getinmemory.c | 2 +- docs/examples/https.c | 2 +- docs/examples/multi-app.c | 4 ++-- docs/examples/multi-debugcallback.c | 2 +- docs/examples/multi-double.c | 2 +- docs/examples/multi-post.c | 3 +-- docs/examples/multi-single.c | 2 +- docs/examples/persistant.c | 4 ++-- docs/examples/post-callback.c | 4 ++-- docs/examples/postit2.c | 2 +- docs/examples/sampleconv.c | 2 +- docs/examples/sendrecv.c | 4 ++-- docs/examples/sepheaders.c | 2 +- docs/examples/simple.c | 2 +- docs/examples/simplepost.c | 2 +- docs/examples/threaded-ssl.c | 8 ++++---- 27 files changed, 41 insertions(+), 43 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/cacertinmem.c b/docs/examples/cacertinmem.c index fc3c9b110..387029501 100644 --- a/docs/examples/cacertinmem.c +++ b/docs/examples/cacertinmem.c @@ -111,7 +111,7 @@ int main(void) rv=curl_easy_setopt(ch,CURLOPT_WRITEHEADER, 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.cacert.org/"); + rv=curl_easy_setopt(ch, CURLOPT_URL, "https://www.example.com/"); /* first try: retrieve page without cacerts' certificate -> will fail */ diff --git a/docs/examples/certinfo.c b/docs/examples/certinfo.c index b0e9759f4..ceb0ac2b0 100644 --- a/docs/examples/certinfo.c +++ b/docs/examples/certinfo.c @@ -20,7 +20,7 @@ int main(int argc, char **argv) curl = curl_easy_init(); if(curl) { - curl_easy_setopt(curl, CURLOPT_URL, "https://www.networking4all.com/"); + curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/"); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wrfu); diff --git a/docs/examples/cookie_interface.c b/docs/examples/cookie_interface.c index 27bfa3932..9f1e629e1 100644 --- a/docs/examples/cookie_interface.c +++ b/docs/examples/cookie_interface.c @@ -53,7 +53,7 @@ main(void) if (curl) { char nline[256]; - curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/"); /* google.com sets "PREF" cookie */ + 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 */ res = curl_easy_perform(curl); diff --git a/docs/examples/debug.c b/docs/examples/debug.c index d5bf75028..cc6848178 100644 --- a/docs/examples/debug.c +++ b/docs/examples/debug.c @@ -118,7 +118,7 @@ int main(void) /* the DEBUGFUNCTION has no effect until we enable VERBOSE */ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); - curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); + curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/"); res = curl_easy_perform(curl); /* always cleanup */ diff --git a/docs/examples/ftp-wildcard.c b/docs/examples/ftp-wildcard.c index 732515c7a..0186a38af 100644 --- a/docs/examples/ftp-wildcard.c +++ b/docs/examples/ftp-wildcard.c @@ -67,8 +67,7 @@ int main(int argc, char **argv) if(argc == 2) curl_easy_setopt(handle, CURLOPT_URL, argv[1]); else - curl_easy_setopt(handle, CURLOPT_URL, - "ftp://curltest.howto.cz:123456@curltest.howto.cz/test/*"); + curl_easy_setopt(handle, CURLOPT_URL, "ftp://example.com/test/*"); /* and start transfer! */ rc = curl_easy_perform(handle); diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 78727e7ef..3c3888a20 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -52,12 +52,10 @@ int main(void) curl = curl_easy_init(); if(curl) { /* - * Get curl 7.9.2 from sunet.se's FTP site. curl 7.9.2 is most likely not - * present there by the time you read this, so you'd better replace the - * URL with one that works! + * You better replace the URL with one that works! */ curl_easy_setopt(curl, CURLOPT_URL, - "ftp://ftp.sunet.se/pub/www/utilities/curl/curl-7.9.2.tar.gz"); + "ftp://ftp.example.com/pub/www/utilities/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 f30974bd1..c4e234f18 100644 --- a/docs/examples/ftpgetinfo.c +++ b/docs/examples/ftpgetinfo.c @@ -28,8 +28,7 @@ static size_t throw_away(void *ptr, size_t size, size_t nmemb, void *data) int main(void) { - /* Check for binutils 2.19.1 from ftp.gnu.org's FTP site. */ - char ftpurl[] = "ftp://ftp.gnu.org/gnu/binutils/binutils-2.19.1.tar.bz2"; + char ftpurl[] = "ftp://ftp.example.com/gnu/binutils/binutils-2.19.1.tar.bz2"; CURL *curl; CURLcode res; const time_t filetime; diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index 8d837f36f..2122c4f68 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -43,7 +43,7 @@ int main(int argc, char **argv) curl = curl_easy_init(); if(curl) { /* Get a file listing from sunet */ - curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.sunet.se/"); + curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.example.com/"); curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftpfile); /* If you intend to use this on windows with a libcurl DLL, you must use CURLOPT_WRITEFUNCTION as well */ diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index d553850f0..f1f66c0a1 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -30,7 +30,7 @@ #define LOCAL_FILE "/tmp/uploadthis.txt" #define UPLOAD_FILE_AS "while-uploading.txt" -#define REMOTE_URL "ftp://localhost/" UPLOAD_FILE_AS +#define REMOTE_URL "ftp://example.com/" UPLOAD_FILE_AS #define RENAME_FILE_TO "renamed-and-fine.txt" /* NOTE: if you want this example to work on Windows with libcurl as a diff --git a/docs/examples/ftpuploadresume.c b/docs/examples/ftpuploadresume.c index 3dda06781..81a790a11 100644 --- a/docs/examples/ftpuploadresume.c +++ b/docs/examples/ftpuploadresume.c @@ -32,7 +32,8 @@ int __cdecl _snscanf(const char * input, size_t length, const char * format, ... /* parse headers for Content-Length */ -size_t getcontentlengthfunc(void *ptr, size_t size, size_t nmemb, void *stream) { +size_t getcontentlengthfunc(void *ptr, size_t size, size_t nmemb, void *stream) +{ int r; long len = 0; @@ -46,7 +47,8 @@ size_t getcontentlengthfunc(void *ptr, size_t size, size_t nmemb, void *stream) } /* discard downloaded data */ -size_t discardfunc(void *ptr, size_t size, size_t nmemb, void *stream) { +size_t discardfunc(void *ptr, size_t size, size_t nmemb, void *stream) +{ return size * nmemb; } @@ -143,13 +145,14 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath, } } -int main(int c, char **argv) { +int main(int c, char **argv) +{ CURL *curlhandle = NULL; curl_global_init(CURL_GLOBAL_ALL); curlhandle = curl_easy_init(); - upload(curlhandle, "ftp://user:pass@host/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 a9630191f..0d8f1f2e9 100644 --- a/docs/examples/getinfo.c +++ b/docs/examples/getinfo.c @@ -19,7 +19,7 @@ int main(void) curl = curl_easy_init(); if(curl) { /* http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTURL */ - curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); + 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); diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 2e34f1787..635a936ba 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -58,7 +58,7 @@ int main(int argc, char **argv) curl_handle = curl_easy_init(); /* specify URL to get */ - curl_easy_setopt(curl_handle, CURLOPT_URL, "http://cool.haxx.se/"); + curl_easy_setopt(curl_handle, CURLOPT_URL, "http://www.example.com/"); /* send all data to this function */ curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); diff --git a/docs/examples/https.c b/docs/examples/https.c index 29b50be3b..10b5c657f 100644 --- a/docs/examples/https.c +++ b/docs/examples/https.c @@ -17,7 +17,7 @@ int main(void) curl = curl_easy_init(); if(curl) { - curl_easy_setopt(curl, CURLOPT_URL, "https://sourceforge.net/"); + curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/"); #ifdef SKIP_PEER_VERIFICATION /* diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index a5e85c42f..09b91b720 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -43,9 +43,9 @@ int main(int argc, char **argv) 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://website.com"); + curl_easy_setopt(handles[HTTP_HANDLE], CURLOPT_URL, "http://example.com"); - curl_easy_setopt(handles[FTP_HANDLE], CURLOPT_URL, "ftp://ftpsite.com"); + curl_easy_setopt(handles[FTP_HANDLE], CURLOPT_URL, "ftp://example.com"); curl_easy_setopt(handles[FTP_HANDLE], CURLOPT_UPLOAD, 1L); /* init a multi stack */ diff --git a/docs/examples/multi-debugcallback.c b/docs/examples/multi-debugcallback.c index 6d647e66e..529c3d9bb 100644 --- a/docs/examples/multi-debugcallback.c +++ b/docs/examples/multi-debugcallback.c @@ -118,7 +118,7 @@ int main(int argc, char **argv) http_handle = curl_easy_init(); /* set the options (I left out a few, you'll get the point anyway) */ - curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.haxx.se/"); + curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.example.com/"); curl_easy_setopt(http_handle, CURLOPT_DEBUGFUNCTION, my_trace); curl_easy_setopt(http_handle, CURLOPT_VERBOSE, 1L); diff --git a/docs/examples/multi-double.c b/docs/examples/multi-double.c index 702f9ae3d..3ea106bf7 100644 --- a/docs/examples/multi-double.c +++ b/docs/examples/multi-double.c @@ -34,7 +34,7 @@ int main(int argc, char **argv) http_handle2 = curl_easy_init(); /* set options */ - curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.haxx.se/"); + curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.example.com/"); /* set options */ curl_easy_setopt(http_handle2, CURLOPT_URL, "http://localhost/"); diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index 8ab4bb904..d2daf70a6 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -58,8 +58,7 @@ int main(int argc, char *argv[]) if(curl && multi_handle) { /* what URL that receives this POST */ - curl_easy_setopt(curl, CURLOPT_URL, - "http://www.fillinyoururl.com/upload.cgi"); + curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.com/upload.cgi"); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c index fdcb5d8a8..f248afe76 100644 --- a/docs/examples/multi-single.c +++ b/docs/examples/multi-single.c @@ -32,7 +32,7 @@ int main(int argc, char **argv) http_handle = curl_easy_init(); /* set the options (I left out a few, you'll get the point anyway) */ - curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.haxx.se/"); + curl_easy_setopt(http_handle, CURLOPT_URL, "http://www.example.com/"); /* init a multi stack */ multi_handle = curl_multi_init(); diff --git a/docs/examples/persistant.c b/docs/examples/persistant.c index 0e65dd8fb..177ada359 100644 --- a/docs/examples/persistant.c +++ b/docs/examples/persistant.c @@ -24,12 +24,12 @@ int main(int argc, char **argv) curl_easy_setopt(curl, CURLOPT_HEADER, 1L); /* get the first document */ - curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/"); + curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/"); res = curl_easy_perform(curl); /* get another document from the same server using the same connection */ - curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/docs/"); + curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/docs/"); res = curl_easy_perform(curl); /* always cleanup */ diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index 1e688a1c8..ae4f4db98 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -51,8 +51,8 @@ int main(void) curl = curl_easy_init(); if(curl) { /* First set the URL that is about to receive our POST. */ - curl_easy_setopt(curl, CURLOPT_URL, - "http://receivingsite.com.pooh/index.cgi"); + curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/index.cgi"); + /* Now specify we want to POST data */ curl_easy_setopt(curl, CURLOPT_POST, 1L); diff --git a/docs/examples/postit2.c b/docs/examples/postit2.c index 7268fcbbc..a6292c5f1 100644 --- a/docs/examples/postit2.c +++ b/docs/examples/postit2.c @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) headerlist = curl_slist_append(headerlist, buf); if(curl) { /* what URL that receives this POST */ - curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/examplepost.cgi"); + curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/examplepost.cgi"); if ( (argc == 2) && (!strcmp(argv[1], "noexpectheader")) ) /* only disable 100-continue header if explicitly requested */ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); diff --git a/docs/examples/sampleconv.c b/docs/examples/sampleconv.c index 3a31a60b4..ed458516d 100644 --- a/docs/examples/sampleconv.c +++ b/docs/examples/sampleconv.c @@ -75,7 +75,7 @@ int main(void) curl = curl_easy_init(); if(curl) { - curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); + curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); /* use platform-specific functions for codeset conversions */ curl_easy_setopt(curl, CURLOPT_CONV_FROM_NETWORK_FUNCTION, diff --git a/docs/examples/sendrecv.c b/docs/examples/sendrecv.c index 6cba1dbcf..ad5ddd115 100644 --- a/docs/examples/sendrecv.c +++ b/docs/examples/sendrecv.c @@ -48,13 +48,13 @@ int main(void) CURL *curl; CURLcode res; /* Minimalistic http request */ - const char *request = "GET / HTTP/1.0\r\nHost: curl.haxx.se\r\n\r\n"; + const char *request = "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n"; int sockfd; /* socket */ size_t iolen; curl = curl_easy_init(); if(curl) { - curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); + curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); /* Do not do the transfer - only connect to host */ curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); res = curl_easy_perform(curl); diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index f2a659d1d..e0c4cbbb7 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -35,7 +35,7 @@ int main(int argc, char **argv) curl_handle = curl_easy_init(); /* set URL to get */ - curl_easy_setopt(curl_handle, CURLOPT_URL, "http://curl.haxx.se"); + curl_easy_setopt(curl_handle, CURLOPT_URL, "http://example.com"); /* no progress meter please */ curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L); diff --git a/docs/examples/simple.c b/docs/examples/simple.c index 582c62426..351cf729b 100644 --- a/docs/examples/simple.c +++ b/docs/examples/simple.c @@ -17,7 +17,7 @@ int main(void) curl = curl_easy_init(); if(curl) { - curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se"); + curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); res = curl_easy_perform(curl); /* always cleanup */ diff --git a/docs/examples/simplepost.c b/docs/examples/simplepost.c index d68435baf..b8e61e07d 100644 --- a/docs/examples/simplepost.c +++ b/docs/examples/simplepost.c @@ -20,7 +20,7 @@ int main(void) curl = curl_easy_init(); if(curl) { - curl_easy_setopt(curl, CURLOPT_URL, "http://posthere.com"); + curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis); /* if we don't provide POSTFIELDSIZE, libcurl will strlen() by diff --git a/docs/examples/threaded-ssl.c b/docs/examples/threaded-ssl.c index 438ddaa03..284edc419 100644 --- a/docs/examples/threaded-ssl.c +++ b/docs/examples/threaded-ssl.c @@ -91,10 +91,10 @@ void init_locks(void) /* List of URLs to fetch.*/ const char * const urls[]= { - "https://www.sf.net/", - "https://www.openssl.org/", - "https://www.sf.net/", - "https://www.openssl.org/", + "https://www.example.com/", + "https://www2.example.com/", + "https://www3.example.com/", + "https://www4.example.com/", }; static void *pull_one_url(void *url) -- cgit v1.2.1 From 909e711e745fe6b23f18dc9780e28a4e19d1a53a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Thu, 4 Nov 2010 10:32:38 +0100 Subject: example: add smtp-multi.c An example application source code sending SMTP mail with the multi interface. It is based on the code Alona Rossen provided, which in turn is based on existing example/test code, and I converted it even more into a decent example with a fair multi API use, put the info required to edit at the top and I added some comments. --- docs/examples/Makefile.inc | 3 +- docs/examples/smtp-multi.c | 196 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 docs/examples/smtp-multi.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 78d312665..51c96a5a8 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -3,7 +3,8 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ fopen ftpget ftpgetresp ftpupload getinfo getinmemory http-post httpput \ https multi-app multi-debugcallback multi-double multi-post multi-single \ persistant post-callback postit2 sepheaders simple simplepost simplessl \ - sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard + sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard \ + smtp-multi.c # 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/smtp-multi.c b/docs/examples/smtp-multi.c new file mode 100644 index 000000000..0a7aeebf9 --- /dev/null +++ b/docs/examples/smtp-multi.c @@ -0,0 +1,196 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * + * This is an example application source code sending SMTP mail using the + * multi interface. + */ + +#include <string.h> +#include <curl/curl.h> + +/* + * This is the list of basic details you need to tweak to get things right. + */ +#define USERNAME "user@example.com" +#define PASSWORD "123qwerty" +#define SMTPSERVER "smtp.example.com" +#define SMTPPORT ":587" /* it is a colon+port string, but you can set it + to "" to use the default port */ +#define RECEPIENT "receipient@example.com" +#define MAILFROM "<realuser@example.com>" + +#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000 + +/* Note that you should include the actual meta data headers here as well if + you want the mail to have a Subject, another From:, show a To: or whatever + you think your mail should feature! */ +static const char *text[]={ + "one\n", + "two\n", + "three\n", + " Hello, this is CURL email SMTP\n", + NULL +}; + +struct WriteThis { + int counter; +}; + +static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp) +{ + struct WriteThis *pooh = (struct WriteThis *)userp; + const char *data; + + if(size*nmemb < 1) + return 0; + + data = text[pooh->counter]; + + if(data) { + size_t len = strlen(data); + memcpy(ptr, data, len); + pooh->counter++; /* advance pointer */ + return len; + } + return 0; /* no more data left to deliver */ +} + +static struct timeval tvnow(void) +{ + /* + ** time() returns the value of time in seconds since the Epoch. + */ + struct timeval now; + now.tv_sec = (long)time(NULL); + now.tv_usec = 0; + return now; +} + +static long tvdiff(struct timeval newer, struct timeval older) +{ + return (newer.tv_sec-older.tv_sec)*1000+ + (newer.tv_usec-older.tv_usec)/1000; +} + +int main(void) +{ + CURL *curl; + CURLM *mcurl; + int still_running = 1; + struct timeval mp_start; + char mp_timedout = 0; + struct WriteThis pooh; + struct curl_slist* rcpt_list = NULL; + + pooh.counter = 0; + + curl_global_init(CURL_GLOBAL_DEFAULT); + + curl = curl_easy_init(); + if(!curl) + return 1; + + mcurl = curl_multi_init(); + if(!mcurl) + return 2; + + rcpt_list = curl_slist_append(rcpt_list, RECEPIENT); + /* more addresses can be added here + rcpt_list = curl_slist_append(rcpt_list, "others@example.com"); + */ + + curl_easy_setopt(curl, CURLOPT_URL, "smtp://" SMTPSERVER SMTPPORT); + curl_easy_setopt(curl, CURLOPT_USERNAME, USERNAME); + curl_easy_setopt(curl, CURLOPT_PASSWORD, PASSWORD); + curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); + curl_easy_setopt(curl, CURLOPT_MAIL_FROM, MAILFROM); + curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt_list); + curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER,0); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); + curl_easy_setopt(curl, CURLOPT_READDATA, &pooh); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + curl_easy_setopt(curl, CURLOPT_SSLVERSION, 0); + curl_easy_setopt(curl, CURLOPT_SSL_SESSIONID_CACHE, 0); + curl_multi_add_handle(mcurl, curl); + + mp_timedout = 0; + mp_start = tvnow(); + + /* we start some action by calling perform right away */ + curl_multi_perform(mcurl, &still_running); + + while(still_running) { + struct timeval timeout; + int rc; /* select() 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(mcurl, &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 */ + curl_multi_fdset(mcurl, &fdread, &fdwrite, &fdexcep, &maxfd); + + /* In a real-world program you OF COURSE check the return code of the + function calls. On success, the value of maxfd is guaranteed to be + greater or equal than -1. We call select(maxfd + 1, ...), specially in + case of (maxfd == -1), we call select(0, ...), which is basically equal + to sleep. */ + + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); + + if (tvdiff(tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) { + fprintf(stderr, "ABORTING TEST, since it seems " + "that it would have run forever.\n"); + break; + } + + switch(rc) { + case -1: + /* select error */ + break; + case 0: + /* timeout, do something else */ + break; + default: + /* one or more of curl's file descriptors say there's data to read + or write */ + curl_multi_perform(mcurl, &still_running); + break; + } + } + + curl_slist_free_all(rcpt_list); + curl_multi_remove_handle(mcurl, curl); + curl_multi_cleanup(mcurl); + curl_easy_cleanup(curl); + curl_global_cleanup(); + return 0; +} + + -- cgit v1.2.1 From 542318b11361210e84d25e653bee3442fccf6766 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Thu, 4 Nov 2010 11:37:23 +0100 Subject: multi use: call multi_perform even on select() timeouts --- docs/examples/fopen.c | 9 +++------ docs/examples/multi-app.c | 8 ++------ docs/examples/multi-post.c | 1 - docs/examples/smtp-multi.c | 8 ++------ 4 files changed, 7 insertions(+), 19 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index 1310993bd..874d380d7 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -180,12 +180,9 @@ fill_buffer(URL_FILE *file,int want,int waittime) break; case 0: - break; - - default: - /* timeout or readable/writable sockets */ - curl_multi_perform(multi_handle, &file->still_running); - break; + /* timeout or readable/writable sockets */ + curl_multi_perform(multi_handle, &file->still_running); + break; } } while(file->still_running && (file->buffer_pos < want)); return 1; diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index 09b91b720..6ba131830 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -101,12 +101,8 @@ int main(int argc, char **argv) case -1: /* select error */ break; - case 0: - /* timeout, do something else */ - break; - default: - /* one or more of curl's file descriptors say there's data to read - or write */ + case 0: /* timeout */ + default: /* action */ curl_multi_perform(multi_handle, &still_running); break; } diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index d2daf70a6..8b4f03e9e 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -112,7 +112,6 @@ int main(int argc, char *argv[]) /* select error */ break; case 0: - printf("timeout!\n"); default: /* timeout or readable/writable sockets */ printf("perform!\n"); diff --git a/docs/examples/smtp-multi.c b/docs/examples/smtp-multi.c index 0a7aeebf9..239172ba9 100644 --- a/docs/examples/smtp-multi.c +++ b/docs/examples/smtp-multi.c @@ -174,12 +174,8 @@ int main(void) case -1: /* select error */ break; - case 0: - /* timeout, do something else */ - break; - default: - /* one or more of curl's file descriptors say there's data to read - or write */ + case 0: /* timeout */ + default: /* action */ curl_multi_perform(mcurl, &still_running); break; } -- cgit v1.2.1 From 809a748124cabb781b654f40e30fa51ae565f7c8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Thu, 4 Nov 2010 11:42:27 +0100 Subject: fopen.c: re-indented, fixed previous mistake I've made the code intended using curl-style now to look more like other examples. My previous "fix" was a bit too invasive but is now fixed again. --- docs/examples/fopen.c | 743 ++++++++++++++++++++++++-------------------------- 1 file changed, 350 insertions(+), 393 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index 874d380d7..e4505bf58 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -53,20 +53,24 @@ #include <curl/curl.h> -enum fcurl_type_e { CFTYPE_NONE=0, CFTYPE_FILE=1, CFTYPE_CURL=2 }; +enum fcurl_type_e { + CFTYPE_NONE=0, + CFTYPE_FILE=1, + CFTYPE_CURL=2 +}; struct fcurl_data { - enum fcurl_type_e type; /* type of handle */ - union { - CURL *curl; - FILE *file; - } handle; /* handle */ - - char *buffer; /* buffer to store cached data*/ - int buffer_len; /* currently allocated buffers length */ - int buffer_pos; /* end of data in buffer*/ - int still_running; /* Is background url fetch still in progress */ + enum fcurl_type_e type; /* type of handle */ + union { + CURL *curl; + FILE *file; + } handle; /* handle */ + + char *buffer; /* buffer to store cached data*/ + int buffer_len; /* currently allocated buffers length */ + int buffer_pos; /* end of data in buffer*/ + int still_running; /* Is background url fetch still in progress */ }; typedef struct fcurl_data URL_FILE; @@ -83,488 +87,441 @@ void url_rewind(URL_FILE *file); CURLM *multi_handle; /* curl calls this routine to get more data */ -static size_t -write_callback(char *buffer, - size_t size, - size_t nitems, - void *userp) +static size_t write_callback(char *buffer, + size_t size, + size_t nitems, + void *userp) { - char *newbuff; - int rembuff; - - URL_FILE *url = (URL_FILE *)userp; - size *= nitems; - - rembuff=url->buffer_len - url->buffer_pos; /* remaining space in buffer */ - - if(size > rembuff) - { - /* not enough space in buffer */ - newbuff=realloc(url->buffer,url->buffer_len + (size - rembuff)); - if(newbuff==NULL) - { - fprintf(stderr,"callback buffer grow failed\n"); - size=rembuff; - } - else - { - /* realloc suceeded increase buffer size*/ - url->buffer_len+=size - rembuff; - url->buffer=newbuff; - - /*printf("Callback buffer grown to %d bytes\n",url->buffer_len);*/ - } - } + char *newbuff; + int rembuff; + + URL_FILE *url = (URL_FILE *)userp; + size *= nitems; - memcpy(&url->buffer[url->buffer_pos], buffer, size); - url->buffer_pos += size; + rembuff=url->buffer_len - url->buffer_pos; /* remaining space in buffer */ + + if(size > rembuff) { + /* not enough space in buffer */ + newbuff=realloc(url->buffer,url->buffer_len + (size - rembuff)); + if(newbuff==NULL) { + fprintf(stderr,"callback buffer grow failed\n"); + size=rembuff; + } + else { + /* realloc suceeded increase buffer size*/ + url->buffer_len+=size - rembuff; + url->buffer=newbuff; + } + } - /*fprintf(stderr, "callback %d size bytes\n", size);*/ + memcpy(&url->buffer[url->buffer_pos], buffer, size); + url->buffer_pos += size; - return size; + return size; } /* use to attempt to fill the read buffer up to requested number of bytes */ -static int -fill_buffer(URL_FILE *file,int want,int waittime) +static int fill_buffer(URL_FILE *file,int want,int waittime) { - fd_set fdread; - fd_set fdwrite; - fd_set fdexcep; - struct timeval timeout; - int rc; - - /* only attempt to fill buffer if transactions still running and buffer - * doesnt exceed required size already - */ - if((!file->still_running) || (file->buffer_pos > want)) - return 0; - - /* attempt to fill buffer */ - do - { - int maxfd = -1; - long curl_timeo = -1; - - FD_ZERO(&fdread); - FD_ZERO(&fdwrite); - FD_ZERO(&fdexcep); - - /* set a suitable timeout to fail on */ - timeout.tv_sec = 60; /* 1 minute */ - 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 */ - curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); - - /* In a real-world program you OF COURSE check the return code of the - function calls. On success, the value of maxfd is guaranteed to be - greater or equal than -1. We call select(maxfd + 1, ...), specially - in case of (maxfd == -1), we call select(0, ...), which is basically - equal to sleep. */ - - rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); - - switch(rc) { - case -1: - /* select error */ - break; - - case 0: - /* timeout or readable/writable sockets */ - curl_multi_perform(multi_handle, &file->still_running); - break; - } - } while(file->still_running && (file->buffer_pos < want)); - return 1; -} + fd_set fdread; + fd_set fdwrite; + fd_set fdexcep; + struct timeval timeout; + int rc; + + /* only attempt to fill buffer if transactions still running and buffer + * doesnt exceed required size already + */ + if((!file->still_running) || (file->buffer_pos > want)) + return 0; -/* use to remove want bytes from the front of a files buffer */ -static int -use_buffer(URL_FILE *file,int want) -{ - /* sort out buffer */ - if((file->buffer_pos - want) <=0) - { - /* ditch buffer - write will recreate */ - if(file->buffer) - free(file->buffer); - - file->buffer=NULL; - file->buffer_pos=0; - file->buffer_len=0; + /* attempt to fill buffer */ + do { + int maxfd = -1; + long curl_timeo = -1; + + FD_ZERO(&fdread); + FD_ZERO(&fdwrite); + FD_ZERO(&fdexcep); + + /* set a suitable timeout to fail on */ + timeout.tv_sec = 60; /* 1 minute */ + 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; } - else - { - /* move rest down make it available for later */ - memmove(file->buffer, - &file->buffer[want], - (file->buffer_pos - want)); - - file->buffer_pos -= want; + + /* get file descriptors from the transfers */ + curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); + + /* In a real-world program you OF COURSE check the return code of the + function calls. On success, the value of maxfd is guaranteed to be + greater or equal than -1. We call select(maxfd + 1, ...), specially + in case of (maxfd == -1), we call select(0, ...), which is basically + equal to sleep. */ + + 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, &file->still_running); + break; } - return 0; + } while(file->still_running && (file->buffer_pos < want)); + return 1; } +/* use to remove want bytes from the front of a files buffer */ +static int use_buffer(URL_FILE *file,int want) +{ + /* sort out buffer */ + if((file->buffer_pos - want) <=0) { + /* ditch buffer - write will recreate */ + if(file->buffer) + free(file->buffer); + + file->buffer=NULL; + file->buffer_pos=0; + file->buffer_len=0; + } + else { + /* move rest down make it available for later */ + memmove(file->buffer, + &file->buffer[want], + (file->buffer_pos - want)); + + file->buffer_pos -= 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 - basicly use the real fopen() for standard files */ + /* this code could check for URLs or types in the 'url' and + basicly use the real fopen() for standard files */ - URL_FILE *file; - (void)operation; + URL_FILE *file; + (void)operation; - file = malloc(sizeof(URL_FILE)); - if(!file) - return NULL; + file = malloc(sizeof(URL_FILE)); + if(!file) + return NULL; - memset(file, 0, sizeof(URL_FILE)); + memset(file, 0, sizeof(URL_FILE)); - if((file->handle.file=fopen(url,operation))) - { - file->type = CFTYPE_FILE; /* marked as URL */ - } - else - { - file->type = CFTYPE_CURL; /* marked as URL */ - file->handle.curl = curl_easy_init(); + if((file->handle.file=fopen(url,operation))) + file->type = CFTYPE_FILE; /* marked as URL */ + + else { + file->type = CFTYPE_CURL; /* marked as URL */ + file->handle.curl = curl_easy_init(); - curl_easy_setopt(file->handle.curl, CURLOPT_URL, url); - curl_easy_setopt(file->handle.curl, CURLOPT_WRITEDATA, file); - curl_easy_setopt(file->handle.curl, CURLOPT_VERBOSE, 0L); - curl_easy_setopt(file->handle.curl, CURLOPT_WRITEFUNCTION, write_callback); + curl_easy_setopt(file->handle.curl, CURLOPT_URL, url); + curl_easy_setopt(file->handle.curl, CURLOPT_WRITEDATA, file); + curl_easy_setopt(file->handle.curl, CURLOPT_VERBOSE, 0L); + curl_easy_setopt(file->handle.curl, CURLOPT_WRITEFUNCTION, write_callback); - if(!multi_handle) - multi_handle = curl_multi_init(); + if(!multi_handle) + multi_handle = curl_multi_init(); - curl_multi_add_handle(multi_handle, file->handle.curl); + curl_multi_add_handle(multi_handle, file->handle.curl); - /* lets start the fetch */ - curl_multi_perform(multi_handle, &file->still_running); + /* lets start the fetch */ + curl_multi_perform(multi_handle, &file->still_running); - if((file->buffer_pos == 0) && (!file->still_running)) - { - /* if still_running is 0 now, we should return NULL */ + if((file->buffer_pos == 0) && (!file->still_running)) { + /* if still_running is 0 now, we should return NULL */ - /* make sure the easy handle is not in the multi handle anymore */ - curl_multi_remove_handle(multi_handle, file->handle.curl); + /* make sure the easy handle is not in the multi handle anymore */ + curl_multi_remove_handle(multi_handle, file->handle.curl); - /* cleanup */ - curl_easy_cleanup(file->handle.curl); + /* cleanup */ + curl_easy_cleanup(file->handle.curl); - free(file); + free(file); - file = NULL; - } + file = NULL; } - return file; + } + return file; } -int -url_fclose(URL_FILE *file) +int url_fclose(URL_FILE *file) { - int ret=0;/* default is good return */ + int ret=0;/* default is good return */ - switch(file->type) - { - case CFTYPE_FILE: - ret=fclose(file->handle.file); /* passthrough */ - break; + switch(file->type) { + case CFTYPE_FILE: + ret=fclose(file->handle.file); /* passthrough */ + break; - case CFTYPE_CURL: - /* make sure the easy handle is not in the multi handle anymore */ - curl_multi_remove_handle(multi_handle, file->handle.curl); + case CFTYPE_CURL: + /* make sure the easy handle is not in the multi handle anymore */ + curl_multi_remove_handle(multi_handle, file->handle.curl); - /* cleanup */ - curl_easy_cleanup(file->handle.curl); - break; + /* cleanup */ + curl_easy_cleanup(file->handle.curl); + break; - default: /* unknown or supported type - oh dear */ - ret=EOF; - errno=EBADF; - break; + default: /* unknown or supported type - oh dear */ + ret=EOF; + errno=EBADF; + break; + } - } + if(file->buffer) + free(file->buffer);/* free any allocated buffer space */ - if(file->buffer) - free(file->buffer);/* free any allocated buffer space */ + free(file); - free(file); - - return ret; + return ret; } -int -url_feof(URL_FILE *file) +int url_feof(URL_FILE *file) { - int ret=0; - - switch(file->type) - { - case CFTYPE_FILE: - ret=feof(file->handle.file); - break; - - case CFTYPE_CURL: - if((file->buffer_pos == 0) && (!file->still_running)) - ret = 1; - break; - default: /* unknown or supported type - oh dear */ - ret=-1; - errno=EBADF; - break; - } - return ret; + int ret=0; + + switch(file->type) { + case CFTYPE_FILE: + ret=feof(file->handle.file); + break; + + case CFTYPE_CURL: + if((file->buffer_pos == 0) && (!file->still_running)) + ret = 1; + break; + + default: /* unknown or supported type - oh dear */ + ret=-1; + errno=EBADF; + break; + } + return ret; } -size_t -url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) +size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) { - size_t want; + size_t want; - switch(file->type) - { - case CFTYPE_FILE: - want=fread(ptr,size,nmemb,file->handle.file); - break; + switch(file->type) { + case CFTYPE_FILE: + want=fread(ptr,size,nmemb,file->handle.file); + break; - case CFTYPE_CURL: - want = nmemb * size; + case CFTYPE_CURL: + want = nmemb * size; - fill_buffer(file,want,1); + fill_buffer(file,want,1); - /* check if theres data in the buffer - if not fill_buffer() - * either errored or EOF */ - if(!file->buffer_pos) - return 0; + /* check if theres data in the buffer - if not fill_buffer() + * either errored or EOF */ + if(!file->buffer_pos) + return 0; - /* ensure only available data is considered */ - if(file->buffer_pos < want) - want = file->buffer_pos; + /* ensure only available data is considered */ + if(file->buffer_pos < want) + want = file->buffer_pos; - /* xfer data to caller */ - memcpy(ptr, file->buffer, want); + /* xfer data to caller */ + memcpy(ptr, file->buffer, want); - use_buffer(file,want); + use_buffer(file,want); - want = want / size; /* number of items - nb correct op - checked - * with glibc code*/ + want = want / size; /* number of items */ + break; - /*printf("(fread) return %d bytes %d left\n", want,file->buffer_pos);*/ - break; + default: /* unknown or supported type - oh dear */ + want=0; + errno=EBADF; + break; - default: /* unknown or supported type - oh dear */ - want=0; - errno=EBADF; - break; - - } - return want; + } + return want; } -char * -url_fgets(char *ptr, int size, URL_FILE *file) +char *url_fgets(char *ptr, int size, URL_FILE *file) { - int want = size - 1;/* always need to leave room for zero termination */ - int loop; - - switch(file->type) - { - case CFTYPE_FILE: - ptr = fgets(ptr,size,file->handle.file); + int want = size - 1;/* always need to leave room for zero termination */ + int loop; + + switch(file->type) { + case CFTYPE_FILE: + ptr = fgets(ptr,size,file->handle.file); + break; + + case CFTYPE_CURL: + fill_buffer(file,want,1); + + /* check if theres data in the buffer - if not fill either errored or + * EOF */ + if(!file->buffer_pos) + return NULL; + + /* ensure only available data is considered */ + if(file->buffer_pos < want) + want = file->buffer_pos; + + /*buffer contains data */ + /* look for newline or eof */ + for(loop=0;loop < want;loop++) { + if(file->buffer[loop] == '\n') { + want=loop+1;/* include newline */ break; + } + } - case CFTYPE_CURL: - fill_buffer(file,want,1); - - /* check if theres data in the buffer - if not fill either errored or - * EOF */ - if(!file->buffer_pos) - return NULL; - - /* ensure only available data is considered */ - if(file->buffer_pos < want) - want = file->buffer_pos; + /* xfer data to caller */ + memcpy(ptr, file->buffer, want); + ptr[want]=0;/* allways null terminate */ - /*buffer contains data */ - /* look for newline or eof */ - for(loop=0;loop < want;loop++) - { - if(file->buffer[loop] == '\n') - { - want=loop+1;/* include newline */ - break; - } - } + use_buffer(file,want); - /* xfer data to caller */ - memcpy(ptr, file->buffer, want); - ptr[want]=0;/* allways null terminate */ + break; - use_buffer(file,want); + default: /* unknown or supported type - oh dear */ + ptr=NULL; + errno=EBADF; + break; + } - /*printf("(fgets) return %d bytes %d left\n", want,file->buffer_pos);*/ - break; - - default: /* unknown or supported type - oh dear */ - ptr=NULL; - errno=EBADF; - break; - } - - return ptr;/*success */ + return ptr;/*success */ } -void -url_rewind(URL_FILE *file) +void url_rewind(URL_FILE *file) { - switch(file->type) - { - case CFTYPE_FILE: - rewind(file->handle.file); /* passthrough */ - break; - - case CFTYPE_CURL: - /* halt transaction */ - curl_multi_remove_handle(multi_handle, file->handle.curl); - - /* restart */ - curl_multi_add_handle(multi_handle, file->handle.curl); + switch(file->type) { + case CFTYPE_FILE: + rewind(file->handle.file); /* passthrough */ + break; - /* ditch buffer - write will recreate - resets stream pos*/ - if(file->buffer) - free(file->buffer); + case CFTYPE_CURL: + /* halt transaction */ + curl_multi_remove_handle(multi_handle, file->handle.curl); - file->buffer=NULL; - file->buffer_pos=0; - file->buffer_len=0; + /* restart */ + curl_multi_add_handle(multi_handle, file->handle.curl); - break; + /* ditch buffer - write will recreate - resets stream pos*/ + if(file->buffer) + free(file->buffer); - default: /* unknown or supported type - oh dear */ - break; + file->buffer=NULL; + file->buffer_pos=0; + file->buffer_len=0; - } + break; + default: /* unknown or supported type - oh dear */ + break; + } } - /* 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 */ -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { - URL_FILE *handle; - FILE *outf; + URL_FILE *handle; + FILE *outf; + + int nread; + char buffer[256]; + const char *url; + + if(argc < 2) + url="http://192.168.7.3/testfile";/* default to testurl */ + else + url=argv[1];/* use passed url */ + + /* copy from url line by line with fgets */ + outf=fopen("fgets.test","w+"); + if(!outf) { + perror("couldn't open fgets output file\n"); + return 1; + } - int nread; - char buffer[256]; - const char *url; + handle = url_fopen(url, "r"); + if(!handle) { + printf("couldn't url_fopen() %s\n", url); + fclose(outf); + return 2; + } - if(argc < 2) - { - url="http://192.168.7.3/testfile";/* default to testurl */ - } - else - { - url=argv[1];/* use passed url */ - } + while(!url_feof(handle)) { + url_fgets(buffer,sizeof(buffer),handle); + fwrite(buffer,1,strlen(buffer),outf); + } - /* copy from url line by line with fgets */ - outf=fopen("fgets.test","w+"); - if(!outf) - { - perror("couldn't open fgets output file\n"); - return 1; - } + url_fclose(handle); - handle = url_fopen(url, "r"); - if(!handle) - { - printf("couldn't url_fopen() %s\n", url); - fclose(outf); - return 2; - } + fclose(outf); - while(!url_feof(handle)) - { - url_fgets(buffer,sizeof(buffer),handle); - fwrite(buffer,1,strlen(buffer),outf); - } - url_fclose(handle); + /* Copy from url with fread */ + outf=fopen("fread.test","w+"); + if(!outf) { + perror("couldn't open fread output file\n"); + return 1; + } + handle = url_fopen("testfile", "r"); + if(!handle) { + printf("couldn't url_fopen() testfile\n"); fclose(outf); + return 2; + } + do { + nread = url_fread(buffer, 1,sizeof(buffer), handle); + fwrite(buffer,1,nread,outf); + } while(nread); - /* Copy from url with fread */ - outf=fopen("fread.test","w+"); - if(!outf) - { - perror("couldn't open fread output file\n"); - return 1; - } + url_fclose(handle); - handle = url_fopen("testfile", "r"); - if(!handle) { - printf("couldn't url_fopen() testfile\n"); - fclose(outf); - return 2; - } + fclose(outf); - do { - nread = url_fread(buffer, 1,sizeof(buffer), handle); - fwrite(buffer,1,nread,outf); - } while(nread); - url_fclose(handle); + /* Test rewind */ + outf=fopen("rewind.test","w+"); + if(!outf) { + perror("couldn't open fread output file\n"); + return 1; + } + handle = url_fopen("testfile", "r"); + if(!handle) { + printf("couldn't url_fopen() testfile\n"); fclose(outf); + return 2; + } + nread = url_fread(buffer, 1,sizeof(buffer), handle); + fwrite(buffer,1,nread,outf); + url_rewind(handle); - /* Test rewind */ - outf=fopen("rewind.test","w+"); - if(!outf) - { - perror("couldn't open fread output file\n"); - return 1; - } + buffer[0]='\n'; + fwrite(buffer,1,1,outf); - handle = url_fopen("testfile", "r"); - if(!handle) { - printf("couldn't url_fopen() testfile\n"); - fclose(outf); - 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); + url_fclose(handle); - nread = url_fread(buffer, 1,sizeof(buffer), handle); - fwrite(buffer,1,nread,outf); - - - url_fclose(handle); - - fclose(outf); + fclose(outf); - return 0;/* all done */ + return 0;/* all done */ } -- cgit v1.2.1 From 34498c13be6ef1f3308d39508884418a1123ca81 Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Sun, 7 Nov 2010 03:39:31 +0100 Subject: fix snapshot generation --- docs/examples/Makefile.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 51c96a5a8..62f0c1b22 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -4,7 +4,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ https multi-app multi-debugcallback multi-double multi-post multi-single \ persistant post-callback postit2 sepheaders simple simplepost simplessl \ sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard \ - smtp-multi.c + smtp-multi # These examples require external dependencies that may not be commonly # available on POSIX systems, so don't bother attempting to compile them here. -- cgit v1.2.1 From 0a2edfc348cbd70940be306e39c1cda0af255a68 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Fri, 12 Nov 2010 23:26:57 +0100 Subject: version-check.pl: display version number for symbols This script is the start of a helper tool that scans a source code and outputs the most recent libcurl version it finds symbols for. Meaning that if there's no conditions in the code, that's the earliest libcurl version the scanned code requires. It is not added to the Makefile.am yet as it is still a bit crude, but I'm committing it to keep it and allow us to work on it. --- docs/examples/version-check.pl | 69 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 docs/examples/version-check.pl (limited to 'docs/examples') diff --git a/docs/examples/version-check.pl b/docs/examples/version-check.pl new file mode 100755 index 000000000..f8f4f9d24 --- /dev/null +++ b/docs/examples/version-check.pl @@ -0,0 +1,69 @@ +#!/usr/bin/env perl + +open(S, "<../libcurl/symbols-in-versions") || die; + +my %doc; +my %rem; +while(<S>) { + if(/(^CURL[^ \n]*) *(.*)/) { + my ($sym, $rest)=($1, $2); + my @a=split(/ +/, $rest); + + $doc{$sym}=$a[0]; # when it was introduced + + if($a[2]) { + # this symbol is documented to have been present the last time + # in this release + $rem{$sym}=$a[2]; + } + } + +} + +close(S); + +sub age { + my ($ver)=@_; + + my @s=split(/\./, $ver); + return $s[0]*10000+$s[1]*100+$s[2]; +} + +my %used; +open(C, "<$ARGV[0]") || die; + +while(<C>) { + if(/\W(CURL[_A-Z0-9v]+)\W/) { + #print "$1\n"; + $used{$1}++; + } +} + +close(C); + +sub sortversions { + my $r = age($doc{$a}) <=> age($doc{$b}); + if(!$r) { + $r = $a cmp $b; + } + return $r; +} + +my @recent = reverse sort sortversions keys %used; + +# the most recent symbol +my $newsym = $recent[0]; +# the most recent version +my $newver = $doc{$newsym}; + +print "The scanned source uses these symbols introduced in $newver:\n"; + +for my $w (@recent) { + if($doc{$w} eq $newver) { + printf " $w\n"; + next; + } + last; +} + + -- cgit v1.2.1 From 46041ee91845846b3058454f8fa989674885f3c5 Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Fri, 19 Nov 2010 17:09:15 -0800 Subject: Added a couple examples that were missing from the tar ball --- docs/examples/Makefile.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 62f0c1b22..34c1c0f1d 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -10,4 +10,5 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ # available on POSIX systems, so don't bother attempting to compile them here. COMPLICATED_EXAMPLES = curlgtk.c curlx.c htmltitle.cc cacertinmem.c \ ftpuploadresume.c ghiper.c hiperfifo.c htmltidy.c multithread.c \ - opensslthreadlock.c sampleconv.c synctime.c threaded-ssl.c evhiperfifo.c + opensslthreadlock.c sampleconv.c synctime.c threaded-ssl.c evhiperfifo.c \ + smooth-gtk-thread.c version-check.pl -- cgit v1.2.1 From 5db0a412ff6972e51ccddaf1e8d6a27c8de4990f Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Sun, 28 Nov 2010 23:11:14 +0100 Subject: atoi: remove atoi usage --- docs/examples/chkspeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/chkspeed.c b/docs/examples/chkspeed.c index d802469b8..00db5bf1d 100644 --- a/docs/examples/chkspeed.c +++ b/docs/examples/chkspeed.c @@ -71,7 +71,7 @@ int main(int argc, char *argv[]) } else if (strncasecmp(*argv, "-T", 2) == 0) { prttime = 1; } else if (strncasecmp(*argv, "-M=", 3) == 0) { - int m = atoi(*argv + 3); + long m = strtol(argv+3, NULL, 10); switch(m) { case 1: url = URL_1M; break; -- cgit v1.2.1 From d97fa56fd47c4b35f95177097458fcb9c54e1615 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Fri, 3 Dec 2010 14:10:04 +0100 Subject: version-check: added brief documentation and the traditional source header --- docs/examples/version-check.pl | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/version-check.pl b/docs/examples/version-check.pl index f8f4f9d24..9b6a2684c 100755 --- a/docs/examples/version-check.pl +++ b/docs/examples/version-check.pl @@ -1,4 +1,40 @@ #!/usr/bin/env perl +#*************************************************************************** +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ +# \___|\___/|_| \_\_____| +# +# Copyright (C) 1998 - 2010, 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. +# +# 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. +# +########################################################################### + +# This script accepts a source file as input on the command line. +# +# It first loads the 'symbols-in-versions' document and stores a lookup +# table for all known symbols for which version they were introduced. +# +# It then scans the given source file to dig up all symbols starting with CURL. +# Finally, it sorts the internal list of found symbols (using the version +# number as sort key) and then it outputs the most recent version number and +# the symbols from that version that are used. +# +# Usage: +# +# version-check.pl [source file] +# open(S, "<../libcurl/symbols-in-versions") || die; -- cgit v1.2.1 From 8f50a404f9752acb7262b1854e1e29fcca0fb3fb Mon Sep 17 00:00:00 2001 From: Brad Hards <bradh@frogmouth.net> Date: Fri, 17 Dec 2010 00:06:03 +0100 Subject: chkspeed: bad strtol() call for -M option Bug: http://curl.haxx.se/mail/lib-2010-12/0192.html --- docs/examples/chkspeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/chkspeed.c b/docs/examples/chkspeed.c index 00db5bf1d..4305bde8d 100644 --- a/docs/examples/chkspeed.c +++ b/docs/examples/chkspeed.c @@ -71,7 +71,7 @@ int main(int argc, char *argv[]) } else if (strncasecmp(*argv, "-T", 2) == 0) { prttime = 1; } else if (strncasecmp(*argv, "-M=", 3) == 0) { - long m = strtol(argv+3, NULL, 10); + long m = strtol((*argv)+3, NULL, 10); switch(m) { case 1: url = URL_1M; break; -- cgit v1.2.1 From 76c54bd1291bc93ed153bb4e8c8dc6e0122f6784 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Fri, 17 Dec 2010 00:07:34 +0100 Subject: example: fix compiler warnings in fopen.c --- docs/examples/fopen.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index e4505bf58..6fe5c0f9f 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -68,8 +68,8 @@ struct fcurl_data } handle; /* handle */ char *buffer; /* buffer to store cached data*/ - int buffer_len; /* currently allocated buffers length */ - int buffer_pos; /* end of data in buffer*/ + size_t buffer_len; /* currently allocated buffers length */ + size_t buffer_pos; /* end of data in buffer*/ int still_running; /* Is background url fetch still in progress */ }; @@ -80,7 +80,7 @@ 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); -char * url_fgets(char *ptr, int size, URL_FILE *file); +char * url_fgets(char *ptr, size_t size, URL_FILE *file); void url_rewind(URL_FILE *file); /* we use a global one for convenience */ @@ -93,7 +93,7 @@ static size_t write_callback(char *buffer, void *userp) { char *newbuff; - int rembuff; + size_t rembuff; URL_FILE *url = (URL_FILE *)userp; size *= nitems; @@ -121,7 +121,7 @@ static size_t write_callback(char *buffer, } /* use to attempt to fill the read buffer up to requested number of bytes */ -static int fill_buffer(URL_FILE *file,int want,int waittime) +static int fill_buffer(URL_FILE *file, size_t want) { fd_set fdread; fd_set fdwrite; @@ -323,7 +323,7 @@ size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) case CFTYPE_CURL: want = nmemb * size; - fill_buffer(file,want,1); + fill_buffer(file,want); /* check if theres data in the buffer - if not fill_buffer() * either errored or EOF */ @@ -351,10 +351,10 @@ size_t url_fread(void *ptr, size_t size, size_t nmemb, URL_FILE *file) return want; } -char *url_fgets(char *ptr, int size, URL_FILE *file) +char *url_fgets(char *ptr, size_t size, URL_FILE *file) { - int want = size - 1;/* always need to leave room for zero termination */ - int loop; + size_t want = size - 1;/* always need to leave room for zero termination */ + size_t loop; switch(file->type) { case CFTYPE_FILE: @@ -362,7 +362,7 @@ char *url_fgets(char *ptr, int size, URL_FILE *file) break; case CFTYPE_CURL: - fill_buffer(file,want,1); + fill_buffer(file,want); /* check if theres data in the buffer - if not fill either errored or * EOF */ -- cgit v1.2.1 From 37a22d474957ef0fe6e62be7f4fc10784760988b Mon Sep 17 00:00:00 2001 From: Brad Hards <bradh@frogmouth.net> Date: Wed, 15 Dec 2010 19:27:28 +1100 Subject: Docs: add simple SMTP example Add a simple SMTP example program, patterned after some of the existing examples, and the curl application. This version addresses issues raised by David Woodhouse on comments in the simplesmtp.c example. --- docs/examples/Makefile.inc | 2 +- docs/examples/simplesmtp.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 docs/examples/simplesmtp.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 34c1c0f1d..a9379f745 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -4,7 +4,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ https multi-app multi-debugcallback multi-double multi-post multi-single \ persistant post-callback postit2 sepheaders simple simplepost simplessl \ sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard \ - smtp-multi + smtp-multi simplesmtp # 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/simplesmtp.c b/docs/examples/simplesmtp.c new file mode 100644 index 000000000..4144ed647 --- /dev/null +++ b/docs/examples/simplesmtp.c @@ -0,0 +1,71 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + */ + +#include <stdio.h> +#include <string.h> +#include <curl/curl.h> + +int main(void) +{ + CURL *curl; + CURLcode res; + struct curl_slist *recipients = NULL; + + /* value for envelope reverse-path */ + static const char *from = "bradh@example.com"; + + /* this becomes the envelope forward-path */ + static const char *to = "bradh@example.net"; + + curl = curl_easy_init(); + if(curl) { + /* this is the URL for your mailserver - you can also use an smtps:// URL + * here */ + curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.net."); + + /* Note that this option isn't strictly required, omitting it will result in + * libcurl will sent the MAIL FROM command with no sender data. All + * autoresponses should have an empty reverse-path, and should be directed + * to the address in the reverse-path which triggered them. Otherwise, they + * could cause an endless loop. See RFC 5321 Section 4.5.5 for more details. + */ + curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from); + + /* Note that the CURLOPT_MAIL_RCPT takes a list, not a char array. */ + recipients = curl_slist_append(recipients, to); + curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients); + + /* You provide the payload (headers and the body of the message) as the + * "data" element. There are two choices, either: + * - provide a callback function and specify the function name using the + * CURLOPT_READFUNCTION option; or + * - just provide a FILE pointer that can be used to read the data from. + * The easiest case is just to read from standard input, (which is available + * as a FILE pointer) as shown here. + */ + curl_easy_setopt(curl, CURLOPT_READDATA, stdin); + + /* send the message (including headers) */ + res = curl_easy_perform(curl); + + /* 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 + * 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. + */ + curl_easy_cleanup(curl); + } + return 0; +} -- cgit v1.2.1 From 57523e3578b17c07b0fbf7b22063544ade3df799 Mon Sep 17 00:00:00 2001 From: Brad Hards <bradh@frogmouth.net> Date: Fri, 17 Dec 2010 22:55:58 +0100 Subject: smtp-tls: new example This example shows how to send SMTP with TLS --- docs/examples/Makefile.inc | 2 +- docs/examples/smtp-tls.c | 135 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 docs/examples/smtp-tls.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index a9379f745..9a2b48ea1 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -4,7 +4,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ https multi-app multi-debugcallback multi-double multi-post multi-single \ persistant post-callback postit2 sepheaders simple simplepost simplessl \ sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard \ - smtp-multi simplesmtp + smtp-multi simplesmtp smtp-tls # 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/smtp-tls.c b/docs/examples/smtp-tls.c new file mode 100644 index 000000000..58719ade2 --- /dev/null +++ b/docs/examples/smtp-tls.c @@ -0,0 +1,135 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + */ + +#include <stdio.h> +#include <string.h> +#include <curl/curl.h> + +/* This is a simple example showing how to send mail using libcurl's SMTP + * capabilities. It builds on the simplesmtp.c example, adding some + * authentication and transport security. + */ + +#define FROM "sender@example.org" +#define TO "addressee@example.net" +#define CC "info@example.org" + +static const char *payload_text[]={ + "Date: Mon, 29 Nov 2010 21:54:29 +1100\n", + "To: " TO "\n", + "From: " FROM "(Example User)\n", + "Cc: " CC "(Another example User)\n" + "Subject: SMTP TLS example message\n", + "\n", /* empty line to divide headers from body, see RFC5322 */ + "The body of the message starts here.\n", + "\n", + "It could be a lot of lines, could be MIME encoded, whatever.\n", + "Check RFC5322.\n", + NULL +}; + +struct upload_status { + int lines_read; +}; + +static size_t payload_source(void *ptr, size_t size, size_t nmemb, void *userp) +{ + struct upload_status *upload_ctx = (struct upload_status *)userp; + const char *data; + + if ((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { + return 0; + } + + data = payload_text[upload_ctx->lines_read]; + + if (data) { + size_t len = strlen(data); + memcpy(ptr, data, len); + upload_ctx->lines_read ++; + return len; + } + return 0; +} + + +int main(void) +{ + CURL *curl; + CURLcode res; + struct curl_slist *recipients = NULL; + struct upload_status upload_ctx; + + upload_ctx.lines_read = 0; + + curl = curl_easy_init(); + if (curl) { + /* This is the URL for your mailserver. Note the use of port 587 here, + * instead of the normal SMTP port (25). Port 587 is commonly used for + * secure mail submission (see RFC4403), but you should use whatever + * matches your server configuration. */ + curl_easy_setopt(curl, CURLOPT_URL, "smtp://mainserver.example.net:587"); + + /* In this example, we'll start with a plain text connection, and upgrade + * to Transport Layer Security (TLS) using the STARTTLS command. Be careful + * of using CURLUSESSL_TRY here, because if TLS upgrade fails, the transfer + * will continue anyway - see the security discussion in the libcurl + * tutorial for more details. */ + curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL); + + /* If your server doesn't have a valid certificate, then you can disable + * part of the Transport Layer Security protection by setting the + * CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST options to 0 (false). + * curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); + * curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); + * 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. + */ + curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem"); + + /* A common reason for requiring transport security is to protect + * authentication details (user names and passwords) from being "snooped" + * on the network. Here is how the user name and password are provided: */ + curl_easy_setopt(curl, CURLOPT_USERNAME, "user@example.net"); + curl_easy_setopt(curl, CURLOPT_PASSWORD, "P@ssw0rd"); + + /* value for envelope reverse-path */ + curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM); + /* Add two recipients, in this particular case they correspond to the + * To: and Cc: addressees in the header, but they could be any kind of + * recipient. */ + recipients = curl_slist_append(recipients, TO); + recipients = curl_slist_append(recipients, CC); + curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients); + + /* In this case, we're using a callback function to specify the data. You + * could just use the CURLOPT_READDATA option to specify a FILE pointer to + * read from. + */ + curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source); + curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx); + + /* Since the traffic will be encrypted, it is very useful to turn on debug + * information within libcurl to see what is happening during the transfer. + */ + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + + /* send the message (including headers) */ + res = curl_easy_perform(curl); + + /* free the list of recipients and clean up */ + curl_slist_free_all(recipients); + curl_easy_cleanup(curl); + } + return 0; +} -- cgit v1.2.1 From 8219bc9e19c78ec4617ae5311b4ea64c49763ff6 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Fri, 17 Dec 2010 23:34:06 +0100 Subject: examples: build all examples easier --- docs/examples/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 8d92f7311..c5f97856b 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -34,4 +34,4 @@ LDADD = $(LIBDIR)/libcurl.la # Makefile.inc provides the check_PROGRAMS and COMPLICATED_EXAMPLES defines include Makefile.inc - +all: $(check_PROGRAMS) -- cgit v1.2.1 From 9583b4af9057c9e35ec3dd3270d4c4813b5f7aaa Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Fri, 17 Dec 2010 23:34:26 +0100 Subject: examples: fix compiler warnings --- docs/examples/certinfo.c | 5 ++++- docs/examples/debug.c | 4 ++-- docs/examples/ftpgetinfo.c | 4 +++- docs/examples/ftpgetresp.c | 2 +- docs/examples/ftpupload.c | 2 +- docs/examples/getinmemory.c | 4 ++-- docs/examples/multi-app.c | 2 +- docs/examples/multi-debugcallback.c | 7 ++++--- docs/examples/multi-double.c | 2 +- docs/examples/multi-post.c | 2 +- docs/examples/multi-single.c | 2 +- docs/examples/persistant.c | 2 +- docs/examples/sepheaders.c | 2 +- docs/examples/simplessl.c | 4 ++-- 14 files changed, 25 insertions(+), 19 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/certinfo.c b/docs/examples/certinfo.c index ceb0ac2b0..2e331a415 100644 --- a/docs/examples/certinfo.c +++ b/docs/examples/certinfo.c @@ -9,9 +9,12 @@ static size_t wrfu(void *ptr, size_t size, size_t nmemb, void *stream) { + (void)stream; + (void)ptr; return size * nmemb; } -int main(int argc, char **argv) + +int main(void) { CURL *curl; CURLcode res; diff --git a/docs/examples/debug.c b/docs/examples/debug.c index cc6848178..1e04acb51 100644 --- a/docs/examples/debug.c +++ b/docs/examples/debug.c @@ -28,12 +28,12 @@ void dump(const char *text, /* without the hex output, we can fit more on screen */ width = 0x40; - fprintf(stream, "%s, %010.10ld bytes (0x%08.8lx)\n", + fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)\n", text, (long)size, (long)size); for(i=0; i<size; i+= width) { - fprintf(stream, "%04.4lx: ", (long)i); + fprintf(stream, "%4.4lx: ", (long)i); if(!nohex) { /* hex not disabled, show it */ diff --git a/docs/examples/ftpgetinfo.c b/docs/examples/ftpgetinfo.c index c4e234f18..95c6f8ac8 100644 --- a/docs/examples/ftpgetinfo.c +++ b/docs/examples/ftpgetinfo.c @@ -21,6 +21,8 @@ static size_t throw_away(void *ptr, size_t size, size_t nmemb, void *data) { + (void)ptr; + (void)data; /* we are not interested in the headers itself, so we only return the size we would have saved ... */ return (size_t)(size * nmemb); @@ -58,7 +60,7 @@ int main(void) if((CURLE_OK == res) && filetime) printf("filetime %s: %s", filename, ctime(&filetime)); res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &filesize); - if((CURLE_OK == res) && filesize) + if((CURLE_OK == res) && (filesize>0)) printf("filesize %s: %0.0f bytes\n", filename, filesize); } else { /* we failed */ diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index 2122c4f68..c78832f3c 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -27,7 +27,7 @@ write_response(void *ptr, size_t size, size_t nmemb, void *data) return fwrite(ptr, size, nmemb, writehere); } -int main(int argc, char **argv) +int main(void) { CURL *curl; CURLcode res; diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index f1f66c0a1..bee62494c 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -48,7 +48,7 @@ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) return retcode; } -int main(int argc, char **argv) +int main(void) { CURL *curl; CURLcode res; diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 635a936ba..85b049483 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -43,7 +43,7 @@ WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) } -int main(int argc, char **argv) +int main(void) { CURL *curl_handle; @@ -87,7 +87,7 @@ int main(int argc, char **argv) * you're done with it, you should free() it as a nice application. */ - printf("%lu bytes retrieved\n", chunk.size); + printf("%lu bytes retrieved\n", (long)chunk.size); if(chunk.memory) free(chunk.memory); diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index 6ba131830..29b07aba1 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -27,7 +27,7 @@ #define HTTP_HANDLE 0 /* Index for the HTTP transfer */ #define FTP_HANDLE 1 /* Index for the FTP transfer */ -int main(int argc, char **argv) +int main(void) { CURL *handles[HANDLECOUNT]; CURLM *multi_handle; diff --git a/docs/examples/multi-debugcallback.c b/docs/examples/multi-debugcallback.c index 529c3d9bb..773faec67 100644 --- a/docs/examples/multi-debugcallback.c +++ b/docs/examples/multi-debugcallback.c @@ -37,12 +37,12 @@ void dump(const char *text, /* without the hex output, we can fit more on screen */ width = 0x40; - fprintf(stream, "%s, %010.10ld bytes (0x%08.8lx)\n", + fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)\n", text, (long)size, (long)size); for(i=0; i<size; i+= width) { - fprintf(stream, "%04.4lx: ", (long)i); + fprintf(stream, "%4.4lx: ", (long)i); if(!nohex) { /* hex not disabled, show it */ @@ -79,6 +79,7 @@ int my_trace(CURL *handle, curl_infotype type, { const char *text; + (void)userp; (void)handle; /* prevent compiler warning */ switch (type) { @@ -108,7 +109,7 @@ int my_trace(CURL *handle, curl_infotype type, /* * Simply download a HTTP file. */ -int main(int argc, char **argv) +int main(void) { CURL *http_handle; CURLM *multi_handle; diff --git a/docs/examples/multi-double.c b/docs/examples/multi-double.c index 3ea106bf7..990fec36a 100644 --- a/docs/examples/multi-double.c +++ b/docs/examples/multi-double.c @@ -22,7 +22,7 @@ /* * Simply download two HTTP files! */ -int main(int argc, char **argv) +int main(void) { CURL *http_handle; CURL *http_handle2; diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index 8b4f03e9e..13cfe6ff4 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -15,7 +15,7 @@ #include <curl/curl.h> -int main(int argc, char *argv[]) +int main(void) { CURL *curl; diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c index f248afe76..ca632e08c 100644 --- a/docs/examples/multi-single.c +++ b/docs/examples/multi-single.c @@ -22,7 +22,7 @@ /* * Simply download a HTTP file. */ -int main(int argc, char **argv) +int main(void) { CURL *http_handle; CURLM *multi_handle; diff --git a/docs/examples/persistant.c b/docs/examples/persistant.c index 177ada359..53710cde4 100644 --- a/docs/examples/persistant.c +++ b/docs/examples/persistant.c @@ -11,7 +11,7 @@ #include <unistd.h> #include <curl/curl.h> -int main(int argc, char **argv) +int main(void) { CURL *curl; CURLcode res; diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index e0c4cbbb7..3fb9045e1 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -21,7 +21,7 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) return written; } -int main(int argc, char **argv) +int main(void) { CURL *curl_handle; static const char *headerfilename = "head.out"; diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index db3accaaa..a02c2ae32 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -32,7 +32,7 @@ */ -int main(int argc, char **argv) +int main(void) { CURL *curl; CURLcode res; @@ -47,7 +47,7 @@ int main(int argc, char **argv) const char *pEngine; -#if USE_ENGINE +#ifdef USE_ENGINE pKeyName = "rsa_test"; pKeyType = "ENG"; pEngine = "chil"; /* for nChiper HSM... */ -- cgit v1.2.1 From 476b1a079b4f2f2f4e2bb9ccdc1b86ed27b985f0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Fri, 17 Dec 2010 23:35:04 +0100 Subject: gitignore: ignore the new example execs --- docs/examples/.gitignore | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/.gitignore b/docs/examples/.gitignore index 3acd509b3..8836a7b98 100644 --- a/docs/examples/.gitignore +++ b/docs/examples/.gitignore @@ -29,4 +29,7 @@ sendrecv sepheaders simple simplepost +simplesmtp simplessl +smtp-multi +smtp-tls -- cgit v1.2.1 From d2395f962dfbeb546b8a64eec88271da48fa66de Mon Sep 17 00:00:00 2001 From: Brad Hards <bradh@frogmouth.net> Date: Sat, 18 Dec 2010 17:07:57 +0100 Subject: smtp-tls: add Message-ID: header --- docs/examples/smtp-tls.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/smtp-tls.c b/docs/examples/smtp-tls.c index 58719ade2..a8baade58 100644 --- a/docs/examples/smtp-tls.c +++ b/docs/examples/smtp-tls.c @@ -24,7 +24,8 @@ static const char *payload_text[]={ "Date: Mon, 29 Nov 2010 21:54:29 +1100\n", "To: " TO "\n", "From: " FROM "(Example User)\n", - "Cc: " CC "(Another example User)\n" + "Cc: " CC "(Another example User)\n", + "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>", "Subject: SMTP TLS example message\n", "\n", /* empty line to divide headers from body, see RFC5322 */ "The body of the message starts here.\n", -- cgit v1.2.1 From bcfb9ea34cc7cddbbf74376aa16043681e4745a7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Sat, 18 Dec 2010 17:12:44 +0100 Subject: examples: socket type cleanup --- docs/examples/evhiperfifo.c | 2 +- docs/examples/hiperfifo.c | 2 +- docs/examples/sendrecv.c | 15 ++++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/evhiperfifo.c b/docs/examples/evhiperfifo.c index 6cdccf839..6a4a5ef2d 100644 --- a/docs/examples/evhiperfifo.c +++ b/docs/examples/evhiperfifo.c @@ -367,7 +367,7 @@ static int init_fifo (GlobalInfo *g) { struct stat st; static const char *fifo = "hiper.fifo"; - int sockfd; + curl_socket_t sockfd; fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo); if ( lstat (fifo, &st) == 0 ) diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index c9096871b..a885c0ce4 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -350,7 +350,7 @@ static int init_fifo (GlobalInfo *g) { struct stat st; static const char *fifo = "hiper.fifo"; - int sockfd; + curl_socket_t sockfd; fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo); if (lstat (fifo, &st) == 0) { diff --git a/docs/examples/sendrecv.c b/docs/examples/sendrecv.c index ad5ddd115..499fadb92 100644 --- a/docs/examples/sendrecv.c +++ b/docs/examples/sendrecv.c @@ -14,7 +14,7 @@ #include <curl/curl.h> /* Auxiliary function that waits on the socket. */ -static int wait_on_socket(int sockfd, int for_recv, long timeout_ms) +static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms) { struct timeval tv; fd_set infd, outfd, errfd; @@ -49,7 +49,8 @@ int main(void) CURLcode res; /* Minimalistic http request */ const char *request = "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n"; - int sockfd; /* socket */ + curl_socket_t sockfd; /* socket */ + long sockextr; size_t iolen; curl = curl_easy_init(); @@ -65,9 +66,11 @@ int main(void) return 1; } - /* Extract the socket from the curl handle - we'll need it - * for waiting */ - res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockfd); + /* Extract the socket from the curl handle - we'll need it for waiting. + * Note that this API takes a pointer to a 'long' while we use + * curl_socket_t for sockets otherwise. + */ + res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockextr); if(CURLE_OK != res) { @@ -75,6 +78,8 @@ int main(void) return 1; } + sockfd = sockextr; + /* wait for the socket to become ready for sending */ if(!wait_on_socket(sockfd, 0, 60000L)) { -- cgit v1.2.1 From 0e944fb24e5ac49e3ff863f89ae83ad10051525b Mon Sep 17 00:00:00 2001 From: Brad Hards <bradh@frogmouth.net> Date: Wed, 22 Dec 2010 11:57:48 +1100 Subject: smtp-tls: add a missing newline Without this you won't get the next (Subject) line. --- docs/examples/smtp-tls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/smtp-tls.c b/docs/examples/smtp-tls.c index a8baade58..97119c568 100644 --- a/docs/examples/smtp-tls.c +++ b/docs/examples/smtp-tls.c @@ -25,7 +25,7 @@ static const char *payload_text[]={ "To: " TO "\n", "From: " FROM "(Example User)\n", "Cc: " CC "(Another example User)\n", - "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>", + "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>\n", "Subject: SMTP TLS example message\n", "\n", /* empty line to divide headers from body, see RFC5322 */ "The body of the message starts here.\n", -- cgit v1.2.1 From 7dc9393d3b1d78f9bc4349b28cff3c58b76a0d2b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Thu, 23 Dec 2010 22:18:16 +0100 Subject: smtp-multi: put recipient within <brackets> Even if libcurl might to do it for us, it is more correct. --- docs/examples/smtp-multi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/smtp-multi.c b/docs/examples/smtp-multi.c index 239172ba9..e13108a43 100644 --- a/docs/examples/smtp-multi.c +++ b/docs/examples/smtp-multi.c @@ -21,7 +21,7 @@ #define SMTPSERVER "smtp.example.com" #define SMTPPORT ":587" /* it is a colon+port string, but you can set it to "" to use the default port */ -#define RECEPIENT "receipient@example.com" +#define RECEPIENT "<receipient@example.com>" #define MAILFROM "<realuser@example.com>" #define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000 -- cgit v1.2.1 From 60765493047cba21e76888e36efaf0cba43ccf6d Mon Sep 17 00:00:00 2001 From: Brad Hards <bradh@frogmouth.net> Date: Sat, 25 Dec 2010 11:54:41 +1100 Subject: Add angle brackets to addresses in easy SMTP examples, as for smtp-multi example. --- docs/examples/simplesmtp.c | 4 ++-- docs/examples/smtp-tls.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/simplesmtp.c b/docs/examples/simplesmtp.c index 4144ed647..0c1f7ff87 100644 --- a/docs/examples/simplesmtp.c +++ b/docs/examples/simplesmtp.c @@ -18,10 +18,10 @@ int main(void) struct curl_slist *recipients = NULL; /* value for envelope reverse-path */ - static const char *from = "bradh@example.com"; + static const char *from = "<bradh@example.com>"; /* this becomes the envelope forward-path */ - static const char *to = "bradh@example.net"; + static const char *to = "<bradh@example.net>"; curl = curl_easy_init(); if(curl) { diff --git a/docs/examples/smtp-tls.c b/docs/examples/smtp-tls.c index 97119c568..276908861 100644 --- a/docs/examples/smtp-tls.c +++ b/docs/examples/smtp-tls.c @@ -16,9 +16,9 @@ * authentication and transport security. */ -#define FROM "sender@example.org" -#define TO "addressee@example.net" -#define CC "info@example.org" +#define FROM "<sender@example.org>" +#define TO "<addressee@example.net>" +#define CC "<info@example.org>" static const char *payload_text[]={ "Date: Mon, 29 Nov 2010 21:54:29 +1100\n", -- cgit v1.2.1 From 879914def3db9f4139b64be20370fd65bdb1f1a4 Mon Sep 17 00:00:00 2001 From: Brad Hards <bradh@frogmouth.net> Date: Sat, 25 Dec 2010 11:56:04 +1100 Subject: Use angle address, as for the rest of the example. Also spelling fix for RECIPIENT #define. --- docs/examples/smtp-multi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/smtp-multi.c b/docs/examples/smtp-multi.c index e13108a43..4d1dfc4fb 100644 --- a/docs/examples/smtp-multi.c +++ b/docs/examples/smtp-multi.c @@ -21,7 +21,7 @@ #define SMTPSERVER "smtp.example.com" #define SMTPPORT ":587" /* it is a colon+port string, but you can set it to "" to use the default port */ -#define RECEPIENT "<receipient@example.com>" +#define RECIPIENT "<recipient@example.com>" #define MAILFROM "<realuser@example.com>" #define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000 @@ -99,9 +99,9 @@ int main(void) if(!mcurl) return 2; - rcpt_list = curl_slist_append(rcpt_list, RECEPIENT); + rcpt_list = curl_slist_append(rcpt_list, RECIPIENT); /* more addresses can be added here - rcpt_list = curl_slist_append(rcpt_list, "others@example.com"); + rcpt_list = curl_slist_append(rcpt_list, "<others@example.com>"); */ curl_easy_setopt(curl, CURLOPT_URL, "smtp://" SMTPSERVER SMTPPORT); -- cgit v1.2.1 From 1aeb635cdd296c16acb375a4a83a78f13166ccab Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Thu, 10 Mar 2011 11:48:02 +0100 Subject: sources: update source headers All C and H files now (should) feature the proper project curl source code header, which includes basic info, a copyright statement and some basic disclaimers. --- docs/examples/10-at-a-time.c | 17 +++++++++++++++-- docs/examples/anyauthput.c | 18 +++++++++++++++--- docs/examples/cacertinmem.c | 17 +++++++++++++++-- docs/examples/certinfo.c | 24 +++++++++++++++++++++--- docs/examples/chkspeed.c | 17 +++++++++++++++-- docs/examples/cookie_interface.c | 19 ++++++++++++++++--- docs/examples/debug.c | 18 +++++++++++++++--- docs/examples/evhiperfifo.c | 17 +++++++++++++++-- docs/examples/fileupload.c | 18 +++++++++++++++--- docs/examples/ftp-wildcard.c | 18 +++++++++++++++--- docs/examples/ftpget.c | 18 +++++++++++++++--- docs/examples/ftpgetinfo.c | 18 +++++++++++++++--- docs/examples/ftpgetresp.c | 18 +++++++++++++++--- docs/examples/ftpupload.c | 18 +++++++++++++++--- docs/examples/ftpuploadresume.c | 17 +++++++++++++++-- docs/examples/getinfo.c | 18 +++++++++++++++--- docs/examples/getinmemory.c | 17 +++++++++++++++-- docs/examples/ghiper.c | 17 +++++++++++++++-- docs/examples/hiperfifo.c | 21 +++++++++++++++++---- docs/examples/htmltidy.c | 17 +++++++++++++++-- docs/examples/http-post.c | 18 +++++++++++++++--- docs/examples/httpcustomheader.c | 18 +++++++++++++++--- docs/examples/httpput.c | 18 +++++++++++++++--- docs/examples/https.c | 18 +++++++++++++++--- docs/examples/multi-app.c | 18 +++++++++++++++--- docs/examples/multi-debugcallback.c | 19 +++++++++++++++---- docs/examples/multi-double.c | 18 ++++++++++++++---- docs/examples/multi-post.c | 20 ++++++++++++++++---- docs/examples/multi-single.c | 18 +++++++++++++++--- docs/examples/multithread.c | 18 +++++++++++++++--- docs/examples/opensslthreadlock.c | 17 +++++++++++++++-- docs/examples/persistant.c | 18 +++++++++++++++--- docs/examples/post-callback.c | 18 +++++++++++++++--- docs/examples/postit2.c | 17 +++++++++++++++-- docs/examples/sampleconv.c | 17 +++++++++++++++-- docs/examples/sendrecv.c | 18 +++++++++++++++--- docs/examples/sepheaders.c | 18 +++++++++++++++--- docs/examples/simple.c | 18 +++++++++++++++--- docs/examples/simplepost.c | 18 +++++++++++++++--- docs/examples/simplesmtp.c | 18 +++++++++++++++--- docs/examples/simplessl.c | 18 +++++++++++++++--- docs/examples/smooth-gtk-thread.c | 17 +++++++++++++++-- docs/examples/smtp-multi.c | 17 +++++++++++++++-- docs/examples/smtp-tls.c | 18 +++++++++++++++--- docs/examples/synctime.c | 17 +++++++++++++++-- docs/examples/threaded-ssl.c | 17 +++++++++++++++-- 46 files changed, 699 insertions(+), 127 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/10-at-a-time.c b/docs/examples/10-at-a-time.c index b215cbfd4..a85fff46f 100644 --- a/docs/examples/10-at-a-time.c +++ b/docs/examples/10-at-a-time.c @@ -1,12 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * Example application source code using the multi interface to download many + * 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. + * + * 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. + * + ***************************************************************************/ +/* Example application source code using the multi interface to download many * files, but with a capped maximum amount of simultaneous transfers. * * Written by Michael Wallner diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index cec9fede5..6b3d74a4b 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <fcntl.h> #ifdef WIN32 diff --git a/docs/examples/cacertinmem.c b/docs/examples/cacertinmem.c index 387029501..051afbca9 100644 --- a/docs/examples/cacertinmem.c +++ b/docs/examples/cacertinmem.c @@ -1,12 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * Example using a "in core" PEM certificate to retrieve a https page. + * 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. + * + * 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. + * + ***************************************************************************/ +/* Example using a "in core" PEM certificate to retrieve a https page. * Written by Theo Borm */ diff --git a/docs/examples/certinfo.c b/docs/examples/certinfo.c index 2e331a415..02558d98c 100644 --- a/docs/examples/certinfo.c +++ b/docs/examples/certinfo.c @@ -1,6 +1,24 @@ -/***************************************************************************** - */ - +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/chkspeed.c b/docs/examples/chkspeed.c index 4305bde8d..fbcb1f764 100644 --- a/docs/examples/chkspeed.c +++ b/docs/examples/chkspeed.c @@ -1,12 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * Example source code to show how the callback function can be used to + * 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. + * + * 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. + * + ***************************************************************************/ +/* 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 * amount of downloaded bytes, the time used for the whole download, and diff --git a/docs/examples/cookie_interface.c b/docs/examples/cookie_interface.c index 9f1e629e1..ac3685fd8 100644 --- a/docs/examples/cookie_interface.c +++ b/docs/examples/cookie_interface.c @@ -1,12 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * This example shows usage of simple cookie interface. - */ + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ +/* This example shows usage of simple cookie interface. */ #include <stdio.h> #include <string.h> diff --git a/docs/examples/debug.c b/docs/examples/debug.c index 1e04acb51..270b497af 100644 --- a/docs/examples/debug.c +++ b/docs/examples/debug.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/evhiperfifo.c b/docs/examples/evhiperfifo.c index 6a4a5ef2d..6de4dadc7 100644 --- a/docs/examples/evhiperfifo.c +++ b/docs/examples/evhiperfifo.c @@ -1,12 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * Example application source code using the multi socket interface to + * 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. + * + * 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. + * + ***************************************************************************/ +/* Example application source code using the multi socket interface to * download many files at once. * * This example features the same basic functionality as hiperfifo.c does, diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c index cdec75137..756367b6b 100644 --- a/docs/examples/fileupload.c +++ b/docs/examples/fileupload.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <curl/curl.h> #include <sys/stat.h> diff --git a/docs/examples/ftp-wildcard.c b/docs/examples/ftp-wildcard.c index 0186a38af..fd92ca651 100644 --- a/docs/examples/ftp-wildcard.c +++ b/docs/examples/ftp-wildcard.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <curl/curl.h> #include <stdio.h> diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 3c3888a20..7b5e0d7cf 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/ftpgetinfo.c b/docs/examples/ftpgetinfo.c index 95c6f8ac8..52f87d633 100644 --- a/docs/examples/ftpgetinfo.c +++ b/docs/examples/ftpgetinfo.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <string.h> diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index c78832f3c..ea882a00f 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index bee62494c..305734d5d 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <string.h> diff --git a/docs/examples/ftpuploadresume.c b/docs/examples/ftpuploadresume.c index 81a790a11..0560b54dc 100644 --- a/docs/examples/ftpuploadresume.c +++ b/docs/examples/ftpuploadresume.c @@ -1,12 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * Upload to FTP, resuming failed transfers + * 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. + * + * 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. + * + ***************************************************************************/ +/* Upload to FTP, resuming failed transfers * * Compile for MinGW like this: * gcc -Wall -pedantic -std=c99 ftpuploadwithresume.c -o ftpuploadresume.exe diff --git a/docs/examples/getinfo.c b/docs/examples/getinfo.c index 0d8f1f2e9..acbe1e1af 100644 --- a/docs/examples/getinfo.c +++ b/docs/examples/getinfo.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 85b049483..b5b34d4f0 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -1,12 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * Example source code to show how the callback function can be used to + * 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. + * + * 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. + * + ***************************************************************************/ +/* 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. */ diff --git a/docs/examples/ghiper.c b/docs/examples/ghiper.c index ac11790cc..9a3f46d3f 100644 --- a/docs/examples/ghiper.c +++ b/docs/examples/ghiper.c @@ -1,12 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * Example application source code using the multi socket interface to + * 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. + * + * 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. + * + ***************************************************************************/ +/* Example application source code using the multi socket interface to * download many files at once. * * Written by Jeff Pohlmeyer diff --git a/docs/examples/hiperfifo.c b/docs/examples/hiperfifo.c index a885c0ce4..6036643b1 100644 --- a/docs/examples/hiperfifo.c +++ b/docs/examples/hiperfifo.c @@ -1,15 +1,28 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * Example application source code using the multi socket interface to - * download many files at once. + * 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. * - * Written by Jeff Pohlmeyer + * 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. + * + ***************************************************************************/ +/* Example application source code using the multi socket interface to + download many files at once. + +Written by Jeff Pohlmeyer Requires libevent and a (POSIX?) system that has mkfifo(). diff --git a/docs/examples/htmltidy.c b/docs/examples/htmltidy.c index 9a46955da..a36e331bf 100644 --- a/docs/examples/htmltidy.c +++ b/docs/examples/htmltidy.c @@ -1,12 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * Download a document and use libtidy to parse the HTML. + * 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. + * + * 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. + * + ***************************************************************************/ +/* Download a document and use libtidy to parse the HTML. * Written by Jeff Pohlmeyer * * LibTidy => http://tidy.sourceforge.net diff --git a/docs/examples/http-post.c b/docs/examples/http-post.c index 523177d28..22de628ca 100644 --- a/docs/examples/http-post.c +++ b/docs/examples/http-post.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/httpcustomheader.c b/docs/examples/httpcustomheader.c index 599b84fe8..077df2164 100644 --- a/docs/examples/httpcustomheader.c +++ b/docs/examples/httpcustomheader.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index 821e95fd8..f78a74107 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <fcntl.h> #include <sys/stat.h> diff --git a/docs/examples/https.c b/docs/examples/https.c index 10b5c657f..984357e37 100644 --- a/docs/examples/https.c +++ b/docs/examples/https.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index 29b07aba1..9615e67bf 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -1,13 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * This is an example application source code using the multi interface. - */ + * 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. + * + * 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. + * + ***************************************************************************/ +/* This is an example application source code using the multi interface. */ #include <stdio.h> #include <string.h> diff --git a/docs/examples/multi-debugcallback.c b/docs/examples/multi-debugcallback.c index 773faec67..c7e819d03 100644 --- a/docs/examples/multi-debugcallback.c +++ b/docs/examples/multi-debugcallback.c @@ -1,14 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * This is a very simple example using the multi interface and the debug - * callback. - */ + * 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. + * + * 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. + * + ***************************************************************************/ +/* This is an example showing the multi interface and the debug callback. */ #include <stdio.h> #include <string.h> diff --git a/docs/examples/multi-double.c b/docs/examples/multi-double.c index 990fec36a..120fde7b8 100644 --- a/docs/examples/multi-double.c +++ b/docs/examples/multi-double.c @@ -1,14 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * This is a very simple example using the multi interface. - */ - + * 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <string.h> diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index 13cfe6ff4..c26338b59 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -1,14 +1,26 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * This is an example application source code using the multi interface - * to do a multipart formpost without "blocking". - */ + * 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. + * + * 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. + * + ***************************************************************************/ +/* This is an example application source code using the multi interface + * to do a multipart formpost without "blocking". */ #include <stdio.h> #include <string.h> #include <sys/time.h> diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c index ca632e08c..0d3542706 100644 --- a/docs/examples/multi-single.c +++ b/docs/examples/multi-single.c @@ -1,13 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * This is a very simple example using the multi interface. - */ + * 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. + * + * 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. + * + ***************************************************************************/ +/* This is a very simple example using the multi interface. */ #include <stdio.h> #include <string.h> diff --git a/docs/examples/multithread.c b/docs/examples/multithread.c index 5f59a99d7..831a07467 100644 --- a/docs/examples/multithread.c +++ b/docs/examples/multithread.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ /* A multi-threaded example that uses pthreads extensively to fetch * X remote files at once */ diff --git a/docs/examples/opensslthreadlock.c b/docs/examples/opensslthreadlock.c index 706e90121..ad54f08ea 100644 --- a/docs/examples/opensslthreadlock.c +++ b/docs/examples/opensslthreadlock.c @@ -1,12 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * Example source code to show one way to set the necessary OpenSSL locking + * 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. + * + * 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. + * + ***************************************************************************/ +/* 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. * diff --git a/docs/examples/persistant.c b/docs/examples/persistant.c index 53710cde4..2d57e4907 100644 --- a/docs/examples/persistant.c +++ b/docs/examples/persistant.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <unistd.h> #include <curl/curl.h> diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index ae4f4db98..bb99a8566 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -1,14 +1,26 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * An example source code that issues a HTTP POST and we provide the actual - * data through a read callback. + * 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. + * + * 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. + * + ***************************************************************************/ +/* An example source code that issues a HTTP POST and we provide the actual + * data through a read callback. */ #include <stdio.h> #include <string.h> diff --git a/docs/examples/postit2.c b/docs/examples/postit2.c index a6292c5f1..bb7fd48d7 100644 --- a/docs/examples/postit2.c +++ b/docs/examples/postit2.c @@ -1,12 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * Example code that uploads a file name 'foo' to a remote script that accepts + * 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. + * + * 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. + * + ***************************************************************************/ +/* 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. * * The imaginary form we'll fill in looks like: diff --git a/docs/examples/sampleconv.c b/docs/examples/sampleconv.c index ed458516d..3db316096 100644 --- a/docs/examples/sampleconv.c +++ b/docs/examples/sampleconv.c @@ -1,11 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ /* 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 diff --git a/docs/examples/sendrecv.c b/docs/examples/sendrecv.c index 499fadb92..0a49f2ff5 100644 --- a/docs/examples/sendrecv.c +++ b/docs/examples/sendrecv.c @@ -1,13 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * An example of curl_easy_send() and curl_easy_recv() usage. + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ +/* An example of curl_easy_send() and curl_easy_recv() usage. */ #include <stdio.h> #include <string.h> diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index 3fb9045e1..dac287886 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <unistd.h> diff --git a/docs/examples/simple.c b/docs/examples/simple.c index 351cf729b..55877f8b2 100644 --- a/docs/examples/simple.c +++ b/docs/examples/simple.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/simplepost.c b/docs/examples/simplepost.c index b8e61e07d..3c8571919 100644 --- a/docs/examples/simplepost.c +++ b/docs/examples/simplepost.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <string.h> #include <curl/curl.h> diff --git a/docs/examples/simplesmtp.c b/docs/examples/simplesmtp.c index 0c1f7ff87..84429f5bf 100644 --- a/docs/examples/simplesmtp.c +++ b/docs/examples/simplesmtp.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <string.h> #include <curl/curl.h> diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index a02c2ae32..aeaadce59 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <curl/curl.h> diff --git a/docs/examples/smooth-gtk-thread.c b/docs/examples/smooth-gtk-thread.c index 5b60ded31..8cf106c81 100644 --- a/docs/examples/smooth-gtk-thread.c +++ b/docs/examples/smooth-gtk-thread.c @@ -1,12 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * This is a multi threaded application that uses a progress bar to show + * 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. + * + * 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. + * + ***************************************************************************/ +/* This is a multi threaded application that uses a progress bar to show * status. It uses Gtk+ to make a smooth pulse. * * Written by Jud Bishop after studying the other examples provided with diff --git a/docs/examples/smtp-multi.c b/docs/examples/smtp-multi.c index 4d1dfc4fb..15b177e5e 100644 --- a/docs/examples/smtp-multi.c +++ b/docs/examples/smtp-multi.c @@ -1,12 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * This is an example application source code sending SMTP mail using the + * 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. + * + * 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. + * + ***************************************************************************/ +/* This is an example application source code sending SMTP mail using the * multi interface. */ diff --git a/docs/examples/smtp-tls.c b/docs/examples/smtp-tls.c index 276908861..2e71f973e 100644 --- a/docs/examples/smtp-tls.c +++ b/docs/examples/smtp-tls.c @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ #include <stdio.h> #include <string.h> #include <curl/curl.h> diff --git a/docs/examples/synctime.c b/docs/examples/synctime.c index 4ed031ac4..70b84c326 100644 --- a/docs/examples/synctime.c +++ b/docs/examples/synctime.c @@ -1,12 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * This example code only builds as-is on Windows. + * 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. + * + * 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. + * + ***************************************************************************/ +/* This example code only builds as-is on Windows. * * While Unix/Linux user, you do not need this software. * You can achieve the same result as synctime using curl, awk and date. diff --git a/docs/examples/threaded-ssl.c b/docs/examples/threaded-ssl.c index 284edc419..a7e9c2de1 100644 --- a/docs/examples/threaded-ssl.c +++ b/docs/examples/threaded-ssl.c @@ -1,12 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. * - * A multi-threaded example that uses pthreads and fetches 4 remote files at + * 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. + * + * 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. + * + ***************************************************************************/ +/* 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. * -- cgit v1.2.1 From 029136da6054a3b2d6cb36b3b4f2ed34f83e010a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Sat, 12 Mar 2011 00:14:32 +0100 Subject: source header: added to more files --- docs/examples/Makefile.am | 19 +++++++++++++++++++ docs/examples/Makefile.example | 15 ++++++++++++++- docs/examples/Makefile.m32 | 21 +++++++++++++++++++++ docs/examples/htmltitle.cc | 18 +++++++++++++++--- docs/examples/makefile.dj | 21 +++++++++++++++++++++ 5 files changed, 90 insertions(+), 4 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index c5f97856b..6cf55f181 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -1,5 +1,24 @@ +#*************************************************************************** +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ +# \___|\___/|_| \_\_____| # +# Copyright (C) 1998 - 2011, 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. +# +# 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. +# +########################################################################### AUTOMAKE_OPTIONS = foreign nostdinc diff --git a/docs/examples/Makefile.example b/docs/examples/Makefile.example index 29ca0d7a2..dfd117873 100644 --- a/docs/examples/Makefile.example +++ b/docs/examples/Makefile.example @@ -1,11 +1,24 @@ -############################################################################# +#*************************************************************************** # _ _ ____ _ # Project ___| | | | _ \| | # / __| | | | |_) | | # | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # +# Copyright (C) 1998 - 2011, 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. +# +# 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. +# +########################################################################### # What to call the final executable TARGET = example diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 15750d01f..4ab596e26 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -1,3 +1,24 @@ +#*************************************************************************** +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ +# \___|\___/|_| \_\_____| +# +# Copyright (C) 1998 - 2011, 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. +# +# 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. +# +########################################################################### ######################################################################### # ## Makefile for building curl examples with MingW32 diff --git a/docs/examples/htmltitle.cc b/docs/examples/htmltitle.cc index da3354a55..55a7935ac 100644 --- a/docs/examples/htmltitle.cc +++ b/docs/examples/htmltitle.cc @@ -1,12 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ - + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ // Get a web page, parse it with libxml. // // Written by Lars Nilsson diff --git a/docs/examples/makefile.dj b/docs/examples/makefile.dj index 8736e6e78..a8bdd6a4e 100644 --- a/docs/examples/makefile.dj +++ b/docs/examples/makefile.dj @@ -1,3 +1,24 @@ +#*************************************************************************** +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ +# \___|\___/|_| \_\_____| +# +# Copyright (C) 1998 - 2011, 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. +# +# 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. +# +########################################################################### # # Adapted for djgpp / Watt-32 / DOS by # Gisle Vanem <giva@bgnett.no> -- cgit v1.2.1 From e9afbe2a65716a1e08677a88976f44c81704b6e8 Mon Sep 17 00:00:00 2001 From: Gisle Vanem <gvanem@broadpark.no> Date: Thu, 7 Apr 2011 15:16:38 +0200 Subject: examples/makefile.dj: update email --- docs/examples/makefile.dj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/makefile.dj b/docs/examples/makefile.dj index a8bdd6a4e..c18ef8a70 100644 --- a/docs/examples/makefile.dj +++ b/docs/examples/makefile.dj @@ -21,7 +21,7 @@ ########################################################################### # # Adapted for djgpp / Watt-32 / DOS by -# Gisle Vanem <giva@bgnett.no> +# Gisle Vanem <gvanem@broadpark.no> # TOPDIR = ../.. -- cgit v1.2.1 From c4bc1d473f324220738f2c60984b3a8ee198bc38 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Thu, 28 Apr 2011 22:14:05 +0200 Subject: anyauthput.c: stdint.h must not be included unconditionally As it is already included by curlbuild.h if it exists on the platform it was included here superfluously anyway. Reported by: Dagobert Michelsen Bug: http://curl.haxx.se/bug/view.cgi?id=3294509 --- docs/examples/anyauthput.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index 6b3d74a4b..76fa15853 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -26,8 +26,6 @@ #else # ifdef __VMS typedef int intptr_t; -# else -# include <stdint.h> # endif # include <unistd.h> #endif -- cgit v1.2.1 From ac28971aa61d28e5dd54888e34e958d1c742b461 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Tue, 28 Jun 2011 19:08:51 +0200 Subject: examples: cleanup curl includes Only <curl/curl.h> is needed typically and curl/types.h has been removed --- docs/examples/certinfo.c | 2 -- docs/examples/chkspeed.c | 2 -- docs/examples/curlgtk.c | 2 -- docs/examples/ftpget.c | 2 -- docs/examples/ftpgetinfo.c | 2 -- docs/examples/ftpgetresp.c | 2 -- docs/examples/postit2.c | 2 -- docs/examples/sepheaders.c | 2 -- docs/examples/simplessl.c | 3 --- docs/examples/smooth-gtk-thread.c | 2 -- 10 files changed, 21 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/certinfo.c b/docs/examples/certinfo.c index 02558d98c..ffcec6356 100644 --- a/docs/examples/certinfo.c +++ b/docs/examples/certinfo.c @@ -22,8 +22,6 @@ #include <stdio.h> #include <curl/curl.h> -#include <curl/types.h> -#include <curl/easy.h> static size_t wrfu(void *ptr, size_t size, size_t nmemb, void *stream) { diff --git a/docs/examples/chkspeed.c b/docs/examples/chkspeed.c index fbcb1f764..b5c397ab7 100644 --- a/docs/examples/chkspeed.c +++ b/docs/examples/chkspeed.c @@ -35,8 +35,6 @@ #include <time.h> #include <curl/curl.h> -#include <curl/types.h> -#include <curl/easy.h> #define URL_BASE "http://speedtest.your.domain/" #define URL_1M URL_BASE "file_1M.bin" diff --git a/docs/examples/curlgtk.c b/docs/examples/curlgtk.c index 2c4428083..8cb9914c6 100644 --- a/docs/examples/curlgtk.c +++ b/docs/examples/curlgtk.c @@ -13,8 +13,6 @@ #include <gtk/gtk.h> #include <curl/curl.h> -#include <curl/types.h> /* new for v7 */ -#include <curl/easy.h> /* new for v7 */ GtkWidget *Bar; diff --git a/docs/examples/ftpget.c b/docs/examples/ftpget.c index 7b5e0d7cf..bcb42bb30 100644 --- a/docs/examples/ftpget.c +++ b/docs/examples/ftpget.c @@ -22,8 +22,6 @@ #include <stdio.h> #include <curl/curl.h> -#include <curl/types.h> -#include <curl/easy.h> /* * This is an example showing how to get a single file from an FTP server. diff --git a/docs/examples/ftpgetinfo.c b/docs/examples/ftpgetinfo.c index 52f87d633..f0746693b 100644 --- a/docs/examples/ftpgetinfo.c +++ b/docs/examples/ftpgetinfo.c @@ -23,8 +23,6 @@ #include <string.h> #include <curl/curl.h> -#include <curl/types.h> -#include <curl/easy.h> /* * This is an example showing how to check a single file's size and mtime diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index ea882a00f..29290a31d 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -22,8 +22,6 @@ #include <stdio.h> #include <curl/curl.h> -#include <curl/types.h> -#include <curl/easy.h> /* * Similar to ftpget.c but this also stores the received response-lines diff --git a/docs/examples/postit2.c b/docs/examples/postit2.c index bb7fd48d7..63c248467 100644 --- a/docs/examples/postit2.c +++ b/docs/examples/postit2.c @@ -37,8 +37,6 @@ #include <string.h> #include <curl/curl.h> -#include <curl/types.h> -#include <curl/easy.h> int main(int argc, char *argv[]) { diff --git a/docs/examples/sepheaders.c b/docs/examples/sepheaders.c index dac287886..afa14fc85 100644 --- a/docs/examples/sepheaders.c +++ b/docs/examples/sepheaders.c @@ -24,8 +24,6 @@ #include <unistd.h> #include <curl/curl.h> -#include <curl/types.h> -#include <curl/easy.h> static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) { diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index aeaadce59..46a378329 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -22,9 +22,6 @@ #include <stdio.h> #include <curl/curl.h> -#include <curl/types.h> -#include <curl/easy.h> - /* some requirements for this to work: 1. set pCertFile to the file with the client certificate diff --git a/docs/examples/smooth-gtk-thread.c b/docs/examples/smooth-gtk-thread.c index 8cf106c81..932f6e396 100644 --- a/docs/examples/smooth-gtk-thread.c +++ b/docs/examples/smooth-gtk-thread.c @@ -37,8 +37,6 @@ #include <pthread.h> #include <curl/curl.h> -#include <curl/types.h> /* new for v7 */ -#include <curl/easy.h> /* new for v7 */ #define NUMT 4 -- cgit v1.2.1 From 8e2de86723e15f625f0c272ae2098554d10f03d0 Mon Sep 17 00:00:00 2001 From: Jim Hollinger <hollinger.jim@gmail.com> Date: Wed, 10 Aug 2011 10:54:53 +0200 Subject: rtsp.c: new example Code from http://code.google.com/p/rtsprequest/source/browse/trunk/rtsprequest.cpp --- docs/examples/rtsp.c | 253 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 docs/examples/rtsp.c (limited to 'docs/examples') diff --git a/docs/examples/rtsp.c b/docs/examples/rtsp.c new file mode 100644 index 000000000..2fe912c63 --- /dev/null +++ b/docs/examples/rtsp.c @@ -0,0 +1,253 @@ +/* + * Copyright (c) 2011, Jim Hollinger + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Jim Hollinger nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#if defined (WIN32) +# include <conio.h> // _getch() +#else +# include <termios.h> +# include <unistd.h> + + int _getch(void) { + struct termios oldt, newt; + tcgetattr( STDIN_FILENO, &oldt ); + newt = oldt; + newt.c_lflag &= ~( ICANON | ECHO ); + tcsetattr( STDIN_FILENO, TCSANOW, &newt ); + int ch = getchar(); + tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); + return ch; + } +#endif + +#include <curl/curl.h> + +#define VERSION_STR "V1.0" + +// error handling macros +#define my_curl_easy_setopt(A, B, C) \ + 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) \ + fprintf(stderr, "curl_easy_perform(%s) failed: %d\n", #A, res); + + +// send RTSP OPTIONS request +void rtsp_options(CURL *curl, const char *uri) { + CURLcode res = CURLE_OK; + printf("\nRTSP: OPTIONS %s\n", uri); + my_curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri); + my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS); + my_curl_easy_perform(curl); +} + + +// send RTSP DESCRIBE request and write sdp response to a file +void rtsp_describe(CURL *curl, const char *uri, const char *sdp_filename) { + CURLcode res = CURLE_OK; + printf("\nRTSP: DESCRIBE %s\n", uri); + FILE *sdp_fp = fopen(sdp_filename, "wt"); + if (sdp_fp == NULL) { + fprintf(stderr, "Could not open '%s' for writing\n", sdp_filename); + sdp_fp = stdout; + } else { + printf("Writing SDP to '%s'\n", sdp_filename); + } + my_curl_easy_setopt(curl, CURLOPT_WRITEDATA, sdp_fp); + my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE); + my_curl_easy_perform(curl); + my_curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout); + if (sdp_fp != stdout) { + fclose(sdp_fp); + } +} + + +// send RTSP SETUP request +void rtsp_setup(CURL *curl, const char *uri, const char *transport) { + CURLcode res = CURLE_OK; + printf("\nRTSP: SETUP %s\n", uri); + printf(" TRANSPORT %s\n", transport); + my_curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri); + my_curl_easy_setopt(curl, CURLOPT_RTSP_TRANSPORT, transport); + my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP); + my_curl_easy_perform(curl); +} + + +// send RTSP PLAY request +void rtsp_play(CURL *curl, const char *uri, const char *range) { + CURLcode res = CURLE_OK; + printf("\nRTSP: PLAY %s\n", uri); + my_curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri); + my_curl_easy_setopt(curl, CURLOPT_RANGE, range); + my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY); + my_curl_easy_perform(curl); +} + + +// send RTSP TEARDOWN request +void rtsp_teardown(CURL *curl, const char *uri) { + CURLcode res = CURLE_OK; + printf("\nRTSP: TEARDOWN %s\n", uri); + my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN); + my_curl_easy_perform(curl); +} + + +// convert url into an sdp filename +void get_sdp_filename(const char *url, char *sdp_filename) { + strcpy(sdp_filename, "video.sdp"); + const char *s = strrchr(url, '/'); + if (s != NULL) { + s++; + if (s[0] != '\0') { + sprintf(sdp_filename, "%s.sdp", s); + } + } +} + + +// scan sdp file for media control attribute +void get_media_control_attribute(const char *sdp_filename, char *control) { + control[0] = '\0'; + int max_len = 256; + char *s = new char[max_len]; + FILE *sdp_fp = fopen(sdp_filename, "rt"); + if (sdp_fp != NULL) { + while (fgets(s, max_len - 2, sdp_fp) != NULL) { + sscanf(s, " a = control: %s", control); + } + fclose(sdp_fp); + } + delete []s; +} + + +// main app +int main(int argc, char * const argv[]) { + const char *transport = "RTP/AVP;unicast;client_port=1234-1235"; // UDP +// const char *transport = "RTP/AVP/TCP;unicast;client_port=1234-1235"; // TCP + const char *range = "0.000-"; + int rc = EXIT_SUCCESS; + + printf("\nRTSP request %s\n", VERSION_STR); + printf(" Project web site: http://code.google.com/p/rtsprequest/\n"); + printf(" Requires cURL V7.20 or greater\n\n"); + + // check command line + char *basename = NULL; + if ((argc != 2) && (argc != 3)) { + basename = strrchr(argv[0], '/'); + if (basename == NULL) { + basename = strrchr(argv[0], '\\'); + } + if (basename == NULL) { + basename = argv[0]; + } else { + basename++; + } + printf("Usage: %s url [transport]\n", basename); + printf(" url of video server\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", basename); + rc = EXIT_FAILURE; + } else { + const char *url = argv[1]; + char *uri = new char[strlen(url) + 32]; + char *sdp_filename = new char[strlen(url) + 32]; + char *control = new char[strlen(url) + 32]; + get_sdp_filename(url, sdp_filename); + if (argc == 3) { + transport = argv[2]; + } + + // initialize curl + CURLcode res = CURLE_OK; + res = curl_global_init(CURL_GLOBAL_ALL); + if (res == CURLE_OK) { + curl_version_info_data *data = curl_version_info(CURLVERSION_NOW); + fprintf(stderr, " cURL V%s loaded\n", data->version); + + // initialize this curl session + CURL *curl = curl_easy_init(); + 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_WRITEHEADER, stdout); + my_curl_easy_setopt(curl, CURLOPT_URL, url); + + // request server options + sprintf(uri, "%s", url); + rtsp_options(curl, uri); + + // request session description and write response to sdp file + rtsp_describe(curl, uri, sdp_filename); + + // get media control attribute from sdp file + get_media_control_attribute(sdp_filename, control); + + // setup media stream + sprintf(uri, "%s/%s", url, control); + rtsp_setup(curl, uri, transport); + + // start playing media stream + sprintf(uri, "%s/", url); + rtsp_play(curl, uri, range); + printf("Playing video, press any key to stop ..."); + _getch(); + printf("\n"); + + // teardown session + rtsp_teardown(curl, uri); + + // cleanup + curl_easy_cleanup(curl); + curl = NULL; + } else { + fprintf(stderr, "curl_easy_init() failed\n"); + } + curl_global_cleanup(); + } else { + fprintf(stderr, "curl_global_init(%s) failed\n", "CURL_GLOBAL_ALL", res); + } + delete []control; + delete []sdp_filename; + delete []uri; + } + + return rc; +} -- cgit v1.2.1 From 657d02fbaca47a8f3a13982f450c7001fc40cc0b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 10 Aug 2011 10:57:50 +0200 Subject: rtsp.c: converted to C Trimmed the newlines to be LF-only. Converted the source to plain C, to use curl style indents, to compile warning-free with picky options and fixed the minor fprintf() bug on line 245. Added to makefile. --- docs/examples/Makefile.inc | 2 +- docs/examples/rtsp.c | 524 +++++++++++++++++++++++---------------------- 2 files changed, 272 insertions(+), 254 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 9a2b48ea1..c07520321 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -4,7 +4,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ https multi-app multi-debugcallback multi-double multi-post multi-single \ persistant post-callback postit2 sepheaders simple simplepost simplessl \ sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard \ - smtp-multi simplesmtp smtp-tls + smtp-multi simplesmtp smtp-tls rtsp # 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/rtsp.c b/docs/examples/rtsp.c index 2fe912c63..42b26cc71 100644 --- a/docs/examples/rtsp.c +++ b/docs/examples/rtsp.c @@ -1,253 +1,271 @@ -/* - * Copyright (c) 2011, Jim Hollinger - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Jim Hollinger nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#if defined (WIN32) -# include <conio.h> // _getch() -#else -# include <termios.h> -# include <unistd.h> - - int _getch(void) { - struct termios oldt, newt; - tcgetattr( STDIN_FILENO, &oldt ); - newt = oldt; - newt.c_lflag &= ~( ICANON | ECHO ); - tcsetattr( STDIN_FILENO, TCSANOW, &newt ); - int ch = getchar(); - tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); - return ch; - } -#endif - -#include <curl/curl.h> - -#define VERSION_STR "V1.0" - -// error handling macros -#define my_curl_easy_setopt(A, B, C) \ - 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) \ - fprintf(stderr, "curl_easy_perform(%s) failed: %d\n", #A, res); - - -// send RTSP OPTIONS request -void rtsp_options(CURL *curl, const char *uri) { - CURLcode res = CURLE_OK; - printf("\nRTSP: OPTIONS %s\n", uri); - my_curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri); - my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS); - my_curl_easy_perform(curl); -} - - -// send RTSP DESCRIBE request and write sdp response to a file -void rtsp_describe(CURL *curl, const char *uri, const char *sdp_filename) { - CURLcode res = CURLE_OK; - printf("\nRTSP: DESCRIBE %s\n", uri); - FILE *sdp_fp = fopen(sdp_filename, "wt"); - if (sdp_fp == NULL) { - fprintf(stderr, "Could not open '%s' for writing\n", sdp_filename); - sdp_fp = stdout; - } else { - printf("Writing SDP to '%s'\n", sdp_filename); - } - my_curl_easy_setopt(curl, CURLOPT_WRITEDATA, sdp_fp); - my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE); - my_curl_easy_perform(curl); - my_curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout); - if (sdp_fp != stdout) { - fclose(sdp_fp); - } -} - - -// send RTSP SETUP request -void rtsp_setup(CURL *curl, const char *uri, const char *transport) { - CURLcode res = CURLE_OK; - printf("\nRTSP: SETUP %s\n", uri); - printf(" TRANSPORT %s\n", transport); - my_curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri); - my_curl_easy_setopt(curl, CURLOPT_RTSP_TRANSPORT, transport); - my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP); - my_curl_easy_perform(curl); -} - - -// send RTSP PLAY request -void rtsp_play(CURL *curl, const char *uri, const char *range) { - CURLcode res = CURLE_OK; - printf("\nRTSP: PLAY %s\n", uri); - my_curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri); - my_curl_easy_setopt(curl, CURLOPT_RANGE, range); - my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY); - my_curl_easy_perform(curl); -} - - -// send RTSP TEARDOWN request -void rtsp_teardown(CURL *curl, const char *uri) { - CURLcode res = CURLE_OK; - printf("\nRTSP: TEARDOWN %s\n", uri); - my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN); - my_curl_easy_perform(curl); -} - - -// convert url into an sdp filename -void get_sdp_filename(const char *url, char *sdp_filename) { - strcpy(sdp_filename, "video.sdp"); - const char *s = strrchr(url, '/'); - if (s != NULL) { - s++; - if (s[0] != '\0') { - sprintf(sdp_filename, "%s.sdp", s); - } - } -} - - -// scan sdp file for media control attribute -void get_media_control_attribute(const char *sdp_filename, char *control) { - control[0] = '\0'; - int max_len = 256; - char *s = new char[max_len]; - FILE *sdp_fp = fopen(sdp_filename, "rt"); - if (sdp_fp != NULL) { - while (fgets(s, max_len - 2, sdp_fp) != NULL) { - sscanf(s, " a = control: %s", control); - } - fclose(sdp_fp); - } - delete []s; -} - - -// main app -int main(int argc, char * const argv[]) { - const char *transport = "RTP/AVP;unicast;client_port=1234-1235"; // UDP -// const char *transport = "RTP/AVP/TCP;unicast;client_port=1234-1235"; // TCP - const char *range = "0.000-"; - int rc = EXIT_SUCCESS; - - printf("\nRTSP request %s\n", VERSION_STR); - printf(" Project web site: http://code.google.com/p/rtsprequest/\n"); - printf(" Requires cURL V7.20 or greater\n\n"); - - // check command line - char *basename = NULL; - if ((argc != 2) && (argc != 3)) { - basename = strrchr(argv[0], '/'); - if (basename == NULL) { - basename = strrchr(argv[0], '\\'); - } - if (basename == NULL) { - basename = argv[0]; - } else { - basename++; - } - printf("Usage: %s url [transport]\n", basename); - printf(" url of video server\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", basename); - rc = EXIT_FAILURE; - } else { - const char *url = argv[1]; - char *uri = new char[strlen(url) + 32]; - char *sdp_filename = new char[strlen(url) + 32]; - char *control = new char[strlen(url) + 32]; - get_sdp_filename(url, sdp_filename); - if (argc == 3) { - transport = argv[2]; - } - - // initialize curl - CURLcode res = CURLE_OK; - res = curl_global_init(CURL_GLOBAL_ALL); - if (res == CURLE_OK) { - curl_version_info_data *data = curl_version_info(CURLVERSION_NOW); - fprintf(stderr, " cURL V%s loaded\n", data->version); - - // initialize this curl session - CURL *curl = curl_easy_init(); - 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_WRITEHEADER, stdout); - my_curl_easy_setopt(curl, CURLOPT_URL, url); - - // request server options - sprintf(uri, "%s", url); - rtsp_options(curl, uri); - - // request session description and write response to sdp file - rtsp_describe(curl, uri, sdp_filename); - - // get media control attribute from sdp file - get_media_control_attribute(sdp_filename, control); - - // setup media stream - sprintf(uri, "%s/%s", url, control); - rtsp_setup(curl, uri, transport); - - // start playing media stream - sprintf(uri, "%s/", url); - rtsp_play(curl, uri, range); - printf("Playing video, press any key to stop ..."); - _getch(); - printf("\n"); - - // teardown session - rtsp_teardown(curl, uri); - - // cleanup - curl_easy_cleanup(curl); - curl = NULL; - } else { - fprintf(stderr, "curl_easy_init() failed\n"); - } - curl_global_cleanup(); - } else { - fprintf(stderr, "curl_global_init(%s) failed\n", "CURL_GLOBAL_ALL", res); - } - delete []control; - delete []sdp_filename; - delete []uri; - } - - return rc; -} +/* + * Copyright (c) 2011, Jim Hollinger + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Jim Hollinger nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#if defined (WIN32) +# include <conio.h> /* _getch() */ +#else +# include <termios.h> +# include <unistd.h> + +static int _getch(void) +{ + struct termios oldt, newt; + int ch; + tcgetattr( STDIN_FILENO, &oldt ); + newt = oldt; + newt.c_lflag &= ~( ICANON | ECHO ); + tcsetattr( STDIN_FILENO, TCSANOW, &newt ); + ch = getchar(); + tcsetattr( STDIN_FILENO, TCSANOW, &oldt ); + return ch; +} +#endif + +#include <curl/curl.h> + +#define VERSION_STR "V1.0" + +/* error handling macros */ +#define my_curl_easy_setopt(A, B, C) \ + 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) \ + fprintf(stderr, "curl_easy_perform(%s) failed: %d\n", #A, res); + + +/* send RTSP OPTIONS request */ +static void rtsp_options(CURL *curl, const char *uri) +{ + CURLcode res = CURLE_OK; + printf("\nRTSP: OPTIONS %s\n", uri); + my_curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri); + my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS); + my_curl_easy_perform(curl); +} + + +/* send RTSP DESCRIBE request and write sdp response to a file */ +static void rtsp_describe(CURL *curl, const char *uri, + const char *sdp_filename) +{ + CURLcode res = CURLE_OK; + FILE *sdp_fp = fopen(sdp_filename, "wt"); + printf("\nRTSP: DESCRIBE %s\n", uri); + if (sdp_fp == NULL) { + fprintf(stderr, "Could not open '%s' for writing\n", sdp_filename); + sdp_fp = stdout; + } + else { + printf("Writing SDP to '%s'\n", sdp_filename); + } + my_curl_easy_setopt(curl, CURLOPT_WRITEDATA, sdp_fp); + my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE); + my_curl_easy_perform(curl); + my_curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout); + if (sdp_fp != stdout) { + fclose(sdp_fp); + } +} + +/* send RTSP SETUP request */ +static void rtsp_setup(CURL *curl, const char *uri, const char *transport) +{ + CURLcode res = CURLE_OK; + printf("\nRTSP: SETUP %s\n", uri); + printf(" TRANSPORT %s\n", transport); + my_curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri); + my_curl_easy_setopt(curl, CURLOPT_RTSP_TRANSPORT, transport); + my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP); + my_curl_easy_perform(curl); +} + + +/* send RTSP PLAY request */ +static void rtsp_play(CURL *curl, const char *uri, const char *range) +{ + CURLcode res = CURLE_OK; + printf("\nRTSP: PLAY %s\n", uri); + my_curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri); + my_curl_easy_setopt(curl, CURLOPT_RANGE, range); + my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY); + my_curl_easy_perform(curl); +} + + +/* send RTSP TEARDOWN request */ +static void rtsp_teardown(CURL *curl, const char *uri) +{ + CURLcode res = CURLE_OK; + printf("\nRTSP: TEARDOWN %s\n", uri); + my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN); + my_curl_easy_perform(curl); +} + + +/* convert url into an sdp filename */ +static void get_sdp_filename(const char *url, char *sdp_filename) +{ + const char *s = strrchr(url, '/'); + strcpy(sdp_filename, "video.sdp"); + if (s != NULL) { + s++; + if (s[0] != '\0') { + sprintf(sdp_filename, "%s.sdp", s); + } + } +} + + +/* scan sdp file for media control attribute */ +static void get_media_control_attribute(const char *sdp_filename, + char *control) +{ + int max_len = 256; + char *s = malloc(max_len); + FILE *sdp_fp = fopen(sdp_filename, "rt"); + control[0] = '\0'; + if (sdp_fp != NULL) { + while (fgets(s, max_len - 2, sdp_fp) != NULL) { + sscanf(s, " a = control: %s", control); + } + fclose(sdp_fp); + } + free(s); +} + + +/* main app */ +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 */ +#endif + const char *range = "0.000-"; + int rc = EXIT_SUCCESS; + char *basename = NULL; + + printf("\nRTSP request %s\n", VERSION_STR); + printf(" Project web site: http://code.google.com/p/rtsprequest/\n"); + printf(" Requires cURL V7.20 or greater\n\n"); + + /* check command line */ + if ((argc != 2) && (argc != 3)) { + basename = strrchr(argv[0], '/'); + if (basename == NULL) { + basename = strrchr(argv[0], '\\'); + } + if (basename == NULL) { + basename = argv[0]; + } else { + basename++; + } + printf("Usage: %s url [transport]\n", basename); + printf(" url of video server\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", basename); + rc = EXIT_FAILURE; + } 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) { + transport = argv[2]; + } + + /* initialize curl */ + res = curl_global_init(CURL_GLOBAL_ALL); + 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) { + my_curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); + my_curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L); + my_curl_easy_setopt(curl, CURLOPT_WRITEHEADER, stdout); + my_curl_easy_setopt(curl, CURLOPT_URL, url); + + /* request server options */ + sprintf(uri, "%s", url); + rtsp_options(curl, uri); + + /* request session description and write response to sdp file */ + rtsp_describe(curl, uri, sdp_filename); + + /* get media control attribute from sdp file */ + get_media_control_attribute(sdp_filename, control); + + /* setup media stream */ + sprintf(uri, "%s/%s", url, control); + rtsp_setup(curl, uri, transport); + + /* start playing media stream */ + sprintf(uri, "%s/", url); + rtsp_play(curl, uri, range); + printf("Playing video, press any key to stop ..."); + _getch(); + printf("\n"); + + /* teardown session */ + rtsp_teardown(curl, uri); + + /* cleanup */ + curl_easy_cleanup(curl); + curl = NULL; + } else { + fprintf(stderr, "curl_easy_init() failed\n"); + } + curl_global_cleanup(); + } else { + fprintf(stderr, "curl_global_init(%s) failed: %d\n", + "CURL_GLOBAL_ALL", res); + } + free(control); + free(sdp_filename); + free(uri); + } + + return rc; +} -- cgit v1.2.1 From c8766ed3fb72ed67fbc78541e04696c9e9237dba Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Sat, 13 Aug 2011 00:02:34 +0200 Subject: ignore rtsp --- docs/examples/.gitignore | 1 + 1 file changed, 1 insertion(+) (limited to 'docs/examples') diff --git a/docs/examples/.gitignore b/docs/examples/.gitignore index 8836a7b98..7e5ecdb1d 100644 --- a/docs/examples/.gitignore +++ b/docs/examples/.gitignore @@ -25,6 +25,7 @@ multi-single persistant post-callback postit2 +rtsp sendrecv sepheaders simple -- cgit v1.2.1 From af809923e4ca05215814b313f9b57f29b8ffdc33 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Tue, 23 Aug 2011 11:28:35 +0200 Subject: externalsocket.c: new example --- docs/examples/.gitignore | 1 + docs/examples/Makefile.inc | 2 +- docs/examples/externalsocket.c | 128 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 docs/examples/externalsocket.c (limited to 'docs/examples') diff --git a/docs/examples/.gitignore b/docs/examples/.gitignore index 7e5ecdb1d..42429d8f8 100644 --- a/docs/examples/.gitignore +++ b/docs/examples/.gitignore @@ -4,6 +4,7 @@ certinfo chkspeed cookie_interface debug +externalsocket fileupload fopen ftp-wildcard diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index c07520321..c6a3e9c5b 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -4,7 +4,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ https multi-app multi-debugcallback multi-double multi-post multi-single \ persistant post-callback postit2 sepheaders simple simplepost simplessl \ sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard \ - smtp-multi simplesmtp smtp-tls rtsp + smtp-multi simplesmtp smtp-tls rtsp externalsocket # 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/externalsocket.c b/docs/examples/externalsocket.c new file mode 100644 index 000000000..39440afd5 --- /dev/null +++ b/docs/examples/externalsocket.c @@ -0,0 +1,128 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ +/* + * This is an example demonstrating how an application can pass in a custom + * socket to libcurl to use. This example also handles the connect itself. + */ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <curl/curl.h> + +#include <sys/types.h> +#include <sys/socket.h> + +#include <sys/socket.h> /* socket definitions */ +#include <sys/types.h> /* socket types */ +#include <arpa/inet.h> /* inet (3) funtions */ +#include <unistd.h> /* misc. UNIX functions */ + +#include <errno.h> + +/* The IP address and port number to connect to */ +#define IPADDR "127.0.0.1" +#define PORTNUM 80 + +static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) +{ + int written = fwrite(ptr, size, nmemb, (FILE *)stream); + return written; +} + +static curl_socket_t opensocket(void *clientp, + curlsocktype purpose, + struct curl_sockaddr *address) +{ + curl_socket_t sockfd = *(curl_socket_t *)clientp; + /* the actual externally set socket is passed in via the OPENSOCKETDATA + option */ + return sockfd; +} + +static int sockopt_callback(void *clientp, curl_socket_t curlfd, + curlsocktype purpose) +{ + /* This return code was added in libcurl 7.21.5 */ + return CURL_SOCKOPT_ALREADY_CONNECTED; +} + +int main(void) +{ + CURL *curl; + CURLcode res; + struct sockaddr_in servaddr; /* socket address structure */ + curl_socket_t sockfd; + + curl = curl_easy_init(); + if(curl) { + /* + * Note that libcurl will internally think that you connect to the host + * and port that you specify in the URL option. + */ + curl_easy_setopt(curl, CURLOPT_URL, "http://99.99.99.99:9999"); + + /* Create the socket "manually" */ + if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) { + fprintf(stderr, "ECHOCLNT: Error creating listening socket.\n"); + return 3; + } + + memset(&servaddr, 0, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_port = htons(PORTNUM); + + if(inet_aton(IPADDR, &servaddr.sin_addr) <= 0 ) + return 2; + + if(connect(sockfd,(struct sockaddr *) &servaddr, sizeof(servaddr)) == + -1) { + close(sockfd); + printf("client error: connect: %s\n", strerror(errno)); + return 1; + } + + /* no progress meter please */ + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L); + + /* send all data to this function */ + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); + + /* call this function to get a socket */ + curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket); + curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &sockfd); + + /* call this function to set options for the socket */ + curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback); + + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + + res = curl_easy_perform(curl); + + curl_easy_cleanup(curl); + + if(res) { + printf("libcurl error: %d\n", res); + return 4; + } + } + return 0; +} -- cgit v1.2.1 From cce6508242ab73cca896788ad9f968b89e5f9f3a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Tue, 23 Aug 2011 16:31:10 +0200 Subject: resolve.c: new example showing off CURLOPT_RESOLVE --- docs/examples/.gitignore | 1 + docs/examples/Makefile.inc | 2 +- docs/examples/resolve.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 docs/examples/resolve.c (limited to 'docs/examples') diff --git a/docs/examples/.gitignore b/docs/examples/.gitignore index 42429d8f8..7443de010 100644 --- a/docs/examples/.gitignore +++ b/docs/examples/.gitignore @@ -26,6 +26,7 @@ multi-single persistant post-callback postit2 +resolve rtsp sendrecv sepheaders diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index c6a3e9c5b..d1ae9ddbb 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -4,7 +4,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ https multi-app multi-debugcallback multi-double multi-post multi-single \ persistant post-callback postit2 sepheaders simple simplepost simplessl \ sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard \ - smtp-multi simplesmtp smtp-tls rtsp externalsocket + smtp-multi simplesmtp smtp-tls rtsp externalsocket resolve # 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/resolve.c b/docs/examples/resolve.c new file mode 100644 index 000000000..7b3e5656e --- /dev/null +++ b/docs/examples/resolve.c @@ -0,0 +1,51 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ +#include <stdio.h> +#include <curl/curl.h> + +int main(void) +{ + CURL *curl; + CURLcode res = CURLE_OK; + struct curl_slist *host = NULL; + + /* Each single name resolve string should be written using the format + HOST:PORT:ADDRESS where HOST is the name libcurl will try to resolve, + PORT is the port number of the service where libcurl wants to connect to + the HOST and ADDRESS is the numerical IP address + */ + host = curl_slist_append(NULL, "example.com:80:127.0.0.1"); + + curl = curl_easy_init(); + if(curl) { + curl_easy_setopt(curl, CURLOPT_RESOLVE, host); + curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + + curl_slist_free_all(host); + + return (int)res; +} -- cgit v1.2.1 From 450975b0c34bcc9659cbb963460b3e4d0df43543 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 7 Sep 2011 22:43:28 +0200 Subject: getinmemory.c: use better argument names for write callback --- docs/examples/getinmemory.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index b5b34d4f0..78e6deb10 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -36,10 +36,10 @@ struct MemoryStruct { static size_t -WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) +WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) { size_t realsize = size * nmemb; - struct MemoryStruct *mem = (struct MemoryStruct *)data; + struct MemoryStruct *mem = (struct MemoryStruct *)userp; mem->memory = realloc(mem->memory, mem->size + realsize + 1); if (mem->memory == NULL) { @@ -48,7 +48,7 @@ WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) exit(EXIT_FAILURE); } - memcpy(&(mem->memory[mem->size]), ptr, realsize); + memcpy(&(mem->memory[mem->size]), contents, realsize); mem->size += realsize; mem->memory[mem->size] = 0; -- cgit v1.2.1 From 6790a543d4b692e0f62971804606fdcbcf84a292 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Tue, 13 Sep 2011 22:47:34 +0200 Subject: progressfunc: a simple CURLOPT_PROGRESSFUNCTION example --- docs/examples/.gitignore | 1 + docs/examples/Makefile.inc | 3 ++- docs/examples/progressfunc.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 docs/examples/progressfunc.c (limited to 'docs/examples') diff --git a/docs/examples/.gitignore b/docs/examples/.gitignore index 7443de010..2ee9df154 100644 --- a/docs/examples/.gitignore +++ b/docs/examples/.gitignore @@ -26,6 +26,7 @@ multi-single persistant post-callback postit2 +progressfunc resolve rtsp sendrecv diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index d1ae9ddbb..bf7337dd8 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -4,7 +4,8 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ https multi-app multi-debugcallback multi-double multi-post multi-single \ persistant post-callback postit2 sepheaders simple simplepost simplessl \ sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard \ - smtp-multi simplesmtp smtp-tls rtsp externalsocket resolve + smtp-multi simplesmtp smtp-tls rtsp externalsocket resolve \ + progressfunc # 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/progressfunc.c b/docs/examples/progressfunc.c new file mode 100644 index 000000000..42ed3287b --- /dev/null +++ b/docs/examples/progressfunc.c @@ -0,0 +1,58 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ +#include <stdio.h> +#include <curl/curl.h> + +#define STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES 6000 + +static int progress(void *p, + double dltotal, double dlnow, + double ultotal, double ulnow) +{ + fprintf(stderr, "UP: %g of %g DOWN: %g of %g\r\n", + ulnow, ultotal, dlnow, dltotal); + + if(dlnow > STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES) + return 1; + return 0; +} + +int main(void) +{ + CURL *curl; + CURLcode res=0; + + curl = curl_easy_init(); + if(curl) { + curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/"); + curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress); + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); + res = curl_easy_perform(curl); + + if(res) + fprintf(stderr, "%s\n", curl_easy_strerror(res)); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return (int)res; +} -- cgit v1.2.1 From a6c168b893205f4a6660250699ac3f046b424b76 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Tue, 20 Sep 2011 15:05:28 +0200 Subject: A bunch of MinGW build tweaks. All paths to dependencies now quoted; synced examples makefile. --- docs/examples/Makefile.m32 | 136 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 107 insertions(+), 29 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 4ab596e26..45cde7746 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -19,31 +19,47 @@ # KIND, either express or implied. # ########################################################################### -######################################################################### # -## Makefile for building curl examples with MingW32 -## and optionally OpenSSL (0.9.8), libssh2 (0.18), zlib (1.2.3) +## Makefile for building curl examples with MingW (GCC-3.2 or later) +## and optionally OpenSSL (0.9.8), libssh2 (1.3), zlib (1.2.5), librtmp (2.3) ## -## Usage: -## mingw32-make -f Makefile.m32 [SSL=1] [SSH2=1] [ZLIB=1] [SSPI=1] [IPV6=1] [DYN=1] +## Usage: mingw32-make -f Makefile.m32 CFG=-feature1[-feature2][-feature3][...] +## Example: mingw32-make -f Makefile.m32 CFG=-zlib-ssl-spi-winidn ## ## Hint: you can also set environment vars to control the build, f.e.: -## set ZLIB_PATH=c:/zlib-1.2.3 +## set ZLIB_PATH=c:/zlib-1.2.5 ## set ZLIB=1 -## -######################################################################### +# +########################################################################### # Edit the path below to point to the base of your Zlib sources. ifndef ZLIB_PATH -ZLIB_PATH = ../../zlib-1.2.3 +ZLIB_PATH = ../../../zlib-1.2.5 endif # Edit the path below to point to the base of your OpenSSL package. ifndef OPENSSL_PATH -OPENSSL_PATH = ../../openssl-0.9.8k +OPENSSL_PATH = ../../../openssl-0.9.8r +endif +ifndef OPENSSL_LIB +OPENSSL_LIB = $(OPENSSL_PATH)/out endif # Edit the path below to point to the base of your LibSSH2 package. ifndef LIBSSH2_PATH -LIBSSH2_PATH = ../../libssh2-1.2 +LIBSSH2_PATH = ../../../libssh2-1.3.0 +endif +# Edit the path below to point to the base of your librtmp package. +ifndef LIBRTMP_PATH +LIBRTMP_PATH = ../../../librtmp-2.3 +endif +# Edit the path below to point to the base of your libidn package. +ifndef LIBIDN_PATH +LIBIDN_PATH = ../../../libidn-1.18 +endif +# Edit the path below to point to the base of your MS idndlpackage. +# Microsoft Internationalized Domain Names (IDN) Mitigation APIs 1.1 +# http://www.microsoft.com/downloads/en/details.aspx?FamilyID=ad6158d7-ddba-416a-9109-07607425a815 +ifndef WINIDN_PATH +WINIDN_PATH = ../../../Microsoft IDN Mitigation APIs endif # Edit the path below to point to the base of your Novell LDAP NDK. ifndef LDAP_SDK @@ -51,25 +67,78 @@ LDAP_SDK = c:/novell/ndk/cldapsdk/win32 endif PROOT = ../.. -ARES_LIB = $(PROOT)/ares + +# Edit the path below to point to the base of your c-ares package. +ifndef LIBCARES_PATH +LIBCARES_PATH = $(PROOT)/ares +endif + +# Edit the var below to set to your architecture or set environment var. +ifndef ARCH +ARCH = w32 +endif SSL = 1 ZLIB = 1 CC = gcc CFLAGS = -g -O2 -Wall +CFLAGS += -fno-strict-aliasing +ifeq ($(ARCH),w64) +CFLAGS += -D_AMD64_ +endif # comment LDFLAGS below to keep debug info LDFLAGS = -s RC = windres RCFLAGS = --include-dir=$(PROOT)/include -O COFF -i -RM = del /q /f > NUL 2>&1 +RM = del /q /f 2>NUL CP = copy ######################################################## ## Nothing more to do below this line! +ifeq ($(findstring -dyn,$(CFG)),-dyn) +DYN = 1 +endif +ifeq ($(findstring -ares,$(CFG)),-ares) +ARES = 1 +endif +ifeq ($(findstring -rtmp,$(CFG)),-rtmp) +RTMP = 1 +SSL = 1 +ZLIB = 1 +endif +ifeq ($(findstring -ssh2,$(CFG)),-ssh2) +SSH2 = 1 +SSL = 1 +ZLIB = 1 +endif +ifeq ($(findstring -ssl,$(CFG)),-ssl) +SSL = 1 +endif +ifeq ($(findstring -zlib,$(CFG)),-zlib) +ZLIB = 1 +endif +ifeq ($(findstring -idn,$(CFG)),-idn) +IDN = 1 +endif +ifeq ($(findstring -winidn,$(CFG)),-winidn) +WINIDN = 1 +endif +ifeq ($(findstring -sspi,$(CFG)),-sspi) +SSPI = 1 +endif +ifeq ($(findstring -spnego,$(CFG)),-spnego) +SPNEGO = 1 +endif +ifeq ($(findstring -ldaps,$(CFG)),-ldaps) +LDAPS = 1 +endif +ifeq ($(findstring -ipv6,$(CFG)),-ipv6) +IPV6 = 1 +endif + INCLUDES = -I. -I$(PROOT) -I$(PROOT)/include -I$(PROOT)/lib -LINK = $(CC) $(LDFLAGS) -o $@ ifdef DYN curl_DEPENDENCIES = $(PROOT)/lib/libcurldll.a $(PROOT)/lib/libcurl.dll @@ -81,34 +150,45 @@ else endif ifdef ARES ifndef DYN - curl_DEPENDENCIES += $(ARES_LIB)/libcares.a + curl_DEPENDENCIES += $(LIBCARES_PATH)/libcares.a endif CFLAGS += -DUSE_ARES - curl_LDADD += -L$(ARES_LIB) -lcares + curl_LDADD += -L"$(LIBCARES_PATH)" -lcares +endif +ifdef RTMP + CFLAGS += -DUSE_LIBRTMP + curl_LDADD += -L"$(LIBRTMP_PATH)/librtmp" -lrtmp -lwinmm endif ifdef SSH2 CFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H - curl_LDADD += -L$(LIBSSH2_PATH)/win32 -lssh2 + curl_LDADD += -L"$(LIBSSH2_PATH)/win32" -lssh2 endif ifdef SSL - INCLUDES += -I"$(OPENSSL_PATH)/outinc" CFLAGS += -DUSE_SSLEAY -DHAVE_OPENSSL_ENGINE_H - ifdef DYN - curl_LDADD += -L$(OPENSSL_PATH)/out -leay32 -lssl32 - else - curl_LDADD += -L$(OPENSSL_PATH)/out -lssl -lcrypto -lgdi32 - endif + curl_LDADD += -L"$(OPENSSL_LIB)" -leay32 -lssl32 endif ifdef ZLIB INCLUDES += -I"$(ZLIB_PATH)" CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H - curl_LDADD += -L$(ZLIB_PATH) -lz + curl_LDADD += -L"$(ZLIB_PATH)" -lz +endif +ifdef IDN + CFLAGS += -DUSE_LIBIDN + curl_LDADD += -L"$(LIBIDN_PATH)/lib" -lidn +else +ifdef WINIDN + CFLAGS += -DUSE_WIN32_IDN + curl_LDADD += -L"$(WINIDN_PATH)" -lnormaliz +endif endif ifdef SSPI CFLAGS += -DUSE_WINDOWS_SSPI endif +ifdef SPNEGO + CFLAGS += -DHAVE_SPNEGO +endif ifdef IPV6 - CFLAGS += -DENABLE_IPV6 + CFLAGS += -DENABLE_IPV6 -D_WIN32_WINNT=0x0501 endif ifdef LDAPS CFLAGS += -DHAVE_LDAP_SSL @@ -127,7 +207,6 @@ curl_LDADD += -lwldap32 endif endif curl_LDADD += -lws2_32 -COMPILE = $(CC) $(INCLUDES) $(CFLAGS) # Makefile.inc provides the check_PROGRAMS and COMPLICATED_EXAMPLES defines include Makefile.inc @@ -140,10 +219,10 @@ example_PROGRAMS := $(patsubst %,%.exe,$(strip $(check_PROGRAMS))) all: $(example_PROGRAMS) .o.exe: $(curl_DEPENDENCIES) - $(LINK) $< $(curl_LDADD) + $(CC) $(LDFLAGS) -o $@ $< $(curl_LDADD) .c.o: - $(COMPILE) -c $< + $(CC) $(INCLUDES) $(CFLAGS) -c $< .rc.res: $(RC) $(RCFLAGS) $< -o $@ @@ -151,4 +230,3 @@ all: $(example_PROGRAMS) clean: $(RM) $(example_PROGRAMS) - -- cgit v1.2.1 From a6b69b64ad402fade4f04434395e2ea97da55fa8 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Wed, 21 Sep 2011 02:02:31 +0200 Subject: Some more MinGW build tweaks. Added envvars to specify OpenSSL include, libpath and lib. Added rule to create curlbuild.h from curlbuild.h.dist. --- docs/examples/Makefile.m32 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 45cde7746..44c288330 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -40,8 +40,11 @@ endif ifndef OPENSSL_PATH OPENSSL_PATH = ../../../openssl-0.9.8r endif -ifndef OPENSSL_LIB -OPENSSL_LIB = $(OPENSSL_PATH)/out +ifndef OPENSSL_LIBPATH +OPENSSL_LIBPATH = $(OPENSSL_PATH)/out +endif +ifndef OPENSSL_LIBS +OPENSSL_LIBS = -leay32 -lssl32 endif # Edit the path below to point to the base of your LibSSH2 package. ifndef LIBSSH2_PATH @@ -91,6 +94,7 @@ endif LDFLAGS = -s RC = windres RCFLAGS = --include-dir=$(PROOT)/include -O COFF -i + RM = del /q /f 2>NUL CP = copy @@ -165,7 +169,7 @@ ifdef SSH2 endif ifdef SSL CFLAGS += -DUSE_SSLEAY -DHAVE_OPENSSL_ENGINE_H - curl_LDADD += -L"$(OPENSSL_LIB)" -leay32 -lssl32 + curl_LDADD += -L"$(OPENSSL_LIBPATH)" $(OPENSSL_LIBS) endif ifdef ZLIB INCLUDES += -I"$(ZLIB_PATH)" -- cgit v1.2.1 From e4172d934da23083eb43660bf3300d77bf157bac Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Wed, 21 Sep 2011 03:25:19 +0200 Subject: Changed suffix rules to pattern rules. Suffix rules cannot have any prerequisites of their own. --- docs/examples/Makefile.m32 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 44c288330..32bc8f479 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -217,20 +217,21 @@ include Makefile.inc example_PROGRAMS := $(patsubst %,%.exe,$(strip $(check_PROGRAMS))) -.SUFFIXES: .rc .res .o .exe - all: $(example_PROGRAMS) -.o.exe: $(curl_DEPENDENCIES) +%.exe: %.o $(curl_DEPENDENCIES) $(CC) $(LDFLAGS) -o $@ $< $(curl_LDADD) -.c.o: +%.o: %.c $(CC) $(INCLUDES) $(CFLAGS) -c $< -.rc.res: +%.res: %.rc $(RC) $(RCFLAGS) $< -o $@ clean: - $(RM) $(example_PROGRAMS) + $(RM) $(example_PROGRAMS:.exe=.o) + +distclean vclean: clean + -$(RM) $(example_PROGRAMS) -- cgit v1.2.1 From 3317160c1978e4ace9ff093ff50e678645854964 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Wed, 21 Sep 2011 18:09:34 +0200 Subject: Fixed sample to compile for Windows platform. --- docs/examples/externalsocket.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/externalsocket.c b/docs/examples/externalsocket.c index 39440afd5..5951c078e 100644 --- a/docs/examples/externalsocket.c +++ b/docs/examples/externalsocket.c @@ -28,13 +28,17 @@ #include <stdlib.h> #include <curl/curl.h> -#include <sys/types.h> -#include <sys/socket.h> - -#include <sys/socket.h> /* socket definitions */ +#ifdef WIN32 +#include <windows.h> +#include <winsock2.h> +#include <ws2tcpip.h> +#define close closesocket +#else #include <sys/types.h> /* socket types */ +#include <sys/socket.h> /* socket definitions */ #include <arpa/inet.h> /* inet (3) funtions */ #include <unistd.h> /* misc. UNIX functions */ +#endif #include <errno.h> @@ -72,6 +76,16 @@ int main(void) struct sockaddr_in servaddr; /* socket address structure */ curl_socket_t sockfd; +#ifdef WIN32 + WSADATA wsaData; + int initwsa; + + if((initwsa = WSAStartup(MAKEWORD(2,0), &wsaData)) != 0) { + printf("WSAStartup failed: %d\n", initwsa); + return 1; + } +#endif + curl = curl_easy_init(); if(curl) { /* @@ -81,16 +95,16 @@ 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)) < 0 ) { - fprintf(stderr, "ECHOCLNT: Error creating listening socket.\n"); + if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) { + printf("Error creating listening socket.\n"); return 3; } memset(&servaddr, 0, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_port = htons(PORTNUM); + servaddr.sin_family = AF_INET; + servaddr.sin_port = htons(PORTNUM); - if(inet_aton(IPADDR, &servaddr.sin_addr) <= 0 ) + if (INADDR_NONE == (servaddr.sin_addr.s_addr = inet_addr(IPADDR))) return 2; if(connect(sockfd,(struct sockaddr *) &servaddr, sizeof(servaddr)) == -- cgit v1.2.1 From 62b0fdca9e556501ae2889075298c23994cecec3 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Wed, 21 Sep 2011 18:21:05 +0200 Subject: Another MinGW example makefile tweak. --- docs/examples/Makefile.m32 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 32bc8f479..909ec8cde 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -207,7 +207,7 @@ ifdef USE_LDAP_OPENLDAP endif ifndef USE_LDAP_NOVELL ifndef USE_LDAP_OPENLDAP -curl_LDADD += -lwldap32 + curl_LDADD += -lwldap32 endif endif curl_LDADD += -lws2_32 @@ -215,10 +215,10 @@ curl_LDADD += -lws2_32 # Makefile.inc provides the check_PROGRAMS and COMPLICATED_EXAMPLES defines include Makefile.inc -example_PROGRAMS := $(patsubst %,%.exe,$(strip $(check_PROGRAMS))) +check_PROGRAMS := $(patsubst %,%.exe,$(strip $(check_PROGRAMS))) -all: $(example_PROGRAMS) +all: $(check_PROGRAMS) %.exe: %.o $(curl_DEPENDENCIES) $(CC) $(LDFLAGS) -o $@ $< $(curl_LDADD) @@ -230,8 +230,8 @@ all: $(example_PROGRAMS) $(RC) $(RCFLAGS) $< -o $@ clean: - $(RM) $(example_PROGRAMS:.exe=.o) + -$(RM) $(check_PROGRAMS:.exe=.o) distclean vclean: clean - -$(RM) $(example_PROGRAMS) + -$(RM) $(check_PROGRAMS) -- cgit v1.2.1 From 3c3aa09c65a6b06b3291f787c1216188ad2d6649 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Thu, 22 Sep 2011 14:34:58 +0200 Subject: Added NetWare examples makefile. --- docs/examples/Makefile.am | 2 +- docs/examples/Makefile.netware | 395 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 396 insertions(+), 1 deletion(-) create mode 100644 docs/examples/Makefile.netware (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 6cf55f181..ea335eb34 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -23,7 +23,7 @@ AUTOMAKE_OPTIONS = foreign nostdinc EXTRA_DIST = README Makefile.example Makefile.inc Makefile.m32 \ - makefile.dj $(COMPLICATED_EXAMPLES) + Makefile.netware makefile.dj $(COMPLICATED_EXAMPLES) # Specify our include paths here, and do it relative to $(top_srcdir) and # $(top_builddir), to ensure that these paths which belong to the library diff --git a/docs/examples/Makefile.netware b/docs/examples/Makefile.netware new file mode 100644 index 000000000..f8853cfee --- /dev/null +++ b/docs/examples/Makefile.netware @@ -0,0 +1,395 @@ +################################################################# +# +## Makefile for building curl.nlm (NetWare version - gnu make) +## Use: make -f Makefile.netware +## +## Comments to: Guenter Knauf http://www.gknw.net/phpbb +# +################################################################# + +# Edit the path below to point to the base of your Novell NDK. +ifndef NDKBASE +NDKBASE = c:/novell +endif + +# Edit the path below to point to the base of your Zlib sources. +ifndef ZLIB_PATH +ZLIB_PATH = ../../../zlib-1.2.5 +endif + +# Edit the path below to point to the base of your OpenSSL package. +ifndef OPENSSL_PATH +OPENSSL_PATH = ../../../openssl-0.9.8r +endif + +# Edit the path below to point to the base of your LibSSH2 package. +ifndef LIBSSH2_PATH +LIBSSH2_PATH = ../../../libssh2-1.3.0 +endif + +# Edit the path below to point to the base of your axTLS package. +ifndef AXTLS_PATH +AXTLS_PATH = ../../../axTLS-1.2.7 +endif + +# Edit the path below to point to the base of your libidn package. +ifndef LIBIDN_PATH +LIBIDN_PATH = ../../../libidn-1.18 +endif + +# Edit the path below to point to the base of your librtmp package. +ifndef LIBRTMP_PATH +LIBRTMP_PATH = ../../../librtmp-2.3 +endif + +# Edit the path below to point to the base of your c-ares package. +ifndef LIBCARES_PATH +LIBCARES_PATH = ../../ares +endif + +ifndef INSTDIR +INSTDIR = ..$(DS)..$(DS)curl-$(LIBCURL_VERSION_STR)-bin-nw +endif + +# Edit the vars below to change NLM target settings. +TARGET = examples +VERSION = $(LIBCURL_VERSION) +COPYR = Copyright (C) $(LIBCURL_COPYRIGHT_STR) +DESCR = cURL ($(LIBARCH)) +MTSAFE = YES +STACK = 8192 +SCREEN = Example Program +# Comment the line below if you dont want to load protected automatically. +# LDRING = 3 + +# Uncomment the next line to enable linking with POSIX semantics. +# POSIXFL = 1 + +# Edit the var below to point to your lib architecture. +ifndef LIBARCH +LIBARCH = LIBC +endif + +# must be equal to NDEBUG or DEBUG, CURLDEBUG +ifndef DB +DB = NDEBUG +endif +# Optimization: -O<n> or debugging: -g +ifeq ($(DB),NDEBUG) + OPT = -O2 + OBJDIR = release +else + OPT = -g + OBJDIR = debug +endif + +# The following lines defines your compiler. +ifdef CWFolder + METROWERKS = $(CWFolder) +endif +ifdef METROWERKS + # MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support + MWCW_PATH = $(subst \,/,$(METROWERKS))/Novell Support/Metrowerks Support + CC = mwccnlm +else + CC = gcc +endif +PERL = perl +# Here you can find a native Win32 binary of the original awk: +# http://www.gknw.net/development/prgtools/awk-20100523.zip +AWK = awk +CP = cp -afv +MKDIR = mkdir +# RM = rm -f +# If you want to mark the target as MTSAFE you will need a tool for +# generating the xdc data for the linker; here's a minimal tool: +# http://www.gknw.net/development/prgtools/mkxdc.zip +MPKXDC = mkxdc + +# LIBARCH_U = $(shell $(AWK) 'BEGIN {print toupper(ARGV[1])}' $(LIBARCH)) +LIBARCH_L = $(shell $(AWK) 'BEGIN {print tolower(ARGV[1])}' $(LIBARCH)) + +# Include the version info retrieved from curlver.h +-include $(OBJDIR)/version.inc + +# Global flags for all compilers +CFLAGS += $(OPT) -D$(DB) -DNETWARE -DHAVE_CONFIG_H -nostdinc + +ifeq ($(CC),mwccnlm) +LD = mwldnlm +LDFLAGS = -nostdlib $< $(PRELUDE) $(LDLIBS) -o $@ -commandfile +LIBEXT = lib +CFLAGS += -gccinc -inline off -opt nointrinsics -proc 586 +CFLAGS += -relax_pointers +#CFLAGS += -w on +ifeq ($(LIBARCH),LIBC) +ifeq ($(POSIXFL),1) + PRELUDE = $(NDK_LIBC)/imports/posixpre.o +else + PRELUDE = $(NDK_LIBC)/imports/libcpre.o +endif + CFLAGS += -align 4 +else + # PRELUDE = $(NDK_CLIB)/imports/clibpre.o + # to avoid the __init_* / __deinit_* whoes dont use prelude from NDK + PRELUDE = "$(MWCW_PATH)/libraries/runtime/prelude.obj" + # CFLAGS += -include "$(MWCW_PATH)/headers/nlm_clib_prefix.h" + CFLAGS += -align 1 +endif +else +LD = nlmconv +LDFLAGS = -T +LIBEXT = a +CFLAGS += -m32 +CFLAGS += -fno-builtin -fno-strict-aliasing +ifeq ($(findstring gcc,$(CC)),gcc) +CFLAGS += -fpcc-struct-return +endif +CFLAGS += -Wall # -pedantic +ifeq ($(LIBARCH),LIBC) +ifeq ($(POSIXFL),1) + PRELUDE = $(NDK_LIBC)/imports/posixpre.gcc.o +else + PRELUDE = $(NDK_LIBC)/imports/libcpre.gcc.o +endif +else + # PRELUDE = $(NDK_CLIB)/imports/clibpre.gcc.o + # to avoid the __init_* / __deinit_* whoes dont use prelude from NDK + # http://www.gknw.net/development/mk_nlm/gcc_pre.zip + PRELUDE = $(NDK_ROOT)/pre/prelude.o + CFLAGS += -include $(NDKBASE)/nlmconv/genlm.h +endif +endif + +NDK_ROOT = $(NDKBASE)/ndk +ifndef NDK_CLIB +NDK_CLIB = $(NDK_ROOT)/nwsdk +endif +ifndef NDK_LIBC +NDK_LIBC = $(NDK_ROOT)/libc +endif +ifndef NDK_LDAP +NDK_LDAP = $(NDK_ROOT)/cldapsdk/netware +endif +CURL_INC = ../../include +CURL_LIB = ../../lib + +INCLUDES = -I$(CURL_INC) + +ifdef LINK_STATIC + LDLIBS = $(CURL_LIB)/libcurl.$(LIBEXT) +ifdef WITH_ARES + LDLIBS += $(LIBCARES_PATH)/libcares.$(LIBEXT) +endif +else + MODULES = libcurl.nlm + IMPORTS = @$(CURL_LIB)/libcurl.imp +endif +ifdef WITH_SSH2 + INCLUDES += -I$(LIBSSH2_PATH)/include +ifdef LINK_STATIC + LDLIBS += $(LIBSSH2_PATH)/nw/libssh2.$(LIBEXT) +else + MODULES += libssh2.nlm + IMPORTS += @$(LIBSSH2_PATH)/nw/libssh2.imp +endif +endif +ifdef WITH_RTMP + # INCLUDES += -I$(LIBRTMP_PATH) +ifdef LINK_STATIC + LDLIBS += $(LIBRTMP_PATH)/librtmp/librtmp.$(LIBEXT) +endif +endif +ifdef WITH_SSL + # INCLUDES += -I$(OPENSSL_PATH)/outinc_nw_$(LIBARCH_L) + LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/ssl.$(LIBEXT) + LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/crypto.$(LIBEXT) + IMPORTS += GetProcessSwitchCount RunningProcess +else +ifdef WITH_AXTLS + INCLUDES += -I$(AXTLS_PATH)/inc +ifdef LINK_STATIC + LDLIBS += $(AXTLS_PATH)/lib/libaxtls.$(LIBEXT) +else + MODULES += libaxtls.nlm + IMPORTS += $(AXTLS_PATH)/lib/libaxtls.imp +endif +endif +endif +ifdef WITH_ZLIB + # INCLUDES += -I$(ZLIB_PATH) +ifdef LINK_STATIC + LDLIBS += $(ZLIB_PATH)/nw/$(LIBARCH)/libz.$(LIBEXT) +else + MODULES += libz.nlm + IMPORTS += @$(ZLIB_PATH)/nw/$(LIBARCH)/libz.imp +endif +endif +ifdef WITH_IDN + # INCLUDES += -I$(LIBIDN_PATH)/include + LDLIBS += $(LIBIDN_PATH)/lib/libidn.$(LIBEXT) +endif + +ifeq ($(LIBARCH),LIBC) + INCLUDES += -I$(NDK_LIBC)/include + # INCLUDES += -I$(NDK_LIBC)/include/nks + # INCLUDES += -I$(NDK_LIBC)/include/winsock + CFLAGS += -D_POSIX_SOURCE +else + INCLUDES += -I$(NDK_CLIB)/include/nlm + # INCLUDES += -I$(NDK_CLIB)/include +endif +ifndef DISABLE_LDAP + # INCLUDES += -I$(NDK_LDAP)/$(LIBARCH_L)/inc +endif +CFLAGS += $(INCLUDES) + +ifeq ($(MTSAFE),YES) + XDCOPT = -n +endif +ifeq ($(MTSAFE),NO) + XDCOPT = -u +endif +ifdef XDCOPT + XDCDATA = $(OBJDIR)/$(TARGET).xdc +endif + +ifeq ($(findstring /sh,$(SHELL)),/sh) +DL = ' +DS = / +PCT = % +#-include $(NDKBASE)/nlmconv/ncpfs.inc +else +DS = \\ +PCT = %% +endif + +# Makefile.inc provides the CSOURCES and HHEADERS defines +include Makefile.inc + +check_PROGRAMS := $(patsubst %,%.nlm,$(strip $(check_PROGRAMS))) + +.PRECIOUS: $(OBJDIR)/%.o $(OBJDIR)/%.def $(OBJDIR)/%.xdc + + +all: prebuild $(check_PROGRAMS) + +prebuild: $(OBJDIR) $(OBJDIR)/version.inc + +$(OBJDIR)/%.o: %.c + @echo Compiling $< + $(CC) $(CFLAGS) -c $< -o $@ + +$(OBJDIR)/version.inc: $(CURL_INC)/curl/curlver.h $(OBJDIR) + @echo Creating $@ + @$(AWK) -f ../../packages/NetWare/get_ver.awk $< > $@ + +install: $(INSTDIR) all + @$(CP) $(check_PROGRAMS) $(INSTDIR) + +clean: + -$(RM) -r $(OBJDIR) + +distclean vclean: clean + -$(RM) $(check_PROGRAMS) + +$(OBJDIR) $(INSTDIR): + @$(MKDIR) $@ + +%.nlm: $(OBJDIR)/%.o $(OBJDIR)/%.def $(XDCDATA) + @echo Linking $@ + @-$(RM) $@ + @$(LD) $(LDFLAGS) $(OBJDIR)/$(@:.nlm=.def) + +$(OBJDIR)/%.xdc: Makefile.netware + @echo Creating $@ + @$(MPKXDC) $(XDCOPT) $@ + +$(OBJDIR)/%.def: Makefile.netware + @echo $(DL)# DEF file for linking with $(LD)$(DL) > $@ + @echo $(DL)# Do not edit this file - it is created by Make!$(DL) >> $@ + @echo $(DL)# All your changes will be lost!!$(DL) >> $@ + @echo $(DL)#$(DL) >> $@ + @echo $(DL)copyright "$(COPYR)"$(DL) >> $@ + @echo $(DL)description "$(DESCR) $(notdir $(@:.def=)) Example"$(DL) >> $@ + @echo $(DL)version $(VERSION)$(DL) >> $@ +ifdef NLMTYPE + @echo $(DL)type $(NLMTYPE)$(DL) >> $@ +endif +ifdef STACK + @echo $(DL)stack $(STACK)$(DL) >> $@ +endif +ifdef SCREEN + @echo $(DL)screenname "$(DESCR) $(notdir $(@:.def=)) $(SCREEN)"$(DL) >> $@ +else + @echo $(DL)screenname "DEFAULT"$(DL) >> $@ +endif +ifneq ($(DB),NDEBUG) + @echo $(DL)debug$(DL) >> $@ +endif + @echo $(DL)threadname "_$(notdir $(@:.def=))"$(DL) >> $@ +ifdef XDCDATA + @echo $(DL)xdcdata $(XDCDATA)$(DL) >> $@ +endif +ifeq ($(LDRING),0) + @echo $(DL)flag_on 16$(DL) >> $@ +endif +ifeq ($(LDRING),3) + @echo $(DL)flag_on 512$(DL) >> $@ +endif +ifeq ($(LIBARCH),CLIB) + @echo $(DL)start _Prelude$(DL) >> $@ + @echo $(DL)exit _Stop$(DL) >> $@ + @echo $(DL)import @$(NDK_CLIB)/imports/clib.imp$(DL) >> $@ + @echo $(DL)import @$(NDK_CLIB)/imports/threads.imp$(DL) >> $@ + @echo $(DL)import @$(NDK_CLIB)/imports/nlmlib.imp$(DL) >> $@ + @echo $(DL)import @$(NDK_CLIB)/imports/socklib.imp$(DL) >> $@ + @echo $(DL)module clib$(DL) >> $@ +ifndef DISABLE_LDAP + @echo $(DL)import @$(NDK_LDAP)/clib/imports/ldapsdk.imp$(DL) >> $@ + @echo $(DL)import @$(NDK_LDAP)/clib/imports/ldapssl.imp$(DL) >> $@ +# @echo $(DL)import @$(NDK_LDAP)/clib/imports/ldapx.imp$(DL) >> $@ + @echo $(DL)module ldapsdk ldapssl$(DL) >> $@ +endif +else +ifeq ($(POSIXFL),1) + @echo $(DL)flag_on 4194304$(DL) >> $@ +endif + @echo $(DL)flag_on 64$(DL) >> $@ + @echo $(DL)pseudopreemption$(DL) >> $@ +ifeq ($(findstring posixpre,$(PRELUDE)),posixpre) + @echo $(DL)start POSIX_Start$(DL) >> $@ + @echo $(DL)exit POSIX_Stop$(DL) >> $@ + @echo $(DL)check POSIX_CheckUnload$(DL) >> $@ +else + @echo $(DL)start _LibCPrelude$(DL) >> $@ + @echo $(DL)exit _LibCPostlude$(DL) >> $@ + @echo $(DL)check _LibCCheckUnload$(DL) >> $@ +endif + @echo $(DL)import @$(NDK_LIBC)/imports/libc.imp$(DL) >> $@ + @echo $(DL)import @$(NDK_LIBC)/imports/netware.imp$(DL) >> $@ + @echo $(DL)module libc$(DL) >> $@ +ifndef DISABLE_LDAP + @echo $(DL)import @$(NDK_LDAP)/libc/imports/lldapsdk.imp$(DL) >> $@ + @echo $(DL)import @$(NDK_LDAP)/libc/imports/lldapssl.imp$(DL) >> $@ +# @echo $(DL)import @$(NDK_LDAP)/libc/imports/lldapx.imp$(DL) >> $@ + @echo $(DL)module lldapsdk lldapssl$(DL) >> $@ +endif +endif +ifdef MODULES + @echo $(DL)module $(MODULES)$(DL) >> $@ +endif +ifdef EXPORTS + @echo $(DL)export $(EXPORTS)$(DL) >> $@ +endif +ifdef IMPORTS + @echo $(DL)import $(IMPORTS)$(DL) >> $@ +endif +ifeq ($(findstring nlmconv,$(LD)),nlmconv) + @echo $(DL)input $(PRELUDE)$(DL) >> $@ + @echo $(DL)input $(@:.def=.o)$(DL) >> $@ +ifdef LDLIBS + @echo $(DL)input $(LDLIBS)$(DL) >> $@ +endif + @echo $(DL)output $(notdir $(@:.def=.nlm))$(DL) >> $@ +endif -- cgit v1.2.1 From ba52e0a93bbdfa0430d12cda14d4ed71616b92a1 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Fri, 23 Sep 2011 01:22:18 +0200 Subject: Added a workaround for printing size_t. --- docs/examples/anyauthput.c | 3 ++- docs/examples/ftpupload.c | 3 ++- docs/examples/httpput.c | 3 ++- docs/examples/printf_macro.h | 45 ++++++++++++++++++++++++++++++++++++++++++++ docs/examples/sendrecv.c | 3 ++- 5 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 docs/examples/printf_macro.h (limited to 'docs/examples') diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index 76fa15853..bab36c57b 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -41,6 +41,7 @@ #endif #include <curl/curl.h> +#include "printf_macro.h" #if LIBCURL_VERSION_NUM < 0x070c03 #error "upgrade your libcurl to no less than 7.12.3" @@ -92,7 +93,7 @@ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) retcode = read(fd, ptr, size * nmemb); - fprintf(stderr, "*** We read %d bytes from file\n", retcode); + fprintf(stderr, "*** We read %" _FMT_SIZE_T " bytes from file\n", retcode); return retcode; } diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index 305734d5d..722acbc9e 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -32,6 +32,7 @@ #else #include <unistd.h> #endif +#include "printf_macro.h" /* * This example shows an FTP upload, with a rename of the file just after @@ -56,7 +57,7 @@ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) by default internally */ size_t retcode = fread(ptr, size, nmemb, stream); - fprintf(stderr, "*** We read %d bytes from file\n", retcode); + fprintf(stderr, "*** We read %" _FMT_SIZE_T " bytes from file\n", retcode); return retcode; } diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index f78a74107..664c8e152 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -25,6 +25,7 @@ #include <unistd.h> #include <curl/curl.h> +#include "printf_macro.h" /* * This example shows a HTTP PUT operation. PUTs a file given as a command @@ -45,7 +46,7 @@ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) by default internally */ retcode = fread(ptr, size, nmemb, stream); - fprintf(stderr, "*** We read %d bytes from file\n", retcode); + fprintf(stderr, "*** We read %" _FMT_SIZE_T " bytes from file\n", retcode); return retcode; } diff --git a/docs/examples/printf_macro.h b/docs/examples/printf_macro.h new file mode 100644 index 000000000..9eed8f4c6 --- /dev/null +++ b/docs/examples/printf_macro.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ +/* Simple hack trying to get a valid printf format string for size_t. + * If that fails for your platform you can define your own _FMT_SIZE_T, + * f.e.: -D_FMT_SIZE_T="zd" + */ +#ifndef _PRINTF_MACRO_H +#define _PRINTF_MACRO_H + +#ifndef _FMT_SIZE_T +#ifdef WIN32 +#define _FMT_SIZE_T "Id" +#else +/* +"zd" is a GNU extension to POSIX; so we dont use it for size_t but hack around +#define _FMT_SIZE_T "zd" +*/ +#ifdef __x86_64__ +#define _FMT_SIZE_T "lu" +#else +#define _FMT_SIZE_T "u" +#endif /* __x86_64__ */ +#endif /* WIN32 */ +#endif /* !_FMT_SIZE_T */ + +#endif /* !_PRINTF_MACRO_H */ diff --git a/docs/examples/sendrecv.c b/docs/examples/sendrecv.c index 0a49f2ff5..369601d16 100644 --- a/docs/examples/sendrecv.c +++ b/docs/examples/sendrecv.c @@ -24,6 +24,7 @@ #include <stdio.h> #include <string.h> #include <curl/curl.h> +#include "printf_macro.h" /* Auxiliary function that waits on the socket. */ static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms) @@ -122,7 +123,7 @@ int main(void) if(CURLE_OK != res) break; - printf("Received %u bytes.\n", iolen); + printf("Received %" _FMT_SIZE_T " bytes.\n", iolen); } /* always cleanup */ -- cgit v1.2.1 From ef3f1f314631eb9bb5843c78349ec685aa5ef4a6 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Fri, 23 Sep 2011 03:00:32 +0200 Subject: Added Win32-only samples. --- docs/examples/Makefile.m32 | 1 + 1 file changed, 1 insertion(+) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 909ec8cde..975eed6b9 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -216,6 +216,7 @@ curl_LDADD += -lws2_32 include Makefile.inc check_PROGRAMS := $(patsubst %,%.exe,$(strip $(check_PROGRAMS))) +check_PROGRAMS += ftpuploadresume.exe synctime.exe all: $(check_PROGRAMS) -- cgit v1.2.1 From dafa2fc9442825dc5256d65f5af7ccb6fbbb78fd Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Fri, 23 Sep 2011 03:21:50 +0200 Subject: Fixed scanf format for WORD = unsigned short. --- docs/examples/synctime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/synctime.c b/docs/examples/synctime.c index 70b84c326..14d77de27 100644 --- a/docs/examples/synctime.c +++ b/docs/examples/synctime.c @@ -147,7 +147,7 @@ size_t SyncTime_CURL_WriteHeader(void *ptr, size_t size, size_t nmemb, TmpStr1 & 2? */ AutoSyncTime = 0; else { - RetVal = sscanf ((char *)(ptr), "Date: %s %d %s %d %d:%d:%d", + RetVal = sscanf ((char *)(ptr), "Date: %s %hu %s %hu %hu:%hu:%hu", TmpStr1, &SYSTime.wDay, TmpStr2, &SYSTime.wYear, &SYSTime.wHour, &SYSTime.wMinute, &SYSTime.wSecond); -- cgit v1.2.1 From 87a45c79986383644f1bcdba8101293432c33926 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Fri, 23 Sep 2011 03:56:34 +0200 Subject: MinGW64 has this prototype already. --- docs/examples/ftpuploadresume.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/ftpuploadresume.c b/docs/examples/ftpuploadresume.c index 0560b54dc..55b8986c7 100644 --- a/docs/examples/ftpuploadresume.c +++ b/docs/examples/ftpuploadresume.c @@ -39,7 +39,7 @@ /* The MinGW headers are missing a few Win32 function definitions, you shouldn't need this if you use VC++ */ -#ifdef __MINGW32__ +#if defined(__MINGW32__) && !defined(__MINGW64__) int __cdecl _snscanf(const char * input, size_t length, const char * format, ...); #endif -- cgit v1.2.1 From 8bab6700d9a7f2085c81c069e0ac0792ac0521b2 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Sat, 24 Sep 2011 15:06:21 +0200 Subject: Added header to be included by dist script. Probably the wrong place, but I dont know better. --- docs/examples/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index ea335eb34..735942e78 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -23,7 +23,7 @@ AUTOMAKE_OPTIONS = foreign nostdinc EXTRA_DIST = README Makefile.example Makefile.inc Makefile.m32 \ - Makefile.netware makefile.dj $(COMPLICATED_EXAMPLES) + Makefile.netware makefile.dj printf_macro.h $(COMPLICATED_EXAMPLES) # Specify our include paths here, and do it relative to $(top_srcdir) and # $(top_builddir), to ensure that these paths which belong to the library -- cgit v1.2.1 From 230459dd00d216992c919a3618d5fa6707b2dd89 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Sun, 25 Sep 2011 16:29:08 +0200 Subject: NetWare makefile tweaks to select different builds. --- docs/examples/Makefile.netware | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.netware b/docs/examples/Makefile.netware index f8853cfee..2f3157d1a 100644 --- a/docs/examples/Makefile.netware +++ b/docs/examples/Makefile.netware @@ -176,6 +176,43 @@ CURL_LIB = ../../lib INCLUDES = -I$(CURL_INC) +ifeq ($(findstring -static,$(CFG)),-static) +LINK_STATIC = 1 +endif +ifeq ($(findstring -ares,$(CFG)),-ares) +WITH_ARES = 1 +endif +ifeq ($(findstring -rtmp,$(CFG)),-rtmp) +WITH_RTMP = 1 +WITH_SSL = 1 +WITH_ZLIB = 1 +endif +ifeq ($(findstring -ssh2,$(CFG)),-ssh2) +WITH_SSH2 = 1 +WITH_SSL = 1 +WITH_ZLIB = 1 +endif +ifeq ($(findstring -axtls,$(CFG)),-axtls) +WITH_AXTLS = 1 +WITH_SSL = +else +ifeq ($(findstring -ssl,$(CFG)),-ssl) +WITH_SSL = 1 +endif +endif +ifeq ($(findstring -zlib,$(CFG)),-zlib) +WITH_ZLIB = 1 +endif +ifeq ($(findstring -idn,$(CFG)),-idn) +WITH_IDN = 1 +endif +ifeq ($(findstring -spnego,$(CFG)),-spnego) +WITH_SPNEGO = 1 +endif +ifeq ($(findstring -ipv6,$(CFG)),-ipv6) +ENABLE_IPV6 = 1 +endif + ifdef LINK_STATIC LDLIBS = $(CURL_LIB)/libcurl.$(LIBEXT) ifdef WITH_ARES -- cgit v1.2.1 From bb94b92894eef5d62d9b19b39cf5af921ee5fd2d Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Sun, 25 Sep 2011 16:31:31 +0200 Subject: Fixed MinGW examples makefile. --- docs/examples/Makefile.m32 | 3 --- 1 file changed, 3 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 975eed6b9..e744c5b30 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -81,9 +81,6 @@ ifndef ARCH ARCH = w32 endif -SSL = 1 -ZLIB = 1 - CC = gcc CFLAGS = -g -O2 -Wall CFLAGS += -fno-strict-aliasing -- cgit v1.2.1 From b4fccc1d8e9bb8a05436e5f0bf8f4910a20ad9af Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Tue, 27 Sep 2011 16:01:36 +0200 Subject: Added SPNEGO to NetWare build. --- docs/examples/Makefile.netware | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.netware b/docs/examples/Makefile.netware index 2f3157d1a..fdea6b81b 100644 --- a/docs/examples/Makefile.netware +++ b/docs/examples/Makefile.netware @@ -42,6 +42,11 @@ ifndef LIBRTMP_PATH LIBRTMP_PATH = ../../../librtmp-2.3 endif +# Edit the path below to point to the base of your fbopenssl package. +ifndef FBOPENSSL_PATH +FBOPENSSL_PATH = ../../fbopenssl-0.4 +endif + # Edit the path below to point to the base of your c-ares package. ifndef LIBCARES_PATH LIBCARES_PATH = ../../ares @@ -223,7 +228,7 @@ else IMPORTS = @$(CURL_LIB)/libcurl.imp endif ifdef WITH_SSH2 - INCLUDES += -I$(LIBSSH2_PATH)/include + # INCLUDES += -I$(LIBSSH2_PATH)/include ifdef LINK_STATIC LDLIBS += $(LIBSSH2_PATH)/nw/libssh2.$(LIBEXT) else @@ -238,10 +243,14 @@ ifdef LINK_STATIC endif endif ifdef WITH_SSL - # INCLUDES += -I$(OPENSSL_PATH)/outinc_nw_$(LIBARCH_L) + INCLUDES += -I$(OPENSSL_PATH)/outinc_nw_$(LIBARCH_L) LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/ssl.$(LIBEXT) LDLIBS += $(OPENSSL_PATH)/out_nw_$(LIBARCH_L)/crypto.$(LIBEXT) IMPORTS += GetProcessSwitchCount RunningProcess +ifdef WITH_SPNEGO + # INCLUDES += -I$(FBOPENSSL_PATH)/include + LDLIBS += $(FBOPENSSL_PATH)/nw/fbopenssl.$(LIBEXT) +endif else ifdef WITH_AXTLS INCLUDES += -I$(AXTLS_PATH)/inc -- cgit v1.2.1 From 95ddbdb1dbfbb051d67bf0d6643b1a917a4c7d88 Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Mon, 14 Nov 2011 14:03:31 -0800 Subject: curl_easy_setopt arguments should be of type long in the examples --- docs/examples/rtsp.c | 10 +++++----- docs/examples/smtp-multi.c | 12 ++++++------ docs/examples/smtp-tls.c | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/rtsp.c b/docs/examples/rtsp.c index 42b26cc71..1cc19677a 100644 --- a/docs/examples/rtsp.c +++ b/docs/examples/rtsp.c @@ -73,7 +73,7 @@ static void rtsp_options(CURL *curl, const char *uri) CURLcode res = CURLE_OK; printf("\nRTSP: OPTIONS %s\n", uri); my_curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri); - my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS); + my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_OPTIONS); my_curl_easy_perform(curl); } @@ -93,7 +93,7 @@ static void rtsp_describe(CURL *curl, const char *uri, printf("Writing SDP to '%s'\n", sdp_filename); } my_curl_easy_setopt(curl, CURLOPT_WRITEDATA, sdp_fp); - my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE); + 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) { @@ -109,7 +109,7 @@ static void rtsp_setup(CURL *curl, const char *uri, const char *transport) printf(" TRANSPORT %s\n", transport); my_curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri); my_curl_easy_setopt(curl, CURLOPT_RTSP_TRANSPORT, transport); - my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP); + my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_SETUP); my_curl_easy_perform(curl); } @@ -121,7 +121,7 @@ static void rtsp_play(CURL *curl, const char *uri, const char *range) printf("\nRTSP: PLAY %s\n", uri); my_curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri); my_curl_easy_setopt(curl, CURLOPT_RANGE, range); - my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY); + my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_PLAY); my_curl_easy_perform(curl); } @@ -131,7 +131,7 @@ static void rtsp_teardown(CURL *curl, const char *uri) { CURLcode res = CURLE_OK; printf("\nRTSP: TEARDOWN %s\n", uri); - my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN); + my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_TEARDOWN); my_curl_easy_perform(curl); } diff --git a/docs/examples/smtp-multi.c b/docs/examples/smtp-multi.c index 15b177e5e..828132073 100644 --- a/docs/examples/smtp-multi.c +++ b/docs/examples/smtp-multi.c @@ -123,13 +123,13 @@ int main(void) curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback); curl_easy_setopt(curl, CURLOPT_MAIL_FROM, MAILFROM); curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt_list); - curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER,0); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); + curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); curl_easy_setopt(curl, CURLOPT_READDATA, &pooh); - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); - curl_easy_setopt(curl, CURLOPT_SSLVERSION, 0); - curl_easy_setopt(curl, CURLOPT_SSL_SESSIONID_CACHE, 0); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + curl_easy_setopt(curl, CURLOPT_SSLVERSION, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_SESSIONID_CACHE, 0L); curl_multi_add_handle(mcurl, curl); mp_timedout = 0; diff --git a/docs/examples/smtp-tls.c b/docs/examples/smtp-tls.c index 2e71f973e..8e2603fa4 100644 --- a/docs/examples/smtp-tls.c +++ b/docs/examples/smtp-tls.c @@ -94,13 +94,13 @@ int main(void) * of using CURLUSESSL_TRY here, because if TLS upgrade fails, the transfer * will continue anyway - see the security discussion in the libcurl * tutorial for more details. */ - curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL); + curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL); /* If your server doesn't have a valid certificate, then you can disable * part of the Transport Layer Security protection by setting the * CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST options to 0 (false). - * curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); - * curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); + * 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 @@ -135,7 +135,7 @@ int main(void) /* Since the traffic will be encrypted, it is very useful to turn on debug * information within libcurl to see what is happening during the transfer. */ - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); /* send the message (including headers) */ res = curl_easy_perform(curl); -- cgit v1.2.1 From 7e4daaf908307220e408754f84a5706efe230a38 Mon Sep 17 00:00:00 2001 From: Rob Ward <rob@rob-ward.co.uk> Date: Mon, 5 Dec 2011 23:07:38 +0100 Subject: progress function example: include timed interval Adds a timer based off of CURLINFO_TOTAL_TIME that is used to perform certain actions after a minimum amount of time has passed using the progress function. As a consequence the curl handle is now also passed into the progress function. Progress example now also includes an example of how to retreive the TOTAL_TIME and print it out. --- docs/examples/progressfunc.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/progressfunc.c b/docs/examples/progressfunc.c index 42ed3287b..a49806028 100644 --- a/docs/examples/progressfunc.c +++ b/docs/examples/progressfunc.c @@ -22,12 +22,32 @@ #include <stdio.h> #include <curl/curl.h> -#define STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES 6000 +#define STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES 6000 +#define MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL 3 + +struct myprogress { + double lastruntime; + CURL *curl; +}; static int progress(void *p, double dltotal, double dlnow, double ultotal, double ulnow) { + struct myprogress *myp = (struct myprogress *)p; + CURL *curl = myp->curl; + double curtime = 0; + + curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &curtime); + + /* under certain circumstances it may be desirable for certain functionality + to only run every N seconds, in order to do this the transaction time can + be used */ + if((curtime - myp->lastruntime) >= MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL) { + myp->lastruntime = curtime; + fprintf(stderr, "TOTAL TIME: %f \r\n", curtime); + } + fprintf(stderr, "UP: %g of %g DOWN: %g of %g\r\n", ulnow, ultotal, dlnow, dltotal); @@ -40,11 +60,17 @@ int main(void) { CURL *curl; CURLcode res=0; + struct myprogress prog; curl = curl_easy_init(); if(curl) { + prog.lastruntime = 0; + prog.curl = curl; + curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/"); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress); + /* pass the struct pointer into the progress function */ + curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &prog); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); res = curl_easy_perform(curl); -- cgit v1.2.1 From 46724b87b769ff50e1e6b90d2aabc50b8ba7c1a9 Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Tue, 6 Dec 2011 19:54:48 -0800 Subject: Added some include files in a couple of example programs This improves portability of the examples. This patch was submitted to the OpenBSD ports collection by naddy. --- docs/examples/anyauthput.c | 1 + docs/examples/externalsocket.c | 1 + 2 files changed, 2 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index bab36c57b..2997a1e98 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -27,6 +27,7 @@ # ifdef __VMS typedef int intptr_t; # endif +# include <stdint.h> # include <unistd.h> #endif #include <sys/types.h> diff --git a/docs/examples/externalsocket.c b/docs/examples/externalsocket.c index 5951c078e..c4abafd87 100644 --- a/docs/examples/externalsocket.c +++ b/docs/examples/externalsocket.c @@ -36,6 +36,7 @@ #else #include <sys/types.h> /* socket types */ #include <sys/socket.h> /* socket definitions */ +#include <netinet/in.h> #include <arpa/inet.h> /* inet (3) funtions */ #include <unistd.h> /* misc. UNIX functions */ #endif -- cgit v1.2.1 From ed0364343dc2472fdc6a390bb00c3e20152e8e6f Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Fri, 30 Dec 2011 03:36:18 +0100 Subject: removed trailing whitespace --- docs/examples/Makefile.m32 | 2 +- docs/examples/version-check.pl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index e744c5b30..3c3d121ed 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -58,7 +58,7 @@ endif ifndef LIBIDN_PATH LIBIDN_PATH = ../../../libidn-1.18 endif -# Edit the path below to point to the base of your MS idndlpackage. +# Edit the path below to point to the base of your MS IDN package. # Microsoft Internationalized Domain Names (IDN) Mitigation APIs 1.1 # http://www.microsoft.com/downloads/en/details.aspx?FamilyID=ad6158d7-ddba-416a-9109-07607425a815 ifndef WINIDN_PATH diff --git a/docs/examples/version-check.pl b/docs/examples/version-check.pl index 9b6a2684c..92f0808d6 100755 --- a/docs/examples/version-check.pl +++ b/docs/examples/version-check.pl @@ -90,7 +90,7 @@ my @recent = reverse sort sortversions keys %used; # the most recent symbol my $newsym = $recent[0]; # the most recent version -my $newver = $doc{$newsym}; +my $newver = $doc{$newsym}; print "The scanned source uses these symbols introduced in $newver:\n"; -- cgit v1.2.1 From ecd75e8cb803f7b938c44e8594222406404a955c Mon Sep 17 00:00:00 2001 From: Alessandro Ghedini <al3xbio@gmail.com> Date: Wed, 28 Dec 2011 15:01:05 +0100 Subject: examples: add a couple of simple pop3s examples These examples show how to fetch a single message (RETR command) and how to list all the messages in a given mailbox (LIST command), with authentication via SSL. They were both based on the https.c example. --- docs/examples/pop3s.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ docs/examples/pop3slist.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 docs/examples/pop3s.c create mode 100644 docs/examples/pop3slist.c (limited to 'docs/examples') diff --git a/docs/examples/pop3s.c b/docs/examples/pop3s.c new file mode 100644 index 000000000..4a2e8fdeb --- /dev/null +++ b/docs/examples/pop3s.c @@ -0,0 +1,68 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ +#include <stdio.h> +#include <curl/curl.h> + +int main(void) +{ + CURL *curl; + CURLcode res; + + curl = curl_easy_init(); + if(curl) { + /* Set username and password */ + curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password"); + + /* This will only fetch the message with ID "1" of the given mailbox */ + curl_easy_setopt(curl, CURLOPT_URL, "pop3s://user@pop.example.com/1"); + +#ifdef SKIP_PEER_VERIFICATION + /* + * 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 + * verification of the server's certificate. This makes the connection + * A LOT LESS SECURE. + * + * If you have a CA cert for the server stored someplace else than in the + * default bundle, then the CURLOPT_CAPATH option might come handy for + * you. + */ + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); +#endif + +#ifdef SKIP_HOSTNAME_VERFICATION + /* + * If the site you're connecting to uses a different host name that what + * they have mentioned in their server certificate's commonName (or + * subjectAltName) fields, libcurl will refuse to connect. You can skip + * this check, but this will make the connection less secure. + */ + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); +#endif + + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} diff --git a/docs/examples/pop3slist.c b/docs/examples/pop3slist.c new file mode 100644 index 000000000..54cb28784 --- /dev/null +++ b/docs/examples/pop3slist.c @@ -0,0 +1,68 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ +#include <stdio.h> +#include <curl/curl.h> + +int main(void) +{ + CURL *curl; + CURLcode res; + + curl = curl_easy_init(); + if(curl) { + /* Set username and password */ + curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password"); + + /* This will list every message of the given mailbox */ + curl_easy_setopt(curl, CURLOPT_URL, "pop3s://user@pop.example.com/"); + +#ifdef SKIP_PEER_VERIFICATION + /* + * 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 + * verification of the server's certificate. This makes the connection + * A LOT LESS SECURE. + * + * If you have a CA cert for the server stored someplace else than in the + * default bundle, then the CURLOPT_CAPATH option might come handy for + * you. + */ + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); +#endif + +#ifdef SKIP_HOSTNAME_VERFICATION + /* + * If the site you're connecting to uses a different host name that what + * they have mentioned in their server certificate's commonName (or + * subjectAltName) fields, libcurl will refuse to connect. You can skip + * this check, but this will make the connection less secure. + */ + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); +#endif + + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return 0; +} -- cgit v1.2.1 From 90343c76c6f1517a2d9d3c9e9cea15a1be2bfd6d Mon Sep 17 00:00:00 2001 From: Alessandro Ghedini <al3xbio@gmail.com> Date: Wed, 28 Dec 2011 16:33:17 +0100 Subject: examples: update README, Makefile.inc and gitignore with pop3s examples --- docs/examples/.gitignore | 2 ++ docs/examples/Makefile.inc | 2 +- docs/examples/README | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/.gitignore b/docs/examples/.gitignore index 2ee9df154..fe677de50 100644 --- a/docs/examples/.gitignore +++ b/docs/examples/.gitignore @@ -24,6 +24,8 @@ multi-double multi-post multi-single persistant +pop3s +pop3slist post-callback postit2 progressfunc diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index bf7337dd8..e87fb1f2a 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -5,7 +5,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ persistant post-callback postit2 sepheaders simple simplepost simplessl \ sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard \ smtp-multi simplesmtp smtp-tls rtsp externalsocket resolve \ - progressfunc + progressfunc pop3s pop3slist # 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/README b/docs/examples/README index d6c478568..da04d2886 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -63,6 +63,8 @@ multi-single.c - a multi-interface app getting a single file 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 -- cgit v1.2.1 From 81524cbfa02f8882040ecf2947dcf5c8523591ca Mon Sep 17 00:00:00 2001 From: Peter Sylvester <peter.sylvester@edelweb.fr> Date: Wed, 4 Jan 2012 23:02:36 +0100 Subject: OpenSSL: remove reference to openssl internal struct With this change, curl compiles with the new OPENSSL_NO_SSL_INTERN cflag. This flag might become the default in some distant future. --- docs/examples/curlx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 62bdfe405..89d5f407b 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -239,8 +239,7 @@ static CURLcode sslctxfun(CURL * curl, void * sslctx, void * parm) { SSL_CTX_set_cipher_list(ctx,"RC4-MD5"); SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY); - X509_STORE_add_cert(ctx->cert_store,sk_X509_value(p->ca, - sk_X509_num(p->ca)-1)); + 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); -- cgit v1.2.1 From e3e24e5b362fe06b2f83b7bb430f3e46f55ddf83 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Mon, 16 Jan 2012 13:47:51 +0100 Subject: imap.c: a dead simple imap example Just to show that IMAP is used just like other protocols --- docs/examples/.gitignore | 1 + docs/examples/Makefile.inc | 2 +- docs/examples/imap.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 docs/examples/imap.c (limited to 'docs/examples') diff --git a/docs/examples/.gitignore b/docs/examples/.gitignore index fe677de50..2f7e8c8f3 100644 --- a/docs/examples/.gitignore +++ b/docs/examples/.gitignore @@ -18,6 +18,7 @@ http-post httpcustomheader httpput https +imap multi-app multi-debugcallback multi-double diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index e87fb1f2a..d814fe819 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -5,7 +5,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ persistant post-callback postit2 sepheaders simple simplepost simplessl \ sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard \ smtp-multi simplesmtp smtp-tls rtsp externalsocket resolve \ - progressfunc pop3s pop3slist + progressfunc pop3s pop3slist imap # 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/imap.c b/docs/examples/imap.c new file mode 100644 index 000000000..eafea81f2 --- /dev/null +++ b/docs/examples/imap.c @@ -0,0 +1,44 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2012, 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. + * + * 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. + * + ***************************************************************************/ +#include <stdio.h> +#include <curl/curl.h> + +int main(void) +{ + CURL *curl; + CURLcode res; + + curl = curl_easy_init(); + if(curl) { + /* Set username and password */ + curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password"); + + /* This will fetch the mailbox named "foobar" */ + curl_easy_setopt(curl, CURLOPT_URL, "imap://imap.example.com/foobar"); + + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + } + return (int)res; +} -- cgit v1.2.1 From 21401840fa26dc88957d1dcf67c325952bc71458 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Mon, 16 Jan 2012 14:45:00 +0100 Subject: url2file: new simple example Just showing how to download the contents of a given URL into a local file. Based on a suggestion and example code by Georg Potthast --- docs/examples/.gitignore | 1 + docs/examples/Makefile.inc | 2 +- docs/examples/url2file.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 docs/examples/url2file.c (limited to 'docs/examples') diff --git a/docs/examples/.gitignore b/docs/examples/.gitignore index 2f7e8c8f3..3912f5f4d 100644 --- a/docs/examples/.gitignore +++ b/docs/examples/.gitignore @@ -40,3 +40,4 @@ simplesmtp simplessl smtp-multi smtp-tls +url2file diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index d814fe819..611881d62 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -5,7 +5,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ persistant post-callback postit2 sepheaders simple simplepost simplessl \ sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard \ smtp-multi simplesmtp smtp-tls rtsp externalsocket resolve \ - progressfunc pop3s pop3slist imap + progressfunc pop3s pop3slist imap url2file # 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/url2file.c b/docs/examples/url2file.c new file mode 100644 index 000000000..64d27c88f --- /dev/null +++ b/docs/examples/url2file.c @@ -0,0 +1,81 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2012, 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. + * + * 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. + * + ***************************************************************************/ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include <curl/curl.h> + +static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) +{ + size_t written = fwrite(ptr, size, nmemb, (FILE *)stream); + return written; +} + +int main(int argc, char *argv[]) +{ + CURL *curl_handle; + static const char *pagefilename = "page.out"; + FILE *pagefile; + + if(argc < 2 ) { + printf("Usage: %s <URL>\n", argv[0]); + return 1; + } + + curl_global_init(CURL_GLOBAL_ALL); + + /* init the curl session */ + curl_handle = curl_easy_init(); + + /* set URL to get here */ + curl_easy_setopt(curl_handle, CURLOPT_URL, argv[1]); + + /* Switch on full protocol/debug output while testing */ + curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); + + /* disable progress meter, set to 0L to enable and disable debug output */ + curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L); + + /* send all data to this function */ + curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data); + + /* open the file */ + pagefile = fopen(pagefilename, "wb"); + if (pagefile) { + + /* write the page body to this file handle. CURLOPT_FILE is also known as + CURLOPT_WRITEDATA*/ + curl_easy_setopt(curl_handle, CURLOPT_FILE, pagefile); + + /* get it! */ + curl_easy_perform(curl_handle); + + /* close the header file */ + fclose(pagefile); + } + + /* cleanup curl stuff */ + curl_easy_cleanup(curl_handle); + + return 0; +} -- cgit v1.2.1 From 5d7a319a55d07ee95b99e412e1d086857da093c4 Mon Sep 17 00:00:00 2001 From: Dan Fandrich <dan@coneharvesters.com> Date: Fri, 20 Jan 2012 22:44:47 -0800 Subject: examples: updated README with two new example programs --- docs/examples/README | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/README b/docs/examples/README index da04d2886..270048a6c 100644 --- a/docs/examples/README +++ b/docs/examples/README @@ -55,6 +55,7 @@ htmltitle.cc - download a HTML file and extract the <title> tag from a HTML 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 @@ -75,4 +76,5 @@ 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 10-at-a-time.c - Download many files simultaneously, 10 at a time. -- cgit v1.2.1 From 21423497efe36c70615d0a54e040f76043823345 Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Mon, 9 Apr 2012 21:24:16 +0200 Subject: configure: Windows cross-compilation fixes BUILDING_LIBCURL and CURL_STATICLIB are no longer defined in curl_config.h, configure will generate appropriate conditionals so that mentioned symbols get defined and used in Makefiles at compilation time --- docs/examples/Makefile.am | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 735942e78..a71014d7c 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -5,7 +5,7 @@ # | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # -# Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. +# Copyright (C) 1998 - 2012, 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 @@ -40,12 +40,12 @@ INCLUDES = -I$(top_builddir)/include/curl \ LIBDIR = $(top_builddir)/lib -if STATICLIB -# we need this define when building with a static lib on Windows -STATICCPPFLAGS = -DCURL_STATICLIB -endif +AM_CPPFLAGS = -DCURL_NO_OLDIES -CPPFLAGS = -DCURL_NO_OLDIES $(STATICCPPFLAGS) +# Mostly for Windows build targets, when using static libcurl +if USE_CPPFLAG_CURL_STATICLIB +AM_CPPFLAGS += -DCURL_STATICLIB +endif # Dependencies LDADD = $(LIBDIR)/libcurl.la -- cgit v1.2.1 From 865893fb143540037ca34f6a4438ebe2e286ec5a Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Fri, 13 Apr 2012 17:58:41 +0200 Subject: examples: fix compiler warnings --- docs/examples/Makefile.am | 2 +- docs/examples/anyauthput.c | 9 ++++++--- docs/examples/externalsocket.c | 12 ++++++++--- docs/examples/ftp-wildcard.c | 7 ++++--- docs/examples/ftpupload.c | 9 ++++++--- docs/examples/httpput.c | 9 ++++++--- docs/examples/imap.c | 2 +- docs/examples/post-callback.c | 6 +++--- docs/examples/printf_macro.h | 45 ------------------------------------------ docs/examples/sendrecv.c | 8 +++++--- 10 files changed, 41 insertions(+), 68 deletions(-) delete mode 100644 docs/examples/printf_macro.h (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index a71014d7c..27d20dfb6 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -23,7 +23,7 @@ AUTOMAKE_OPTIONS = foreign nostdinc EXTRA_DIST = README Makefile.example Makefile.inc Makefile.m32 \ - Makefile.netware makefile.dj printf_macro.h $(COMPLICATED_EXAMPLES) + Makefile.netware makefile.dj $(COMPLICATED_EXAMPLES) # Specify our include paths here, and do it relative to $(top_srcdir) and # $(top_builddir), to ensure that these paths which belong to the library diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index 2997a1e98..a28ecb769 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -42,7 +42,6 @@ #endif #include <curl/curl.h> -#include "printf_macro.h" #if LIBCURL_VERSION_NUM < 0x070c03 #error "upgrade your libcurl to no less than 7.12.3" @@ -89,12 +88,16 @@ static curlioerr my_ioctl(CURL *handle, curliocmd cmd, void *userp) static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) { size_t retcode; + curl_off_t nread; intptr_t fd = (intptr_t)stream; retcode = read(fd, ptr, size * nmemb); - fprintf(stderr, "*** We read %" _FMT_SIZE_T " bytes from file\n", retcode); + nread = (curl_off_t)retcode; + + fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T + " bytes from file\n", nread); return retcode; } diff --git a/docs/examples/externalsocket.c b/docs/examples/externalsocket.c index c4abafd87..6e2a773b2 100644 --- a/docs/examples/externalsocket.c +++ b/docs/examples/externalsocket.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -57,7 +57,10 @@ static curl_socket_t opensocket(void *clientp, curlsocktype purpose, struct curl_sockaddr *address) { - curl_socket_t sockfd = *(curl_socket_t *)clientp; + curl_socket_t sockfd; + (void)purpose; + (void)address; + sockfd = *(curl_socket_t *)clientp; /* the actual externally set socket is passed in via the OPENSOCKETDATA option */ return sockfd; @@ -66,6 +69,9 @@ static curl_socket_t opensocket(void *clientp, static int sockopt_callback(void *clientp, curl_socket_t curlfd, curlsocktype purpose) { + (void)clientp; + (void)curlfd; + (void)purpose; /* This return code was added in libcurl 7.21.5 */ return CURL_SOCKOPT_ALREADY_CONNECTED; } @@ -96,7 +102,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)) < 0 ) { + if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) == CURL_SOCKET_BAD ) { printf("Error creating listening socket.\n"); return 3; } diff --git a/docs/examples/ftp-wildcard.c b/docs/examples/ftp-wildcard.c index fd92ca651..5a2a10311 100644 --- a/docs/examples/ftp-wildcard.c +++ b/docs/examples/ftp-wildcard.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -33,7 +33,7 @@ static long file_is_comming(struct curl_fileinfo *finfo, static long file_is_downloaded(struct callback_data *data); static size_t write_it(char *buff, size_t size, size_t nmemb, - struct callback_data *data); + void *cb_data); int main(int argc, char **argv) { @@ -135,8 +135,9 @@ static long file_is_downloaded(struct callback_data *data) } static size_t write_it(char *buff, size_t size, size_t nmemb, - struct callback_data *data) + void *cb_data) { + struct callback_data *data = cb_data; size_t written = 0; if(data->output) written = fwrite(buff, size, nmemb, data->output); diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index 722acbc9e..9928b9e81 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -32,7 +32,6 @@ #else #include <unistd.h> #endif -#include "printf_macro.h" /* * This example shows an FTP upload, with a rename of the file just after @@ -52,12 +51,16 @@ variable's memory when passed in to it from an app like this. */ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) { + curl_off_t nread; /* in real-world cases, this would probably get this data differently as this fread() stuff is exactly what the library already would do by default internally */ size_t retcode = fread(ptr, size, nmemb, stream); - fprintf(stderr, "*** We read %" _FMT_SIZE_T " bytes from file\n", retcode); + nread = (curl_off_t)retcode; + + fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T + " bytes from file\n", nread); return retcode; } diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index 664c8e152..f04618f96 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -25,7 +25,6 @@ #include <unistd.h> #include <curl/curl.h> -#include "printf_macro.h" /* * This example shows a HTTP PUT operation. PUTs a file given as a command @@ -40,13 +39,17 @@ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream) { size_t retcode; + curl_off_t nread; /* in real-world cases, this would probably get this data differently as this fread() stuff is exactly what the library already would do by default internally */ retcode = fread(ptr, size, nmemb, stream); - fprintf(stderr, "*** We read %" _FMT_SIZE_T " bytes from file\n", retcode); + nread = (curl_off_t)retcode; + + fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T + " bytes from file\n", nread); return retcode; } diff --git a/docs/examples/imap.c b/docs/examples/imap.c index eafea81f2..ba07f022a 100644 --- a/docs/examples/imap.c +++ b/docs/examples/imap.c @@ -25,7 +25,7 @@ int main(void) { CURL *curl; - CURLcode res; + CURLcode res = CURLE_OK; curl = curl_easy_init(); if(curl) { diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index bb99a8566..adadaf803 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -30,7 +30,7 @@ const char data[]="this is what we post to the silly web server"; struct WriteThis { const char *readptr; - int sizeleft; + long sizeleft; }; static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp) @@ -96,7 +96,7 @@ int main(void) #else /* Set the expected POST size. If you want to POST large amounts of data, consider CURLOPT_POSTFIELDSIZE_LARGE */ - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)pooh.sizeleft); + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, pooh.sizeleft); #endif #ifdef DISABLE_EXPECT diff --git a/docs/examples/printf_macro.h b/docs/examples/printf_macro.h deleted file mode 100644 index 9eed8f4c6..000000000 --- a/docs/examples/printf_macro.h +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) 1998 - 2011, 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. - * - * 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. - * - ***************************************************************************/ -/* Simple hack trying to get a valid printf format string for size_t. - * If that fails for your platform you can define your own _FMT_SIZE_T, - * f.e.: -D_FMT_SIZE_T="zd" - */ -#ifndef _PRINTF_MACRO_H -#define _PRINTF_MACRO_H - -#ifndef _FMT_SIZE_T -#ifdef WIN32 -#define _FMT_SIZE_T "Id" -#else -/* -"zd" is a GNU extension to POSIX; so we dont use it for size_t but hack around -#define _FMT_SIZE_T "zd" -*/ -#ifdef __x86_64__ -#define _FMT_SIZE_T "lu" -#else -#define _FMT_SIZE_T "u" -#endif /* __x86_64__ */ -#endif /* WIN32 */ -#endif /* !_FMT_SIZE_T */ - -#endif /* !_PRINTF_MACRO_H */ diff --git a/docs/examples/sendrecv.c b/docs/examples/sendrecv.c index 369601d16..88fddf59f 100644 --- a/docs/examples/sendrecv.c +++ b/docs/examples/sendrecv.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -24,7 +24,6 @@ #include <stdio.h> #include <string.h> #include <curl/curl.h> -#include "printf_macro.h" /* Auxiliary function that waits on the socket. */ static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms) @@ -65,6 +64,7 @@ int main(void) curl_socket_t sockfd; /* socket */ long sockextr; size_t iolen; + curl_off_t nread; curl = curl_easy_init(); if(curl) { @@ -123,7 +123,9 @@ int main(void) if(CURLE_OK != res) break; - printf("Received %" _FMT_SIZE_T " bytes.\n", iolen); + nread = (curl_off_t)iolen; + + printf("Received %" CURL_FORMAT_CURL_OFF_T " bytes.\n", nread); } /* always cleanup */ -- cgit v1.2.1 From 0f548802775b01c26c4c263be86f3605310f6f35 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Fri, 20 Apr 2012 13:33:54 +0200 Subject: Updated dependency lib versions. --- docs/examples/Makefile.m32 | 8 ++++---- docs/examples/Makefile.netware | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 3c3d121ed..469d7a1cd 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -27,18 +27,18 @@ ## Example: mingw32-make -f Makefile.m32 CFG=-zlib-ssl-spi-winidn ## ## Hint: you can also set environment vars to control the build, f.e.: -## set ZLIB_PATH=c:/zlib-1.2.5 +## set ZLIB_PATH=c:/zlib-1.2.6 ## set ZLIB=1 # ########################################################################### # Edit the path below to point to the base of your Zlib sources. ifndef ZLIB_PATH -ZLIB_PATH = ../../../zlib-1.2.5 +ZLIB_PATH = ../../../zlib-1.2.6 endif # Edit the path below to point to the base of your OpenSSL package. ifndef OPENSSL_PATH -OPENSSL_PATH = ../../../openssl-0.9.8r +OPENSSL_PATH = ../../../openssl-0.9.8v endif ifndef OPENSSL_LIBPATH OPENSSL_LIBPATH = $(OPENSSL_PATH)/out @@ -48,7 +48,7 @@ OPENSSL_LIBS = -leay32 -lssl32 endif # Edit the path below to point to the base of your LibSSH2 package. ifndef LIBSSH2_PATH -LIBSSH2_PATH = ../../../libssh2-1.3.0 +LIBSSH2_PATH = ../../../libssh2-1.4.1 endif # Edit the path below to point to the base of your librtmp package. ifndef LIBRTMP_PATH diff --git a/docs/examples/Makefile.netware b/docs/examples/Makefile.netware index fdea6b81b..cba66a7a0 100644 --- a/docs/examples/Makefile.netware +++ b/docs/examples/Makefile.netware @@ -14,17 +14,17 @@ endif # Edit the path below to point to the base of your Zlib sources. ifndef ZLIB_PATH -ZLIB_PATH = ../../../zlib-1.2.5 +ZLIB_PATH = ../../../zlib-1.2.6 endif # Edit the path below to point to the base of your OpenSSL package. ifndef OPENSSL_PATH -OPENSSL_PATH = ../../../openssl-0.9.8r +OPENSSL_PATH = ../../../openssl-0.9.8v endif # Edit the path below to point to the base of your LibSSH2 package. ifndef LIBSSH2_PATH -LIBSSH2_PATH = ../../../libssh2-1.3.0 +LIBSSH2_PATH = ../../../libssh2-1.4.1 endif # Edit the path below to point to the base of your axTLS package. -- cgit v1.2.1 From 1beda0cbb76358559b23fe59a8fd2fabaf7b6340 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Thu, 26 Apr 2012 14:40:50 +0200 Subject: Updated dependency lib versions. --- docs/examples/Makefile.m32 | 2 +- docs/examples/Makefile.netware | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 469d7a1cd..930d0017c 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -38,7 +38,7 @@ ZLIB_PATH = ../../../zlib-1.2.6 endif # Edit the path below to point to the base of your OpenSSL package. ifndef OPENSSL_PATH -OPENSSL_PATH = ../../../openssl-0.9.8v +OPENSSL_PATH = ../../../openssl-0.9.8w endif ifndef OPENSSL_LIBPATH OPENSSL_LIBPATH = $(OPENSSL_PATH)/out diff --git a/docs/examples/Makefile.netware b/docs/examples/Makefile.netware index cba66a7a0..b2fc329a9 100644 --- a/docs/examples/Makefile.netware +++ b/docs/examples/Makefile.netware @@ -19,7 +19,7 @@ endif # Edit the path below to point to the base of your OpenSSL package. ifndef OPENSSL_PATH -OPENSSL_PATH = ../../../openssl-0.9.8v +OPENSSL_PATH = ../../../openssl-0.9.8w endif # Edit the path below to point to the base of your LibSSH2 package. -- cgit v1.2.1 From 1c58f291ccc40e5b9719d9ab13fceb3300c55404 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Tue, 22 May 2012 04:15:37 +0200 Subject: Updated dependency libary versions. --- docs/examples/Makefile.m32 | 8 ++++---- docs/examples/Makefile.netware | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 930d0017c..4327a64f8 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -27,18 +27,18 @@ ## Example: mingw32-make -f Makefile.m32 CFG=-zlib-ssl-spi-winidn ## ## Hint: you can also set environment vars to control the build, f.e.: -## set ZLIB_PATH=c:/zlib-1.2.6 +## set ZLIB_PATH=c:/zlib-1.2.7 ## set ZLIB=1 # ########################################################################### # Edit the path below to point to the base of your Zlib sources. ifndef ZLIB_PATH -ZLIB_PATH = ../../../zlib-1.2.6 +ZLIB_PATH = ../../../zlib-1.2.7 endif # Edit the path below to point to the base of your OpenSSL package. ifndef OPENSSL_PATH -OPENSSL_PATH = ../../../openssl-0.9.8w +OPENSSL_PATH = ../../../openssl-0.9.8x endif ifndef OPENSSL_LIBPATH OPENSSL_LIBPATH = $(OPENSSL_PATH)/out @@ -48,7 +48,7 @@ OPENSSL_LIBS = -leay32 -lssl32 endif # Edit the path below to point to the base of your LibSSH2 package. ifndef LIBSSH2_PATH -LIBSSH2_PATH = ../../../libssh2-1.4.1 +LIBSSH2_PATH = ../../../libssh2-1.4.2 endif # Edit the path below to point to the base of your librtmp package. ifndef LIBRTMP_PATH diff --git a/docs/examples/Makefile.netware b/docs/examples/Makefile.netware index b2fc329a9..934f17aef 100644 --- a/docs/examples/Makefile.netware +++ b/docs/examples/Makefile.netware @@ -14,17 +14,17 @@ endif # Edit the path below to point to the base of your Zlib sources. ifndef ZLIB_PATH -ZLIB_PATH = ../../../zlib-1.2.6 +ZLIB_PATH = ../../../zlib-1.2.7 endif # Edit the path below to point to the base of your OpenSSL package. ifndef OPENSSL_PATH -OPENSSL_PATH = ../../../openssl-0.9.8w +OPENSSL_PATH = ../../../openssl-0.9.8x endif # Edit the path below to point to the base of your LibSSH2 package. ifndef LIBSSH2_PATH -LIBSSH2_PATH = ../../../libssh2-1.4.1 +LIBSSH2_PATH = ../../../libssh2-1.4.2 endif # Edit the path below to point to the base of your axTLS package. -- cgit v1.2.1 From f95f19e85495572541134ecaf3f39369f1e4e1cd Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Sun, 27 May 2012 07:26:48 +0200 Subject: Enabled OpenSSL static linkage. --- docs/examples/Makefile.m32 | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 4327a64f8..3387c9283 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -40,12 +40,6 @@ endif ifndef OPENSSL_PATH OPENSSL_PATH = ../../../openssl-0.9.8x endif -ifndef OPENSSL_LIBPATH -OPENSSL_LIBPATH = $(OPENSSL_PATH)/out -endif -ifndef OPENSSL_LIBS -OPENSSL_LIBS = -leay32 -lssl32 -endif # Edit the path below to point to the base of your LibSSH2 package. ifndef LIBSSH2_PATH LIBSSH2_PATH = ../../../libssh2-1.4.2 @@ -148,6 +142,7 @@ else curl_DEPENDENCIES = $(PROOT)/lib/libcurl.a curl_LDADD = -L$(PROOT)/lib -lcurl CFLAGS += -DCURL_STATICLIB + LDFLAGS += -static endif ifdef ARES ifndef DYN @@ -165,7 +160,22 @@ ifdef SSH2 curl_LDADD += -L"$(LIBSSH2_PATH)/win32" -lssh2 endif ifdef SSL - CFLAGS += -DUSE_SSLEAY -DHAVE_OPENSSL_ENGINE_H + ifndef OPENSSL_LIBPATH + OPENSSL_LIBS = -lssl -lcrypto + ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out" + OPENSSL_LIBPATH = $(OPENSSL_PATH)/out + ifdef DYN + OPENSSL_LIBS = -lssl32 -leay32 + endif + endif + ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib" + OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib + endif + endif + ifndef DYN + OPENSSL_LIBS += -lgdi32 -lcrypt32 + endif + CFLAGS += -DUSE_SSLEAY curl_LDADD += -L"$(OPENSSL_LIBPATH)" $(OPENSSL_LIBS) endif ifdef ZLIB -- cgit v1.2.1 From 1ba5712f8823a3cb587cb75d2053a16daa9cdfe6 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Tue, 3 Jul 2012 12:56:41 +0200 Subject: MinGW makefile tweaks for running from sh. Added function macros to make path converting easier. Added CROSSPREFIX to all compile tools. --- docs/examples/Makefile.m32 | 59 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 11 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 index 3387c9283..c1db6207a 100644 --- a/docs/examples/Makefile.m32 +++ b/docs/examples/Makefile.m32 @@ -75,19 +75,44 @@ ifndef ARCH ARCH = w32 endif -CC = gcc -CFLAGS = -g -O2 -Wall -CFLAGS += -fno-strict-aliasing +CC = $(CROSSPREFIX)gcc +CFLAGS = -g -O2 -Wall +CFLAGS += -fno-strict-aliasing ifeq ($(ARCH),w64) -CFLAGS += -D_AMD64_ +CFLAGS += -D_AMD64_ endif # comment LDFLAGS below to keep debug info -LDFLAGS = -s -RC = windres -RCFLAGS = --include-dir=$(PROOT)/include -O COFF -i +LDFLAGS = -s +RC = $(CROSSPREFIX)windres +RCFLAGS = --include-dir=$(PROOT)/include -O COFF -i -RM = del /q /f 2>NUL -CP = copy +# Platform-dependent helper tool macros +ifeq ($(findstring /sh,$(SHELL)),/sh) +DEL = rm -f $1 +RMDIR = rm -fr $1 +MKDIR = mkdir -p $1 +COPY = -cp -afv $1 $2 +#COPYR = -cp -afr $1/* $2 +COPYR = -rsync -aC $1/* $2 +TOUCH = touch $1 +CAT = cat +ECHONL = echo "" +DL = ' +else +ifeq "$(OS)" "Windows_NT" +DEL = -del 2>NUL /q /f $(subst /,\,$1) +RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) +else +DEL = -del 2>NUL $(subst /,\,$1) +RMDIR = -deltree 2>NUL /y $(subst /,\,$1) +endif +MKDIR = -md 2>NUL $(subst /,\,$1) +COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) +COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) +TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, +CAT = type +ECHONL = $(ComSpec) /c echo. +endif ######################################################## ## Nothing more to do below this line! @@ -132,6 +157,13 @@ endif ifeq ($(findstring -ipv6,$(CFG)),-ipv6) IPV6 = 1 endif +ifeq ($(findstring -metalink,$(CFG)),-metalink) +METALINK = 1 +endif +ifeq ($(findstring -winssl,$(CFG)),-winssl) +SCHANNEL = 1 +SSPI = 1 +endif INCLUDES = -I. -I$(PROOT) -I$(PROOT)/include -I$(PROOT)/lib @@ -194,6 +226,9 @@ endif endif ifdef SSPI CFLAGS += -DUSE_WINDOWS_SSPI + ifdef SCHANNEL + CFLAGS += -DUSE_SCHANNEL + endif endif ifdef SPNEGO CFLAGS += -DHAVE_SPNEGO @@ -225,6 +260,8 @@ include Makefile.inc check_PROGRAMS := $(patsubst %,%.exe,$(strip $(check_PROGRAMS))) check_PROGRAMS += ftpuploadresume.exe synctime.exe +.PRECIOUS: %.o + all: $(check_PROGRAMS) @@ -238,8 +275,8 @@ all: $(check_PROGRAMS) $(RC) $(RCFLAGS) $< -o $@ clean: - -$(RM) $(check_PROGRAMS:.exe=.o) + @$(call DEL, $(check_PROGRAMS:.exe=.o)) distclean vclean: clean - -$(RM) $(check_PROGRAMS) + @$(call DEL, $(check_PROGRAMS)) -- cgit v1.2.1 From a3dbbcfd2ac7ab8f597e26e76935726279d3fa0c Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Wed, 4 Jul 2012 17:03:52 +0200 Subject: Added error checking for samples. --- docs/examples/anyauthput.c | 4 ++++ docs/examples/debug.c | 4 ++++ docs/examples/fileupload.c | 17 ++++++++++++----- docs/examples/ftpgetresp.c | 4 ++++ docs/examples/ftpupload.c | 4 ++++ docs/examples/http-post.c | 4 ++++ docs/examples/httpcustomheader.c | 8 ++++++++ docs/examples/httpput.c | 4 ++++ docs/examples/https.c | 5 +++++ docs/examples/persistant.c | 12 ++++++++++++ docs/examples/pop3s.c | 5 +++++ docs/examples/pop3slist.c | 5 +++++ docs/examples/post-callback.c | 4 ++++ docs/examples/postit2.c | 6 ++++++ docs/examples/simple.c | 6 ++++++ docs/examples/simplepost.c | 5 +++++ docs/examples/simplesmtp.c | 4 ++++ docs/examples/simplessl.c | 6 ++++++ docs/examples/smtp-tls.c | 4 ++++ 19 files changed, 106 insertions(+), 5 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index a28ecb769..5dac0e779 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -162,6 +162,10 @@ int main(int argc, char **argv) /* Now run off and do what you've been told! */ res = curl_easy_perform(curl); + /* Check for errors */ + if(res != CURLE_OK) + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); /* always cleanup */ curl_easy_cleanup(curl); diff --git a/docs/examples/debug.c b/docs/examples/debug.c index 270b497af..3852bf2cc 100644 --- a/docs/examples/debug.c +++ b/docs/examples/debug.c @@ -132,6 +132,10 @@ int main(void) curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/"); res = curl_easy_perform(curl); + /* Check for errors */ + if(res != CURLE_OK) + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); /* always cleanup */ curl_easy_cleanup(curl); diff --git a/docs/examples/fileupload.c b/docs/examples/fileupload.c index 756367b6b..665eca0af 100644 --- a/docs/examples/fileupload.c +++ b/docs/examples/fileupload.c @@ -64,14 +64,21 @@ int main(void) curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); res = curl_easy_perform(curl); + /* Check for errors */ + if(res != CURLE_OK) { + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); - /* now extract transfer info */ - curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload); - curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time); + } + else { + /* now extract transfer info */ + curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload); + curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time); - fprintf(stderr, "Speed: %.3f bytes/sec during %.3f seconds\n", - speed_upload, total_time); + fprintf(stderr, "Speed: %.3f bytes/sec during %.3f seconds\n", + speed_upload, total_time); + } /* always cleanup */ curl_easy_cleanup(curl); } diff --git a/docs/examples/ftpgetresp.c b/docs/examples/ftpgetresp.c index 29290a31d..db96a3a13 100644 --- a/docs/examples/ftpgetresp.c +++ b/docs/examples/ftpgetresp.c @@ -60,6 +60,10 @@ int main(void) curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_response); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, respfile); res = curl_easy_perform(curl); + /* Check for errors */ + if(res != CURLE_OK) + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); /* always cleanup */ curl_easy_cleanup(curl); diff --git a/docs/examples/ftpupload.c b/docs/examples/ftpupload.c index 9928b9e81..e79f8d842 100644 --- a/docs/examples/ftpupload.c +++ b/docs/examples/ftpupload.c @@ -122,6 +122,10 @@ int main(void) /* Now run off and do what you've been told! */ res = curl_easy_perform(curl); + /* Check for errors */ + if(res != CURLE_OK) + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); /* clean up the FTP commands list */ curl_slist_free_all (headerlist); diff --git a/docs/examples/http-post.c b/docs/examples/http-post.c index 22de628ca..80f2b343b 100644 --- a/docs/examples/http-post.c +++ b/docs/examples/http-post.c @@ -38,6 +38,10 @@ int main(void) /* 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)); /* always cleanup */ curl_easy_cleanup(curl); diff --git a/docs/examples/httpcustomheader.c b/docs/examples/httpcustomheader.c index 077df2164..5c013750f 100644 --- a/docs/examples/httpcustomheader.c +++ b/docs/examples/httpcustomheader.c @@ -38,10 +38,18 @@ int main(void) curl_easy_setopt(curl, CURLOPT_URL, "localhost"); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); res = curl_easy_perform(curl); + /* Check for errors */ + if(res != CURLE_OK) + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); /* redo request with our own custom Accept: */ res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk); res = curl_easy_perform(curl); + /* Check for errors */ + if(res != CURLE_OK) + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); /* always cleanup */ curl_easy_cleanup(curl); diff --git a/docs/examples/httpput.c b/docs/examples/httpput.c index f04618f96..fbbca9448 100644 --- a/docs/examples/httpput.c +++ b/docs/examples/httpput.c @@ -110,6 +110,10 @@ int main(int argc, char **argv) /* Now run off and do what you've been told! */ res = curl_easy_perform(curl); + /* Check for errors */ + if(res != CURLE_OK) + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); /* always cleanup */ curl_easy_cleanup(curl); diff --git a/docs/examples/https.c b/docs/examples/https.c index 984357e37..8bfd90cac 100644 --- a/docs/examples/https.c +++ b/docs/examples/https.c @@ -55,7 +55,12 @@ int main(void) curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); #endif + /* 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)); /* always cleanup */ curl_easy_cleanup(curl); diff --git a/docs/examples/persistant.c b/docs/examples/persistant.c index 2d57e4907..0917dfdb8 100644 --- a/docs/examples/persistant.c +++ b/docs/examples/persistant.c @@ -37,12 +37,24 @@ int main(void) /* get the first document */ curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/"); + + /* 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)); /* get another document from the same server using the same connection */ curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/docs/"); + + /* 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)); /* always cleanup */ curl_easy_cleanup(curl); diff --git a/docs/examples/pop3s.c b/docs/examples/pop3s.c index 4a2e8fdeb..44d7c80d0 100644 --- a/docs/examples/pop3s.c +++ b/docs/examples/pop3s.c @@ -59,7 +59,12 @@ int main(void) curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); #endif + /* 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)); /* always cleanup */ curl_easy_cleanup(curl); diff --git a/docs/examples/pop3slist.c b/docs/examples/pop3slist.c index 54cb28784..9d9668fa0 100644 --- a/docs/examples/pop3slist.c +++ b/docs/examples/pop3slist.c @@ -59,7 +59,12 @@ int main(void) curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); #endif + /* 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)); /* always cleanup */ curl_easy_cleanup(curl); diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index adadaf803..9736d8854 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -120,6 +120,10 @@ int main(void) /* 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)); /* always cleanup */ curl_easy_cleanup(curl); diff --git a/docs/examples/postit2.c b/docs/examples/postit2.c index 63c248467..67dcc1330 100644 --- a/docs/examples/postit2.c +++ b/docs/examples/postit2.c @@ -83,7 +83,13 @@ int main(int argc, char *argv[]) /* only disable 100-continue header if explicitly requested */ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); + + /* 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)); /* always cleanup */ curl_easy_cleanup(curl); diff --git a/docs/examples/simple.c b/docs/examples/simple.c index 55877f8b2..cb23b7ae3 100644 --- a/docs/examples/simple.c +++ b/docs/examples/simple.c @@ -30,7 +30,13 @@ int main(void) curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); + + /* 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)); /* always cleanup */ curl_easy_cleanup(curl); diff --git a/docs/examples/simplepost.c b/docs/examples/simplepost.c index 3c8571919..8657771f4 100644 --- a/docs/examples/simplepost.c +++ b/docs/examples/simplepost.c @@ -39,7 +39,12 @@ int main(void) itself */ curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(postthis)); + /* 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)); /* always cleanup */ curl_easy_cleanup(curl); diff --git a/docs/examples/simplesmtp.c b/docs/examples/simplesmtp.c index 84429f5bf..df8516242 100644 --- a/docs/examples/simplesmtp.c +++ b/docs/examples/simplesmtp.c @@ -65,6 +65,10 @@ int main(void) /* send the message (including headers) */ res = curl_easy_perform(curl); + /* Check for errors */ + if(res != CURLE_OK) + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); /* free the list of recipients */ curl_slist_free_all(recipients); diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index 46a378329..b77c276e4 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -118,7 +118,13 @@ int main(void) /* disconnect if we can't validate server's cert */ curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,1L); + /* 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)); + break; /* we are done... */ } /* always cleanup */ diff --git a/docs/examples/smtp-tls.c b/docs/examples/smtp-tls.c index 8e2603fa4..3635c103f 100644 --- a/docs/examples/smtp-tls.c +++ b/docs/examples/smtp-tls.c @@ -139,6 +139,10 @@ int main(void) /* send the message (including headers) */ res = curl_easy_perform(curl); + /* Check for errors */ + if(res != CURLE_OK) + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); /* free the list of recipients and clean up */ curl_slist_free_all(recipients); -- cgit v1.2.1 From 897cf5d1175fc4757cf71a7bd45d531c7f50dec3 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Wed, 4 Jul 2012 22:14:18 +0200 Subject: Removed non-used variable. --- docs/examples/smtp-multi.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/smtp-multi.c b/docs/examples/smtp-multi.c index 828132073..6462aff2d 100644 --- a/docs/examples/smtp-multi.c +++ b/docs/examples/smtp-multi.c @@ -96,7 +96,6 @@ int main(void) CURLM *mcurl; int still_running = 1; struct timeval mp_start; - char mp_timedout = 0; struct WriteThis pooh; struct curl_slist* rcpt_list = NULL; @@ -132,7 +131,6 @@ int main(void) curl_easy_setopt(curl, CURLOPT_SSL_SESSIONID_CACHE, 0L); curl_multi_add_handle(mcurl, curl); - mp_timedout = 0; mp_start = tvnow(); /* we start some action by calling perform right away */ -- cgit v1.2.1 From be795f90dac26c240ab64e1e1e156a66fa21db89 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Thu, 12 Jul 2012 02:02:22 +0200 Subject: Added curl_global_* functions. --- docs/examples/http-post.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/http-post.c b/docs/examples/http-post.c index 80f2b343b..f1975b1ec 100644 --- a/docs/examples/http-post.c +++ b/docs/examples/http-post.c @@ -27,6 +27,10 @@ int main(void) CURL *curl; CURLcode res; + /* In windows, this will init the winsock stuff */ + curl_global_init(CURL_GLOBAL_ALL); + + /* get a curl handle */ curl = curl_easy_init(); if(curl) { /* First set the URL that is about to receive our POST. This URL can @@ -46,5 +50,6 @@ int main(void) /* always cleanup */ curl_easy_cleanup(curl); } + curl_global_cleanup(); return 0; } -- cgit v1.2.1 From df5a47b8198ad51146390c80162d098a3c9b7ba5 Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Thu, 12 Jul 2012 15:01:18 +0200 Subject: Added curl_global_* functions. --- docs/examples/post-callback.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index 9736d8854..fa0c4b686 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -60,6 +60,10 @@ int main(void) pooh.readptr = data; pooh.sizeleft = strlen(data); + /* In windows, this will init the winsock stuff */ + curl_global_init(CURL_GLOBAL_DEFAULT); + + /* get a curl handle */ curl = curl_easy_init(); if(curl) { /* First set the URL that is about to receive our POST. */ @@ -128,5 +132,6 @@ int main(void) /* always cleanup */ curl_easy_cleanup(curl); } + curl_global_cleanup(); return 0; } -- cgit v1.2.1 From 6e3802a2cfde2edaabef902d494dea58d77f6d5b Mon Sep 17 00:00:00 2001 From: Guenter Knauf <lists@gknw.net> Date: Thu, 12 Jul 2012 15:18:00 +0200 Subject: Added error checking for curl_global_init(). --- docs/examples/post-callback.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index fa0c4b686..f11fb983b 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -61,7 +61,13 @@ int main(void) pooh.sizeleft = strlen(data); /* In windows, this will init the winsock stuff */ - curl_global_init(CURL_GLOBAL_DEFAULT); + res = curl_global_init(CURL_GLOBAL_DEFAULT); + /* Check for errors */ + if(res != CURLE_OK) { + fprintf(stderr, "curl_global_init() failed: %s\n", + curl_easy_strerror(res)); + return 1; + } /* get a curl handle */ curl = curl_easy_init(); -- cgit v1.2.1 From a90492a08314f5148069fa14132d7dc8ca54c395 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Tue, 21 Aug 2012 22:30:47 +0200 Subject: https.c example: spell check used define Bug: http://curl.haxx.se/bug/view.cgi?id=3559845 Reported by: Olivier Berger --- docs/examples/https.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/https.c b/docs/examples/https.c index 8bfd90cac..96225b597 100644 --- a/docs/examples/https.c +++ b/docs/examples/https.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -45,7 +45,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); #endif -#ifdef SKIP_HOSTNAME_VERFICATION +#ifdef SKIP_HOSTNAME_VERIFICATION /* * If the site you're connecting to uses a different host name that what * they have mentioned in their server certificate's commonName (or -- cgit v1.2.1 From be5fbf73726fd6e22912be9df2967b675d37222c Mon Sep 17 00:00:00 2001 From: Armel Asselin <armelasselin@hotmail.com> Date: Mon, 27 Aug 2012 14:33:27 +0200 Subject: sftpget: example showing a simple SFTP download ... using SSH-agent --- docs/examples/.gitignore | 1 + docs/examples/Makefile.inc | 2 +- docs/examples/sftpget.c | 106 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 docs/examples/sftpget.c (limited to 'docs/examples') diff --git a/docs/examples/.gitignore b/docs/examples/.gitignore index 3912f5f4d..a82cd44d3 100644 --- a/docs/examples/.gitignore +++ b/docs/examples/.gitignore @@ -34,6 +34,7 @@ resolve rtsp sendrecv sepheaders +sftpget simple simplepost simplesmtp diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 611881d62..35f079f5f 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -5,7 +5,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ persistant post-callback postit2 sepheaders simple simplepost simplessl \ sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard \ smtp-multi simplesmtp smtp-tls rtsp externalsocket resolve \ - progressfunc pop3s pop3slist imap url2file + progressfunc pop3s pop3slist imap url2file sftpget # 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/sftpget.c b/docs/examples/sftpget.c new file mode 100644 index 000000000..e44c5ff2e --- /dev/null +++ b/docs/examples/sftpget.c @@ -0,0 +1,106 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2012, 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. + * + * 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. + * + ***************************************************************************/ + +#include <stdio.h> + +#include <curl/curl.h> + +/* define this to switch off the use of ssh-agent in this program */ +#undef DISABLE_SSH_AGENT + +/* + * This is an example showing how to get a single file from an SSH 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. + */ + +struct FtpFile { + const char *filename; + FILE *stream; +}; + +static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, + void *stream) +{ + struct FtpFile *out=(struct FtpFile *)stream; + if(out && !out->stream) { + /* open file for writing */ + out->stream=fopen(out->filename, "wb"); + if(!out->stream) + return -1; /* failure, can't open file to write */ + } + return fwrite(buffer, size, nmemb, out->stream); +} + + +int main(void) +{ + CURL *curl; + CURLcode res; + struct FtpFile ftpfile={ + "yourfile.bin", /* name to store the file as if succesful */ + NULL + }; + + curl_global_init(CURL_GLOBAL_DEFAULT); + + curl = curl_easy_init(); + if(curl) { + /* + * You better replace the URL with one that works! + */ + curl_easy_setopt(curl, CURLOPT_URL, + "sftp://user@server/home/user/file.txt"); + /* 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 */ + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile); + +#ifndef DISABLE_SSH_AGENT + /* We activate ssh agent. For this to work you need + to have ssh-agent running (type set | grep SSH_AGENT to check) or + pageant on Windows (there is an icon in systray if so) */ + curl_easy_setopt(curl, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_AGENT); +#endif + + /* Switch on full protocol/debug output */ + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + + if(CURLE_OK != res) { + /* we failed */ + fprintf(stderr, "curl told us %d\n", res); + } + } + + if(ftpfile.stream) + fclose(ftpfile.stream); /* close the local file */ + + curl_global_cleanup(); + + return 0; +} -- cgit v1.2.1 From 71358ddffd699c90f1de03e27370c8222ca792cf Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Mon, 27 Aug 2012 14:42:56 +0200 Subject: sftpget: SFTP is not "SSH FTP" --- docs/examples/sftpget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/sftpget.c b/docs/examples/sftpget.c index e44c5ff2e..8317462e9 100644 --- a/docs/examples/sftpget.c +++ b/docs/examples/sftpget.c @@ -28,7 +28,7 @@ #undef DISABLE_SSH_AGENT /* - * This is an example showing how to get a single file from an SSH FTP server. + * This is an example showing how to get a single file from an SFTP 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. -- cgit v1.2.1 From 8136649e9d704ed97ab419f1a2e005d586591853 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Mon, 27 Aug 2012 14:48:56 +0200 Subject: ftpsget: simple example showing a FTPS fetch --- docs/examples/.gitignore | 1 + docs/examples/Makefile.inc | 2 +- docs/examples/ftpsget.c | 101 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 docs/examples/ftpsget.c (limited to 'docs/examples') diff --git a/docs/examples/.gitignore b/docs/examples/.gitignore index a82cd44d3..cbe0d04d4 100644 --- a/docs/examples/.gitignore +++ b/docs/examples/.gitignore @@ -11,6 +11,7 @@ ftp-wildcard ftpget ftpgetinfo ftpgetresp +ftpsget ftpupload getinfo getinmemory diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 35f079f5f..b548ebf7b 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -5,7 +5,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ persistant post-callback postit2 sepheaders simple simplepost simplessl \ sendrecv httpcustomheader certinfo chkspeed ftpgetinfo ftp-wildcard \ smtp-multi simplesmtp smtp-tls rtsp externalsocket resolve \ - progressfunc pop3s pop3slist imap url2file sftpget + progressfunc pop3s pop3slist imap url2file sftpget ftpsget # 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/ftpsget.c b/docs/examples/ftpsget.c new file mode 100644 index 000000000..0cfe32024 --- /dev/null +++ b/docs/examples/ftpsget.c @@ -0,0 +1,101 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2012, 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. + * + * 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. + * + ***************************************************************************/ + +#include <stdio.h> + +#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. + */ + +struct FtpFile { + const char *filename; + FILE *stream; +}; + +static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, + void *stream) +{ + struct FtpFile *out=(struct FtpFile *)stream; + if(out && !out->stream) { + /* open file for writing */ + out->stream=fopen(out->filename, "wb"); + if(!out->stream) + return -1; /* failure, can't open file to write */ + } + return fwrite(buffer, size, nmemb, out->stream); +} + + +int main(void) +{ + CURL *curl; + CURLcode res; + struct FtpFile ftpfile={ + "yourfile.bin", /* name to store the file as if succesful */ + NULL + }; + + curl_global_init(CURL_GLOBAL_DEFAULT); + + curl = curl_easy_init(); + if(curl) { + /* + * You better replace the URL with one that works! Note that we use an + * FTP:// URL with standard explicit FTPS. You can also do FTPS:// URLs if + * you want to do the rarer kind of transfers: implicit. + */ + curl_easy_setopt(curl, CURLOPT_URL, + "ftp://user@server/home/user/file.txt"); + /* 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 */ + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile); + + /* We activate SSL and we require it for both control and data */ + curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL); + + /* Switch on full protocol/debug output */ + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + + res = curl_easy_perform(curl); + + /* always cleanup */ + curl_easy_cleanup(curl); + + if(CURLE_OK != res) { + /* we failed */ + fprintf(stderr, "curl told us %d\n", res); + } + } + + if(ftpfile.stream) + fclose(ftpfile.stream); /* close the local file */ + + curl_global_cleanup(); + + return 0; +} -- cgit v1.2.1 From 4c070de4fb01b4fbf29f8c463ba96da97b36bd2f Mon Sep 17 00:00:00 2001 From: Dave Reisner <dreisner@archlinux.org> Date: Mon, 23 Jul 2012 15:34:25 +0000 Subject: examples: use do/while loop for multi examples It's conceivable that after the first time curl_multi_perform returns, the outvalue still_running will be 0, but work will have been done. This is shown by a workload of small, purely file:// based URLs. Ensure that we always read pending messages off the multi handle by forcing the while loop to run at least once. --- docs/examples/multi-app.c | 4 ++-- docs/examples/multi-debugcallback.c | 4 ++-- docs/examples/multi-double.c | 4 ++-- docs/examples/multi-post.c | 4 ++-- docs/examples/multi-single.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/multi-app.c b/docs/examples/multi-app.c index 9615e67bf..a5f71c5ac 100644 --- a/docs/examples/multi-app.c +++ b/docs/examples/multi-app.c @@ -70,7 +70,7 @@ int main(void) /* we start some action by calling perform right away */ curl_multi_perform(multi_handle, &still_running); - while(still_running) { + do { struct timeval timeout; int rc; /* select() return code */ @@ -118,7 +118,7 @@ int main(void) curl_multi_perform(multi_handle, &still_running); break; } - } + } while(still_running); /* See how the transfers went */ while ((msg = curl_multi_info_read(multi_handle, &msgs_left))) { diff --git a/docs/examples/multi-debugcallback.c b/docs/examples/multi-debugcallback.c index c7e819d03..8eedcee5b 100644 --- a/docs/examples/multi-debugcallback.c +++ b/docs/examples/multi-debugcallback.c @@ -144,7 +144,7 @@ int main(void) /* we start some action by calling perform right away */ curl_multi_perform(multi_handle, &still_running); - while(still_running) { + do { struct timeval timeout; int rc; /* select() return code */ @@ -195,7 +195,7 @@ int main(void) curl_multi_perform(multi_handle, &still_running); break; } - } + } while(still_running); curl_multi_cleanup(multi_handle); diff --git a/docs/examples/multi-double.c b/docs/examples/multi-double.c index 120fde7b8..91422e6e2 100644 --- a/docs/examples/multi-double.c +++ b/docs/examples/multi-double.c @@ -59,7 +59,7 @@ int main(void) /* we start some action by calling perform right away */ curl_multi_perform(multi_handle, &still_running); - while(still_running) { + do { struct timeval timeout; int rc; /* select() return code */ @@ -108,7 +108,7 @@ int main(void) curl_multi_perform(multi_handle, &still_running); break; } - } + } while(still_running); curl_multi_cleanup(multi_handle); diff --git a/docs/examples/multi-post.c b/docs/examples/multi-post.c index c26338b59..965a2c3f6 100644 --- a/docs/examples/multi-post.c +++ b/docs/examples/multi-post.c @@ -80,7 +80,7 @@ int main(void) curl_multi_perform(multi_handle, &still_running); - while(still_running) { + do { struct timeval timeout; int rc; /* select() return code */ @@ -131,7 +131,7 @@ int main(void) printf("running: %d!\n", still_running); break; } - } + } while(still_running); curl_multi_cleanup(multi_handle); diff --git a/docs/examples/multi-single.c b/docs/examples/multi-single.c index 0d3542706..aeda71419 100644 --- a/docs/examples/multi-single.c +++ b/docs/examples/multi-single.c @@ -55,7 +55,7 @@ int main(void) /* we start some action by calling perform right away */ curl_multi_perform(multi_handle, &still_running); - while(still_running) { + do { struct timeval timeout; int rc; /* select() return code */ @@ -106,7 +106,7 @@ int main(void) curl_multi_perform(multi_handle, &still_running); break; } - } + } while(still_running); curl_multi_cleanup(multi_handle); -- cgit v1.2.1 From c01b6f4d098347ddfa3ece4ac33d6cc0607b79dd Mon Sep 17 00:00:00 2001 From: Kamil Dudka <kdudka@redhat.com> Date: Mon, 1 Oct 2012 11:20:11 +0200 Subject: https.c example: remember to call curl_global_init() ... in order not to leak memory on initializing an SSL library. Reported by: Tomas Mlcoch --- docs/examples/https.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/https.c b/docs/examples/https.c index 96225b597..bd9a33ba6 100644 --- a/docs/examples/https.c +++ b/docs/examples/https.c @@ -27,6 +27,8 @@ int main(void) CURL *curl; CURLcode res; + curl_global_init(CURL_GLOBAL_DEFAULT); + curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/"); @@ -65,5 +67,8 @@ int main(void) /* always cleanup */ curl_easy_cleanup(curl); } + + curl_global_cleanup(); + return 0; } -- cgit v1.2.1 From 8ffc971138a4f23dcabf45197255a059bf9e1b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kowalczyk?= <netuskowal@gmail.com> Date: Thu, 18 Oct 2012 16:45:51 +0200 Subject: href_extractor: example code extracting href elements It does so in a streaming manner using the "Streaming HTML parser". --- docs/examples/Makefile.inc | 2 +- docs/examples/href_extractor.c | 86 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 docs/examples/href_extractor.c (limited to 'docs/examples') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index b548ebf7b..2b31f86fb 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -12,4 +12,4 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ COMPLICATED_EXAMPLES = curlgtk.c curlx.c htmltitle.cc cacertinmem.c \ ftpuploadresume.c ghiper.c hiperfifo.c htmltidy.c multithread.c \ opensslthreadlock.c sampleconv.c synctime.c threaded-ssl.c evhiperfifo.c \ - smooth-gtk-thread.c version-check.pl + smooth-gtk-thread.c version-check.pl href_extractor.c diff --git a/docs/examples/href_extractor.c b/docs/examples/href_extractor.c new file mode 100644 index 000000000..4181c8e24 --- /dev/null +++ b/docs/examples/href_extractor.c @@ -0,0 +1,86 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 2012, 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. + * + * 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. + * + ***************************************************************************/ + +/* + * 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/streamhtmlparser/ + */ + +#include <stdio.h> +#include <curl/curl.h> +#include <htmlstreamparser.h> + + +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++) { + 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)) { + html_parser_val(hsp)[html_parser_val_length(hsp)] = '\0'; + printf("%s\n", html_parser_val(hsp)); + } + } + return realsize; +} + +int main(int argc, char *argv[]) +{ + char tag[1], attr[4], val[128]; + CURL *curl; + HTMLSTREAMPARSER *hsp; + + if (argc != 2) { + printf("Usage: %s URL\n", argv[0]); + return EXIT_FAILURE; + } + + curl = curl_easy_init(); + + hsp = html_parser_init(); + + html_parser_set_tag_to_lower(hsp, 1); + html_parser_set_attr_to_lower(hsp, 1); + html_parser_set_tag_buffer(hsp, tag, sizeof(tag)); + html_parser_set_attr_buffer(hsp, attr, sizeof(attr)); + html_parser_set_val_buffer(hsp, val, sizeof(val)-1); + + curl_easy_setopt(curl, CURLOPT_URL, argv[1]); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, hsp); + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); + + curl_easy_perform(curl); + + curl_easy_cleanup(curl); + + html_parser_cleanup(hsp); + + return EXIT_SUCCESS; +} -- cgit v1.2.1 From 12a40e17a9aa274e63aff0c8457b0298f959efc6 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Thu, 18 Oct 2012 19:42:31 +0200 Subject: href_extractor.c: fix the URL --- docs/examples/href_extractor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/href_extractor.c b/docs/examples/href_extractor.c index 4181c8e24..4b307a29e 100644 --- a/docs/examples/href_extractor.c +++ b/docs/examples/href_extractor.c @@ -26,7 +26,7 @@ * Kowalczyk. * * The parser is found at - * http://code.google.com/p/streamhtmlparser/ + * http://code.google.com/p/htmlstreamparser/ */ #include <stdio.h> -- cgit v1.2.1 From af121ccad8190a47a2a62594bfc01c039b68ca44 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Thu, 1 Nov 2012 14:19:21 +0100 Subject: evhiperfifo: fix the pointer passed to WRITEDATA Bug: http://curl.haxx.se/bug/view.cgi?id=3582407 Reported by: Oscar Norlander --- docs/examples/evhiperfifo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/evhiperfifo.c b/docs/examples/evhiperfifo.c index 6de4dadc7..c2e87fcc5 100644 --- a/docs/examples/evhiperfifo.c +++ b/docs/examples/evhiperfifo.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -336,7 +336,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); -- cgit v1.2.1 From 550e403f0023e1ca6c50a658e2d994e7f89d576b Mon Sep 17 00:00:00 2001 From: Dave Reisner <dreisner@archlinux.org> Date: Wed, 10 Oct 2012 10:05:02 +0200 Subject: uniformly use AM_CPPFLAGS, avoid deprecated INCLUDES Since automake 1.12.4, the warnings are issued on running automake: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS') Avoid INCLUDES and roll these flags into AM_CPPFLAGS. Compile tested on: Ubuntu 10.04 (automake 1:1.11.1-1) Ubuntu 12.04 (automake 1:1.11.3-1ubuntu2) Arch Linux (automake 1.12.4) --- docs/examples/Makefile.am | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 27d20dfb6..eb4e7c767 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -34,14 +34,13 @@ EXTRA_DIST = README Makefile.example Makefile.inc Makefile.m32 \ # $(top_builddir)/include for generated curlbuild.h included from lib/setup.h # $(top_srcdir)/include is for libcurl's external include files -INCLUDES = -I$(top_builddir)/include/curl \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/include +AM_CPPFLAGS = -I$(top_builddir)/include/curl \ + -I$(top_builddir)/include \ + -I$(top_srcdir)/include \ + -DCURL_NO_OLDIES LIBDIR = $(top_builddir)/lib -AM_CPPFLAGS = -DCURL_NO_OLDIES - # Mostly for Windows build targets, when using static libcurl if USE_CPPFLAG_CURL_STATICLIB AM_CPPFLAGS += -DCURL_STATICLIB -- cgit v1.2.1 From fa6d78829fd30adabd6d622848cdfde8824cb973 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Tue, 6 Nov 2012 11:50:50 +0100 Subject: httpcustomheader.c: free the headers after use --- docs/examples/httpcustomheader.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/httpcustomheader.c b/docs/examples/httpcustomheader.c index 5c013750f..07ff95997 100644 --- a/docs/examples/httpcustomheader.c +++ b/docs/examples/httpcustomheader.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -53,6 +53,9 @@ int main(void) /* always cleanup */ curl_easy_cleanup(curl); + + /* free the custom headers */ + curl_slist_free_all(chunk); } return 0; } -- cgit v1.2.1 From ba33665d1ffc27ccbb9a65c6af058c7c977c9614 Mon Sep 17 00:00:00 2001 From: Lijo Antony <lta@one.com> Date: Wed, 21 Nov 2012 14:19:45 +0400 Subject: examples: Added a c++ example of using multi with boost::asio Added an example for demonstrating the usage of curl multi interface with boost::asio in c++ --- docs/examples/Makefile.inc | 2 +- docs/examples/asiohiper.cpp | 467 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 468 insertions(+), 1 deletion(-) create mode 100644 docs/examples/asiohiper.cpp (limited to 'docs/examples') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index 2b31f86fb..e1f24cb7c 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -12,4 +12,4 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ COMPLICATED_EXAMPLES = curlgtk.c curlx.c htmltitle.cc cacertinmem.c \ ftpuploadresume.c ghiper.c hiperfifo.c htmltidy.c multithread.c \ opensslthreadlock.c sampleconv.c synctime.c threaded-ssl.c evhiperfifo.c \ - smooth-gtk-thread.c version-check.pl href_extractor.c + smooth-gtk-thread.c version-check.pl href_extractor.c asiohiper.cpp diff --git a/docs/examples/asiohiper.cpp b/docs/examples/asiohiper.cpp new file mode 100644 index 000000000..1ea350253 --- /dev/null +++ b/docs/examples/asiohiper.cpp @@ -0,0 +1,467 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 2012, 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. + * + * 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. + * + ***************************************************************************/ + +/* + * 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 + * + * This is an adaptation of libcurl's "hiperfifo.c" and "evhiperfifo.c" + * sample programs. This example implements a subset of the functionality from + * hiperfifo.c, for full functionality refer hiperfifo.c or evhiperfifo.c + * + * Written by Lijo Antony based on hiperfifo.c by Jeff Pohlmeyer + * + * When running, the program creates an easy handle for a URL and + * uses the curl_multi API to fetch it. + * + * Note: + * For the sake of simplicity, URL is hard coded to "www.google.com" + * + * This is purely a demo app, all retrieved data is simply discarded by the write + * callback. + */ + + +#include <curl/curl.h> +#include <boost/asio.hpp> +#include <boost/bind.hpp> + +#define MSG_OUT stdout /* Send info to stdout, change to stderr if you want */ + +/* boost::asio related objects + * using global variables for simplicity + */ +boost::asio::io_service io_service; +boost::asio::deadline_timer timer(io_service); +std::map<curl_socket_t, boost::asio::ip::tcp::socket *> socket_map; + +/* Global information, common to all connections */ +typedef struct _GlobalInfo +{ + CURLM *multi; + int still_running; +} GlobalInfo; + +/* Information associated with a specific easy handle */ +typedef struct _ConnInfo +{ + CURL *easy; + char *url; + GlobalInfo *global; + char error[CURL_ERROR_SIZE]; +} ConnInfo; + +static void timer_cb(const boost::system::error_code & error, GlobalInfo *g); + +/* Update the event timer after curl_multi library calls */ +static int multi_timer_cb(CURLM *multi, long timeout_ms, GlobalInfo *g) +{ + fprintf(MSG_OUT, "\nmulti_timer_cb: timeout_ms %ld", timeout_ms); + + /* cancel running timer */ + timer.cancel(); + + if ( timeout_ms > 0 ) + { + /* update timer */ + timer.expires_from_now(boost::posix_time::millisec(timeout_ms)); + timer.async_wait(boost::bind(&timer_cb, _1, g)); + } + else + { + /* call timeout function immediately */ + boost::system::error_code error; /*success*/ + timer_cb(error, g); + } + + return 0; +} + +/* Die if we get a bad CURLMcode somewhere */ +static void mcode_or_die(const char *where, CURLMcode code) +{ + if ( CURLM_OK != code ) + { + const char *s; + switch ( code ) + { + case CURLM_CALL_MULTI_PERFORM: s="CURLM_CALL_MULTI_PERFORM"; break; + 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"; + break; + case CURLM_BAD_SOCKET: s="CURLM_BAD_SOCKET"; + fprintf(MSG_OUT, "\nERROR: %s returns %s", where, s); + /* ignore this error */ + return; + } + fprintf(MSG_OUT, "\nERROR: %s returns %s", where, s); + exit(code); + } +} + +/* Check for completed transfers, and remove their easy handles */ +static void check_multi_info(GlobalInfo *g) +{ + char *eff_url; + CURLMsg *msg; + int msgs_left; + ConnInfo *conn; + CURL *easy; + CURLcode res; + + fprintf(MSG_OUT, "\nREMAINING: %d", g->still_running); + + 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); + curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url); + fprintf(MSG_OUT, "\nDONE: %s => (%d) %s", eff_url, res, conn->error); + curl_multi_remove_handle(g->multi, easy); + free(conn->url); + curl_easy_cleanup(easy); + free(conn); + } + } +} + +/* Called by asio when there is an action on a socket */ +static void event_cb(GlobalInfo * g, boost::asio::ip::tcp::socket * tcp_socket, int action) +{ + fprintf(MSG_OUT, "\nevent_cb: action=%d", action); + + CURLMcode rc; + rc = curl_multi_socket_action(g->multi, tcp_socket->native_handle(), action, &g->still_running); + + mcode_or_die("event_cb: curl_multi_socket_action", rc); + check_multi_info(g); + + if ( g->still_running <= 0 ) + { + fprintf(MSG_OUT, "\nlast transfer done, kill timeout"); + timer.cancel(); + } +} + +/* Called by asio when our timeout expires */ +static void timer_cb(const boost::system::error_code & error, GlobalInfo *g) +{ + if ( !error) + { + fprintf(MSG_OUT, "\ntimer_cb: "); + + CURLMcode rc; + 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); + } +} + +/* Clean up any data */ +static void remsock(int *f, GlobalInfo *g) +{ + fprintf(MSG_OUT, "\nremsock: "); + + if ( f ) + { + free(f); + } +} + +static void setsock(int *fdp, curl_socket_t s, CURL*e, int act, GlobalInfo*g) +{ + fprintf(MSG_OUT, "\nsetsock: socket=%d, act=%d, fdp=%p", s, act, fdp); + + std::map<curl_socket_t, boost::asio::ip::tcp::socket *>::iterator it = socket_map.find(s); + + if ( it == socket_map.end() ) + { + fprintf(MSG_OUT, "\nsocket %d is a c-ares socket, ignoring", s); + return; + } + + boost::asio::ip::tcp::socket * tcp_socket = it->second; + + *fdp = act; + + if ( act == CURL_POLL_IN ) + { + fprintf(MSG_OUT, "\nwatching for socket to become readable"); + + tcp_socket->async_read_some(boost::asio::null_buffers(), + boost::bind(&event_cb, g, + tcp_socket, + act)); + } + else if ( act == CURL_POLL_OUT ) + { + fprintf(MSG_OUT, "\nwatching for socket to become writable"); + + tcp_socket->async_write_some(boost::asio::null_buffers(), + boost::bind(&event_cb, g, + tcp_socket, + act)); + } + else if ( act == CURL_POLL_INOUT ) + { + fprintf(MSG_OUT, "\nwatching for socket to become readable & writable"); + + tcp_socket->async_read_some(boost::asio::null_buffers(), + boost::bind(&event_cb, g, + tcp_socket, + act)); + + tcp_socket->async_write_some(boost::asio::null_buffers(), + boost::bind(&event_cb, g, + tcp_socket, + act)); + } +} + + +static void addsock(curl_socket_t s, CURL *easy, int action, GlobalInfo *g) +{ + int *fdp = (int *)calloc(sizeof(int), 1); /* fdp is used to store current action */ + + setsock(fdp, s, easy, action, 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) +{ + fprintf(MSG_OUT, "\nsock_cb: socket=%d, what=%d, sockp=%p", s, what, sockp); + + GlobalInfo *g = (GlobalInfo*) cbp; + int *actionp = (int*) sockp; + const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE"}; + + fprintf(MSG_OUT, + "\nsocket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); + + if ( what == CURL_POLL_REMOVE ) + { + fprintf(MSG_OUT, "\n"); + remsock(actionp, g); + } + else + { + if ( !actionp ) + { + fprintf(MSG_OUT, "\nAdding data: %s", whatstr[what]); + addsock(s, e, what, g); + } + else + { + fprintf(MSG_OUT, + "\nChanging action from %s to %s", + whatstr[*actionp], whatstr[what]); + setsock(actionp, s, e, what, g); + } + } + return 0; +} + + +/* CURLOPT_WRITEFUNCTION */ +static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data) +{ + + size_t written = size * nmemb; + char* pBuffer = (char*)malloc(written + 1); + + strncpy(pBuffer, (const char *)ptr, written); + pBuffer [written] = '\0'; + + fprintf(MSG_OUT, "%s", pBuffer); + + free(pBuffer); + + return written; +} + + +/* CURLOPT_PROGRESSFUNCTION */ +static int prog_cb (void *p, double dltotal, double dlnow, double ult, + double uln) +{ + ConnInfo *conn = (ConnInfo *)p; + (void)ult; + (void)uln; + + fprintf(MSG_OUT, "\nProgress: %s (%g/%g)", conn->url, dlnow, dltotal); + fprintf(MSG_OUT, "\nProgress: %s (%g)", conn->url, ult); + + return 0; +} + +/* CURLOPT_OPENSOCKETFUNCTION */ +static curl_socket_t opensocket(void *clientp, + curlsocktype purpose, + struct curl_sockaddr *address) +{ + fprintf(MSG_OUT, "\nopensocket :"); + + curl_socket_t sockfd = CURL_SOCKET_BAD; + + struct sockaddr_in * addr = (struct sockaddr_in *)&(address->addr); + char * ip_addr_str = inet_ntoa(addr->sin_addr); + unsigned short port = ntohs(addr->sin_port); + + /* create a tcp socket object */ + boost::asio::ip::address ip_addr = boost::asio::ip::address::from_string(ip_addr_str); + boost::asio::ip::tcp::endpoint endpoint(ip_addr, port); + boost::asio::ip::tcp::socket * tcp_socket = new boost::asio::ip::tcp::socket(io_service); + + /* connect */ + boost::system::error_code ec; + tcp_socket->connect(endpoint, ec); + + if (ec) + { + //An error occurred + std::cout << std::endl << "Couldn't connect to remote endpoint '" << endpoint << "' [" << ec << "][" << ec.message() << "]"; + fprintf(MSG_OUT, "\nERROR: Returning CURL_SOCKET_BAD to signal error"); + } + else + { + sockfd = tcp_socket->native_handle(); + std::cout << std::endl << "Connected to remote endpoint '" << endpoint << "', with socket : " << sockfd; + + /* save it for monitoring */ + socket_map.insert(std::pair<curl_socket_t, boost::asio::ip::tcp::socket *>(sockfd, tcp_socket)); + } + + return sockfd; +} + +/* CURLOPT_SOCKOPTFUNCTION */ +static int sockopt_callback(void *clientp, curl_socket_t curlfd, + curlsocktype purpose) +{ + fprintf(MSG_OUT, "\nsockopt_callback :"); + + /* This return code was added in libcurl 7.21.5 */ + return CURL_SOCKOPT_ALREADY_CONNECTED; +} + +/* CURLOPT_CLOSESOCKETFUNCTION */ +static int closesocket(void *clientp, curl_socket_t item) +{ + fprintf(MSG_OUT, "\nclosesocket :"); + + std::map<curl_socket_t, boost::asio::ip::tcp::socket *>::iterator it = socket_map.find(item); + + if ( it != socket_map.end() ) + { + delete it->second; + socket_map.erase(it); + } + + return 0; +} + +/* Create a new easy handle, and add it to the global curl_multi */ +static void new_conn(char *url, GlobalInfo *g ) +{ + ConnInfo *conn; + CURLMcode rc; + + conn = (ConnInfo *)calloc(1, sizeof(ConnInfo)); + memset(conn, 0, sizeof(ConnInfo)); + conn->error[0]='\0'; + + conn->easy = curl_easy_init(); + + if ( !conn->easy ) + { + fprintf(MSG_OUT, "\ncurl_easy_init() failed, exiting!"); + exit(2); + } + conn->global = 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_VERBOSE, 1L); + curl_easy_setopt(conn->easy, CURLOPT_ERRORBUFFER, conn->error); + curl_easy_setopt(conn->easy, CURLOPT_PRIVATE, conn); + curl_easy_setopt(conn->easy, CURLOPT_NOPROGRESS, 1L); + curl_easy_setopt(conn->easy, CURLOPT_PROGRESSFUNCTION, prog_cb); + curl_easy_setopt(conn->easy, CURLOPT_PROGRESSDATA, conn); + curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_TIME, 3L); + curl_easy_setopt(conn->easy, CURLOPT_LOW_SPEED_LIMIT, 10L); + + /* call this function to get a socket */ + curl_easy_setopt(conn->easy, CURLOPT_OPENSOCKETFUNCTION, opensocket); + + /* call this function to set options for the socket */ + curl_easy_setopt(conn->easy, CURLOPT_SOCKOPTFUNCTION, sockopt_callback); + curl_easy_setopt(conn->easy, CURLOPT_CLOSESOCKETFUNCTION, closesocket); + + fprintf(MSG_OUT, + "\nAdding easy %p to multi %p (%s)", conn->easy, g->multi, url); + rc = curl_multi_add_handle(g->multi, conn->easy); + mcode_or_die("new_conn: curl_multi_add_handle", rc); + + /* note that the add_handle() will set a time-out to trigger very soon so + that the necessary socket_action() call will be called by this app */ +} + +int main(int argc, char **argv) +{ + GlobalInfo g; + CURLMcode rc; + (void)argc; + (void)argv; + + memset(&g, 0, sizeof(GlobalInfo)); + g.multi = curl_multi_init(); + + curl_multi_setopt(g.multi, CURLMOPT_SOCKETFUNCTION, sock_cb); + curl_multi_setopt(g.multi, CURLMOPT_SOCKETDATA, &g); + curl_multi_setopt(g.multi, CURLMOPT_TIMERFUNCTION, multi_timer_cb); + curl_multi_setopt(g.multi, CURLMOPT_TIMERDATA, &g); + + new_conn((char *)"www.google.com", &g); /* add a URL */ + + /* enter io_service run loop */ + io_service.run(); + + curl_multi_cleanup(g.multi); + + fprintf(MSG_OUT, "\ndone.\n"); + return 0; +} -- cgit v1.2.1 From f435d6699df9abac105ba2271d70a2290516c895 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <daniel@haxx.se> Date: Wed, 21 Nov 2012 18:26:42 +0100 Subject: htmltitle: use .cpp extension for C++ examples --- docs/examples/Makefile.inc | 2 +- docs/examples/htmltitle.cc | 313 -------------------------------------------- docs/examples/htmltitle.cpp | 313 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 314 insertions(+), 314 deletions(-) delete mode 100644 docs/examples/htmltitle.cc create mode 100644 docs/examples/htmltitle.cpp (limited to 'docs/examples') diff --git a/docs/examples/Makefile.inc b/docs/examples/Makefile.inc index e1f24cb7c..9aabfcabd 100644 --- a/docs/examples/Makefile.inc +++ b/docs/examples/Makefile.inc @@ -9,7 +9,7 @@ check_PROGRAMS = 10-at-a-time anyauthput cookie_interface debug fileupload \ # These examples require external dependencies that may not be commonly # available on POSIX systems, so don't bother attempting to compile them here. -COMPLICATED_EXAMPLES = curlgtk.c curlx.c htmltitle.cc cacertinmem.c \ +COMPLICATED_EXAMPLES = curlgtk.c curlx.c htmltitle.cpp cacertinmem.c \ ftpuploadresume.c ghiper.c hiperfifo.c htmltidy.c multithread.c \ opensslthreadlock.c sampleconv.c synctime.c threaded-ssl.c evhiperfifo.c \ smooth-gtk-thread.c version-check.pl href_extractor.c asiohiper.cpp diff --git a/docs/examples/htmltitle.cc b/docs/examples/htmltitle.cc deleted file mode 100644 index 55a7935ac..000000000 --- a/docs/examples/htmltitle.cc +++ /dev/null @@ -1,313 +0,0 @@ -/*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ - * \___|\___/|_| \_\_____| - * - * Copyright (C) 1998 - 2011, 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. - * - * 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. - * - ***************************************************************************/ -// Get a web page, parse it with libxml. -// -// Written by Lars Nilsson -// -// GNU C++ compile command line suggestion (edit paths accordingly): -// -// g++ -Wall -I/opt/curl/include -I/opt/libxml/include/libxml2 htmltitle.cc \ -// -o htmltitle -L/opt/curl/lib -L/opt/libxml/lib -lcurl -lxml2 - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <string> -#include <curl/curl.h> -#include <libxml/HTMLparser.h> - -// -// Case-insensitive string comparison -// - -#ifdef _MSC_VER -#define COMPARE(a, b) (!stricmp((a), (b))) -#else -#define COMPARE(a, b) (!strcasecmp((a), (b))) -#endif - -// -// libxml callback context structure -// - -struct Context -{ - Context(): addTitle(false) { } - - bool addTitle; - std::string title; -}; - -// -// libcurl variables for error strings and returned data - -static char errorBuffer[CURL_ERROR_SIZE]; -static std::string buffer; - -// -// libcurl write callback function -// - -static int writer(char *data, size_t size, size_t nmemb, - std::string *writerData) -{ - if (writerData == NULL) - return 0; - - writerData->append(data, size*nmemb); - - return size * nmemb; -} - -// -// libcurl connection initialization -// - -static bool init(CURL *&conn, char *url) -{ - CURLcode code; - - conn = curl_easy_init(); - - if (conn == NULL) - { - fprintf(stderr, "Failed to create CURL connection\n"); - - exit(EXIT_FAILURE); - } - - code = curl_easy_setopt(conn, CURLOPT_ERRORBUFFER, errorBuffer); - if (code != CURLE_OK) - { - fprintf(stderr, "Failed to set error buffer [%d]\n", code); - - return false; - } - - code = curl_easy_setopt(conn, CURLOPT_URL, url); - if (code != CURLE_OK) - { - fprintf(stderr, "Failed to set URL [%s]\n", errorBuffer); - - return false; - } - - code = curl_easy_setopt(conn, CURLOPT_FOLLOWLOCATION, 1L); - if (code != CURLE_OK) - { - fprintf(stderr, "Failed to set redirect option [%s]\n", errorBuffer); - - return false; - } - - code = curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writer); - if (code != CURLE_OK) - { - fprintf(stderr, "Failed to set writer [%s]\n", errorBuffer); - - return false; - } - - code = curl_easy_setopt(conn, CURLOPT_WRITEDATA, &buffer); - if (code != CURLE_OK) - { - fprintf(stderr, "Failed to set write data [%s]\n", errorBuffer); - - return false; - } - - return true; -} - -// -// libxml start element callback function -// - -static void StartElement(void *voidContext, - const xmlChar *name, - const xmlChar **attributes) -{ - Context *context = (Context *)voidContext; - - if (COMPARE((char *)name, "TITLE")) - { - context->title = ""; - context->addTitle = true; - } - (void) attributes; -} - -// -// libxml end element callback function -// - -static void EndElement(void *voidContext, - const xmlChar *name) -{ - Context *context = (Context *)voidContext; - - if (COMPARE((char *)name, "TITLE")) - context->addTitle = false; -} - -// -// Text handling helper function -// - -static void handleCharacters(Context *context, - const xmlChar *chars, - int length) -{ - if (context->addTitle) - context->title.append((char *)chars, length); -} - -// -// libxml PCDATA callback function -// - -static void Characters(void *voidContext, - const xmlChar *chars, - int length) -{ - Context *context = (Context *)voidContext; - - handleCharacters(context, chars, length); -} - -// -// libxml CDATA callback function -// - -static void cdata(void *voidContext, - const xmlChar *chars, - int length) -{ - Context *context = (Context *)voidContext; - - handleCharacters(context, chars, length); -} - -// -// libxml SAX callback structure -// - -static htmlSAXHandler saxHandler = -{ - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - StartElement, - EndElement, - NULL, - Characters, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - cdata, - NULL -}; - -// -// Parse given (assumed to be) HTML text and return the title -// - -static void parseHtml(const std::string &html, - std::string &title) -{ - htmlParserCtxtPtr ctxt; - Context context; - - ctxt = htmlCreatePushParserCtxt(&saxHandler, &context, "", 0, "", - XML_CHAR_ENCODING_NONE); - - htmlParseChunk(ctxt, html.c_str(), html.size(), 0); - htmlParseChunk(ctxt, "", 0, 1); - - htmlFreeParserCtxt(ctxt); - - title = context.title; -} - -int main(int argc, char *argv[]) -{ - CURL *conn = NULL; - CURLcode code; - std::string title; - - // Ensure one argument is given - - if (argc != 2) - { - fprintf(stderr, "Usage: %s <url>\n", argv[0]); - - exit(EXIT_FAILURE); - } - - curl_global_init(CURL_GLOBAL_DEFAULT); - - // Initialize CURL connection - - if (!init(conn, argv[1])) - { - fprintf(stderr, "Connection initializion failed\n"); - - exit(EXIT_FAILURE); - } - - // Retrieve content for the URL - - code = curl_easy_perform(conn); - curl_easy_cleanup(conn); - - if (code != CURLE_OK) - { - fprintf(stderr, "Failed to get '%s' [%s]\n", argv[1], errorBuffer); - - exit(EXIT_FAILURE); - } - - // Parse the (assumed) HTML code - - parseHtml(buffer, title); - - // Display the extracted title - - printf("Title: %s\n", title.c_str()); - - return EXIT_SUCCESS; -} diff --git a/docs/examples/htmltitle.cpp b/docs/examples/htmltitle.cpp new file mode 100644 index 000000000..55a7935ac --- /dev/null +++ b/docs/examples/htmltitle.cpp @@ -0,0 +1,313 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2011, 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. + * + * 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. + * + ***************************************************************************/ +// Get a web page, parse it with libxml. +// +// Written by Lars Nilsson +// +// GNU C++ compile command line suggestion (edit paths accordingly): +// +// g++ -Wall -I/opt/curl/include -I/opt/libxml/include/libxml2 htmltitle.cc \ +// -o htmltitle -L/opt/curl/lib -L/opt/libxml/lib -lcurl -lxml2 + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <string> +#include <curl/curl.h> +#include <libxml/HTMLparser.h> + +// +// Case-insensitive string comparison +// + +#ifdef _MSC_VER +#define COMPARE(a, b) (!stricmp((a), (b))) +#else +#define COMPARE(a, b) (!strcasecmp((a), (b))) +#endif + +// +// libxml callback context structure +// + +struct Context +{ + Context(): addTitle(false) { } + + bool addTitle; + std::string title; +}; + +// +// libcurl variables for error strings and returned data + +static char errorBuffer[CURL_ERROR_SIZE]; +static std::string buffer; + +// +// libcurl write callback function +// + +static int writer(char *data, size_t size, size_t nmemb, + std::string *writerData) +{ + if (writerData == NULL) + return 0; + + writerData->append(data, size*nmemb); + + return size * nmemb; +} + +// +// libcurl connection initialization +// + +static bool init(CURL *&conn, char *url) +{ + CURLcode code; + + conn = curl_easy_init(); + + if (conn == NULL) + { + fprintf(stderr, "Failed to create CURL connection\n"); + + exit(EXIT_FAILURE); + } + + code = curl_easy_setopt(conn, CURLOPT_ERRORBUFFER, errorBuffer); + if (code != CURLE_OK) + { + fprintf(stderr, "Failed to set error buffer [%d]\n", code); + + return false; + } + + code = curl_easy_setopt(conn, CURLOPT_URL, url); + if (code != CURLE_OK) + { + fprintf(stderr, "Failed to set URL [%s]\n", errorBuffer); + + return false; + } + + code = curl_easy_setopt(conn, CURLOPT_FOLLOWLOCATION, 1L); + if (code != CURLE_OK) + { + fprintf(stderr, "Failed to set redirect option [%s]\n", errorBuffer); + + return false; + } + + code = curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, writer); + if (code != CURLE_OK) + { + fprintf(stderr, "Failed to set writer [%s]\n", errorBuffer); + + return false; + } + + code = curl_easy_setopt(conn, CURLOPT_WRITEDATA, &buffer); + if (code != CURLE_OK) + { + fprintf(stderr, "Failed to set write data [%s]\n", errorBuffer); + + return false; + } + + return true; +} + +// +// libxml start element callback function +// + +static void StartElement(void *voidContext, + const xmlChar *name, + const xmlChar **attributes) +{ + Context *context = (Context *)voidContext; + + if (COMPARE((char *)name, "TITLE")) + { + context->title = ""; + context->addTitle = true; + } + (void) attributes; +} + +// +// libxml end element callback function +// + +static void EndElement(void *voidContext, + const xmlChar *name) +{ + Context *context = (Context *)voidContext; + + if (COMPARE((char *)name, "TITLE")) + context->addTitle = false; +} + +// +// Text handling helper function +// + +static void handleCharacters(Context *context, + const xmlChar *chars, + int length) +{ + if (context->addTitle) + context->title.append((char *)chars, length); +} + +// +// libxml PCDATA callback function +// + +static void Characters(void *voidContext, + const xmlChar *chars, + int length) +{ + Context *context = (Context *)voidContext; + + handleCharacters(context, chars, length); +} + +// +// libxml CDATA callback function +// + +static void cdata(void *voidContext, + const xmlChar *chars, + int length) +{ + Context *context = (Context *)voidContext; + + handleCharacters(context, chars, length); +} + +// +// libxml SAX callback structure +// + +static htmlSAXHandler saxHandler = +{ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + StartElement, + EndElement, + NULL, + Characters, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + cdata, + NULL +}; + +// +// Parse given (assumed to be) HTML text and return the title +// + +static void parseHtml(const std::string &html, + std::string &title) +{ + htmlParserCtxtPtr ctxt; + Context context; + + ctxt = htmlCreatePushParserCtxt(&saxHandler, &context, "", 0, "", + XML_CHAR_ENCODING_NONE); + + htmlParseChunk(ctxt, html.c_str(), html.size(), 0); + htmlParseChunk(ctxt, "", 0, 1); + + htmlFreeParserCtxt(ctxt); + + title = context.title; +} + +int main(int argc, char *argv[]) +{ + CURL *conn = NULL; + CURLcode code; + std::string title; + + // Ensure one argument is given + + if (argc != 2) + { + fprintf(stderr, "Usage: %s <url>\n", argv[0]); + + exit(EXIT_FAILURE); + } + + curl_global_init(CURL_GLOBAL_DEFAULT); + + // Initialize CURL connection + + if (!init(conn, argv[1])) + { + fprintf(stderr, "Connection initializion failed\n"); + + exit(EXIT_FAILURE); + } + + // Retrieve content for the URL + + code = curl_easy_perform(conn); + curl_easy_cleanup(conn); + + if (code != CURLE_OK) + { + fprintf(stderr, "Failed to get '%s' [%s]\n", argv[1], errorBuffer); + + exit(EXIT_FAILURE); + } + + // Parse the (assumed) HTML code + + parseHtml(buffer, title); + + // Display the extracted title + + printf("Title: %s\n", title.c_str()); + + return EXIT_SUCCESS; +} -- cgit v1.2.1 From 616a0099d14887b933c3b5bc5c253e6b8b1139f5 Mon Sep 17 00:00:00 2001 From: Lijo Antony <lta@one.com> Date: Sun, 25 Nov 2012 10:00:58 +0400 Subject: examples: Updated asiohiper.cpp to remove connect from opensocket Blocking connect on the socket has been removed from opensocket callback. opensocket just opens a new socket and gives it back to libcurl and libcurl will take care of the connect. sockopt_callback has also been removed, as it is no longer required. --- docs/examples/asiohiper.cpp | 59 ++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 36 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/asiohiper.cpp b/docs/examples/asiohiper.cpp index 1ea350253..44836fdc1 100644 --- a/docs/examples/asiohiper.cpp +++ b/docs/examples/asiohiper.cpp @@ -336,51 +336,39 @@ static curl_socket_t opensocket(void *clientp, curl_socket_t sockfd = CURL_SOCKET_BAD; - struct sockaddr_in * addr = (struct sockaddr_in *)&(address->addr); - char * ip_addr_str = inet_ntoa(addr->sin_addr); - unsigned short port = ntohs(addr->sin_port); - - /* create a tcp socket object */ - boost::asio::ip::address ip_addr = boost::asio::ip::address::from_string(ip_addr_str); - boost::asio::ip::tcp::endpoint endpoint(ip_addr, port); - boost::asio::ip::tcp::socket * tcp_socket = new boost::asio::ip::tcp::socket(io_service); + /* restrict to ipv4 */ + if (purpose == CURLSOCKTYPE_IPCXN && address->family == AF_INET) + { + /* create a tcp socket object */ + boost::asio::ip::tcp::socket *tcp_socket = new boost::asio::ip::tcp::socket(io_service); - /* connect */ - boost::system::error_code ec; - tcp_socket->connect(endpoint, ec); + /* open it and get the native handle*/ + boost::system::error_code ec; + tcp_socket->open(boost::asio::ip::tcp::v4(), ec); - if (ec) - { - //An error occurred - std::cout << std::endl << "Couldn't connect to remote endpoint '" << endpoint << "' [" << ec << "][" << ec.message() << "]"; - fprintf(MSG_OUT, "\nERROR: Returning CURL_SOCKET_BAD to signal error"); - } - else - { - sockfd = tcp_socket->native_handle(); - std::cout << std::endl << "Connected to remote endpoint '" << endpoint << "', with socket : " << sockfd; + if (ec) + { + //An error occurred + std::cout << std::endl << "Couldn't open socket [" << ec << "][" << ec.message() << "]"; + fprintf(MSG_OUT, "\nERROR: Returning CURL_SOCKET_BAD to signal error"); + } + else + { + sockfd = tcp_socket->native_handle(); + fprintf(MSG_OUT, "\nOpened socket %d", sockfd); - /* save it for monitoring */ - socket_map.insert(std::pair<curl_socket_t, boost::asio::ip::tcp::socket *>(sockfd, tcp_socket)); + /* save it for monitoring */ + socket_map.insert(std::pair<curl_socket_t, boost::asio::ip::tcp::socket *>(sockfd, tcp_socket)); + } } return sockfd; } -/* CURLOPT_SOCKOPTFUNCTION */ -static int sockopt_callback(void *clientp, curl_socket_t curlfd, - curlsocktype purpose) -{ - fprintf(MSG_OUT, "\nsockopt_callback :"); - - /* This return code was added in libcurl 7.21.5 */ - return CURL_SOCKOPT_ALREADY_CONNECTED; -} - /* CURLOPT_CLOSESOCKETFUNCTION */ static int closesocket(void *clientp, curl_socket_t item) { - fprintf(MSG_OUT, "\nclosesocket :"); + fprintf(MSG_OUT, "\nclosesocket : %d", item); std::map<curl_socket_t, boost::asio::ip::tcp::socket *>::iterator it = socket_map.find(item); @@ -427,8 +415,7 @@ static void new_conn(char *url, GlobalInfo *g ) /* call this function to get a socket */ curl_easy_setopt(conn->easy, CURLOPT_OPENSOCKETFUNCTION, opensocket); - /* call this function to set options for the socket */ - curl_easy_setopt(conn->easy, CURLOPT_SOCKOPTFUNCTION, sockopt_callback); + /* call this function to close a socket */ curl_easy_setopt(conn->easy, CURLOPT_CLOSESOCKETFUNCTION, closesocket); fprintf(MSG_OUT, -- cgit v1.2.1 From 6bd6b3a8a17e2f2004e276c7568feaa01acebfe7 Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Fri, 30 Nov 2012 19:12:18 +0100 Subject: build: prevent global LIBS from influencing examples build targets --- docs/examples/Makefile.am | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index eb4e7c767..49c20361f 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -36,18 +36,27 @@ EXTRA_DIST = README Makefile.example Makefile.inc Makefile.m32 \ AM_CPPFLAGS = -I$(top_builddir)/include/curl \ -I$(top_builddir)/include \ - -I$(top_srcdir)/include \ - -DCURL_NO_OLDIES + -I$(top_srcdir)/include LIBDIR = $(top_builddir)/lib +# Avoid libcurl obsolete stuff +AM_CPPFLAGS += -DCURL_NO_OLDIES + # Mostly for Windows build targets, when using static libcurl if USE_CPPFLAG_CURL_STATICLIB AM_CPPFLAGS += -DCURL_STATICLIB endif +# Prevent global LIBS from influencing examples build targets +LIBS = $(BLANK_AT_MAKETIME) + # Dependencies +if USE_EXPLICIT_LIB_DEPS +LDADD = $(LIBDIR)/libcurl.la @LIBCURL_LIBS@ +else LDADD = $(LIBDIR)/libcurl.la +endif # Makefile.inc provides the check_PROGRAMS and COMPLICATED_EXAMPLES defines include Makefile.inc -- cgit v1.2.1 From b908376bef462644e204b50f7a8c3df5871883bf Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Tue, 4 Dec 2012 23:30:05 +0100 Subject: build: explain current role of LIBS in our Makefile.am files BLANK_AT_MAKETIME may be used in our Makefile.am files to blank LIBS variable used in generated makefile at makefile processing time. Doing this functionally prevents LIBS from being used for all link targets in given makefile. --- docs/examples/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples') diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am index 49c20361f..865f09371 100644 --- a/docs/examples/Makefile.am +++ b/docs/examples/Makefile.am @@ -48,7 +48,7 @@ if USE_CPPFLAG_CURL_STATICLIB AM_CPPFLAGS += -DCURL_STATICLIB endif -# Prevent global LIBS from influencing examples build targets +# Prevent LIBS from being used for all link targets LIBS = $(BLANK_AT_MAKETIME) # Dependencies -- cgit v1.2.1 From 23f8dca6fb91329fe78bb5a00527286692d2a357 Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Wed, 5 Dec 2012 00:37:57 +0100 Subject: examples: fix compilation issues --- docs/examples/anyauthput.c | 6 +++++- docs/examples/ftpgetinfo.c | 10 +++++----- docs/examples/progressfunc.c | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index 5dac0e779..54e5f1aff 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -27,7 +27,11 @@ # ifdef __VMS typedef int intptr_t; # endif -# include <stdint.h> +# if defined(_AIX) || defined(__sgi) || defined(__osf) + typedef long intptr_t; +# else +# include <stdint.h> +# endif # include <unistd.h> #endif #include <sys/types.h> diff --git a/docs/examples/ftpgetinfo.c b/docs/examples/ftpgetinfo.c index f0746693b..7063d89b9 100644 --- a/docs/examples/ftpgetinfo.c +++ b/docs/examples/ftpgetinfo.c @@ -43,8 +43,8 @@ int main(void) char ftpurl[] = "ftp://ftp.example.com/gnu/binutils/binutils-2.19.1.tar.bz2"; CURL *curl; CURLcode res; - const time_t filetime; - const double filesize; + long filetime = -1; + double filesize = 0.0; const char *filename = strrchr(ftpurl, '/') + 1; curl_global_init(CURL_GLOBAL_DEFAULT); @@ -67,10 +67,10 @@ int main(void) if(CURLE_OK == res) { /* http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html */ res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime); - if((CURLE_OK == res) && filetime) - printf("filetime %s: %s", filename, ctime(&filetime)); + if((CURLE_OK == res) && (filetime >= 0)) + printf("filetime %s: %s", filename, ctime(&(time_t)filetime)); res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &filesize); - if((CURLE_OK == res) && (filesize>0)) + if((CURLE_OK == res) && (filesize>0.0)) printf("filesize %s: %0.0f bytes\n", filename, filesize); } else { /* we failed */ diff --git a/docs/examples/progressfunc.c b/docs/examples/progressfunc.c index a49806028..51a9c9b5e 100644 --- a/docs/examples/progressfunc.c +++ b/docs/examples/progressfunc.c @@ -59,7 +59,7 @@ static int progress(void *p, int main(void) { CURL *curl; - CURLcode res=0; + CURLcode res = CURLE_OK; struct myprogress prog; curl = curl_easy_init(); @@ -74,7 +74,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); res = curl_easy_perform(curl); - if(res) + if(res != CURLE_OK) fprintf(stderr, "%s\n", curl_easy_strerror(res)); /* always cleanup */ -- cgit v1.2.1 From 7332a7cafba43c96893a8df9b08e5d15df4f3288 Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Wed, 5 Dec 2012 11:43:40 +0100 Subject: examples: fix compilation issues - commit 23f8dca6fb follow-up --- docs/examples/anyauthput.c | 10 +++++++--- docs/examples/ftpgetinfo.c | 8 +++++--- docs/examples/post-callback.c | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index 54e5f1aff..6eea98f1d 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -27,9 +27,7 @@ # ifdef __VMS typedef int intptr_t; # endif -# if defined(_AIX) || defined(__sgi) || defined(__osf) - typedef long intptr_t; -# else +# if !defined(_AIX) && !defined(__sgi) && !defined(__DECC) # include <stdint.h> # endif # include <unistd.h> @@ -55,6 +53,12 @@ #define TRUE 1 #endif +#if defined(_AIX) || defined(__sgi) || defined(__DECC) +#ifndef intptr_t +#define intptr_t long +#endif +#endif + /* * This example shows a HTTP PUT operation with authentiction using "any" * type. It PUTs a file given as a command line argument to the URL also given diff --git a/docs/examples/ftpgetinfo.c b/docs/examples/ftpgetinfo.c index 7063d89b9..dfdcf78b7 100644 --- a/docs/examples/ftpgetinfo.c +++ b/docs/examples/ftpgetinfo.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -67,8 +67,10 @@ int main(void) if(CURLE_OK == res) { /* http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html */ res = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime); - if((CURLE_OK == res) && (filetime >= 0)) - printf("filetime %s: %s", filename, ctime(&(time_t)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); if((CURLE_OK == res) && (filesize>0.0)) printf("filesize %s: %0.0f bytes\n", filename, filesize); diff --git a/docs/examples/post-callback.c b/docs/examples/post-callback.c index f11fb983b..3e1cfb060 100644 --- a/docs/examples/post-callback.c +++ b/docs/examples/post-callback.c @@ -58,7 +58,7 @@ int main(void) struct WriteThis pooh; pooh.readptr = data; - pooh.sizeleft = strlen(data); + pooh.sizeleft = (long)strlen(data); /* In windows, this will init the winsock stuff */ res = curl_global_init(CURL_GLOBAL_DEFAULT); -- cgit v1.2.1 From fe2b2a3b9dbe18883cf7c9789cd958915978dc3a Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Wed, 5 Dec 2012 12:59:14 +0100 Subject: examples: fix compilation issues - commit 7332a7cafb follow-up --- docs/examples/cookie_interface.c | 4 ++-- docs/examples/rtsp.c | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/cookie_interface.c b/docs/examples/cookie_interface.c index ac3685fd8..2e7c66db2 100644 --- a/docs/examples/cookie_interface.c +++ b/docs/examples/cookie_interface.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -89,7 +89,7 @@ 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", time(NULL) + 31337, "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)); diff --git a/docs/examples/rtsp.c b/docs/examples/rtsp.c index 1cc19677a..669780a9b 100644 --- a/docs/examples/rtsp.c +++ b/docs/examples/rtsp.c @@ -178,7 +178,7 @@ int main(int argc, char * const argv[]) #endif const char *range = "0.000-"; int rc = EXIT_SUCCESS; - char *basename = NULL; + char *base_name = NULL; printf("\nRTSP request %s\n", VERSION_STR); printf(" Project web site: http://code.google.com/p/rtsprequest/\n"); @@ -186,20 +186,20 @@ int main(int argc, char * const argv[]) /* check command line */ if ((argc != 2) && (argc != 3)) { - basename = strrchr(argv[0], '/'); - if (basename == NULL) { - basename = strrchr(argv[0], '\\'); + base_name = strrchr(argv[0], '/'); + if (base_name == NULL) { + base_name = strrchr(argv[0], '\\'); } - if (basename == NULL) { - basename = argv[0]; + if (base_name == NULL) { + base_name = argv[0]; } else { - basename++; + base_name++; } - printf("Usage: %s url [transport]\n", basename); + printf("Usage: %s url [transport]\n", base_name); printf(" url of video server\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", basename); + printf("Example: %s rtsp://192.168.0.2/media/video1\n\n", base_name); rc = EXIT_FAILURE; } else { const char *url = argv[1]; -- cgit v1.2.1 From d758234ade7c1cbc4cdd91ea1bd6defb6b690340 Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Mon, 10 Dec 2012 15:42:12 +0100 Subject: examples/anyauthput.c: fix Tru64 compilation issue --- docs/examples/anyauthput.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/anyauthput.c b/docs/examples/anyauthput.c index 6eea98f1d..b89dca2e1 100644 --- a/docs/examples/anyauthput.c +++ b/docs/examples/anyauthput.c @@ -27,7 +27,7 @@ # ifdef __VMS typedef int intptr_t; # endif -# if !defined(_AIX) && !defined(__sgi) && !defined(__DECC) +# if !defined(_AIX) && !defined(__sgi) && !defined(__osf__) # include <stdint.h> # endif # include <unistd.h> @@ -53,7 +53,7 @@ #define TRUE 1 #endif -#if defined(_AIX) || defined(__sgi) || defined(__DECC) +#if defined(_AIX) || defined(__sgi) || defined(__osf__) #ifndef intptr_t #define intptr_t long #endif -- cgit v1.2.1 From e880680fb666f42cbb0cc3457b35c51d23695980 Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Mon, 10 Dec 2012 17:55:18 +0100 Subject: examples/simplessl.c: fix compiler warning --- docs/examples/simplessl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index b77c276e4..0765e1224 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, 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 @@ -76,7 +76,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_URL, "HTTPS://your.favourite.ssl.site"); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, headerfile); - while(1) /* do some ugly short cut... */ + for(;;) /* do some ugly short cut... */ { if (pEngine) /* use crypto engine */ { -- cgit v1.2.1 From 85b77209ae10d6d0fc90f93a47b06440aa184ede Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Mon, 10 Dec 2012 18:06:35 +0100 Subject: examples/externalsocket.c: fix SunPro compilation issue --- docs/examples/externalsocket.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docs/examples') diff --git a/docs/examples/externalsocket.c b/docs/examples/externalsocket.c index 6e2a773b2..1b326c8b2 100644 --- a/docs/examples/externalsocket.c +++ b/docs/examples/externalsocket.c @@ -47,6 +47,10 @@ #define IPADDR "127.0.0.1" #define PORTNUM 80 +#ifndef INADDR_NONE +#define INADDR_NONE 0xffffffff +#endif + static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) { int written = fwrite(ptr, size, nmemb, (FILE *)stream); -- cgit v1.2.1 From f4b60e7f140d72a052a22a05bc47a0ffdc00725c Mon Sep 17 00:00:00 2001 From: Yang Tse <yangsita@gmail.com> Date: Tue, 11 Dec 2012 15:03:17 +0100 Subject: examples/simplessl.c: fix compiler warning --- docs/examples/simplessl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'docs/examples') diff --git a/docs/examples/simplessl.c b/docs/examples/simplessl.c index 0765e1224..74c58461a 100644 --- a/docs/examples/simplessl.c +++ b/docs/examples/simplessl.c @@ -43,6 +43,7 @@ int main(void) { + int i; CURL *curl; CURLcode res; FILE *headerfile; @@ -76,7 +77,7 @@ int main(void) curl_easy_setopt(curl, CURLOPT_URL, "HTTPS://your.favourite.ssl.site"); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, headerfile); - for(;;) /* do some ugly short cut... */ + for(i = 0; i < 1; i++) /* single-iteration loop, just to break out from */ { if (pEngine) /* use crypto engine */ { @@ -125,7 +126,7 @@ int main(void) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); - break; /* we are done... */ + /* we are done... */ } /* always cleanup */ curl_easy_cleanup(curl); -- cgit v1.2.1