[asterisk-commits] mmichelson: branch group/dns_naptr r434052 - in /team/group/dns_naptr: ./ app...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 6 11:18:33 CDT 2015


Author: mmichelson
Date: Mon Apr  6 11:18:30 2015
New Revision: 434052

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=434052
Log:
Resolve conflicts and reset automerge.


Added:
    team/group/dns_naptr/tests/test_dns_srv.c
      - copied unchanged from r434047, trunk/tests/test_dns_srv.c
Modified:
    team/group/dns_naptr/   (props changed)
    team/group/dns_naptr/apps/app_stasis.c
    team/group/dns_naptr/build_tools/cflags.xml
    team/group/dns_naptr/include/asterisk/dns_internal.h
    team/group/dns_naptr/include/asterisk/res_pjsip_session.h
    team/group/dns_naptr/main/dns_core.c
    team/group/dns_naptr/main/dns_srv.c
    team/group/dns_naptr/main/format.c
    team/group/dns_naptr/res/parking/parking_applications.c
    team/group/dns_naptr/res/res_pjsip_messaging.c
    team/group/dns_naptr/res/res_resolver_unbound.c

Propchange: team/group/dns_naptr/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/group/dns_naptr/
------------------------------------------------------------------------------
Binary property 'branch-13-merged' - no diff available.

Propchange: team/group/dns_naptr/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Apr  6 11:18:30 2015
@@ -1,1 +1,1 @@
-/trunk:1-433868
+/trunk:1-434047

Modified: team/group/dns_naptr/apps/app_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_naptr/apps/app_stasis.c?view=diff&rev=434052&r1=434051&r2=434052
==============================================================================
--- team/group/dns_naptr/apps/app_stasis.c (original)
+++ team/group/dns_naptr/apps/app_stasis.c Mon Apr  6 11:18:30 2015
@@ -51,29 +51,27 @@
 			</parameter>
 		</syntax>
 		<description>
-			<para>
-				Invoke a Stasis application.
-			</para>
-		</description>
-		<para>This application will set the following channel variable upon
-		completion:</para>
+			<para>Invoke a Stasis application.</para>
+			<para>This application will set the following channel variable upon
+			completion:</para>
 			<variablelist>
 				<variable name="STASISSTATUS">
 					<para>This indicates the status of the execution of the
 					Stasis application.</para>
 					<value name="SUCCESS">
-					The channel has exited Stasis without any failures in Stasis
+						The channel has exited Stasis without any failures in
+						Stasis.
 					</value>
 					<value name="FAILED">
-					A failure occurred when executing the Stasis application.
-					Some (not all) possible reasons for this:
-					    <para>The app registry is not instantiated</para>
-					    <para>The app requested is not registered</para>
-					    <para>The app requested is not active</para>
-					    <para>Stasis couldn't send a start message</para>
+						A failure occurred when executing the Stasis
+						The app registry is not instantiated; The app
+						application. Some (not all) possible reasons for this:
+						requested is not registered; The app requested is not
+						active; Stasis couldn't send a start message.
 					</value>
 				</variable>
 			</variablelist>
+		</description>
 	</application>
  ***/
 

Modified: team/group/dns_naptr/build_tools/cflags.xml
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_naptr/build_tools/cflags.xml?view=diff&rev=434052&r1=434051&r2=434052
==============================================================================
--- team/group/dns_naptr/build_tools/cflags.xml (original)
+++ team/group/dns_naptr/build_tools/cflags.xml Mon Apr  6 11:18:30 2015
@@ -77,6 +77,7 @@
 			<support_level>extended</support_level>
 		</member>
 		<member name="MALLOC_DEBUG" displayname="Keep Track of Memory Allocations">
+			<conflict>DEBUG_CHAOS</conflict>
 			<support_level>core</support_level>
 		</member>
 		<member name="DEBUG_CHAOS" displayname="Randomly FAIL memory allocations or other operations">

