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.
/trunk/include/asterisk/dns_internal.h
Revision 434218 New Change
[20] 192 lines
[+20] [+] void dns_naptr_sort(struct ast_dns_result *result);
193
 * \param size The size of the SRV record
193
 * \param size The size of the SRV record
194
 *
194
 *
195
 * \retval non-NULL success
195
 * \retval non-NULL success
196
 * \retval NULL failure
196
 * \retval NULL failure
197
 */
197
 */
198
struct ast_dns_record *ast_dns_srv_alloc(struct ast_dns_query *query, const char *data, const size_t size);
198
struct ast_dns_record *dns_srv_alloc(struct ast_dns_query *query, const char *data, const size_t size);
199

    
   
199

   
200
/*!
200
/*!
201
 * \brief Sort the SRV records on a result
201
 * \brief Sort the SRV records on a result
202
 *
202
 *
203
 * \param result The DNS result
203
 * \param result The DNS result
204
 */
204
 */
205
void ast_dns_srv_sort(struct ast_dns_result *result);
205
void dns_srv_sort(struct ast_dns_result *result);
206

    
   
206

   

    
   
207
/*!

    
   
208
 * \brief Find the location of a DNS record within the entire DNS answer

    
   
209
 *

    
   
210
 * The DNS record that has been returned by the resolver may be a copy of the record that was

    
   
211
 * found in the complete DNS response. If so, then some DNS record types (specifically those that

    
   
212
 * parse domains) will need to locate the DNS record within the complete DNS response. This is so

    
   
213
 * that if the domain contains pointers to other sections of the DNS response, then the referenced

    
   
214
 * domains may be located.

    
   
215
 *

    
   
216
 * \param record The DNS record returned by a resolver implementation

    
   
217
 * \param record_size The size of the DNS record in bytes

    
   
218
 * \param response The complete DNS answer

    
   
219
 * \param response_size The size of the complete DNS response

    
   
220
 */

    
   
221
char *dns_find_record(const char *record, size_t record_size, const char *response, size_t response_size);

    
   
222

   

    
   
223
/*!

    
   
224
 * \brief Parse a 16-bit unsigned value from a DNS record

    
   
225
 *

    
   
226
 * \param cur Pointer to the location of the 16-bit value in the DNS record

    
   
227
 * \param[out] val The parsed 16-bit unsigned integer

    
   
228
 * \return The number of bytes consumed while parsing

    
   
229
 */

    
   
230
int dns_parse_short(unsigned char *cur, uint16_t *val);

    
   
231

   

    
   
232
/*!

    
   
233
 * \brief Parse a DNS string from a DNS record

    
   
234
 *

    
   
235
 * A DNS string consists of an 8-bit size, followed by the

    
   
236
 * string value (not NULL-terminated).

    
   
237
 *

    
   
238
 * \param cur Pointer to the location of the DNS string

    
   
239
 * \param[out] size The parsed size of the DNS string

    
   
240
 * \param[out] val The contained string (not NULL-terminated)

    
   
241
 * \return The number of bytes consumed while parsing

    
   
242
 */

    
   
243
int dns_parse_string(char *cur, uint8_t *size, char **val);
/trunk/include/asterisk/dns_test.h
New File
 
/trunk/main/dns_core.c
Revision 434218 New Change
 
/trunk/main/dns_naptr.c
Revision 434218 New Change
 
/trunk/main/dns_srv.c
Revision 434218 New Change
 
/trunk/main/dns_test.c
New File
 
/trunk/tests/test_dns_naptr.c
Revision 434218 New Change
 
/trunk/tests/test_dns_srv.c
Revision 434218 New Change
 
  1. /trunk/include/asterisk/dns_internal.h: Loading...
  2. /trunk/include/asterisk/dns_test.h: Loading...
  3. /trunk/main/dns_core.c: Loading...
  4. /trunk/main/dns_naptr.c: Loading...
  5. /trunk/main/dns_srv.c: Loading...
  6. /trunk/main/dns_test.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.