]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-var-expand: Add var_expand_program_execute_one()
authorAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 29 Jan 2026 09:22:12 +0000 (11:22 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 20 Mar 2026 16:11:43 +0000 (16:11 +0000)
Executes first program in expansion program.

src/lib-var-expand/expansion-program.c
src/lib-var-expand/var-expand.h

index 0eb63d76e479ff174366a5e6c3530ed954381b5a..ab3fbae68ea4670294d578f54664ae3ba1fc9441 100644 (file)
@@ -166,6 +166,30 @@ var_expand_program_execute_one_real(const struct var_expand_program *program,
        return ret;
 }
 
+int var_expand_program_execute_one(string_t *dest, const struct var_expand_program *program,
+                                  const struct var_expand_params *params, const char **error_r)
+{
+       int ret = 0;
+       struct var_expand_state state;
+       if (params == NULL)
+               params = &empty_params;
+       prepare_state(params, &state);
+
+       *error_r = NULL;
+
+       ret = var_expand_program_execute_one_real(program, params, &state, error_r);
+
+       str_free(&state.transfer);
+       i_free(state.delayed_error);
+       /* only write to dest on success */
+       if (ret == 0)
+               str_append_str(dest, state.result);
+       str_free(&state.result);
+       i_assert(ret == 0 || *error_r != NULL);
+
+       return ret;
+}
+
 int var_expand_program_execute(string_t *dest, const struct var_expand_program *program,
                               const struct var_expand_params *params, const char **error_r)
  {
index 189811fcfb65026227142cb139c979ff4f20189c..c71fba21b284ad87d4764f2be995cf8aa4c2e62d 100644 (file)
@@ -100,6 +100,10 @@ void var_expand_program_dump(const struct var_expand_program *program, string_t
 int var_expand_program_execute(string_t *dest, const struct var_expand_program *program,
                               const struct var_expand_params *params,
                               const char **error_r) ATTR_NULL(3);
+/* Execute the first program only */
+int var_expand_program_execute_one(string_t *dest, const struct var_expand_program *program,
+                                  const struct var_expand_params *params,
+                                  const char **error_r);
 /* Free up program */
 void var_expand_program_free(struct var_expand_program **_program);