Ejemplo n.º 1
0
var_t *
exp_eval(exp_t *exp, var_t *mailspec)
{
	if (exp == NULL)
	{
		log_debug("exp_eval: expression is null");
		return NULL;
	}

	switch (exp->ex_type)
	{
	case EX_PARENTHESES:	return exp_eval(exp->ex_data, mailspec);
	case EX_CONSTANT:	return exp->ex_data;
	case EX_LIST:		return exp_eval_list(exp, mailspec);
	case EX_SYMBOL:		return acl_symbol_get(mailspec, exp->ex_data);
	case EX_FUNCTION:	return exp_eval_function(exp, mailspec);
	case EX_OPERATION:	return exp_eval_operation(exp, mailspec);
	case EX_VARIABLE:	return exp_eval_variable(exp, mailspec);
	case EX_MACRO:		return exp_eval_macro(exp, mailspec);
	case EX_TERNARY_COND:	return exp_eval_ternary_condition(exp, mailspec);

	default:
		log_error("exp_eval: bad type");
	}

	return NULL;
}
Ejemplo n.º 2
0
static var_t *
hitlist_record(hitlist_t *hl, var_t *attrs, int load_data)
{
	ll_entry_t *pos;
	var_t *key;
	char *keystr;
	var_t *v;
	var_t *schema = NULL;
	VAR_INT_T zero = 0;
	char *name;

	name = hl->hl_table? hl->hl_table: hl->hl_name;

	schema = vlist_create(name, VF_KEEPNAME);
	if (schema == NULL)
	{
		log_error("hitlist_schema: vlist_create failed");
		goto error;
	}

	pos = LL_START(hl->hl_keys);
	while ((key = ll_next(hl->hl_keys, &pos)))
	{
		// Impossible
		if (key->v_data == NULL)
		{
			log_error("hitlist_schema: key is NULL");
			goto error;
		}

		// Bad configured
		if (key->v_type != VT_STRING)
		{
			log_error("hitlist_scheme: bad configuration %s:"
				" hitlist keys must be strings.", hl->hl_name);
			goto error;
		}

		keystr = key->v_data;

		// Variables
		if (keystr[0] == '$')
		{
			v = acl_variable_get(attrs, keystr);
		}

		// Regular symbol
		else
		{
			v = acl_symbol_get(attrs, keystr);
		}

		if (v == NULL)
		{
			log_error("hitlist_scheme: %s: lookup %s failed",
				hl->hl_name, keystr);
			goto error;
		}

		if (load_data && v->v_data == NULL)
		{
			log_error("hitlist_scheme: %s: key %s is NULL",
				hl->hl_name, keystr);
			goto error;
		}

		if (vlist_append_new(schema, v->v_type, keystr,
			load_data? v->v_data: NULL, VF_COPY | VF_KEY))
		{
			log_error("hitlist_schema: %s: vlist_append_new"
				" failed", hl->hl_name);
			goto error;
		}
	}

	// Add value
	if (vlist_append_new(schema, VT_INT, hl->hl_value_field,
	    load_data? &zero: NULL, VF_COPY))
	{
		log_error("hitlist_schema: %s: vlist_append_new failed for %s",
			hl->hl_name, hl->hl_value_field);
		goto error;
	}

	if (vlist_append_new(schema, VT_INT, hl->hl_expire_field,
	    load_data? &zero: NULL, VF_COPY))
	{
		log_error("hitlist_schema: %s: vlist_append_new failed for %s",
			hl->hl_name, hl->hl_expire_field);
		goto error;
	}

	return schema;

error:
	if (schema != NULL)
	{
		var_delete(schema);
	}

	return NULL;
}