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