From c7868e2262d57451c7f0ce246be5f44e8c33f1e0 Mon Sep 17 00:00:00 2001 From: Michael Sawyer Date: Wed, 24 May 2000 18:17:53 +0000 Subject: [PATCH] Modify dns_message_totext, dns_message_sectiontotext, dns_message_pseudosectiontotext to use bitfields instead of flags --- bin/tests/dispatch_tcp_test.c | 3 +- bin/tests/dispatch_test.c | 3 +- lib/dns/include/dns/message.h | 33 +++++++++----------- lib/dns/message.c | 58 +++++++++++++---------------------- 4 files changed, 38 insertions(+), 59 deletions(-) diff --git a/bin/tests/dispatch_tcp_test.c b/bin/tests/dispatch_tcp_test.c index 158315b8a1..9c7b9702c8 100644 --- a/bin/tests/dispatch_tcp_test.c +++ b/bin/tests/dispatch_tcp_test.c @@ -60,8 +60,7 @@ printmsg(dns_message_t *msg, FILE *out) { int result; isc_buffer_init(&textbuf, text, sizeof text); - result = dns_message_totext(msg, ISC_TRUE, ISC_TRUE, - ISC_FALSE, &textbuf); + result = dns_message_totext(msg, 0, &textbuf); if (result != ISC_R_SUCCESS) return (result); diff --git a/bin/tests/dispatch_test.c b/bin/tests/dispatch_test.c index 5259397881..5632f8064c 100644 --- a/bin/tests/dispatch_test.c +++ b/bin/tests/dispatch_test.c @@ -67,8 +67,7 @@ printmsg(dns_message_t *msg, FILE *out) { int result; isc_buffer_init(&textbuf, text, sizeof text); - result = dns_message_totext(msg, ISC_TRUE, ISC_TRUE, - ISC_FALSE, &textbuf); + result = dns_message_totext(msg, 0, &textbuf); if (result != ISC_R_SUCCESS) return (result); diff --git a/lib/dns/include/dns/message.h b/lib/dns/include/dns/message.h index 1ad72de2a3..2f17a482af 100644 --- a/lib/dns/include/dns/message.h +++ b/lib/dns/include/dns/message.h @@ -122,6 +122,10 @@ typedef int dns_pseudosection_t; #define DNS_PSEUDOSECTION_SIG0 2 #define DNS_PSEUDOSECTION_MAX 3 +typedef int dns_messagetextflag_t; +#define DNS_MESSAGETEXTFLAG_NOCOMMENTS 0x0001 +#define DNS_MESSAGETEXTFLAG_NOHEADERS 0x0002 +#define DNS_MESSAGETEXTFLAG_OMITDOT 0x0004 /* * Dynamic update names for these sections. @@ -275,26 +279,20 @@ dns_message_destroy(dns_message_t **msgp); isc_result_t dns_message_sectiontotext(dns_message_t *msg, dns_section_t section, - isc_boolean_t comments, - isc_boolean_t omit_final_dot, + dns_messagetextflag_t flags, isc_buffer_t *target); isc_result_t dns_message_pseudosectiontotext(dns_message_t *msg, dns_pseudosection_t section, - isc_boolean_t comments, - isc_boolean_t omit_final_dot, + dns_messagetextflag_t flags, isc_buffer_t *target); /* * Convert section 'section' or 'pseudosection' of message 'msg' to * a cleartext representation * * Notes: - * If 'omit_final_dot' is true, then the final '.' in absolute names - * will not be emitted. - * If 'no_rdata_or_tt;' is true, omit rdata and ttl fields. - * If 'comments' is true, lines beginning with ";;" will be emitted - * indicating section name. + * See dns_message_totext for meanings of flags. * * Requires: * @@ -322,18 +320,18 @@ dns_message_pseudosectiontotext(dns_message_t *msg, */ isc_result_t -dns_message_totext(dns_message_t *msg, isc_boolean_t comments, - isc_boolean_t headers, isc_boolean_t omit_final_dot, +dns_message_totext(dns_message_t *msg, dns_messagetextflag_t flags, isc_buffer_t *target); /* * Convert all sections of message 'msg' to a cleartext representation * * Notes: - * If 'omit_final_dot' is true, then the final '.' in absolute names - * will not be emitted. - * If 'no_rdata_or_tt;' is true, omit rdata and ttl fields. - * If 'comments' is true, lines beginning with ";;" will be emitted - * indicating section name. + * In flags, If DNS_MESSAGETEXTFLAG_OMITDOT is set, then the * + * final '.' in absolute names will not be emitted. If + * DNS_MESSAGETEXTFLAG_NOCOMMENTS is cleared, * lines * beginning + * with ";;" will be emitted indicating section name. If + * DNS_MESSAGETEXTFLAG_NOHEADERS is cleared, header lines will + * be emmitted. * * Requires: * @@ -355,8 +353,7 @@ dns_message_totext(dns_message_t *msg, isc_boolean_t comments, * ISC_R_NOSPACE * ISC_R_NOMORE * - * Note: On error return, *target may be partially filled with data. -*/ + * Note: On error return, *target may be partially filled with data. */ isc_result_t dns_message_parse(dns_message_t *msg, isc_buffer_t *source, diff --git a/lib/dns/message.c b/lib/dns/message.c index 7484e54316..c91c87dc98 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -2418,22 +2418,20 @@ dns_message_checksig(dns_message_t *msg, dns_view_t *view) { isc_result_t dns_message_sectiontotext(dns_message_t *msg, dns_section_t section, - isc_boolean_t comments, - isc_boolean_t omit_final_dot, + dns_messagetextflag_t flags, isc_buffer_t *target) { dns_name_t *name, empty_name; dns_rdataset_t *rdataset; isc_result_t result; isc_boolean_t no_rdata; + isc_boolean_t omit_final_dot; REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(target != NULL); REQUIRE(VALID_SECTION(section)); - /* - * If the section is empty, that's still success, but we don't - * actually do anything. - */ + omit_final_dot = ISC_TF((flags & DNS_MESSAGETEXTFLAG_OMITDOT) != 0); + if (ISC_LIST_EMPTY(msg->sections[section])) return ISC_R_SUCCESS; @@ -2442,7 +2440,7 @@ dns_message_sectiontotext(dns_message_t *msg, dns_section_t section, else no_rdata = ISC_FALSE; - if (comments) { + if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) { ADD_STRING(target, ";; "); ADD_STRING(target, sectiontext[section]); ADD_STRING(target, " SECTION:\n"); @@ -2479,28 +2477,26 @@ dns_message_sectiontotext(dns_message_t *msg, dns_section_t section, isc_result_t dns_message_pseudosectiontotext(dns_message_t *msg, dns_pseudosection_t section, - isc_boolean_t comments, - isc_boolean_t omit_final_dot, + dns_messagetextflag_t flags, isc_buffer_t *target) { dns_rdataset_t *ps = NULL; dns_name_t *name = NULL; isc_result_t result; char buf[sizeof("1234567890")]; + isc_boolean_t omit_final_dot; REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(target != NULL); REQUIRE(VALID_PSEUDOSECTION(section)); - /* - * If the section is empty, that's still success, but we don't - * actually do anything. - */ + omit_final_dot = ISC_TF((flags & DNS_MESSAGETEXTFLAG_OMITDOT) != 0); + switch (section) { case DNS_PSEUDOSECTION_OPT: ps = dns_message_getopt(msg); if (ps == NULL) return (ISC_R_SUCCESS); - if (comments) + if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) ADD_STRING(target, ";; OPT PSEUDOSECTION:\n"); ADD_STRING(target, "; EDNS: version: "); sprintf(buf, "%4u", @@ -2516,7 +2512,7 @@ dns_message_pseudosectiontotext(dns_message_t *msg, ps = dns_message_gettsig(msg, &name); if (ps == NULL) return (ISC_R_SUCCESS); - if (comments) + if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) ADD_STRING(target, ";; TSIG PSEUDOSECTION:\n"); result = dns_rdataset_totext(ps, name, omit_final_dot, ISC_FALSE, target); @@ -2526,7 +2522,7 @@ dns_message_pseudosectiontotext(dns_message_t *msg, ps = dns_message_getsig0(msg, &name); if (ps == NULL) return (ISC_R_SUCCESS); - if (comments) + if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) ADD_STRING(target, ";; SIG0 PSEUDOSECTION:\n"); result = dns_rdataset_totext(ps, name, omit_final_dot, ISC_FALSE, target); @@ -2537,8 +2533,7 @@ dns_message_pseudosectiontotext(dns_message_t *msg, } isc_result_t -dns_message_totext(dns_message_t *msg, isc_boolean_t comments, - isc_boolean_t headers, isc_boolean_t omit_final_dot, +dns_message_totext(dns_message_t *msg, dns_messagetextflag_t flags, isc_buffer_t *target) { char buf[sizeof "1234567890"]; isc_result_t result; @@ -2546,7 +2541,7 @@ dns_message_totext(dns_message_t *msg, isc_boolean_t comments, REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(target != NULL); - if (headers) { + if ((flags & DNS_MESSAGETEXTFLAG_NOHEADERS) == 0) { ADD_STRING(target, ";; ->>HEADER<<- opcode: "); ADD_STRING(target, opcodetext[msg->opcode]); ADD_STRING(target, ", status: "); @@ -2585,47 +2580,36 @@ dns_message_totext(dns_message_t *msg, isc_boolean_t comments, } result = dns_message_pseudosectiontotext(msg, DNS_PSEUDOSECTION_OPT, - comments, omit_final_dot, - target); + flags, target); if (result != ISC_R_SUCCESS) return (result); result = dns_message_sectiontotext(msg, DNS_SECTION_QUESTION, - comments, - omit_final_dot, - target); + flags, target); if (result != ISC_R_SUCCESS) return (result); result = dns_message_sectiontotext(msg, DNS_SECTION_ANSWER, - comments, - omit_final_dot, - target); + flags, target); if (result != ISC_R_SUCCESS) return (result); result = dns_message_sectiontotext(msg, DNS_SECTION_AUTHORITY, - comments, - omit_final_dot, - target); + flags, target); if (result != ISC_R_SUCCESS) return (result); result = dns_message_sectiontotext(msg, DNS_SECTION_ADDITIONAL, - comments, - omit_final_dot, - target); + flags, target); if (result != ISC_R_SUCCESS) return (result); result = dns_message_pseudosectiontotext(msg, DNS_PSEUDOSECTION_TSIG, - comments, omit_final_dot, - target); + flags, target); if (result != ISC_R_SUCCESS) return (result); result = dns_message_pseudosectiontotext(msg, DNS_PSEUDOSECTION_SIG0, - comments, omit_final_dot, - target); + flags, target); if (result != ISC_R_SUCCESS) return (result);