Update all copyright messages to cover 1995 - 2009. Remove tab from exim_checkaccess.src
[exim.git] / src / src / routers / rf_get_transport.c
CommitLineData
0a49a7a4 1/* $Cambridge: exim/src/src/routers/rf_get_transport.c,v 1.5 2009/11/16 19:50:38 nm4 Exp $ */
0756eb3c
PH
2
3/*************************************************
4* Exim - an Internet mail transport agent *
5*************************************************/
6
0a49a7a4 7/* Copyright (c) University of Cambridge 1995 - 2009 */
0756eb3c
PH
8/* See the file NOTICE for conditions of use and distribution. */
9
10#include "../exim.h"
11#include "rf_functions.h"
12
13
14/*************************************************
15* Get transport for a router *
16*************************************************/
17
18/* If transport_name contains $, it must be expanded each time and used as a
19transport name. Otherwise, look up the transport only if the destination is not
20already set.
21
22Some routers (e.g. accept) insist that their transport option is set at
23initialization time. However, for some (e.g. file_transport in redirect), there
24is no such check, because the transport may not be required. Calls to this
25function from the former type of router have require_name = NULL, because it
26will never be used. NULL is also used in verify_only cases, where a transport
27is not required.
28
29Arguments:
30 tpname the text of the transport name
31 tpptr where to put the transport
32 addr the address being processed
33 router_name for error messages
34 require_name used in the error message if transport is unset
35
36Returns: TRUE if *tpptr is already set and tpname has no '$' in it;
37 TRUE if a transport has been placed in tpptr;
38 FALSE if there's a problem, in which case
39 addr->message contains a message, and addr->basic_errno has
40 ERRNO_BADTRANSPORT set in it.
41*/
42
43BOOL
44rf_get_transport(uschar *tpname, transport_instance **tpptr, address_item *addr,
45 uschar *router_name, uschar *require_name)
46{
47uschar *ss;
48BOOL expandable;
49transport_instance *tp;
50
51if (tpname == NULL)
52 {
53 if (require_name == NULL) return TRUE;
54 addr->basic_errno = ERRNO_BADTRANSPORT;
55 addr->message = string_sprintf("%s unset in %s router", require_name,
56 router_name);
57 return FALSE;
58 }
59
60expandable = Ustrchr(tpname, '$') != NULL;
61if (*tpptr != NULL && !expandable) return TRUE;
62
63if (expandable)
64 {
65 ss = expand_string(tpname);
66 if (ss == NULL)
67 {
68 addr->basic_errno = ERRNO_BADTRANSPORT;
69 addr->message = string_sprintf("failed to expand transport "
70 "\"%s\" in %s router: %s", tpname, router_name, expand_string_message);
71 return FALSE;
72 }
73 }
74else ss = tpname;
75
76for (tp = transports; tp != NULL; tp = tp->next)
77 {
78 if (Ustrcmp(tp->name, ss) == 0)
79 {
80 DEBUG(D_route) debug_printf("set transport %s\n", ss);
81 *tpptr = tp;
82 return TRUE;
83 }
84 }
85
86addr->basic_errno = ERRNO_BADTRANSPORT;
87addr->message = string_sprintf("transport \"%s\" not found in %s router", ss,
88 router_name);
89return FALSE;
90}
91
92/* End of rf_get_transport.c */