auth_request_escape_func_t *escape_func)
{
static struct var_expand_table static_tab[] = {
- { 'u', NULL },
- { 'n', NULL },
- { 'd', NULL },
- { 's', NULL },
- { 'h', NULL },
- { 'l', NULL },
- { 'r', NULL },
- { 'p', NULL },
- { 'w', NULL },
- { '!', NULL },
- { 'm', NULL },
- { 'c', NULL },
- { 'a', NULL },
- { 'b', NULL },
- { 'k', NULL },
- { '\0', NULL }
+ { 'u', NULL, "user" },
+ { 'n', NULL, "username" },
+ { 'd', NULL, "domain" },
+ { 's', NULL, "service" },
+ { 'h', NULL, "home" },
+ { 'l', NULL, "lip" },
+ { 'r', NULL, "rip" },
+ { 'p', NULL, "pid" },
+ { 'w', NULL, "password" },
+ { '!', NULL, NULL },
+ { 'm', NULL, "mech" },
+ { 'c', NULL, "secured" },
+ { 'a', NULL, "lport" },
+ { 'b', NULL, "rport" },
+ { 'k', NULL, "cert" },
+ { '\0', NULL, NULL }
};
struct var_expand_table *tab;
get_log_var_expand_table(struct mail *mail, const char *message)
{
static struct var_expand_table static_tab[] = {
- { '$', NULL },
- { 'm', NULL },
- { 's', NULL },
- { 'f', NULL },
- { '\0', NULL }
+ { '$', NULL, NULL },
+ { 'm', NULL, "msgid" },
+ { 's', NULL, "subject" },
+ { 'f', NULL, "from" },
+ { '\0', NULL, NULL }
};
struct var_expand_table *tab;
unsigned int i;
get_var_expand_table(const char *user, const char *home)
{
static struct var_expand_table static_tab[] = {
- { 'u', NULL },
- { 'n', NULL },
- { 'd', NULL },
- { 's', NULL },
- { 'h', NULL },
- { 'l', NULL },
- { 'r', NULL },
- { 'p', NULL },
- { 'i', NULL },
- { '\0', NULL }
+ { 'u', NULL, "user" },
+ { 'n', NULL, "username" },
+ { 'd', NULL, "domain" },
+ { 's', NULL, "service" },
+ { 'h', NULL, "home" },
+ { 'l', NULL, "lip" },
+ { 'r', NULL, "rip" },
+ { 'p', NULL, "pid" },
+ { 'i', NULL, "uid" },
+ { '\0', NULL, NULL }
};
struct var_expand_table *tab;
const char *recipient)
{
static struct var_expand_table static_tab[] = {
- { 'n', NULL },
- { 'r', NULL },
- { 's', NULL },
- { 't', NULL },
- { '\0', NULL }
+ { 'n', NULL, "crlf" },
+ { 'r', NULL, "reason" },
+ { 's', NULL, "subject" },
+ { 't', NULL, "to" },
+ { '\0', NULL, NULL }
};
struct var_expand_table *tab;
const char *subject;
static const char *client_stats(struct client *client)
{
static struct var_expand_table static_tab[] = {
- { 'i', NULL },
- { 'o', NULL },
- { '\0', NULL }
+ { 'i', NULL, "input" },
+ { 'o', NULL, "output" },
+ { '\0', NULL, NULL }
};
struct var_expand_table *tab;
string_t *str;
struct shared_storage *storage = (struct shared_storage *)_storage;
struct mail_user *user = _storage->ns->user;
static struct var_expand_table static_tab[] = {
- { 'u', NULL },
- { 'n', NULL },
- { 'd', NULL },
- { 'h', NULL },
- { '\0', NULL }
+ { 'u', NULL, "user" },
+ { 'n', NULL, "username" },
+ { 'd', NULL, "domain" },
+ { 'h', NULL, "home" },
+ { '\0', NULL, NULL }
};
struct var_expand_table *tab;
struct mail_namespace *ns;
}
owner = mail_user_init(userdomain);
- if (!var_has_key(storage->location, 'h'))
+ if (!var_has_key(storage->location, 'h', "home"))
ret = 1;
else {
/* we'll need to look up the user's home directory */
#include <stdlib.h>
#include <ctype.h>
+#define TABLE_LAST(t) \
+ ((t)->key == '\0' && (t)->long_key == NULL)
+
struct var_expand_context {
int offset;
unsigned int width;
struct var_expand_context ctx;
const char *(*modifier[MAX_MODIFIER_COUNT])
(const char *, struct var_expand_context *);
- unsigned int i, modifier_count;
+ const char *end;
+ unsigned int i, len, modifier_count;
memset(&ctx, 0, sizeof(ctx));
for (; *str != '\0'; str++) {
break;
var = NULL;
- for (t = table; t->key != '\0'; t++) {
- if (t->key == *str) {
- var = t->value != NULL ? t->value : "";
- break;
+ if (*str == '{' && (end = strchr(str, '}')) != NULL) {
+ /* %{long_key} */
+ len = end - (str + 1);
+ for (t = table; !TABLE_LAST(t); t++) {
+ if (t->long_key != NULL &&
+ strncmp(t->long_key, str+1,
+ len) == 0 &&
+ t->long_key[len] == '\0') {
+ var = t->value != NULL ?
+ t->value : "";
+ str = end;
+ break;
+ }
+ }
+ } else {
+ for (t = table; !TABLE_LAST(t); t++) {
+ if (t->key == *str) {
+ var = t->value != NULL ?
+ t->value : "";
+ break;
+ }
}
}
return *str;
}
-bool var_has_key(const char *str, char key)
+bool var_has_key(const char *str, char key, const char *long_key)
{
+ const char *end;
+ char c;
+
for (; *str != '\0'; str++) {
if (*str == '%' && str[1] != '\0') {
str++;
- if (var_get_key(str) == key)
+ c = var_get_key(str);
+ if (c == key)
return TRUE;
+
+ if (c == '{' && long_key != NULL &&
+ (str = strchr(str, '{')) != NULL &&
+ (end = strchr(++str, '}')) != NULL) {
+ if (strncmp(str, long_key, end-str) == 0 &&
+ long_key[end-str] == '\0')
+ return TRUE;
+ str = end;
+ }
}
}
return FALSE;
struct var_expand_table {
char key;
const char *value;
+ const char *long_key;
};
/* Expand % variables in src and append the string in dest.
/* Returns the actual key character for given string, ie. skip any modifiers
that are before it. The string should be the data after the '%' character. */
char var_get_key(const char *str) ATTR_PURE;
-/* Returns TRUE if key variable is used in the string. */
-bool var_has_key(const char *str, char key) ATTR_PURE;
+/* Returns TRUE if key variable is used in the string. long_key may be NULL. */
+bool var_has_key(const char *str, char key, const char *long_key) ATTR_PURE;
const struct var_expand_table *
var_expand_table_build(char key, const char *value, char key2, ...);
get_var_expand_table(struct client *client)
{
static struct var_expand_table static_tab[] = {
- { 'u', NULL },
- { 'n', NULL },
- { 'd', NULL },
- { 's', NULL },
- { 'h', NULL },
- { 'l', NULL },
- { 'r', NULL },
- { 'p', NULL },
- { 'm', NULL },
- { 'a', NULL },
- { 'b', NULL },
- { 'c', NULL },
- { 'k', NULL },
- { 'e', NULL },
- { '\0', NULL }
+ { 'u', NULL, "user" },
+ { 'n', NULL, "username" },
+ { 'd', NULL, "domain" },
+ { 's', NULL, "service" },
+ { 'h', NULL, "home" },
+ { 'l', NULL, "lip" },
+ { 'r', NULL, "rip" },
+ { 'p', NULL, "pid" },
+ { 'm', NULL, "mech" },
+ { 'a', NULL, "lport" },
+ { 'b', NULL, "rport" },
+ { 'c', NULL, "secured" },
+ { 'k', NULL, "ssl_security" },
+ { 'e', NULL, "mail_pid" },
+ { '\0', NULL, NULL }
};
struct var_expand_table *tab;
unsigned int i;
static void client_syslog_real(struct client *client, const char *msg)
{
static struct var_expand_table static_tab[3] = {
- { 's', NULL },
- { '$', NULL },
- { '\0', NULL }
+ { 's', NULL, NULL },
+ { '$', NULL, NULL },
+ { '\0', NULL, NULL }
};
const struct var_expand_table *var_expand_table;
struct var_expand_table *tab;
{
#define VAR_EXPAND_HOME_IDX 4
static struct var_expand_table static_tab[] = {
- { 'u', NULL },
- { 'n', NULL },
- { 'd', NULL },
- { 's', NULL },
- { 'h', NULL },
- { 'l', NULL },
- { 'r', NULL },
- { 'p', NULL },
- { 'i', NULL },
- { '\0', NULL }
+ { 'u', NULL, "user" },
+ { 'n', NULL, "username" },
+ { 'd', NULL, "domain" },
+ { 's', NULL, "service" },
+ { 'h', NULL, "home" },
+ { 'l', NULL, "lip" },
+ { 'r', NULL, "rip" },
+ { 'p', NULL, "pid" },
+ { 'i', NULL, "uid" },
+ { '\0', NULL, NULL }
};
struct var_expand_table *tab;
i_assert(table[VAR_EXPAND_HOME_IDX].key == 'h');
return table[VAR_EXPAND_HOME_IDX].value == NULL &&
- var_has_key(str, 'h');
+ var_has_key(str, 'h', "home");
}
static const char *
const char *userdomain)
{
static struct var_expand_table static_tab[] = {
- { 'u', NULL },
- { 'n', NULL },
- { 'd', NULL },
- { '\0', NULL }
+ { 'u', NULL, "user" },
+ { 'n', NULL, "username" },
+ { 'd', NULL, "domain" },
+ { '\0', NULL, NULL }
};
struct var_expand_table *tab;
struct mail_namespace *ns;
static const char *client_stats(struct client *client)
{
static struct var_expand_table static_tab[] = {
- { 'p', NULL },
- { 't', NULL },
- { 'b', NULL },
- { 'r', NULL },
- { 'd', NULL },
- { 'm', NULL },
- { 's', NULL },
- { 'i', NULL },
- { 'o', NULL },
- { '\0', NULL }
+ { 'p', NULL, "top_bytes" },
+ { 't', NULL, "top_count" },
+ { 'b', NULL, "retr_bytes" },
+ { 'r', NULL, "retr_count" },
+ { 'd', NULL, "deleted_count" },
+ { 'm', NULL, "message_count" },
+ { 's', NULL, "message_bytes" },
+ { 'i', NULL, "input" },
+ { 'o', NULL, "output" },
+ { '\0', NULL, NULL }
};
struct var_expand_table *tab;
string_t *str;
static bool list_uids_iter(struct client *client, struct cmd_uidl_context *ctx)
{
static struct var_expand_table static_tab[] = {
- { 'v', NULL },
- { 'u', NULL },
- { 'm', NULL },
- { 'f', NULL },
- { '\0', NULL }
+ { 'v', NULL, "uidvalidity" },
+ { 'u', NULL, "uid" },
+ { 'm', NULL, "md5" },
+ { 'f', NULL, "filename" },
+ { '\0', NULL, NULL }
};
struct var_expand_table *tab;
string_t *str;