Mercurial > notdcc
comparison dcclib/type2str.c @ 0:c7f6b056b673
First import of vendor version
author | Peter Gervai <grin@grin.hu> |
---|---|
date | Tue, 10 Mar 2009 13:49:58 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c7f6b056b673 |
---|---|
1 /* Distributed Checksum Clearinghouse | |
2 * | |
3 * Copyright (c) 2008 by Rhyolite Software, LLC | |
4 * | |
5 * This agreement is not applicable to any entity which sells anti-spam | |
6 * solutions to others or provides an anti-spam solution as part of a | |
7 * security solution sold to other entities, or to a private network | |
8 * which employs the DCC or uses data provided by operation of the DCC | |
9 * but does not provide corresponding data to other users. | |
10 * | |
11 * Permission to use, copy, modify, and distribute this software without | |
12 * changes for any purpose with or without fee is hereby granted, provided | |
13 * that the above copyright notice and this permission notice appear in all | |
14 * copies and any distributed versions or copies are either unchanged | |
15 * or not called anything similar to "DCC" or "Distributed Checksum | |
16 * Clearinghouse". | |
17 * | |
18 * Parties not eligible to receive a license under this agreement can | |
19 * obtain a commercial license to use DCC by contacting Rhyolite Software | |
20 * at sales@rhyolite.com. | |
21 * | |
22 * A commercial license would be for Distributed Checksum and Reputation | |
23 * Clearinghouse software. That software includes additional features. This | |
24 * free license for Distributed ChecksumClearinghouse Software does not in any | |
25 * way grant permision to use Distributed Checksum and Reputation Clearinghouse | |
26 * software | |
27 * | |
28 * THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL | |
29 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | |
30 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC | |
31 * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES | |
32 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
33 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | |
34 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |
35 * SOFTWARE. | |
36 * | |
37 * Rhyolite Software DCC 1.3.103-1.23 $Revision$ | |
38 */ | |
39 | |
40 #include "dcc_defs.h" | |
41 #include "dcc_xhdr.h" | |
42 | |
43 char * | |
44 dcc_type2str(char *buf, u_int buf_len, /* put it here */ | |
45 DCC_CK_TYPES type, /* this type */ | |
46 const char *sub_str, /* sub-type for DCC_CK_SUB */ | |
47 u_char is_db, /* 0=whitelist 1=database */ | |
48 u_char is_grey_db) /* 1=greylist DB */ | |
49 { | |
50 #define PCK(t) case DCC_CK_##t: \ | |
51 STRLCPY(buf,DCC_XHDR_TYPE_##t,buf_len); \ | |
52 return buf; | |
53 #define PCK2(c,sw,t1,t2) case DCC_CK_##c: \ | |
54 if (!sw) \ | |
55 STRLCPY(buf,DCC_XHDR_TYPE_##t1,buf_len); \ | |
56 else \ | |
57 STRLCPY(buf,DCC_XHDR_TYPE_##t2,buf_len); \ | |
58 return buf; | |
59 | |
60 switch (type) { | |
61 PCK(IP) | |
62 PCK(ENV_FROM) | |
63 PCK(FROM) | |
64 PCK(MESSAGE_ID) | |
65 PCK(RECEIVED) | |
66 PCK(BODY) | |
67 PCK(FUZ1) | |
68 PCK(FUZ2) | |
69 PCK2(G_MSG_R_TOTAL, is_grey_db, REP_TOTAL, GREY_MSG) | |
70 PCK2(G_TRIPLE_R_BULK, is_grey_db, REP_BULK, GREY_TRIPLE) | |
71 PCK(SRVR_ID) | |
72 PCK2(FLOD_PATH, is_db, ENV_TO, FLOD_PATH) | |
73 case DCC_CK_SUB: | |
74 if (sub_str) | |
75 snprintf(buf, buf_len, DCC_XHDR_TYPE_SUB" %s", | |
76 sub_str); | |
77 else | |
78 snprintf(buf, buf_len, DCC_XHDR_TYPE_SUB); | |
79 return buf; | |
80 case DCC_CK_INVALID: | |
81 break; | |
82 } | |
83 | |
84 snprintf(buf, buf_len, "unknown %d", type); | |
85 return buf; | |
86 #undef PCK | |
87 #undef PCK2 | |
88 } | |
89 | |
90 | |
91 | |
92 /* use sparingly for error messages since it is not thread safe */ | |
93 const char * | |
94 dcc_type2str_err(DCC_CK_TYPES type, /* type to convert to a string */ | |
95 const char *sub_str, /* sub-type for DCC_CK_SUB */ | |
96 u_char is_db, /* 0=whitelist 1=database */ | |
97 u_char is_grey_db) /* 1=greylist DB */ | |
98 { | |
99 static int bufno; | |
100 static struct { | |
101 char str[DCC_XHDR_MAX_TYPE_LEN+1]; | |
102 } bufs[4]; | |
103 char *s; | |
104 | |
105 s = bufs[bufno].str; | |
106 bufno = (bufno+1) % DIM(bufs); | |
107 | |
108 return dcc_type2str(s, sizeof(bufs[0].str), | |
109 type, sub_str, is_db, is_grey_db); | |
110 } |