xref: /netbsd-src/external/ibm-public/postfix/dist/src/global/dsb_scan.c (revision 67b9b338a7386232ac596b5fd0cd5a9cc8a03c71)
1 /*	$NetBSD: dsb_scan.c,v 1.3 2022/10/08 16:12:45 christos Exp $	*/
2 
3 /*++
4 /* NAME
5 /*	dsb_scan
6 /* SUMMARY
7 /*	read DSN_BUF from stream
8 /* SYNOPSIS
9 /*	#include <dsb_scan.h>
10 /*
11 /*	int	dsb_scan(scan_fn, stream, flags, ptr)
12 /*	ATTR_SCAN_COMMON_FN scan_fn;
13 /*	VSTREAM *stream;
14 /*	int	flags;
15 /*	void	*ptr;
16 /* DESCRIPTION
17 /*	dsb_scan() reads a DSN_BUF from the named stream using the
18 /*	specified attribute scan routine. dsb_scan() is meant
19 /*	to be passed as a call-back to attr_scan(), thusly:
20 /*
21 /*	... RECV_ATTR_FUNC(dsb_scan, (void *) &dsbuf), ...
22 /* DIAGNOSTICS
23 /*	Fatal: out of memory.
24 /* LICENSE
25 /* .ad
26 /* .fi
27 /*	The Secure Mailer license must be distributed with this software.
28 /* AUTHOR(S)
29 /*	Wietse Venema
30 /*	IBM T.J. Watson Research
31 /*	P.O. Box 704
32 /*	Yorktown Heights, NY 10598, USA
33 /*
34 /*	Wietse Venema
35 /*	Google, Inc.
36 /*	111 8th Avenue
37 /*	New York, NY 10011, USA
38 /*--*/
39 
40 /* System library. */
41 
42 #include <sys_defs.h>
43 
44 /* Utility library. */
45 
46 #include <attr.h>
47 
48 /* Global library. */
49 
50 #include <mail_proto.h>
51 #include <dsb_scan.h>
52 
53 /* dsb_scan - read DSN_BUF from stream */
54 
dsb_scan(ATTR_SCAN_COMMON_FN scan_fn,VSTREAM * fp,int flags,void * ptr)55 int     dsb_scan(ATTR_SCAN_COMMON_FN scan_fn, VSTREAM *fp,
56 		         int flags, void *ptr)
57 {
58     DSN_BUF *dsb = (DSN_BUF *) ptr;
59     int     ret;
60 
61     /*
62      * The attribute order is determined by backwards compatibility. It can
63      * be sanitized after all the ad-hoc DSN read/write code is replaced.
64      */
65     ret = scan_fn(fp, flags | ATTR_FLAG_MORE,
66 		  RECV_ATTR_STR(MAIL_ATTR_DSN_STATUS, dsb->status),
67 		  RECV_ATTR_STR(MAIL_ATTR_DSN_DTYPE, dsb->dtype),
68 		  RECV_ATTR_STR(MAIL_ATTR_DSN_DTEXT, dsb->dtext),
69 		  RECV_ATTR_STR(MAIL_ATTR_DSN_MTYPE, dsb->mtype),
70 		  RECV_ATTR_STR(MAIL_ATTR_DSN_MNAME, dsb->mname),
71 		  RECV_ATTR_STR(MAIL_ATTR_DSN_ACTION, dsb->action),
72 		  RECV_ATTR_STR(MAIL_ATTR_WHY, dsb->reason),
73 		  ATTR_TYPE_END);
74     return (ret == 7 ? 1 : -1);
75 }
76