Modified: team/group/dns_naptr/include/asterisk/dns_internal.h
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_naptr/include/asterisk/dns_internal.h?view=diff&rev=434052&r1=434051&r2=434052
==============================================================================
--- team/group/dns_naptr/include/asterisk/dns_internal.h (original)
+++ team/group/dns_naptr/include/asterisk/dns_internal.h Mon Apr  6 11:18:30 2015
@@ -60,6 +60,10 @@
 	unsigned short weight;
 	/*! \brief The port in the SRV record */
 	unsigned short port;
+	/*! \brief The running weight sum */
+	unsigned int weight_sum;
+	/*! \brief Additional data */
+	char data[0];
 };
 
 /*! \brief A NAPTR record */
@@ -96,7 +100,7 @@
 	/*! \brief Optional rcode, set if an error occurred */
 	unsigned int rcode;
 	/*! \brief Records returned */
-	AST_LIST_HEAD_NOLOCK(, ast_dns_record) records;
+	AST_LIST_HEAD_NOLOCK(dns_records, ast_dns_record) records;
 	/*! \brief The canonical name */
 	const char *canonical;
 	/*! \brief The raw DNS answer */
@@ -180,3 +184,23 @@
  * \param result The DNS result
  */
 void dns_naptr_sort(struct ast_dns_result *result);
+
+/*!
+ * \brief Allocate and parse a DNS SRV record
+ *
+ * \param query The DNS query
+ * \param data This specific SRV record
+ * \param size The size of the SRV record
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ */
+struct ast_dns_record *ast_dns_srv_alloc(struct ast_dns_query *query, const char *data, const size_t size);
+
+/*!
+ * \brief Sort the SRV records on a result
+ *
+ * \param result The DNS result
+ */
+void ast_dns_srv_sort(struct ast_dns_result *result);
+

Modified: team/group/dns_naptr/include/asterisk/res_pjsip_session.h
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_naptr/include/asterisk/res_pjsip_session.h?view=diff&rev=434052&r1=434051&r2=434052
==============================================================================
--- team/group/dns_naptr/include/asterisk/res_pjsip_session.h (original)
+++ team/group/dns_naptr/include/asterisk/res_pjsip_session.h Mon Apr  6 11:18:30 2015
@@ -107,8 +107,6 @@
 	char exten[AST_MAX_EXTENSION];
 	/*! The endpoint with which Asterisk is communicating */
 	struct ast_sip_endpoint *endpoint;
-	/*! The AOR associated with this session */
-	struct ast_sip_aor *aor;
 	/*! The contact associated with this session */
 	struct ast_sip_contact *contact;
 	/*! The PJSIP details of the session, which includes the dialog */
@@ -147,6 +145,8 @@
 	pjsip_rx_data *deferred_reinvite;
 	/*! Current T.38 state */
 	enum ast_sip_session_t38state t38state;
+	/*! The AOR associated with this session */
+	struct ast_sip_aor *aor;
 };
 
 typedef int (*ast_sip_session_request_creation_cb)(struct ast_sip_session *session, pjsip_tx_data *tdata);

Modified: team/group/dns_naptr/main/dns_core.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_naptr/main/dns_core.c?view=diff&rev=434052&r1=434051&r2=434052
==============================================================================
--- team/group/dns_naptr/main/dns_core.c (original)
+++ team/group/dns_naptr/main/dns_core.c Mon Apr  6 11:18:30 2015
@@ -462,6 +462,8 @@
 
 	if (rr_type == ns_t_naptr) {
 		record = dns_naptr_alloc(query, data, size);
+	} else if (rr_type == ns_t_srv) {
+		record = ast_dns_srv_alloc(query, data, size);
 	} else {
 		record = generic_record_alloc(query, data, size);
 	}
@@ -485,7 +487,10 @@
 {
 	if (ast_dns_query_get_rr_type(query) == ns_t_naptr) {
 		dns_naptr_sort(query->result);
-	}
+	} else if (ast_dns_query_get_rr_type(query) == ns_t_srv) {
+		ast_dns_srv_sort(query->result);
+	}
+
 	query->callback(query);
 }
 

