No empty .Rs/.Re
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / cleanup / cleanup_rewrite.c
blobd1e7a5dca33ed010efe2dadf7509b3c0cb7b7bfb
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* cleanup_rewrite 3
6 /* SUMMARY
7 /* address canonicalization
8 /* SYNOPSIS
9 /* #include <cleanup.h>
11 /* int cleanup_rewrite_external(context_name, result, addr)
12 /* const char *context;
13 /* VSTRING *result;
14 /* const char *addr;
16 /* int cleanup_rewrite_internal(context_name, result, addr)
17 /* const char *context;
18 /* VSTRING *result;
19 /* const char *addr;
21 /* int cleanup_rewrite_tree(context_name, tree)
22 /* const char *context;
23 /* TOK822 *tree;
24 /* DESCRIPTION
25 /* This module rewrites addresses to canonical form, adding missing
26 /* domains and stripping source routes etc., and performs
27 /* \fIcanonical\fR map lookups to map addresses to official form.
28 /* These functions return non-zero when the address was changed.
30 /* cleanup_rewrite_init() performs one-time initialization.
32 /* cleanup_rewrite_external() rewrites the external (quoted) string
33 /* form of an address.
35 /* cleanup_rewrite_internal() is a wrapper around the
36 /* cleanup_rewrite_external() routine that transforms from
37 /* internal (quoted) string form to external form and back.
39 /* cleanup_rewrite_tree() is a wrapper around the
40 /* cleanup_rewrite_external() routine that transforms from
41 /* internal parse tree form to external form and back.
43 /* Arguments:
44 /* .IP context_name
45 /* The name of an address rewriting context that supplies
46 /* the equivalents of myorigin and mydomain.
47 /* .IP result
48 /* Result buffer.
49 /* .IP addr
50 /* Input buffer.
51 /* DIAGNOSTICS
52 /* LICENSE
53 /* .ad
54 /* .fi
55 /* The Secure Mailer license must be distributed with this software.
56 /* AUTHOR(S)
57 /* Wietse Venema
58 /* IBM T.J. Watson Research
59 /* P.O. Box 704
60 /* Yorktown Heights, NY 10598, USA
61 /*--*/
63 /* System library. */
65 #include <sys_defs.h>
67 /* Utility library. */
69 #include <msg.h>
70 #include <vstring.h>
72 /* Global library. */
74 #include <tok822.h>
75 #include <rewrite_clnt.h>
76 #include <quote_822_local.h>
78 /* Application-specific. */
80 #include "cleanup.h"
82 #define STR vstring_str
84 /* cleanup_rewrite_external - rewrite address external form */
86 int cleanup_rewrite_external(const char *context_name, VSTRING *result,
87 const char *addr)
89 rewrite_clnt(context_name, addr, result);
90 return (strcmp(STR(result), addr) != 0);
93 /* cleanup_rewrite_tree - rewrite address node */
95 int cleanup_rewrite_tree(const char *context_name, TOK822 *tree)
97 VSTRING *dst = vstring_alloc(100);
98 VSTRING *src = vstring_alloc(100);
99 int did_rewrite;
101 tok822_externalize(src, tree->head, TOK822_STR_DEFL);
102 did_rewrite = cleanup_rewrite_external(context_name, dst, STR(src));
103 tok822_free_tree(tree->head);
104 tree->head = tok822_scan(STR(dst), &tree->tail);
105 vstring_free(dst);
106 vstring_free(src);
107 return (did_rewrite);
110 /* cleanup_rewrite_internal - rewrite address internal form */
112 int cleanup_rewrite_internal(const char *context_name,
113 VSTRING *result, const char *addr)
115 VSTRING *dst = vstring_alloc(100);
116 VSTRING *src = vstring_alloc(100);
117 int did_rewrite;
119 quote_822_local(src, addr);
120 did_rewrite = cleanup_rewrite_external(context_name, dst, STR(src));
121 unquote_822_local(result, STR(dst));
122 vstring_free(dst);
123 vstring_free(src);
124 return (did_rewrite);