Added new user api unit test for the new fields.
[libgcal.git] / src / curl_debug_gcal.c
blobad045ccf29efa5f4b9f5b9f28c429b0fb6cd62c9
1 #include <stdio.h>
2 #include "curl_debug_gcal.h"
4 /* Coments: this came straight from libcurl examples directory and
5 * will print information to stderr when executing curl_easy_perform.
6 * I'm not completely sure about its author, but I'm assuming that it uses
7 * the same license as curl itself (X11/MIT).
9 * I made only small changes in space and formating.
11 * Adenilson Cavalcanti
14 /*****************************************************************************
15 * _ _ ____ _
16 * Project ___| | | | _ \| |
17 * / __| | | | |_) | |
18 * | (__| |_| | _ <| |___
19 * \___|\___/|_| \_\_____|
21 * $Id: debug.c,v 1.2 2006-10-20 21:26:10 bagder Exp $
25 static void curl_debug_dump(const char *text,
26 FILE *stream, unsigned char *ptr, size_t size,
27 char nohex)
29 size_t i;
30 size_t c;
32 unsigned int width=0x10;
34 /* without the hex output, we can fit more on screen */
35 if (nohex)
36 width = 0x40;
38 fprintf(stream, "%s, %zd bytes (0x%zx)\n", text, size, size);
40 for (i = 0; i< size; i+= width) {
42 fprintf(stream, "%04zx: ", i);
44 if (!nohex) {
45 /* hex not disabled, show it */
46 for(c = 0; c < width; c++)
47 if(i+c < size)
48 fprintf(stream, "%02x ", ptr[i+c]);
49 else
50 fputs(" ", stream);
53 for(c = 0; (c < width) && (i+c < size); c++) {
54 /* check for 0D0A; if found, skip past and start
55 * a new line of output
57 if (nohex && (i+c+1 < size) &&
58 ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) {
59 i+=(c+2-width);
60 break;
63 fprintf(stream, "%c",
64 (ptr[i+c]>=0x20) &&
65 (ptr[i+c]<0x80)?ptr[i+c]:'.');
67 /* check again for 0D0A, to avoid an extra
68 * \n if it's at width
70 if (nohex && (i+c+2 < size) &&
71 ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) {
72 i+=(c+3-width);
73 break;
77 fputc('\n', stream); /* newline */
80 fflush(stream);
83 int curl_debug_gcal_trace(CURL *handle, curl_infotype type,
84 unsigned char *data, size_t size,
85 void *userp)
87 struct data_curl_debug *config = (struct data_curl_debug *)userp;
88 const char *text;
89 (void)handle; /* prevent compiler warning */
91 switch (type) {
92 case CURLINFO_TEXT:
93 fprintf(stderr, "== Info: %s", data);
94 default: /* in case a new one is introduced to shock us */
95 return 0;
97 case CURLINFO_HEADER_OUT:
98 text = "=> Send header";
99 break;
100 case CURLINFO_DATA_OUT:
101 text = "=> Send data";
102 break;
103 case CURLINFO_SSL_DATA_OUT:
104 text = "=> Send SSL data";
105 break;
106 case CURLINFO_HEADER_IN:
107 text = "<= Recv header";
108 break;
109 case CURLINFO_DATA_IN:
110 text = "<= Recv data";
111 break;
112 case CURLINFO_SSL_DATA_IN:
113 text = "<= Recv SSL data";
114 break;
117 curl_debug_dump(text, stderr, data, size, config->trace_ascii);
118 return 0;