Postfix3.3.1
cleanup_rewrite.c
[詳解]
1 /*++
2 /* NAME
3 /* cleanup_rewrite 3
4 /* SUMMARY
5 /* address canonicalization
6 /* SYNOPSIS
7 /* #include <cleanup.h>
8 /*
9 /* int cleanup_rewrite_external(context_name, result, addr)
10 /* const char *context;
11 /* VSTRING *result;
12 /* const char *addr;
13 /*
14 /* int cleanup_rewrite_internal(context_name, result, addr)
15 /* const char *context;
16 /* VSTRING *result;
17 /* const char *addr;
18 /*
19 /* int cleanup_rewrite_tree(context_name, tree)
20 /* const char *context;
21 /* TOK822 *tree;
22 /* DESCRIPTION
23 /* This module rewrites addresses to canonical form, adding missing
24 /* domains and stripping source routes etc., and performs
25 /* \fIcanonical\fR map lookups to map addresses to official form.
26 /* These functions return non-zero when the address was changed.
27 /*
28 /* cleanup_rewrite_init() performs one-time initialization.
29 /*
30 /* cleanup_rewrite_external() rewrites the external (quoted) string
31 /* form of an address.
32 /*
33 /* cleanup_rewrite_internal() is a wrapper around the
34 /* cleanup_rewrite_external() routine that transforms from
35 /* internal (quoted) string form to external form and back.
36 /*
37 /* cleanup_rewrite_tree() is a wrapper around the
38 /* cleanup_rewrite_external() routine that transforms from
39 /* internal parse tree form to external form and back.
40 /*
41 /* Arguments:
42 /* .IP context_name
43 /* The name of an address rewriting context that supplies
44 /* the equivalents of myorigin and mydomain.
45 /* .IP result
46 /* Result buffer.
47 /* .IP addr
48 /* Input buffer.
49 /* DIAGNOSTICS
50 /* LICENSE
51 /* .ad
52 /* .fi
53 /* The Secure Mailer license must be distributed with this software.
54 /* AUTHOR(S)
55 /* Wietse Venema
56 /* IBM T.J. Watson Research
57 /* P.O. Box 704
58 /* Yorktown Heights, NY 10598, USA
59 /*--*/
60 
61 /* System library. */
62 
63 #include <sys_defs.h>
64 
65 /* Utility library. */
66 
67 #include <msg.h>
68 #include <vstring.h>
69 
70 /* Global library. */
71 
72 #include <tok822.h>
73 #include <rewrite_clnt.h>
74 #include <quote_822_local.h>
75 
76 /* Application-specific. */
77 
78 #include "cleanup.h"
79 
80 #define STR vstring_str
81 
82 /* cleanup_rewrite_external - rewrite address external form */
83 
84 int cleanup_rewrite_external(const char *context_name, VSTRING *result,
85  const char *addr)
86 {
87  rewrite_clnt(context_name, addr, result);
88  return (strcmp(STR(result), addr) != 0);
89 }
90 
91 /* cleanup_rewrite_tree - rewrite address node */
92 
93 int cleanup_rewrite_tree(const char *context_name, TOK822 *tree)
94 {
95  VSTRING *dst = vstring_alloc(100);
96  VSTRING *src = vstring_alloc(100);
97  int did_rewrite;
98 
100  did_rewrite = cleanup_rewrite_external(context_name, dst, STR(src));
101  tok822_free_tree(tree->head);
102  tree->head = tok822_scan(STR(dst), &tree->tail);
103  vstring_free(dst);
104  vstring_free(src);
105  return (did_rewrite);
106 }
107 
108 /* cleanup_rewrite_internal - rewrite address internal form */
109 
110 int cleanup_rewrite_internal(const char *context_name,
111  VSTRING *result, const char *addr)
112 {
113  VSTRING *dst = vstring_alloc(100);
114  VSTRING *src = vstring_alloc(100);
115  int did_rewrite;
116 
117  quote_822_local(src, addr);
118  did_rewrite = cleanup_rewrite_external(context_name, dst, STR(src));
119  unquote_822_local(result, STR(dst));
120  vstring_free(dst);
121  vstring_free(src);
122  return (did_rewrite);
123 }
#define tok822_scan(cp, ptr)
Definition: tok822.h:83
Definition: tok822.h:27
VSTRING * unquote_822_local(VSTRING *dst, const char *mbox)
TOK822 * tok822_free_tree(TOK822 *)
Definition: tok822_tree.c:262
#define STR
int cleanup_rewrite_external(const char *context_name, VSTRING *result, const char *addr)
struct TOK822 * head
Definition: tok822.h:32
VSTRING * vstring_alloc(ssize_t len)
Definition: vstring.c:353
VSTRING * tok822_externalize(VSTRING *, TOK822 *, int)
Definition: tok822_parse.c:270
int cleanup_rewrite_internal(const char *context_name, VSTRING *result, const char *addr)
#define TOK822_STR_DEFL
Definition: tok822.h:91
#define quote_822_local(dst, src)
VSTRING * vstring_free(VSTRING *vp)
Definition: vstring.c:380
VSTRING * rewrite_clnt(const char *rule, const char *addr, VSTRING *result)
Definition: rewrite_clnt.c:82
int cleanup_rewrite_tree(const char *context_name, TOK822 *tree)
struct TOK822 * tail
Definition: tok822.h:33