dovecot-1.2: var_expand(): Added support for long %{variable} na...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Dec 13 18:05:00 EET 2008
details: http://hg.dovecot.org/dovecot-1.2/rev/983d38de06c9
changeset: 8544:983d38de06c9
user: Timo Sirainen <tss at iki.fi>
date: Sat Dec 13 18:04:55 2008 +0200
description:
var_expand(): Added support for long %{variable} names.
diffstat:
12 files changed, 138 insertions(+), 103 deletions(-)
src/auth/auth-request.c | 32 ++++++++--------
src/deliver/deliver.c | 30 +++++++--------
src/deliver/mail-send.c | 10 ++---
src/imap/client.c | 6 +--
src/lib-storage/index/shared/shared-storage.c | 12 +++---
src/lib/var-expand.c | 50 +++++++++++++++++++++----
src/lib/var-expand.h | 5 +-
src/login-common/client-common.c | 36 +++++++++---------
src/master/mail-process.c | 22 +++++------
src/plugins/acl/acl-shared-storage.c | 8 ++--
src/pop3/client.c | 20 +++++-----
src/pop3/commands.c | 10 ++---
diffs (truncated from 421 to 300 lines):
diff -r 89a31d203d0b -r 983d38de06c9 src/auth/auth-request.c
--- a/src/auth/auth-request.c Sat Dec 13 17:12:46 2008 +0200
+++ b/src/auth/auth-request.c Sat Dec 13 18:04:55 2008 +0200
@@ -1340,22 +1340,22 @@ auth_request_get_var_expand_table(const
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;
diff -r 89a31d203d0b -r 983d38de06c9 src/deliver/deliver.c
--- a/src/deliver/deliver.c Sat Dec 13 17:12:46 2008 +0200
+++ b/src/deliver/deliver.c Sat Dec 13 18:04:55 2008 +0200
@@ -101,11 +101,11 @@ get_log_var_expand_table(struct mail *ma
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;
@@ -504,16 +504,16 @@ get_var_expand_table(const char *user, c
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;
diff -r 89a31d203d0b -r 983d38de06c9 src/deliver/mail-send.c
--- a/src/deliver/mail-send.c Sat Dec 13 17:12:46 2008 +0200
+++ b/src/deliver/mail-send.c Sat Dec 13 18:04:55 2008 +0200
@@ -25,11 +25,11 @@ get_var_expand_table(struct mail *mail,
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;
diff -r 89a31d203d0b -r 983d38de06c9 src/imap/client.c
--- a/src/imap/client.c Sat Dec 13 17:12:46 2008 +0200
+++ b/src/imap/client.c Sat Dec 13 18:04:55 2008 +0200
@@ -100,9 +100,9 @@ static const char *client_stats(struct c
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;
diff -r 89a31d203d0b -r 983d38de06c9 src/lib-storage/index/shared/shared-storage.c
--- a/src/lib-storage/index/shared/shared-storage.c Sat Dec 13 17:12:46 2008 +0200
+++ b/src/lib-storage/index/shared/shared-storage.c Sat Dec 13 18:04:55 2008 +0200
@@ -126,11 +126,11 @@ int shared_storage_get_namespace(struct
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;
@@ -208,7 +208,7 @@ int shared_storage_get_namespace(struct
}
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 */
diff -r 89a31d203d0b -r 983d38de06c9 src/lib/var-expand.c
--- a/src/lib/var-expand.c Sat Dec 13 17:12:46 2008 +0200
+++ b/src/lib/var-expand.c Sat Dec 13 18:04:55 2008 +0200
@@ -11,6 +11,9 @@
#include <stdlib.h>
#include <ctype.h>
+
+#define TABLE_LAST(t) \
+ ((t)->key == '\0' && (t)->long_key == NULL)
struct var_expand_context {
int offset;
@@ -142,7 +145,8 @@ void var_expand(string_t *dest, const ch
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++) {
@@ -209,10 +213,27 @@ void var_expand(string_t *dest, const ch
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;
+ }
}
}
@@ -283,13 +304,26 @@ char var_get_key(const char *str)
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;
diff -r 89a31d203d0b -r 983d38de06c9 src/lib/var-expand.h
--- a/src/lib/var-expand.h Sat Dec 13 17:12:46 2008 +0200
+++ b/src/lib/var-expand.h Sat Dec 13 18:04:55 2008 +0200
@@ -4,6 +4,7 @@ struct var_expand_table {
struct var_expand_table {
char key;
const char *value;
+ const char *long_key;
};
/* Expand % variables in src and append the string in dest.
@@ -14,8 +15,8 @@ void var_expand(string_t *dest, const ch
/* 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, ...);
diff -r 89a31d203d0b -r 983d38de06c9 src/login-common/client-common.c
--- a/src/login-common/client-common.c Sat Dec 13 17:12:46 2008 +0200
+++ b/src/login-common/client-common.c Sat Dec 13 18:04:55 2008 +0200
@@ -37,21 +37,21 @@ get_var_expand_table(struct client *clie
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;
More information about the dovecot-cvs
mailing list