comparison dcclib/op2str.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 * convert a DCC opcode to a string
4 *
5 * Copyright (c) 2008 by Rhyolite Software, LLC
6 *
7 * This agreement is not applicable to any entity which sells anti-spam
8 * solutions to others or provides an anti-spam solution as part of a
9 * security solution sold to other entities, or to a private network
10 * which employs the DCC or uses data provided by operation of the DCC
11 * but does not provide corresponding data to other users.
12 *
13 * Permission to use, copy, modify, and distribute this software without
14 * changes for any purpose with or without fee is hereby granted, provided
15 * that the above copyright notice and this permission notice appear in all
16 * copies and any distributed versions or copies are either unchanged
17 * or not called anything similar to "DCC" or "Distributed Checksum
18 * Clearinghouse".
19 *
20 * Parties not eligible to receive a license under this agreement can
21 * obtain a commercial license to use DCC by contacting Rhyolite Software
22 * at sales@rhyolite.com.
23 *
24 * A commercial license would be for Distributed Checksum and Reputation
25 * Clearinghouse software. That software includes additional features. This
26 * free license for Distributed ChecksumClearinghouse Software does not in any
27 * way grant permision to use Distributed Checksum and Reputation Clearinghouse
28 * software
29 *
30 * THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL
31 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
32 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC
33 * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
34 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
35 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
36 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
37 * SOFTWARE.
38 *
39 * Rhyolite Software DCC 1.3.103-1.37 $Revision$
40 */
41
42 #include "dcc_defs.h"
43
44
45
46 const char *
47 dcc_aop2str(char *buf, int buf_len,
48 DCC_AOPS aop,
49 u_int32_t val1) /* host byte order */
50 {
51 switch (aop) {
52 case DCC_AOP_OK: return "ADMN";
53 case DCC_AOP_STOP: return "ADMN STOP";
54 case DCC_AOP_DB_UNLOAD: return "ADMN DB UNLOAD";
55 case DCC_AOP_FLOD:
56 switch ((DCC_AOP_FLODS)(val1 % 256)) {
57 # define RFS(s) return "ADMN FLOD "s
58 case DCC_AOP_FLOD_CHECK: RFS("CHECK");
59 case DCC_AOP_FLOD_SHUTDOWN: RFS("SHUTDOWN");
60 case DCC_AOP_FLOD_HALT: RFS("HALT");
61 case DCC_AOP_FLOD_RESUME: RFS("RESUME");
62 case DCC_AOP_FLOD_REWIND: RFS("REWIND");
63 case DCC_AOP_FLOD_LIST: RFS("LIST");
64 case DCC_AOP_FLOD_STATS: RFS("STATS");
65 case DCC_AOP_FLOD_STATS_CLEAR:RFS("STATS CLEAR");
66 case DCC_AOP_FLOD_FFWD_IN: RFS("FFWD IN");
67 case DCC_AOP_FLOD_FFWD_OUT: RFS("FFWD OUT");
68 # undef RFS
69 }
70 break;
71 case DCC_AOP_DB_CLEAN: return "ADMN DB CLEAN";
72 case DCC_AOP_DB_NEW: return "ADMN DB NEW";
73 case DCC_AOP_STATS: return "ADMN STATS";
74 case DCC_AOP_STATS_CLEAR: return "ADMN STATS CLEAR";
75 case DCC_AOP_TRACE_ON:
76 if (!buf || !buf_len)
77 return "ADMN TRACE ON";
78 snprintf(buf, buf_len, "ADMN TRACE ON %#x", val1);
79 return buf;
80 case DCC_AOP_TRACE_OFF:
81 if (!buf || !buf_len)
82 return "ADMN TRACE OFF";
83 snprintf(buf, buf_len, "ADMN TRACE OFF %#x", val1);
84 return buf;
85 case DCC_AOP_unused1: break;
86 case DCC_AOP_CLIENTS: return "ADMN CLIENTS";
87 case DCC_AOP_CLIENTS_ID: return "ADMN CLIENTS BY ID";
88 case DCC_AOP_ANON_DELAY: return "ADMN ANON DELAY";
89 case DCC_AOP_CLOCK_CHECK: return "ADMN CLOCK CHECK";
90 }
91
92 if (!buf || !buf_len)
93 return "ADMN UNKNOWN ???";
94 snprintf(buf, buf_len,
95 "ADMN UNKNOWN #%d %#x", aop, val1);
96 return buf;
97 }
98
99
100
101 const char *
102 dcc_hdr_op2str(char *buf, int buf_len,
103 const DCC_HDR *hdr) /* all in network byte order */
104 {
105 const char *p;
106 int len, slen, i;
107
108 switch ((DCC_OPS)hdr->op) {
109 case DCC_OP_INVALID: return "INVALID";
110 case DCC_OP_NOP: return "NOP";
111 case DCC_OP_REPORT: return "REPORT";
112 case DCC_OP_QUERY: return "QUERY";
113 case DCC_OP_ANSWER: return "ANSWER";
114 case DCC_OP_ADMN:
115 /* display ASCII results */
116 len = ntohs(hdr->len);
117 slen = len - (sizeof(*hdr) + sizeof(DCC_SIGNATURE));
118 if (slen > 0) {
119 for (p = (char *)(hdr+1), i = slen;
120 i > 0;
121 --i, ++p) {
122 if ((*p < ' ' || *p >= 0x7f)
123 && *p != '\n' && *p != '\t')
124 break;
125 }
126 if (i == 0) {
127 if (!buf || buf_len <= ISZ("ADMN \"...\""))
128 return "ADMN \"...\"";
129 if (slen+ISZ("ADMN \"\"") > buf_len) {
130 slen = buf_len - ISZ("ADMN \"...\"");
131 snprintf(buf, buf_len,
132 "ADMN \"%.*s...\"",
133 slen, (char *)(hdr+1));
134 } else {
135 snprintf(buf, buf_len,
136 "ADMN \"%.*s\"",
137 slen, (char *)(hdr+1));
138 }
139 return buf;
140 }
141 }
142 if (len < DCC_ADMN_REQ_MIN_SIZE)
143 return "ADMIN ???";
144 return dcc_aop2str(buf, buf_len, ((DCC_ADMN_REQ *)hdr)->aop,
145 ntohl(((DCC_ADMN_REQ *)hdr)->val1));
146 case DCC_OP_OK: return "OK";
147 case DCC_OP_ERROR: return "ERROR";
148 case DCC_OP_DELETE: return "DELETE";
149 case DCC_OP_GREY_REPORT:return "GREYLIST REPORT";
150 case DCC_OP_GREY_QUERY: return "GREYLIST QUERY";
151 case DCC_OP_GREY_SPAM: return "GREYLIST SPAM";
152 case DCC_OP_GREY_WHITE: return "GREYLIST WHITELIST";
153 }
154
155 if (!buf || !buf_len)
156 return "unknown op ???";
157 snprintf(buf, buf_len, "unknown op #%d", hdr->op);
158 return buf;
159 }