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