Skip to content
Snippets Groups Projects
Commit 7b531076 authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Removed code duplication between testsuite and commandline tools. Also...

Removed code duplication between testsuite and commandline tools. Also restructured source code of the tools.
parent 501216f5
No related branches found
No related tags found
No related merge requests found
Showing
with 171 additions and 156 deletions
...@@ -56,7 +56,7 @@ Features ...@@ -56,7 +56,7 @@ Features
* Testsuite included: * Testsuite included:
This package includes a testsuite to automatically asses whether the compiled This package includes a testsuite to automatically asses whether the compiled
sieve engine works correctly. The testsuite is an extension to the Sieve sieve engine works correctly. The testsuite is an extension to the Sieve
language and is therefore easily extended with new tests. Currently, the language and is therefore easily extended with new tests. Currently, the
testsuite is limited to testing script processing. The performed actions are testsuite is limited to testing script processing. The performed actions are
...@@ -133,7 +133,7 @@ that no other files are written and no permission to do so is necessary for the ...@@ -133,7 +133,7 @@ that no other files are written and no permission to do so is necessary for the
global script directories. global script directories.
To test the sieve engine outside deliver it is useful to execute the binaries To test the sieve engine outside deliver it is useful to execute the binaries
that exist in the src/sieve-bin/ directory of this package. After installation, that exist in the src/sieve-tools/ directory of this package. After installation,
these scripts are available in the dovecot lib directory. The following commands these scripts are available in the dovecot lib directory. The following commands
are available: are available:
...@@ -176,7 +176,8 @@ Options: ...@@ -176,7 +176,8 @@ Options:
sieve-exec sieve-exec
Currently undocumented (will be merged with sieve-test). Currently undocumented (will evolve into sieve-filter which can process existing
mail stores).
-- --
......
Next (in order of descending priority/precedence): Next (in order of descending priority/precedence):
* Fix code duplication between command line tools and the testsuite.
* Fix remaining RFC deviations: * Fix remaining RFC deviations:
- Fix issues listed in doc/rfc/RFC-questions.txt when answers arrive - Fix issues listed in doc/rfc/RFC-questions.txt when answers arrive
- Allow for the existance of dynamic comparators (i.e. specified by - Allow for the existance of dynamic comparators (i.e. specified by
......
...@@ -86,10 +86,10 @@ src/lib-sieve/plugins/include/Makefile ...@@ -86,10 +86,10 @@ src/lib-sieve/plugins/include/Makefile
src/lib-sieve/plugins/body/Makefile src/lib-sieve/plugins/body/Makefile
src/lib-sieve/plugins/variables/Makefile src/lib-sieve/plugins/variables/Makefile
src/lib-sieve/plugins/enotify/Makefile src/lib-sieve/plugins/enotify/Makefile
src/lib-util/Makefile src/lib-sieve-tool/Makefile
src/plugins/Makefile src/plugins/Makefile
src/plugins/lda-sieve/Makefile src/plugins/lda-sieve/Makefile
src/sieve-bin/Makefile src/sieve-tools/Makefile
src/testsuite/Makefile src/testsuite/Makefile
stamp.h]) stamp.h])
......
SUBDIRS = lib-sieve lib-util sieve-bin plugins testsuite SUBDIRS = lib-sieve lib-sieve-tool sieve-tools plugins testsuite
noinst_LTLIBRARIES = libsieve-tool.la
AM_CPPFLAGS = \
-I$(top_srcdir)/src/lib-sieve \
-I$(dovecot_incdir) \
-I$(dovecot_incdir)/src/lib \
-I$(dovecot_incdir)/src/lib-mail \
-I$(dovecot_incdir)/src/lib-index \
-I$(dovecot_incdir)/src/lib-storage \
-I$(dovecot_incdir)/src/lib-storage/index \
-I$(dovecot_incdir)/src/lib-storage/index/raw
libsieve_tool_la_SOURCES = \
sieve-tool.c \
mail-raw.c
noinst_HEADERS = \
sieve-tool.h \
mail-raw.h
File moved
File moved
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "mail-storage.h" #include "mail-storage.h"
#include "sieve.h" #include "sieve.h"
#include "bin-common.h" #include "sieve-tool.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -17,25 +17,36 @@ ...@@ -17,25 +17,36 @@
#include <fcntl.h> #include <fcntl.h>
#include <pwd.h> #include <pwd.h>
/* Functionality common to all sieve test tools */ /*
* Global state
/* FIXME: this file is currently very messy */ */
static struct ioloop *ioloop; static struct ioloop *ioloop;
/*
* Signal handlers
*/
static void sig_die(int signo, void *context ATTR_UNUSED) static void sig_die(int signo, void *context ATTR_UNUSED)
{ {
/* warn about being killed because of some signal, except SIGINT (^C) /* Warn about being killed because of some signal, except SIGINT (^C)
which is too common at least while testing :) */ * which is too common at least while testing :)
*/
if (signo != SIGINT) if (signo != SIGINT)
i_warning("Killed with signal %d", signo); i_warning("killed with signal %d", signo);
// io_loop_stop(ioloop); We are not running an ioloop
io_loop_stop(ioloop);
exit(1); exit(1);
} }
void bin_init(void) /*
* Initialization
*/
void sieve_tool_init(void)
{ {
lib_init(); lib_init();
ioloop = io_loop_create(); ioloop = io_loop_create();
lib_signals_init(); lib_signals_init();
...@@ -45,10 +56,10 @@ void bin_init(void) ...@@ -45,10 +56,10 @@ void bin_init(void)
lib_signals_ignore(SIGALRM, FALSE); lib_signals_ignore(SIGALRM, FALSE);
if ( !sieve_init("") ) if ( !sieve_init("") )
i_fatal("Failed to initialize sieve implementation\n"); i_fatal("failed to initialize sieve implementation\n");
} }
void bin_deinit(void) void sieve_tool_deinit(void)
{ {
sieve_deinit(); sieve_deinit();
...@@ -58,7 +69,11 @@ void bin_deinit(void) ...@@ -58,7 +69,11 @@ void bin_deinit(void)
lib_deinit(); lib_deinit();
} }
const char *bin_get_user(void) /*
* Commonly needed functionality
*/
const char *sieve_tool_get_user(void)
{ {
uid_t process_euid = geteuid(); uid_t process_euid = geteuid();
struct passwd *pw = getpwuid(process_euid); struct passwd *pw = getpwuid(process_euid);
...@@ -66,11 +81,37 @@ const char *bin_get_user(void) ...@@ -66,11 +81,37 @@ const char *bin_get_user(void)
return t_strdup(pw->pw_name); return t_strdup(pw->pw_name);
} }
i_fatal("Couldn't lookup our username (uid=%s)", dec2str(process_euid)); i_fatal("couldn't lookup our username (uid=%s)", dec2str(process_euid));
return NULL; return NULL;
} }
struct sieve_binary *bin_compile_sieve_script(const char *filename) void sieve_tool_get_envelope_data
(struct mail *mail, const char **recipient, const char **sender)
{
/* Get recipient address */
if ( *recipient == NULL )
(void)mail_get_first_header(mail, "Envelope-To", recipient);
if ( *recipient == NULL )
(void)mail_get_first_header(mail, "To", recipient);
if ( *recipient == NULL )
*recipient = "recipient@example.com";
/* Get sender address */
if ( *sender == NULL )
(void)mail_get_first_header(mail, "Return-path", sender);
if ( *sender == NULL )
(void)mail_get_first_header(mail, "Sender", sender);
if ( *sender == NULL )
(void)mail_get_first_header(mail, "From", sender);
if ( *sender == NULL )
*sender = "sender@example.com";
}
/*
* Sieve script handling
*/
struct sieve_binary *sieve_tool_script_compile(const char *filename)
{ {
struct sieve_error_handler *ehandler; struct sieve_error_handler *ehandler;
struct sieve_binary *sbin; struct sieve_binary *sbin;
...@@ -80,7 +121,7 @@ struct sieve_binary *bin_compile_sieve_script(const char *filename) ...@@ -80,7 +121,7 @@ struct sieve_binary *bin_compile_sieve_script(const char *filename)
if ( (sbin = sieve_compile(filename, ehandler)) == NULL ) { if ( (sbin = sieve_compile(filename, ehandler)) == NULL ) {
sieve_error_handler_unref(&ehandler); sieve_error_handler_unref(&ehandler);
i_fatal("Failed to compile sieve script\n"); i_fatal("failed to compile sieve script\n");
} }
sieve_error_handler_unref(&ehandler); sieve_error_handler_unref(&ehandler);
...@@ -88,7 +129,7 @@ struct sieve_binary *bin_compile_sieve_script(const char *filename) ...@@ -88,7 +129,7 @@ struct sieve_binary *bin_compile_sieve_script(const char *filename)
return sbin; return sbin;
} }
struct sieve_binary *bin_open_sieve_script(const char *filename) struct sieve_binary *sieve_tool_script_open(const char *filename)
{ {
struct sieve_error_handler *ehandler; struct sieve_error_handler *ehandler;
struct sieve_binary *sbin; struct sieve_binary *sbin;
...@@ -106,7 +147,7 @@ struct sieve_binary *bin_open_sieve_script(const char *filename) ...@@ -106,7 +147,7 @@ struct sieve_binary *bin_open_sieve_script(const char *filename)
return sbin; return sbin;
} }
void bin_dump_sieve_binary_to(struct sieve_binary *sbin, const char *filename) void sieve_tool_dump_binary_to(struct sieve_binary *sbin, const char *filename)
{ {
int dfd = -1; int dfd = -1;
struct ostream *dumpstream; struct ostream *dumpstream;
...@@ -117,8 +158,7 @@ void bin_dump_sieve_binary_to(struct sieve_binary *sbin, const char *filename) ...@@ -117,8 +158,7 @@ void bin_dump_sieve_binary_to(struct sieve_binary *sbin, const char *filename)
dumpstream = o_stream_create_fd(1, 0, FALSE); dumpstream = o_stream_create_fd(1, 0, FALSE);
else { else {
if ( (dfd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0600)) < 0 ) { if ( (dfd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0600)) < 0 ) {
i_fatal("Failed to open dump-file for writing: %m"); i_fatal("failed to open dump-file for writing: %m");
exit(1);
} }
dumpstream = o_stream_create_fd(dfd, 0, FALSE); dumpstream = o_stream_create_fd(dfd, 0, FALSE);
...@@ -135,32 +175,3 @@ void bin_dump_sieve_binary_to(struct sieve_binary *sbin, const char *filename) ...@@ -135,32 +175,3 @@ void bin_dump_sieve_binary_to(struct sieve_binary *sbin, const char *filename)
close(dfd); close(dfd);
} }
void bin_close_mail_file(int mfd)
{
if ( mfd != 0 )
close(mfd);
}
void bin_fill_in_envelope
(struct mail *mail, const char **recipient, const char **sender)
{
/* Get recipient address */
if ( *recipient == NULL )
(void)mail_get_first_header(mail, "Envelope-To", recipient);
if ( *recipient == NULL )
(void)mail_get_first_header(mail, "To", recipient);
if ( *recipient == NULL )
*recipient = "recipient@example.com";
/* Get sender address */
if ( *sender == NULL )
(void)mail_get_first_header(mail, "Return-path", sender);
if ( *sender == NULL )
(void)mail_get_first_header(mail, "Sender", sender);
if ( *sender == NULL )
(void)mail_get_first_header(mail, "From", sender);
if ( *sender == NULL )
*sender = "sender@example.com";
}
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
#ifndef __SIEVE_TOOL_H
#define __SIEVE_TOOL_H
/* Functionality common to all Sieve command line tools. */
/*
* Initialization
*/
void sieve_tool_init(void);
void sieve_tool_deinit(void);
/*
* Commonly needed functionality
*/
const char *sieve_tool_get_user(void);
void sieve_tool_get_envelope_data
(struct mail *mail, const char **recipient, const char **sender);
/*
* Sieve script handling
*/
struct sieve_binary *sieve_tool_script_compile(const char *filename);
struct sieve_binary *sieve_tool_script_open(const char *filename);
void sieve_tool_dump_binary_to(struct sieve_binary *sbin, const char *filename);
#endif /* __SIEVE_TOOL_H */
noinst_LTLIBRARIES = libutil.la
AM_CPPFLAGS = \
-I$(dovecot_incdir) \
-I$(dovecot_incdir)/src/lib \
-I$(dovecot_incdir)/src/lib-mail \
-I$(dovecot_incdir)/src/lib-index \
-I$(dovecot_incdir)/src/lib-storage \
-I$(dovecot_incdir)/src/lib-storage/index \
-I$(dovecot_incdir)/src/lib-storage/index/raw \
-I$(dovecot_incdir)/src/lib-storage/index/mbox \
-I$(dovecot_incdir)/src/lib-storage/index/maildir
libutil_la_SOURCES = \
mail-raw.c
noinst_HEADERS = \
mail-raw.h
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
#ifndef __BIN_COMMON_H
#define __BIN_COMMON_H
#include "sieve.h"
/* Functionality common to all sieve test tools */
void bin_init(void);
void bin_deinit(void);
const char *bin_get_user(void);
struct sieve_binary *bin_compile_sieve_script(const char *filename);
struct sieve_binary *bin_open_sieve_script(const char *filename);
void bin_dump_sieve_binary_to(struct sieve_binary *sbin, const char *filename);
int bin_open_mail_file(const char *filename);
void bin_close_mail_file(int mfd);
void bin_fill_in_envelope
(struct mail *mail, const char **recipient, const char **sender);
#endif /* __BIN_COMMON_H */
...@@ -4,7 +4,7 @@ bin_PROGRAMS = sievec sieved sieve-test sieve-exec ...@@ -4,7 +4,7 @@ bin_PROGRAMS = sievec sieved sieve-test sieve-exec
AM_CPPFLAGS = \ AM_CPPFLAGS = \
-I$(top_srcdir)/src/lib-sieve \ -I$(top_srcdir)/src/lib-sieve \
-I$(top_srcdir)/src/lib-util \ -I$(top_srcdir)/src/lib-sieve-tool \
-I$(dovecot_incdir) \ -I$(dovecot_incdir) \
-I$(dovecot_incdir)/src/lib \ -I$(dovecot_incdir)/src/lib \
-I$(dovecot_incdir)/src/lib-mail \ -I$(dovecot_incdir)/src/lib-mail \
...@@ -19,10 +19,10 @@ sieve_exec_LDFLAGS = -export-dynamic -Wl,--start-group ...@@ -19,10 +19,10 @@ sieve_exec_LDFLAGS = -export-dynamic -Wl,--start-group
libs = \ libs = \
$(top_srcdir)/src/lib-sieve/libsieve.la \ $(top_srcdir)/src/lib-sieve/libsieve.la \
$(top_srcdir)/src/lib-util/libutil.la \ $(top_srcdir)/src/lib-sieve-tool/libsieve-tool.la \
$(dovecot_incdir)/src/lib-storage/list/libstorage_list.a \ $(dovecot_incdir)/src/lib-storage/list/libstorage_list.a \
$(dovecot_incdir)/src/lib-storage/register/libstorage-register.a \ $(dovecot_incdir)/src/lib-storage/register/libstorage-register.a \
$(STORAGE_LIBS) \ $(STORAGE_LIBS) \
$(dovecot_incdir)/src/lib-storage/libstorage.a \ $(dovecot_incdir)/src/lib-storage/libstorage.a \
$(dovecot_incdir)/src/lib-index/libindex.a \ $(dovecot_incdir)/src/lib-index/libindex.a \
$(dovecot_incdir)/src/lib-imap/libimap.a \ $(dovecot_incdir)/src/lib-imap/libimap.a \
...@@ -46,24 +46,16 @@ sieved_DEPENDENCIES = $(libs) ...@@ -46,24 +46,16 @@ sieved_DEPENDENCIES = $(libs)
sieve_test_DEPENDENCIES = $(libs) sieve_test_DEPENDENCIES = $(libs)
sieve_exec_DEPENDENCIES = $(libs) sieve_exec_DEPENDENCIES = $(libs)
common_sources = \
bin-common.c
sievec_SOURCES = \ sievec_SOURCES = \
$(common_sources) \
sievec.c sievec.c
sieved_SOURCES = \ sieved_SOURCES = \
$(common_sources) \
sieved.c sieved.c
sieve_test_SOURCES = \ sieve_test_SOURCES = \
$(common_sources) \
sieve-test.c sieve-test.c
sieve_exec_SOURCES = \ sieve_exec_SOURCES = \
$(common_sources) \
sieve-exec.c sieve-exec.c
noinst_HEADERS = \ noinst_HEADERS =
bin-common.h
File added
...@@ -7,11 +7,12 @@ ...@@ -7,11 +7,12 @@
#include "mail-namespace.h" #include "mail-namespace.h"
#include "env-util.h" #include "env-util.h"
#include "bin-common.h"
#include "mail-raw.h"
#include "sieve.h" #include "sieve.h"
#include "sieve-binary.h" #include "sieve-binary.h"
#include "mail-raw.h"
#include "sieve-tool.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
...@@ -94,8 +95,6 @@ int main(int argc, char **argv) ...@@ -94,8 +95,6 @@ int main(int argc, char **argv)
struct sieve_exec_status estatus; struct sieve_exec_status estatus;
struct sieve_error_handler *ehandler; struct sieve_error_handler *ehandler;
bin_init();
/* Parse arguments */ /* Parse arguments */
scriptfile = recipient = sender = mailbox = dumpfile = mailfile = NULL; scriptfile = recipient = sender = mailbox = dumpfile = mailfile = NULL;
mailloc = NULL; mailloc = NULL;
...@@ -150,13 +149,15 @@ int main(int argc, char **argv) ...@@ -150,13 +149,15 @@ int main(int argc, char **argv)
i_fatal("Missing <mailfile> argument"); i_fatal("Missing <mailfile> argument");
} }
sieve_tool_init();
/* Compile sieve script */ /* Compile sieve script */
sbin = bin_open_sieve_script(scriptfile); sbin = sieve_tool_script_open(scriptfile);
/* Dump script */ /* Dump script */
bin_dump_sieve_binary_to(sbin, dumpfile); sieve_tool_dump_binary_to(sbin, dumpfile);
user = bin_get_user(); user = sieve_tool_get_user();
home = getenv("HOME"); home = getenv("HOME");
/* Initialize mail storages */ /* Initialize mail storages */
...@@ -183,7 +184,7 @@ int main(int argc, char **argv) ...@@ -183,7 +184,7 @@ int main(int argc, char **argv)
mail_raw_init(user); mail_raw_init(user);
mailr = mail_raw_open_file(mailfile); mailr = mail_raw_open_file(mailfile);
bin_fill_in_envelope(mailr->mail, &recipient, &sender); sieve_tool_get_envelope_data(mailr->mail, &recipient, &sender);
if ( mailbox == NULL ) if ( mailbox == NULL )
mailbox = "INBOX"; mailbox = "INBOX";
...@@ -213,19 +214,19 @@ int main(int argc, char **argv) ...@@ -213,19 +214,19 @@ int main(int argc, char **argv)
/* Run */ /* Run */
switch ( sieve_execute(sbin, &msgdata, &scriptenv, &estatus, ehandler, NULL) ) { switch ( sieve_execute(sbin, &msgdata, &scriptenv, &estatus, ehandler, NULL) ) {
case SIEVE_EXEC_OK: case SIEVE_EXEC_OK:
i_info("Final result: success"); i_info("final result: success");
break; break;
case SIEVE_EXEC_FAILURE: case SIEVE_EXEC_FAILURE:
i_info("Final result: failed; resolved with successful implicit keep"); i_info("final result: failed; resolved with successful implicit keep");
break; break;
case SIEVE_EXEC_BIN_CORRUPT: case SIEVE_EXEC_BIN_CORRUPT:
i_info("Corrupt binary deleted."); i_info("corrupt binary deleted.");
(void) unlink(sieve_binary_path(sbin)); (void) unlink(sieve_binary_path(sbin));
case SIEVE_EXEC_KEEP_FAILED: case SIEVE_EXEC_KEEP_FAILED:
i_info("Final result: utter failure (caller please handle implicit keep!)"); i_info("final result: utter failure (caller please handle implicit keep!)");
break; break;
default: default:
i_info("Final result: unrecognized return value?!"); i_info("final result: unrecognized return value?!");
} }
sieve_close(&sbin); sieve_close(&sbin);
...@@ -242,7 +243,8 @@ int main(int argc, char **argv) ...@@ -242,7 +243,8 @@ int main(int argc, char **argv)
/* De-intialize mail storages */ /* De-intialize mail storages */
mail_storage_deinit(); mail_storage_deinit();
bin_deinit(); sieve_tool_deinit();
return 0; return 0;
} }
File added
...@@ -5,11 +5,12 @@ ...@@ -5,11 +5,12 @@
#include "ostream.h" #include "ostream.h"
#include "mail-storage.h" #include "mail-storage.h"
#include "bin-common.h"
#include "mail-raw.h"
#include "sieve.h" #include "sieve.h"
#include "sieve-binary.h" #include "sieve-binary.h"
#include "mail-raw.h"
#include "sieve-tool.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
...@@ -62,8 +63,6 @@ int main(int argc, char **argv) ...@@ -62,8 +63,6 @@ int main(int argc, char **argv)
bool trace = FALSE; bool trace = FALSE;
struct ostream *trace_stream = FALSE; struct ostream *trace_stream = FALSE;
bin_init();
/* Parse arguments */ /* Parse arguments */
scriptfile = recipient = sender = mailbox = dumpfile = mailfile = NULL; scriptfile = recipient = sender = mailbox = dumpfile = mailfile = NULL;
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
...@@ -118,19 +117,21 @@ int main(int argc, char **argv) ...@@ -118,19 +117,21 @@ int main(int argc, char **argv)
print_help(); print_help();
i_fatal("Missing <mailfile> argument"); i_fatal("Missing <mailfile> argument");
} }
sieve_tool_init();
/* Compile sieve script */ /* Compile sieve script */
if ( force_compile ) { if ( force_compile ) {
sbin = bin_compile_sieve_script(scriptfile); sbin = sieve_tool_script_compile(scriptfile);
(void) sieve_save(sbin, NULL); (void) sieve_save(sbin, NULL);
} else { } else {
sbin = bin_open_sieve_script(scriptfile); sbin = sieve_tool_script_open(scriptfile);
} }
/* Dump script */ /* Dump script */
bin_dump_sieve_binary_to(sbin, dumpfile); sieve_tool_dump_binary_to(sbin, dumpfile);
user = bin_get_user(); user = sieve_tool_get_user();
/* Initialize mail storages */ /* Initialize mail storages */
mail_storage_init(); mail_storage_init();
...@@ -141,7 +142,7 @@ int main(int argc, char **argv) ...@@ -141,7 +142,7 @@ int main(int argc, char **argv)
mail_raw_init(user); mail_raw_init(user);
mailr = mail_raw_open_file(mailfile); mailr = mail_raw_open_file(mailfile);
bin_fill_in_envelope(mailr->mail, &recipient, &sender); sieve_tool_get_envelope_data(mailr->mail, &recipient, &sender);
if ( mailbox == NULL ) if ( mailbox == NULL )
mailbox = "INBOX"; mailbox = "INBOX";
...@@ -188,6 +189,6 @@ int main(int argc, char **argv) ...@@ -188,6 +189,6 @@ int main(int argc, char **argv)
/* De-initialize mail storages */ /* De-initialize mail storages */
mail_storage_deinit(); mail_storage_deinit();
bin_deinit(); sieve_tool_deinit();
return 0; return 0;
} }
File added
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file /* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/ */
#include "lib.h"
#include "sieve.h"
#include "sieve-tool.h"
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -9,14 +14,10 @@ ...@@ -9,14 +14,10 @@
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include "lib.h"
#include "sieve.h"
#include "bin-common.h"
/* /*
* Print help * Print help
*/ */
static void print_help(void) static void print_help(void)
{ {
printf( printf(
...@@ -34,7 +35,7 @@ int main(int argc, char **argv) { ...@@ -34,7 +35,7 @@ int main(int argc, char **argv) {
bool dump = FALSE; bool dump = FALSE;
const char *scriptfile, *outfile; const char *scriptfile, *outfile;
bin_init(); sieve_tool_init();
scriptfile = outfile = NULL; scriptfile = outfile = NULL;
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
...@@ -61,11 +62,11 @@ int main(int argc, char **argv) { ...@@ -61,11 +62,11 @@ int main(int argc, char **argv) {
i_fatal("Missing <outfile> argument"); i_fatal("Missing <outfile> argument");
} }
sbin = bin_compile_sieve_script(scriptfile); sbin = sieve_tool_script_compile(scriptfile);
if ( sbin != NULL ) { if ( sbin != NULL ) {
if ( dump ) if ( dump )
bin_dump_sieve_binary_to(sbin, outfile); sieve_tool_dump_binary_to(sbin, outfile);
else { else {
sieve_save(sbin, outfile); sieve_save(sbin, outfile);
} }
...@@ -73,5 +74,5 @@ int main(int argc, char **argv) { ...@@ -73,5 +74,5 @@ int main(int argc, char **argv) {
sieve_close(&sbin); sieve_close(&sbin);
} }
bin_deinit(); sieve_tool_deinit();
} }
File added
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file /* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/ */
#include "lib.h"
#include "sieve.h"
#include "sieve-binary.h"
#include "sieve-tool.h"
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -9,12 +15,6 @@ ...@@ -9,12 +15,6 @@
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include "lib.h"
#include "sieve.h"
#include "sieve-binary.h"
#include "bin-common.h"
/* /*
* Print help * Print help
*/ */
...@@ -43,16 +43,16 @@ int main(int argc, char **argv) { ...@@ -43,16 +43,16 @@ int main(int argc, char **argv) {
outfile = argv[i]; outfile = argv[i];
} else { } else {
print_help(); print_help();
i_fatal("Unknown argument: %s", argv[i]); i_fatal("unknown argument: %s", argv[i]);
} }
} }
if ( binfile == NULL ) { if ( binfile == NULL ) {
print_help(); print_help();
i_fatal("Missing <binfile> argument"); i_fatal("missing <binfile> argument");
} }
bin_init(); sieve_tool_init();
sbin = sieve_binary_open(binfile, NULL); sbin = sieve_binary_open(binfile, NULL);
...@@ -62,12 +62,12 @@ int main(int argc, char **argv) { ...@@ -62,12 +62,12 @@ int main(int argc, char **argv) {
} }
if ( sbin != NULL ) { if ( sbin != NULL ) {
bin_dump_sieve_binary_to(sbin, outfile == NULL ? "-" : outfile); sieve_tool_dump_binary_to(sbin, outfile == NULL ? "-" : outfile);
sieve_binary_unref(&sbin); sieve_binary_unref(&sbin);
} else } else
i_error("Failed to load binary: %s", binfile); i_error("failed to load binary: %s", binfile);
bin_deinit(); sieve_tool_deinit();
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.