From 823d2903b229518574f91146ffe15939796d5b70 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Fri, 8 Jan 2016 20:49:39 +0100
Subject: [PATCH] lib-sieve: Cleaned up object definitions using newer C99
 syntax.

---
 src/lib-sieve/cmp-i-ascii-casemap.c             | 17 ++++++++++-------
 src/lib-sieve/cmp-i-octet.c                     | 16 ++++++++++------
 src/lib-sieve/mcht-contains.c                   | 10 ++++------
 src/lib-sieve/mcht-is.c                         |  7 +++----
 src/lib-sieve/mcht-matches.c                    | 10 ++++------
 .../ext-cmp-i-ascii-numeric.c                   | 11 ++++++-----
 src/lib-sieve/plugins/copy/ext-copy.c           |  9 +++------
 .../plugins/include/ext-include-variables.c     |  9 ++++-----
 .../plugins/mailbox/tag-mailbox-create.c        |  8 +++-----
 src/lib-sieve/plugins/regex/mcht-regex.c        | 11 ++++-------
 src/lib-sieve/plugins/relational/mcht-count.c   | 14 ++++++--------
 src/lib-sieve/plugins/relational/mcht-value.c   | 14 ++++++--------
 .../plugins/subaddress/ext-subaddress.c         |  8 +++++---
 .../environment/ext-vnd-environment-variables.c |  8 ++++----
 src/lib-sieve/sieve-address-parts.c             | 15 +++++++++------
 src/lib-sieve/sieve-objects.h                   |  8 ++++++--
 src/testsuite/testsuite-objects.c               | 17 ++++++++---------
 src/testsuite/testsuite-substitutions.c         | 13 ++++++-------
 18 files changed, 101 insertions(+), 104 deletions(-)

