dns_rdata_reset(&rdata);
}
} else {
+ dns_indent_t indent = { " ", 2 };
if (!yaml && (rdataset->attributes &
DNS_RDATASETATTR_NEGATIVE) != 0)
{
isc_buffer_putstr(&target, "; ");
}
-
result = dns_master_rdatasettotext(owner, rdataset,
- style, &target);
+ style,
+ yaml ? &indent :
+ NULL,
+ &target);
}
if (result == ISC_R_NOSPACE) {
styleflags |= DNS_STYLEFLAG_REL_OWNER;
if (yaml) {
styleflags |= DNS_STYLEFLAG_YAML;
- dns_master_indentstr = " ";
- dns_master_indent = 2;
} else {
if (showcomments) {
styleflags |= DNS_STYLEFLAG_COMMENT;
styleflags |= DNS_STYLEFLAG_REL_OWNER;
if (yaml) {
- dns_master_indentstr = " ";
- dns_master_indent = 3;
+ msg->indent.string = " ";
+ msg->indent.count = 3;
styleflags |= DNS_STYLEFLAG_YAML;
} else {
if (query->lookup->comments) {
result = isc_buffer_allocate(mctx, &buf, MAX_CDS_RDATA_TEXT_SIZE);
check_result(result, "printing DS records");
- result = dns_master_rdatasettotext(name, rdataset, style, buf);
+ result = dns_master_rdatasettotext(name, rdataset, style, NULL, buf);
if ((result == ISC_R_SUCCESS) && isc_buffer_availablelength(buf) < 1) {
result = ISC_R_NOSPACE;
for (;;) {
result = dns_master_rdatasettotext(name, &rds,
- masterstyle, buffer);
+ masterstyle, NULL,
+ buffer);
if (result != ISC_R_NOSPACE)
break;
status=$((status+ret))
fi
+ n=$((n+1))
echo_i "check that dig +unexpected works ($n)"
ret=0
dig_with_opts @10.53.0.6 +unexpected a a.example > dig.out.test$n || ret=1
}
if (dt->msg != NULL) {
+ dt->msg->indent.count = 2;
+ dt->msg->indent.string = " ";
printf(" %s:\n", ((dt->type & DNS_DTTYPE_QUERY) != 0)
? "query_message_data"
: "response_message_data");
break;
case 'y':
yaml = true;
- dns_master_indentstr = " ";
- dns_master_indent = 2;
break;
default:
usage();
styleflags |= DNS_STYLEFLAG_REL_OWNER;
if (yaml) {
- dns_master_indentstr = " ";
- dns_master_indent = 3;
styleflags |= DNS_STYLEFLAG_YAML;
+ response->indent.string = " ";
+ response->indent.count = 3;
} else {
if (display_comments) {
styleflags |= DNS_STYLEFLAG_COMMENT;
LIBDNS_EXTERNAL_DATA extern const dns_master_style_t dns_master_style_comment;
/*%
- * Similar to dns_master_style_debug but data is indented with
- * dns_master_indentstr (defaults to tab).
+ * Similar to dns_master_style_debug but data is indented with "\t" (tab)
*/
LIBDNS_EXTERNAL_DATA extern const dns_master_style_t dns_master_style_indent;
*/
LIBDNS_EXTERNAL_DATA extern const dns_master_style_t dns_master_style_yaml;
-/*%
- * The default indent string to prepend lines with when using
- * styleflag DNS_STYLEFLAG_INDENT or DNS_STYLEFLAG_YAML.
- * This is set to "\t" by default. The indent is repeated
- * 'dns_master_indent' times. This precedes everything else
- * on the line, including comment characters (;).
- *
- * XXX: Changing this value at runtime is not thread-safe.
- */
-LIBDNS_EXTERNAL_DATA extern const char *dns_master_indentstr;
-
-/*%
- * The number of copies of the indent string to put at the beginning
- * of the line when using DNS_STYLEFLAG_INDENT or DNS_STYLEFLAG_YAML.
- * This is set to 1 by default. It is increased and decreased
- * to adjust indentation levels when producing YAML output.
- *
- * XXX: This is not thread-safe.
- */
-LIBDNS_EXTERNAL_DATA extern unsigned int dns_master_indent;
-
/***
*** Functions
***/
dns_master_rdatasettotext(const dns_name_t *owner_name,
dns_rdataset_t *rdataset,
const dns_master_style_t *style,
- isc_buffer_t *target);
+ dns_indent_t *indent, isc_buffer_t *target);
/*%<
* Convert 'rdataset' to text format, storing the result in 'target'.
*
dns_rdatasetorderfunc_t order;
dns_sortlist_arg_t order_arg;
+
+ dns_indent_t indent;
};
struct dns_ednsopt {
dns_stale_answer_conf
} dns_stale_answer_t;
+typedef struct {
+ const char *string;
+ size_t count;
+} dns_indent_t;
+
/*
* Functions.
*/
uint32_t current_ttl;
bool current_ttl_valid;
dns_ttl_t serve_stale_ttl;
+ dns_indent_t indent;
} dns_totext_ctx_t;
LIBDNS_EXTERNAL_DATA const dns_master_style_t
};
/*%
- * Similar, but indented (i.e., prepended with dns_master_indentstr).
+ * Similar, but indented (i.e., prepended with msg->indent.string).
*/
LIBDNS_EXTERNAL_DATA const dns_master_style_t
dns_master_style_indent = {
24, 32, 40, 48, 80, 8, UINT_MAX
};
-/*%
- * Default indent string.
- */
-LIBDNS_EXTERNAL_DATA const char *dns_master_indentstr = "\t";
-LIBDNS_EXTERNAL_DATA unsigned int dns_master_indent = 1;
-
#define N_SPACES 10
static char spaces[N_SPACES+1] = " ";
#define NXDOMAIN(x) (((x)->attributes & DNS_RDATASETATTR_NXDOMAIN) != 0)
+static const dns_indent_t default_indent = { "\t", 1 };
+
/*%
* Output tabs and spaces to go from column '*current' to
* column 'to', and update '*current' to reflect the new
}
static isc_result_t
-totext_ctx_init(const dns_master_style_t *style, dns_totext_ctx_t *ctx) {
+totext_ctx_init(const dns_master_style_t *style, const dns_indent_t *indentctx,
+ dns_totext_ctx_t *ctx)
+{
isc_result_t result;
REQUIRE(style->tab_width != 0);
if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0 ||
(ctx->style.flags & DNS_STYLEFLAG_YAML) != 0)
{
- unsigned int i, len = strlen(dns_master_indentstr);
- for (i = 0; i < dns_master_indent; i++) {
+ if (indentctx == NULL) {
+ indentctx = &default_indent;
+ }
+ unsigned int i, len = strlen(indentctx->string);
+ for (i = 0; i < indentctx->count; i++) {
if (isc_buffer_availablelength(&buf) < len)
return (DNS_R_TEXTTOOLONG);
- isc_buffer_putstr(&buf, dns_master_indentstr);
+ isc_buffer_putstr(&buf, indentctx->string);
}
}
ctx->current_ttl = 0;
ctx->current_ttl_valid = false;
ctx->serve_stale_ttl = 0;
+ ctx->indent = indentctx ? *indentctx : default_indent;
return (ISC_R_SUCCESS);
}
(ctx->style.flags & DNS_STYLEFLAG_YAML) != 0)
{
unsigned int i;
- for (i = 0; i < dns_master_indent; i++) {
- CHECK(str_totext(dns_master_indentstr,
+ for (i = 0; i < ctx->indent.count; i++) {
+ CHECK(str_totext(ctx->indent.string,
target));
}
}
if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0 ||
(ctx->style.flags & DNS_STYLEFLAG_YAML) != 0)
{
- for (i = 0; i < dns_master_indent; i++)
- RETERR(str_totext(dns_master_indentstr,
+ for (i = 0; i < ctx->indent.count; i++)
+ RETERR(str_totext(ctx->indent.string,
target));
}
{
dns_totext_ctx_t ctx;
isc_result_t result;
- result = totext_ctx_init(&dns_master_style_debug, &ctx);
+ result = totext_ctx_init(&dns_master_style_debug, NULL, &ctx);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"could not set master file style");
dns_master_rdatasettotext(const dns_name_t *owner_name,
dns_rdataset_t *rdataset,
const dns_master_style_t *style,
- isc_buffer_t *target)
+ dns_indent_t *indent, isc_buffer_t *target)
{
dns_totext_ctx_t ctx;
isc_result_t result;
- result = totext_ctx_init(style, &ctx);
+ result = totext_ctx_init(style, indent, &ctx);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"could not set master file style");
{
dns_totext_ctx_t ctx;
isc_result_t result;
- result = totext_ctx_init(style, &ctx);
+ result = totext_ctx_init(style, NULL, &ctx);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"could not set master file style");
(ctx->style.flags & DNS_STYLEFLAG_YAML) != 0)
{
unsigned int j;
- for (j = 0; j < dns_master_indent; j++)
- fprintf(f, "%s", dns_master_indentstr);
+ for (j = 0; j < ctx->indent.count; j++)
+ fprintf(f, "%s", ctx->indent.string);
}
fprintf(f, "; %s\n", dns_trust_totext(rds->trust));
}
(ctx->style.flags & DNS_STYLEFLAG_YAML) != 0)
{
unsigned int j;
- for (j = 0; j < dns_master_indent; j++)
- fprintf(f, "%s", dns_master_indentstr);
+ for (j = 0; j < ctx->indent.count; j++)
+ fprintf(f, "%s", ctx->indent.string);
}
fprintf(f, "; resign=%s\n", buf);
}
ISC_UNREACHABLE();
}
- result = totext_ctx_init(style, &dctx->tctx);
+ result = totext_ctx_init(style, NULL, &dctx->tctx);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"could not set master file style");
dns_totext_ctx_t ctx;
dns_rdatasetiter_t *rdsiter = NULL;
- result = totext_ctx_init(style, &ctx);
+ result = totext_ctx_init(style, NULL, &ctx);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"could not set master file style");
m->tkey = 0;
m->rdclass_set = 0;
m->querytsig = NULL;
+ m->indent.string = "\t";
+ m->indent.count = 0;
}
static inline void
if ((__flags & DNS_STYLEFLAG_INDENT) == 0ULL && \
(__flags & DNS_STYLEFLAG_YAML) == 0ULL) \
break; \
- for (__i = 0; __i < dns_master_indent; __i++) { \
- ADD_STRING(target, dns_master_indentstr); \
+ for (__i = 0; __i < msg->indent.count; __i++) { \
+ ADD_STRING(target, msg->indent.string); \
} \
} while (0)
dns_message_sectiontotext(dns_message_t *msg, dns_section_t section,
const dns_master_style_t *style,
dns_messagetextflag_t flags,
- isc_buffer_t *target) {
+ isc_buffer_t *target)
+{
dns_name_t *name, empty_name;
dns_rdataset_t *rdataset;
isc_result_t result = ISC_R_SUCCESS;
bool seensoa = false;
- unsigned int saveindent;
+ size_t saved_count;
dns_masterstyle_flags_t sflags;
REQUIRE(DNS_MESSAGE_VALID(msg));
REQUIRE(target != NULL);
REQUIRE(VALID_SECTION(section));
- saveindent = dns_master_indent;
- sflags = dns_master_styleflags(style);
- if (ISC_LIST_EMPTY(msg->sections[section]))
+ saved_count = msg->indent.count;
+
+ if (ISC_LIST_EMPTY(msg->sections[section])) {
goto cleanup;
+ }
+ sflags = dns_master_styleflags(style);
INDENT(style);
if ((sflags & DNS_STYLEFLAG_YAML) != 0) {
goto cleanup;
}
if ((sflags & DNS_STYLEFLAG_YAML) != 0) {
- dns_master_indent++;
+ msg->indent.count++;
}
do {
name = NULL;
result = dns_master_rdatasettotext(name,
rdataset,
style,
+ &msg->indent,
target);
}
if (result != ISC_R_SUCCESS)
result = dns_message_nextname(msg, section);
} while (result == ISC_R_SUCCESS);
if ((sflags & DNS_STYLEFLAG_YAML) != 0) {
- dns_master_indent--;
+ msg->indent.count--;
}
if ((flags & DNS_MESSAGETEXTFLAG_NOHEADERS) == 0 &&
(flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0 &&
result = ISC_R_SUCCESS;
cleanup:
- dns_master_indent = saveindent;
+ msg->indent.count = saved_count;
return (result);
}
dns_rdata_t rdata;
isc_buffer_t optbuf;
uint16_t optcode, optlen;
+ size_t saved_count;
unsigned char *optdata;
- unsigned int saveindent = dns_master_indent;
REQUIRE(DNS_MESSAGE_VALID(msg));
REQUIRE(target != NULL);
REQUIRE(VALID_PSEUDOSECTION(section));
+ saved_count = msg->indent.count;
+
switch (section) {
case DNS_PSEUDOSECTION_OPT:
ps = dns_message_getopt(msg);
INDENT(style);
ADD_STRING(target, "OPT_PSEUDOSECTION:\n");
- dns_master_indent++;
+ msg->indent.count++;
INDENT(style);
ADD_STRING(target, "EDNS:\n");
- dns_master_indent++;
+ msg->indent.count++;
INDENT(style);
ADD_STRING(target, "version: ");
}
INDENT(style);
ADD_STRING(target, "TSIG_PSEUDOSECTION:\n");
- result = dns_master_rdatasettotext(name, ps, style, target);
+ result = dns_master_rdatasettotext(name, ps, style,
+ &msg->indent, target);
ADD_STRING(target, "\n");
goto cleanup;
case DNS_PSEUDOSECTION_SIG0:
}
INDENT(style);
ADD_STRING(target, "SIG0_PSEUDOSECTION:\n");
- result = dns_master_rdatasettotext(name, ps, style, target);
+ result = dns_master_rdatasettotext(name, ps, style,
+ &msg->indent, target);
if ((flags & DNS_MESSAGETEXTFLAG_NOHEADERS) == 0 &&
(flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0)
ADD_STRING(target, "\n");
result = ISC_R_UNEXPECTED;
cleanup:
- dns_master_indent = saveindent;
+ msg->indent.count = saved_count;
return (result);
}
REQUIRE(target != NULL);
REQUIRE(VALID_PSEUDOSECTION(section));
- if ((dns_master_styleflags(style) & DNS_STYLEFLAG_YAML) != 0)
+ if ((dns_master_styleflags(style) & DNS_STYLEFLAG_YAML) != 0) {
return (dns_message_pseudosectiontoyaml(msg, section, style,
flags, target));
+ }
+
switch (section) {
case DNS_PSEUDOSECTION_OPT:
ps = dns_message_getopt(msg);
INDENT(style);
if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0)
ADD_STRING(target, ";; TSIG PSEUDOSECTION:\n");
- result = dns_master_rdatasettotext(name, ps, style, target);
+ result = dns_master_rdatasettotext(name, ps, style,
+ &msg->indent, target);
if ((flags & DNS_MESSAGETEXTFLAG_NOHEADERS) == 0 &&
(flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0)
ADD_STRING(target, "\n");
INDENT(style);
if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0)
ADD_STRING(target, ";; SIG0 PSEUDOSECTION:\n");
- result = dns_master_rdatasettotext(name, ps, style, target);
+ result = dns_master_rdatasettotext(name, ps, style,
+ &msg->indent, target);
if ((flags & DNS_MESSAGETEXTFLAG_NOHEADERS) == 0 &&
(flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0)
ADD_STRING(target, "\n");
goto cleanup;
result = dns_master_rdatasettotext(sdlznode->name, rdataset,
- style, buffer);
+ style, NULL, buffer);
if (result != ISC_R_SUCCESS)
goto cleanup;
assert_int_equal(result, ISC_R_SUCCESS);
isc_buffer_init(&target, buf, BIGBUFLEN);
- result = dns_master_rdatasettotext(dns_rootname,
- &rdataset, &dns_master_style_debug,
+ result = dns_master_rdatasettotext(dns_rootname, &rdataset,
+ &dns_master_style_debug, NULL,
&target);
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(isc_buffer_usedlength(&target), 0);