Review Board 1.7.16


Refactor duplicated DNS routines into common sections

Review Request #4598 - Created April 6, 2015 and submitted

Mark Michelson
/trunk/
Reviewers
asterisk-dev
Asterisk
Josh worked on SRV in one branch, and I worked on NAPTR in a separate branch. Independently we kept coming to realizations that something that one of us had developed independently would be needed by the other person. We decided to simply have copies of common functionality in our branches. After merging, we would perform a refactor to remove duplication.

This changeset introduces no new DNS functionality. Instead, it takes some duplicated code and places them into common areas of the DNS core.
All DNS unit tests continue to pass.

Diff revision 1

This is not the most recent revision of the diff. The latest diff is revision 2. See what's changed.

1 2
1 2

  1. /trunk/include/asterisk/dns_test.h: Loading...
  2. /trunk/main/dns_test.c: Loading...
  3. /trunk/include/asterisk/dns_internal.h: Loading...
  4. /trunk/main/dns_core.c: Loading...
  5. /trunk/main/dns_naptr.c: Loading...
  6. /trunk/main/dns_srv.c: Loading...
  7. /trunk/tests/test_dns_naptr.c: Loading...
  8. /trunk/tests/test_dns_srv.c: Loading...
/team/group/dns/include/asterisk/dns_test.h /trunk/include/asterisk/dns_test.h
New 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
 */

    
   
33
struct ast_dns_test_string {

    
   
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
 */

    
   
51
int 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
 */

    
   
68
int 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
 */

    
   
85
typedef 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
 */

    
   
106
int 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 */
/team/group/dns/main/dns_test.c
New File
 
/trunk/include/asterisk/dns_internal.h
Revision 434186 New Change
 
/trunk/main/dns_core.c
Revision 434186 New Change
 
/trunk/main/dns_naptr.c
Revision 434186 New Change
 
/trunk/main/dns_srv.c
Revision 434186 New Change
 
/trunk/tests/test_dns_naptr.c
Revision 434186 New Change
 
/trunk/tests/test_dns_srv.c
Revision 434186 New Change
 
  1. /trunk/include/asterisk/dns_test.h: Loading...
  2. /trunk/main/dns_test.c: Loading...
  3. /trunk/include/asterisk/dns_internal.h: Loading...
  4. /trunk/main/dns_core.c: Loading...
  5. /trunk/main/dns_naptr.c: Loading...
  6. /trunk/main/dns_srv.c: Loading...
  7. /trunk/tests/test_dns_naptr.c: Loading...
  8. /trunk/tests/test_dns_srv.c: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.