[asterisk-commits] file: branch group/dns r432477 - in /team/group/dns: include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 4 17:04:43 CST 2015


Author: file
Date: Wed Mar  4 17:04:41 2015
New Revision: 432477

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=432477
Log:
Implement ast_dns_resolver_set_result and ast_dns_resolver_add_record.

Modified:
    team/group/dns/include/asterisk/dns_internal.h
    team/group/dns/main/dns_core.c

Modified: team/group/dns/include/asterisk/dns_internal.h
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/include/asterisk/dns_internal.h?view=diff&rev=432477&r1=432476&r2=432477
==============================================================================
--- team/group/dns/include/asterisk/dns_internal.h (original)
+++ team/group/dns/include/asterisk/dns_internal.h Wed Mar  4 17:04:41 2015
@@ -31,12 +31,12 @@
 	int rr_class;
 	/*! \brief Time-to-live of the record */
 	int ttl;
-	/*! \brief The raw DNS record */
-	char *data;
 	/*! \brief The size of the raw DNS record */
 	size_t data_len;
 	/*! \brief Linked list information */
 	AST_LIST_ENTRY(ast_dns_record) list;
+	/*! \brief The raw DNS record */
+	char data[0];
 };
 
 /*! \brief An SRV record */
@@ -79,10 +79,10 @@
 	unsigned int secure;
 	/*! \brief Whether the result is bogus */
 	unsigned int bogus;
-	/*! \brief The canonical name */
-	const char *canonical;
 	/*! \brief Records returned */
 	AST_LIST_HEAD_NOLOCK(, ast_dns_record) records;
+	/*! \brief The canonical name */
+	char canonical[0];
 };
 
 /*! \brief A DNS query */

Modified: team/group/dns/main/dns_core.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/main/dns_core.c?view=diff&rev=432477&r1=432476&r2=432477
==============================================================================
--- team/group/dns/main/dns_core.c (original)
+++ team/group/dns/main/dns_core.c Wed Mar  4 17:04:41 2015
@@ -101,6 +101,7 @@
 
 void ast_dns_result_free(struct ast_dns_result *result)
 {
+	ao2_cleanup(result);
 }
 
 int ast_dns_record_get_rr_type(const struct ast_dns_record *record)
@@ -333,6 +334,17 @@
 	return query->resolver_data;
 }
 
+/*! \brief Destructor for DNS result */
+static void dns_result_destroy(void *obj)
+{
+	struct ast_dns_result *result = obj;
+	struct ast_dns_record *record;
+
+	while ((record = AST_LIST_REMOVE_HEAD(&result->records, list))) {
+		ast_free(record);
+	}
+}
+
 int ast_dns_resolver_set_result(struct ast_dns_query *query, unsigned int nxdomain, unsigned int secure, unsigned int bogus,
 	const char *canonical)
 {
@@ -340,17 +352,41 @@
 		ast_dns_result_free(query->result);
 	}
 
-	query->result = NULL;
+	query->result = ao2_alloc_options(sizeof(*query->result) + strlen(canonical) + 1, dns_result_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
+	if (!query->result) {
+		return -1;
+	}
+
+	query->result->nxdomain = nxdomain;
+	query->result->secure = secure;
+	query->result->bogus = bogus;
+	strcpy(query->result->canonical, canonical); /* SAFE */
+
 	return 0;
 }
 
 int ast_dns_resolver_add_record(struct ast_dns_query *query, int rr_type, int rr_class, int ttl, const char *data, const size_t size)
 {
+	struct ast_dns_record *record;
+
 	if (!query->result) {
 		return -1;
 	}
 
-	return -1;
+	record = ast_calloc(1, sizeof(*record) + size);
+	if (!record) {
+		return -1;
+	}
+
+	record->rr_type = rr_type;
+	record->rr_class = rr_class;
+	record->ttl = ttl;
+	memcpy(record->data, data, size);
+	record->data_len = size;
+
+	AST_LIST_INSERT_TAIL(&query->result->records, record, list);
+
+	return 0;
 }
 
 void ast_dns_resolver_completed(const struct ast_dns_query *query)




More information about the asterisk-commits mailing list