7 /* read MSG_STATS from stream
9 /* #include <msg_stats.h>
11 /* int msg_stats_scan(scan_fn, stream, flags, ptr)
12 /* ATTR_SCAN_MASTER_FN scan_fn;
17 /* msg_stats_scan() reads an MSG_STATS from the named stream
18 /* using the specified attribute scan routine. msg_stats_scan()
19 /* is meant to be passed as a call-back to attr_scan(), thusly:
21 /* ... ATTR_SCAN_FUNC, msg_stats_scan, (void *) &stats, ...
23 /* Fatal: out of memory.
27 /* The Secure Mailer license must be distributed with this software.
30 /* IBM T.J. Watson Research
32 /* Yorktown Heights, NY 10598, USA
39 /* Utility library. */
47 #include <mail_proto.h>
48 #include <msg_stats.h>
53 #define STR(x) vstring_str(x)
54 #define LEN(x) VSTRING_LEN(x)
56 /* msg_stats_scan - read MSG_STATS from stream */
58 int msg_stats_scan(ATTR_SCAN_MASTER_FN scan_fn
, VSTREAM
*fp
,
61 MSG_STATS
*stats
= (MSG_STATS
*) ptr
;
62 VSTRING
*buf
= vstring_alloc(sizeof(MSG_STATS
) * 2);
66 * Receive the entire structure. This is not only simpler but also likely
67 * to be quicker than having the sender figure out what fields need to be
68 * sent, converting those numbers to string and back, and having the
69 * receiver initialize the unused fields by hand.
71 * XXX Would be nice if VSTRINGs could import a fixed-size buffer and
72 * gracefully reject attempts to extend it.
74 ret
= scan_fn(fp
, flags
| ATTR_FLAG_MORE
,
75 ATTR_TYPE_DATA
, MAIL_ATTR_TIME
, buf
,
78 if (LEN(buf
) == sizeof(*stats
)) {
79 memcpy((char *) stats
, STR(buf
), sizeof(*stats
));
81 msg_warn("msg_stats_scan: size mis-match: %u != %u",
82 (unsigned) LEN(buf
), (unsigned) sizeof(*stats
));