Adjusted to changes in the matching and operand retrieval APIs in Pigeonhole.
authorStephan Bosch <stephan@rename-it.nl>
Sat Aug 14 00:48:12 2010 +0200 (2010-08-14)
changeset 26046364d2e5a2
parent 25 7446ebab92ce
child 27 e5b366279b45
Adjusted to changes in the matching and operand retrieval APIs in Pigeonhole.
src/ext-extdata-variables.c
src/tst-extdata.c
     1.1 --- a/src/ext-extdata-variables.c	Fri Jul 30 19:21:55 2010 +0200
     1.2 +++ b/src/ext-extdata-variables.c	Sat Aug 14 00:48:12 2010 +0200
     1.3 @@ -24,21 +24,21 @@
     1.4  	(const struct sieve_codegen_env *cgenv,
     1.5  		const struct sieve_variables_namespace *nspc,
     1.6  		struct sieve_ast_argument *arg, struct sieve_command *cmd, void *var_data);
     1.7 -bool vnspc_sieve_extdata_read_variable
     1.8 -	(const struct sieve_runtime_env *renv,
     1.9 -		const struct sieve_variables_namespace *nspc, sieve_size_t *address,
    1.10 -		string_t **str_r);
    1.11  bool vnspc_sieve_extdata_dump_variable
    1.12  	(const struct sieve_dumptime_env *denv,
    1.13 -		const struct sieve_variables_namespace *nspc, sieve_size_t *address,
    1.14 -		const char *field_name);
    1.15 +		const struct sieve_variables_namespace *nspc, 
    1.16 +		const struct sieve_operand *oprnd, sieve_size_t *address);
    1.17 +int vnspc_sieve_extdata_read_variable
    1.18 +	(const struct sieve_runtime_env *renv,
    1.19 +		const struct sieve_variables_namespace *nspc,
    1.20 +		const struct sieve_operand *oprnd, sieve_size_t *address, string_t **str_r);
    1.21  
    1.22  static const struct sieve_variables_namespace_def extdata_namespace = {
    1.23  	SIEVE_OBJECT("extdata", &extdata_namespace_operand, 0),
    1.24  	vnspc_sieve_extdata_validate,
    1.25  	vnspc_sieve_extdata_generate,
    1.26 -	vnspc_sieve_extdata_read_variable,
    1.27 -	vnspc_sieve_extdata_dump_variable
    1.28 +	vnspc_sieve_extdata_dump_variable,
    1.29 +	vnspc_sieve_extdata_read_variable
    1.30  };
    1.31  
    1.32  bool vnspc_sieve_extdata_validate
    1.33 @@ -104,49 +104,54 @@
    1.34  	return TRUE;
    1.35  }
    1.36  
    1.37 -bool vnspc_sieve_extdata_read_variable
    1.38 +bool vnspc_sieve_extdata_dump_variable
    1.39 +(const struct sieve_dumptime_env *denv,
    1.40 +	const struct sieve_variables_namespace *nspc ATTR_UNUSED,
    1.41 +	const struct sieve_operand *oprnd, sieve_size_t *address)
    1.42 +{
    1.43 +	string_t *var_name;
    1.44 +
    1.45 +	if ( !sieve_binary_read_string(denv->sblock, address, &var_name) )
    1.46 +		return FALSE;
    1.47 +
    1.48 +	if ( oprnd->field_name != NULL )
    1.49 +		sieve_code_dumpf(denv, "%s: VAR ${extdata.%s}",
    1.50 +			oprnd->field_name, str_c(var_name));
    1.51 +	else
    1.52 +		sieve_code_dumpf(denv, "VAR ${extdata.%s}",
    1.53 +			str_c(var_name));
    1.54 +
    1.55 +	return TRUE;
    1.56 +}
    1.57 +
    1.58 +int vnspc_sieve_extdata_read_variable
    1.59  (const struct sieve_runtime_env *renv,
    1.60 -	const struct sieve_variables_namespace *nspc, sieve_size_t *address,
    1.61 +	const struct sieve_variables_namespace *nspc,
    1.62 +	const struct sieve_operand *oprnd, sieve_size_t *address,
    1.63  	string_t **str_r)
    1.64  {
    1.65  	const struct sieve_extension *this_ext = SIEVE_OBJECT_EXTENSION(nspc);	
    1.66  	string_t *var_name;
    1.67  	const char *ext_value;
    1.68  
    1.69 -	if ( !sieve_binary_read_string(renv->sblock, address, &var_name) )
    1.70 -		return FALSE;
    1.71 +	if ( !sieve_binary_read_string(renv->sblock, address, &var_name) ) {
    1.72 +		sieve_runtime_trace_operand_error(renv, oprnd,
    1.73 +			"extdata variable operand corrupt: invalid name");
    1.74 +		return SIEVE_EXEC_BIN_CORRUPT;
    1.75 +	}
    1.76  
    1.77  	if ( str_r !=  NULL ) {
    1.78  		ext_value=ext_extdata_get_value(renv, this_ext, str_c(var_name));
    1.79  		if ( ext_value == NULL ) {
    1.80  			*str_r = t_str_new_const("", 0);
    1.81 -			return TRUE;
    1.82 +			return SIEVE_EXEC_OK;
    1.83  		}
    1.84  
    1.85  		*str_r = t_str_new_const(ext_value, strlen(ext_value));
    1.86  	}
    1.87 -	return TRUE;
    1.88 +	return SIEVE_EXEC_OK;
    1.89  }
    1.90  
    1.91 -bool vnspc_sieve_extdata_dump_variable
    1.92 -(const struct sieve_dumptime_env *denv,
    1.93 -	const struct sieve_variables_namespace *nspc ATTR_UNUSED, 
    1.94 -	sieve_size_t *address, const char *field_name)
    1.95 -{
    1.96 -	string_t *var_name;
    1.97 -
    1.98 -	if ( !sieve_binary_read_string(denv->sblock, address, &var_name) )
    1.99 -		return FALSE;
   1.100 -
   1.101 -	if ( field_name != NULL )
   1.102 -		sieve_code_dumpf(denv, "%s: VAR ${extdata.%s}",
   1.103 -			field_name, str_c(var_name));
   1.104 -	else
   1.105 -		sieve_code_dumpf(denv, "VAR ${extdata.%s}",
   1.106 -			str_c(var_name));
   1.107 -
   1.108 -	return TRUE;
   1.109 -}
   1.110  
   1.111  /*
   1.112   * Namespace registration
     2.1 --- a/src/tst-extdata.c	Fri Jul 30 19:21:55 2010 +0200
     2.2 +++ b/src/tst-extdata.c	Sat Aug 14 00:48:12 2010 +0200
     2.3 @@ -133,18 +133,13 @@
     2.4  static bool tst_extdata_operation_dump
     2.5  (const struct sieve_dumptime_env *denv, sieve_size_t *address)
     2.6  {
     2.7 -	int opt_code = 0;
     2.8 -
     2.9  	sieve_code_dumpf(denv, "EXTDATA");
    2.10  	sieve_code_descend(denv);
    2.11  
    2.12  	/* Handle any optional arguments */
    2.13 -	 if ( sieve_match_opr_optional_dump(denv, address, &opt_code) != 0 )
    2.14 +	 if ( sieve_match_opr_optional_dump(denv, address, NULL) != 0 )
    2.15          return FALSE;
    2.16  
    2.17 -	if ( opt_code != SIEVE_MATCH_OPT_END )
    2.18 -		return FALSE;
    2.19 -		
    2.20  	return
    2.21  		sieve_opr_string_dump(denv, address, "name") &&
    2.22  		sieve_opr_stringlist_dump(denv, address, "key list");
    2.23 @@ -158,8 +153,6 @@
    2.24  (const struct sieve_runtime_env *renv, sieve_size_t *address)
    2.25  {
    2.26  	const struct sieve_extension *this_ext = renv->oprtn->ext;
    2.27 -	int ret;
    2.28 -	int opt_code = 0;
    2.29  	struct sieve_match_type mcht = 
    2.30  		SIEVE_MATCH_TYPE_DEFAULT(is_match_type);
    2.31  	struct sieve_comparator cmp = 
    2.32 @@ -167,30 +160,25 @@
    2.33  	string_t *name;
    2.34  	struct sieve_stringlist *value_list, *key_list;
    2.35  	const char *ext_value = NULL;
    2.36 +	int match, ret;
    2.37  
    2.38  	/*
    2.39  	 * Read operands 
    2.40  	 */
    2.41  	
    2.42  	/* Handle match-type and comparator operands */
    2.43 -	if ( (ret=sieve_match_opr_optional_read
    2.44 -        (renv, address, &opt_code, &cmp, &mcht)) < 0 )
    2.45 -        return SIEVE_EXEC_BIN_CORRUPT;
    2.46 +	if ( sieve_match_opr_optional_read
    2.47 +		(renv, address, NULL, &ret, &cmp, &mcht) < 0 )
    2.48 +		return ret;
    2.49  	
    2.50 -	/* Check whether we neatly finished the list of optional operands*/
    2.51 -	if ( opt_code != SIEVE_MATCH_OPT_END) {
    2.52 -		sieve_runtime_trace_error(renv, "invalid optional operand");
    2.53 -		return SIEVE_EXEC_BIN_CORRUPT;
    2.54 -	}
    2.55 -
    2.56  	/* Read source */
    2.57 -	if ( !sieve_opr_string_read(renv, address, "name", &name) )
    2.58 -		return SIEVE_EXEC_BIN_CORRUPT;
    2.59 +	if ( (ret=sieve_opr_string_read(renv, address, "name", &name)) <= 0 )
    2.60 +		return ret;
    2.61  	
    2.62  	/* Read key-list */
    2.63 -	if ( (key_list=sieve_opr_stringlist_read(renv, address, "key-list"))
    2.64 -		== NULL )
    2.65 -		return SIEVE_EXEC_BIN_CORRUPT;
    2.66 +	if ( (ret=sieve_opr_stringlist_read(renv, address, "key-list", &key_list))
    2.67 +		<= 0 )
    2.68 +		return ret;
    2.69  
    2.70  	/*
    2.71  	 * Perform operation
    2.72 @@ -207,16 +195,14 @@
    2.73  		value_list = sieve_single_stringlist_create_cstr(renv, ext_value, FALSE);
    2.74  
    2.75  		/* Perform match */
    2.76 -		ret = sieve_match(renv, &mcht, &cmp, value_list, key_list); 	
    2.77 +		if ( (match=sieve_match(renv, &mcht, &cmp, value_list, key_list, &ret))
    2.78 +			< 0 )
    2.79 +			return ret;	
    2.80  	} else {
    2.81 -		ret = 0;
    2.82 +		match = 0;
    2.83  	}
    2.84  	
    2.85 -	if ( ret >= 0 ) {
    2.86 -		sieve_interpreter_set_test_result(renv->interp, ret > 0);
    2.87 -		return SIEVE_EXEC_OK;
    2.88 -	}
    2.89 -	
    2.90 -	sieve_runtime_trace_error(renv, "invalid string list item");
    2.91 -	return SIEVE_EXEC_BIN_CORRUPT;
    2.92 +	/* Set test result for subsequent conditional jump */
    2.93 +	sieve_interpreter_set_test_result(renv->interp, match > 0);
    2.94 +	return SIEVE_EXEC_OK;
    2.95  }