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/debug.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 docs/examples/debug.c (limited to 'docs/examples/debug.c') 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 7575e6afc44f30f07a9bc8c2696c1fb451fd323e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg 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/debug.c') 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 b12fef3f3137bc606d283a2e527dd9050edf2b12 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg 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/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples/debug.c') 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; } -- cgit v1.2.1 From e664cd5826d43930fcc5b5dbaedbec94af33184b Mon Sep 17 00:00:00 2001 From: Dan Fandrich 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/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/debug.c') 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); -- cgit v1.2.1 From 6582895b5146149aab7c619cbcb0ea292cfe12e6 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 5 Jun 2009 18:40:40 +0000 Subject: docs/example patches for VMS --- docs/examples/debug.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'docs/examples/debug.c') 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 Date: Wed, 24 Mar 2010 11:02:54 +0100 Subject: remove the CVSish $Id$ lines --- docs/examples/debug.c | 1 - 1 file changed, 1 deletion(-) (limited to 'docs/examples/debug.c') 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 -- cgit v1.2.1 From 18e7b52e8e95f7204d8ef7ff0f0ff0043afe45a9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 5 Oct 2010 15:00:19 +0200 Subject: examples: use example.com in example URLs --- docs/examples/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/debug.c') 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 */ -- cgit v1.2.1 From 9583b4af9057c9e35ec3dd3270d4c4813b5f7aaa Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 17 Dec 2010 23:34:26 +0100 Subject: examples: fix compiler warnings --- docs/examples/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples/debug.c') 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 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/debug.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'docs/examples/debug.c') 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, , 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 #include -- cgit v1.2.1 From a3dbbcfd2ac7ab8f597e26e76935726279d3fa0c Mon Sep 17 00:00:00 2001 From: Guenter Knauf Date: Wed, 4 Jul 2012 17:03:52 +0200 Subject: Added error checking for samples. --- docs/examples/debug.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docs/examples/debug.c') 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); -- cgit v1.2.1