SPDX: Mass-update to GPL-2.0-or-later
[exim.git] / src / src / routers / rf_expand_data.c
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /* Copyright (c) University of Cambridge 1995 - 2009 */
6 /* See the file NOTICE for conditions of use and distribution. */
7 /* SPDX-License-Identifier: GPL-2.0-or-later */
8
9
10 #include "../exim.h"
11 #include "rf_functions.h"
12
13
14 /*************************************************
15 *       Expand data string and handle errors     *
16 *************************************************/
17
18 /* This little function is used by a couple of routers for expanding things. It
19 just saves repeating this code too many times. It does an expansion, and
20 chooses a suitable return code on error.
21
22 Arguments:
23   addr       the address that's being routed
24   s          the string to be expanded
25   prc        pointer to where to put the return code on failure
26
27 Returns:     the expanded string, or NULL (with prc set) on failure
28 */
29
30 uschar *
31 rf_expand_data(address_item *addr, uschar *s, int *prc)
32 {
33 uschar *yield = expand_string(s);
34 if (yield != NULL) return yield;
35 if (f.expand_string_forcedfail)
36   {
37   DEBUG(D_route) debug_printf("forced failure for expansion of \"%s\"\n", s);
38   *prc = DECLINE;
39   }
40 else
41   {
42   addr->message = string_sprintf("failed to expand \"%s\": %s", s,
43     expand_string_message);
44   *prc = DEFER;
45   }
46 return NULL;
47 }
48
49 /* End of routers/rf_expand_data.c */