dns_test.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2015, Digium, Inc.
00005  *
00006  * Mark Michelson <mmichelson@digium.com>
00007  *
00008  * Includes code and algorithms from the Zapata library.
00009  *
00010  * See http://www.asterisk.org for more information about
00011  * the Asterisk project. Please do not directly contact
00012  * any of the maintainers of this project for assistance;
00013  * the project provides a web site, mailing lists and IRC
00014  * channels for your use.
00015  *
00016  * This program is free software, distributed under the terms of
00017  * the GNU General Public License Version 2. See the LICENSE file
00018  * at the top of the source tree.
00019  */
00020 
00021 #ifndef DNS_TEST_H
00022 #define DNS_TEST_H
00023 
00024 /*!
00025  * \brief Representation of a string in DNS
00026  *
00027  * In DNS, a string has a byte to indicate the length,
00028  * followed by a series of bytes representing the string.
00029  * DNS does not NULL-terminate its strings. However, the
00030  * string stored in this structure is expected to be NULL-
00031  * terminated.
00032  */
00033 struct ast_dns_test_string {
00034    uint8_t len;
00035    const char *val;
00036 };
00037 
00038 /*!
00039  * \brief Write a DNS string to a buffer
00040  *
00041  * This writes the DNS string to the buffer and returns the total
00042  * number of bytes written to the buffer.
00043  *
00044  * There is no buffer size passed to this function. Tests are expected to
00045  * use a buffer that is sufficiently large for their tests.
00046  *
00047  * \param string The string to write
00048  * \param buf The buffer to write the string into
00049  * \return The number of bytes written to the buffer
00050  */
00051 int ast_dns_test_write_string(const struct ast_dns_test_string *string, char *buf);
00052 
00053 /*!
00054  * \brief Write a DNS domain to a buffer
00055  *
00056  * A DNS domain consists of a series of labels separated
00057  * by dots. Each of these labels gets written as a DNS
00058  * string. A DNS domain ends with a NULL label, which is
00059  * essentially a zero-length DNS string.
00060  *
00061  * There is no buffer size passed to this function. Tests are expected to
00062  * use a buffer that is sufficiently large for their tests.
00063  *
00064  * \param string The DNS domain to write
00065  * \param buf The buffer to write the domain into
00066  * \return The number of bytes written to the buffer
00067  */
00068 int ast_dns_test_write_domain(const char *string, char *buf);
00069 
00070 /*!
00071  * \brief Callback to write specific DNS record to an answer
00072  *
00073  * When generating a DNS result, the type of DNS record being generated
00074  * will need to be performed by individual test cases. This is a callback
00075  * that tests can define to write a specific type of DNS record to the
00076  * provided buffer.
00077  *
00078  * There is no buffer size passed to this function. Tests are expected to
00079  * use a buffer that is sufficiently large for their tests.
00080  *
00081  * \param record Pointer to test-specific DNS record data
00082  * \param buf The buffer into which to write the DNS record
00083  * \return The number of bytes written to the buffer
00084  */
00085 typedef int (*record_fn)(void *record, char *buf);
00086 
00087 /*!
00088  * \brief Generate a full DNS response for the given DNS records.
00089  *
00090  * This function takes care of generating the DNS header, question, and
00091  * answer sections of a DNS response. In order to place test-specific
00092  * record data into the DNS answers, a callback is provided as a parameter
00093  * to this function so that the necessary records can be encoded properly
00094  * by the tests.
00095  *
00096  * There is no buffer size passed to this function. Tests are expected to
00097  * use a buffer that is sufficiently large for their tests.
00098  *
00099  * \param query The DNS query that is being processed
00100  * \param records An array of test-specific representations of DNS records
00101  * \param num_records The number of elements in the records array
00102  * \param record_size The size of each element in the records array
00103  * \param generate The test-specific encoder for DNS records
00104  * \param buffer The buffer into which to write the DNS response
00105  */
00106 int ast_dns_test_generate_result(struct ast_dns_query *query, void *records, size_t num_records,
00107       size_t record_size, record_fn generate, char *buffer);
00108 
00109 #endif /* DNS_TEST_H */

Generated on Thu Apr 16 06:27:33 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6