diff --git a/src/lib-sieve/cmp-i-ascii-casemap.c b/src/lib-sieve/cmp-i-ascii-casemap.c
index 6daddf50b..ad25e0f22 100644
--- a/src/lib-sieve/cmp-i-ascii-casemap.c
+++ b/src/lib-sieve/cmp-i-ascii-casemap.c
@@ -30,13 +30,16 @@ static bool cmp_i_ascii_casemap_char_match
  */
 
 const struct sieve_comparator_def i_ascii_casemap_comparator = {
-	SIEVE_OBJECT
-		("i;ascii-casemap", &comparator_operand, SIEVE_COMPARATOR_I_ASCII_CASEMAP),
-	SIEVE_COMPARATOR_FLAG_ORDERING | SIEVE_COMPARATOR_FLAG_EQUALITY |
-		SIEVE_COMPARATOR_FLAG_SUBSTRING_MATCH | SIEVE_COMPARATOR_FLAG_PREFIX_MATCH,
-	cmp_i_ascii_casemap_compare,
-	cmp_i_ascii_casemap_char_match,
-	sieve_comparator_octet_skip
+	SIEVE_OBJECT("i;ascii-casemap",
+		&comparator_operand, SIEVE_COMPARATOR_I_ASCII_CASEMAP),
+	.flags =
+		SIEVE_COMPARATOR_FLAG_ORDERING |
+		SIEVE_COMPARATOR_FLAG_EQUALITY |
+		SIEVE_COMPARATOR_FLAG_SUBSTRING_MATCH |
+		SIEVE_COMPARATOR_FLAG_PREFIX_MATCH,
+	.compare = cmp_i_ascii_casemap_compare,
+	.char_match = cmp_i_ascii_casemap_char_match,
+	.char_skip = sieve_comparator_octet_skip
 };
 
 /*
diff --git a/src/lib-sieve/cmp-i-octet.c b/src/lib-sieve/cmp-i-octet.c
index bbddcc1ec..6c267e2d4 100644
--- a/src/lib-sieve/cmp-i-octet.c
+++ b/src/lib-sieve/cmp-i-octet.c
@@ -29,12 +29,16 @@ static bool cmp_i_octet_char_match
  */
 
 const struct sieve_comparator_def i_octet_comparator = {
-	SIEVE_OBJECT("i;octet",	&comparator_operand, SIEVE_COMPARATOR_I_OCTET),
-	SIEVE_COMPARATOR_FLAG_ORDERING | SIEVE_COMPARATOR_FLAG_EQUALITY |
-		SIEVE_COMPARATOR_FLAG_SUBSTRING_MATCH | SIEVE_COMPARATOR_FLAG_PREFIX_MATCH,
-	cmp_i_octet_compare,
-	cmp_i_octet_char_match,
-	sieve_comparator_octet_skip
+	SIEVE_OBJECT("i;octet",
+		&comparator_operand, SIEVE_COMPARATOR_I_OCTET),
+	.flags =
+		SIEVE_COMPARATOR_FLAG_ORDERING |
+		SIEVE_COMPARATOR_FLAG_EQUALITY |
+		SIEVE_COMPARATOR_FLAG_SUBSTRING_MATCH |
+		SIEVE_COMPARATOR_FLAG_PREFIX_MATCH,
+	.compare = cmp_i_octet_compare,
+	.char_match = cmp_i_octet_char_match,
+	.char_skip = sieve_comparator_octet_skip
 };
 
 /*
diff --git a/src/lib-sieve/mcht-contains.c b/src/lib-sieve/mcht-contains.c
index f07bba180..d68e44097 100644
--- a/src/lib-sieve/mcht-contains.c
+++ b/src/lib-sieve/mcht-contains.c
@@ -26,12 +26,10 @@ static int mcht_contains_match_key
  */
 
 const struct sieve_match_type_def contains_match_type = {
-	SIEVE_OBJECT("contains", &match_type_operand,	SIEVE_MATCH_TYPE_CONTAINS),
-	NULL,
-	sieve_match_substring_validate_context,
-	NULL, NULL, NULL,
-	mcht_contains_match_key,
-	NULL
+	SIEVE_OBJECT("contains",
+		&match_type_operand, SIEVE_MATCH_TYPE_CONTAINS),
+	.validate_context = sieve_match_substring_validate_context,
+	.match_key = mcht_contains_match_key
 };
 
 /*
diff --git a/src/lib-sieve/mcht-is.c b/src/lib-sieve/mcht-is.c
index 0ead3a66e..a637790b8 100644
--- a/src/lib-sieve/mcht-is.c
+++ b/src/lib-sieve/mcht-is.c
@@ -26,10 +26,9 @@ static int mcht_is_match_key
  */
 
 const struct sieve_match_type_def is_match_type = {
-	SIEVE_OBJECT("is", &match_type_operand, SIEVE_MATCH_TYPE_IS),
-	NULL, NULL, NULL, NULL, NULL,
-	mcht_is_match_key,
-	NULL
+	SIEVE_OBJECT("is",
+		&match_type_operand, SIEVE_MATCH_TYPE_IS),
+	.match_key = mcht_is_match_key
 };
 
 /*
diff --git a/src/lib-sieve/mcht-matches.c b/src/lib-sieve/mcht-matches.c
index b1d6ec041..02ce2a833 100644
--- a/src/lib-sieve/mcht-matches.c
+++ b/src/lib-sieve/mcht-matches.c
@@ -27,12 +27,10 @@ static int mcht_matches_match_key
  */
 
 const struct sieve_match_type_def matches_match_type = {
-	SIEVE_OBJECT("matches", &match_type_operand, SIEVE_MATCH_TYPE_MATCHES),
-	NULL,
-	sieve_match_substring_validate_context,
-	NULL, NULL, NULL,
-	mcht_matches_match_key,
-	NULL
+	SIEVE_OBJECT("matches",
+		&match_type_operand, SIEVE_MATCH_TYPE_MATCHES),
+	.validate_context = sieve_match_substring_validate_context,
+	.match_key = mcht_matches_match_key
 };
 
 /*
diff --git a/src/lib-sieve/plugins/comparator-i-ascii-numeric/ext-cmp-i-ascii-numeric.c b/src/lib-sieve/plugins/comparator-i-ascii-numeric/ext-cmp-i-ascii-numeric.c
index 0eb91bf39..2393f750e 100644
--- a/src/lib-sieve/plugins/comparator-i-ascii-numeric/ext-cmp-i-ascii-numeric.c
+++ b/src/lib-sieve/plugins/comparator-i-ascii-numeric/ext-cmp-i-ascii-numeric.c
@@ -77,11 +77,12 @@ static int cmp_i_ascii_numeric_compare
 /* Comparator object */
 
 const struct sieve_comparator_def i_ascii_numeric_comparator = {
-	SIEVE_OBJECT("i;ascii-numeric", &my_comparator_operand, 0),
-	SIEVE_COMPARATOR_FLAG_ORDERING | SIEVE_COMPARATOR_FLAG_EQUALITY,
-	cmp_i_ascii_numeric_compare,
-	NULL,
-	NULL
+	SIEVE_OBJECT("i;ascii-numeric",
+		&my_comparator_operand, 0),
+	.flags =
+		SIEVE_COMPARATOR_FLAG_ORDERING |
+		SIEVE_COMPARATOR_FLAG_EQUALITY,
+	.compare = cmp_i_ascii_numeric_compare
 };
 
 /* Comparator implementation */
