Postfix3.3.1
tok822_rewrite.c
[詳解]
1 /*++
2 /* NAME
3 /* tok822_rewrite 3
4 /* SUMMARY
5 /* address rewriting, client interface
6 /* SYNOPSIS
7 /* #include <tok822.h>
8 /*
9 /* TOK822 *tok822_rewrite(addr, how)
10 /* TOK822 *addr;
11 /* char *how;
12 /* DESCRIPTION
13 /* tok822_rewrite() takes an address token tree and transforms
14 /* it according to the rule set specified via \fIhow\fR. The
15 /* result is the \fIaddr\fR argument.
16 /* LICENSE
17 /* .ad
18 /* .fi
19 /* The Secure Mailer license must be distributed with this software.
20 /* AUTHOR(S)
21 /* Wietse Venema
22 /* IBM T.J. Watson Research
23 /* P.O. Box 704
24 /* Yorktown Heights, NY 10598, USA
25 /*--*/
26 
27 /* System library. */
28 
29 #include <sys_defs.h>
30 
31 /* Utility library. */
32 
33 #include <vstring.h>
34 #include <msg.h>
35 
36 /* Global library. */
37 
38 #include "rewrite_clnt.h"
39 #include "tok822.h"
40 
41 /* tok822_rewrite - address rewriting interface */
42 
43 TOK822 *tok822_rewrite(TOK822 *addr, const char *how)
44 {
45  VSTRING *input_ext_form = vstring_alloc(100);
46  VSTRING *canon_ext_form = vstring_alloc(100);
47 
48  if (addr->type != TOK822_ADDR)
49  msg_panic("tok822_rewrite: non-address token type: %d", addr->type);
50 
51  /*
52  * Externalize the token tree, ship it to the rewrite service, and parse
53  * the result. Shipping external form is much simpler than shipping parse
54  * trees.
55  */
56  tok822_externalize(input_ext_form, addr->head, TOK822_STR_DEFL);
57  if (msg_verbose)
58  msg_info("tok822_rewrite: input: %s", vstring_str(input_ext_form));
59  rewrite_clnt(how, vstring_str(input_ext_form), canon_ext_form);
60  if (msg_verbose)
61  msg_info("tok822_rewrite: result: %s", vstring_str(canon_ext_form));
62  tok822_free_tree(addr->head);
63  addr->head = tok822_scan(vstring_str(canon_ext_form), &addr->tail);
64 
65  vstring_free(input_ext_form);
66  vstring_free(canon_ext_form);
67  return (addr);
68 }
int msg_verbose
Definition: msg.c:177
#define TOK822_ADDR
Definition: tok822.h:46
NORETURN msg_panic(const char *fmt,...)
Definition: msg.c:295
#define vstring_str(vp)
Definition: vstring.h:71
#define tok822_scan(cp, ptr)
Definition: tok822.h:83
Definition: tok822.h:27
TOK822 * tok822_free_tree(TOK822 *)
Definition: tok822_tree.c:262
struct TOK822 * head
Definition: tok822.h:32
int type
Definition: tok822.h:28
VSTRING * vstring_alloc(ssize_t len)
Definition: vstring.c:353
VSTRING * tok822_externalize(VSTRING *, TOK822 *, int)
Definition: tok822_parse.c:270
#define TOK822_STR_DEFL
Definition: tok822.h:91
VSTRING * vstring_free(VSTRING *vp)
Definition: vstring.c:380
TOK822 * tok822_rewrite(TOK822 *addr, const char *how)
VSTRING * rewrite_clnt(const char *rule, const char *addr, VSTRING *result)
Definition: rewrite_clnt.c:82
void msg_info(const char *fmt,...)
Definition: msg.c:199
struct TOK822 * tail
Definition: tok822.h:33