1 /* $NetBSD: dsn_util.h,v 1.1.1.1 2009/06/23 10:08:46 tron Exp $ */ 2 3 #ifndef _DSN_UTIL_H_INCLUDED_ 4 #define _DSN_UTIL_H_INCLUDED_ 5 6 /*++ 7 /* NAME 8 /* dsn_util 3h 9 /* SUMMARY 10 /* DSN status parsing routines 11 /* SYNOPSIS 12 /* #include <dsn_util.h> 13 /* DESCRIPTION 14 /* .nf 15 16 /* 17 * Utility library. 18 */ 19 #include <vstring.h> 20 21 /* 22 * Detail format is digit "." digit{1,3} "." digit{1,3}. 23 */ 24 #define DSN_DIGS1 1 /* leading digits */ 25 #define DSN_DIGS2 3 /* middle digits */ 26 #define DSN_DIGS3 3 /* trailing digits */ 27 #define DSN_LEN (DSN_DIGS1 + 1 + DSN_DIGS2 + 1 + DSN_DIGS3) 28 #define DSN_SIZE (DSN_LEN + 1) 29 30 /* 31 * Storage for an enhanced status code. Avoid using malloc for itty-bitty 32 * strings with a known size limit. 33 * 34 * XXX gcc version 2 complains about sizeof() as format width specifier. 35 */ 36 typedef struct { 37 char data[DSN_SIZE]; /* NOT a public interface */ 38 } DSN_STAT; 39 40 #define DSN_UPDATE(dsn_buf, dsn, len) do { \ 41 if (len >= sizeof((dsn_buf).data)) \ 42 msg_panic("DSN_UPDATE: bad DSN code \"%.*s...\" length %d", \ 43 INT_SIZEOF((dsn_buf).data) - 1, dsn, len); \ 44 strncpy((dsn_buf).data, (dsn), (len)); \ 45 (dsn_buf).data[len] = 0; \ 46 } while (0) 47 48 #define DSN_STATUS(dsn_buf) ((const char *) (dsn_buf).data) 49 50 #define DSN_CLASS(dsn_buf) ((dsn_buf).data[0]) 51 52 /* 53 * Split flat text into detail code and free text. 54 */ 55 typedef struct { 56 DSN_STAT dsn; /* RFC 3463 status */ 57 const char *text; /* free text */ 58 } DSN_SPLIT; 59 60 extern DSN_SPLIT *dsn_split(DSN_SPLIT *, const char *, const char *); 61 extern size_t dsn_valid(const char *); 62 63 /* 64 * Create flat text from detail code and free text. 65 */ 66 extern char *dsn_prepend(const char *, const char *); 67 68 /* LICENSE 69 /* .ad 70 /* .fi 71 /* The Secure Mailer license must be distributed with this software. 72 /* AUTHOR(S) 73 /* Wietse Venema 74 /* IBM T.J. Watson Research 75 /* P.O. Box 704 76 /* Yorktown Heights, NY 10598, USA 77 /*--*/ 78 79 #endif 80