diff --git a/src/lib-sieve/plugins/copy/ext-copy.c b/src/lib-sieve/plugins/copy/ext-copy.c
index 3ab85b0e2..49a5186c7 100644
--- a/src/lib-sieve/plugins/copy/ext-copy.c
+++ b/src/lib-sieve/plugins/copy/ext-copy.c
@@ -72,12 +72,9 @@ static void seff_copy_post_commit
 
 const struct sieve_side_effect_def copy_side_effect = {
 	SIEVE_OBJECT("copy", &copy_side_effect_operand, 0),
-	&act_store,
-	NULL, NULL, NULL,
-	seff_copy_print,
-	NULL, NULL,
-	seff_copy_post_commit,
-	NULL
+	.to_action = &act_store,
+	.print = seff_copy_print,
+	.post_commit = seff_copy_post_commit
 };
 
 /*
diff --git a/src/lib-sieve/plugins/include/ext-include-variables.c b/src/lib-sieve/plugins/include/ext-include-variables.c
index 00b10dae7..cadd378dc 100644
--- a/src/lib-sieve/plugins/include/ext-include-variables.c
+++ b/src/lib-sieve/plugins/include/ext-include-variables.c
@@ -160,14 +160,13 @@ bool vnspc_global_variables_generate
 		const struct sieve_variables_namespace *nspc,
 		struct sieve_ast_argument *arg, struct sieve_command *cmd, void *var_data);
 
-static const struct sieve_variables_namespace_def global_variables_namespace = {
+static const struct sieve_variables_namespace_def
+global_variables_namespace = {
 	SIEVE_OBJECT("global", NULL, 0),
-	vnspc_global_variables_validate,
-	vnspc_global_variables_generate,
-	NULL, NULL
+	.validate = vnspc_global_variables_validate,
+	.generate = vnspc_global_variables_generate
 };
 
-
 bool vnspc_global_variables_validate
 (struct sieve_validator *valdtr,
 	const struct sieve_variables_namespace *nspc, struct sieve_ast_argument *arg,
diff --git a/src/lib-sieve/plugins/mailbox/tag-mailbox-create.c b/src/lib-sieve/plugins/mailbox/tag-mailbox-create.c
index bb0406dfa..cea99cdd1 100644
--- a/src/lib-sieve/plugins/mailbox/tag-mailbox-create.c
+++ b/src/lib-sieve/plugins/mailbox/tag-mailbox-create.c
@@ -46,11 +46,9 @@ static int seff_mailbox_create_pre_execute
 
 const struct sieve_side_effect_def mailbox_create_side_effect = {
 	SIEVE_OBJECT("create", &mailbox_create_operand, 0),
-	&act_store,
-	NULL, NULL, NULL,
-	seff_mailbox_create_print,
-	seff_mailbox_create_pre_execute,
-	NULL, NULL, NULL
+	.to_action = &act_store,
+	.print = seff_mailbox_create_print,
+	.pre_execute = seff_mailbox_create_pre_execute
 };
 
 /*
diff --git a/src/lib-sieve/plugins/regex/mcht-regex.c b/src/lib-sieve/plugins/regex/mcht-regex.c
index afca7a303..82a3011b0 100644
--- a/src/lib-sieve/plugins/regex/mcht-regex.c
+++ b/src/lib-sieve/plugins/regex/mcht-regex.c
@@ -50,13 +50,10 @@ static void mcht_regex_match_deinit(struct sieve_match_context *mctx);
 
 const struct sieve_match_type_def regex_match_type = {
 	SIEVE_OBJECT("regex", &regex_match_type_operand, 0),
-	NULL,
-	mcht_regex_validate_context,
-	NULL,
-	mcht_regex_match_init,
-	mcht_regex_match_keys,
-	NULL,
-	mcht_regex_match_deinit
+	.validate_context = mcht_regex_validate_context,
+	.match_init = mcht_regex_match_init,
+	.match_keys = mcht_regex_match_keys,
+	.match_deinit = mcht_regex_match_deinit
 };
 
 /*
diff --git a/src/lib-sieve/plugins/relational/mcht-count.c b/src/lib-sieve/plugins/relational/mcht-count.c
index 3554aefe9..b35f3fd84 100644
--- a/src/lib-sieve/plugins/relational/mcht-count.c
+++ b/src/lib-sieve/plugins/relational/mcht-count.c
@@ -37,19 +37,17 @@ static int mcht_count_match
  */
 
 const struct sieve_match_type_def count_match_type = {
-	SIEVE_OBJECT("count", &rel_match_type_operand, RELATIONAL_COUNT),
-	mcht_relational_validate,
-	NULL, NULL, NULL, NULL, NULL, NULL
+	SIEVE_OBJECT("count",
+		&rel_match_type_operand, RELATIONAL_COUNT),
+	.validate = mcht_relational_validate
 };
 
 #define COUNT_MATCH_TYPE(name, rel_match)                      \
 const struct sieve_match_type_def rel_match_count_ ## name = { \
