From a611b483cc81f0915a6fd28098e2eaaa863daf90 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Sun, 2 Aug 2009 15:26:33 +0200
Subject: [PATCH] Made proper API for loading a binary directly.

---
 src/lib-sieve/sieve.c    | 17 +++++++++++++++--
 src/lib-sieve/sieve.h    | 14 ++++++++++++--
 src/sieve-tools/sieved.c | 10 ++--------
 3 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/src/lib-sieve/sieve.c b/src/lib-sieve/sieve.c
index 8ce37650d..e174b405d 100644
--- a/src/lib-sieve/sieve.c
+++ b/src/lib-sieve/sieve.c
@@ -259,9 +259,22 @@ struct sieve_binary *sieve_open
 } 
 
 bool sieve_save
-    (struct sieve_binary *sbin, const char *path)
+(struct sieve_binary *sbin, const char *bin_path)
 {
-	return sieve_binary_save(sbin, path);
+	return sieve_binary_save(sbin, bin_path);
+}
+
+struct sieve_binary *sieve_load
+(const char *bin_path)
+{
+	struct sieve_binary *sbin = sieve_binary_open(bin_path, NULL);
+
+    if ( sbin != NULL && !sieve_binary_load(sbin) ) {
+        sieve_binary_unref(&sbin);
+        sbin = NULL;
+    }
+
+	return sbin;
 }
 
 void sieve_close(struct sieve_binary **sbin)
diff --git a/src/lib-sieve/sieve.h b/src/lib-sieve/sieve.h
index a8d09ed3f..5aa953d26 100644
--- a/src/lib-sieve/sieve.h
+++ b/src/lib-sieve/sieve.h
@@ -72,10 +72,20 @@ struct sieve_binary *sieve_open
 		struct sieve_error_handler *ehandler, bool *exists_r);
 
 /* sieve_save:
- *  Saves the binary as the file indicated by the path parameter.
+ *
+ *  Saves the binary as the file indicated by the path parameter. If 
+ *  path is NULL, it chooses the default path relative to the original
+ *  script.
  */
 bool sieve_save
-    (struct sieve_binary *sbin, const char *path);
+    (struct sieve_binary *sbin, const char *bin_path);
+
+/* sieve_load:
+ *
+ *  Loads the sieve binary indicated by the provided path.
+ */
+struct sieve_binary *sieve_load
+	(const char *bin_path);
 
 /* sieve_close:
  *
diff --git a/src/sieve-tools/sieved.c b/src/sieve-tools/sieved.c
index 6bb01788e..f687a9cdd 100644
--- a/src/sieve-tools/sieved.c
+++ b/src/sieve-tools/sieved.c
@@ -5,7 +5,6 @@
 
 #include "sieve.h"
 #include "sieve-extensions.h"
-#include "sieve-binary.h"
 #include "sieve-tool.h"
 
 #include "sieve-ext-debug.h"
@@ -72,17 +71,12 @@ int main(int argc, char **argv) {
 	/* Register tool-specific extensions */
 	(void) sieve_extension_register(&debug_extension, TRUE);
 		
-	sbin = sieve_binary_open(binfile, NULL);
-
-	if ( sbin != NULL && !sieve_binary_load(sbin) ) {
-		sieve_binary_unref(&sbin);
-		sbin = NULL;
-	}
+	sbin = sieve_load(binfile);
 
 	if ( sbin != NULL ) {
 		sieve_tool_dump_binary_to(sbin, outfile == NULL ? "-" : outfile);
 	
-		sieve_binary_unref(&sbin);
+		sieve_close(&sbin);
 	} else 
 		i_error("failed to load binary: %s", binfile);
 	
-- 
GitLab