Asterisk - The Open Source Telephony Project GIT-master-a358458
dns_test.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2015, Digium, Inc.
5 *
6 * Mark Michelson <mmichelson@digium.com>
7 *
8 * Includes code and algorithms from the Zapata library.
9 *
10 * See http://www.asterisk.org for more information about
11 * the Asterisk project. Please do not directly contact
12 * any of the maintainers of this project for assistance;
13 * the project provides a web site, mailing lists and IRC
14 * channels for your use.
15 *
16 * This program is free software, distributed under the terms of
17 * the GNU General Public License Version 2. See the LICENSE file
18 * at the top of the source tree.
19 */
20
21#ifndef DNS_TEST_H
22#define DNS_TEST_H
23
24/*!
25 * \brief Representation of a string in DNS
26 *
27 * In DNS, a string has a byte to indicate the length,
28 * followed by a series of bytes representing the string.
29 * DNS does not NULL-terminate its strings. However, the
30 * string stored in this structure is expected to be NULL-
31 * terminated.
32 */
34 uint8_t len;
35 const char *val;
36};
37
38/*!
39 * \brief Write a DNS string to a buffer
40 *
41 * This writes the DNS string to the buffer and returns the total
42 * number of bytes written to the buffer.
43 *
44 * There is no buffer size passed to this function. Tests are expected to
45 * use a buffer that is sufficiently large for their tests.
46 *
47 * \param string The string to write
48 * \param buf The buffer to write the string into
49 * \return The number of bytes written to the buffer
50 */
51int ast_dns_test_write_string(const struct ast_dns_test_string *string, char *buf);
52
53/*!
54 * \brief Write a DNS domain to a buffer
55 *
56 * A DNS domain consists of a series of labels separated
57 * by dots. Each of these labels gets written as a DNS
58 * string. A DNS domain ends with a NULL label, which is
59 * essentially a zero-length DNS string.
60 *
61 * There is no buffer size passed to this function. Tests are expected to
62 * use a buffer that is sufficiently large for their tests.
63 *
64 * \param string The DNS domain to write
65 * \param buf The buffer to write the domain into
66 * \return The number of bytes written to the buffer
67 */
68int ast_dns_test_write_domain(const char *string, char *buf);
69
70/*!
71 * \brief Callback to write specific DNS record to an answer
72 *
73 * When generating a DNS result, the type of DNS record being generated
74 * will need to be performed by individual test cases. This is a callback
75 * that tests can define to write a specific type of DNS record to the
76 * provided buffer.
77 *
78 * There is no buffer size passed to this function. Tests are expected to
79 * use a buffer that is sufficiently large for their tests.
80 *
81 * \param record Pointer to test-specific DNS record data
82 * \param buf The buffer into which to write the DNS record
83 * \return The number of bytes written to the buffer
84 */
85typedef int (*record_fn)(void *record, char *buf);
86
87/*!
88 * \brief Generate a full DNS response for the given DNS records.
89 *
90 * This function takes care of generating the DNS header, question, and
91 * answer sections of a DNS response. In order to place test-specific
92 * record data into the DNS answers, a callback is provided as a parameter
93 * to this function so that the necessary records can be encoded properly
94 * by the tests.
95 *
96 * There is no buffer size passed to this function. Tests are expected to
97 * use a buffer that is sufficiently large for their tests.
98 *
99 * \param query The DNS query that is being processed
100 * \param records An array of test-specific representations of DNS records
101 * \param num_records The number of elements in the records array
102 * \param record_size The size of each element in the records array
103 * \param generate The test-specific encoder for DNS records
104 * \param buffer The buffer into which to write the DNS response
105 */
106int ast_dns_test_generate_result(struct ast_dns_query *query, void *records, size_t num_records,
107 size_t record_size, record_fn generate, char *buffer);
108
109#endif /* DNS_TEST_H */
static int records
Definition: cdr_pgsql.c:78
int(* record_fn)(void *record, char *buf)
Callback to write specific DNS record to an answer.
Definition: dns_test.h:85
int ast_dns_test_write_domain(const char *string, char *buf)
Write a DNS domain to a buffer.
Definition: dns_test.c:224
int ast_dns_test_generate_result(struct ast_dns_query *query, void *records, size_t num_records, size_t record_size, record_fn generate, char *buffer)
Generate a full DNS response for the given DNS records.
Definition: dns_test.c:229
int ast_dns_test_write_string(const struct ast_dns_test_string *string, char *buf)
Write a DNS string to a buffer.
Definition: dns_test.c:219
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
A DNS query.
Definition: dns_internal.h:137
Representation of a string in DNS.
Definition: dns_test.h:33
const char * val
Definition: dns_test.h:35