-	SIEVE_OBJECT(                                                \
-		"count-" #name, &rel_match_type_operand,                   \
+	SIEVE_OBJECT("count-" #name,                                 \
+    &rel_match_type_operand,                                   \
 		REL_MATCH_INDEX(RELATIONAL_COUNT, rel_match)),             \
-	NULL, NULL,                                                  \
-	mcht_count_match,                                            \
-	NULL, NULL, NULL, NULL                                       \
+	.match = mcht_count_match,                                   \
 }
 
 COUNT_MATCH_TYPE(gt, REL_MATCH_GREATER);
diff --git a/src/lib-sieve/plugins/relational/mcht-value.c b/src/lib-sieve/plugins/relational/mcht-value.c
index 5ecf79eca..e89e6d3fe 100644
--- a/src/lib-sieve/plugins/relational/mcht-value.c
+++ b/src/lib-sieve/plugins/relational/mcht-value.c
@@ -24,19 +24,17 @@
  */
 
 const struct sieve_match_type_def value_match_type = {
-	SIEVE_OBJECT("value", &rel_match_type_operand, RELATIONAL_VALUE),
-	mcht_relational_validate,
-	NULL, NULL, NULL, NULL, NULL, NULL
+	SIEVE_OBJECT("value",
+		&rel_match_type_operand, RELATIONAL_VALUE),
+	.validate = mcht_relational_validate
 };
 
 #define VALUE_MATCH_TYPE(name, rel_match)                       \
 const struct sieve_match_type_def rel_match_value_ ## name = {  \
