These now work with struct var_expand_params, which allows more flexibility.
}
static void
-auth_request_event_var_expand_callback(struct event *event,
- const struct var_expand_table **tab_r,
- const struct var_expand_func_table **func_tab_r)
+auth_request_event_var_expand_callback(void *context,
+ struct var_expand_params *params_r)
{
- struct auth_request_var_expand_ctx *ctx =
- event_get_ptr(event, SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT);
+ struct auth_request_var_expand_ctx *ctx = context;
- *tab_r = auth_request_get_var_expand_table(ctx->auth_request,
- ctx->escape_func);
- *func_tab_r = auth_request_var_funcs_table;
+ params_r->table = auth_request_get_var_expand_table(ctx->auth_request,
+ ctx->escape_func);
+ params_r->func_table = auth_request_var_funcs_table;
+ params_r->func_context = ctx;
}
void auth_request_event_set_var_expand(struct auth_request *auth_request)
event_set_ptr(auth_request->event, SETTINGS_EVENT_VAR_EXPAND_CALLBACK,
auth_request_event_var_expand_callback);
event_set_ptr(auth_request->event,
- SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT, ctx);
+ SETTINGS_EVENT_VAR_EXPAND_CALLBACK_CONTEXT, ctx);
}
{ driver_name, auth_request_fields_var_expand_lookup },
{ NULL, NULL }
};
-
- event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_FUNC_TABLE,
- auth_request_fields_funcs);
- event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT, fields);
+ struct var_expand_params params = {
+ .func_table = auth_request_fields_funcs,
+ .func_context = fields,
+ };
+ event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_PARAMS, ¶ms);
if (settings_get(event, &auth_passdb_post_setting_parser_info, 0,
&post_set, &error) < 0) {
{ driver_name, auth_request_fields_var_expand_lookup },
{ NULL, NULL }
};
-
- event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_FUNC_TABLE,
- auth_request_fields_funcs);
- event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT, fields);
+ struct var_expand_params params = {
+ .func_table = auth_request_fields_funcs,
+ .func_context = fields,
+ };
+ event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_PARAMS, ¶ms);
if (settings_get(event, &auth_userdb_post_setting_parser_info, 0,
&post_set, &error) < 0) {
ARRAY_TYPE(settings_override_p) overrides;
string_t *str;
- const struct var_expand_table *const *tables;
- const struct var_expand_params_func *funcs;
+ struct var_expand_params var_params;
};
static ARRAY(const struct setting_parser_info *) set_registered_infos;
/* Make sure only the file path is var-expanded. */
value = file.path;
}
- if (var_expand_with_arrays(ctx->str, value, ctx->tables,
- ctx->funcs, &error) <= 0 &&
+ if (var_expand(ctx->str, value, &ctx->var_params, &error) <= 0 &&
(ctx->flags & SETTINGS_GET_FLAG_FAKE_EXPAND) == 0) {
*error_r = t_strdup_printf(
"Failed to expand %s setting variables: %s",
if ((ctx->flags & SETTINGS_GET_FLAG_NO_EXPAND) == 0) {
const char *error;
str_truncate(ctx->str, 0);
- if (var_expand_with_arrays(ctx->str, value, ctx->tables,
- ctx->funcs, &error) <= 0 &&
+ if (var_expand(ctx->str, value, &ctx->var_params, &error) <= 0 &&
(ctx->flags & SETTINGS_GET_FLAG_FAKE_EXPAND) == 0) {
*error_r = t_strdup_printf(
"Failed to expand default setting %s=%s variables: %s",
return mpool;
}
+struct settings_var_expand_init_ctx {
+ ARRAY(const struct var_expand_table *) tables;
+ ARRAY(struct var_expand_params_func) funcs;
+};
+
+static void
+settings_var_expand_init_add(struct settings_var_expand_init_ctx *init_ctx,
+ const struct var_expand_params *params)
+{
+ if (params->table != NULL)
+ array_push_back(&init_ctx->tables, ¶ms->table);
+ if (params->func_table != NULL) {
+ struct var_expand_params_func *func =
+ array_append_space(&init_ctx->funcs);
+ func->table = params->func_table;
+ func->context = params->func_context;
+ }
+ if (params->tables_arr != NULL) {
+ for (unsigned int i = 0; params->tables_arr[i] != NULL; i++)
+ array_push_back(&init_ctx->tables, ¶ms->tables_arr[i]);
+ }
+ if (params->funcs_arr != NULL) {
+ for (unsigned int i = 0; params->funcs_arr[i].table != NULL; i++)
+ array_push_back(&init_ctx->funcs, ¶ms->funcs_arr[i]);
+ }
+}
+
static void
settings_var_expand_init(struct settings_apply_ctx *ctx)
{
struct event *event = ctx->event;
- ARRAY(const struct var_expand_table *) tables;
- ARRAY(struct var_expand_params_func) funcs;
- const struct var_expand_table *table;
- const struct var_expand_func_table *func_table;
+ struct settings_var_expand_init_ctx init_ctx;
+ struct var_expand_params tmp_params;
- t_array_init(&tables, 4);
- t_array_init(&funcs, 4);
+ i_zero(&init_ctx);
+ t_array_init(&init_ctx.tables, 4);
+ t_array_init(&init_ctx.funcs, 4);
while (event != NULL) {
settings_var_expand_t *callback =
event_get_ptr(event, SETTINGS_EVENT_VAR_EXPAND_CALLBACK);
if (callback != NULL) {
- callback(event, &table, &func_table);
- if (table != NULL)
- array_push_back(&tables, &table);
- if (func_table != NULL) {
- struct var_expand_params_func *func =
- array_append_space(&funcs);
- func->table = func_table;
- func->context = event_get_ptr(event,
- SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT);
- }
+ void *callback_context = event_get_ptr(event,
+ SETTINGS_EVENT_VAR_EXPAND_CALLBACK_CONTEXT);
+ i_zero(&tmp_params);
+ callback(callback_context, &tmp_params);
+ settings_var_expand_init_add(&init_ctx, &tmp_params);
}
- table = event_get_ptr(event, SETTINGS_EVENT_VAR_EXPAND_TABLE);
- if (table != NULL)
- array_push_back(&tables, &table);
-
- func_table = event_get_ptr(event, SETTINGS_EVENT_VAR_EXPAND_FUNC_TABLE);
- if (func_table != NULL) {
- struct var_expand_params_func *func =
- array_append_space(&funcs);
- func->table = func_table;
- func->context = event_get_ptr(event,
- SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT);
- }
+ struct var_expand_params *params =
+ event_get_ptr(event, SETTINGS_EVENT_VAR_EXPAND_PARAMS);
+ if (params != NULL)
+ settings_var_expand_init_add(&init_ctx, params);
event = event_get_parent(event);
}
- array_append_zero(&funcs);
- ctx->tables = array_front(&tables);
- ctx->funcs = array_front(&funcs);
+ array_append_zero(&init_ctx.tables);
+ array_append_zero(&init_ctx.funcs);
+
+ ctx->var_params.tables_arr = array_front(&init_ctx.tables);
+ ctx->var_params.funcs_arr = array_front(&init_ctx.funcs);
}
static int settings_override_cmp(struct settings_override *const *set1,
or with SETTINGS_OVERRIDE_TYPE_2ND_DEFAULT. */
const char *error;
str_truncate(ctx->str, 0);
- if (var_expand_with_arrays(ctx->str, value, ctx->tables,
- ctx->funcs, &error) <= 0 &&
+ if (var_expand(ctx->str, value, &ctx->var_params, &error) <= 0 &&
(ctx->flags & SETTINGS_GET_FLAG_FAKE_EXPAND) == 0) {
*error_r = t_strdup_printf(
"Failed to expand default setting %s=%s variables: %s",
#include "settings-parser.h"
-struct var_expand_table;
-struct var_expand_func_table;
+struct var_expand_params;
struct settings_root;
struct settings_mmap;
#define SETTINGS_EVENT_MAILBOX_NAME_WITH_PREFIX "mailbox"
#define SETTINGS_EVENT_MAILBOX_NAME_WITHOUT_PREFIX "mailbox_subname"
-/* Set struct var_expand_table to be used for settings expansion. The table is
- expected to be accessible until the event is freed or the table is cleared
+/* Set struct var_expand_params to be used for settings expansion. The struct is
+ expected to be accessible until the event is freed or the params is removed
from the event. Usage:
- event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_TABLE, var_expand_table);
-*/
-#define SETTINGS_EVENT_VAR_EXPAND_TABLE \
- "settings_var_expand_table"
-/* Set struct var_expand_func_table and its function context pointer to be used
- for settings expansion. The table is expected to be accessible until the
- event is freed or the table is cleared from the event. Usage:
-
- event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_FUNC_TABLE, func_table);
- event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT, func_context);
-
- You can set any combination of SETTINGS_EVENT_VAR_EXPAND_TABLE,
- SETTINGS_EVENT_VAR_EXPAND_FUNC_TABLE and SETTINGS_EVENT_VAR_EXPAND_CALLBACK
- to the same event or parent events. They are all merged while expanding
- the variables. */
-#define SETTINGS_EVENT_VAR_EXPAND_FUNC_TABLE \
- "settings_var_expand_func_table"
-#define SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT \
- "settings_var_expand_func_context"
-
-/* Set a settings_var_expand_t callback that returns
- var_expand_[func_]table for settings expansion. This can be used instead of
- SETTINGS_EVENT_VAR_EXPAND_[FUNC_]TABLE to dynamically generate the table
+ event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_PARAMS, var_expand_params);
+
+ You can set any combination of SETTINGS_EVENT_VAR_EXPAND_PARAMS
+ and SETTINGS_EVENT_VAR_EXPAND_CALLBACK to the same event or parent events.
+ They are all merged while expanding the variables. */
+#define SETTINGS_EVENT_VAR_EXPAND_PARAMS \
+ "settings_var_expand_params"
+
+/* Set a settings_var_expand_t callback that returns var_expand_params for
+ settings expansion. This can be used instead of
+ SETTINGS_EVENT_VAR_EXPAND_PARAMS to dynamically generate the tables
on-demand. Usage:
event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_CALLBACK, callback);
- event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT, func_context);
+ event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_CALLBACK_CONTEXT, context);
*/
#define SETTINGS_EVENT_VAR_EXPAND_CALLBACK \
"settings_var_expand_callback"
-/* Callback function used with SETTINGS_EVENT_VAR_EXPAND_CALLBACK. The function
- can return either or both of tab_r and func_tab_r, using NULL for the field
- that isn't needed. */
+#define SETTINGS_EVENT_VAR_EXPAND_CALLBACK_CONTEXT \
+ "settings_var_expand_callback_context"
+/* Callback function used with SETTINGS_EVENT_VAR_EXPAND_CALLBACK. */
typedef void
-settings_var_expand_t(struct event *event,
- const struct var_expand_table **tab_r,
- const struct var_expand_func_table **func_tab_r);
+settings_var_expand_t(void *context, struct var_expand_params *params_r);
/* Get the wanted settings and check that the settings are valid.
The settings struct must have pool_t (info->pool_offset1), which the caller
{ "owner_home", shared_mail_user_var_home },
{ NULL, NULL }
};
+ struct var_expand_params *params =
+ p_new(user->pool, struct var_expand_params, 1);
+ params->table = tab;
+ params->func_table = func_tab;
+ params->func_context = &var_expand_ctx;
struct event *set_event = event_create(user->event);
event_add_str(set_event, SETTINGS_EVENT_NAMESPACE_NAME, ns->set->name);
- event_set_ptr(set_event, SETTINGS_EVENT_VAR_EXPAND_TABLE, tab);
- event_set_ptr(set_event, SETTINGS_EVENT_VAR_EXPAND_FUNC_TABLE,
- func_tab);
- event_set_ptr(set_event, SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT,
- &var_expand_ctx);
+ event_set_ptr(set_event, SETTINGS_EVENT_VAR_EXPAND_PARAMS, params);
/* Expanding mail_path may verify whether the user exists by
trying to access %{owner_home}. This sets
};
static void
-mail_storage_service_var_expand_callback(struct event *event,
- const struct var_expand_table **tab_r,
- const struct var_expand_func_table **func_tab_r)
+mail_storage_service_var_expand_callback(void *context,
+ struct var_expand_params *params_r)
{
- struct mail_storage_service_init_var_expand_ctx *var_expand_ctx =
- event_get_ptr(event, SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT);
- i_assert(var_expand_ctx != NULL);
-
- *tab_r = get_var_expand_table(var_expand_ctx->ctx->service,
- var_expand_ctx->user,
- var_expand_ctx->input);
- *func_tab_r = mail_storage_service_var_expand_func_table;
+ struct mail_storage_service_init_var_expand_ctx *var_expand_ctx = context;
+
+ params_r->table = get_var_expand_table(var_expand_ctx->ctx->service,
+ var_expand_ctx->user,
+ var_expand_ctx->input);
+ params_r->func_table = mail_storage_service_var_expand_func_table;
+ params_r->func_context = var_expand_ctx;
}
const char *
settings lookups are expected to be using mail_user.event. */
event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_CALLBACK,
mail_storage_service_var_expand_callback);
- event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT,
+ event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_CALLBACK_CONTEXT,
&var_expand_ctx);
if (settings_get(event, &mail_user_setting_parser_info,
0, &user_set, error_r) < 0) {
/* The context points to a variable in stack, so it can't be
used anymore. */
event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_CALLBACK, NULL);
- event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT, NULL);
+ event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_CALLBACK_CONTEXT, NULL);
}
*user_r = user;
return ret;
}
static void
-mail_user_var_expand_callback(struct event *event,
- const struct var_expand_table **tab_r,
- const struct var_expand_func_table **func_tab_r)
+mail_user_var_expand_callback(void *context, struct var_expand_params *params_r)
{
- struct mail_user *user =
- event_get_ptr(event, SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT);
- i_assert(user != NULL);
+ struct mail_user *user = context;
- *tab_r = mail_user_var_expand_table(user);
- *func_tab_r = mail_user_var_expand_func_table;
+ params_r->table = mail_user_var_expand_table(user);
+ params_r->func_table = mail_user_var_expand_func_table;
+ params_r->func_context = user;
}
struct mail_user *
lookups. */
event_set_ptr(user->event, SETTINGS_EVENT_VAR_EXPAND_CALLBACK,
mail_user_var_expand_callback);
- event_set_ptr(user->event, SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT, user);
+ event_set_ptr(user->event,
+ SETTINGS_EVENT_VAR_EXPAND_CALLBACK_CONTEXT, user);
user->v.deinit = mail_user_deinit_base;
user->v.deinit_pre = mail_user_deinit_pre_base;
client->raw_mail_user =
raw_storage_create_from_set(storage_service, client->set_instance);
- const struct var_expand_table *tab =
- mail_storage_service_get_var_expand_table(storage_service, &input);
+ struct var_expand_params params = {
+ .table = mail_storage_service_get_var_expand_table(storage_service, &input),
+ };
struct event *event = event_create(client->event);
- event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_TABLE, (void *)tab);
+ event_set_ptr(event, SETTINGS_EVENT_VAR_EXPAND_PARAMS, ¶ms);
if (settings_get(event, &lda_setting_parser_info, 0,
&client->lda_set, &error) < 0 ||
settings_get(event, &lmtp_setting_parser_info, 0,
}
static void
-client_var_expand_callback(struct event *event,
- const struct var_expand_table **tab_r,
- const struct var_expand_func_table **func_tab_r ATTR_UNUSED)
+client_var_expand_callback(void *context, struct var_expand_params *params_r)
{
- struct client *client = event_get_ptr(event, "client");
-
- *tab_r = get_var_expand_table(client);
+ struct client *client = context;
+ params_r->table = get_var_expand_table(client);
}
static int client_settings_get(struct client *client, const char **error_r)
/* Get settings before using log callback */
event_set_ptr(client->event, SETTINGS_EVENT_VAR_EXPAND_CALLBACK,
client_var_expand_callback);
- event_set_ptr(client->event, "client", client);
+ event_set_ptr(client->event, SETTINGS_EVENT_VAR_EXPAND_CALLBACK_CONTEXT,
+ client);
if (client_settings_get(client, &error) < 0) {
e_error(client->event, "%s", error);
event_unref(&client->event);