dovecot-2.2: lib-fts: Implemented default create/destory functio...

dovecot at dovecot.org dovecot at dovecot.org
Tue Jun 2 22:07:16 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/6a710924df27
changeset: 18813:6a710924df27
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jun 03 00:43:28 2015 +0300
description:
lib-fts: Implemented default create/destory functions for fts-filters.

diffstat:

 src/lib-fts/fts-filter.c |  26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)

diffs (50 lines):

diff -r a13ce2bce9cd -r 6a710924df27 src/lib-fts/fts-filter.c
--- a/src/lib-fts/fts-filter.c	Wed Jun 03 00:39:11 2015 +0300
+++ b/src/lib-fts/fts-filter.c	Wed Jun 03 00:43:28 2015 +0300
@@ -2,6 +2,7 @@
 
 #include "lib.h"
 #include "array.h"
+#include "str.h"
 #include "fts-language.h"
 #include "fts-filter-private.h"
 
@@ -62,9 +63,19 @@
 	if (settings == NULL)
 		settings = &empty_settings;
 
-	if (filter_class->v->create(lang, settings, &fp, error_r) < 0) {
-		*filter_r = NULL;
-		return -1;
+	if (filter_class->v->create != NULL) {
+		if (filter_class->v->create(lang, settings, &fp, error_r) < 0) {
+			*filter_r = NULL;
+			return -1;
+		}
+	} else {
+		/* default implementation */
+		if (settings[0] != NULL) {
+			*error_r = t_strdup_printf("Unknown setting: %s", settings[0]);
+			return -1;
+		}
+		fp = i_new(struct fts_filter, 1);
+		*fp = *filter_class;
 	}
 	fp->refcount = 1;
 	fp->parent = parent;
@@ -93,7 +104,14 @@
 
 	if (fp->parent != NULL)
 		fts_filter_unref(&fp->parent);
-	fp->v->destroy(fp);
+	if (fp->v->destroy != NULL)
+		fp->v->destroy(fp);
+	else {
+		/* default destroy implementation */
+		if (fp->token != NULL)
+			str_free(&fp->token);
+		i_free(fp);
+	}
 }
 
 int fts_filter_filter(struct fts_filter *filter, const char **token,


More information about the dovecot-cvs mailing list