-	SIEVE_OBJECT(                                                 \
-		"value-" #name, &rel_match_type_operand,                    \
+	SIEVE_OBJECT("value-" #name,                                  \
+		&rel_match_type_operand,                                    \
 		REL_MATCH_INDEX(RELATIONAL_VALUE, rel_match)),              \
-	NULL, NULL, NULL, NULL, NULL,                                 \
-	mcht_value_match_key,                                         \
-	NULL                                                          \
+	.match_key = mcht_value_match_key,                            \
 }
 
 VALUE_MATCH_TYPE(gt, REL_MATCH_GREATER);
diff --git a/src/lib-sieve/plugins/subaddress/ext-subaddress.c b/src/lib-sieve/plugins/subaddress/ext-subaddress.c
index 2b73e4d10..c0e4a1ad5 100644
--- a/src/lib-sieve/plugins/subaddress/ext-subaddress.c
+++ b/src/lib-sieve/plugins/subaddress/ext-subaddress.c
@@ -124,13 +124,15 @@ static const char *subaddress_detail_extract_from
 /* Address part objects */
 
 const struct sieve_address_part_def user_address_part = {
-	SIEVE_OBJECT("user", &subaddress_operand, SUBADDRESS_USER),
+	SIEVE_OBJECT("user",
+		&subaddress_operand, SUBADDRESS_USER),
 	subaddress_user_extract_from
 };
 
 const struct sieve_address_part_def detail_address_part = {
-	SIEVE_OBJECT("detail", &subaddress_operand, SUBADDRESS_DETAIL),
-	subaddress_detail_extract_from
+	SIEVE_OBJECT("detail",
+		&subaddress_operand, SUBADDRESS_DETAIL),
+	.extract_from = subaddress_detail_extract_from
 };
 
 /* Address part implementation */
diff --git a/src/lib-sieve/plugins/vnd.dovecot/environment/ext-vnd-environment-variables.c b/src/lib-sieve/plugins/vnd.dovecot/environment/ext-vnd-environment-variables.c
index 5a32ae128..3ebba7cda 100644
--- a/src/lib-sieve/plugins/vnd.dovecot/environment/ext-vnd-environment-variables.c
+++ b/src/lib-sieve/plugins/vnd.dovecot/environment/ext-vnd-environment-variables.c
@@ -42,10 +42,10 @@ static int vnspc_vnd_environment_read_variable
 static const struct sieve_variables_namespace_def
 environment_namespace = {
 	SIEVE_OBJECT("env", &environment_namespace_operand, 0),
-	vnspc_vnd_environment_validate,
-	vnspc_vnd_environment_generate,
-	vnspc_vnd_environment_dump_variable,
-	vnspc_vnd_environment_read_variable
+	.validate = vnspc_vnd_environment_validate,
+	.generate = vnspc_vnd_environment_generate,
+	.dump_variable = vnspc_vnd_environment_dump_variable,
+	.read_variable = vnspc_vnd_environment_read_variable
 };
 
 static bool vnspc_vnd_environment_validate
diff --git a/src/lib-sieve/sieve-address-parts.c b/src/lib-sieve/sieve-address-parts.c
index 357d5e79a..ef904ae9f 100644
--- a/src/lib-sieve/sieve-address-parts.c
+++ b/src/lib-sieve/sieve-address-parts.c
@@ -485,17 +485,20 @@ static const char *addrp_localpart_extract_from
 }
 
 const struct sieve_address_part_def all_address_part = {
-	SIEVE_OBJECT("all", &address_part_operand, SIEVE_ADDRESS_PART_ALL),
-	addrp_all_extract_from
+	SIEVE_OBJECT("all",
+		&address_part_operand, SIEVE_ADDRESS_PART_ALL),
+	.extract_from = addrp_all_extract_from
 };
 
 const struct sieve_address_part_def local_address_part = {
-	SIEVE_OBJECT("localpart", &address_part_operand, SIEVE_ADDRESS_PART_LOCAL),
-	addrp_localpart_extract_from
+	SIEVE_OBJECT("localpart",
+		&address_part_operand, SIEVE_ADDRESS_PART_LOCAL),
+	.extract_from = addrp_localpart_extract_from
 };
 
 const struct sieve_address_part_def domain_address_part = {
-	SIEVE_OBJECT("domain", &address_part_operand,	SIEVE_ADDRESS_PART_DOMAIN),
-	addrp_domain_extract_from
+	SIEVE_OBJECT("domain",
+		&address_part_operand,	SIEVE_ADDRESS_PART_DOMAIN),
+	.extract_from = addrp_domain_extract_from
 };
 
