Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / smtp / smtp_map11.c
blob2406a9adf15b7086545211b6038608260555b2fd
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* smtp_map11 3
6 /* SUMMARY
7 /* one-to-one address mapping
8 /* SYNOPSIS
9 /* #include <smtp.h>
11 /* int smtp_map11_external(addr, maps, propagate)
12 /* VSTRING *addr;
13 /* MAPS *maps;
14 /* int propagate;
16 /* int smtp_map11_internal(addr, maps, propagate)
17 /* VSTRING *addr;
18 /* MAPS *maps;
19 /* int propagate;
21 /* int smtp_map11_tree(tree, maps, propagate)
22 /* TOK822 *tree;
23 /* MAPS *maps;
24 /* int propagate;
25 /* DESCRIPTION
26 /* This module performs non-recursive one-to-one address mapping.
27 /* An unmatched address extension is propagated when
28 /* \fIpropagate\fR is non-zero.
30 /* smtp_map11_external() looks up the RFC 822 external (quoted) string
31 /* form of an address in the maps specified via the \fImaps\fR argument.
33 /* smtp_map11_internal() is a wrapper around the
34 /* smtp_map11_external() routine that transforms from
35 /* internal (quoted) string form to external form and back.
37 /* smtp_map11_tree() is a wrapper around the
38 /* smtp_map11_external() routine that transforms from
39 /* internal parse tree form to external form and back.
40 /* DIAGNOSTICS
41 /* Table lookup errors are fatal.
42 /* SEE ALSO
43 /* mail_addr_map(3) address mappings
44 /* LICENSE
45 /* .ad
46 /* .fi
47 /* The Secure Mailer license must be distributed with this software.
48 /* AUTHOR(S)
49 /* Wietse Venema
50 /* IBM T.J. Watson Research
51 /* P.O. Box 704
52 /* Yorktown Heights, NY 10598, USA
53 /*--*/
55 /* System library. */
57 #include <sys_defs.h>
58 #include <string.h>
60 /* Utility library. */
62 #include <msg.h>
63 #include <vstring.h>
64 #include <dict.h>
65 #include <argv.h>
66 #include <tok822.h>
67 #include <valid_hostname.h>
69 /* Global library. */
71 #include <mail_addr_map.h>
72 #include <quote_822_local.h>
74 /* Application-specific. */
76 #include <smtp.h>
78 /* smtp_map11_external - one-to-one table lookups */
80 int smtp_map11_external(VSTRING *addr, MAPS *maps, int propagate)
82 const char *myname = "smtp_map11_external";
83 ARGV *new_addr;
84 const char *result;
86 if ((new_addr = mail_addr_map(maps, STR(addr), propagate)) != 0) {
87 if (new_addr->argc > 1)
88 msg_warn("multi-valued %s result for %s", maps->title, STR(addr));
89 result = new_addr->argv[0];
90 if (msg_verbose)
91 msg_info("%s: %s -> %s", myname, STR(addr), result);
92 vstring_strcpy(addr, result);
93 argv_free(new_addr);
94 return (1);
95 } else {
96 if (dict_errno != 0)
97 msg_fatal("%s map lookup problem for %s", maps->title, STR(addr));
98 if (msg_verbose)
99 msg_info("%s: %s not found", myname, STR(addr));
100 return (0);
104 /* smtp_map11_tree - rewrite address node */
106 int smtp_map11_tree(TOK822 *tree, MAPS *maps, int propagate)
108 VSTRING *temp = vstring_alloc(100);
109 int ret;
111 tok822_externalize(temp, tree->head, TOK822_STR_DEFL);
112 ret = smtp_map11_external(temp, maps, propagate);
113 tok822_free_tree(tree->head);
114 tree->head = tok822_scan(STR(temp), &tree->tail);
115 vstring_free(temp);
116 return (ret);
119 /* smtp_map11_internal - rewrite address internal form */
121 int smtp_map11_internal(VSTRING *addr, MAPS *maps, int propagate)
123 VSTRING *temp = vstring_alloc(100);
124 int ret;
126 quote_822_local(temp, STR(addr));
127 ret = smtp_map11_external(temp, maps, propagate);
128 unquote_822_local(addr, STR(temp));
129 vstring_free(temp);
130 return (ret);
133 #ifdef TEST
135 #include <msg_vstream.h>
136 #include <stringops.h>
137 #include <mail_params.h>
139 int main(int argc, char **argv)
141 VSTRING *buf = vstring_alloc(100);
142 MAPS *maps;
144 msg_vstream_init(basename(argv[0]), VSTREAM_ERR);
145 if (argc < 3)
146 msg_fatal("usage: %s maptype:mapname address...", argv[0]);
148 maps = maps_create(argv[1], argv[1], DICT_FLAG_FOLD_FIX);
149 mail_params_init();
150 if (chdir(var_queue_dir) < 0)
151 msg_fatal("chdir(%s): %m", var_queue_dir);
152 argv += 1;
154 msg_verbose = 1;
155 while (--argc && *++argv) {
156 msg_info("-- start %s --", *argv);
157 smtp_map11_external(vstring_strcpy(buf, *argv), maps, 1);
158 msg_info("-- end %s --", *argv);
160 vstring_free(buf);
161 maps_free(maps);
162 return (0);
165 #endif