1 /*
2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
7  *
8  * See the COPYRIGHT file distributed with this work for additional
9  * information regarding copyright ownership.
10  */
11 
12 #pragma once
13 
14 #include <dns/name.h>
15 
16 typedef enum {
17 	DNS_TRANSPORT_NONE = 0,
18 	DNS_TRANSPORT_UDP = 1,
19 	DNS_TRANSPORT_TCP = 2,
20 	DNS_TRANSPORT_TLS = 3,
21 	DNS_TRANSPORT_HTTP = 4,
22 	DNS_TRANSPORT_COUNT = 5,
23 } dns_transport_type_t;
24 
25 typedef enum {
26 	DNS_HTTP_GET = 0,
27 	DNS_HTTP_POST = 1,
28 } dns_http_mode_t;
29 
30 typedef struct dns_transport	  dns_transport_t;
31 typedef struct dns_transport_list dns_transport_list_t;
32 
33 dns_transport_t *
34 dns_transport_new(const dns_name_t *name, dns_transport_type_t type,
35 		  dns_transport_list_t *list);
36 /*%<
37  * Create a new transport object with name 'name' and type 'type',
38  * and append it to 'list'.
39  */
40 
41 dns_transport_type_t
42 dns_transport_get_type(dns_transport_t *transport);
43 char *
44 dns_transport_get_certfile(dns_transport_t *transport);
45 char *
46 dns_transport_get_keyfile(dns_transport_t *transport);
47 char *
48 dns_transport_get_cafile(dns_transport_t *transport);
49 char *
50 dns_transport_get_hostname(dns_transport_t *transport);
51 char *
52 dns_transport_get_endpoint(dns_transport_t *transport);
53 dns_http_mode_t
54 dns_transport_get_mode(dns_transport_t *transport);
55 /*%<
56  * Getter functions: return the type, cert file, key file, CA file,
57  * hostname, HTTP endpoint, or HTTP mode (GET or POST) for 'transport'.
58  */
59 
60 void
61 dns_transport_set_certfile(dns_transport_t *transport, const char *certfile);
62 void
63 dns_transport_set_keyfile(dns_transport_t *transport, const char *keyfile);
64 void
65 dns_transport_set_cafile(dns_transport_t *transport, const char *cafile);
66 void
67 dns_transport_set_hostname(dns_transport_t *transport, const char *hostname);
68 void
69 dns_transport_set_endpoint(dns_transport_t *transport, const char *endpoint);
70 void
71 dns_transport_set_mode(dns_transport_t *transport, dns_http_mode_t mode);
72 /*%<
73  * Setter functions: set the type, cert file, key file, CA file,
74  * hostname, HTTP endpoint, or HTTP mode (GET or POST) for 'transport'.
75  *
76  * Requires:
77  *\li	'transport' is valid.
78  *\li	'transport' is of type DNS_TRANSPORT_TLS or DNS_TRANSPORT_HTTP
79  *	(for certfile, keyfile, cafile, or hostname).
80  *\li	'transport' is of type DNS_TRANSPORT_HTTP (for endpoint or mode).
81  */
82 
83 void
84 dns_transport_attach(dns_transport_t *source, dns_transport_t **targetp);
85 /*%<
86  * Attach to a transport object.
87  *
88  * Requires:
89  *\li	'source' is a valid transport.
90  *\li	'targetp' is not NULL and '*targetp' is NULL.
91  */
92 
93 void
94 dns_transport_detach(dns_transport_t **transportp);
95 /*%<
96  * Detach a transport object; destroy it if there are no remaining
97  * references.
98  *
99  * Requires:
100  *\li	'transportp' is not NULL.
101  *\li	'*transportp' is a valid transport.
102  */
103 
104 dns_transport_t *
105 dns_transport_find(const dns_transport_type_t type, const dns_name_t *name,
106 		   dns_transport_list_t *list);
107 /*%<
108  * Find a transport matching type 'type' and name `name` in 'list'.
109  *
110  * Requires:
111  *\li	'list' is valid.
112  *\li	'list' contains a table of type 'type' transports.
113  */
114 
115 dns_transport_list_t *
116 dns_transport_list_new(isc_mem_t *mctx);
117 /*%<
118  * Create a new transport list.
119  */
120 
121 void
122 dns_transport_list_attach(dns_transport_list_t * source,
123 			  dns_transport_list_t **targetp);
124 /*%<
125  * Attach to a transport list.
126  *
127  * Requires:
128  *\li	'source' is a valid transport list.
129  *\li	'targetp' is not NULL and '*targetp' is NULL.
130  */
131 
132 void
133 dns_transport_list_detach(dns_transport_list_t **listp);
134 /*%<
135  * Detach a transport list; destroy it if there are no remaining
136  * references.
137  *
138  * Requires:
139  *\li	'listp' is not NULL.
140  *\li	'*listp' is a valid transport list.
141  */
142