Modified: team/group/dns_naptr/main/dns_srv.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_naptr/main/dns_srv.c?view=diff&rev=434052&r1=434051&r2=434052
==============================================================================
--- team/group/dns_naptr/main/dns_srv.c (original)
+++ team/group/dns_naptr/main/dns_srv.c Mon Apr  6 11:18:30 2015
@@ -31,25 +31,205 @@
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <resolv.h>
+
 #include "asterisk/dns_core.h"
 #include "asterisk/dns_srv.h"
+#include "asterisk/linkedlists.h"
+#include "asterisk/dns_internal.h"
+#include "asterisk/utils.h"
+
+struct ast_dns_record *ast_dns_srv_alloc(struct ast_dns_query *query, const char *data, const size_t size)
+{
+	uint16_t priority;
+	uint16_t weight;
+	uint16_t port;
+	const char *ptr;
+	char *srv_offset;
+	char *srv_search_base = (char *)query->result->answer;
+	size_t remaining_size = query->result->answer_size;
+	const char *end_of_record;
+	struct ast_dns_srv_record *srv;
+	int host_size;
+	char host[NI_MAXHOST] = "";
+
+	while (1) {
+		srv_offset = memchr(srv_search_base, data[0], remaining_size);
+
+		ast_assert(srv_offset != NULL);
+		ast_assert(srv_search_base + remaining_size - srv_offset >= size);
+
+		if (!memcmp(srv_offset, data, size)) {
+			ptr = srv_offset;
+			break;
+		}
+
+		remaining_size -= srv_offset - srv_search_base;
+		srv_search_base = srv_offset + 1;
+	}
+
+	ast_assert(ptr != NULL);
+
+	end_of_record = ptr + size;
+
+	/* PRIORITY */
+	priority = ((unsigned char)(ptr[1]) << 0) | ((unsigned char)(ptr[0]) << 8);
+	ptr += 2;
+
+	if (ptr >= end_of_record) {
+		return NULL;
+	}
+
+	/* WEIGHT */
+	weight = ((unsigned char)(ptr[1]) << 0) | ((unsigned char)(ptr[0]) << 8);
+	ptr += 2;
+
+	if (ptr >= end_of_record) {
+		return NULL;
+	}
+
+	/* PORT */
+	port = ((unsigned char)(ptr[1]) << 0) | ((unsigned char)(ptr[0]) << 8);
+	ptr += 2;
+
+	if (ptr >= end_of_record) {
+		return NULL;
+	}
+
+	host_size = dn_expand((unsigned char *)query->result->answer, (unsigned char *) end_of_record, (unsigned char *) ptr, host, sizeof(host) - 1);
+	if (host_size < 0) {
+		ast_log(LOG_ERROR, "Failed to expand domain name: %s\n", strerror(errno));
+		return NULL;
+	}
+
+	if (!strcmp(host, ".")) {
+		return NULL;
+	}
+
+	srv = ast_calloc(1, sizeof(*srv) + size + host_size + 1);
+	if (!srv) {
+		return NULL;
+	}
+
+	srv->priority = priority;
+	srv->weight = weight;
+	srv->port = port;
+
+	srv->host = srv->data + size;
+	strcpy((char *)srv->host, host); /* SAFE */
+	((char *)srv->host)[host_size] = '\0';
+
+	srv->generic.data_ptr = srv->data;
+
+	return (struct ast_dns_record *)srv;
+}
+
+/* This implementation was taken from the existing srv.c which, after reading the RFC, implements it
+ * as it should.
+ */
+void ast_dns_srv_sort(struct ast_dns_result *result)
+{
+	struct ast_dns_record *current;
+	struct dns_records newlist = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
+
+	while (AST_LIST_FIRST(&result->records)) {
+		unsigned short cur_priority = 0;
+		struct dns_records temp_list = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
+
+		/* Find the lowest current priority to work on */
+		AST_LIST_TRAVERSE(&result->records, current, list) {
+			if (!cur_priority || ((struct ast_dns_srv_record *)current)->priority < cur_priority) {
+				cur_priority = ((struct ast_dns_srv_record *)current)->priority;
+			}
+		}
+
+		/* Find all records which match this priority */
+		AST_LIST_TRAVERSE_SAFE_BEGIN(&result->records, current, list) {
+			if (((struct ast_dns_srv_record *)current)->priority != cur_priority) {
+				continue;
+			}
+
+			AST_LIST_REMOVE_CURRENT(list);
+
+			/* Records with a weight of zero must always be at the head */
+			if (((struct ast_dns_srv_record *)current)->weight == 0) {
+				AST_LIST_INSERT_HEAD(&temp_list, current, list);
+			} else {
+				AST_LIST_INSERT_TAIL(&temp_list, current, list);
+			}
+		}
+		AST_LIST_TRAVERSE_SAFE_END;
+
+		/* Apply weighting - as each record is passed the sum of all previous weights (plus its own) is stored away, and then a random weight
+		 * is calculated. The first record with a weight sum greater than the random weight is put in the new list and the whole thing starts
+		 * once again.
+		 */
+		while (AST_LIST_FIRST(&temp_list)) {
+			unsigned int weight_sum = 0;
+			unsigned int random_weight;
+
+			AST_LIST_TRAVERSE(&temp_list, current, list) {
+				((struct ast_dns_srv_record *)current)->weight_sum = weight_sum += ((struct ast_dns_srv_record *)current)->weight;
+			}
+
+			/* if all the remaining entries have weight == 0,
+			   then just append them to the result list and quit */
+			if (weight_sum == 0) {
+				AST_LIST_APPEND_LIST(&newlist, &temp_list, list);
+				break;
+			}
+
+			random_weight = 1 + (unsigned int) ((float) weight_sum * (ast_random() / ((float) RAND_MAX + 1.0)));
+
+			AST_LIST_TRAVERSE_SAFE_BEGIN(&temp_list, current, list) {
+				if (((struct ast_dns_srv_record *)current)->weight_sum < random_weight) {
+					continue;
+				}
+
+				AST_LIST_MOVE_CURRENT(&newlist, list);
+				break;
+			}
+			AST_LIST_TRAVERSE_SAFE_END;
+		}
+
+	}
+
+	/* now that the new list has been ordered,
+	   put it in place */
+
+	AST_LIST_APPEND_LIST(&result->records, &newlist, list);
+}
 
 const char *ast_dns_srv_get_host(const struct ast_dns_record *record)
 {
-	return NULL;
+	struct ast_dns_srv_record *srv = (struct ast_dns_srv_record *) record;
+
+	ast_assert(ast_dns_record_get_rr_type(record) == ns_t_srv);
+	return srv->host;
 }
 
 unsigned short ast_dns_srv_get_priority(const struct ast_dns_record *record)
 {
-	return 0;
+	struct ast_dns_srv_record *srv = (struct ast_dns_srv_record *) record;
+
+	ast_assert(ast_dns_record_get_rr_type(record) == ns_t_srv);
+	return srv->priority;
 }
 
 unsigned short ast_dns_srv_get_weight(const struct ast_dns_record *record)
 {
-	return 0;
+	struct ast_dns_srv_record *srv = (struct ast_dns_srv_record *) record;
+
+	ast_assert(ast_dns_record_get_rr_type(record) == ns_t_srv);
+	return srv->weight;
 }
 
 unsigned short ast_dns_srv_get_port(const struct ast_dns_record *record)
 {
-	return 0;
-}
+	struct ast_dns_srv_record *srv = (struct ast_dns_srv_record *) record;
+
+	ast_assert(ast_dns_record_get_rr_type(record) == ns_t_srv);
+	return srv->port;
+}

