File: type2str.c

package info (click to toggle)
dcc 1.2.74-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,552 kB
  • ctags: 4,041
  • sloc: ansic: 41,034; perl: 2,310; sh: 2,186; makefile: 224
file content (89 lines) | stat: -rw-r--r-- 2,402 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Distributed Checksum Clearinghouse
 *
 * Copyright (c) 2005 by Rhyolite Software
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE DISCLAIMS ALL
 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE
 * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 *
 * Rhyolite Software DCC 1.2.74-1.16 $Revision$
 */

#include "dcc_defs.h"
#include "dcc_xhdr.h"

char *
dcc_type2str(char *buf, u_int buf_len,	/* put it here */
	     DCC_CK_TYPES type,		/* this type */
	     const char *sub_str,	/* sub-type for DCC_CK_SUB */
	     u_char is_db)		/* 1=database or 0=whitelist */
{
#define PCK(t) case DCC_CK_##t:					\
	STRLIMCPY(buf,buf_len,DCC_XHDR_TYPE_##t);		\
	return buf;
#define PCK2(sw,t1,t2) case DCC_CK_##t1:			\
	if (!sw)						\
		STRLIMCPY(buf,buf_len,DCC_XHDR_TYPE_##t1);	\
	else							\
		STRLIMCPY(buf,buf_len,DCC_XHDR_TYPE_##t2);	\
	return buf;

	switch (type) {
	PCK(IP)
	PCK(ENV_FROM)
	PCK(FROM)
	PCK(MESSAGE_ID)
	PCK(RECEIVED)
	PCK(BODY)
	PCK(FUZ1)
	PCK(FUZ2)
	PCK(GREY_MSG)
	PCK(GREY_TRIPLE)
	PCK(SRVR_ID)
	PCK2(is_db, ENV_TO, FLOD_PATH)
	case DCC_CK_SUB:
		if (sub_str)
			snprintf(buf, buf_len, DCC_XHDR_TYPE_SUB" %s",
				 sub_str);
		else
			snprintf(buf, buf_len, DCC_XHDR_TYPE_SUB);
		return buf;
	case DCC_CK_INVALID:
		break;
	}

	snprintf(buf, buf_len, "unknown %d", type);
	return buf;
#undef PCK
#undef PCK2
}



/* use sparingly for error messages since it is not thread safe */
const char *
dcc_type2str_err(DCC_CK_TYPES type,	/* type to convert to a string */
		 const char *sub_str,	/* sub-type for DCC_CK_SUB */
		 u_char is_db)		/* 1=database or 0=whitelist */
{
	static int bufno;
	static struct {
	    char    str[DCC_XHDR_MAX_TYPE_LEN+1];
	} bufs[4];
	char *s;

	s = bufs[bufno].str;
	bufno = (bufno+1) % DIM(bufs);

	return dcc_type2str(s, sizeof(bufs[0].str),
			    type, sub_str, is_db);
}