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