view src/lib/var-expand.h @ 21941:bb81856fe3c1

lib, userdb-vpopmail: Fully remove var_expand_table_build() It was accidentally removed in master-2.2 as part of the changes in 122014ad84488d6309dc7d1572dfc988fedc18c4 This finishes up the removal as it was done in master in 79fe1b28df44ba22b230326bee895583c1df5a28
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Tue, 11 Apr 2017 10:11:00 +0300
parents 64f547f5bd86
children 7b6f77272538
line wrap: on
line source

#ifndef VAR_EXPAND_H
#define VAR_EXPAND_H

struct var_expand_table {
	char key;
	const char *value;
	const char *long_key;
};

struct var_expand_func_table {
	const char *key;
	/* %{key:data}, or data is "" with %{key}, */
	const char *(*func)(const char *data, void *context);
};

/* Expand % variables in src and append the string in dest.
   table must end with key = 0. */
void var_expand(string_t *dest, const char *str,
		const struct var_expand_table *table);
/* Like var_expand(), but support also callback functions for
   variable expansion. */
void var_expand_with_funcs(string_t *dest, const char *str,
			   const struct var_expand_table *table,
			   const struct var_expand_func_table *func_table,
			   void *func_context) ATTR_NULL(3, 4, 5);

/* 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.
   For %{long_variable}, '{' is returned. */
char var_get_key(const char *str) ATTR_PURE;
/* Similar to var_get_key(), but works for long keys as well. For single char
   keys size=1, while for e.g. %{key} size=3 and idx points to 'k'. */
void var_get_key_range(const char *str, unsigned int *idx_r,
		       unsigned int *size_r);
/* Returns TRUE if key variable is used in the string.
   If key is '\0', it's ignored. If long_key is NULL, it's ignored. */
bool var_has_key(const char *str, char key, const char *long_key) ATTR_PURE;

#endif