2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 21:47:59 +00:00

Modify dns_message_totext, dns_message_sectiontotext,

dns_message_pseudosectiontotext to use bitfields instead of flags
This commit is contained in:
Michael Sawyer 2000-05-24 18:17:53 +00:00
parent 1d51470051
commit c7868e2262
4 changed files with 38 additions and 59 deletions

View File

@ -60,8 +60,7 @@ printmsg(dns_message_t *msg, FILE *out) {
int result; int result;
isc_buffer_init(&textbuf, text, sizeof text); isc_buffer_init(&textbuf, text, sizeof text);
result = dns_message_totext(msg, ISC_TRUE, ISC_TRUE, result = dns_message_totext(msg, 0, &textbuf);
ISC_FALSE, &textbuf);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return (result); return (result);

View File

@ -67,8 +67,7 @@ printmsg(dns_message_t *msg, FILE *out) {
int result; int result;
isc_buffer_init(&textbuf, text, sizeof text); isc_buffer_init(&textbuf, text, sizeof text);
result = dns_message_totext(msg, ISC_TRUE, ISC_TRUE, result = dns_message_totext(msg, 0, &textbuf);
ISC_FALSE, &textbuf);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return (result); return (result);

View File

@ -122,6 +122,10 @@ typedef int dns_pseudosection_t;
#define DNS_PSEUDOSECTION_SIG0 2 #define DNS_PSEUDOSECTION_SIG0 2
#define DNS_PSEUDOSECTION_MAX 3 #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. * Dynamic update names for these sections.
@ -275,26 +279,20 @@ dns_message_destroy(dns_message_t **msgp);
isc_result_t isc_result_t
dns_message_sectiontotext(dns_message_t *msg, dns_section_t section, dns_message_sectiontotext(dns_message_t *msg, dns_section_t section,
isc_boolean_t comments, dns_messagetextflag_t flags,
isc_boolean_t omit_final_dot,
isc_buffer_t *target); isc_buffer_t *target);
isc_result_t isc_result_t
dns_message_pseudosectiontotext(dns_message_t *msg, dns_message_pseudosectiontotext(dns_message_t *msg,
dns_pseudosection_t section, dns_pseudosection_t section,
isc_boolean_t comments, dns_messagetextflag_t flags,
isc_boolean_t omit_final_dot,
isc_buffer_t *target); isc_buffer_t *target);
/* /*
* Convert section 'section' or 'pseudosection' of message 'msg' to * Convert section 'section' or 'pseudosection' of message 'msg' to
* a cleartext representation * a cleartext representation
* *
* Notes: * Notes:
* If 'omit_final_dot' is true, then the final '.' in absolute names * See dns_message_totext for meanings of flags.
* 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.
* *
* Requires: * Requires:
* *
@ -322,18 +320,18 @@ dns_message_pseudosectiontotext(dns_message_t *msg,
*/ */
isc_result_t isc_result_t
dns_message_totext(dns_message_t *msg, isc_boolean_t comments, dns_message_totext(dns_message_t *msg, dns_messagetextflag_t flags,
isc_boolean_t headers, isc_boolean_t omit_final_dot,
isc_buffer_t *target); isc_buffer_t *target);
/* /*
* Convert all sections of message 'msg' to a cleartext representation * Convert all sections of message 'msg' to a cleartext representation
* *
* Notes: * Notes:
* If 'omit_final_dot' is true, then the final '.' in absolute names * In flags, If DNS_MESSAGETEXTFLAG_OMITDOT is set, then the *
* will not be emitted. * final '.' in absolute names will not be emitted. If
* If 'no_rdata_or_tt;' is true, omit rdata and ttl fields. * DNS_MESSAGETEXTFLAG_NOCOMMENTS is cleared, * lines * beginning
* If 'comments' is true, lines beginning with ";;" will be emitted * with ";;" will be emitted indicating section name. If
* indicating section name. * DNS_MESSAGETEXTFLAG_NOHEADERS is cleared, header lines will
* be emmitted.
* *
* Requires: * Requires:
* *
@ -355,8 +353,7 @@ dns_message_totext(dns_message_t *msg, isc_boolean_t comments,
* ISC_R_NOSPACE * ISC_R_NOSPACE
* ISC_R_NOMORE * 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 isc_result_t
dns_message_parse(dns_message_t *msg, isc_buffer_t *source, dns_message_parse(dns_message_t *msg, isc_buffer_t *source,

View File

@ -2418,22 +2418,20 @@ dns_message_checksig(dns_message_t *msg, dns_view_t *view) {
isc_result_t isc_result_t
dns_message_sectiontotext(dns_message_t *msg, dns_section_t section, dns_message_sectiontotext(dns_message_t *msg, dns_section_t section,
isc_boolean_t comments, dns_messagetextflag_t flags,
isc_boolean_t omit_final_dot,
isc_buffer_t *target) { isc_buffer_t *target) {
dns_name_t *name, empty_name; dns_name_t *name, empty_name;
dns_rdataset_t *rdataset; dns_rdataset_t *rdataset;
isc_result_t result; isc_result_t result;
isc_boolean_t no_rdata; isc_boolean_t no_rdata;
isc_boolean_t omit_final_dot;
REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(DNS_MESSAGE_VALID(msg));
REQUIRE(target != NULL); REQUIRE(target != NULL);
REQUIRE(VALID_SECTION(section)); REQUIRE(VALID_SECTION(section));
/* omit_final_dot = ISC_TF((flags & DNS_MESSAGETEXTFLAG_OMITDOT) != 0);
* If the section is empty, that's still success, but we don't
* actually do anything.
*/
if (ISC_LIST_EMPTY(msg->sections[section])) if (ISC_LIST_EMPTY(msg->sections[section]))
return ISC_R_SUCCESS; return ISC_R_SUCCESS;
@ -2442,7 +2440,7 @@ dns_message_sectiontotext(dns_message_t *msg, dns_section_t section,
else else
no_rdata = ISC_FALSE; no_rdata = ISC_FALSE;
if (comments) { if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) {
ADD_STRING(target, ";; "); ADD_STRING(target, ";; ");
ADD_STRING(target, sectiontext[section]); ADD_STRING(target, sectiontext[section]);
ADD_STRING(target, " SECTION:\n"); ADD_STRING(target, " SECTION:\n");
@ -2479,28 +2477,26 @@ dns_message_sectiontotext(dns_message_t *msg, dns_section_t section,
isc_result_t isc_result_t
dns_message_pseudosectiontotext(dns_message_t *msg, dns_message_pseudosectiontotext(dns_message_t *msg,
dns_pseudosection_t section, dns_pseudosection_t section,
isc_boolean_t comments, dns_messagetextflag_t flags,
isc_boolean_t omit_final_dot,
isc_buffer_t *target) { isc_buffer_t *target) {
dns_rdataset_t *ps = NULL; dns_rdataset_t *ps = NULL;
dns_name_t *name = NULL; dns_name_t *name = NULL;
isc_result_t result; isc_result_t result;
char buf[sizeof("1234567890")]; char buf[sizeof("1234567890")];
isc_boolean_t omit_final_dot;
REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(DNS_MESSAGE_VALID(msg));
REQUIRE(target != NULL); REQUIRE(target != NULL);
REQUIRE(VALID_PSEUDOSECTION(section)); REQUIRE(VALID_PSEUDOSECTION(section));
/* omit_final_dot = ISC_TF((flags & DNS_MESSAGETEXTFLAG_OMITDOT) != 0);
* If the section is empty, that's still success, but we don't
* actually do anything.
*/
switch (section) { switch (section) {
case DNS_PSEUDOSECTION_OPT: case DNS_PSEUDOSECTION_OPT:
ps = dns_message_getopt(msg); ps = dns_message_getopt(msg);
if (ps == NULL) if (ps == NULL)
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
if (comments) if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0)
ADD_STRING(target, ";; OPT PSEUDOSECTION:\n"); ADD_STRING(target, ";; OPT PSEUDOSECTION:\n");
ADD_STRING(target, "; EDNS: version: "); ADD_STRING(target, "; EDNS: version: ");
sprintf(buf, "%4u", sprintf(buf, "%4u",
@ -2516,7 +2512,7 @@ dns_message_pseudosectiontotext(dns_message_t *msg,
ps = dns_message_gettsig(msg, &name); ps = dns_message_gettsig(msg, &name);
if (ps == NULL) if (ps == NULL)
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
if (comments) if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0)
ADD_STRING(target, ";; TSIG PSEUDOSECTION:\n"); ADD_STRING(target, ";; TSIG PSEUDOSECTION:\n");
result = dns_rdataset_totext(ps, name, omit_final_dot, result = dns_rdataset_totext(ps, name, omit_final_dot,
ISC_FALSE, target); ISC_FALSE, target);
@ -2526,7 +2522,7 @@ dns_message_pseudosectiontotext(dns_message_t *msg,
ps = dns_message_getsig0(msg, &name); ps = dns_message_getsig0(msg, &name);
if (ps == NULL) if (ps == NULL)
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
if (comments) if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0)
ADD_STRING(target, ";; SIG0 PSEUDOSECTION:\n"); ADD_STRING(target, ";; SIG0 PSEUDOSECTION:\n");
result = dns_rdataset_totext(ps, name, omit_final_dot, result = dns_rdataset_totext(ps, name, omit_final_dot,
ISC_FALSE, target); ISC_FALSE, target);
@ -2537,8 +2533,7 @@ dns_message_pseudosectiontotext(dns_message_t *msg,
} }
isc_result_t isc_result_t
dns_message_totext(dns_message_t *msg, isc_boolean_t comments, dns_message_totext(dns_message_t *msg, dns_messagetextflag_t flags,
isc_boolean_t headers, isc_boolean_t omit_final_dot,
isc_buffer_t *target) { isc_buffer_t *target) {
char buf[sizeof "1234567890"]; char buf[sizeof "1234567890"];
isc_result_t result; 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(DNS_MESSAGE_VALID(msg));
REQUIRE(target != NULL); REQUIRE(target != NULL);
if (headers) { if ((flags & DNS_MESSAGETEXTFLAG_NOHEADERS) == 0) {
ADD_STRING(target, ";; ->>HEADER<<- opcode: "); ADD_STRING(target, ";; ->>HEADER<<- opcode: ");
ADD_STRING(target, opcodetext[msg->opcode]); ADD_STRING(target, opcodetext[msg->opcode]);
ADD_STRING(target, ", status: "); ADD_STRING(target, ", status: ");
@ -2585,47 +2580,36 @@ dns_message_totext(dns_message_t *msg, isc_boolean_t comments,
} }
result = dns_message_pseudosectiontotext(msg, result = dns_message_pseudosectiontotext(msg,
DNS_PSEUDOSECTION_OPT, DNS_PSEUDOSECTION_OPT,
comments, omit_final_dot, flags, target);
target);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return (result); return (result);
result = dns_message_sectiontotext(msg, DNS_SECTION_QUESTION, result = dns_message_sectiontotext(msg, DNS_SECTION_QUESTION,
comments, flags, target);
omit_final_dot,
target);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return (result); return (result);
result = dns_message_sectiontotext(msg, DNS_SECTION_ANSWER, result = dns_message_sectiontotext(msg, DNS_SECTION_ANSWER,
comments, flags, target);
omit_final_dot,
target);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return (result); return (result);
result = dns_message_sectiontotext(msg, DNS_SECTION_AUTHORITY, result = dns_message_sectiontotext(msg, DNS_SECTION_AUTHORITY,
comments, flags, target);
omit_final_dot,
target);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return (result); return (result);
result = dns_message_sectiontotext(msg, DNS_SECTION_ADDITIONAL, result = dns_message_sectiontotext(msg, DNS_SECTION_ADDITIONAL,
comments, flags, target);
omit_final_dot,
target);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return (result); return (result);
result = dns_message_pseudosectiontotext(msg, result = dns_message_pseudosectiontotext(msg,
DNS_PSEUDOSECTION_TSIG, DNS_PSEUDOSECTION_TSIG,
comments, omit_final_dot, flags, target);
target);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return (result); return (result);
result = dns_message_pseudosectiontotext(msg, result = dns_message_pseudosectiontotext(msg,
DNS_PSEUDOSECTION_SIG0, DNS_PSEUDOSECTION_SIG0,
comments, omit_final_dot, flags, target);
target);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return (result); return (result);