dovecot-2.0-pigeonhole: Sieve-dump: added support for producing ...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Mon Sep 6 19:36:29 EEST 2010
details: http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/1a7060ef63ce
changeset: 1414:1a7060ef63ce
user: Stephan Bosch <stephan at rename-it.nl>
date: Mon Sep 06 18:36:25 2010 +0200
description:
Sieve-dump: added support for producing per-block hexdump output.
diffstat:
doc/man/sieve-dump.1.in | 4 +
src/lib-sieve-tool/sieve-tool.c | 8 ++-
src/lib-sieve-tool/sieve-tool.h | 2 +-
src/lib-sieve/sieve-binary-dumper.c | 94 ++++++++++++++++++++++++++++++-
src/lib-sieve/sieve-binary-dumper.h | 6 ++
src/lib-sieve/sieve-binary.h | 1 -
src/lib-sieve/sieve.c | 13 ++++-
src/lib-sieve/sieve.h | 11 +++-
src/sieve-tools/sieve-dump.c | 21 +++++--
src/sieve-tools/sieve-test.c | 2 +-
src/sieve-tools/sievec.c | 2 +-
src/testsuite/testsuite.c | 2 +-
12 files changed, 149 insertions(+), 17 deletions(-)
diffs (truncated from 327 to 300 lines):
diff -r 33bc93bdde44 -r 1a7060ef63ce doc/man/sieve-dump.1.in
--- a/doc/man/sieve-dump.1.in Sun Sep 05 21:37:41 2010 +0200
+++ b/doc/man/sieve-dump.1.in Mon Sep 06 18:36:25 2010 +0200
@@ -40,6 +40,10 @@
.BI \-c\ config\-file
Alternative Dovecot configuration file path.
.TP
+.B \-h
+Produce per-block hexdump output of the whole binary instead of the normal
+human-readable output.
+.TP
.BI \-x\ extensions
Set the available extensions. The parameter is a space\-separated list of the
active extensions. By prepending the extension identifiers with \fB+\fP or
diff -r 33bc93bdde44 -r 1a7060ef63ce src/lib-sieve-tool/sieve-tool.c
--- a/src/lib-sieve-tool/sieve-tool.c Sun Sep 05 21:37:41 2010 +0200
+++ b/src/lib-sieve-tool/sieve-tool.c Mon Sep 06 18:36:25 2010 +0200
@@ -547,7 +547,8 @@
return sbin;
}
-void sieve_tool_dump_binary_to(struct sieve_binary *sbin, const char *filename)
+void sieve_tool_dump_binary_to
+(struct sieve_binary *sbin, const char *filename, bool hexdump)
{
struct ostream *dumpstream;
@@ -555,7 +556,10 @@
dumpstream = sieve_tool_open_output_stream(filename);
if ( dumpstream != NULL ) {
- (void) sieve_dump(sbin, dumpstream, FALSE);
+ if ( hexdump )
+ (void) sieve_hexdump(sbin, dumpstream);
+ else
+ (void) sieve_dump(sbin, dumpstream, FALSE);
o_stream_destroy(&dumpstream);
} else {
i_fatal("Failed to create stream for sieve code dump.");
diff -r 33bc93bdde44 -r 1a7060ef63ce src/lib-sieve-tool/sieve-tool.h
--- a/src/lib-sieve-tool/sieve-tool.h Sun Sep 05 21:37:41 2010 +0200
+++ b/src/lib-sieve-tool/sieve-tool.h Mon Sep 06 18:36:25 2010 +0200
@@ -87,7 +87,7 @@
struct sieve_binary *sieve_tool_script_open
(struct sieve_instance *svinst, const char *filename);
void sieve_tool_dump_binary_to
- (struct sieve_binary *sbin, const char *filename);
+ (struct sieve_binary *sbin, const char *filename, bool hexdump);
/*
* Command line option parsing
diff -r 33bc93bdde44 -r 1a7060ef63ce src/lib-sieve/sieve-binary-dumper.c
--- a/src/lib-sieve/sieve-binary-dumper.c Sun Sep 05 21:37:41 2010 +0200
+++ b/src/lib-sieve/sieve-binary-dumper.c Mon Sep 06 18:36:25 2010 +0200
@@ -4,12 +4,14 @@
#include "lib.h"
#include "str.h"
#include "ostream.h"
+#include "array.h"
+#include "buffer.h"
#include "sieve-common.h"
#include "sieve-extensions.h"
-#include "sieve-binary.h"
+#include "sieve-dump.h"
-#include "sieve-dump.h"
+#include "sieve-binary-private.h"
/*
* Binary dumper object
@@ -180,3 +182,91 @@
return TRUE;
}
+
+/*
+ * Hexdump production
+ */
+
+void sieve_binary_dumper_hexdump
+(struct sieve_binary_dumper *dumper, struct ostream *stream)
+{
+ struct sieve_binary *sbin = dumper->dumpenv.sbin;
+ struct sieve_dumptime_env *denv = &(dumper->dumpenv);
+ int count, i;
+
+ dumper->dumpenv.stream = stream;
+
+ count = sieve_binary_block_count(sbin);
+
+ /* Block overview */
+
+ sieve_binary_dump_sectionf
+ (denv, "Binary blocks (count: %d)", count);
+
+ for ( i = 0; i < count; i++ ) {
+ struct sieve_binary_block *sblock = sieve_binary_block_get(sbin, i);
+
+ sieve_binary_dumpf(denv,
+ "%3d: size: %"PRIuSIZE_T" bytes\n", i,
+ sieve_binary_block_get_size(sblock));
+ }
+
+ /* Hexdump for each block */
+
+ for ( i = 0; i < count; i++ ) {
+ struct sieve_binary_block *sblock = sieve_binary_block_get(sbin, i);
+ buffer_t *blockbuf = sieve_binary_block_get_buffer(sblock);
+ string_t *line;
+ size_t data_size;
+ const char *data;
+ size_t offset;
+
+ data = (const char *) buffer_get_data(blockbuf, &data_size);
+
+ sieve_binary_dump_sectionf
+ (denv, "Block %d (%"PRIuSIZE_T" bytes, file offset %08llx)", i,
+ data_size, sblock->offset + 8 /* header size (yuck) */);
+
+ line = t_str_new(128);
+ offset = 0;
+ while ( offset < data_size ) {
+ size_t len = ( data_size - offset >= 16 ? 16 : data_size - offset );
+ size_t b;
+
+ str_printfa(line, "%08llx ", (unsigned long long) offset);
+
+ for ( b = 0; b < len; b++ ) {
+ str_printfa(line, "%02x ", (unsigned int) data[offset+b]);
+ if ( b == 7 ) str_append_c(line, ' ');
+ }
+
+ if ( len < 16 ) {
+ if ( len <= 7 ) str_append_c(line, ' ');
+
+ for ( b = len; b < 16; b++ ) {
+ str_append(line, " ");
+ }
+ }
+
+ str_append(line, " |");
+
+ for ( b = 0; b < len; b++ ) {
+ const char c = data[offset+b];
+
+ if ( c >= 32 && c <= 126 )
+ str_append_c(line, c);
+ else
+ str_append_c(line, '.');
+ }
+
+ str_append(line, "|\n");
+ o_stream_send(stream, str_data(line), str_len(line));
+ str_truncate(line, 0);
+ offset += len;
+ }
+
+ str_printfa(line, "%08llx\n", (unsigned long long) offset);
+ o_stream_send(stream, str_data(line), str_len(line));
+ }
+}
+
diff -r 33bc93bdde44 -r 1a7060ef63ce src/lib-sieve/sieve-binary-dumper.h
--- a/src/lib-sieve/sieve-binary-dumper.h Sun Sep 05 21:37:41 2010 +0200
+++ b/src/lib-sieve/sieve-binary-dumper.h Mon Sep 06 18:36:25 2010 +0200
@@ -36,5 +36,11 @@
bool sieve_binary_dumper_run
(struct sieve_binary_dumper *dumper, struct ostream *stream, bool verbose);
+/*
+ * Hexdump production
+ */
+
+void sieve_binary_dumper_hexdump
+(struct sieve_binary_dumper *dumper, struct ostream *stream);
#endif /* __SIEVE_BINARY_DUMPER_H */
diff -r 33bc93bdde44 -r 1a7060ef63ce src/lib-sieve/sieve-binary.h
--- a/src/lib-sieve/sieve-binary.h Sun Sep 05 21:37:41 2010 +0200
+++ b/src/lib-sieve/sieve-binary.h Mon Sep 06 18:36:25 2010 +0200
@@ -257,7 +257,6 @@
void sieve_binary_debug_reader_deinit
(struct sieve_binary_debug_reader **dreader);
-
void sieve_binary_debug_reader_reset
(struct sieve_binary_debug_reader *dreader);
diff -r 33bc93bdde44 -r 1a7060ef63ce src/lib-sieve/sieve.c
--- a/src/lib-sieve/sieve.c Sun Sep 05 21:37:41 2010 +0200
+++ b/src/lib-sieve/sieve.c Mon Sep 06 18:36:25 2010 +0200
@@ -397,7 +397,8 @@
* Debugging
*/
-void sieve_dump(struct sieve_binary *sbin, struct ostream *stream, bool verbose)
+void sieve_dump
+(struct sieve_binary *sbin, struct ostream *stream, bool verbose)
{
struct sieve_binary_dumper *dumpr = sieve_binary_dumper_create(sbin);
@@ -406,6 +407,16 @@
sieve_binary_dumper_free(&dumpr);
}
+void sieve_hexdump
+(struct sieve_binary *sbin, struct ostream *stream)
+{
+ struct sieve_binary_dumper *dumpr = sieve_binary_dumper_create(sbin);
+
+ sieve_binary_dumper_hexdump(dumpr, stream);
+
+ sieve_binary_dumper_free(&dumpr);
+}
+
int sieve_test
(struct sieve_binary *sbin, const struct sieve_message_data *msgdata,
const struct sieve_script_env *senv, struct sieve_error_handler *ehandler,
diff -r 33bc93bdde44 -r 1a7060ef63ce src/lib-sieve/sieve.h
--- a/src/lib-sieve/sieve.h Sun Sep 05 21:37:41 2010 +0200
+++ b/src/lib-sieve/sieve.h Mon Sep 06 18:36:25 2010 +0200
@@ -119,7 +119,16 @@
*
* Dumps the byte code in human-readable form to the specified ostream.
*/
-void sieve_dump(struct sieve_binary *sbin, struct ostream *stream, bool verbose);
+void sieve_dump
+ (struct sieve_binary *sbin, struct ostream *stream, bool verbose);
+
+/* sieve_hexdump:
+ *
+ * Dumps the byte code in hexdump form to the specified ostream.
+ */
+
+void sieve_hexdump
+ (struct sieve_binary *sbin, struct ostream *stream);
/* sieve_test:
*
diff -r 33bc93bdde44 -r 1a7060ef63ce src/sieve-tools/sieve-dump.c
--- a/src/sieve-tools/sieve-dump.c Sun Sep 05 21:37:41 2010 +0200
+++ b/src/sieve-tools/sieve-dump.c Mon Sep 06 18:36:25 2010 +0200
@@ -30,7 +30,7 @@
static void print_help(void)
{
printf(
-"Usage: sieve-dump [-P <plugin>] [-x <extensions>]\n"
+"Usage: sieve-dump [-h] [-P <plugin>] [-x <extensions>]\n"
" <sieve-binary> [<out-file>]\n"
);
}
@@ -44,16 +44,25 @@
struct sieve_instance *svinst;
struct sieve_binary *sbin;
const char *binfile, *outfile;
+ bool hexdump = FALSE;
int exit_status = EXIT_SUCCESS;
int c;
- sieve_tool = sieve_tool_init("sieve-dump", &argc, &argv, "P:x:", FALSE);
+ sieve_tool = sieve_tool_init("sieve-dump", &argc, &argv, "hP:x:", FALSE);
binfile = outfile = NULL;
- if ( (c = sieve_tool_getopt(sieve_tool)) > 0 ) {
- print_help();
- i_fatal_status(EX_USAGE, "Unknown argument: %c", c);
+ while ((c = sieve_tool_getopt(sieve_tool)) > 0) {
+ switch (c) {
+ case 'h':
+ /* produce hexdump */
+ hexdump = TRUE;
+ break;
+ default:
+ print_help();
+ i_fatal_status(EX_USAGE, "Unknown argument: %c", c);
+ break;
+ }
}
if ( optind < argc ) {
@@ -76,7 +85,7 @@
/* Dump binary */
sbin = sieve_load(svinst, binfile, NULL);
if ( sbin != NULL ) {
- sieve_tool_dump_binary_to(sbin, outfile == NULL ? "-" : outfile);
+ sieve_tool_dump_binary_to(sbin, outfile == NULL ? "-" : outfile, hexdump);
sieve_close(&sbin);
} else {
diff -r 33bc93bdde44 -r 1a7060ef63ce src/sieve-tools/sieve-test.c
--- a/src/sieve-tools/sieve-test.c Sun Sep 05 21:37:41 2010 +0200
+++ b/src/sieve-tools/sieve-test.c Mon Sep 06 18:36:25 2010 +0200
@@ -224,7 +224,7 @@
exit_status = EXIT_FAILURE;
} else {
/* Dump script */
- sieve_tool_dump_binary_to(main_sbin, dumpfile);
+ sieve_tool_dump_binary_to(main_sbin, dumpfile, FALSE);
More information about the dovecot-cvs
mailing list