/* Copyright (c) 2003-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "str.h"
#include "var-expand.h"
#include "var-expand-private.h"
#include "wildcard-match.h"
#include <regex.h>
enum var_expand_if_op {
/* put all numeric comparisons before this line */
/* keep this as last */
};
{
NULL,
"==",
"<",
"<=",
">",
">=",
"!=",
"eq",
"lt",
"le",
"gt",
"ge",
"ne",
"*",
"!*",
"~",
"!~",
};
return i;
}
return OP_UNKNOWN;
}
{
if (op == OP_UNKNOWN) {
return -1;
}
intmax_t a;
intmax_t b;
if (str_to_intmax(lhs, &a) < 0) {
return -1;
}
if (str_to_intmax(rhs, &b) < 0) {
return -1;
}
switch(op) {
case OP_NUM_EQ:
*result_r = a==b;
return 0;
case OP_NUM_LT:
*result_r = a<b;
return 0;
case OP_NUM_LE:
*result_r = a<=b;
return 0;
case OP_NUM_GT:
*result_r = a>b;
return 0;
case OP_NUM_GE:
*result_r = a>=b;
return 0;
case OP_NUM_NE:
*result_r = a!=b;
return 0;
default:
}
}
switch(op) {
case OP_STR_EQ:
return 0;
case OP_STR_LT:
return 0;
case OP_STR_LE:
return 0;
case OP_STR_GT:
return 0;
case OP_STR_GE:
return 0;
case OP_STR_NE:
return 0;
case OP_STR_LIKE:
return 0;
case OP_STR_NOT_LIKE:
return 0;
case OP_STR_NOT_REGEXP:
/* fall through */
case OP_STR_REGEXP: {
int ec;
bool res;
char *errbuf;
errbuf);
return -1;
}
} else {
}
/* this should be same as neg.
if NOT_REGEXP, neg == TRUE and res should be FALSE
if REGEXP, ned == FALSE, and res should be TRUE
*/
return 0;
}
default:
}
}
{
/* in case the original input had :, we need to fix that
by concatenating the key and field together. */
const char *par_end;
const char *const *parms;
unsigned int depth = 0;
int ret;
if (p == NULL) {
*error_r = "if: missing parameter(s)";
return -1;
}
/* we need to skip any %{} parameters here, so we can split the string
correctly from , without breaking any inner expansions */
if (*par_end == '\\') {
continue;
} else if (escape) {
continue;
}
if (*par_end == '%') {
depth++;
depth--;
continue;
/* if there is a unescaped : at top level it means
that the key + arguments end here. it's probably
a by-product of the t_strconcat at top of function,
which is best handled here. */
break;
}
}
}
} else {
array_count(¶ms));
return -1;
}
}
/* expand the parameters */
error_r)) <= 0) {
return ret;
}
}
/* execute comparison */
return -1;
return 1;
}