/src/bind9/lib/dns/zone/viewname.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) Internet Systems Consortium, Inc. ("ISC") |
3 | | * |
4 | | * SPDX-License-Identifier: MPL-2.0 |
5 | | * |
6 | | * This Source Code Form is subject to the terms of the Mozilla Public |
7 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
8 | | * file, you can obtain one at https://mozilla.org/MPL/2.0/. |
9 | | * |
10 | | * See the COPYRIGHT file distributed with this work for additional |
11 | | * information regarding copyright ownership. |
12 | | */ |
13 | | |
14 | | #include <string.h> |
15 | | |
16 | | #include <isc/mem.h> |
17 | | #include <isc/util.h> |
18 | | |
19 | | #include "viewname_p.h" |
20 | | |
21 | | static const char default_view[] = "_default"; |
22 | | static const char bind_view[] = "_bind"; |
23 | | |
24 | | const char * |
25 | 2 | dns__viewname_get(const dns_viewname_t *name) { |
26 | 2 | return name->name; |
27 | 2 | } |
28 | | |
29 | | const char * |
30 | 4 | dns__viewname_display(const dns_viewname_t *name) { |
31 | 4 | if (name->name == default_view || name->name == bind_view) { |
32 | 0 | return NULL; |
33 | 0 | } |
34 | 4 | return name->name; |
35 | 4 | } |
36 | | |
37 | | void |
38 | 2 | dns__viewname_free(dns_viewname_t *name, isc_mem_t *mctx) { |
39 | 2 | if (dns__viewname_display(name) != NULL) { |
40 | 0 | char *value = (char *)name->name; |
41 | 0 | isc_mem_free(mctx, value); |
42 | 0 | } |
43 | 2 | name->name = NULL; |
44 | 2 | } |
45 | | |
46 | | void |
47 | 2 | dns__viewname_set(dns_viewname_t *name, isc_mem_t *mctx, const char *value) { |
48 | 2 | REQUIRE(value != NULL); |
49 | | |
50 | | /* Reattaching a view of the same name leaves logging storage intact. */ |
51 | 2 | if (name->name != NULL && strcmp(name->name, value) == 0) { |
52 | 0 | return; |
53 | 0 | } |
54 | | |
55 | 2 | const char *replacement = NULL; |
56 | 2 | if (value[0] == '_' && strcmp(value, default_view) == 0) { |
57 | 0 | replacement = default_view; |
58 | 2 | } else if (value[0] == '_' && strcmp(value, bind_view) == 0) { |
59 | 0 | replacement = bind_view; |
60 | 2 | } else { |
61 | 2 | replacement = isc_mem_strdup(mctx, value); |
62 | 2 | } |
63 | 2 | dns__viewname_free(name, mctx); |
64 | 2 | name->name = replacement; |
65 | 2 | } |