<commit_before>/*
 * Copyright (C) 1999  Internet Software Consortium.
 * 
 * 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 INTERNET SOFTWARE CONSORTIUM DISCLAIMS
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
 * CONSORTIUM 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.
 */

#include <config.h>

#include <sys/types.h>	/* XXXRTH */

#include <limits.h>
#include <syslog.h>	/* XXXRTH */
#include <ctype.h>
#include <string.h>

#include <isc/assertions.h>
#include <isc/buffer.h>

/* XXX this next include is needed by <dns/rdataclass.h>  */
#include <dns/result.h>

#include <dns/rdataclass.h>
#include <dns/rdatatype.h>

#include <dns/confcommon.h>



/***
 *** TYPES
 ***/
 
#define ordering_nametable_size \
	(sizeof (ordering_nametable) / sizeof (struct dns_c_pvt_ont))
static struct dns_c_pvt_ont {
	dns_c_ordering_t val;
	const char *strval;
} ordering_nametable[] = {
	{ dns_c_ordering_fixed,		"fixed" },
	{ dns_c_ordering_random,	"random" },
	{ dns_c_ordering_cyclic,	"cyclic" }
};


#define log_severity_nametable_size \
	(sizeof (log_severity_nametable) / sizeof (struct dns_c_pvt_lsnt))
static struct dns_c_pvt_lsnt {
	dns_c_logseverity_t val;
	const char *strval;
} log_severity_nametable[] = {
	{ dns_c_log_critical,		"critical" },
	{ dns_c_log_error,		"error" },
	{ dns_c_log_info,		"info" },
	{ dns_c_log_notice,		"notice" },
	{ dns_c_log_warn,		"warning" },
	{ dns_c_log_debug,		"debug" },
	{ dns_c_log_dynamic,		"dynamic" }
};

	
static struct dsn_c_pvt_sfnt {
	int val;
	const char *strval;
} syslog_facil_nametable[] = {
	{ LOG_KERN,			"kern" },
	{ LOG_USER,			"user" },
	{ LOG_MAIL,			"mail" },
	{ LOG_DAEMON,			"daemon" },
	{ LOG_AUTH,			"auth" },
	{ LOG_SYSLOG,			"syslog" },
	{ LOG_LPR,			"lpr" },
#ifdef LOG_NEWS
	{ LOG_NEWS,			"news" },
#endif
#ifdef LOG_UUCP
	{ LOG_UUCP,			"uucp" },
#endif
#ifdef LOG_CRON
	{ LOG_CRON,			"cron" },
#endif
#ifdef LOG_AUTHPRIV
	{ LOG_AUTHPRIV,			"authpriv" },
#endif
#ifdef LOG_FTP
	{ LOG_FTP,			"ftp" },
#endif
	{ LOG_LOCAL0,			"local0"}, 
	{ LOG_LOCAL1,			"local1"}, 
	{ LOG_LOCAL2,			"local2"}, 
	{ LOG_LOCAL3,			"local3"}, 
	{ LOG_LOCAL4,			"local4"}, 
	{ LOG_LOCAL5,			"local5"}, 
	{ LOG_LOCAL6,			"local6"}, 
	{ LOG_LOCAL7,			"local7"}, 
	{ 0,				NULL }
};


#define category_nametable_size \
	(sizeof (category_nametable) / sizeof(struct dns_c_pvt_cntable))
static struct dns_c_pvt_cntable {
	dns_c_category_t val;
	const char *strval;
} category_nametable[] = {
	{ dns_c_cat_default,		"default" },
	{ dns_c_cat_config,		"config" },
	{ dns_c_cat_parser,		"parser" },
	{ dns_c_cat_queries,		"queries" },
	{ dns_c_cat_lameservers,	"lame-servers" },
	{ dns_c_cat_statistics,		"statistics" },
	{ dns_c_cat_panic,		"panic" },
	{ dns_c_cat_update,		"update" },
	{ dns_c_cat_ncache,		"ncache" },
	{ dns_c_cat_xferin,		"xfer-in" },
	{ dns_c_cat_xferout,		"xfer-out" },
	{ dns_c_cat_db,			"db" },
	{ dns_c_cat_eventlib,		"eventlib" },
	{ dns_c_cat_packet,		"packet" },
	{ dns_c_cat_notify,		"notify" },
	{ dns_c_cat_cname,		"cname" },
	{ dns_c_cat_security,		"security" },
	{ dns_c_cat_os,			"os" },
	{ dns_c_cat_insist,		"insist" },
	{ dns_c_cat_maint,		"maintenance" },
	{ dns_c_cat_load,		"load" },
	{ dns_c_cat_respchecks,		"response-checks" },
	{ dns_c_cat_control,		"control" }
};



