Postfix3.3.1
rcpt_buf.c
[詳解]
1 /*++
2 /* NAME
3 /* rcpt_buf
4 /* SUMMARY
5 /* recipient buffer manager
6 /* SYNOPSIS
7 /* #include <rcpt_buf.h>
8 /*
9 /* typedef struct {
10 /* RECIPIENT rcpt; /* convenience */
11 /* .in +4
12 /* VSTRING *address; /* final recipient */
13 /* VSTRING *orig_addr; /* original recipient */
14 /* VSTRING *dsn_orcpt; /* dsn original recipient */
15 /* int dsn_notify; /* DSN notify flags */
16 /* long offset; /* REC_TYPE_RCPT byte */
17 /* .in -4
18 /* } RCPT_BUF;
19 /*
20 /* RECIPIENT *RECIPIENT_FROM_RCPT_BUF(rcpb)
21 /* RCPT_BUF *rcpb;
22 /*
23 /* RCPT_BUF *rcpb_create(void)
24 /*
25 /* void rcpb_reset(rcpb)
26 /* RCPT_BUF *rcpb;
27 /*
28 /* void rcpb_free(rcpb)
29 /* RCPT_BUF *rcpb;
30 /*
31 /* int rcpb_scan(scan_fn, stream, flags, ptr)
32 /* ATTR_SCAN_MASTER_FN scan_fn;
33 /* VSTREAM *stream;
34 /* int flags;
35 /* void *ptr;
36 /* DESCRIPTION
37 /* RECIPIENT_FROM_RCPT_BUF() populates the rcpt member with
38 /* a shallow copy of the contents of the other fields.
39 /*
40 /* rcpb_scan() reads a recipient buffer from the named stream
41 /* using the specified attribute scan routine. rcpb_scan()
42 /* is meant to be passed as a call-back to attr_scan(), thusly:
43 /*
44 /* ... ATTR_TYPE_FUNC, rcpb_scan, (void *) rcpt_buf, ...
45 /*
46 /* rcpb_create(), rcpb_reset() and rcpb_free() create, wipe
47 /* and destroy recipient buffer instances.
48 /* DIAGNOSTICS
49 /* Fatal: out of memory.
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 <mymalloc.h>
68 #include <vstring.h>
69 #include <vstream.h>
70 
71 /* Global library. */
72 
73 #include <mail_proto.h>
74 #include <rcpt_buf.h>
75 
76 /* Application-specific. */
77 
78 /* rcpb_create - create recipient buffer */
79 
81 {
82  RCPT_BUF *rcpt;
83 
84  rcpt = (RCPT_BUF *) mymalloc(sizeof(*rcpt));
85  rcpt->offset = 0;
86  rcpt->dsn_orcpt = vstring_alloc(10);
87  rcpt->dsn_notify = 0;
88  rcpt->orig_addr = vstring_alloc(10);
89  rcpt->address = vstring_alloc(10);
90  return (rcpt);
91 }
92 
93 /* rcpb_reset - reset recipient buffer */
94 
95 void rcpb_reset(RCPT_BUF *rcpt)
96 {
97 #define BUF_TRUNCATE(s) (vstring_str(s)[0] = 0)
98 
99  rcpt->offset = 0;
100  BUF_TRUNCATE(rcpt->dsn_orcpt);
101  rcpt->dsn_notify = 0;
102  BUF_TRUNCATE(rcpt->orig_addr);
103  BUF_TRUNCATE(rcpt->address);
104 }
105 
106 /* rcpb_free - destroy recipient buffer */
107 
108 void rcpb_free(RCPT_BUF *rcpt)
109 {
110  vstring_free(rcpt->dsn_orcpt);
111  vstring_free(rcpt->orig_addr);
112  vstring_free(rcpt->address);
113  myfree((void *) rcpt);
114 }
115 
116 /* rcpb_scan - receive recipient buffer */
117 
119  int flags, void *ptr)
120 {
121  RCPT_BUF *rcpt = (RCPT_BUF *) ptr;
122  int ret;
123 
124  /*
125  * The order of attributes is determined by historical compatibility and
126  * can be fixed after all the ad-hoc read/write code is replaced.
127  */
128  ret = scan_fn(fp, flags | ATTR_FLAG_MORE,
134  ATTR_TYPE_END);
135  return (ret == 5 ? 1 : -1);
136 }
#define MAIL_ATTR_DSN_NOTIFY
Definition: mail_proto.h:275
void myfree(void *ptr)
Definition: mymalloc.c:207
#define MAIL_ATTR_ORCPT
Definition: mail_proto.h:133
void rcpb_reset(RCPT_BUF *rcpt)
Definition: rcpt_buf.c:95
#define BUF_TRUNCATE(s)
int rcpb_scan(ATTR_SCAN_MASTER_FN scan_fn, VSTREAM *fp, int flags, void *ptr)
Definition: rcpt_buf.c:118
#define RECV_ATTR_INT(name, val)
Definition: attr.h:71
#define ATTR_TYPE_END
Definition: attr.h:39
VSTRING * dsn_orcpt
Definition: rcpt_buf.h:33
RCPT_BUF * rcpb_create(void)
Definition: rcpt_buf.c:80
#define MAIL_ATTR_DSN_ORCPT
Definition: mail_proto.h:276
void rcpb_free(RCPT_BUF *rcpt)
Definition: rcpt_buf.c:108
int dsn_notify
Definition: rcpt_buf.h:34
int(* ATTR_SCAN_MASTER_FN)(VSTREAM *, int,...)
Definition: attr.h:31
VSTRING * address
Definition: rcpt_buf.h:31
#define RECV_ATTR_LONG(name, val)
Definition: attr.h:75
VSTRING * vstring_alloc(ssize_t len)
Definition: vstring.c:353
VSTRING * orig_addr
Definition: rcpt_buf.h:32
#define MAIL_ATTR_RECIP
Definition: mail_proto.h:134
VSTRING * vstring_free(VSTRING *vp)
Definition: vstring.c:380
long offset
Definition: rcpt_buf.h:35
#define ATTR_FLAG_MORE
Definition: attr.h:101
#define MAIL_ATTR_OFFSET
Definition: mail_proto.h:138
#define RECV_ATTR_STR(name, val)
Definition: attr.h:72
void * mymalloc(ssize_t len)
Definition: mymalloc.c:150