mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-04 16:45:24 +00:00
test dns_name_splitatdepth() and dns_name_depth()
This commit is contained in:
@@ -47,6 +47,28 @@ print_wirename(isc_region_t *name) {
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_name(dns_name_t *name) {
|
||||||
|
isc_result_t result;
|
||||||
|
isc_buffer_t source;
|
||||||
|
isc_region_t r;
|
||||||
|
char s[1000];
|
||||||
|
|
||||||
|
isc_buffer_init(&source, s, sizeof s, ISC_BUFFERTYPE_TEXT);
|
||||||
|
if (dns_name_countlabels(name) > 0)
|
||||||
|
result = dns_name_totext(name, ISC_FALSE, &source);
|
||||||
|
else
|
||||||
|
result = DNS_R_SUCCESS;
|
||||||
|
if (result == DNS_R_SUCCESS) {
|
||||||
|
isc_buffer_used(&source, &r);
|
||||||
|
if (r.length > 0)
|
||||||
|
printf("%.*s\n", (int)r.length, r.base);
|
||||||
|
else
|
||||||
|
printf("<empty text name>\n");
|
||||||
|
} else
|
||||||
|
printf("error: %s\n", dns_result_totext(result));
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[]) {
|
main(int argc, char *argv[]) {
|
||||||
char s[1000];
|
char s[1000];
|
||||||
@@ -64,9 +86,13 @@ main(int argc, char *argv[]) {
|
|||||||
isc_boolean_t check_wildcard = ISC_FALSE;
|
isc_boolean_t check_wildcard = ISC_FALSE;
|
||||||
isc_boolean_t test_downcase = ISC_FALSE;
|
isc_boolean_t test_downcase = ISC_FALSE;
|
||||||
isc_boolean_t inplace = ISC_FALSE;
|
isc_boolean_t inplace = ISC_FALSE;
|
||||||
|
isc_boolean_t want_split = ISC_FALSE;
|
||||||
|
unsigned int depth, split_depth = 0;
|
||||||
|
dns_fixedname_t fprefix, fsuffix;
|
||||||
|
dns_name_t *prefix, *suffix;
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
while ((ch = isc_commandline_parse(argc, argv, "acdiqw")) != -1) {
|
while ((ch = isc_commandline_parse(argc, argv, "acdiqs:w")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'a':
|
case 'a':
|
||||||
check_absolute = ISC_TRUE;
|
check_absolute = ISC_TRUE;
|
||||||
@@ -83,6 +109,10 @@ main(int argc, char *argv[]) {
|
|||||||
case 'q':
|
case 'q':
|
||||||
quiet = ISC_TRUE;
|
quiet = ISC_TRUE;
|
||||||
break;
|
break;
|
||||||
|
case 's':
|
||||||
|
want_split = ISC_TRUE;
|
||||||
|
split_depth = atoi(isc_commandline_argument);
|
||||||
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
check_wildcard = ISC_TRUE;
|
check_wildcard = ISC_TRUE;
|
||||||
break;
|
break;
|
||||||
@@ -264,23 +294,7 @@ main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
isc_buffer_init(&source, s, sizeof s,
|
isc_buffer_init(&source, s, sizeof s,
|
||||||
ISC_BUFFERTYPE_TEXT);
|
ISC_BUFFERTYPE_TEXT);
|
||||||
if (dns_name_countlabels(down) > 0)
|
print_name(down);
|
||||||
result = dns_name_totext(down, ISC_FALSE,
|
|
||||||
&source);
|
|
||||||
else
|
|
||||||
result = DNS_R_SUCCESS;
|
|
||||||
if (result == DNS_R_SUCCESS) {
|
|
||||||
isc_buffer_used(&source, &r);
|
|
||||||
if (r.length > 0)
|
|
||||||
printf("%.*s\n", (int)r.length,
|
|
||||||
r.base);
|
|
||||||
else
|
|
||||||
printf("<empty text name>\n");
|
|
||||||
if (!quiet) {
|
|
||||||
printf("%u bytes.\n", source.used);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
printf("%s\n", dns_result_totext(result));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (comp != NULL && dns_name_countlabels(name) > 0) {
|
if (comp != NULL && dns_name_countlabels(name) > 0) {
|
||||||
@@ -320,6 +334,26 @@ main(int argc, char *argv[]) {
|
|||||||
dns_name_equal(name, comp) ? "TRUE" : "FALSE");
|
dns_name_equal(name, comp) ? "TRUE" : "FALSE");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
depth = dns_name_depth(name);
|
||||||
|
if (want_split && split_depth < depth) {
|
||||||
|
dns_fixedname_init(&fprefix);
|
||||||
|
prefix = dns_fixedname_name(&fprefix);
|
||||||
|
dns_fixedname_init(&fsuffix);
|
||||||
|
suffix = dns_fixedname_name(&fsuffix);
|
||||||
|
printf("splitting at depth %u: ", split_depth);
|
||||||
|
result = dns_name_splitatdepth(name, split_depth,
|
||||||
|
prefix, suffix);
|
||||||
|
if (result == ISC_R_SUCCESS) {
|
||||||
|
printf("\n prefix = ");
|
||||||
|
print_name(prefix);
|
||||||
|
printf(" suffix = ");
|
||||||
|
print_name(suffix);
|
||||||
|
} else {
|
||||||
|
printf("failed: %s\n",
|
||||||
|
isc_result_totext(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (concatenate) {
|
if (concatenate) {
|
||||||
if (got_name)
|
if (got_name)
|
||||||
name = &wname2.name;
|
name = &wname2.name;
|
||||||
|
Reference in New Issue
Block a user