aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2015-01-21 11:05:45 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2015-01-21 11:13:33 +0200
commit5fe918d1f84af9b1f70deb152bf20d0b8a296524 (patch)
treebf97fd6460a92260a1f3563c7583febe6ca863d1 /lib
parentf896658fd2c2c2b832536adb8af5ae6789c387a2 (diff)
downloadeclat-5fe918d1f84af9b1f70deb152bf20d0b8a296524.tar.gz
eclat-5fe918d1f84af9b1f70deb152bf20d0b8a296524.tar.bz2
Add ispeek.
* src/ispeek.c: New file. * src/ispeek-cl.opt: New file * src/Makefile.am: Add ispeek * src/io.c (dump, eclat_trace_fun): Moved to the library. (eclat_io_setup): Use eclat_set_curl_trace. * NEWS: Document ispeek. * doc/Makefile.inc: Add ispeek.1 * doc/eclat.1man: Mention ispeek(1) in the "see also" section. * doc/eclat.conf.5: Update. * doc/ispeek.1: New file. * lib/Makefile.am (libeclat_a_SOURCES): Add trace.c * lib/libeclat.h (eclat_trace_fun) (eclat_set_curl_trace): New proto. * lib/trace.c: New file.
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am1
-rw-r--r--lib/libeclat.h6
-rw-r--r--lib/trace.c121
3 files changed, 128 insertions, 0 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 428de49..445d949 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -62,6 +62,7 @@ libeclat_a_SOURCES=\
sha1.h\
sha256.c\
sha256.h\
+ trace.c\
urlencode.c\
xmltree.c\
$(maps)
diff --git a/lib/libeclat.h b/lib/libeclat.h
index 2265a7b..4d6882e 100644
--- a/lib/libeclat.h
+++ b/lib/libeclat.h
@@ -16,6 +16,7 @@
#include <stddef.h>
#include <expat.h>
+#include <curl/curl.h>
#include "grecs.h"
extern const char *program_name;
@@ -50,6 +51,11 @@ void debug_printf(const char *fmt, ...);
int parse_debug_level(const char *arg);
int debug_register(char *name);
+int eclat_trace_fun(CURL *handle, curl_infotype type,
+ char *data, size_t size,
+ void *userp);
+void eclat_set_curl_trace(CURL *curl, int lev);
+
void hmac_sha1(const void *text, size_t textlen,
const void *key, size_t keylen,
diff --git a/lib/trace.c b/lib/trace.c
new file mode 100644
index 0000000..4438822
--- /dev/null
+++ b/lib/trace.c
@@ -0,0 +1,121 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012-2015 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "libeclat.h"
+#include <curl/curl.h>
+
+static void
+dump(const char *text, FILE *stream, unsigned char *ptr, size_t size, int hex)
+{
+ size_t i;
+ size_t c;
+ unsigned int width = 0x10;
+
+ if (!hex)
+ /* 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 < size; i += width) {
+ fprintf(stream, "%04zx: ", i);
+
+ if (hex) {
+ for (c = 0; c < width; c++)
+ if (i+c < size)
+ fprintf(stream, "%02x ", ptr[i+c]);
+ else
+ fputs(" ", stream);
+ }
+
+ for (c = 0; (c < width) && (i+c < size); c++) {
+ /* check for CRLf; if found, skip past and start a
+ new line of output */
+ if (!hex && (i + c + 1 < size) &&
+ ptr[i+c] == '\r' && ptr[i+c+1] == '\n') {
+ i += (c + 2 -width);
+ break;
+ }
+ fprintf(stream, "%c",
+ isprint(ptr[i+c]) ? ptr[i+c] : '.');
+ /* check again for CRLF, to avoid an extra \n if
+ it's at width */
+ if (!hex && (i + c + 2 < size) &&
+ ptr[i+c+1] == '\r' && ptr[i+c+2] == '\n') {
+ i += (c + 3 - width);
+ break;
+ }
+ }
+ fputc('\n', stream);
+ }
+ fflush(stream);
+}
+
+int
+eclat_trace_fun(CURL *handle, curl_infotype type,
+ char *data, size_t size,
+ void *userp)
+{
+ int hex;
+ const char *text;
+
+ hex = !!userp;
+
+ switch (type) {
+ case CURLINFO_TEXT:
+ fprintf(stderr, "== Info: %s", data);
+ default: /* in case a new one is introduced to shock us */
+ return 0;
+
+ case CURLINFO_HEADER_OUT:
+ text = "=> Send header";
+ break;
+ case CURLINFO_DATA_OUT:
+ text = "=> Send data";
+ break;
+ case CURLINFO_SSL_DATA_OUT:
+ text = "=> Send SSL data";
+ break;
+ case CURLINFO_HEADER_IN:
+ text = "<= Recv header";
+ break;
+ case CURLINFO_DATA_IN:
+ text = "<= Recv data";
+ break;
+ case CURLINFO_SSL_DATA_IN:
+ text = "<= Recv SSL data";
+ break;
+ }
+
+ dump(text, stderr, (unsigned char *)data, size, hex);
+ return 0;
+}
+
+void
+eclat_set_curl_trace(CURL *curl, int lev)
+{
+ if (lev == 0)
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
+ else {
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+ if (lev > 1) {
+ curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
+ eclat_trace_fun);
+ if (lev > 2)
+ curl_easy_setopt(curl, CURLOPT_DEBUGDATA, 1L);
+ }
+ }
+}

Return to:

Send suggestions and report system problems to the System administrator.