/***
 *** DATA
 ***/

isc_boolean_t debug_mem_print;
FILE *debug_mem_print_stream;



/***
 *** FUNCTIONS
 ***/

#if 0					/* XXXJAB delete this code */
static void default_cfgerror(isc_result_t result, const char *fmt,
			     va_list args);
#endif



void
dns_c_printinunits(FILE *fp, isc_uint32_t val)
{
	isc_uint32_t one_gig = (1024 * 1024 * 1024);
	isc_uint32_t one_meg = (1024 * 1024);
	isc_uint32_t one_k = 1024;

	if (val == DNS_C_SIZE_SPEC_DEFAULT)
		fprintf(fp, "default");
	else if ((val % one_gig) == 0)
		fprintf(fp, "%luG", (unsigned long) val / one_gig);
	else if ((val % one_meg) == 0)
		fprintf(fp, "%luM", (unsigned long) val / one_meg);
	else if ((val % one_k) == 0)
		fprintf(fp, "%luK", (unsigned long) val / one_k);
	else if (val == DNS_C_SIZE_SPEC_UNLIM)
		fprintf(fp, "unlimited");
	else
		fprintf(fp, "%lu", (unsigned long) val);
}


void
dns_c_dataclass_tostream(FILE *fp, dns_rdataclass_t rclass)
{
	char buffer[64];
	isc_buffer_t sourceb;

	isc_buffer_init(&sourceb, buffer, sizeof buffer,
			ISC_BUFFERTYPE_GENERIC);
	
	if (dns_rdataclass_totext(rclass, &sourceb) == DNS_R_SUCCESS) {
		INSIST(sourceb.used + 1 < sizeof buffer);
		buffer[sourceb.used] = '\0';
		fputs(buffer, fp);<commit_msg>minor output change.<commit_after>/*
 * Copyright (C) 1999  Internet Software Consortium.
 * 
 * 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 INTERNET SOFTWARE CONSORTIUM DISCLAIMS
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
 * CONSORTIUM 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.
 */

#include <config.h>

#include <sys/types.h>	/* XXXRTH */

#include <limits.h>
#include <syslog.h>	/* XXXRTH */
#include <ctype.h>
#include <string.h>

#include <isc/assertions.h>
#include <isc/buffer.h>

/* XXX this next include is needed by <dns/rdataclass.h>  */
#include <dns/result.h>

#include <dns/rdataclass.h>
#include <dns/rdatatype.h>

#include <dns/confcommon.h>



/***
 *** TYPES
 ***/
 
#define ordering_nametable_size \
	(sizeof (ordering_nametable) / sizeof (struct dns_c_pvt_ont))
static struct dns_c_pvt_ont {
	dns_c_ordering_t val;
	const char *strval;
} ordering_nametable[] = {
	{ dns_c_ordering_fixed,		"fixed" },
	{ dns_c_ordering_random,	"random" },
	{ dns_c_ordering_cyclic,	"cyclic" }
};


#define log_severity_nametable_size \
	(sizeof (log_severity_nametable) / sizeof (struct dns_c_pvt_lsnt))
static struct dns_c_pvt_lsnt {
	dns_c_logseverity_t val;
	const char *strval;
} log_severity_nametable[] = {
	{ dns_c_log_critical,		"critical" },
	{ dns_c_log_error,		"error" },
	{ dns_c_log_info,		"info" },
	{ dns_c_log_notice,		"notice" },
	{ dns_c_log_warn,		"warning" },
	{ dns_c_log_debug,		"debug" },
	{ dns_c_log_dynamic,		"dynamic" }
};

	
static struct dsn_c_pvt_sfnt {
	int val;
	const char *strval;
} syslog_facil_nametable[] = {
	{ LOG_KERN,			"kern" },
	{ LOG_USER,			"user" },
	{ LOG_MAIL,			"mail" },
	{ LOG_DAEMON,			"daemon" },
	{ LOG_AUTH,			"auth" },
	{ LOG_SYSLOG,			"syslog" },
	{ LOG_LPR,			"lpr" },
#ifdef LOG_NEWS
	{ LOG_NEWS,			"news" },
#endif
#ifdef LOG_UUCP
	{ LOG_UUCP,			"uucp" },
#endif
#ifdef LOG_CRON
	{ LOG_CRON,			"cron" },
#endif
#ifdef LOG_AUTHPRIV
	{ LOG_AUTHPRIV,			"authpriv" },
#endif
#ifdef LOG_FTP
	{ LOG_FTP,			"ftp" },
#endif
	{ LOG_LOCAL0,			"local0"}, 
	{ LOG_LOCAL1,			"local1"}, 
	{ LOG_LOCAL2,			"local2"}, 
	{ LOG_LOCAL3,			"local3"}, 
	{ LOG_LOCAL4,			"local4"}, 
	{ LOG_LOCAL5,			"local5"}, 
	{ LOG_LOCAL6,			"local6"}, 
	{ LOG_LOCAL7,			"local7"}, 
	{ 0,				NULL }
};


#define category_nametable_size \
	(sizeof (category_nametable) / sizeof(struct dns_c_pvt_cntable))
static struct dns_c_pvt_cntable {
	dns_c_category_t val;
	const char *strval;
} category_nametable[] = {
	{ dns_c_cat_default,		"default" },
	{ dns_c_cat_config,		"config" },
	{ dns_c_cat_parser,		"parser" },
	{ dns_c_cat_queries,		"queries" },
	{ dns_c_cat_lameservers,	"lame-servers" },
	{ dns_c_cat_statistics,		"statistics" },
	{ dns_c_cat_panic,		"panic" },
	{ dns_c_cat_update,		"update" },
	{ dns_c_cat_ncache,		"ncache" },
	{ dns_c_cat_xferin,		"xfer-in" },
	{ dns_c_cat_xferout,		"xfer-out" },
	{ dns_c_cat_db,			"db" },
	{ dns_c_cat_eventlib,		"eventlib" },
	{ dns_c_cat_packet,		"packet" },
	{ dns_c_cat_notify,		"notify" },
	{ dns_c_cat_cname,		"cname" },
	{ dns_c_cat_security,		"security" },
	{ dns_c_cat_os,			"os" },
	{ dns_c_cat_insist,		"insist" },
	{ dns_c_cat_maint,		"maintenance" },
	{ dns_c_cat_load,		"load" },
	{ dns_c_cat_respchecks,		"response-checks" },
	{ dns_c_cat_control,		"control" }
};



/***
 *** DATA
 ***/

isc_boolean_t debug_mem_print;
FILE *debug_mem_print_stream;



/***
 *** FUNCTIONS
 ***/

#if 0					/* XXXJAB delete this code */
static void default_cfgerror(isc_result_t result, const char *fmt,
			     va_list args);
#endif



void
dns_c_printinunits(FILE *fp, isc_uint32_t val)
{
	isc_uint32_t one_gig = (1024 * 1024 * 1024);
	isc_uint32_t one_meg = (1024 * 1024);
	isc_uint32_t one_k = 1024;

	if (val == DNS_C_SIZE_SPEC_DEFAULT)
		fprintf(fp, "default");
	else if (val == 0)
		fprintf(fp, "0");
	else if ((val % one_gig) == 0)
		fprintf(fp, "%luG", (unsigned long) val / one_gig);
	else if ((val % one_meg) == 0)
		fprintf(fp, "%luM", (unsigned long) val / one_meg);
	else if ((val % one_k) == 0)
		fprintf(fp, "%luK", (unsigned long) val / one_k);
	else if (val == DNS_C_SIZE_SPEC_UNLIM)
		fprintf(fp, "unlimited");
	else
		fprintf(fp, "%lu", (unsigned long) val);
}


void
dns_c_dataclass_tostream(FILE *fp, dns_rdataclass_t rclass)
{
	char buffer[64];
	isc_buffer_t sourceb;

	isc_buffer_init(&sourceb, buffer, sizeof buffer,
			ISC_BUFFERTYPE_GENERIC);
	
	if (dns_rdataclass_totext(rclass, &sourceb) == DNS_R_SUCCESS) {
		INSIST(sourceb.used + 1 < sizeof buffer);
		buffer[sourceb.used] = '\0';
		fputs(buffer, fp);
{'fraction_non_alphanumeric': 0.14102184010277696, 'fraction_numerical': 0.012254175313766182, 'mean_word_length': 4.326315789473684, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4502346', 'n_tokens_mistral': 4618, 'n_tokens_neox': 4301, 'n_words': 905}