Modified: team/group/dns_naptr/main/format.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_naptr/main/format.c?view=diff&rev=434052&r1=434051&r2=434052
==============================================================================
--- team/group/dns_naptr/main/format.c (original)
+++ team/group/dns_naptr/main/format.c Mon Apr  6 11:18:30 2015
@@ -375,7 +375,7 @@
 
 unsigned int ast_format_get_sample_rate(const struct ast_format *format)
 {
-	return format->codec->sample_rate;
+	return format->codec->sample_rate ?: 8000;
 }
 
 unsigned int ast_format_determine_length(const struct ast_format *format, unsigned int samples)

Modified: team/group/dns_naptr/res/parking/parking_applications.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_naptr/res/parking/parking_applications.c?view=diff&rev=434052&r1=434051&r2=434052
==============================================================================
--- team/group/dns_naptr/res/parking/parking_applications.c (original)
+++ team/group/dns_naptr/res/parking/parking_applications.c Mon Apr  6 11:18:30 2015
@@ -647,7 +647,10 @@
 
 	ast_bridge_features_cleanup(&chan_features);
 
-	return 0;
+	/* Return -1 so that call does not continue in the dialplan. This is to make
+	 * behavior consistent with Asterisk versions prior to 12.
+	 */
+	return -1;
 }
 
 struct park_announce_subscription_data {

Modified: team/group/dns_naptr/res/res_pjsip_messaging.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_naptr/res/res_pjsip_messaging.c?view=diff&rev=434052&r1=434051&r2=434052
==============================================================================
--- team/group/dns_naptr/res/res_pjsip_messaging.c (original)
+++ team/group/dns_naptr/res/res_pjsip_messaging.c Mon Apr  6 11:18:30 2015
@@ -42,12 +42,15 @@
 #include "asterisk/pbx.h"
 #include "asterisk/res_pjsip.h"
 #include "asterisk/res_pjsip_session.h"
+#include "asterisk/taskprocessor.h"
 
 const pjsip_method pjsip_message_method = {PJSIP_OTHER_METHOD, {"MESSAGE", 7} };
 
 #define MAX_HDR_SIZE 512
 #define MAX_BODY_SIZE 1024
 #define MAX_USER_SIZE 128
+
+static struct ast_taskprocessor *message_serializer;
 
 /*!
  * \internal
@@ -593,7 +596,7 @@
 	}
 
 	if (!(mdata = msg_data_create(msg, to, from)) ||
-	    ast_sip_push_task(NULL, msg_send, mdata)) {
+	    ast_sip_push_task(message_serializer, msg_send, mdata)) {
 		ao2_ref(mdata, -1);
 		return -1;
 	}
@@ -748,6 +751,13 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
+	message_serializer = ast_sip_create_serializer();
+	if (!message_serializer) {
+		ast_sip_unregister_service(&messaging_module);
+		ast_msg_tech_unregister(&msg_tech);
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
 	ast_sip_session_register_supplement(&messaging_supplement);
 	return AST_MODULE_LOAD_SUCCESS;
 }
@@ -757,6 +767,7 @@
 	ast_sip_session_unregister_supplement(&messaging_supplement);
 	ast_msg_tech_unregister(&msg_tech);
 	ast_sip_unregister_service(&messaging_module);
+	ast_taskprocessor_unreference(message_serializer);
 	return 0;
 }
 

Modified: team/group/dns_naptr/res/res_resolver_unbound.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_naptr/res/res_resolver_unbound.c?view=diff&rev=434052&r1=434051&r2=434052
==============================================================================
--- team/group/dns_naptr/res/res_resolver_unbound.c (original)
+++ team/group/dns_naptr/res/res_resolver_unbound.c Mon Apr  6 11:18:30 2015
@@ -35,6 +35,10 @@
 #include "asterisk/config.h"
 #include "asterisk/config_options.h"
 #include "asterisk/test.h"
+
+#ifdef TEST_FRAMEWORK
+#include "asterisk/dns_srv.h"
+#endif
 
 /*** DOCUMENTATION
 	<configInfo name="res_resolver_unbound" language="en_US">
@@ -1299,6 +1303,74 @@
 	return res;
 
 }
+
+AST_TEST_DEFINE(resolve_srv)
+{
+	RAII_VAR(struct unbound_resolver *, resolver, NULL, ao2_cleanup);
+	RAII_VAR(struct unbound_config *, cfg, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_dns_result *, result, NULL, ast_dns_result_free);
+	const struct ast_dns_record *record;
+	static const char *DOMAIN1 = "taco.bananas";
+	static const char *DOMAIN1_SRV = "taco.bananas 12345 IN SRV 10 20 5060 sip.taco.bananas";
+	enum ast_test_result_state res = AST_TEST_PASS;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "resolve_srv";
+		info->category = "/res/res_resolver_unbound/";
+		info->summary = "Test synchronous SRV resolution using libunbound\n";
+		info->description = "This test performs the following:\n"
+			"\t* Set one SRV record on one domain\n"
+			"\t* Perform an SRV lookup on the domain\n"
+			"\t* Ensure that the SRV record returned matches the expected value\n";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	cfg = ao2_global_obj_ref(globals);
+	resolver = ao2_bump(cfg->global->state->resolver);
+
+	ub_ctx_zone_add(resolver->context, DOMAIN1, "static");
+	ub_ctx_data_add(resolver->context, DOMAIN1_SRV);
+
+	if (ast_dns_resolve(DOMAIN1, ns_t_srv, ns_c_in, &result)) {
+		ast_test_status_update(test, "Failed to synchronously resolve SRV for domain '%s'\n", DOMAIN1);
+		res = AST_TEST_FAIL;
+		goto cleanup;
+	}
+
+	record = ast_dns_result_get_records(result);
+	if (ast_dns_srv_get_priority(record) != 10) {
+		ast_test_status_update(test, "SRV Record returned priority '%d' when we expected 10\n", ast_dns_srv_get_priority(record));
+		res = AST_TEST_FAIL;
+		goto cleanup;
+	}
+
+	if (ast_dns_srv_get_weight(record) != 20) {
+		ast_test_status_update(test, "SRV Record returned weight '%d' when we expected 20\n", ast_dns_srv_get_weight(record));
+		res = AST_TEST_FAIL;
+		goto cleanup;
+	}
+
+	if (ast_dns_srv_get_port(record) != 5060) {
+		ast_test_status_update(test, "SRV Record returned port '%d' when we expected 5060\n", ast_dns_srv_get_port(record));
+		res = AST_TEST_FAIL;
+		goto cleanup;
+	}
+
+	if (strcmp(ast_dns_srv_get_host(record), "sip.taco.bananas")) {
+		ast_test_status_update(test, "SRV Record returned host '%s' when we expected sip.taco.bananas\n", ast_dns_srv_get_host(record));
+		res = AST_TEST_FAIL;
+		goto cleanup;
+	}
+
+cleanup:
+	ub_ctx_data_remove(resolver->context, DOMAIN1_SRV);
+	ub_ctx_zone_remove(resolver->context, DOMAIN1);
+
+	return res;
+}
 #endif
 
 static int reload_module(void)
@@ -1321,6 +1393,7 @@
 	AST_TEST_UNREGISTER(resolve_sync_off_nominal);
 	AST_TEST_UNREGISTER(resolve_cancel_off_nominal);
 	AST_TEST_UNREGISTER(resolve_naptr);
+	AST_TEST_UNREGISTER(resolve_srv);
 	return 0;
 }
 
@@ -1378,6 +1451,7 @@
 	AST_TEST_REGISTER(resolve_async_off_nominal);
 	AST_TEST_REGISTER(resolve_cancel_off_nominal);
 	AST_TEST_REGISTER(resolve_naptr);
+	AST_TEST_REGISTER(resolve_srv);
 
 	return AST_MODULE_LOAD_SUCCESS;
 }




More information about the asterisk-commits mailing list