diff --git a/src/lib-sieve/sieve-objects.h b/src/lib-sieve/sieve-objects.h
index 863232d3f..597d11caf 100644
--- a/src/lib-sieve/sieve-objects.h
+++ b/src/lib-sieve/sieve-objects.h
@@ -14,8 +14,12 @@ struct sieve_object_def {
 	unsigned int code;
 };
 
-#define SIEVE_OBJECT(identifier, operand, code) \
-	{ identifier, operand, code }
+#define SIEVE_OBJECT(_identifier, _operand, _code) \
+	.obj_def = { \
+		.identifier = (_identifier), \
+		.operand = (_operand), \
+		.code = (_code) \
+	}
 
 /*
  * Object instance
diff --git a/src/testsuite/testsuite-objects.c b/src/testsuite/testsuite-objects.c
index 5f403418b..c30bfa632 100644
--- a/src/testsuite/testsuite-objects.c
+++ b/src/testsuite/testsuite-objects.c
@@ -287,18 +287,17 @@ static bool tsto_envelope_set_member
 	(const struct sieve_runtime_env *renv, int id, string_t *value);
 
 const struct testsuite_object_def message_testsuite_object = {
-	SIEVE_OBJECT("message",	&testsuite_object_operand, TESTSUITE_OBJECT_MESSAGE),
-	NULL, NULL,
-	tsto_message_set_member,
-	NULL
+	SIEVE_OBJECT("message",
+		&testsuite_object_operand, TESTSUITE_OBJECT_MESSAGE),
+	.set_member = tsto_message_set_member
 };
 
 const struct testsuite_object_def envelope_testsuite_object = {
-	SIEVE_OBJECT("envelope", &testsuite_object_operand, TESTSUITE_OBJECT_ENVELOPE),
-	tsto_envelope_get_member_id,
-	tsto_envelope_get_member_name,
-	tsto_envelope_set_member,
-	NULL
+	SIEVE_OBJECT("envelope",
+		&testsuite_object_operand, TESTSUITE_OBJECT_ENVELOPE),
+	.get_member_id = tsto_envelope_get_member_id,
+	.get_member_name = tsto_envelope_get_member_name,
+	.set_member = tsto_envelope_set_member
 };
 
 enum testsuite_object_envelope_field {
diff --git a/src/testsuite/testsuite-substitutions.c b/src/testsuite/testsuite-substitutions.c
index e3c768aeb..d5f49ddda 100644
--- a/src/testsuite/testsuite-substitutions.c
+++ b/src/testsuite/testsuite-substitutions.c
@@ -234,17 +234,16 @@ static int opr_substitution_read_value
 static bool testsuite_file_substitution_get_value
 	(const char *param, string_t **result);
 
-static const struct testsuite_substitution_def testsuite_file_substitution = {
-	SIEVE_OBJECT(
-		"file",
+static const struct testsuite_substitution_def
+testsuite_file_substitution = {
+	SIEVE_OBJECT("file",
 		&testsuite_substitution_operand,
-		TESTSUITE_SUBSTITUTION_FILE
-	),
-	testsuite_file_substitution_get_value
+		TESTSUITE_SUBSTITUTION_FILE),
+	.get_value = testsuite_file_substitution_get_value
 };
 
 static bool testsuite_file_substitution_get_value
-	(const char *param, string_t **result)
+(const char *param, string_t **result)
 {
 	*result = t_str_new(256);
 
-- 
GitLab