No empty .Rs/.Re
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / rcpt_buf.c
blobffa2745a815a17ab98c044b71866a004705fda95
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* rcpt_buf
6 /* SUMMARY
7 /* recipient buffer manager
8 /* SYNOPSIS
9 /* #include <rcpt_buf.h>
11 /* typedef struct {
12 /* RECIPIENT rcpt; /* convenience */
13 /* .in +4
14 /* VSTRING *address; /* final recipient */
15 /* VSTRING *orig_addr; /* original recipient */
16 /* VSTRING *dsn_orcpt; /* dsn original recipient */
17 /* int dsn_notify; /* DSN notify flags */
18 /* long offset; /* REC_TYPE_RCPT byte */
19 /* .in -4
20 /* } RCPT_BUF;
22 /* RECIPIENT *RECIPIENT_FROM_RCPT_BUF(rcpb)
23 /* RCPT_BUF *rcpb;
25 /* RCPT_BUF *rcpb_create(void)
27 /* void rcpb_reset(rcpb)
28 /* RCPT_BUF *rcpb;
30 /* void rcpb_free(rcpb)
31 /* RCPT_BUF *rcpb;
33 /* int rcpb_scan(scan_fn, stream, flags, ptr)
34 /* ATTR_SCAN_MASTER_FN scan_fn;
35 /* VSTREAM *stream;
36 /* int flags;
37 /* void *ptr;
38 /* DESCRIPTION
39 /* RECIPIENT_FROM_RCPT_BUF() populates the rcpt member with
40 /* a shallow copy of the contents of the other fields.
42 /* rcpb_scan() reads a recipient buffer from the named stream
43 /* using the specified attribute scan routine. rcpb_scan()
44 /* is meant to be passed as a call-back to attr_scan(), thusly:
46 /* ... ATTR_TYPE_FUNC, rcpb_scan, (void *) rcpt_buf, ...
48 /* rcpb_create(), rcpb_reset() and rcpb_free() create, wipe
49 /* and destroy recipient buffer instances.
50 /* DIAGNOSTICS
51 /* Fatal: out of memory.
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 /* Syste, library. */
65 #include <sys_defs.h>
67 /* Utility library. */
69 #include <mymalloc.h>
70 #include <vstring.h>
71 #include <vstream.h>
73 /* Global library. */
75 #include <mail_proto.h>
76 #include <rcpt_buf.h>
78 /* Application-specific. */
80 /* rcpb_create - create recipient buffer */
82 RCPT_BUF *rcpb_create(void)
84 RCPT_BUF *rcpt;
86 rcpt = (RCPT_BUF *) mymalloc(sizeof(*rcpt));
87 rcpt->offset = 0;
88 rcpt->dsn_orcpt = vstring_alloc(10);
89 rcpt->dsn_notify = 0;
90 rcpt->orig_addr = vstring_alloc(10);
91 rcpt->address = vstring_alloc(10);
92 return (rcpt);
95 /* rcpb_reset - reset recipient buffer */
97 void rcpb_reset(RCPT_BUF *rcpt)
99 #define BUF_TRUNCATE(s) (vstring_str(s)[0] = 0)
101 rcpt->offset = 0;
102 BUF_TRUNCATE(rcpt->dsn_orcpt);
103 rcpt->dsn_notify = 0;
104 BUF_TRUNCATE(rcpt->orig_addr);
105 BUF_TRUNCATE(rcpt->address);
108 /* rcpb_free - destroy recipient buffer */
110 void rcpb_free(RCPT_BUF *rcpt)
112 vstring_free(rcpt->dsn_orcpt);
113 vstring_free(rcpt->orig_addr);
114 vstring_free(rcpt->address);
115 myfree((char *) rcpt);
118 /* rcpb_scan - receive recipient buffer */
120 int rcpb_scan(ATTR_SCAN_MASTER_FN scan_fn, VSTREAM *fp,
121 int flags, void *ptr)
123 RCPT_BUF *rcpt = (RCPT_BUF *) ptr;
124 int ret;
127 * The order of attributes is determined by historical compatibility and
128 * can be fixed after all the ad-hoc read/write code is replaced.
130 ret = scan_fn(fp, flags | ATTR_FLAG_MORE,
131 ATTR_TYPE_STR, MAIL_ATTR_ORCPT, rcpt->orig_addr,
132 ATTR_TYPE_STR, MAIL_ATTR_RECIP, rcpt->address,
133 ATTR_TYPE_LONG, MAIL_ATTR_OFFSET, &rcpt->offset,
134 ATTR_TYPE_STR, MAIL_ATTR_DSN_ORCPT, rcpt->dsn_orcpt,
135 ATTR_TYPE_INT, MAIL_ATTR_DSN_NOTIFY, &rcpt->dsn_notify,
136 ATTR_TYPE_END);
137 return (ret == 5 ? 1 : -1);